1 /* 2 * Copyright (c) 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.awt.AWTError; 25 import java.awt.Toolkit; 26 import java.io.File; 27 import java.util.ArrayList; 28 import java.util.List; 29 import javax.accessibility.AccessibilityProvider; 30 31 public class Load { 32 33 public static void main(String[] args) { 34 // args[0]: "pass" or "fail" (the expected result) 35 // args[1]: "<first provider name>" 36 // args[2]: "<optional second provider name>" 37 38 boolean passExpected = args[0].equals("pass"); 39 40 // Fill Set with provider names that were requested. 41 // The providers may or may not be available: 42 // - available: FooProvider, BarProvider 43 // - not available: NoProvider 44 List<String> requestedNames = new ArrayList<>(); 45 for (int i = 1; i < args.length; ++i) { 46 requestedNames.add(args[i]); 47 } 48 // cleanup files from any prior run 49 for (String name : requestedNames) { 50 File f = new File(name + ".txt"); 51 f.delete(); 52 } 53 // Activate getDefaultToolkit which will in turn activate the providers 54 try { 55 Toolkit.getDefaultToolkit(); 56 } catch (AWTError e) { 57 if (passExpected) { 58 throw new RuntimeException(e.getMessage()); 59 } 60 } 61 // Toolkit.getDefaultToolkit() already went through all the service 62 // providers, loading and activating the requested ones, but now we need 63 // to see if they actually got activated. 64 // Go through the providers that were requested, for each one: 65 // If it was activated pass 66 // else fail (throw exception) 67 boolean failure = false; 68 String failingName = ""; 69 for (String name : requestedNames) { 70 File f = new File(name + ".txt"); 71 if (!f.exists()) { 72 failure = true; 73 failingName = name; 74 break; 75 } 76 } // if get to here, no issues, so try next provider 77 if (failure && passExpected) { 78 throw new RuntimeException(failingName + " was not activated"); 79 } 80 if (!failure && !passExpected) { 81 String s = "Test passed but a failure was expected. "; 82 s += "The requested providers were:\n"; 83 for (String name : requestedNames) { 84 s += (" " + name + "\n"); 85 } 86 throw new RuntimeException(s); 87 } 88 } 89 }