2 **********************************************************************
\r
3 * Copyright (c) 2004-2010, International Business Machines
\r
4 * Corporation and others. All Rights Reserved.
\r
5 **********************************************************************
\r
7 * Created: January 14 2004
\r
9 **********************************************************************
\r
11 package com.ibm.icu.dev.test.util;
\r
13 import java.lang.reflect.InvocationTargetException;
\r
14 import java.lang.reflect.Method;
\r
15 import java.util.Hashtable;
\r
16 import java.util.Iterator;
\r
17 import java.util.Locale;
\r
18 import java.util.TreeMap;
\r
20 import com.ibm.icu.dev.test.TestFmwk;
\r
21 import com.ibm.icu.lang.UCharacter;
\r
22 import com.ibm.icu.text.BreakIterator;
\r
23 import com.ibm.icu.text.DateFormat;
\r
24 import com.ibm.icu.text.DecimalFormat;
\r
25 import com.ibm.icu.text.NumberFormat;
\r
26 import com.ibm.icu.text.SimpleDateFormat;
\r
27 import com.ibm.icu.text.NumberFormat.SimpleNumberFormatFactory;
\r
28 import com.ibm.icu.util.Calendar;
\r
29 import com.ibm.icu.util.IllformedLocaleException;
\r
30 import com.ibm.icu.util.LocaleData;
\r
31 import com.ibm.icu.util.ULocale;
\r
32 import com.ibm.icu.util.UResourceBundle;
\r
33 import com.ibm.icu.util.VersionInfo;
\r
34 import com.ibm.icu.util.ULocale.Builder;
\r
36 public class ULocaleTest extends TestFmwk {
\r
38 public static void main(String[] args) throws Exception {
\r
39 new ULocaleTest().run(args);
\r
42 public void TestCalendar() {
\r
43 // TODO The CalendarFactory mechanism is not public,
\r
44 // so we can't test it yet. If it becomes public,
\r
45 // enable this code.
\r
47 // class CFactory implements CalendarFactory {
\r
50 // public CFactory(Locale locale, Calendar prototype) {
\r
52 // proto = prototype;
\r
54 // public Calendar create(TimeZone tz, Locale locale) {
\r
55 // // ignore tz -- not relevant to this test
\r
56 // return locale.equals(loc) ?
\r
57 // (Calendar) proto.clone() : null;
\r
59 // public String factoryName() {
\r
60 // return "CFactory";
\r
64 checkService("en_US_BROOKLYN", new ServiceFacade() {
\r
65 public Object create(ULocale req) {
\r
66 return Calendar.getInstance(req);
\r
68 // }, null, new Registrar() {
\r
69 // public Object register(ULocale loc, Object prototype) {
\r
70 // CFactory f = new CFactory(loc, (Calendar) prototype);
\r
71 // return Calendar.register(f, loc);
\r
73 // public boolean unregister(Object key) {
\r
74 // return Calendar.unregister(key);
\r
79 // Currency getLocale API is obsolete in 3.2. Since it now returns ULocale.ROOT,
\r
80 // and this is not equal to the requested locale zh_TW_TAIPEI, the
\r
81 // checkService call would always fail. So we now omit the test.
\r
83 public void TestCurrency() {
\r
84 checkService("zh_TW_TAIPEI", new ServiceFacade() {
\r
85 public Object create(ULocale req) {
\r
86 return Currency.getInstance(req);
\r
88 }, null, new Registrar() {
\r
89 public Object register(ULocale loc, Object prototype) {
\r
90 return Currency.registerInstance((Currency) prototype, loc);
\r
92 public boolean unregister(Object key) {
\r
93 return Currency.unregister(key);
\r
99 public void TestBreakIterator() {
\r
100 checkService("ja_JP_OSAKA", new ServiceFacade() {
\r
101 public Object create(ULocale req) {
\r
102 return BreakIterator.getWordInstance(req);
\r
104 }, null, new Registrar() {
\r
105 public Object register(ULocale loc, Object prototype) {
\r
106 return BreakIterator.registerInstance(
\r
107 (BreakIterator) prototype,
\r
108 loc, BreakIterator.KIND_WORD);
\r
110 public boolean unregister(Object key) {
\r
111 return BreakIterator.unregister(key);
\r
116 public void TestDateFormat() {
\r
117 checkService("de_CH_ZURICH", new ServiceFacade() {
\r
118 public Object create(ULocale req) {
\r
119 return DateFormat.getDateInstance(DateFormat.DEFAULT, req);
\r
121 }, new Subobject() {
\r
122 public Object get(Object parent) {
\r
123 return ((SimpleDateFormat) parent).getDateFormatSymbols();
\r
128 public void TestNumberFormat() {
\r
129 class NFactory extends SimpleNumberFormatFactory {
\r
130 NumberFormat proto;
\r
132 public NFactory(ULocale loc, NumberFormat fmt) {
\r
137 public NumberFormat createFormat(ULocale loc, int formatType) {
\r
138 return (NumberFormat) (locale.equals(loc) ?
\r
139 proto.clone() : null);
\r
143 checkService("fr_FR_NICE", new ServiceFacade() {
\r
144 public Object create(ULocale req) {
\r
145 return NumberFormat.getInstance(req);
\r
147 }, new Subobject() {
\r
148 public Object get(Object parent) {
\r
149 return ((DecimalFormat) parent).getDecimalFormatSymbols();
\r
151 }, new Registrar() {
\r
152 public Object register(ULocale loc, Object prototype) {
\r
153 NFactory f = new NFactory(loc, (NumberFormat) prototype);
\r
154 return NumberFormat.registerFactory(f);
\r
156 public boolean unregister(Object key) {
\r
157 return NumberFormat.unregister(key);
\r
162 public void TestSetULocaleKeywords() {
\r
163 ULocale uloc = new ULocale("en_Latn_US");
\r
164 uloc = uloc.setKeywordValue("Foo", "FooValue");
\r
165 if (!"en_Latn_US@foo=FooValue".equals(uloc.getName())) {
\r
166 errln("failed to add foo keyword, got: " + uloc.getName());
\r
168 uloc = uloc.setKeywordValue("Bar", "BarValue");
\r
169 if (!"en_Latn_US@bar=BarValue;foo=FooValue".equals(uloc.getName())) {
\r
170 errln("failed to add bar keyword, got: " + uloc.getName());
\r
172 uloc = uloc.setKeywordValue("BAR", "NewBarValue");
\r
173 if (!"en_Latn_US@bar=NewBarValue;foo=FooValue".equals(uloc.getName())) {
\r
174 errln("failed to change bar keyword, got: " + uloc.getName());
\r
176 uloc = uloc.setKeywordValue("BaR", null);
\r
177 if (!"en_Latn_US@foo=FooValue".equals(uloc.getName())) {
\r
178 errln("failed to delete bar keyword, got: " + uloc.getName());
\r
180 uloc = uloc.setKeywordValue(null, null);
\r
181 if (!"en_Latn_US".equals(uloc.getName())) {
\r
182 errln("failed to delete all keywords, got: " + uloc.getName());
\r
189 public void TestJavaLocaleCompatibility() {
\r
190 Locale backupDefault = Locale.getDefault();
\r
192 // Java Locale for ja_JP with Japanese calendar
\r
193 Locale jaJPJP = new Locale("ja", "JP", "JP");
\r
194 Locale jaJP = new Locale("ja", "JP");
\r
195 // Java Locale for th_TH with Thai digits
\r
196 Locale thTHTH = new Locale("th", "TH", "TH");
\r
198 Calendar cal = Calendar.getInstance(jaJPJP);
\r
199 String caltype = cal.getType();
\r
200 if (!caltype.equals("japanese")) {
\r
201 errln("FAIL: Invalid calendar type: " + caltype + " /expected: japanese");
\r
204 cal = Calendar.getInstance(jaJP);
\r
205 caltype = cal.getType();
\r
206 if (!caltype.equals("gregorian")) {
\r
207 errln("FAIL: Invalid calendar type: " + caltype + " /expected: gregorian");
\r
211 Locale.setDefault(jaJPJP);
\r
212 ULocale defUloc = ULocale.getDefault();
\r
213 if (!defUloc.toString().equals("ja_JP@calendar=japanese")) {
\r
214 errln("FAIL: Invalid default ULocale: " + defUloc + " /expected: ja_JP@calendar=japanese");
\r
216 // Check calendar type
\r
217 cal = Calendar.getInstance();
\r
218 caltype = cal.getType();
\r
219 if (!caltype.equals("japanese")) {
\r
220 errln("FAIL: Invalid calendar type: " + caltype + " /expected: japanese");
\r
222 Locale.setDefault(backupDefault);
\r
224 // Set default via ULocale
\r
225 ULocale ujaJP_calJP = new ULocale("ja_JP@calendar=japanese");
\r
226 ULocale.setDefault(ujaJP_calJP);
\r
227 if (!Locale.getDefault().equals(jaJPJP)) {
\r
228 errln("FAIL: ULocale#setDefault failed to set Java Locale ja_JP_JP /actual: " + Locale.getDefault());
\r
230 // Ticket#6672 - missing keywords
\r
231 defUloc = ULocale.getDefault();
\r
232 if (!defUloc.equals(ujaJP_calJP)) {
\r
233 errln("FAIL: ULocale#getDefault returned " + defUloc + " /expected: ja_JP@calendar=japanese");
\r
235 // Set a incompatible base locale via Locale#setDefault
\r
236 Locale.setDefault(Locale.US);
\r
237 defUloc = ULocale.getDefault();
\r
238 if (defUloc.equals(ujaJP_calJP)) {
\r
239 errln("FAIL: ULocale#getDefault returned " + defUloc + " /expected: " + ULocale.forLocale(Locale.US));
\r
242 Locale.setDefault(backupDefault);
\r
244 // We also want to map ICU locale ja@calendar=japanese to Java ja_JP_JP
\r
245 ULocale.setDefault(new ULocale("ja@calendar=japanese"));
\r
246 if (!Locale.getDefault().equals(jaJPJP)) {
\r
247 errln("FAIL: ULocale#setDefault failed to set Java Locale ja_JP_JP /actual: " + Locale.getDefault());
\r
249 Locale.setDefault(backupDefault);
\r
252 Locale noNONY = new Locale("no", "NO", "NY");
\r
253 Locale.setDefault(noNONY);
\r
254 defUloc = ULocale.getDefault();
\r
255 if (defUloc.toString().equals("nn_NY")) {
\r
256 errln("FAIL: Invalid default ULocale: " + defUloc + " /expected: nn_NY");
\r
258 Locale.setDefault(backupDefault);
\r
260 // Java th_TH_TH -> ICU th_TH@numbers=thai
\r
261 ULocale.setDefault(new ULocale("th@numbers=thai"));
\r
262 if (!Locale.getDefault().equals(thTHTH)) {
\r
263 errln("FAIL: ULocale#setDefault failed to set Java Locale th_TH_TH /actual: " + Locale.getDefault());
\r
265 Locale.setDefault(backupDefault);
\r
267 // Set default via ULocale
\r
268 ULocale.setDefault(new ULocale("nn_NO"));
\r
269 if (!Locale.getDefault().equals(noNONY)) {
\r
270 errln("FAIL: ULocale#setDefault failed to set Java Locale no_NO_NY /actual: " + Locale.getDefault());
\r
272 Locale.setDefault(backupDefault);
\r
274 // We also want to map ICU locale nn to Java no_NO_NY
\r
275 ULocale.setDefault(new ULocale("nn"));
\r
276 if (!Locale.getDefault().equals(noNONY)) {
\r
277 errln("FAIL: ULocale#setDefault failed to set Java Locale no_NO_NY /actual: " + Locale.getDefault());
\r
279 Locale.setDefault(backupDefault);
\r
282 // ================= Infrastructure =================
\r
285 * Compare two locale IDs. If they are equal, return 0. If `string'
\r
286 * starts with `prefix' plus an additional element, that is, string ==
\r
287 * prefix + '_' + x, then return 1. Otherwise return a value < 0.
\r
289 static int loccmp(String string, String prefix) {
\r
290 int slen = string.length(),
\r
291 plen = prefix.length();
\r
292 /* 'root' is "less than" everything */
\r
293 if (prefix.equals("root")) {
\r
294 return string.equals("root") ? 0 : 1;
\r
296 // ON JAVA (only -- not on C -- someone correct me if I'm wrong)
\r
297 // consider "" to be an alternate name for "root".
\r
299 return slen == 0 ? 0 : 1;
\r
301 if (!string.startsWith(prefix)) return -1; /* mismatch */
\r
302 if (slen == plen) return 0;
\r
303 if (string.charAt(plen) == '_') return 1;
\r
304 return -2; /* false match, e.g. "en_USX" cmp "en_US" */
\r
308 * Check the relationship between requested locales, and report problems.
\r
309 * The caller specifies the expected relationships between requested
\r
310 * and valid (expReqValid) and between valid and actual (expValidActual).
\r
311 * Possible values are:
\r
312 * "gt" strictly greater than, e.g., en_US > en
\r
313 * "ge" greater or equal, e.g., en >= en
\r
314 * "eq" equal, e.g., en == en
\r
316 void checklocs(String label,
\r
320 String expReqValid,
\r
321 String expValidActual) {
\r
322 String valid = validLoc.toString();
\r
323 String actual = actualLoc.toString();
\r
324 int reqValid = loccmp(req, valid);
\r
325 int validActual = loccmp(valid, actual);
\r
326 boolean reqOK = (expReqValid.equals("gt") && reqValid > 0) ||
\r
327 (expReqValid.equals("ge") && reqValid >= 0) ||
\r
328 (expReqValid.equals("eq") && reqValid == 0);
\r
329 boolean valOK = (expValidActual.equals("gt") && validActual > 0) ||
\r
330 (expValidActual.equals("ge") && validActual >= 0) ||
\r
331 (expValidActual.equals("eq") && validActual == 0);
\r
332 if (reqOK && valOK) {
\r
333 logln("Ok: " + label + "; req=" + req + ", valid=" + valid +
\r
334 ", actual=" + actual);
\r
336 errln("FAIL: " + label + "; req=" + req + ", valid=" + valid +
\r
337 ", actual=" + actual +
\r
338 (reqOK ? "" : "\n req !" + expReqValid + " valid") +
\r
339 (valOK ? "" : "\n val !" + expValidActual + " actual"));
\r
344 * Interface used by checkService defining a protocol to create an
\r
345 * object, given a requested locale.
\r
347 interface ServiceFacade {
\r
348 Object create(ULocale requestedLocale);
\r
352 * Interface used by checkService defining a protocol to get a
\r
353 * contained subobject, given its parent object.
\r
355 interface Subobject {
\r
356 Object get(Object parent);
\r
360 * Interface used by checkService defining a protocol to register
\r
361 * and unregister a service object prototype.
\r
363 interface Registrar {
\r
364 Object register(ULocale loc, Object prototype);
\r
365 boolean unregister(Object key);
\r
369 * Use reflection to call getLocale() on the given object to
\r
370 * determine both the valid and the actual locale. Verify these
\r
373 void checkObject(String requestedLocale, Object obj,
\r
374 String expReqValid, String expValidActual) {
\r
375 Class[] getLocaleParams = new Class[] { ULocale.Type.class };
\r
377 Class cls = obj.getClass();
\r
378 Method getLocale = cls.getMethod("getLocale", getLocaleParams);
\r
379 ULocale valid = (ULocale) getLocale.invoke(obj, new Object[] {
\r
380 ULocale.VALID_LOCALE });
\r
381 ULocale actual = (ULocale) getLocale.invoke(obj, new Object[] {
\r
382 ULocale.ACTUAL_LOCALE });
\r
383 checklocs(cls.getName(), requestedLocale,
\r
384 valid.toLocale(), actual.toLocale(),
\r
385 expReqValid, expValidActual);
\r
388 // Make the following exceptions _specific_ -- do not
\r
389 // catch(Exception), since that will catch the exception
\r
390 // that errln throws.
\r
391 catch(NoSuchMethodException e1) {
\r
392 // no longer an error, Currency has no getLocale
\r
393 // errln("FAIL: reflection failed: " + e1);
\r
394 } catch(SecurityException e2) {
\r
395 errln("FAIL: reflection failed: " + e2);
\r
396 } catch(IllegalAccessException e3) {
\r
397 errln("FAIL: reflection failed: " + e3);
\r
398 } catch(IllegalArgumentException e4) {
\r
399 errln("FAIL: reflection failed: " + e4);
\r
400 } catch(InvocationTargetException e5) {
\r
401 // no longer an error, Currency has no getLocale
\r
402 // errln("FAIL: reflection failed: " + e5);
\r
407 * Verify the correct getLocale() behavior for the given service.
\r
408 * @param requestedLocale the locale to request. This MUST BE
\r
409 * FAKE. In other words, it should be something like
\r
410 * en_US_FAKEVARIANT so this method can verify correct fallback
\r
412 * @param svc a factory object that can create the object to be
\r
413 * tested. This isn't necessary here (one could just pass in the
\r
414 * object) but is required for the overload of this method that
\r
415 * takes a Registrar.
\r
417 void checkService(String requestedLocale, ServiceFacade svc) {
\r
418 checkService(requestedLocale, svc, null, null);
\r
422 * Verify the correct getLocale() behavior for the given service.
\r
423 * @param requestedLocale the locale to request. This MUST BE
\r
424 * FAKE. In other words, it should be something like
\r
425 * en_US_FAKEVARIANT so this method can verify correct fallback
\r
427 * @param svc a factory object that can create the object to be
\r
429 * @param sub an object that can be used to retrieve a subobject
\r
430 * which should also be tested. May be null.
\r
431 * @param reg an object that supplies the registration and
\r
432 * unregistration functionality to be tested. May be null.
\r
434 void checkService(String requestedLocale, ServiceFacade svc,
\r
435 Subobject sub, Registrar reg) {
\r
436 ULocale req = new ULocale(requestedLocale);
\r
437 Object obj = svc.create(req);
\r
438 checkObject(requestedLocale, obj, "gt", "ge");
\r
440 Object subobj = sub.get(obj);
\r
441 checkObject(requestedLocale, subobj, "gt", "ge");
\r
444 logln("Info: Registering service");
\r
445 Object key = reg.register(req, obj);
\r
446 Object objReg = svc.create(req);
\r
447 checkObject(requestedLocale, objReg, "eq", "eq");
\r
449 Object subobj = sub.get(obj);
\r
450 // Assume subobjects don't come from services, so
\r
451 // their metadata should be structured normally.
\r
452 checkObject(requestedLocale, subobj, "gt", "ge");
\r
454 logln("Info: Unregistering service");
\r
455 if (!reg.unregister(key)) {
\r
456 errln("FAIL: unregister failed");
\r
458 Object objUnreg = svc.create(req);
\r
459 checkObject(requestedLocale, objUnreg, "gt", "ge");
\r
462 private static final int LOCALE_SIZE = 9;
\r
463 private static final String[][] rawData2 = new String[][]{
\r
464 /* language code */
\r
465 { "en", "fr", "ca", "el", "no", "zh", "de", "es", "ja" },
\r
467 { "", "", "", "", "", "Hans", "", "", "" },
\r
469 { "US", "FR", "ES", "GR", "NO", "CN", "DE", "", "JP" },
\r
471 { "", "", "", "", "NY", "", "", "", "" },
\r
473 { "en_US", "fr_FR", "ca_ES",
\r
474 "el_GR", "no_NO_NY", "zh_Hans_CN",
\r
475 "de_DE@collation=phonebook", "es@collation=traditional", "ja_JP@calendar=japanese" },
\r
476 /* ISO-3 language */
\r
477 { "eng", "fra", "cat", "ell", "nor", "zho", "deu", "spa", "jpn" },
\r
478 /* ISO-3 country */
\r
479 { "USA", "FRA", "ESP", "GRC", "NOR", "CHN", "DEU", "", "JPN" },
\r
481 { "409", "40c", "403", "408", "814", "804", "407", "a", "411" },
\r
483 /* display language (English) */
\r
484 { "English", "French", "Catalan", "Greek", "Norwegian", "Chinese", "German", "Spanish", "Japanese" },
\r
485 /* display script code (English) */
\r
486 { "", "", "", "", "", "Simplified Han", "", "", "" },
\r
487 /* display country (English) */
\r
488 { "United States", "France", "Spain", "Greece", "Norway", "China", "Germany", "", "Japan" },
\r
489 /* display variant (English) */
\r
490 { "", "", "", "", "NY", "", "", "", "" },
\r
491 /* display name (English) */
\r
492 { "English (United States)", "French (France)", "Catalan (Spain)",
\r
493 "Greek (Greece)", "Norwegian (Norway, NY)", "Chinese (Simplified Han, China)",
\r
494 "German (Germany, Collation=Phonebook Order)", "Spanish (Collation=Traditional)", "Japanese (Japan, Calendar=Japanese Calendar)" },
\r
496 /* display language (French) */
\r
497 { "anglais", "fran\\u00E7ais", "catalan", "grec", "norv\\u00E9gien", "chinois", "allemand", "espagnol", "japonais" },
\r
498 /* display script code (French) */
\r
499 { "", "", "", "", "", "Hans", "", "", "" },
\r
500 /* display country (French) */
\r
501 { "\\u00C9tats-Unis", "France", "Espagne", "Gr\\u00E8ce", "Norv\\u00E8ge", "Chine", "Allemagne", "", "Japon" },
\r
502 /* display variant (French) */
\r
503 { "", "", "", "", "NY", "", "", "", "" },
\r
504 /* display name (French) */
\r
505 { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)",
\r
506 "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "chinois (Hans, Chine)",
\r
507 "allemand (Allemagne, Ordonnancement=Ordre de l'annuaire)", "espagnol (Ordonnancement=Ordre traditionnel)", "japonais (Japon, Calendrier=Calendrier japonais)" },
\r
509 /* display language (Catalan) */
\r
510 { "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec", "noruec", "xin\\u00E9s", "alemany", "espanyol", "japon\\u00E8s" },
\r
511 /* display script code (Catalan) */
\r
512 { "", "", "", "", "", "Hans", "", "", "" },
\r
513 /* display country (Catalan) */
\r
514 { "Estats Units", "Fran\\u00E7a", "Espanya", "Gr\\u00E8cia", "Noruega", "Xina", "Alemanya", "", "Jap\\u00F3" },
\r
515 /* display variant (Catalan) */
\r
516 { "", "", "", "", "NY", "", "", "", "" },
\r
517 /* display name (Catalan) */
\r
518 { "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)",
\r
519 "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "xin\\u00E9s (Hans, Xina)",
\r
520 "alemany (Alemanya, COLLATION=PHONEBOOK)", "espanyol (COLLATION=TRADITIONAL)", "japon\\u00E8s (Jap\\u00F3, CALENDAR=JAPANESE)" },
\r
522 /* display language (Greek) */
\r
524 "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac",
\r
525 "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac",
\r
526 "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac",
\r
527 "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac",
\r
528 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac",
\r
529 "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC",
\r
530 "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
\r
531 "\\u0399\\u03C3\\u03C0\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
\r
532 "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03AC"
\r
534 /* display script code (Greek) */
\r
535 { "", "", "", "", "", "Hans", "", "", "" },
\r
536 /* display country (Greek) */
\r
538 "\\u0397\\u03bd\\u03c9\\u03bc\\u03ad\\u03bd\\u03b5\\u03c2 \\u03a0\\u03bf\\u03bb\\u03b9\\u03c4\\u03b5\\u03af\\u03b5\\u03c2",
\r
539 "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1",
\r
540 "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1",
\r
541 "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1",
\r
542 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1",
\r
543 "\\u039A\\u03AF\\u03BD\\u03B1",
\r
544 "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03AF\\u03B1",
\r
546 "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03AF\\u03B1"
\r
548 /* display variant (Greek) */
\r
549 { "", "", "", "", "NY", "", "", "", "" }, /* TODO: currently there is no translation for NY in Greek fix this test when we have it */
\r
550 /* display name (Greek) */
\r
552 "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03bd\\u03c9\\u03bc\\u03ad\\u03bd\\u03b5\\u03c2 \\u03a0\\u03bf\\u03bb\\u03b9\\u03c4\\u03b5\\u03af\\u03b5\\u03c2)",
\r
553 "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)",
\r
554 "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)",
\r
555 "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)",
\r
556 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)",
\r
557 "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC (Hans, \\u039A\\u03AF\\u03BD\\u03B1)",
\r
558 "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC (\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03AF\\u03B1, COLLATION=PHONEBOOK)",
\r
559 "\\u0399\\u03C3\\u03C0\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC (COLLATION=TRADITIONAL)",
\r
560 "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03AC (\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03AF\\u03B1, CALENDAR=JAPANESE)"
\r
563 // private static final int ENGLISH = 0;
\r
564 // private static final int FRENCH = 1;
\r
565 // private static final int CATALAN = 2;
\r
566 // private static final int GREEK = 3;
\r
567 // private static final int NORWEGIAN = 4;
\r
568 private static final int LANG = 0;
\r
569 private static final int SCRIPT = 1;
\r
570 private static final int CTRY = 2;
\r
571 private static final int VAR = 3;
\r
572 private static final int NAME = 4;
\r
573 // private static final int LANG3 = 5;
\r
574 // private static final int CTRY3 = 6;
\r
575 // private static final int LCID = 7;
\r
576 // private static final int DLANG_EN = 8;
\r
577 // private static final int DSCRIPT_EN = 9;
\r
578 // private static final int DCTRY_EN = 10;
\r
579 // private static final int DVAR_EN = 11;
\r
580 // private static final int DNAME_EN = 12;
\r
581 // private static final int DLANG_FR = 13;
\r
582 // private static final int DSCRIPT_FR = 14;
\r
583 // private static final int DCTRY_FR = 15;
\r
584 // private static final int DVAR_FR = 16;
\r
585 // private static final int DNAME_FR = 17;
\r
586 // private static final int DLANG_CA = 18;
\r
587 // private static final int DSCRIPT_CA = 19;
\r
588 // private static final int DCTRY_CA = 20;
\r
589 // private static final int DVAR_CA = 21;
\r
590 // private static final int DNAME_CA = 22;
\r
591 // private static final int DLANG_EL = 23;
\r
592 // private static final int DSCRIPT_EL = 24;
\r
593 // private static final int DCTRY_EL = 25;
\r
594 // private static final int DVAR_EL = 26;
\r
595 // private static final int DNAME_EL = 27;
\r
597 public void TestBasicGetters() {
\r
599 logln("Testing Basic Getters\n");
\r
600 for (i = 0; i < LOCALE_SIZE; i++) {
\r
601 String testLocale=(rawData2[NAME][i]);
\r
602 logln("Testing "+ testLocale+".....\n");
\r
604 String lang =ULocale.getLanguage(testLocale);
\r
605 if (0 !=lang.compareTo(rawData2[LANG][i])) {
\r
606 errln(" Language code mismatch: "+lang+" versus "+ rawData2[LANG][i]);
\r
609 String ctry=ULocale.getCountry(testLocale);
\r
610 if (0 !=ctry.compareTo(rawData2[CTRY][i])) {
\r
611 errln(" Country code mismatch: "+ctry+" versus "+ rawData2[CTRY][i]);
\r
614 String var=ULocale.getVariant(testLocale);
\r
615 if (0 !=var.compareTo(rawData2[VAR][i])) {
\r
616 errln(" Variant code mismatch: "+var+" versus "+ rawData2[VAR][i]);
\r
619 String name = ULocale.getName(testLocale);
\r
620 if (0 !=name.compareTo(rawData2[NAME][i])) {
\r
621 errln(" Name mismatch: "+name+" versus "+ rawData2[NAME][i]);
\r
627 public void TestPrefixes() {
\r
628 // POSIX ids are no longer handled by getName, so POSIX failures are ignored
\r
629 final String [][] testData = new String[][]{
\r
630 /* null canonicalize() column means "expect same as getName()" */
\r
631 {"sv", "", "FI", "AL", "sv-fi-al", "sv_FI_AL", null},
\r
632 {"en", "", "GB", "", "en-gb", "en_GB", null},
\r
633 {"i-hakka", "", "MT", "XEMXIJA", "i-hakka_MT_XEMXIJA", "i-hakka_MT_XEMXIJA", null},
\r
634 {"i-hakka", "", "CN", "", "i-hakka_CN", "i-hakka_CN", null},
\r
635 {"i-hakka", "", "MX", "", "I-hakka_MX", "i-hakka_MX", null},
\r
636 {"x-klingon", "", "US", "SANJOSE", "X-KLINGON_us_SANJOSE", "x-klingon_US_SANJOSE", null},
\r
638 {"mr", "", "", "", "mr.utf8", "mr.utf8", "mr"},
\r
639 {"de", "", "TV", "", "de-tv.koi8r", "de_TV.koi8r", "de_TV"},
\r
640 {"x-piglatin", "", "ML", "", "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML"}, /* Multibyte English */
\r
641 {"i-cherokee", "","US", "", "i-Cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US"},
\r
642 {"x-filfli", "", "MT", "FILFLA", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA"},
\r
643 {"no", "", "NO", "NY_B", "no-no-ny.utf32@B", "no_NO_NY.utf32@B", "no_NO_NY_B"},
\r
644 {"no", "", "NO", "B", "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B"},
\r
645 {"no", "", "", "NY", "no__ny", "no__NY", null},
\r
646 {"no", "", "", "NY", "no@ny", "no@ny", "no__NY"},
\r
647 {"el", "Latn", "", "", "el-latn", "el_Latn", null},
\r
648 {"en", "Cyrl", "RU", "", "en-cyrl-ru", "en_Cyrl_RU", null},
\r
649 {"zh", "Hant", "TW", "STROKE", "zh-hant_TW_STROKE", "zh_Hant_TW_STROKE", "zh_Hant_TW@collation=stroke"},
\r
650 {"zh", "Hant", "CN", "STROKE", "zh-hant_CN_STROKE", "zh_Hant_CN_STROKE", "zh_Hant_CN@collation=stroke"},
\r
651 {"zh", "Hant", "TW", "PINYIN", "zh-hant_TW_PINYIN", "zh_Hant_TW_PINYIN", "zh_Hant_TW@collation=pinyin"},
\r
652 {"qq", "Qqqq", "QQ", "QQ", "qq_Qqqq_QQ_QQ", "qq_Qqqq_QQ_QQ", null},
\r
653 {"qq", "Qqqq", "", "QQ", "qq_Qqqq__QQ", "qq_Qqqq__QQ", null},
\r
654 {"12", "3456", "78", "90", "12_3456_78_90", "12_3456_78_90", null}, /* total garbage */
\r
657 {"", "", "", "", "@FOO=bar", "@foo=bar", null},
\r
658 {"", "", "", "", "_@FOO=bar", "@foo=bar", null},
\r
659 {"", "", "", "", "__@FOO=bar", "@foo=bar", null},
\r
660 {"", "", "", "FOO", "__foo@FOO=bar", "__FOO@foo=bar", null}, // we have some of these prefixes
\r
663 String loc, buf,buf1;
\r
664 final String [] testTitles = {
\r
665 "ULocale.getLanguage()",
\r
666 "ULocale.getScript()",
\r
667 "ULocale.getCountry()",
\r
668 "ULocale.getVariant()",
\r
670 "ULocale.getName()",
\r
675 for(int row=0;row<testData.length;row++) {
\r
676 loc = testData[row][NAME];
\r
677 logln("Test #"+row+": "+loc);
\r
679 uloc = new ULocale(loc);
\r
681 for(int n=0;n<=(NAME+2);n++) {
\r
682 if(n==NAME) continue;
\r
686 buf = ULocale.getLanguage(loc);
\r
687 buf1 = uloc.getLanguage();
\r
691 buf = ULocale.getScript(loc);
\r
692 buf1 = uloc.getScript();
\r
696 buf = ULocale.getCountry(loc);
\r
697 buf1 = uloc.getCountry();
\r
701 buf = ULocale.getVariant(loc);
\r
706 buf = ULocale.getName(loc);
\r
707 buf1 = uloc.getName();
\r
711 buf = ULocale.canonicalize(loc);
\r
712 buf1 = ULocale.createCanonical(loc).getName();
\r
720 logln("#"+row+": "+testTitles[n]+" on "+loc+": -> ["+buf+"]");
\r
722 String expected = testData[row][n];
\r
723 if (expected == null && n == (NAME+2)) {
\r
724 expected = testData[row][NAME+1];
\r
727 // ignore POSIX failures in getName, we don't spec behavior in this case
\r
729 (expected.indexOf('.') != -1 ||
\r
730 expected.indexOf('@') != -1)) {
\r
734 if(buf.compareTo(expected)!=0) {
\r
735 errln("#"+row+": "+testTitles[n]+" on "+loc+": -> ["+buf+"] (expected '"+expected+"'!)");
\r
737 if(buf1.compareTo(expected)!=0) {
\r
738 errln("#"+row+": "+testTitles[n]+" on ULocale object "+loc+": -> ["+buf1+"] (expected '"+expected+"'!)");
\r
744 public void TestObsoleteNames(){
\r
745 final String[][] tests = new String[][]{
\r
746 /* locale, language3, language2, Country3, country2 */
\r
747 { "eng_USA", "eng", "en", "USA", "US" },
\r
748 { "kok", "kok", "kok", "", "" },
\r
749 { "in", "ind", "in", "", "" },
\r
750 { "id", "ind", "id", "", "" }, /* NO aliasing */
\r
751 { "sh", "srp", "sh", "", "" },
\r
752 { "zz_CS", "", "zz", "SCG", "CS" },
\r
753 { "zz_FX", "", "zz", "FXX", "FX" },
\r
754 { "zz_RO", "", "zz", "ROU", "RO" },
\r
755 { "zz_TP", "", "zz", "TMP", "TP" },
\r
756 { "zz_TL", "", "zz", "TLS", "TL" },
\r
757 { "zz_ZR", "", "zz", "ZAR", "ZR" },
\r
758 { "zz_FXX", "", "zz", "FXX", "FX" }, /* no aliasing. Doesn't go to PS(PSE). */
\r
759 { "zz_ROM", "", "zz", "ROU", "RO" },
\r
760 { "zz_ROU", "", "zz", "ROU", "RO" },
\r
761 { "zz_ZAR", "", "zz", "ZAR", "ZR" },
\r
762 { "zz_TMP", "", "zz", "TMP", "TP" },
\r
763 { "zz_TLS", "", "zz", "TLS", "TL" },
\r
764 { "zz_YUG", "", "zz", "YUG", "YU" },
\r
765 { "mlt_PSE", "mlt", "mt", "PSE", "PS" },
\r
766 { "iw", "heb", "iw", "", "" },
\r
767 { "ji", "yid", "ji", "", "" },
\r
768 { "jw", "jaw", "jw", "", "" },
\r
769 { "sh", "srp", "sh", "", "" },
\r
770 { "", "", "", "", "" }
\r
773 for(int i=0;i<tests.length;i++){
\r
774 String locale = tests[i][0];
\r
775 logln("** Testing : "+ locale);
\r
776 String buff, buff1;
\r
777 ULocale uloc = new ULocale(locale);
\r
779 buff = ULocale.getISO3Language(locale);
\r
780 if(buff.compareTo(tests[i][1])!=0){
\r
781 errln("FAIL: ULocale.getISO3Language("+locale+")=="+
\r
782 buff+",\t expected "+tests[i][1]);
\r
784 logln(" ULocale.getISO3Language("+locale+")=="+buff);
\r
787 buff1 = uloc.getISO3Language();
\r
788 if(buff1.compareTo(tests[i][1])!=0){
\r
789 errln("FAIL: ULocale.getISO3Language("+locale+")=="+
\r
790 buff+",\t expected "+tests[i][1]);
\r
792 logln(" ULocale.getISO3Language("+locale+")=="+buff);
\r
795 buff = ULocale.getLanguage(locale);
\r
796 if(buff.compareTo(tests[i][2])!=0){
\r
797 errln("FAIL: ULocale.getLanguage("+locale+")=="+
\r
798 buff+",\t expected "+tests[i][2]);
\r
800 logln(" ULocale.getLanguage("+locale+")=="+buff);
\r
803 buff = ULocale.getISO3Country(locale);
\r
804 if(buff.compareTo(tests[i][3])!=0){
\r
805 errln("FAIL: ULocale.getISO3Country("+locale+")=="+
\r
806 buff+",\t expected "+tests[i][3]);
\r
808 logln(" ULocale.getISO3Country("+locale+")=="+buff);
\r
811 buff1 = uloc.getISO3Country();
\r
812 if(buff1.compareTo(tests[i][3])!=0){
\r
813 errln("FAIL: ULocale.getISO3Country("+locale+")=="+
\r
814 buff+",\t expected "+tests[i][3]);
\r
816 logln(" ULocale.getISO3Country("+locale+")=="+buff);
\r
819 buff = ULocale.getCountry(locale);
\r
820 if(buff.compareTo(tests[i][4])!=0){
\r
821 errln("FAIL: ULocale.getCountry("+locale+")=="+
\r
822 buff+",\t expected "+tests[i][4]);
\r
824 logln(" ULocale.getCountry("+locale+")=="+buff);
\r
828 if (ULocale.getLanguage("iw_IL").compareTo( ULocale.getLanguage("he_IL"))==0) {
\r
829 errln("he,iw ULocale.getLanguage mismatch");
\r
832 String buff = ULocale.getLanguage("kok_IN");
\r
833 if(buff.compareTo("kok")!=0){
\r
834 errln("ULocale.getLanguage(\"kok\") failed. Expected: kok Got: "+buff);
\r
837 public void TestCanonicalization(){
\r
838 final String[][]testCases = new String[][]{
\r
839 { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" },
\r
840 { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" },
\r
841 { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" },
\r
842 { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=EUR" },
\r
843 { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" },
\r
844 { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" },
\r
845 { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" },
\r
846 { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" },
\r
847 { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" },
\r
848 { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" },
\r
849 { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" },
\r
850 { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" },
\r
851 { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" },
\r
852 { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" },
\r
853 { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" },
\r
854 { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" },
\r
855 { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" },
\r
856 { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" },
\r
857 { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" },
\r
858 { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" },
\r
859 { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" },
\r
860 { "en_GB@EURO", null, "en_GB@currency=EUR" }, /* POSIX ID */
\r
861 { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" },
\r
862 { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" },
\r
863 { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" },
\r
864 { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" },
\r
865 { "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" },
\r
866 { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" },
\r
867 { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" },
\r
868 { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" },
\r
869 { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" },
\r
870 { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" },
\r
871 { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" },
\r
872 { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ },
\r
873 { "no@ny", null, "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */
\r
874 { "no-no.utf32@B", null, "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */
\r
875 { "qz-qz@Euro", null, "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */
\r
876 { "en-BOONT", "en__BOONT", "en__BOONT" }, /* registered name */
\r
877 { "de-1901", "de_1901", "de__1901" }, /* registered name */
\r
878 { "de-1906", "de_1906", "de__1906" }, /* registered name */
\r
879 { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_RS" }, /* .NET name */
\r
880 { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_RS" }, /* .NET name */
\r
881 { "sr_YU_CYRILLIC", "sr_YU_CYRILLIC", "sr_Cyrl_RS" }, /* Linux name */
\r
882 { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */
\r
883 { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */
\r
884 { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */
\r
885 { "zh-CHT", "zh_CHT", "zh_Hant" }, /* .NET name This may change back to zh_Hant */
\r
887 /* posix behavior that used to be performed by getName */
\r
888 { "mr.utf8", null, "mr" },
\r
889 { "de-tv.koi8r", null, "de_TV" },
\r
890 { "x-piglatin_ML.MBE", null, "x-piglatin_ML" },
\r
891 { "i-cherokee_US.utf7", null, "i-cherokee_US" },
\r
892 { "x-filfli_MT_FILFLA.gb-18030", null, "x-filfli_MT_FILFLA" },
\r
893 { "no-no-ny.utf8@B", null, "no_NO_NY_B" /* not: "nn_NO" [alan ICU3.0] */ }, /* @ ignored unless variant is empty */
\r
895 /* fleshing out canonicalization */
\r
896 /* sort keywords, ';' is separator so not present at end in canonical form */
\r
897 { "en_Hant_IL_VALLEY_GIRL@currency=EUR;calendar=Japanese;", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR" },
\r
898 /* already-canonical ids are not changed */
\r
899 { "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR" },
\r
900 /* PRE_EURO and EURO conversions don't affect other keywords */
\r
902 { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" },
\r
903 { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" },
\r
905 /* currency keyword overrides PRE_EURO and EURO currency */
\r
907 { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" },
\r
908 { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" },
\r
910 /* norwegian is just too weird, if we handle things in their full generality */
\r
911 /* this is a negative test to show that we DO NOT handle 'lang=no,var=NY' specially. */
\r
912 { "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ },
\r
914 /* test cases reflecting internal resource bundle usage */
\r
915 /* root is just a language */
\r
916 { "root@kw=foo", "root@kw=foo", "root@kw=foo" },
\r
917 /* level 2 canonicalization should not touch basename when there are keywords and it is null */
\r
918 { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" },
\r
921 for(int i = 0; i< testCases.length;i++){
\r
922 String[] testCase = testCases[i];
\r
923 String source = testCase[0];
\r
924 String level1Expected = testCase[1];
\r
925 String level2Expected = testCase[2];
\r
927 if (level1Expected != null) { // null means we have no expectations for how this case is handled
\r
928 String level1 = ULocale.getName(source);
\r
929 if (!level1.equals(level1Expected)) {
\r
930 errln("ULocale.getName error for: '" + source +
\r
931 "' expected: '" + level1Expected + "' but got: '" + level1 + "'");
\r
933 logln("Ulocale.getName for: '" + source + "' returned: '" + level1 + "'");
\r
936 logln("ULocale.getName skipped: '" + source + "'");
\r
939 if (level2Expected != null) {
\r
940 String level2 = ULocale.canonicalize(source);
\r
941 if(!level2.equals(level2Expected)){
\r
942 errln("ULocale.getName error for: '" + source +
\r
943 "' expected: '" + level2Expected + "' but got: '" + level2 + "'");
\r
945 logln("Ulocale.canonicalize for: '" + source + "' returned: '" + level2 + "'");
\r
948 logln("ULocale.canonicalize skipped: '" + source + "'");
\r
953 public void TestGetAvailable(){
\r
954 ULocale[] locales = ULocale.getAvailableLocales();
\r
955 if(locales.length<10){
\r
956 errln("Did not get the correct result from getAvailableLocales");
\r
958 if(!locales[locales.length-1].equals("zu_ZA")){
\r
959 errln("Did not get the expected result");
\r
963 public void TestDisplayNames() {
\r
964 // consistency check, also check that all data is available
\r
966 ULocale[] locales = ULocale.getAvailableLocales();
\r
967 for (int i = 0; i < locales.length; ++i) {
\r
968 ULocale l = locales[i];
\r
969 String name = l.getDisplayName();
\r
971 logln(l + " --> " + name +
\r
972 ", " + l.getDisplayName(ULocale.GERMAN) +
\r
973 ", " + l.getDisplayName(ULocale.FRANCE));
\r
975 String language = l.getDisplayLanguage();
\r
976 String script = l.getDisplayScript();
\r
977 String country = l.getDisplayCountry();
\r
978 String variant = l.getDisplayVariant();
\r
980 checkName(name, language, script, country, variant, ULocale.getDefault());
\r
982 for (int j = 0; j < locales.length; ++j) {
\r
983 ULocale dl = locales[j];
\r
985 name = l.getDisplayName(dl);
\r
986 language = l.getDisplayLanguage(dl);
\r
987 script = l.getDisplayScript(dl);
\r
988 country = l.getDisplayCountry(dl);
\r
989 variant = l.getDisplayVariant(dl);
\r
991 if (!checkName(name, language, script, country, variant, dl)) {
\r
999 ULocale[] locales = {
\r
1000 ULocale.US, ULocale.GERMANY, ULocale.FRANCE
\r
1002 String[] names = {
\r
1003 "Chinese (China)", "Chinesisch (China)", "chinois (Chine)"
\r
1005 String[] names2 = {
\r
1006 "Simplified Chinese (China)", "Chinesisch (vereinfacht) (China)", "chinois simplifi\u00E9 (Chine)"
\r
1008 ULocale locale = new ULocale("zh_CN");
\r
1009 ULocale locale2 = new ULocale("zh_Hans_CN");
\r
1011 for (int i = 0; i < locales.length; ++i) {
\r
1012 String name = locale.getDisplayName(locales[i]);
\r
1013 if (!names[i].equals(name)) {
\r
1014 errln("expected '" + names[i] + "' but got '" + name + "'");
\r
1017 for (int i = 0; i < locales.length; ++i) {
\r
1018 String name = locale2.getDisplayNameWithDialect(locales[i]);
\r
1019 if (!names2[i].equals(name)) {
\r
1020 errln("expected '" + names2[i] + "' but got '" + name + "'");
\r
1026 private boolean checkName(String name, String language, String script, String country, String variant, ULocale dl) {
\r
1027 if (language.length() > 0 && name.indexOf(language) == -1) {
\r
1028 errln("loc: " + dl + " name '" + name + "' does not contain language '" + language + "'");
\r
1031 if (script.length() > 0 && name.indexOf(script) == -1) {
\r
1032 errln("loc: " + dl + " name '" + name + "' does not contain script '" + script + "'");
\r
1035 if (country.length() > 0 && name.indexOf(country) == -1) {
\r
1036 errln("loc: " + dl + " name '" + name + "' does not contain country '" + country + "'");
\r
1039 if (variant.length() > 0 && name.indexOf(variant) == -1) {
\r
1040 errln("loc: " + dl + " name '" + name + "' does not contain variant '" + variant + "'");
\r
1046 public void TestCoverage() {
\r
1048 //Cover displayXXX
\r
1050 String localeID="zh_CN";
\r
1051 String name, language, script, country, variant;
\r
1052 logln("Covering APIs with signature displayXXX(String, String)");
\r
1053 for (i = 0; i < LOCALE_SIZE; i++) {
\r
1055 String testLocale=(rawData2[NAME][i]);
\r
1057 logln("Testing "+ testLocale+".....");
\r
1058 name = ULocale.getDisplayName(localeID, testLocale);
\r
1059 language = ULocale.getDisplayLanguage(localeID, testLocale);
\r
1060 script = ULocale.getDisplayScript(localeID, testLocale);
\r
1061 country = ULocale.getDisplayCountry(localeID, testLocale);
\r
1062 variant = ULocale.getDisplayVariant(localeID, testLocale);
\r
1064 if (!checkName(name, language, script, country, variant, new ULocale(testLocale))) {
\r
1069 logln("Covering APIs with signature displayXXX(String, ULocale)\n");
\r
1070 for (j = 0; j < LOCALE_SIZE; j++) {
\r
1071 String testLocale=(rawData2[NAME][j]);
\r
1072 ULocale loc = new ULocale(testLocale);
\r
1074 logln("Testing "+ testLocale+".....");
\r
1075 name = ULocale.getDisplayName(localeID, loc);
\r
1076 language = ULocale.getDisplayLanguage(localeID, loc);
\r
1077 script = ULocale.getDisplayScript(localeID, loc);
\r
1078 country = ULocale.getDisplayCountry(localeID, loc);
\r
1079 variant = ULocale.getDisplayVariant(localeID, loc);
\r
1081 if (!checkName(name, language, script, country, variant, loc)) {
\r
1086 ULocale loc1 = new ULocale("en_US_BROOKLYN");
\r
1087 ULocale loc2 = new ULocale("en","US","BROOKLYN");
\r
1088 if (!loc2.equals(loc1)){
\r
1089 errln("ULocale.ULocale(String a, String b, String c)");
\r
1092 ULocale loc3 = new ULocale("en_US");
\r
1093 ULocale loc4 = new ULocale("en","US");
\r
1094 if (!loc4.equals(loc3)){
\r
1095 errln("ULocale.ULocale(String a, String b)");
\r
1098 ULocale loc5 = (ULocale) loc4.clone();
\r
1099 if (!loc5.equals(loc4)){
\r
1100 errln("ULocale.clone should get the same ULocale");
\r
1102 ULocale.getISOCountries(); // To check the result ?!
\r
1105 public void TestBamBm() {
\r
1106 // "bam" shouldn't be there since the official code is 'bm'
\r
1107 String[] isoLanguages = ULocale.getISOLanguages();
\r
1108 for (int i = 0; i < isoLanguages.length; ++i) {
\r
1109 if ("bam".equals(isoLanguages[i])) {
\r
1110 errln("found bam");
\r
1112 if (i > 0 && isoLanguages[i].compareTo(isoLanguages[i-1]) <= 0) {
\r
1113 errln("language list out of order: '" + isoLanguages[i] + " <= " + isoLanguages[i-1]);
\r
1118 public void TestDisplayKeyword() {
\r
1119 //prepare testing data
\r
1121 String[] data = {"en_US@collation=direct;calendar=islamic-civil",
\r
1122 "zh_Hans@collation=pinyin;calendar=chinese",
\r
1123 "foo_Bar_BAZ@collation=traditional;calendar=buddhist"};
\r
1125 for (int i = 0; i < data.length; i++) {
\r
1126 String localeID = data[i];
\r
1128 logln("Testing locale " + localeID + " ...");
\r
1129 ULocale loc = new ULocale(localeID);
\r
1131 Iterator it = loc.getKeywords();
\r
1132 Iterator it2 = ULocale.getKeywords(localeID);
\r
1133 //it and it2 are not equal here. No way to verify their equivalence yet.
\r
1134 while(it.hasNext()) {
\r
1135 String key = (String)it.next();
\r
1136 String key2 = (String)it2.next();
\r
1137 if (!key.equals(key2)) {
\r
1138 errln("FAIL: static and non-static getKeywords returned different results.");
\r
1141 //To verify display of Keyword
\r
1142 // display the above key in English
\r
1143 String s0 = ULocale.getDisplayKeyword(key); //display in default locale
\r
1144 String s1 = ULocale.getDisplayKeyword(key, ULocale.US);
\r
1145 String s2 = ULocale.getDisplayKeyword(key, "en_US");
\r
1146 if (!s1.equals(s2)) {
\r
1147 errln ("FAIL: one of the getDisplayKeyword methods failed.");
\r
1149 if (ULocale.getDefault().equals(ULocale.US) && !s1.equals(s0)) {
\r
1150 errln ("FAIL: getDisplayKeyword methods failed for the default locale.");
\r
1152 if (!s1.equals(h[0].get(key))) {
\r
1153 warnln("Locale " + localeID + " getDisplayKeyword for key: " + key +
\r
1154 " in English expected \"" + h[0].get(key) + "\" saw \"" + s1 + "\" instead");
\r
1156 logln("OK: getDisplayKeyword for key: " + key + " in English got " + s1);
\r
1159 // display the key in S-Chinese
\r
1160 s1 = ULocale.getDisplayKeyword(key, ULocale.CHINA);
\r
1161 s2 = ULocale.getDisplayKeyword(key, "zh_Hans");
\r
1162 if (!s1.equals(s2)) {
\r
1163 errln ("one of the getDisplayKeyword methods failed.");
\r
1165 if (!s1.equals(h[1].get(key))) {
\r
1166 warnln("Locale " + localeID + " getDisplayKeyword for key: " + key +
\r
1167 " in Chinese expected \"" + h[1].get(key) + "\" saw \"" + s1 + "\" instead");
\r
1169 logln("OK: getDisplayKeyword for key: " + key + " in Chinese got " + s1);
\r
1172 //To verify display of Keyword values
\r
1173 String type = loc.getKeywordValue(key);
\r
1174 // display type in English
\r
1175 String ss0 = loc.getDisplayKeywordValue(key);
\r
1176 String ss1 = loc.getDisplayKeywordValue(key, ULocale.US);
\r
1177 String ss2 = ULocale.getDisplayKeywordValue(localeID, key, "en_US");
\r
1178 String ss3 = ULocale.getDisplayKeywordValue(localeID, key, ULocale.US);
\r
1179 if (!ss1.equals(ss2) || !ss1.equals(ss3)) {
\r
1180 errln ("FAIL: one of the getDisplayKeywordValue methods failed.");
\r
1182 if (ULocale.getDefault().equals(ULocale.US) && !ss1.equals(ss0)) {
\r
1183 errln ("FAIL: getDisplayKeyword methods failed for the default locale.");
\r
1185 if (!ss1.equals(h[0].get(type))) {
\r
1186 warnln(" Locale " + localeID + " getDisplayKeywordValue for key: " + key +
\r
1187 " in English expected \"" + h[0].get(type) + "\" saw \"" + ss1 + "\" instead");
\r
1189 logln("OK: getDisplayKeywordValue for key: " + key + " in English got " + ss1);
\r
1192 // display type in Chinese
\r
1193 ss0 = loc.getDisplayKeywordValue(key);
\r
1194 ss1 = loc.getDisplayKeywordValue(key, ULocale.CHINA);
\r
1195 ss2 = ULocale.getDisplayKeywordValue(localeID, key, "zh_Hans");
\r
1196 ss3 = ULocale.getDisplayKeywordValue(localeID, key, ULocale.CHINA);
\r
1197 if (!ss1.equals(ss2) || !ss1.equals(ss3)) {
\r
1198 warnln ("one of the getDisplayKeywordValue methods failed.");
\r
1200 if (!ss1.equals(h[1].get(type))) {
\r
1201 warnln("Locale " + localeID + " getDisplayKeywordValue for key: " + key +
\r
1202 " in Chinese expected \"" + h[1].get(type) + "\" saw \"" + ss1 + "\" instead");
\r
1204 logln("OK: getDisplayKeywordValue for key: " + key + " in Chinese got " + ss1);
\r
1209 private void initHashtable() {
\r
1210 h[0] = new Hashtable();
\r
1211 h[1] = new Hashtable();
\r
1213 //display in English
\r
1214 h[0].put("collation", "collation");
\r
1215 h[0].put("calendar", "calendar");
\r
1216 h[0].put("currency", "Currency");
\r
1217 h[0].put("phonebook", "Phonebook Order");
\r
1218 h[0].put("pinyin", "Simplified Chinese Pinyin Sort Order");
\r
1219 h[0].put("traditional", "Traditional Sort Order");
\r
1220 h[0].put("stroke", "Stroke Order");
\r
1221 h[0].put("direct", "Direct Sort Order");
\r
1222 h[0].put("japanese", "Japanese Calendar");
\r
1223 h[0].put("buddhist", "Buddhist Calendar");
\r
1224 h[0].put("islamic", "Islamic Calendar");
\r
1225 h[0].put("islamic-civil", "Islamic-Civil Calendar" );
\r
1226 h[0].put("hebrew", "Hebrew Calendar");
\r
1227 h[0].put("chinese", "Chinese Calendar");
\r
1228 h[0].put("gregorian", "Gregorian Calendar" );
\r
1230 //display in S-Chinese
\r
1231 h[1].put("collation", "\u5BF9\u7167");
\r
1232 h[1].put("calendar", "\u65E5\u5386");
\r
1233 h[1].put("currency", "\u8D27\u5E01");
\r
1234 h[1].put("direct", "\u987A\u5E8F");
\r
1235 h[1].put("phonebook", "\u7535\u8BDD\u7C3F\u987A\u5E8F");
\r
1236 h[1].put("pinyin", "\u62FC\u97F3\u987a\u5e8f");
\r
1237 h[1].put("stroke", "\u7B14\u5212\u987A\u5E8F");
\r
1238 h[1].put("traditional", "\u4F20\u7EDF\u5386\u6CD5");
\r
1239 h[1].put("japanese", "\u65E5\u672C\u65E5\u5386");
\r
1240 h[1].put("buddhist", "\u4F5B\u6559\u65E5\u5386");
\r
1241 h[1].put("islamic", "\u4F0A\u65AF\u5170\u65E5\u5386");
\r
1242 h[1].put("islamic-civil", "\u4F0A\u65AF\u5170\u5E0C\u5409\u6765\u5386");
\r
1243 h[1].put("hebrew", "\u5E0C\u4F2F\u6765\u65E5\u5386");
\r
1244 h[1].put("chinese", "\u519C\u5386");
\r
1245 h[1].put("gregorian", "\u516C\u5386");
\r
1248 //Hashtables for storing expected display of keys/types of locale in English and Chinese
\r
1249 private static Hashtable[] h = new Hashtable[2];
\r
1251 private static final String ACCEPT_LANGUAGE_TESTS[][] = {
\r
1252 /*# result fallback? */
\r
1253 /*0*/ { "mt_MT", "false" },
\r
1254 /*1*/ { "en", "false" },
\r
1255 /*2*/ { "en", "true" }, // fell back from en-zzz to en
\r
1256 /*3*/ { null, "true" },
\r
1257 /*4*/ { "es", "false" },
\r
1258 /*5*/ { "de", "false" }};
\r
1260 private static final String ACCEPT_LANGUAGE_HTTP[] = {
\r
1261 /*0*/ "mt-mt, ja;q=0.76, en-us;q=0.95, en;q=0.92, en-gb;q=0.89, fr;q=0.87, iu-ca;q=0.84, iu;q=0.82, ja-jp;q=0.79, mt;q=0.97, de-de;q=0.74, de;q=0.71, es;q=0.68, it-it;q=0.66, it;q=0.63, vi-vn;q=0.61, vi;q=0.58, nl-nl;q=0.55, nl;q=0.53, th-th-traditional;q=.01",
\r
1262 /*1*/ "ja;q=0.5, en;q=0.8, tlh",
\r
1263 /*2*/ "en-zzz, de-lx;q=0.8",
\r
1264 /*3*/ "mga-ie;q=0.9, tlh",
\r
1265 /*4*/ "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1266 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1267 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1268 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1269 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1270 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1271 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1272 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1273 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1274 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "+
\r
1276 /*5*/ "de;q=.9, fr;q=.9, xxx-yyy, sr;q=.8"};
\r
1279 public void TestAcceptLanguage() {
\r
1280 for(int i = 0 ; i < (ACCEPT_LANGUAGE_HTTP.length); i++) {
\r
1281 Boolean expectBoolean = new Boolean(ACCEPT_LANGUAGE_TESTS[i][1]);
\r
1282 String expectLocale=ACCEPT_LANGUAGE_TESTS[i][0];
\r
1284 logln("#" + i + ": expecting: " + expectLocale + " (" + expectBoolean + ")");
\r
1286 boolean r[] = { false };
\r
1287 ULocale n = ULocale.acceptLanguage(ACCEPT_LANGUAGE_HTTP[i], r);
\r
1288 if((n==null)&&(expectLocale!=null)) {
\r
1289 errln("result was null! line #" + i);
\r
1292 if(((n==null)&&(expectLocale==null)) || (n.toString().equals(expectLocale))) {
\r
1293 logln(" locale: OK." );
\r
1295 errln("expected " + expectLocale + " but got " + n.toString());
\r
1297 if(expectBoolean.equals(new Boolean(r[0]))) {
\r
1298 logln(" bool: OK.");
\r
1300 errln("bool: not OK, was " + new Boolean(r[0]).toString() + " expected " + expectBoolean.toString());
\r
1305 private ULocale[] StringToULocaleArray(String acceptLanguageList){
\r
1306 //following code is copied from
\r
1307 //ULocale.acceptLanguage(String acceptLanguageList, ULocale[] availableLocales, boolean[] fallback)
\r
1308 class ULocaleAcceptLanguageQ implements Comparable {
\r
1310 private double serial;
\r
1311 public ULocaleAcceptLanguageQ(double theq, int theserial) {
\r
1313 serial = theserial;
\r
1315 public int compareTo(Object o) {
\r
1316 ULocaleAcceptLanguageQ other = (ULocaleAcceptLanguageQ) o;
\r
1317 if(q > other.q) { // reverse - to sort in descending order
\r
1319 } else if(q < other.q) {
\r
1322 if(serial < other.serial) {
\r
1324 } else if(serial > other.serial) {
\r
1327 return 0; // same object
\r
1332 // 1st: parse out the acceptLanguageList into an array
\r
1334 TreeMap map = new TreeMap();
\r
1336 final int l = acceptLanguageList.length();
\r
1338 for(n=0;n<l;n++) {
\r
1339 int itemEnd = acceptLanguageList.indexOf(',',n);
\r
1340 if(itemEnd == -1) {
\r
1343 int paramEnd = acceptLanguageList.indexOf(';',n);
\r
1346 if((paramEnd != -1) && (paramEnd < itemEnd)) {
\r
1347 /* semicolon (;) is closer than end (,) */
\r
1348 int t = paramEnd + 1;
\r
1349 while(UCharacter.isWhitespace(acceptLanguageList.charAt(t))) {
\r
1352 if(acceptLanguageList.charAt(t)=='q') {
\r
1355 while(UCharacter.isWhitespace(acceptLanguageList.charAt(t))) {
\r
1358 if(acceptLanguageList.charAt(t)=='=') {
\r
1361 while(UCharacter.isWhitespace(acceptLanguageList.charAt(t))) {
\r
1365 String val = acceptLanguageList.substring(t,itemEnd).trim();
\r
1366 q = Double.parseDouble(val);
\r
1367 } catch (NumberFormatException nfe) {
\r
1371 q = 1.0; //default
\r
1372 paramEnd = itemEnd;
\r
1375 String loc = acceptLanguageList.substring(n,paramEnd).trim();
\r
1376 int serial = map.size();
\r
1377 ULocaleAcceptLanguageQ entry = new ULocaleAcceptLanguageQ(q,serial);
\r
1378 map.put(entry, new ULocale(ULocale.canonicalize(loc))); // sort in reverse order.. 1.0, 0.9, 0.8 .. etc
\r
1379 n = itemEnd; // get next item. (n++ will skip over delimiter)
\r
1382 // 2. pull out the map
\r
1383 ULocale acceptList[] = (ULocale[])map.values().toArray(new ULocale[map.size()]);
\r
1384 return acceptList;
\r
1387 public void TestAcceptLanguage2() {
\r
1388 for(int i = 0 ; i < (ACCEPT_LANGUAGE_HTTP.length); i++) {
\r
1389 Boolean expectBoolean = new Boolean(ACCEPT_LANGUAGE_TESTS[i][1]);
\r
1390 String expectLocale=ACCEPT_LANGUAGE_TESTS[i][0];
\r
1392 logln("#" + i + ": expecting: " + expectLocale + " (" + expectBoolean + ")");
\r
1394 boolean r[] = { false };
\r
1395 ULocale n = ULocale.acceptLanguage(StringToULocaleArray(ACCEPT_LANGUAGE_HTTP[i]), r);
\r
1396 if((n==null)&&(expectLocale!=null)) {
\r
1397 errln("result was null! line #" + i);
\r
1400 if(((n==null)&&(expectLocale==null)) || (n.toString().equals(expectLocale))) {
\r
1401 logln(" locale: OK." );
\r
1403 errln("expected " + expectLocale + " but got " + n.toString());
\r
1405 if(expectBoolean.equals(new Boolean(r[0]))) {
\r
1406 logln(" bool: OK.");
\r
1408 errln("bool: not OK, was " + new Boolean(r[0]).toString() + " expected " + expectBoolean.toString());
\r
1413 public void TestOrientation() {
\r
1415 String toTest [][] = {
\r
1416 { "ar", "right-to-left", "top-to-bottom" },
\r
1417 { "ar_Arab", "right-to-left", "top-to-bottom" },
\r
1418 { "fa", "right-to-left", "top-to-bottom" },
\r
1419 { "he", "right-to-left", "top-to-bottom" },
\r
1420 { "ps", "right-to-left", "top-to-bottom" },
\r
1421 { "ur", "right-to-left", "top-to-bottom" },
\r
1422 { "en", "left-to-right", "top-to-bottom" }
\r
1425 for (int i = 0; i < toTest.length; ++i) {
\r
1426 ULocale loc = new ULocale(toTest[i][0]);
\r
1427 String co = loc.getCharacterOrientation();
\r
1428 String lo = loc.getLineOrientation();
\r
1429 if (!co.equals(toTest[i][1])) {
\r
1430 errln("Locale \"" + toTest[i][0] + "\" should have \"" + toTest[i][1] + "\" character orientation, but got \'" + co + "\"");
\r
1432 else if (!lo.equals(toTest[i][2])) {
\r
1433 errln("Locale \"" + toTest[i][0] + "\" should have \"" + toTest[i][2] + "\" line orientation, but got \'" + lo + "\"");
\r
1439 public void TestJB3962(){
\r
1440 ULocale loc = new ULocale("de_CH");
\r
1441 String disp = loc.getDisplayName(ULocale.GERMAN);
\r
1442 if(!disp.equals("Deutsch (Schweiz)")){
\r
1443 errln("Did not get the expected display name for de_CH locale. Got: "+ prettify(disp));
\r
1447 public void TestAddLikelySubtags() {
\r
1448 String[][] data = {
\r
1449 {"en", "en_Latn_US"},
\r
1450 {"en_US_BOSTON", "en_Latn_US_BOSTON"},
\r
1451 {"th@calendar=buddhist", "th_Thai_TH@calendar=buddhist"},
\r
1452 {"ar_ZZ", "ar_Arab_EG"},
\r
1453 {"zh", "zh_Hans_CN"},
\r
1454 {"zh_TW", "zh_Hant_TW"},
\r
1455 {"zh_HK", "zh_Hant_HK"},
\r
1456 {"zh_Hant", "zh_Hant_TW"},
\r
1457 {"zh_Zzzz_CN", "zh_Hans_CN"},
\r
1458 {"und_US", "en_Latn_US"},
\r
1459 {"und_HK", "zh_Hant_HK"},
\r
1460 /* Not yet implemented
\r
1461 {"art_lojban", "arg_lojban"},
\r
1462 {"zh_cmn_Hans", "zh_cmn_Hans"},
\r
1465 for (int i = 0; i < data.length; i++) {
\r
1466 ULocale org = new ULocale(data[i][0]);
\r
1467 ULocale res = ULocale.addLikelySubtags(org);
\r
1468 if (!res.toString().equals(data[i][1])) {
\r
1469 errln("Original: " + data[i][0] + " Expected: " + data[i][1] + " - but got " + res.toString());
\r
1473 String[][] basic_maximize_data = {
\r
1493 "en_Kore_ZA_POSIX",
\r
1494 "en_Kore_ZA_POSIX"
\r
1508 "en_Gujr_ZA_POSIX",
\r
1509 "en_Gujr_ZA_POSIX"
\r
1511 "en_US_POSIX_1901",
\r
1512 "en_Latn_US_POSIX_1901"
\r
1514 "en_Latn__POSIX_1901",
\r
1515 "en_Latn_US_POSIX_1901"
\r
1518 "en_Latn_US_POSIX_1901"
\r
1521 "de_Latn_DE_POSIX_1901"
\r
1528 for (int i = 0; i < basic_maximize_data.length; i++) {
\r
1529 ULocale org = new ULocale(basic_maximize_data[i][0]);
\r
1530 ULocale res = ULocale.addLikelySubtags(org);
\r
1531 String exp = basic_maximize_data[i][1];
\r
1532 if (exp.length() == 0) {
\r
1533 if (!org.equals(res)) {
\r
1534 errln("Original: " + basic_maximize_data[i][0] + " expected: " + exp + " - but got " + res.toString());
\r
1537 else if (!res.toString().equals(exp)) {
\r
1538 errln("Original: " + basic_maximize_data[i][0] + " expected: " + exp + " - but got " + res.toString());
\r
1542 String[][] basic_minimize_data = {
\r
1547 "en_Latn_US_POSIX_1901",
\r
1550 "en_Zzzz_US_POSIX_1901",
\r
1553 "de_Latn_DE_POSIX_1901",
\r
1561 for (int i = 0; i < basic_minimize_data.length; i++) {
\r
1562 ULocale org = new ULocale(basic_minimize_data[i][0]);
\r
1563 ULocale res = ULocale.minimizeSubtags(org);
\r
1564 String exp = basic_minimize_data[i][1];
\r
1565 if (exp.length() == 0) {
\r
1566 if (!org.equals(res)) {
\r
1567 errln("Original: " + basic_minimize_data[i][0] + " expected: " + exp + " - but got " + res.toString());
\r
1570 else if (!res.toString().equals(exp)) {
\r
1571 errln("Original: " + basic_minimize_data[i][0] + " expected: " + exp + " - but got " + res.toString());
\r
1575 String[][] full_data = {
\r
1578 /* "ADD-LIKELY", */
\r
1579 /* "REMOVE-LIKELY" */
\r
3647 for (int i = 0; i < full_data.length; i++) {
\r
3648 ULocale org = new ULocale(full_data[i][0]);
\r
3649 ULocale res = ULocale.addLikelySubtags(org);
\r
3650 String exp = full_data[i][1];
\r
3651 if (exp.length() == 0) {
\r
3652 if (!org.equals(res)) {
\r
3653 errln("Original: " + full_data[i][0] + " expected: " + exp + " - but got " + res.toString());
\r
3656 else if (!res.toString().equals(exp)) {
\r
3657 errln("Original: " + full_data[i][0] + " expected: " + exp + " - but got " + res.toString());
\r
3661 for (int i = 0; i < full_data.length; i++) {
\r
3662 String maximal = full_data[i][1];
\r
3664 if (maximal.length() > 0) {
\r
3665 ULocale org = new ULocale(maximal);
\r
3666 ULocale res = ULocale.minimizeSubtags(org);
\r
3667 String exp = full_data[i][2];
\r
3668 if (exp.length() == 0) {
\r
3669 if (!org.equals(res)) {
\r
3670 errln("Original: " + full_data[i][1] + " expected: " + exp + " - but got " + res.toString());
\r
3673 else if (!res.toString().equals(exp)) {
\r
3674 errln("Original: " + full_data[i][1] + " expected: " + exp + " - but got " + res.toString());
\r
3679 public void TestCLDRVersion() {
\r
3680 //VersionInfo zeroVersion = VersionInfo.getInstance(0, 0, 0, 0);
\r
3681 VersionInfo testExpect;
\r
3682 VersionInfo testCurrent;
\r
3683 VersionInfo cldrVersion;
\r
3685 cldrVersion = LocaleData.getCLDRVersion();
\r
3687 this.logln("uloc_getCLDRVersion() returned: '"+cldrVersion+"'");
\r
3689 // why isn't this public for tests somewhere?
\r
3690 final ClassLoader testLoader = ICUResourceBundleTest.class.getClassLoader();
\r
3691 UResourceBundle bundle = (UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", ULocale.ROOT, testLoader);
\r
3693 testExpect = VersionInfo.getInstance(bundle.getString("ExpectCLDRVersionAtLeast"));
\r
3694 testCurrent = VersionInfo.getInstance(bundle.getString("CurrentCLDRVersion"));
\r
3697 logln("(data) ExpectCLDRVersionAtLeast { "+testExpect+"");
\r
3698 if(cldrVersion.compareTo(testExpect)<0) {
\r
3699 errln("CLDR version is too old, expect at least "+testExpect+".");
\r
3702 int r = cldrVersion.compareTo(testCurrent);
\r
3704 logln("CLDR version is behind 'current' (for testdata/root.txt) "+testCurrent+". Some things may fail.\n");
\r
3705 } else if ( r > 0) {
\r
3706 logln("CLDR version is ahead of 'current' (for testdata/root.txt) "+testCurrent+". Some things may fail.\n");
\r
3708 // CLDR version is OK.
\r
3712 public void TestToLanguageTag() {
\r
3713 final String[][] locale_to_langtag = {
\r
3716 {"en_US", "en-US"},
\r
3717 {"iw_IL", "he-IL"},
\r
3718 {"sr_Latn_SR", "sr-Latn-SR"},
\r
3719 {"en__POSIX", "en-posix"},
\r
3720 // {"en_POSIX", "en"}, /* ICU4J locale parser successfully parse en_POSIX as language:en/variant:POSIX */
\r
3721 {"und_555", "und-555"},
\r
3724 {"_Latn", "und-Latn"},
\r
3725 {"_DE", "und-DE"},
\r
3726 {"und_FR", "und-FR"},
\r
3727 {"th_TH_TH", "th-TH-x-variant-th"},
\r
3728 {"bogus", "bogus"},
\r
3729 {"foooobarrr", "und"},
\r
3730 //{"az_AZ_CYRL", "az-cyrl-az"}, /* ICU4J does not have this specia locale mapping */
\r
3731 {"aa_BB_CYRL", "aa-BB-x-variant-cyrl"},
\r
3732 {"en_US_1234", "en-US-1234"},
\r
3733 {"en_US_VARIANTA_VARIANTB", "en-US-varianta-variantb"},
\r
3734 {"en_US_VARIANTB_VARIANTA", "en-US-variantb-varianta"},
\r
3735 {"ja__9876_5432", "ja-9876-5432"},
\r
3736 {"zh_Hant__VAR", "zh-Hant-x-variant-var"},
\r
3737 {"es__BADVARIANT_GOODVAR", "es"},
\r
3738 {"es__GOODVAR_BAD_BADVARIANT", "es-goodvar-x-variant-bad"},
\r
3739 {"en@calendar=gregorian", "en-u-ca-gregory"},
\r
3740 {"de@collation=phonebook;calendar=gregorian", "de-u-ca-gregory-co-phonebk"},
\r
3741 {"th@numbers=thai;z=extz;x=priv-use;a=exta", "th-a-exta-u-nu-thai-z-extz-x-priv-use"},
\r
3742 {"en@timezone=America/New_York;calendar=japanese", "en-u-ca-japanese-tz-usnyc"},
\r
3743 {"en@timezone=US/Eastern", "en-u-tz-usnyc"},
\r
3744 {"en@x=x-y-z;a=a-b-c", "en-x-x-y-z"},
\r
3745 {"it@collation=badcollationtype;colStrength=identical;cu=usd-eur", "it-u-ks-identic"},
\r
3748 for (int i = 0; i < locale_to_langtag.length; i++) {
\r
3749 ULocale loc = new ULocale(locale_to_langtag[i][0]);
\r
3750 String langtag = loc.toLanguageTag();
\r
3751 if (!langtag.equals(locale_to_langtag[i][1])) {
\r
3752 errln("FAIL: toLanguageTag returned language tag [" + langtag + "] for locale ["
\r
3753 + loc + "] - expected: [" + locale_to_langtag[i][1] + "]");
\r
3758 public void TestForLanguageTag() {
\r
3759 final Integer NOERROR = Integer.valueOf(-1);
\r
3761 final Object[][] langtag_to_locale = {
\r
3762 {"en", "en", NOERROR},
\r
3763 {"en-us", "en_US", NOERROR},
\r
3764 {"und-us", "_US", NOERROR},
\r
3765 {"und-latn", "_Latn", NOERROR},
\r
3766 {"en-us-posix", "en_US_POSIX", NOERROR},
\r
3767 {"de-de_euro", "de", Integer.valueOf(3)},
\r
3768 {"kok-in", "kok_IN", NOERROR},
\r
3769 {"123", "", Integer.valueOf(0)},
\r
3770 {"en_us", "", Integer.valueOf(0)},
\r
3771 {"en-latn-x", "en_Latn", Integer.valueOf(8)},
\r
3772 {"art-lojban", "jbo", NOERROR},
\r
3773 {"zh-hakka", "hak", NOERROR},
\r
3774 {"zh-cmn-CH", "cmn_CH", NOERROR},
\r
3775 {"xxx-yy", "xxx_YY", NOERROR},
\r
3776 {"fr-234", "fr_234", NOERROR},
\r
3777 {"i-default", "", NOERROR},
\r
3778 {"i-test", "", Integer.valueOf(0)},
\r
3779 {"ja-jp-jp", "ja_JP", Integer.valueOf(6)},
\r
3780 {"bogus", "bogus", NOERROR},
\r
3781 {"boguslang", "", Integer.valueOf(0)},
\r
3782 {"EN-lATN-us", "en_Latn_US", NOERROR},
\r
3783 {"und-variant-1234", "__VARIANT_1234", NOERROR},
\r
3784 {"und-varzero-var1-vartwo", "__VARZERO", Integer.valueOf(12)},
\r
3785 {"en-u-ca-gregory", "en@calendar=gregorian", NOERROR},
\r
3786 {"en-U-cu-USD", "en@currency=usd", NOERROR},
\r
3787 {"ar-x-1-2-3", "ar@x=1-2-3", NOERROR},
\r
3788 {"fr-u-nu-latn-cu-eur", "fr@currency=eur;numbers=latn", NOERROR},
\r
3789 {"de-k-kext-u-co-phonebk-nu-latn", "de@collation=phonebook;k=kext;numbers=latn", NOERROR},
\r
3790 {"ja-u-cu-jpy-ca-jp", "ja@currency=jpy", Integer.valueOf(15)},
\r
3791 {"en-us-u-tz-usnyc", "en_US@timezone=America/New_York", NOERROR},
\r
3792 {"und-a-abc-def", "@a=abc-def", NOERROR},
\r
3793 {"zh-u-ca-chinese-x-u-ca-chinese", "zh@calendar=chinese;x=u-ca-chinese", NOERROR},
\r
3794 {"fr--FR", "fr", Integer.valueOf(3)},
\r
3795 {"fr-", "fr", Integer.valueOf(3)},
\r
3798 for (int i = 0; i < langtag_to_locale.length; i++) {
\r
3799 String tag = (String)langtag_to_locale[i][0];
\r
3800 ULocale expected = new ULocale((String)langtag_to_locale[i][1]);
\r
3801 ULocale loc = ULocale.forLanguageTag(tag);
\r
3803 if (!loc.equals(expected)) {
\r
3804 errln("FAIL: forLanguageTag returned locale [" + loc + "] for language tag [" + tag
\r
3805 + "] - expected: [" + expected + "]");
\r
3809 // Use locale builder to check errors
\r
3810 for (int i = 0; i < langtag_to_locale.length; i++) {
\r
3811 String tag = (String)langtag_to_locale[i][0];
\r
3812 ULocale expected = new ULocale((String)langtag_to_locale[i][1]);
\r
3813 int errorIdx = ((Integer)langtag_to_locale[i][2]).intValue();
\r
3816 Builder bld = new Builder();
\r
3817 bld.setLanguageTag(tag);
\r
3818 ULocale loc = bld.build();
\r
3820 if (!loc.equals(expected)) {
\r
3821 errln("FAIL: forLanguageTag returned locale [" + loc + "] for language tag [" + tag
\r
3822 + "] - expected: [" + expected + "]");
\r
3824 if (errorIdx != NOERROR.intValue()) {
\r
3825 errln("FAIL: Builder.setLanguageTag should throw an exception for input tag [" + tag + "]");
\r
3827 } catch (IllformedLocaleException ifle) {
\r
3828 if (ifle.getErrorIndex() != errorIdx) {
\r
3829 errln("FAIL: Builder.setLanguageTag returned error index " + ifle.getErrorIndex()
\r
3830 + " for input language tag [" + tag + "] expected: " + errorIdx);
\r
3837 * Test that if you use any locale without keyword that you will get a NULL
\r
3838 * string returned and not throw and exception.
\r
3840 public void Test4735()
\r
3843 new ULocale("und").getDisplayKeywordValue("calendar",ULocale.GERMAN);
\r
3844 new ULocale("en").getDisplayKeywordValue("calendar",ULocale.GERMAN);
\r
3845 } catch (Exception e) {
\r
3846 errln("Unexpected exception: " + e.getMessage());
\r
3850 public void TestGetFallback() {
\r
3851 // Testing static String getFallback(String)
\r
3852 final String[][] TESTIDS =
\r
3854 {"en_US", "en", "", ""}, // ULocale.getFallback("") should return ""
\r
3855 {"EN_us_Var", "en_US", "en", ""}, // Case is always normalized
\r
3856 {"de_DE@collation=phonebook", "de@collation=phonebook", "@collation=phonebook", "@collation=phonebook"}, // Keyword is preserved
\r
3857 {"en__POSIX", "en", ""}, // Trailing empty segment should be truncated
\r
3858 {"_US_POSIX", "_US", ""}, // Same as above
\r
3859 {"root", ""}, // No canonicalization
\r
3862 for (String[] chain : TESTIDS) {
\r
3863 for (int i = 1; i < chain.length; i++) {
\r
3864 String fallback = ULocale.getFallback(chain[i-1]);
\r
3865 assertEquals("getFallback(\"" + chain[i-1] + "\")", chain[i], fallback);
\r
3869 // Testing ULocale getFallback()
\r
3870 final ULocale[][] TESTLOCALES =
\r
3872 {new ULocale("en_US"), new ULocale("en"), ULocale.ROOT, null},
\r
3873 {new ULocale("en__POSIX"), new ULocale("en"), ULocale.ROOT, null},
\r
3874 {new ULocale("de_DE@collation=phonebook"), new ULocale("de@collation=phonebook"), new ULocale("@collation=phonebook"), null},
\r
3875 {new ULocale("_US_POSIX"), new ULocale("_US"), ULocale.ROOT, null},
\r
3876 {new ULocale("root"), ULocale.ROOT, null},
\r
3879 for(ULocale[] chain : TESTLOCALES) {
\r
3880 for (int i = 1; i < chain.length; i++) {
\r
3881 ULocale fallback = chain[i-1].getFallback();
\r
3882 assertEquals("ULocale(" + chain[i-1] + ").getFallback()", chain[i], fallback);
\r