]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/tests/collate/src/com/ibm/icu/dev/test/util/ICUResourceBundleCollationTest.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / tests / collate / src / com / ibm / icu / dev / test / util / ICUResourceBundleCollationTest.java
1 /**\r
2  *******************************************************************************\r
3  * Copyright (C) 2009, International Business Machines Corporation and         *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 package com.ibm.icu.dev.test.util;\r
8 \r
9 import java.util.MissingResourceException;\r
10 \r
11 import com.ibm.icu.dev.test.TestFmwk;\r
12 import com.ibm.icu.impl.ICUResourceBundle;\r
13 import com.ibm.icu.text.Collator;\r
14 import com.ibm.icu.util.ULocale;\r
15 import com.ibm.icu.util.UResourceBundle;\r
16 \r
17 \r
18 public final class ICUResourceBundleCollationTest extends TestFmwk {\r
19     private static final String COLLATION_RESNAME = "collations";\r
20     private static final String COLLATION_KEYWORD = "collation";\r
21     private static final String DEFAULT_NAME = "default";\r
22     private static final String STANDARD_NAME = "standard";\r
23 \r
24     public static void main(String args[]) throws Exception {\r
25         new ICUResourceBundleCollationTest().run(args);\r
26     }\r
27 \r
28     public void TestFunctionalEquivalent(){\r
29        String[] collCases = {\r
30        //  avail   locale                               equiv\r
31            "f",     "de_US_CALIFORNIA",                 "de",\r
32            "f",     "zh_TW@collation=stroke",           "zh@collation=stroke", /* alias of zh_Hant_TW */\r
33            "t",     "zh_Hant_TW@collation=stroke",      "zh@collation=stroke",\r
34            "f",     "de_CN@collation=pinyin",           "de",\r
35            "t",     "zh@collation=pinyin",              "zh",\r
36            "f",     "zh_CN@collation=pinyin",           "zh", /* alias of zh_Hans_CN */\r
37            "t",     "zh_Hans_CN@collation=pinyin",      "zh",\r
38            "f",     "zh_HK@collation=pinyin",           "zh", /* alias of zh_Hant_HK */\r
39            "t",     "zh_Hant_HK@collation=pinyin",      "zh",\r
40            "f",     "zh_HK@collation=stroke",           "zh@collation=stroke", /* alias of zh_Hant_HK */\r
41            "t",     "zh_Hant_HK@collation=stroke",      "zh@collation=stroke",\r
42            "f",     "zh_HK",                            "zh@collation=stroke", /* alias of zh_Hant_HK */\r
43            "t",     "zh_Hant_HK",                       "zh@collation=stroke",\r
44            "f",     "zh_MO",                            "zh@collation=stroke", /* alias of zh_Hant_MO */\r
45            "t",     "zh_Hant_MO",                       "zh@collation=stroke",\r
46            "f",     "zh_TW_STROKE",                     "zh@collation=stroke",\r
47            "f",     "zh_TW_STROKE@collation=big5han",   "zh@collation=big5han",\r
48            "f",     "de_CN@calendar=japanese",          "de",\r
49            "t",     "de@calendar=japanese",             "de",\r
50            "f",     "zh_TW@collation=big5han",          "zh@collation=big5han", /* alias of zh_Hant_TW */\r
51            "t",     "zh_Hant_TW@collation=big5han",     "zh@collation=big5han",\r
52            "f",     "zh_TW@collation=gb2312han",        "zh@collation=gb2312han", /* alias of zh_Hant_TW */\r
53            "t",     "zh_Hant_TW@collation=gb2312han",   "zh@collation=gb2312han",\r
54            "f",     "zh_CN@collation=big5han",          "zh@collation=big5han", /* alias of zh_Hans_CN */\r
55            "t",     "zh_Hans_CN@collation=big5han",     "zh@collation=big5han",\r
56            "f",     "zh_CN@collation=gb2312han",        "zh@collation=gb2312han", /* alias of zh_Hans_CN */\r
57            "t",     "zh_Hans_CN@collation=gb2312han",   "zh@collation=gb2312han",\r
58            "t",     "zh@collation=big5han",             "zh@collation=big5han",\r
59            "t",     "zh@collation=gb2312han",           "zh@collation=gb2312han",\r
60            "t",     "hi_IN@collation=direct",           "hi@collation=direct",\r
61            "t",     "hi@collation=standard",            "hi",\r
62            "t",     "hi@collation=direct",              "hi@collation=direct",\r
63            "f",     "hi_AU@collation=direct;currency=CHF;calendar=buddhist",    "hi@collation=direct",\r
64            "f",     "hi_AU@collation=standard;currency=CHF;calendar=buddhist",  "hi",\r
65            "t",     "de_DE@collation=pinyin",           "de", /* bug 4582 tests */\r
66            "f",     "de_DE_BONN@collation=pinyin",      "de",\r
67            "t",     "nl",                               "root",\r
68            "t",     "nl_NL",                            "root",\r
69            "f",     "nl_NL_EEXT",                       "root",\r
70            "t",     "nl@collation=stroke",              "root",\r
71            "t",     "nl_NL@collation=stroke",           "root",\r
72            "f",     "nl_NL_EEXT@collation=stroke",      "root",\r
73        };\r
74 \r
75        logln("Testing functional equivalents for collation...");\r
76        getFunctionalEquivalentTestCases(ICUResourceBundle.ICU_COLLATION_BASE_NAME,\r
77                                         Collator.class.getClassLoader(),\r
78                COLLATION_RESNAME, COLLATION_KEYWORD, true, collCases);\r
79     }\r
80 \r
81     public void TestGetWithFallback(){\r
82         /*\r
83         UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");\r
84         String key = bundle.getStringWithFallback("Keys/collation");\r
85         if(!key.equals("COLLATION")){\r
86             errln("Did not get the expected result from getStringWithFallback method.");\r
87         }\r
88         String type = bundle.getStringWithFallback("Types/collation/direct");\r
89         if(!type.equals("DIRECT")){\r
90             errln("Did not get the expected result form getStringWithFallback method.");\r
91         }\r
92         */\r
93         ICUResourceBundle bundle = null;\r
94         String key = null;\r
95         try{\r
96             bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,ULocale.canonicalize("de__PHONEBOOK"));\r
97 \r
98             if(!bundle.getULocale().equals("de")){\r
99                 errln("did not get the expected bundle");\r
100             }\r
101             key = bundle.getStringWithFallback("collations/collation/default");\r
102             if(!key.equals("phonebook")){\r
103                 errln("Did not get the expected result from getStringWithFallback method.");\r
104             }\r
105 \r
106         }catch(MissingResourceException ex){\r
107             logln("got the expected exception");\r
108         }\r
109 \r
110 \r
111         bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"fr_FR");\r
112         key = bundle.getStringWithFallback("collations/default");\r
113         if(!key.equals("standard")){\r
114             errln("Did not get the expected result from getStringWithFallback method.");\r
115         }\r
116     }\r
117 \r
118     public void TestKeywordValues(){\r
119         String kwVals[];\r
120         boolean foundStandard = false;\r
121         int n;\r
122 \r
123         logln("Testing getting collation values:");\r
124         kwVals = ICUResourceBundle.getKeywordValues(ICUResourceBundle.ICU_COLLATION_BASE_NAME,COLLATION_RESNAME);\r
125         for(n=0;n<kwVals.length;n++) {\r
126             logln(new Integer(n).toString() + ": " + kwVals[n]);\r
127             if(DEFAULT_NAME.equals(kwVals[n])) {\r
128                 errln("getKeywordValues for collation returned 'default' in the list.");\r
129             } else if(STANDARD_NAME.equals(kwVals[n])) {\r
130                 if(foundStandard == false) {\r
131                     foundStandard = true;\r
132                     logln("found 'standard'");\r
133                 } else {\r
134                     errln("Error - 'standard' is in the keyword list twice!");\r
135                 }\r
136             }\r
137         }\r
138 \r
139         if(foundStandard == false) {\r
140             errln("Error - 'standard' was not in the collation tree as a keyword.");\r
141         } else {\r
142             logln("'standard' was found as a collation keyword.");\r
143         }\r
144     }\r
145 \r
146     public void TestOpen(){\r
147         UResourceBundle bundle = (UResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME, "en_US_POSIX");\r
148         if(bundle==null){\r
149             errln("could not load the stream");\r
150         }\r
151     }\r
152 \r
153     private void getFunctionalEquivalentTestCases(String path, ClassLoader cl, String resName, String keyword,\r
154             boolean truncate, String[] testCases) {\r
155         //String F_STR = "f";\r
156         String T_STR = "t";\r
157         boolean isAvail[] = new boolean[1];\r
158 \r
159         logln("Testing functional equivalents...");\r
160         for(int i = 0; i < testCases.length ;i+=3) {\r
161             boolean expectAvail = T_STR.equals(testCases[i+0]);\r
162             ULocale inLocale = new ULocale(testCases[i+1]);\r
163             ULocale expectLocale = new ULocale(testCases[i+2]);\r
164 \r
165             logln(new Integer(i/3).toString() + ": " + new Boolean(expectAvail).toString() + "\t\t" +\r
166                     inLocale.toString() + "\t\t" + expectLocale.toString());\r
167 \r
168             ULocale equivLocale = ICUResourceBundle.getFunctionalEquivalent(path, cl, resName, keyword, inLocale, isAvail, truncate);\r
169             boolean gotAvail = isAvail[0];\r
170 \r
171             if((gotAvail != expectAvail) || !equivLocale.equals(expectLocale)) {\r
172                 errln(new Integer(i/3).toString() + ":  Error, expected  Equiv=" + new Boolean(expectAvail).toString() + "\t\t" +\r
173                         inLocale.toString() + "\t\t--> " + expectLocale.toString() + ",  but got " + new Boolean(gotAvail).toString() + " " +\r
174                         equivLocale.toString());\r
175             }\r
176         }\r
177     }\r
178 }