/* * Copyright (c) 1998, 2016, 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. * * 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.
*/
/** * IntlTest is a base class for tests that can be run conveniently from * the command line as well as under the Java test harness. * <p> * Sub-classes implement a set of public void methods named "Test*" or * "test*" with no arguments. Each of these methods performs some * test. Test methods should indicate errors by calling either err() or * errln(). This will increment the errorCount field and may optionally * print a message to the log. Debugging information may also be added to * the log via the log and logln methods. These methods will add their * arguments to the log only if the test is being run in verbose mode.
*/ publicabstractclass IntlTest {
//------------------------------------------------------------------------ // Everything below here is boilerplate code that makes it possible // to add a new test by simply adding a method to an existing class. //------------------------------------------------------------------------
protected IntlTest() { // Populate testMethods with all the test methods.
Method[] methods = getClass().getDeclaredMethods(); for (Method method : methods) { if (Modifier.isPublic(method.getModifiers())
&& method.getReturnType() == void.class
&& method.getParameterCount() == 0) {
String name = method.getName(); if (name.length() > 4) { if (name.startsWith("Test") || name.startsWith("test")) {
testMethods.put(name, method);
}
}
}
}
}
protectedvoid run(String[] args) throws Exception
{ // Set up the log and reference streams. We use PrintWriters in order to // take advantage of character conversion. The JavaEsc converter will // convert Unicode outside the ASCII range to Java's \\uxxxx notation.
log = new PrintWriter(System.out, true);
// Parse the test arguments. They can be either the flag // "-verbose" or names of test methods. Create a list of // tests to be run.
List<Method> testsToRun = new ArrayList<>(args.length); for (String arg : args) { switch (arg) { case"-verbose":
verbose = true; break; case"-prompt":
prompt = true; break; case"-nothrow":
nothrow = true; break; case"-exitcode":
exitCode = true; break; default:
Method m = testMethods.get(arg); if (m == null) {
System.out.println("Method " + arg + ": not found");
usage(); return;
}
testsToRun.add(m); break;
}
}
// If no test method names were given explicitly, run them all. if (testsToRun.isEmpty()) {
testsToRun.addAll(testMethods.values());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.