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