]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/util/LocaleAliasTest.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / util / LocaleAliasTest.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2005-2008, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 \r
8 /*\r
9  * New added, 2005-5-10 [Terry/SGL]\r
10  * Major modification by Ram\r
11  */\r
12 \r
13 package com.ibm.icu.dev.test.util;\r
14 \r
15 import java.util.HashMap;\r
16 \r
17 import com.ibm.icu.impl.ICUResourceBundle;\r
18 import com.ibm.icu.text.Collator;\r
19 import com.ibm.icu.text.DateFormat;\r
20 import com.ibm.icu.util.Calendar;\r
21 import com.ibm.icu.util.ULocale;\r
22 import com.ibm.icu.util.UResourceBundle;\r
23 \r
24 public class LocaleAliasTest extends com.ibm.icu.dev.test.TestFmwk {\r
25     private static final ULocale[][] _LOCALES = {\r
26 \r
27             {new ULocale("en", "RH"), new ULocale("en", "ZW")},\r
28             {new ULocale("in"), new ULocale("id")},\r
29             {new ULocale("in", "ID"), new ULocale("id", "ID")},\r
30             {new ULocale("iw"), new ULocale("he")},\r
31             {new ULocale("iw", "IL"), new ULocale("he", "IL")},\r
32             {new ULocale("ji"), new ULocale("yi")},\r
33             \r
34             {new ULocale("en", "BU"), new ULocale("en", "MM")},\r
35             {new ULocale("en", "DY"), new ULocale("en", "BJ")},\r
36             {new ULocale("en", "HV"), new ULocale("en", "BF")},\r
37             {new ULocale("en", "NH"), new ULocale("en", "VU")},\r
38             {new ULocale("en", "TP"), new ULocale("en", "TL")},\r
39             {new ULocale("en", "ZR"), new ULocale("en", "CD")}\r
40     };\r
41     \r
42     private static final int _LOCALE_NUMBER = _LOCALES.length;\r
43     private static ULocale[] available = null;\r
44     private HashMap availableMap = new HashMap();\r
45     private static final ULocale _DEFAULT_LOCALE = ULocale.US;\r
46     \r
47     public LocaleAliasTest(){\r
48     }\r
49     protected void init(){\r
50         available = ULocale.getAvailableLocales();\r
51         for(int i=0; i<available.length;i++){\r
52             availableMap.put(available[i].toString(),"");\r
53         }\r
54     }\r
55     public static void main(String[] args) {\r
56         new LocaleAliasTest().run(args);\r
57     }\r
58     public void TestCalendar() {\r
59         ULocale defLoc = ULocale.getDefault();\r
60         ULocale.setDefault(_DEFAULT_LOCALE);\r
61         for (int i=0; i<_LOCALE_NUMBER; i++) {\r
62             ULocale oldLoc = _LOCALES[i][0];\r
63             ULocale newLoc = _LOCALES[i][1];\r
64             if(availableMap.get(_LOCALES[i][1])==null){\r
65                 logln(_LOCALES[i][1]+" is not available. Skipping!");\r
66                 continue;\r
67             }\r
68             Calendar c1 = Calendar.getInstance(oldLoc);\r
69             Calendar c2 = Calendar.getInstance(newLoc);\r
70             c1.setTime(c2.getTime());\r
71             //Test function "getFirstDayOfWeek"\r
72     //        int firstDayOfWeek1 = c1.getFirstDayOfWeek();\r
73     //        int firstDayOfWeek2 = c2.getFirstDayOfWeek();\r
74     //        if (firstDayOfWeek1 != firstDayOfWeek2) {\r
75     //            this.logln("Calendar(getFirstDayOfWeek) old:"\r
76     //                    +firstDayOfWeek1+"   new:"+firstDayOfWeek2);\r
77     //            pass = false;\r
78     //        }\r
79                     \r
80             //Test function "getLocale(ULocale.VALID_LOCALE)"\r
81             ULocale l1 = c1.getLocale(ULocale.VALID_LOCALE);\r
82             ULocale l2 = c2.getLocale(ULocale.VALID_LOCALE);\r
83             if (!newLoc.equals(l1)) {\r
84                 errln("CalendarTest: newLoc!=l1: newLoc= "+newLoc +" l1= "+l1);\r
85             }\r
86             if (!l1.equals(l2)) {\r
87                 errln("CalendarTest: l1!=l2: l1= "+l1 +" l2= "+l2);\r
88             }\r
89             if(!c1.equals(c2)){\r
90                 errln("CalendarTest: c1!=c2.  newLoc= "+newLoc +" oldLoc= "+oldLoc);\r
91             }\r
92             logln("Calendar(getLocale) old:"+l1+"   new:"+l2);    \r
93         }\r
94         ULocale.setDefault(defLoc);\r
95     }\r
96     \r
97     public void  TestDateFormat() {\r
98         ULocale defLoc = ULocale.getDefault();\r
99         ULocale.setDefault(_DEFAULT_LOCALE);\r
100         for (int i=0; i<_LOCALE_NUMBER; i++) {\r
101             ULocale oldLoc = _LOCALES[i][0];\r
102             ULocale newLoc = _LOCALES[i][1];\r
103             if(availableMap.get(_LOCALES[i][1])==null){\r
104                 logln(_LOCALES[i][1]+" is not available. Skipping!");\r
105                 continue;\r
106             }\r
107             DateFormat df1 = DateFormat.getDateInstance(DateFormat.FULL, oldLoc);\r
108             DateFormat df2 = DateFormat.getDateInstance(DateFormat.FULL, newLoc);\r
109             \r
110             //Test function "getLocale"\r
111             ULocale l1 = df1.getLocale(ULocale.VALID_LOCALE);\r
112             ULocale l2 = df2.getLocale(ULocale.VALID_LOCALE);\r
113             if (!newLoc.equals(l1)) {\r
114                 errln("DateFormatTest: newLoc!=l1: newLoc= "+newLoc +" l1= "+l1);\r
115             }\r
116             if (!l1.equals(l2)) {\r
117                 errln("DateFormatTest: l1!=l2: l1= "+l1 +" l2= "+l2);\r
118             }\r
119             if (!df1.equals(df2)) {\r
120                 errln("DateFormatTest: df1!=df2: newLoc= "+newLoc +" oldLoc= "+oldLoc);\r
121             }\r
122             this.logln("DateFormat(getLocale) old:"+l1+"   new:"+l2);\r
123             \r
124             //Test function "format"\r
125     //        Date d = new Date();\r
126     //        String d1 = df1.format(d);\r
127     //        String d2 = df2.format(d);\r
128     //        if (!d1.equals(d2)) {\r
129     //            pass = false;\r
130     //        }\r
131     //        this.logln("DateFormat(format) old:"+d1+"   new:"+d2);\r
132         }\r
133         ULocale.setDefault(defLoc);\r
134     }\r
135     \r
136     public void TestCollation() {\r
137         ULocale defLoc = ULocale.getDefault();\r
138         ULocale.setDefault(_DEFAULT_LOCALE);\r
139         for (int i=0; i<_LOCALE_NUMBER; i++) {\r
140             ULocale oldLoc = _LOCALES[i][0];\r
141             ULocale newLoc = _LOCALES[i][1];\r
142             if(availableMap.get(_LOCALES[i][1])==null){\r
143                 logln(_LOCALES[i][1]+" is not available. Skipping!");\r
144                 continue;\r
145             }\r
146             Collator c1 = Collator.getInstance(oldLoc);\r
147             Collator c2 = Collator.getInstance(newLoc);\r
148             \r
149             if (!c1.equals(c2)) {\r
150                 errln("CollationTest: c1!=c2: newLoc= "+newLoc +" oldLoc= "+oldLoc);\r
151             }\r
152  \r
153             logln("Collation old:"+oldLoc+"   new:"+newLoc);\r
154         }\r
155         ULocale.setDefault(defLoc);\r
156     }\r
157     \r
158     public void TestULocale() {\r
159         ULocale defLoc = ULocale.getDefault();\r
160         ULocale.setDefault(_DEFAULT_LOCALE);\r
161         for (int i=0; i<_LOCALE_NUMBER; i++) {\r
162             ULocale oldLoc = _LOCALES[i][0];\r
163             ULocale newLoc = _LOCALES[i][1];\r
164             if(availableMap.get(_LOCALES[i][1])==null){\r
165                 logln(_LOCALES[i][1]+" is not available. Skipping!");\r
166                 continue;\r
167             }\r
168             ULocale ul1 = new ULocale(oldLoc.toString());\r
169             ULocale ul2 = new ULocale(newLoc.toString());\r
170             \r
171             String name1 = ul1.getDisplayName();\r
172             String name2 = ul2.getDisplayName();\r
173             if (!name1.equals(name2)) {\r
174                 errln("name1!=name2. name1 = " + name1 +" name2 = " +name2);\r
175             }\r
176             logln("ULocale(getDisplayName) old:"+name1+"   new:"+name2);\r
177         }\r
178         ULocale.setDefault(defLoc);\r
179     }\r
180     \r
181     public void TestDisplayName() {\r
182         ULocale defLoc = ULocale.getDefault();\r
183         ULocale.setDefault(_DEFAULT_LOCALE);\r
184         for (int i=0; i<_LOCALE_NUMBER; i++) {\r
185             ULocale oldLoc = _LOCALES[i][0];\r
186             ULocale newLoc = _LOCALES[i][1];\r
187 \r
188             for(int j=0; j<available.length; j++){\r
189                String oldCountry = oldLoc.getDisplayCountry(available[j]);\r
190                String newCountry = newLoc.getDisplayCountry(available[j]);\r
191                String oldLang = oldLoc.getDisplayLanguage(available[j]);\r
192                String newLang = newLoc.getDisplayLanguage(available[j]);\r
193                \r
194                // is  there  display name for the current country ID               \r
195                if(!newCountry.equals(newLoc.getCountry())){\r
196                    if(!oldCountry.equals(newCountry)){\r
197                        errln("getCountry() failed for "+ oldLoc +" oldCountry= "+ prettify(oldCountry) +" newCountry = "+prettify(newCountry)+ " in display locale "+ available[j].toString());\r
198                    }\r
199                }\r
200                //there is a display name for the current lang ID               \r
201                if(!newLang.equals(newLoc.getLanguage())){\r
202                    if(!oldLang.equals(newLang)){\r
203                        errln("getLanguage() failed for " + oldLoc + " oldLang = "+ prettify(oldLang) +" newLang = "+prettify(newLang)+ " in display locale "+ available[j].toString());\r
204                    }\r
205                }\r
206             }\r
207         }\r
208         ULocale.setDefault(defLoc);\r
209     }\r
210     public void TestUResourceBundle() {\r
211         ULocale defLoc = ULocale.getDefault();\r
212         ULocale.setDefault(_DEFAULT_LOCALE);\r
213         for (int i=0; i<_LOCALE_NUMBER; i++) {\r
214             if(availableMap.get(_LOCALES[i][1])==null){\r
215                 logln(_LOCALES[i][1]+" is not available. Skipping!");\r
216                 continue;\r
217             }\r
218             ULocale oldLoc = _LOCALES[i][0];\r
219             ULocale newLoc = _LOCALES[i][1];\r
220             UResourceBundle urb1 = null;\r
221             UResourceBundle urb2 = null;\r
222             \r
223             urb1 = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, oldLoc);\r
224             urb2 = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, newLoc);\r
225             ULocale l1 = urb1.getULocale();\r
226             ULocale l2 = urb2.getULocale();        \r
227             if (!newLoc.equals(l1)) {\r
228                 errln("ResourceBundleTest: newLoc!=l1: newLoc= "+newLoc +" l1= "+l1);\r
229             }\r
230             if (!l1.equals(l2)) {\r
231                 errln("ResourceBundleTest: l1!=l2: l1= "+l1 +" l2= "+l2);\r
232             }\r
233             this.logln("UResourceBundle old:"+l1+"   new:"+l2);\r
234         }\r
235         ULocale.setDefault(defLoc);\r
236     }\r
237 }\r