Path: blob/master/test/jdk/javax/accessibility/AccessibilityProvider/Load.java
41149 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.AWTError;24import java.awt.Toolkit;25import java.io.File;26import java.util.ArrayList;27import java.util.List;28import javax.accessibility.AccessibilityProvider;2930public class Load {3132public static void main(String[] args) {33// args[0]: "pass" or "fail" (the expected result)34// args[1]: "<first provider name>"35// args[2]: "<optional second provider name>"3637boolean passExpected = args[0].equals("pass");3839// Fill Set with provider names that were requested.40// The providers may or may not be available:41// - available: FooProvider, BarProvider42// - not available: NoProvider43List<String> requestedNames = new ArrayList<>();44for (int i = 1; i < args.length; ++i) {45requestedNames.add(args[i]);46}47// cleanup files from any prior run48for (String name : requestedNames) {49File f = new File(name + ".txt");50f.delete();51}52// Activate getDefaultToolkit which will in turn activate the providers53try {54Toolkit.getDefaultToolkit();55} catch (AWTError e) {56if (passExpected) {57throw new RuntimeException(e.getMessage());58}59}60// Toolkit.getDefaultToolkit() already went through all the service61// providers, loading and activating the requested ones, but now we need62// to see if they actually got activated.63// Go through the providers that were requested, for each one:64// If it was activated pass65// else fail (throw exception)66boolean failure = false;67String failingName = "";68for (String name : requestedNames) {69File f = new File(name + ".txt");70if (!f.exists()) {71failure = true;72failingName = name;73break;74}75} // if get to here, no issues, so try next provider76if (failure && passExpected) {77throw new RuntimeException(failingName + " was not activated");78}79if (!failure && !passExpected) {80String s = "Test passed but a failure was expected. ";81s += "The requested providers were:\n";82for (String name : requestedNames) {83s += (" " + name + "\n");84}85throw new RuntimeException(s);86}87}88}899091