1 /* 2 * Copyright (c) 2001, 2015, 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 * @modules java.datatransfer 40 * @run main InvalidMapArgumentsTest 41 */ 42 43 public class InvalidMapArgumentsTest { 44 45 SystemFlavorMap flavorMap; 46 String test_nat; 47 String[] test_natives; 48 DataFlavor test_flav; 49 DataFlavor[] test_flavors; 50 51 public static void main (String[] args){ 52 new InvalidMapArgumentsTest().doTest(); 53 } 54 55 public void doTest (){ 56 //Get things going. Request focus, set size, et cetera 57 initMappings(); 58 59 // Test for combinations of null values for 60 // addFlavorForUnencodedNative(String nat, DataFlavor flav) 61 addFlavorForUnencodedNativeTest(null, null, "both String nat and DataFlavor flav set to null. "); 62 addFlavorForUnencodedNativeTest(null, test_flav, "String nat set to null. "); 63 addFlavorForUnencodedNativeTest(test_nat, null, "DataFlavor flav set to null. "); 64 65 66 // Test for combinations of null values for 67 // addUnencodedNativeForFlavor(DataFlavor flav, String nat) 68 addUnencodedNativeForFlavorTest(null, null, "both DataFlavor flav and String nat set to null. "); 69 addUnencodedNativeForFlavorTest(null, test_nat, "DataFlavor flav set to null. "); 70 addUnencodedNativeForFlavorTest(test_flav, null, "String nat set to null. "); 71 72 73 // Test for combinations of null values for 74 // setNativesForFlavor(DataFlavor flav, String[] natives) 75 setNativesForFlavorTest(null, null, "both DataFlavor flav and String[] natives set to null. "); 76 setNativesForFlavorTest(null, test_natives, "DataFlavor flav set to null. "); 77 setNativesForFlavorTest(test_flav, null, "String[] natives set to null. "); 78 79 80 // Test for combinations of null values for 81 // setFlavorsForNative(String nat, DataFlavor[] flavors) 82 setFlavorsForNativeTest(null, null, "both String nat and DataFlavor[] flavors set to null. "); 83 setFlavorsForNativeTest(null, test_flavors, "String nat set to null. "); 84 setFlavorsForNativeTest(test_nat, null, "DataFlavor[] flavors set to null. "); 85 } 86 87 public void initMappings() { 88 //initialize mapping variables used in this test 89 flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap(); 90 91 //create a DataFlavor with valid parameters (mimeType, humanPresentableName) 92 test_flav = new DataFlavor("text/plain; charset=ascii","ASCII Flavor"); 93 94 //create a String native 95 test_nat = "TEXT_TEST"; 96 97 //create a DataFlavor array 98 test_flavors = new DataFlavor[] {test_flav}; 99 100 //create a String native array 101 test_natives = new String[] {test_nat}; 102 } 103 104 public void setNativesForFlavorTest(DataFlavor flav, String[] natives, String errmsg) { 105 try{ 106 flavorMap.setNativesForFlavor(flav, natives); 107 throw new RuntimeException("NullPointerException is not thrown for method "+ 108 "setNativesForFlavor with "+errmsg); 109 } catch (NullPointerException e) { 110 } 111 } 112 113 public void setFlavorsForNativeTest(String nat, DataFlavor[] flavors, String errmsg) { 114 try{ 115 flavorMap.setFlavorsForNative(nat, flavors); 116 throw new RuntimeException("NullPointerException is not thrown for method "+ 117 "setFlavorsForNative with "+errmsg); 118 } catch (NullPointerException e) { 119 } 120 } 121 122 public void addFlavorForUnencodedNativeTest(String nat, DataFlavor flav, String errmsg) { 123 try{ 124 flavorMap.addFlavorForUnencodedNative(nat, flav); 125 throw new RuntimeException("NullPointerException is not thrown for method "+ 126 "addFlavorForUnencodedNative with "+errmsg); 127 } catch (NullPointerException e) { 128 } 129 } 130 131 public void addUnencodedNativeForFlavorTest(DataFlavor flav, String nat, String errmsg) { 132 try{ 133 flavorMap.addUnencodedNativeForFlavor(flav, nat); 134 throw new RuntimeException("NullPointerException is not thrown for method "+ 135 "addUnencodedNativeForFlavor with "+errmsg); 136 } catch (NullPointerException e) { 137 } 138 } 139 } 140