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