]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/ResourceModule.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / ResourceModule.java
old mode 100755 (executable)
new mode 100644 (file)
index 00a832e..79b4d13
-//##header\r
-/*\r
- **********************************************************************\r
- * Copyright (c) 2006-2009, International Business Machines\r
- * Corporation and others.  All Rights Reserved.\r
- **********************************************************************\r
- * Created on 2006-4-21\r
- */\r
-package com.ibm.icu.dev.test;\r
-\r
-import java.util.Arrays;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.MissingResourceException;\r
-import java.util.NoSuchElementException;\r
-\r
-import com.ibm.icu.impl.ICUResourceBundle;\r
-import com.ibm.icu.util.UResourceBundle;\r
-import com.ibm.icu.util.UResourceBundleIterator;\r
-import com.ibm.icu.util.UResourceTypeMismatchException;\r
-\r
-/**\r
- * Represents a collection of test data described in a UResourceBoundle file. \r
- * \r
- * The root of the UResourceBoundle file is a table resource, and it has one \r
- * Info and one TestData sub-resources. The Info describes the data module\r
- * itself. The TestData, which is a table resource, has a collection of test \r
- * data.\r
- * \r
- * The test data is a named table resource which has Info, Settings, Headers,\r
- * and Cases sub-resources. \r
- * \r
- * <pre>\r
- * DataModule:table(nofallback){ \r
- *   Info:table {} \r
- *   TestData:table {\r
- *     entry_name:table{\r
- *       Info:table{}\r
- *       Settings:array{}\r
- *       Headers:array{}\r
- *       Cases:array{}\r
- *     }\r
- *   } \r
- * }\r
- * </pre>\r
- * \r
- * The test data is expected to be fed to test code by following sequence \r
- *\r
- *   for each setting in Setting{\r
- *       prepare the setting\r
- *     for each test data in Cases{\r
- *       perform the test\r
- *     }\r
- *   }\r
- * \r
- * For detail of the specification, please refer to the code. The code is \r
- * initially ported from "icu4c/source/tools/ctestfw/unicode/tstdtmod.h"\r
- * and should be maintained parallelly.\r
- * \r
- * @author Raymond Yang\r
- */\r
-class ResourceModule implements TestDataModule {\r
-    private static final String INFO = "Info";\r
-//    private static final String DESCRIPTION = "Description";\r
-//    private static final String LONG_DESCRIPTION = "LongDescription";\r
-    private static final String TEST_DATA = "TestData";\r
-    private static final String SETTINGS = "Settings";\r
-    private static final String HEADER = "Headers";\r
-    private static final String DATA = "Cases";\r
-\r
-    \r
-    UResourceBundle res;\r
-    UResourceBundle info;\r
-    UResourceBundle defaultHeader;\r
-    UResourceBundle testData;\r
-    \r
-    ResourceModule(String baseName, String localeName) throws DataModuleFormatError{\r
-\r
-        res = (UResourceBundle) UResourceBundle.getBundleInstance(baseName, localeName);\r
-        info = getFromTable(res, INFO, UResourceBundle.TABLE);\r
-        testData = getFromTable(res, TEST_DATA, UResourceBundle.TABLE);\r
-\r
-        try {\r
-            // unfortunately, actually, data can be either ARRAY or STRING\r
-            defaultHeader = getFromTable(info, HEADER, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});\r
-        } catch (MissingResourceException e){\r
-            defaultHeader = null;\r
-        }\r
-    }\r
-\r
-    public String getName() {\r
-        return res.getKey();\r
-    }\r
-\r
-    public DataMap getInfo() {\r
-        return new UTableResource(info);\r
-    }\r
-\r
-    public TestData getTestData(String testName) throws DataModuleFormatError {\r
-        return new UResourceTestData(defaultHeader, testData.get(testName));\r
-    }\r
-\r
-    public Iterator getTestDataIterator() {\r
-        return new IteratorAdapter(testData){\r
-            protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {\r
-                return new UResourceTestData(defaultHeader, nextRes);\r
-            }\r
-        };\r
-    }\r
-\r
-    /**\r
-     * To make UResourceBundleIterator works like Iterator\r
-     * and return various data-driven test object for next() call\r
-     * \r
-     * @author Raymond Yang\r
-     */\r
-    private abstract static class IteratorAdapter implements Iterator{\r
-        private UResourceBundle res;\r
-        private UResourceBundleIterator itr;\r
-        private Object preparedNextElement = null;\r
-        // fix a strange behavior for UResourceBundleIterator for \r
-        // UResourceBundle.STRING. It support hasNext(), but does \r
-        // not support next() now. \r
-        // \r
-        // Use the iterated resource itself as the result from next() call\r
-        private boolean isStrRes = false;\r
-        private boolean isStrResPrepared = false; // for STRING resouce, we only prepare once\r
-\r
-        IteratorAdapter(UResourceBundle theRes) {\r
-            assert_not (theRes == null);\r
-            res = theRes;\r
-            itr = ((ICUResourceBundle)res).getIterator();\r
-            isStrRes = res.getType() == UResourceBundle.STRING;\r
-        }\r
-        \r
-        public void remove() {\r
-            // do nothing\r
-        }\r
-\r
-        private boolean hasNextForStrRes(){\r
-            assert_is (isStrRes);\r
-            assert_not (!isStrResPrepared && preparedNextElement != null);\r
-            if (isStrResPrepared && preparedNextElement != null) return true;\r
-            if (isStrResPrepared && preparedNextElement == null) return false; // only prepare once\r
-            assert_is (!isStrResPrepared && preparedNextElement == null);\r
-            \r
-            try {\r
-                preparedNextElement = prepareNext(res);\r
-                assert_not (preparedNextElement == null, "prepareNext() should not return null");\r
-                isStrResPrepared = true; // toggle the tag\r
-                return true;\r
-            } catch (DataModuleFormatError e) {\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//##                throw new RuntimeException(e.getMessage());\r
-//#else\r
-                throw new RuntimeException(e.getMessage(),e);\r
-//#endif\r
-            }            \r
-        }\r
-        public boolean hasNext() {\r
-            if (isStrRes) return hasNextForStrRes();\r
-            \r
-            if (preparedNextElement != null) return true;\r
-            UResourceBundle t = null;\r
-            if (itr.hasNext()) {\r
-                // Notice, other RuntimeException may be throwed\r
-                t = itr.next();\r
-            } else {\r
-                return false;\r
-            }\r
-\r
-            try {\r
-                preparedNextElement = prepareNext(t);\r
-                assert_not (preparedNextElement == null, "prepareNext() should not return null");\r
-                return true;\r
-            } catch (DataModuleFormatError e) {\r
-                // Sadly, we throw RuntimeException also\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//##                throw new RuntimeException(e.getMessage());\r
-//#else\r
-                throw new RuntimeException(e.getMessage(),e);\r
-//#endif\r
-            }\r
-        }\r
-\r
-        public Object next(){\r
-            if (hasNext()) {\r
-                Object t = preparedNextElement;\r
-                preparedNextElement = null;\r
-                return t;\r
-            } else {\r
-                throw new NoSuchElementException();\r
-            }\r
-        }\r
-        /**\r
-         * To prepare data-driven test object for next() call, should not return null\r
-         */\r
-        abstract protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError;\r
-    }\r
-    \r
-    \r
-    /**\r
-     * Avoid use Java 1.4 language new assert keyword \r
-     */\r
-    static void assert_is(boolean eq, String msg){\r
-        if (!eq) throw new Error("test code itself has error: " + msg);\r
-    }\r
-    static void assert_is(boolean eq){\r
-        if (!eq) throw new Error("test code itself has error.");\r
-    }\r
-    static void assert_not(boolean eq, String msg){\r
-        assert_is(!eq, msg);\r
-    }\r
-    static void assert_not(boolean eq){\r
-        assert_is(!eq);\r
-    }\r
-            \r
-    /**\r
-     * Internal helper function to get resource with following add-on \r
-     * \r
-     * 1. Assert the returned resource is never null.\r
-     * 2. Check the type of resource. \r
-     * \r
-     * The UResourceTypeMismatchException for various get() method is a \r
-     * RuntimeException which can be silently bypassed. This behavior is a \r
-     * trouble. One purpose of the class is to enforce format checking for \r
-     * resource file. We don't want to the exceptions are silently bypassed \r
-     * and spreaded to our customer's code. \r
-     * \r
-     * Notice, the MissingResourceException for get() method is also a\r
-     * RuntimeException. The caller functions should avoid sepread the execption\r
-     * silently also. The behavior is modified because some resource are \r
-     * optional and can be missed.\r
-     */\r
-    static UResourceBundle getFromTable(UResourceBundle res, String key, int expResType) throws DataModuleFormatError{\r
-        return getFromTable(res, key, new int[]{expResType});\r
-    }\r
-    \r
-    static UResourceBundle getFromTable(UResourceBundle res, String key, int[] expResTypes) throws DataModuleFormatError{\r
-        assert_is (res != null && key != null && res.getType() == UResourceBundle.TABLE);\r
-        UResourceBundle t = res.get(key); \r
-      \r
-        assert_not (t ==null);\r
-        int type = t.getType();\r
-        Arrays.sort(expResTypes);\r
-        if (Arrays.binarySearch(expResTypes, type) >= 0) {\r
-            return t;\r
-        } else {\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//##            throw new DataModuleFormatError("Actual type " + t.getType() + " != expected types " + expResTypes + ".");\r
-//#else\r
-            throw new DataModuleFormatError(new UResourceTypeMismatchException("Actual type " + t.getType() + " != expected types " + expResTypes + "."));\r
-//#endif\r
-        }\r
-    }\r
-    \r
-    /**\r
-     * Unfortunately, UResourceBundle is unable to treat one string as string array.\r
-     * This function return a String[] from UResourceBundle, regardless it is an array or a string \r
-     */\r
-    static String[] getStringArrayHelper(UResourceBundle res, String key) throws DataModuleFormatError{\r
-        UResourceBundle t = getFromTable(res, key, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});\r
-        return getStringArrayHelper(t);\r
-    }\r
-\r
-    static String[] getStringArrayHelper(UResourceBundle res) throws DataModuleFormatError{\r
-        try{\r
-            int type = res.getType();\r
-            switch (type) {\r
-            case UResourceBundle.ARRAY:\r
-                return res.getStringArray();\r
-            case UResourceBundle.STRING:\r
-                return new String[]{res.getString()};\r
-            default:\r
-                throw new UResourceTypeMismatchException("Only accept ARRAY and STRING types.");\r
-            }\r
-        } catch (UResourceTypeMismatchException e){\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//##            throw new DataModuleFormatError(e.getMessage());\r
-//#else\r
-            throw new DataModuleFormatError(e);\r
-//#endif\r
-        }\r
-    }\r
-    \r
-    public static void main(String[] args){\r
-        try {\r
-            TestDataModule m = new ResourceModule("com/ibm/icu/dev/data/testdata/","DataDrivenCollationTest");\r
-        System.out.println("hello: " + m.getName());\r
-        m.getInfo();\r
-        m.getTestDataIterator();\r
-        } catch (DataModuleFormatError e) {\r
-            // TODO Auto-generated catch block\r
-            System.out.println("???");\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-\r
-    private static class UResourceTestData implements TestData{\r
-        private UResourceBundle res;\r
-        private UResourceBundle info;\r
-        private UResourceBundle settings; \r
-        private UResourceBundle header;\r
-        private UResourceBundle data;\r
-\r
-        UResourceTestData(UResourceBundle defaultHeader, UResourceBundle theRes) throws DataModuleFormatError{\r
-            \r
-            assert_is (theRes != null && theRes.getType() == UResourceBundle.TABLE);\r
-            res = theRes;\r
-            // unfortunately, actually, data can be either ARRAY or STRING\r
-            data = getFromTable(res, DATA, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});\r
-       \r
-\r
-            \r
-            try {\r
-                // unfortunately, actually, data can be either ARRAY or STRING\r
-                header = getFromTable(res, HEADER, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});\r
-            } catch (MissingResourceException e){\r
-                if (defaultHeader == null) {\r
-                    throw new DataModuleFormatError("Unable to find a header for test data '" + res.getKey() + "' and no default header exist.");\r
-                } else {\r
-                    header = defaultHeader;\r
-                }\r
-            }\r
-         try{\r
-                settings = getFromTable(res, SETTINGS, UResourceBundle.ARRAY);\r
-                info = getFromTable(res, INFO, UResourceBundle.TABLE);\r
-            } catch (MissingResourceException e){\r
-                // do nothing, left them null;\r
-                settings = data;\r
-            }\r
-        }\r
-        \r
-        public String getName() {\r
-            return res.getKey();\r
-        }\r
-\r
-        public DataMap getInfo() {\r
-            return info == null ? null : new UTableResource(info);\r
-        }\r
-\r
-        public Iterator getSettingsIterator() {\r
-            assert_is (settings.getType() == UResourceBundle.ARRAY);\r
-            return new IteratorAdapter(settings){\r
-                protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {\r
-                    return new UTableResource(nextRes);\r
-                }\r
-            };\r
-        }\r
-\r
-        public Iterator getDataIterator() {\r
-            // unfortunately,\r
-            assert_is (data.getType() == UResourceBundle.ARRAY \r
-                 || data.getType() == UResourceBundle.STRING);\r
-            return new IteratorAdapter(data){\r
-                protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {\r
-                    return new UArrayResource(header, nextRes);\r
-                }\r
-            };\r
-        }\r
-    }\r
-        \r
-    private static class UTableResource implements DataMap{\r
-        private UResourceBundle res;\r
-\r
-        UTableResource(UResourceBundle theRes){\r
-            res = theRes;\r
-        }\r
-        public String getString(String key) {\r
-            String t;\r
-            try{\r
-                t = res.getString(key);\r
-            } catch (MissingResourceException e){\r
-                t = null;\r
-            }\r
-            return t;\r
-        }\r
-         public Object getObject(String key) {\r
-            \r
-            return res.get(key);\r
-        }\r
-    }\r
-    \r
-    private static class UArrayResource implements DataMap{\r
-        private Map theMap; \r
-        UArrayResource(UResourceBundle theHeader, UResourceBundle theData) throws DataModuleFormatError{\r
-            assert_is (theHeader != null && theData != null);\r
-            String[] header;\r
-         \r
-            header = getStringArrayHelper(theHeader);\r
-            if (theData.getSize() != header.length) \r
-                throw new DataModuleFormatError("The count of Header and Data is mismatch.");\r
-            theMap = new HashMap();\r
-            for (int i = 0; i < header.length; i++) {\r
-                if(theData.getType()==UResourceBundle.ARRAY){\r
-                    theMap.put(header[i], theData.get(i));\r
-                }else if(theData.getType()==UResourceBundle.STRING){\r
-                    theMap.put(header[i], theData.getString());\r
-                }else{\r
-                    throw new DataModuleFormatError("Did not get the expected data!");                   \r
-                }\r
-            }\r
-            \r
-        }\r
-        \r
-        public String getString(String key) {\r
-            Object o = theMap.get(key);\r
-            UResourceBundle rb;\r
-            if(o instanceof UResourceBundle) {\r
-                // unpack ResourceBundle strings\r
-                rb = (UResourceBundle)o;\r
-                return rb.getString();\r
-            }\r
-            return (String)o;\r
-        }\r
-        public Object getObject(String key) {\r
-            return theMap.get(key);\r
-        }\r
-    }\r
-}\r
+//##header J2SE15
+/*
+ **********************************************************************
+ * Copyright (c) 2006-2009, International Business Machines
+ * Corporation and others.  All Rights Reserved.
+ **********************************************************************
+ * Created on 2006-4-21
+ */
+package com.ibm.icu.dev.test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.NoSuchElementException;
+
+import com.ibm.icu.impl.ICUResourceBundle;
+import com.ibm.icu.util.UResourceBundle;
+import com.ibm.icu.util.UResourceBundleIterator;
+import com.ibm.icu.util.UResourceTypeMismatchException;
+
+/**
+ * Represents a collection of test data described in a UResourceBoundle file. 
+ * 
+ * The root of the UResourceBoundle file is a table resource, and it has one 
+ * Info and one TestData sub-resources. The Info describes the data module
+ * itself. The TestData, which is a table resource, has a collection of test 
+ * data.
+ * 
+ * The test data is a named table resource which has Info, Settings, Headers,
+ * and Cases sub-resources. 
+ * 
+ * <pre>
+ * DataModule:table(nofallback){ 
+ *   Info:table {} 
+ *   TestData:table {
+ *     entry_name:table{
+ *       Info:table{}
+ *       Settings:array{}
+ *       Headers:array{}
+ *       Cases:array{}
+ *     }
+ *   } 
+ * }
+ * </pre>
+ * 
+ * The test data is expected to be fed to test code by following sequence 
+ *
+ *   for each setting in Setting{
+ *       prepare the setting
+ *     for each test data in Cases{
+ *       perform the test
+ *     }
+ *   }
+ * 
+ * For detail of the specification, please refer to the code. The code is 
+ * initially ported from "icu4c/source/tools/ctestfw/unicode/tstdtmod.h"
+ * and should be maintained parallelly.
+ * 
+ * @author Raymond Yang
+ */
+class ResourceModule implements TestDataModule {
+    private static final String INFO = "Info";
+//    private static final String DESCRIPTION = "Description";
+//    private static final String LONG_DESCRIPTION = "LongDescription";
+    private static final String TEST_DATA = "TestData";
+    private static final String SETTINGS = "Settings";
+    private static final String HEADER = "Headers";
+    private static final String DATA = "Cases";
+
+    
+    UResourceBundle res;
+    UResourceBundle info;
+    UResourceBundle defaultHeader;
+    UResourceBundle testData;
+    
+    ResourceModule(String baseName, String localeName) throws DataModuleFormatError{
+
+        res = (UResourceBundle) UResourceBundle.getBundleInstance(baseName, localeName);
+        info = getFromTable(res, INFO, UResourceBundle.TABLE);
+        testData = getFromTable(res, TEST_DATA, UResourceBundle.TABLE);
+
+        try {
+            // unfortunately, actually, data can be either ARRAY or STRING
+            defaultHeader = getFromTable(info, HEADER, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
+        } catch (MissingResourceException e){
+            defaultHeader = null;
+        }
+    }
+
+    public String getName() {
+        return res.getKey();
+    }
+
+    public DataMap getInfo() {
+        return new UTableResource(info);
+    }
+
+    public TestData getTestData(String testName) throws DataModuleFormatError {
+        return new UResourceTestData(defaultHeader, testData.get(testName));
+    }
+
+    public Iterator getTestDataIterator() {
+        return new IteratorAdapter(testData){
+            protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
+                return new UResourceTestData(defaultHeader, nextRes);
+            }
+        };
+    }
+
+    /**
+     * To make UResourceBundleIterator works like Iterator
+     * and return various data-driven test object for next() call
+     * 
+     * @author Raymond Yang
+     */
+    private abstract static class IteratorAdapter implements Iterator{
+        private UResourceBundle res;
+        private UResourceBundleIterator itr;
+        private Object preparedNextElement = null;
+        // fix a strange behavior for UResourceBundleIterator for 
+        // UResourceBundle.STRING. It support hasNext(), but does 
+        // not support next() now. 
+        // 
+        // Use the iterated resource itself as the result from next() call
+        private boolean isStrRes = false;
+        private boolean isStrResPrepared = false; // for STRING resouce, we only prepare once
+
+        IteratorAdapter(UResourceBundle theRes) {
+            assert_not (theRes == null);
+            res = theRes;
+            itr = ((ICUResourceBundle)res).getIterator();
+            isStrRes = res.getType() == UResourceBundle.STRING;
+        }
+        
+        public void remove() {
+            // do nothing
+        }
+
+        private boolean hasNextForStrRes(){
+            assert_is (isStrRes);
+            assert_not (!isStrResPrepared && preparedNextElement != null);
+            if (isStrResPrepared && preparedNextElement != null) return true;
+            if (isStrResPrepared && preparedNextElement == null) return false; // only prepare once
+            assert_is (!isStrResPrepared && preparedNextElement == null);
+            
+            try {
+                preparedNextElement = prepareNext(res);
+                assert_not (preparedNextElement == null, "prepareNext() should not return null");
+                isStrResPrepared = true; // toggle the tag
+                return true;
+            } catch (DataModuleFormatError e) {
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//##                throw new RuntimeException(e.getMessage());
+//#else
+                throw new RuntimeException(e.getMessage(),e);
+//#endif
+            }            
+        }
+        public boolean hasNext() {
+            if (isStrRes) return hasNextForStrRes();
+            
+            if (preparedNextElement != null) return true;
+            UResourceBundle t = null;
+            if (itr.hasNext()) {
+                // Notice, other RuntimeException may be throwed
+                t = itr.next();
+            } else {
+                return false;
+            }
+
+            try {
+                preparedNextElement = prepareNext(t);
+                assert_not (preparedNextElement == null, "prepareNext() should not return null");
+                return true;
+            } catch (DataModuleFormatError e) {
+                // Sadly, we throw RuntimeException also
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//##                throw new RuntimeException(e.getMessage());
+//#else
+                throw new RuntimeException(e.getMessage(),e);
+//#endif
+            }
+        }
+
+        public Object next(){
+            if (hasNext()) {
+                Object t = preparedNextElement;
+                preparedNextElement = null;
+                return t;
+            } else {
+                throw new NoSuchElementException();
+            }
+        }
+        /**
+         * To prepare data-driven test object for next() call, should not return null
+         */
+        abstract protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError;
+    }
+    
+    
+    /**
+     * Avoid use Java 1.4 language new assert keyword 
+     */
+    static void assert_is(boolean eq, String msg){
+        if (!eq) throw new Error("test code itself has error: " + msg);
+    }
+    static void assert_is(boolean eq){
+        if (!eq) throw new Error("test code itself has error.");
+    }
+    static void assert_not(boolean eq, String msg){
+        assert_is(!eq, msg);
+    }
+    static void assert_not(boolean eq){
+        assert_is(!eq);
+    }
+            
+    /**
+     * Internal helper function to get resource with following add-on 
+     * 
+     * 1. Assert the returned resource is never null.
+     * 2. Check the type of resource. 
+     * 
+     * The UResourceTypeMismatchException for various get() method is a 
+     * RuntimeException which can be silently bypassed. This behavior is a 
+     * trouble. One purpose of the class is to enforce format checking for 
+     * resource file. We don't want to the exceptions are silently bypassed 
+     * and spreaded to our customer's code. 
+     * 
+     * Notice, the MissingResourceException for get() method is also a
+     * RuntimeException. The caller functions should avoid sepread the execption
+     * silently also. The behavior is modified because some resource are 
+     * optional and can be missed.
+     */
+    static UResourceBundle getFromTable(UResourceBundle res, String key, int expResType) throws DataModuleFormatError{
+        return getFromTable(res, key, new int[]{expResType});
+    }
+    
+    static UResourceBundle getFromTable(UResourceBundle res, String key, int[] expResTypes) throws DataModuleFormatError{
+        assert_is (res != null && key != null && res.getType() == UResourceBundle.TABLE);
+        UResourceBundle t = res.get(key); 
+      
+        assert_not (t ==null);
+        int type = t.getType();
+        Arrays.sort(expResTypes);
+        if (Arrays.binarySearch(expResTypes, type) >= 0) {
+            return t;
+        } else {
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//##            throw new DataModuleFormatError("Actual type " + t.getType() + " != expected types " + expResTypes + ".");
+//#else
+            throw new DataModuleFormatError(new UResourceTypeMismatchException("Actual type " + t.getType() + " != expected types " + expResTypes + "."));
+//#endif
+        }
+    }
+    
+    /**
+     * Unfortunately, UResourceBundle is unable to treat one string as string array.
+     * This function return a String[] from UResourceBundle, regardless it is an array or a string 
+     */
+    static String[] getStringArrayHelper(UResourceBundle res, String key) throws DataModuleFormatError{
+        UResourceBundle t = getFromTable(res, key, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
+        return getStringArrayHelper(t);
+    }
+
+    static String[] getStringArrayHelper(UResourceBundle res) throws DataModuleFormatError{
+        try{
+            int type = res.getType();
+            switch (type) {
+            case UResourceBundle.ARRAY:
+                return res.getStringArray();
+            case UResourceBundle.STRING:
+                return new String[]{res.getString()};
+            default:
+                throw new UResourceTypeMismatchException("Only accept ARRAY and STRING types.");
+            }
+        } catch (UResourceTypeMismatchException e){
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//##            throw new DataModuleFormatError(e.getMessage());
+//#else
+            throw new DataModuleFormatError(e);
+//#endif
+        }
+    }
+    
+    public static void main(String[] args){
+        try {
+            TestDataModule m = new ResourceModule("com/ibm/icu/dev/data/testdata/","DataDrivenCollationTest");
+        System.out.println("hello: " + m.getName());
+        m.getInfo();
+        m.getTestDataIterator();
+        } catch (DataModuleFormatError e) {
+            // TODO Auto-generated catch block
+            System.out.println("???");
+            e.printStackTrace();
+        }
+    }
+
+    private static class UResourceTestData implements TestData{
+        private UResourceBundle res;
+        private UResourceBundle info;
+        private UResourceBundle settings; 
+        private UResourceBundle header;
+        private UResourceBundle data;
+
+        UResourceTestData(UResourceBundle defaultHeader, UResourceBundle theRes) throws DataModuleFormatError{
+            
+            assert_is (theRes != null && theRes.getType() == UResourceBundle.TABLE);
+            res = theRes;
+            // unfortunately, actually, data can be either ARRAY or STRING
+            data = getFromTable(res, DATA, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
+       
+
+            
+            try {
+                // unfortunately, actually, data can be either ARRAY or STRING
+                header = getFromTable(res, HEADER, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
+            } catch (MissingResourceException e){
+                if (defaultHeader == null) {
+                    throw new DataModuleFormatError("Unable to find a header for test data '" + res.getKey() + "' and no default header exist.");
+                } else {
+                    header = defaultHeader;
+                }
+            }
+         try{
+                settings = getFromTable(res, SETTINGS, UResourceBundle.ARRAY);
+                info = getFromTable(res, INFO, UResourceBundle.TABLE);
+            } catch (MissingResourceException e){
+                // do nothing, left them null;
+                settings = data;
+            }
+        }
+        
+        public String getName() {
+            return res.getKey();
+        }
+
+        public DataMap getInfo() {
+            return info == null ? null : new UTableResource(info);
+        }
+
+        public Iterator getSettingsIterator() {
+            assert_is (settings.getType() == UResourceBundle.ARRAY);
+            return new IteratorAdapter(settings){
+                protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
+                    return new UTableResource(nextRes);
+                }
+            };
+        }
+
+        public Iterator getDataIterator() {
+            // unfortunately,
+            assert_is (data.getType() == UResourceBundle.ARRAY 
+                 || data.getType() == UResourceBundle.STRING);
+            return new IteratorAdapter(data){
+                protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
+                    return new UArrayResource(header, nextRes);
+                }
+            };
+        }
+    }
+        
+    private static class UTableResource implements DataMap{
+        private UResourceBundle res;
+
+        UTableResource(UResourceBundle theRes){
+            res = theRes;
+        }
+        public String getString(String key) {
+            String t;
+            try{
+                t = res.getString(key);
+            } catch (MissingResourceException e){
+                t = null;
+            }
+            return t;
+        }
+         public Object getObject(String key) {
+            
+            return res.get(key);
+        }
+    }
+    
+    private static class UArrayResource implements DataMap{
+        private Map theMap; 
+        UArrayResource(UResourceBundle theHeader, UResourceBundle theData) throws DataModuleFormatError{
+            assert_is (theHeader != null && theData != null);
+            String[] header;
+         
+            header = getStringArrayHelper(theHeader);
+            if (theData.getSize() != header.length) 
+                throw new DataModuleFormatError("The count of Header and Data is mismatch.");
+            theMap = new HashMap();
+            for (int i = 0; i < header.length; i++) {
+                if(theData.getType()==UResourceBundle.ARRAY){
+                    theMap.put(header[i], theData.get(i));
+                }else if(theData.getType()==UResourceBundle.STRING){
+                    theMap.put(header[i], theData.getString());
+                }else{
+                    throw new DataModuleFormatError("Did not get the expected data!");                   
+                }
+            }
+            
+        }
+        
+        public String getString(String key) {
+            Object o = theMap.get(key);
+            UResourceBundle rb;
+            if(o instanceof UResourceBundle) {
+                // unpack ResourceBundle strings
+                rb = (UResourceBundle)o;
+                return rb.getString();
+            }
+            return (String)o;
+        }
+        public Object getObject(String key) {
+            return theMap.get(key);
+        }
+    }
+}