|
1 /* |
|
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 import java.awt.datatransfer.DataFlavor; |
|
27 import java.awt.datatransfer.SystemFlavorMap; |
|
28 |
|
29 /* |
|
30 * @test |
|
31 * @summary To check for error handling with new Clipboard/SystemFlavorMap |
|
32 * methods, and insure that the appropriate exceptions are being thrown. |
|
33 * Specifically check for null variables in the methods: |
|
34 * - addFlavorForUnencodedNative(String nat, DataFlavor flav) |
|
35 * - addUnencodedNativeForFlavor(DataFlavor flav, String nat) |
|
36 * - setNativesForFlavor(DataFlavor flav, String[] natives) |
|
37 * - setFlavorsForNative(String nat, DataFlavor[] flavors) |
|
38 * @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard |
|
39 * @run main InvalidMapArgumentsTest |
|
40 */ |
|
41 |
|
42 public class InvalidMapArgumentsTest { |
|
43 |
|
44 SystemFlavorMap flavorMap; |
|
45 String test_nat; |
|
46 String[] test_natives; |
|
47 DataFlavor test_flav; |
|
48 DataFlavor[] test_flavors; |
|
49 |
|
50 public static void main (String[] args){ |
|
51 new InvalidMapArgumentsTest().doTest(); |
|
52 } |
|
53 |
|
54 public void doTest (){ |
|
55 //Get things going. Request focus, set size, et cetera |
|
56 initMappings(); |
|
57 |
|
58 // Test for combinations of null values for |
|
59 // addFlavorForUnencodedNative(String nat, DataFlavor flav) |
|
60 addFlavorForUnencodedNativeTest(null, null, "both String nat and DataFlavor flav set to null. "); |
|
61 addFlavorForUnencodedNativeTest(null, test_flav, "String nat set to null. "); |
|
62 addFlavorForUnencodedNativeTest(test_nat, null, "DataFlavor flav set to null. "); |
|
63 |
|
64 |
|
65 // Test for combinations of null values for |
|
66 // addUnencodedNativeForFlavor(DataFlavor flav, String nat) |
|
67 addUnencodedNativeForFlavorTest(null, null, "both DataFlavor flav and String nat set to null. "); |
|
68 addUnencodedNativeForFlavorTest(null, test_nat, "DataFlavor flav set to null. "); |
|
69 addUnencodedNativeForFlavorTest(test_flav, null, "String nat set to null. "); |
|
70 |
|
71 |
|
72 // Test for combinations of null values for |
|
73 // setNativesForFlavor(DataFlavor flav, String[] natives) |
|
74 setNativesForFlavorTest(null, null, "both DataFlavor flav and String[] natives set to null. "); |
|
75 setNativesForFlavorTest(null, test_natives, "DataFlavor flav set to null. "); |
|
76 setNativesForFlavorTest(test_flav, null, "String[] natives set to null. "); |
|
77 |
|
78 |
|
79 // Test for combinations of null values for |
|
80 // setFlavorsForNative(String nat, DataFlavor[] flavors) |
|
81 setFlavorsForNativeTest(null, null, "both String nat and DataFlavor[] flavors set to null. "); |
|
82 setFlavorsForNativeTest(null, test_flavors, "String nat set to null. "); |
|
83 setFlavorsForNativeTest(test_nat, null, "DataFlavor[] flavors set to null. "); |
|
84 } |
|
85 |
|
86 public void initMappings() { |
|
87 //initialize mapping variables used in this test |
|
88 flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap(); |
|
89 |
|
90 //create a DataFlavor with valid parameters (mimeType, humanPresentableName) |
|
91 test_flav = new DataFlavor("text/plain; charset=ascii","ASCII Flavor"); |
|
92 |
|
93 //create a String native |
|
94 test_nat = "TEXT_TEST"; |
|
95 |
|
96 //create a DataFlavor array |
|
97 test_flavors = new DataFlavor[] {test_flav}; |
|
98 |
|
99 //create a String native array |
|
100 test_natives = new String[] {test_nat}; |
|
101 } |
|
102 |
|
103 public void setNativesForFlavorTest(DataFlavor flav, String[] natives, String errmsg) { |
|
104 try{ |
|
105 flavorMap.setNativesForFlavor(flav, natives); |
|
106 throw new RuntimeException("NullPointerException is not thrown for method "+ |
|
107 "setNativesForFlavor with "+errmsg); |
|
108 } catch (NullPointerException e) { |
|
109 } |
|
110 } |
|
111 |
|
112 public void setFlavorsForNativeTest(String nat, DataFlavor[] flavors, String errmsg) { |
|
113 try{ |
|
114 flavorMap.setFlavorsForNative(nat, flavors); |
|
115 throw new RuntimeException("NullPointerException is not thrown for method "+ |
|
116 "setFlavorsForNative with "+errmsg); |
|
117 } catch (NullPointerException e) { |
|
118 } |
|
119 } |
|
120 |
|
121 public void addFlavorForUnencodedNativeTest(String nat, DataFlavor flav, String errmsg) { |
|
122 try{ |
|
123 flavorMap.addFlavorForUnencodedNative(nat, flav); |
|
124 throw new RuntimeException("NullPointerException is not thrown for method "+ |
|
125 "addFlavorForUnencodedNative with "+errmsg); |
|
126 } catch (NullPointerException e) { |
|
127 } |
|
128 } |
|
129 |
|
130 public void addUnencodedNativeForFlavorTest(DataFlavor flav, String nat, String errmsg) { |
|
131 try{ |
|
132 flavorMap.addUnencodedNativeForFlavor(flav, nat); |
|
133 throw new RuntimeException("NullPointerException is not thrown for method "+ |
|
134 "addUnencodedNativeForFlavor with "+errmsg); |
|
135 } catch (NullPointerException e) { |
|
136 } |
|
137 } |
|
138 } |
|
139 |