/* * 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. */ import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Map; import java.util.LinkedHashMap; import java.util.List; /** * IntlTest is a base class for tests that can be run conveniently from * the command line as well as under the Java test harness. *
* 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.
*/
public abstract class 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);
}
}
}
}
}
protected void 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