mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-3842 Fix loading
X-SVN-Rev: 20158
This commit is contained in:
parent
81896bcea0
commit
d855976624
3 changed files with 77 additions and 88 deletions
|
@ -22,26 +22,31 @@ import com.ibm.icu.dev.test.TestDataModule.TestData;
|
|||
* Tests can implement this if they make extensive use of information in a
|
||||
* TestDataModule.
|
||||
*
|
||||
* The module should be openable using TestDataModule.open() passing in the
|
||||
* class name of this test + "Data". For example, a test named MyTest would have
|
||||
* a module named MyTestData. Each test method should also have a corresponding
|
||||
* test data in the module whose name matches the test method name.
|
||||
*
|
||||
* Subclasses can allow for test methods that don't use data from the modeul by
|
||||
* overriding validateMethod to return true for these methods. Tests are also
|
||||
* free to instantiate their own modules and run from them, though care should
|
||||
* be taken not to interfere with the methods in this class.
|
||||
*
|
||||
* See ModuleTestSample for an example.
|
||||
* See CollationTest for an example.
|
||||
*/
|
||||
public abstract class ModuleTest extends TestFmwk {
|
||||
private TestDataModule m;
|
||||
protected TestData t;
|
||||
|
||||
|
||||
protected TestData t = null;
|
||||
|
||||
private String localeName = null;
|
||||
|
||||
private String baseName = null;
|
||||
|
||||
abstract protected void processModules();
|
||||
|
||||
|
||||
protected ModuleTest(String baseName, String locName) {
|
||||
localeName = locName;
|
||||
this.baseName = baseName;
|
||||
}
|
||||
|
||||
protected Target getTargets(String targetName) {
|
||||
if (params.doMethods()) {
|
||||
if (params.doMethods()) {
|
||||
Target target = null;
|
||||
if (!validate()) {
|
||||
return null;
|
||||
|
@ -49,12 +54,13 @@ public abstract class ModuleTest extends TestFmwk {
|
|||
Iterator testData = m.getTestDataIterator();
|
||||
if (testData != null) {
|
||||
try {
|
||||
Method method = getClass().getMethod("processModules", null);
|
||||
Method method = getClass()
|
||||
.getMethod("processModules", null);
|
||||
while (testData.hasNext()) {
|
||||
target = new MethodTarget(((TestData)testData.next()).getName(), method).setNext(target);
|
||||
target = new MethodTarget(((TestData) testData.next())
|
||||
.getName(), method).setNext(target);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new IllegalStateException(e.getMessage());
|
||||
}
|
||||
|
@ -67,20 +73,14 @@ public abstract class ModuleTest extends TestFmwk {
|
|||
|
||||
/**
|
||||
*
|
||||
* TestFmwk calls this before trying to run a suite of tests.
|
||||
* The test suite if valid if a module whose name is the name of
|
||||
* this class + "Data" can be opened. Subclasses can override
|
||||
* this if there are different or additional data required.
|
||||
* TestFmwk calls this before trying to run a suite of tests. The test suite
|
||||
* if valid if a module whose name is the name of this class + "Data" can be
|
||||
* opened. Subclasses can override this if there are different or additional
|
||||
* data required.
|
||||
*/
|
||||
protected boolean validate() {
|
||||
t = null;
|
||||
String n = getClass().getName();
|
||||
String localename = "DataDriven" + n.substring(n.lastIndexOf('.') + 1);
|
||||
String baseName = "com/ibm/icu/dev/data/testdata/";
|
||||
|
||||
try {
|
||||
//m = Factory.get(getClass().getName()+"Data", this);
|
||||
m = Factory.get(baseName, localename);
|
||||
m = Factory.get(baseName, localeName);
|
||||
} catch (DataModuleFormatError e) {
|
||||
e.printStackTrace();
|
||||
m = null;
|
||||
|
@ -89,77 +89,78 @@ public abstract class ModuleTest extends TestFmwk {
|
|||
}
|
||||
|
||||
/**
|
||||
* TestFmwk calls this before trying to invoke a test method.
|
||||
* The method is valid if there is test data with the name of this
|
||||
* method in the module. Subclasses can override this to allow
|
||||
* for tests that do not require test data from the module, or
|
||||
* if there are different or additional data required.
|
||||
* TestFmwk calls this before trying to invoke a test method. The method is
|
||||
* valid if there is test data with the name of this method in the module.
|
||||
* Subclasses can override this to allow for tests that do not require test
|
||||
* data from the module, or if there are different or additional data
|
||||
* required.
|
||||
*/
|
||||
protected boolean validateMethod(String methodName) {
|
||||
return openTestData(methodName);
|
||||
return openTestData(methodName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of TestFmwk method to get the test suite description
|
||||
* from the DESCRIPTION field of the module info.
|
||||
* Override of TestFmwk method to get the test suite description from the
|
||||
* DESCRIPTION field of the module info.
|
||||
*/
|
||||
protected String getDescription() {
|
||||
DataMap info = moduleInfo();
|
||||
if (info != null) {
|
||||
// return info.getString(TestDataModule.DESCRIPTION);
|
||||
}
|
||||
return null;
|
||||
DataMap info = moduleInfo();
|
||||
if (info != null) {
|
||||
// return info.getString(TestDataModule.DESCRIPTION);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of TestFmwk method to get the test method description
|
||||
* from the DESCRIPTION field of the test info.
|
||||
* Override of TestFmwk method to get the test method description from the
|
||||
* DESCRIPTION field of the test info.
|
||||
*/
|
||||
protected String getMethodDescription(String methodName) {
|
||||
if (openTestData(methodName)) {
|
||||
DataMap info = testInfo();
|
||||
if (info != null) {
|
||||
// return info.getString(TestDataModule.DESCRIPTION);
|
||||
if (openTestData(methodName)) {
|
||||
DataMap info = testInfo();
|
||||
if (info != null) {
|
||||
// return info.getString(TestDataModule.DESCRIPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the test data in the module with the given name, and return
|
||||
* true if success. The current test is reset.
|
||||
* Open the test data in the module with the given name, and return true if
|
||||
* success. The current test is reset.
|
||||
*
|
||||
* @throws DataModuleFormatError
|
||||
*/
|
||||
protected boolean openTestData(String name){
|
||||
try {
|
||||
t = m == null ? null : m.getTestData(name);
|
||||
} catch (DataModuleFormatError e) {
|
||||
return false;
|
||||
}
|
||||
return t != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information on this module. Returns null if no module
|
||||
* open or no info for the module.
|
||||
*/
|
||||
private DataMap moduleInfo() {
|
||||
return m == null ? null : m.getInfo();
|
||||
protected boolean openTestData(String name) {
|
||||
try {
|
||||
t = m == null ? null : m.getTestData(name);
|
||||
} catch (DataModuleFormatError e) {
|
||||
return false;
|
||||
}
|
||||
return t != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information on this test. Returns null if no module
|
||||
* open or no test open or not info for this test.
|
||||
* Get information on this module. Returns null if no module open or no info
|
||||
* for the module.
|
||||
*/
|
||||
private DataMap moduleInfo() {
|
||||
return m == null ? null : m.getInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information on this test. Returns null if no module open or no test
|
||||
* open or not info for this test.
|
||||
*/
|
||||
private DataMap testInfo() {
|
||||
return t == null ? null : t.getInfo();
|
||||
return t == null ? null : t.getInfo();
|
||||
}
|
||||
|
||||
public void msg(String message, int level, boolean incCount, boolean newln) {
|
||||
if (level == ERR && t != null) {
|
||||
// t.stopIteration();
|
||||
//t.stopIteration();
|
||||
}
|
||||
super.msg(message, level, incCount, newln);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -24,31 +24,16 @@ import com.ibm.icu.text.RawCollationKey;
|
|||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
|
||||
public class CollationTest extends ModuleTest
|
||||
{
|
||||
public class CollationTest extends ModuleTest{
|
||||
// public methods --------------------------------------------------------
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
public static void main(String[] args) throws Exception{
|
||||
new CollationTest().run(args);
|
||||
/* CollationTest test = new CollationTest();
|
||||
if (test.validate()) {
|
||||
test.TestCIgnorableContraction();
|
||||
}*/
|
||||
}
|
||||
|
||||
// public CollationTest() {
|
||||
// super("processModules");
|
||||
// }
|
||||
|
||||
// Want to be static, why super class not?
|
||||
private class DataDrivenTarget extends TestFmwk.Target{
|
||||
public DataDrivenTarget(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public CollationTest() {
|
||||
super("com/ibm/icu/dev/data/testdata/", "DataDrivenCollationTest");
|
||||
}
|
||||
|
||||
|
||||
public void processModules() {
|
||||
for (Iterator iter = t.getSettingsIterator(); iter.hasNext();) {
|
||||
|
@ -188,7 +173,7 @@ public class CollationTest extends ModuleTest
|
|||
}catch (Exception e) {
|
||||
errln("Error creating collator for locale " + locale);
|
||||
}
|
||||
logln("Testing collator for locale %s\n" + locale);
|
||||
logln("Testing collator for locale " + locale);
|
||||
processSetting2(settings, col);
|
||||
}
|
||||
String rules = settings.getString("Rules");
|
||||
|
|
|
@ -12,6 +12,9 @@ public class ModuleTestSample extends ModuleTest {
|
|||
public static void main(String[] args) throws Exception {
|
||||
new ModuleTestSample().run(args);
|
||||
}
|
||||
ModuleTestSample(){
|
||||
super("com/ibm/icu/dev/data/testdata/", "Test");
|
||||
}
|
||||
|
||||
// // standard loop, settings and cases
|
||||
// public void Test01() {
|
||||
|
|
Loading…
Add table
Reference in a new issue