Home | History | Annotate | Download | only in test
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /**
      5  *******************************************************************************
      6  * Copyright (C) 2001-2007, International Business Machines Corporation and    *
      7  * others. All Rights Reserved.                                                *
      8  *******************************************************************************
      9  */
     10 package android.icu.dev.test;
     11 
     12 import java.util.ArrayList;
     13 import java.util.Iterator;
     14 import java.util.List;
     15 
     16 import android.icu.dev.test.TestDataModule.DataMap;
     17 import android.icu.dev.test.TestDataModule.DataModuleFormatError;
     18 import android.icu.dev.test.TestDataModule.Factory;
     19 import android.icu.dev.test.TestDataModule.TestData;
     20 import android.icu.testsharding.MainTestShard;
     21 
     22 /**
     23  * Ray: An adapter class for TestDataMoule to make it like TestFmwk
     24  *
     25  * A convenience extension of TestFmwk for use by data module-driven tests.
     26  *
     27  * Tests can implement this if they make extensive use of information in a
     28  * TestDataModule.
     29  *
     30  * Subclasses can allow for test methods that don't use data from the module by
     31  * overriding validateMethod to return true for these methods. Tests are also
     32  * free to instantiate their own modules and run from them, though care should
     33  * be taken not to interfere with the methods in this class.
     34  *
     35  * See CollationTest for an example.
     36  */
     37 @MainTestShard
     38 public class ModuleTest {
     39     private ModuleTest() {
     40         // prevent construction
     41     }
     42 
     43     /**
     44      *
     45      * TestFmwk calls this before trying to run a suite of tests. The test suite
     46      * if valid if a module whose name is the name of this class + "Data" can be
     47      * opened. Subclasses can override this if there are different or additional
     48      * data required.
     49      */
     50 
     51     public static TestDataModule loadTestData(String baseName, String testName) throws DataModuleFormatError {
     52         return Factory.get(baseName, testName);
     53     }
     54 
     55     static TestData openTestData(TestDataModule module, String name) throws DataModuleFormatError {
     56         return module.getTestData(name);
     57     }
     58 
     59     public static class TestDataPair {
     60         public TestData td;
     61         public DataMap dm;
     62 
     63         public TestDataPair(TestData td, DataMap dm) {
     64             this.td = td;
     65             this.dm = dm;
     66         }
     67     }
     68 
     69     public static List<TestDataPair> getTestData(String moduleLocation, String moduleName) throws Exception {
     70         List<TestDataPair> list = new ArrayList<TestDataPair>();
     71 
     72         TestDataModule m = ModuleTest.loadTestData(moduleLocation, moduleName);
     73         Iterator<TestData> tIter = m.getTestDataIterator();
     74         while (tIter.hasNext()) {
     75             TestData t = tIter.next();
     76             for (Iterator siter = t.getSettingsIterator(); siter.hasNext();) {
     77                 DataMap settings = (DataMap) siter.next();
     78                 list.add(new TestDataPair(t, settings));
     79             }
     80         }
     81         return list;
     82     }
     83 }
     84