author | yan |
Tue, 23 Jun 2015 11:59:27 +0300 | |
changeset 31448 | 1066345d2a8a |
parent 25569 | 2bea87828632 |
permissions | -rw-r--r-- |
25569
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
1 |
/* |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
25569
diff
changeset
|
2 |
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. |
25569
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
4 |
* |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
10 |
* |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
15 |
* accompanied this code). |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
16 |
* |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
20 |
* |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
23 |
* questions. |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
24 |
*/ |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
25 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
26 |
import java.awt.datatransfer.DataFlavor; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
27 |
import java.awt.datatransfer.SystemFlavorMap; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
28 |
import java.util.Arrays; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
29 |
import java.util.Hashtable; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
30 |
import java.util.Vector; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
31 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
32 |
/* |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
33 |
* @test |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
34 |
* @summary To test SystemFlavorMap method |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
35 |
* getNativesForFlavor(DataFlavor flav) |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
36 |
* with unknown DataFlavor. Specifically test for |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
37 |
* passing an unknown DataFlavor where two-way mapping |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
38 |
* should be established. |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
39 |
* @author Rick Reynaga (rick.reynaga@eng.sun.com) area=Clipboard |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
25569
diff
changeset
|
40 |
* @modules java.datatransfer |
25569
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
41 |
* @run main GetNativesForNewFlavorTest |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
42 |
*/ |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
43 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
44 |
public class GetNativesForNewFlavorTest { |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
45 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
46 |
SystemFlavorMap flavorMap; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
47 |
Vector comp1, comp2, comp3, comp4; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
48 |
Hashtable hash; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
49 |
int hashSize; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
50 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
51 |
String test_encoded; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
52 |
DataFlavor test_flavor1, test_flavor2; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
53 |
String[] test_natives_set; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
54 |
DataFlavor[] test_flavors_set; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
55 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
56 |
public static void main (String[] args) throws Exception { |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
57 |
new GetNativesForNewFlavorTest().doTest(); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
58 |
} |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
59 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
60 |
public void doTest() throws Exception { |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
61 |
// Initialize DataFlavors and arrays used for test data |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
62 |
initMappings(); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
63 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
64 |
boolean passed = true; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
65 |
flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap(); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
66 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
67 |
// Get all the native strings and preferred DataFlavor mappings |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
68 |
hash = new Hashtable(flavorMap.getFlavorsForNatives(null)); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
69 |
hashSize = hash.size(); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
70 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
71 |
// GetNativesForFlavor using unknown DataFlavor (verify 2-way mapping) |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
72 |
// |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
73 |
// If a new DataFlavor is specified, the method should establish a mapping |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
74 |
// in both directions between specified DataFlavor and an encoded |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
75 |
// version of its MIME type as its native. |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
76 |
System.out.println("GetNativesForFlavor using new DataFlavor"); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
77 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
78 |
comp1 = new Vector(Arrays.asList(test_natives_set)); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
79 |
comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1)); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
80 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
81 |
comp3 = new Vector(Arrays.asList(test_flavors_set)); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
82 |
comp4 = new Vector(flavorMap.getFlavorsForNative(test_encoded)); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
83 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
84 |
if ( !comp1.equals(comp2) || !comp3.equals(comp4) ) { |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
85 |
throw new RuntimeException("\n*** After passing a new DataFlavor" + |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
86 |
"\nwith getNativesForFlavor(DataFlavor flav)" + |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
87 |
"\nthe mapping in both directions was not established."); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
88 |
} |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
89 |
else |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
90 |
System.out.println("GetNativesForFlavor using new DataFlavor: Test Passes"); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
91 |
} |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
92 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
93 |
public void initMappings() throws Exception { |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
94 |
//initialize mapping variables used in this test |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
95 |
//create a DataFlavor from Button class |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
96 |
test_flavor1 = new DataFlavor(Class.forName("java.awt.Button"), "Button"); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
97 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
98 |
//create an Encoded String native using Button class MIME Type |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
99 |
String buttonMIME = test_flavor1.getMimeType(); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
100 |
test_encoded = SystemFlavorMap.encodeJavaMIMEType(buttonMIME); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
101 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
102 |
//create a DataFlavor from the Encoded String native |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
103 |
test_flavor2 = SystemFlavorMap.decodeDataFlavor(test_encoded); |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
104 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
105 |
//create and initialize DataFlavor arrays |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
106 |
test_flavors_set = new DataFlavor[] {test_flavor1}; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
107 |
|
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
108 |
//create and initialize String native arrays |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
109 |
test_natives_set = new String[] {test_encoded}; |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
110 |
} |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
111 |
} |
2bea87828632
8048246: Move AWT_DnD/Clipboard/Automated functional tests to OpenJDK
yan
parents:
diff
changeset
|
112 |