jdk/test/java/awt/datatransfer/DataFlavor/GetReaderForTextIAEForStringSelectionTest.java
author yan
Tue, 23 Jun 2015 11:59:27 +0300
changeset 31448 1066345d2a8a
parent 25197 533f45be322f
permissions -rw-r--r--
8076468: Add @modules to tests in jdk_desktop test group Reviewed-by: yan, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25197
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     1
/*
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 25197
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
25197
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     4
 *
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     7
 * published by the Free Software Foundation.
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     8
 *
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    13
 * accompanied this code).
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    14
 *
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    18
 *
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    21
 * questions.
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    22
 */
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    23
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    24
/*
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    25
  @test
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    26
  @bug 4260874
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    27
  @summary Tests that DataFlavor.getReaderForText do not throw NPE when transferObject is null
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    28
  @author tdv@sparc.spb.su: area=
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 25197
diff changeset
    29
  @modules java.datatransfer
25197
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    30
  @run main GetReaderForTextIAEForStringSelectionTest
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    31
*/
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    32
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    33
import java.awt.datatransfer.DataFlavor;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    34
import java.awt.datatransfer.StringSelection;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    35
import java.awt.datatransfer.Transferable;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    36
import java.awt.datatransfer.UnsupportedFlavorException;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    37
import java.io.IOException;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    38
import java.io.Reader;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    39
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    40
public class GetReaderForTextIAEForStringSelectionTest  {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    41
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    42
   public static void main(String[] args) throws Exception {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    43
      DataFlavor pt ;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    44
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    45
      try {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    46
          pt = DataFlavor.plainTextFlavor;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    47
          StringSelection ss = new StringSelection("ReaderExample");
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    48
          Reader re = pt.getReaderForText(ss);
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    49
          if(re == null) {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    50
              throw new RuntimeException("Test FAILED! reader==null");
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    51
          }
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    52
      } catch (Exception e) {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    53
          throw new RuntimeException("Test FAILED because of the exception: " + e);
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    54
      }
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    55
    }
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    56
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    57
 }
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    58
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    59
class FakeTransferable implements Transferable {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    60
    public DataFlavor[] getTransferDataFlavors() {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    61
        return null;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    62
    }
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    63
    public boolean isDataFlavorSupported(DataFlavor flavor) {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    64
        return false;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    65
    }
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    66
    public Object getTransferData(DataFlavor flavor) throws
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    67
        UnsupportedFlavorException, IOException {
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    68
        return null;
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    69
    }
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    70
}
533f45be322f 8046221: [TEST_BUG] Cleanup datatransfer tests
pchelko
parents:
diff changeset
    71