1 /********************************************************************
3 * Copyright (c) 1997-2011, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
8 #include "unicode/decimfmt.h"
9 #include "unicode/ucurr.h"
10 #include "unicode/smpdtfmt.h"
11 #include "unicode/dtfmtsym.h"
12 #include "unicode/brkiter.h"
13 #include "unicode/coll.h"
18 #include "unicode/ustring.h"
20 static const char* const rawData
[33][8] = {
23 { "en", "fr", "ca", "el", "no", "it", "xx", "zh" },
25 { "", "", "", "", "", "", "", "Hans" },
27 { "US", "FR", "ES", "GR", "NO", "", "YY", "CN" },
29 { "", "", "", "", "NY", "", "", "" },
31 { "en_US", "fr_FR", "ca_ES", "el_GR", "no_NO_NY", "it", "xx_YY", "zh_Hans_CN" },
33 { "eng", "fra", "cat", "ell", "nor", "ita", "", "zho" },
35 { "USA", "FRA", "ESP", "GRC", "NOR", "", "", "CHN" },
37 { "409", "40c", "403", "408", "814", "10", "0", "804" },
39 // display langage (English)
40 { "English", "French", "Catalan", "Greek", "Norwegian", "Italian", "xx", "Chinese" },
41 // display script (English)
42 { "", "", "", "", "", "", "", "Simplified Han" },
43 // display country (English)
44 { "United States", "France", "Spain", "Greece", "Norway", "", "YY", "China" },
45 // display variant (English)
46 { "", "", "", "", "NY", "", "", ""},
47 // display name (English)
48 // Updated no_NO_NY English display name for new pattern-based algorithm
49 // (part of Euro support).
50 { "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway, NY)", "Italian", "xx (YY)", "Chinese (Simplified, China)" },
52 // display langage (French)
53 { "anglais", "fran\\u00E7ais", "catalan", "grec", "norv\\u00E9gien", "italien", "xx", "chinois" },
54 // display script (French)
55 { "", "", "", "", "", "", "", "chinois simplifi\\u00E9" },
56 // display country (French)
57 { "\\u00C9tats-Unis", "France", "Espagne", "Gr\\u00E8ce", "Norv\\u00E8ge", "", "YY", "Chine" },
58 // display variant (French)
59 { "", "", "", "", "NY", "", "", "" },
60 // display name (French)
61 //{ "anglais (Etats-Unis)", "francais (France)", "catalan (Espagne)", "grec (Grece)", "norvegien (Norvege,Nynorsk)", "italien", "xx (YY)" },
62 { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "italien", "xx (YY)", "chinois (id\\u00E9ogrammes han simplifi\\u00E9s, Chine)" }, // STILL not right
65 /* display language (Catalan) */
66 { "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec", "noruec", "itali\\u00E0", "", "xin\\u00E8s" },
67 /* display script (Catalan) */
68 { "", "", "", "", "", "", "", "xin\\u00E8s simplificat" },
69 /* display country (Catalan) */
70 { "Estats Units", "Fran\\u00E7a", "Espanya", "Gr\\u00E8cia", "Noruega", "", "", "Xina" },
71 /* display variant (Catalan) */
72 { "", "", "", "", "NY", "", "" },
73 /* display name (Catalan) */
74 { "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)", "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "itali\\u00E0", "", "xin\\u00E8s (simplificat, Xina)" },
76 // display langage (Greek)[actual values listed below]
77 { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac",
78 "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac",
79 "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac",
80 "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac",
81 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac",
82 "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac",
84 "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC"
86 // display script (Greek)
87 { "", "", "", "", "", "", "", "\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03b1 \\u03a7\\u03b1\\u03bd" },
88 // display country (Greek)[actual values listed below]
89 { "\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2 \\u03C4\\u03B7\\u03C2 \\u0391\\u03BC\\u03B5\\u03C1\\u03B9\\u03BA\\u03AE\\u03C2",
90 "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1",
91 "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1",
92 "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1",
93 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1",
96 "\\u039A\\u03AF\\u03BD\\u03B1"
98 // display variant (Greek)
99 { "", "", "", "", "NY", "", "" },
100 // display name (Greek)[actual values listed below]
101 { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2 \\u03C4\\u03B7\\u03C2 \\u0391\\u03BC\\u03B5\\u03C1\\u03B9\\u03BA\\u03AE\\u03C2)",
102 "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)",
103 "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)",
104 "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)",
105 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)",
106 "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac",
108 "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC (\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf \\u039a\\u03b9\\u03bd\\u03b5\\u03b6\\u03b9\\u03ba\\u03cc, \\u039A\\u03AF\\u03BD\\u03B1)"
111 // display langage (<root>)
112 { "English", "French", "Catalan", "Greek", "Norwegian", "Italian", "xx", "" },
113 // display script (<root>)
114 { "", "", "", "", "", "", "", ""},
115 // display country (<root>)
116 { "United States", "France", "Spain", "Greece", "Norway", "", "YY", "" },
117 // display variant (<root>)
118 { "", "", "", "", "Nynorsk", "", "", ""},
119 // display name (<root>)
120 //{ "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
121 { "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)", "" }
127 test_assert( Test (should be TRUE) )
132 the macro is ugly but makes the tests pretty.
135 #define test_assert(test) \
138 errln("FAIL: " #test " was not true. In " __FILE__ " on line %d", __LINE__ ); \
140 logln("PASS: asserted " #test); \
145 test_assert_print( Test (should be TRUE), printable )
148 test_assert(i==3, toString(i));
150 the macro is ugly but makes the tests pretty.
153 #define test_assert_print(test,print) \
156 errln("FAIL: " #test " was not true. " + UnicodeString(print) ); \
158 logln("PASS: asserted " #test "-> " + UnicodeString(print)); \
162 #define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
164 LocaleTest::LocaleTest()
170 LocaleTest::~LocaleTest()
172 if (dataTable
!= 0) {
173 for (int32_t i
= 0; i
< 33; i
++) {
174 delete []dataTable
[i
];
181 void LocaleTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
184 TESTCASE(0, TestBasicGetters
);
185 TESTCASE(1, TestSimpleResourceInfo
);
186 TESTCASE(2, TestDisplayNames
);
187 TESTCASE(3, TestSimpleObjectStuff
);
188 TESTCASE(4, TestPOSIXParsing
);
189 TESTCASE(5, TestGetAvailableLocales
);
190 TESTCASE(6, TestDataDirectory
);
191 TESTCASE(7, TestISO3Fallback
);
192 TESTCASE(8, TestGetLangsAndCountries
);
193 TESTCASE(9, TestSimpleDisplayNames
);
194 TESTCASE(10, TestUninstalledISO3Names
);
195 TESTCASE(11, TestAtypicalLocales
);
196 #if !UCONFIG_NO_FORMATTING
197 TESTCASE(12, TestThaiCurrencyFormat
);
198 TESTCASE(13, TestEuroSupport
);
200 TESTCASE(14, TestToString
);
201 #if !UCONFIG_NO_FORMATTING
202 TESTCASE(15, Test4139940
);
203 TESTCASE(16, Test4143951
);
205 TESTCASE(17, Test4147315
);
206 TESTCASE(18, Test4147317
);
207 TESTCASE(19, Test4147552
);
208 TESTCASE(20, TestVariantParsing
);
209 #if !UCONFIG_NO_FORMATTING
210 TESTCASE(21, Test4105828
);
212 TESTCASE(22, TestSetIsBogus
);
213 TESTCASE(23, TestParallelAPIValues
);
214 TESTCASE(24, TestKeywordVariants
);
215 TESTCASE(25, TestKeywordVariantParsing
);
216 TESTCASE(26, TestSetKeywordValue
);
217 TESTCASE(27, TestGetBaseName
);
218 #if !UCONFIG_NO_FILE_IO
219 TESTCASE(28, TestGetLocale
);
221 TESTCASE(29, TestVariantWithOutCountry
);
222 TESTCASE(30, TestCanonicalization
);
223 TESTCASE(31, TestCurrencyByDate
);
224 TESTCASE(32, TestGetVariantWithKeywords
);
226 // keep the last index in sync with the condition in default:
229 if (index
<= 28) { // keep this in sync with the last index!
230 name
= "(test omitted by !UCONFIG_NO_FORMATTING)";
234 break; //needed to end loop
238 void LocaleTest::TestBasicGetters() {
242 for (i
= 0; i
<= MAX_LOCALES
; i
++) {
243 Locale
testLocale("");
244 if (rawData
[SCRIPT
][i
] && rawData
[SCRIPT
][i
][0] != 0) {
245 testLocale
= Locale(rawData
[LANG
][i
], rawData
[SCRIPT
][i
], rawData
[CTRY
][i
], rawData
[VAR
][i
]);
248 testLocale
= Locale(rawData
[LANG
][i
], rawData
[CTRY
][i
], rawData
[VAR
][i
]);
250 logln("Testing " + (UnicodeString
)testLocale
.getName() + "...");
252 if ( (temp
=testLocale
.getLanguage()) != (dataTable
[LANG
][i
]))
253 errln(" Language code mismatch: " + temp
+ " versus "
254 + dataTable
[LANG
][i
]);
255 if ( (temp
=testLocale
.getScript()) != (dataTable
[SCRIPT
][i
]))
256 errln(" Script code mismatch: " + temp
+ " versus "
257 + dataTable
[SCRIPT
][i
]);
258 if ( (temp
=testLocale
.getCountry()) != (dataTable
[CTRY
][i
]))
259 errln(" Country code mismatch: " + temp
+ " versus "
260 + dataTable
[CTRY
][i
]);
261 if ( (temp
=testLocale
.getVariant()) != (dataTable
[VAR
][i
]))
262 errln(" Variant code mismatch: " + temp
+ " versus "
263 + dataTable
[VAR
][i
]);
264 if ( (temp
=testLocale
.getName()) != (dataTable
[NAME
][i
]))
265 errln(" Locale name mismatch: " + temp
+ " versus "
266 + dataTable
[NAME
][i
]);
269 logln("Same thing without variant codes...");
270 for (i
= 0; i
<= MAX_LOCALES
; i
++) {
271 Locale
testLocale("");
272 if (rawData
[SCRIPT
][i
] && rawData
[SCRIPT
][i
][0] != 0) {
273 testLocale
= Locale(rawData
[LANG
][i
], rawData
[SCRIPT
][i
], rawData
[CTRY
][i
]);
276 testLocale
= Locale(rawData
[LANG
][i
], rawData
[CTRY
][i
]);
278 logln("Testing " + (temp
=testLocale
.getName()) + "...");
280 if ( (temp
=testLocale
.getLanguage()) != (dataTable
[LANG
][i
]))
281 errln("Language code mismatch: " + temp
+ " versus "
282 + dataTable
[LANG
][i
]);
283 if ( (temp
=testLocale
.getScript()) != (dataTable
[SCRIPT
][i
]))
284 errln("Script code mismatch: " + temp
+ " versus "
285 + dataTable
[SCRIPT
][i
]);
286 if ( (temp
=testLocale
.getCountry()) != (dataTable
[CTRY
][i
]))
287 errln("Country code mismatch: " + temp
+ " versus "
288 + dataTable
[CTRY
][i
]);
289 if (testLocale
.getVariant()[0] != 0)
290 errln("Variant code mismatch: something versus \"\"");
293 logln("Testing long language names and getters");
294 Locale test8
= Locale::createFromName("x-klingon-latn-zx.utf32be@special");
296 temp
= test8
.getLanguage();
297 if (temp
!= UnicodeString("x-klingon") )
298 errln("Language code mismatch: " + temp
+ " versus \"x-klingon\"");
300 temp
= test8
.getScript();
301 if (temp
!= UnicodeString("Latn") )
302 errln("Script code mismatch: " + temp
+ " versus \"Latn\"");
304 temp
= test8
.getCountry();
305 if (temp
!= UnicodeString("ZX") )
306 errln("Country code mismatch: " + temp
+ " versus \"ZX\"");
308 temp
= test8
.getVariant();
309 //if (temp != UnicodeString("SPECIAL") )
310 // errln("Variant code mismatch: " + temp + " versus \"SPECIAL\"");
311 // As of 3.0, the "@special" will *not* be parsed by uloc_getName()
312 if (temp
!= UnicodeString("") )
313 errln("Variant code mismatch: " + temp
+ " versus \"\"");
315 if (Locale::getDefault() != Locale::createFromName(NULL
))
316 errln("Locale::getDefault() == Locale::createFromName(NULL)");
319 // NOTE: There used to be a special test for locale names that had language or
320 // country codes that were longer than two letters. The new version of Locale
321 // doesn't support anything that isn't an officially recognized language or
322 // country code, so we no longer support this feature.
324 Locale
bogusLang("THISISABOGUSLANGUAGE"); // Jitterbug 2864: language code too long
325 if(!bogusLang
.isBogus()) {
326 errln("Locale(\"THISISABOGUSLANGUAGE\").isBogus()==FALSE");
329 bogusLang
=Locale("eo");
330 if( bogusLang
.isBogus() ||
331 strcmp(bogusLang
.getLanguage(), "eo")!=0 ||
332 *bogusLang
.getCountry()!=0 ||
333 *bogusLang
.getVariant()!=0 ||
334 strcmp(bogusLang
.getName(), "eo")!=0
336 errln("assignment to bogus Locale does not unbogus it or sets bad data");
339 Locale
a("eo_DE@currency=DEM");
340 Locale
*pb
=a
.clone();
341 if(pb
==&a
|| *pb
!=a
) {
342 errln("Locale.clone() failed");
347 void LocaleTest::TestParallelAPIValues() {
348 logln("Test synchronization between C and C++ API");
349 if (strcmp(Locale::getChinese().getName(), ULOC_CHINESE
) != 0) {
350 errln("Differences for ULOC_CHINESE Locale");
352 if (strcmp(Locale::getEnglish().getName(), ULOC_ENGLISH
) != 0) {
353 errln("Differences for ULOC_ENGLISH Locale");
355 if (strcmp(Locale::getFrench().getName(), ULOC_FRENCH
) != 0) {
356 errln("Differences for ULOC_FRENCH Locale");
358 if (strcmp(Locale::getGerman().getName(), ULOC_GERMAN
) != 0) {
359 errln("Differences for ULOC_GERMAN Locale");
361 if (strcmp(Locale::getItalian().getName(), ULOC_ITALIAN
) != 0) {
362 errln("Differences for ULOC_ITALIAN Locale");
364 if (strcmp(Locale::getJapanese().getName(), ULOC_JAPANESE
) != 0) {
365 errln("Differences for ULOC_JAPANESE Locale");
367 if (strcmp(Locale::getKorean().getName(), ULOC_KOREAN
) != 0) {
368 errln("Differences for ULOC_KOREAN Locale");
370 if (strcmp(Locale::getSimplifiedChinese().getName(), ULOC_SIMPLIFIED_CHINESE
) != 0) {
371 errln("Differences for ULOC_SIMPLIFIED_CHINESE Locale");
373 if (strcmp(Locale::getTraditionalChinese().getName(), ULOC_TRADITIONAL_CHINESE
) != 0) {
374 errln("Differences for ULOC_TRADITIONAL_CHINESE Locale");
378 if (strcmp(Locale::getCanada().getName(), ULOC_CANADA
) != 0) {
379 errln("Differences for ULOC_CANADA Locale");
381 if (strcmp(Locale::getCanadaFrench().getName(), ULOC_CANADA_FRENCH
) != 0) {
382 errln("Differences for ULOC_CANADA_FRENCH Locale");
384 if (strcmp(Locale::getChina().getName(), ULOC_CHINA
) != 0) {
385 errln("Differences for ULOC_CHINA Locale");
387 if (strcmp(Locale::getPRC().getName(), ULOC_PRC
) != 0) {
388 errln("Differences for ULOC_PRC Locale");
390 if (strcmp(Locale::getFrance().getName(), ULOC_FRANCE
) != 0) {
391 errln("Differences for ULOC_FRANCE Locale");
393 if (strcmp(Locale::getGermany().getName(), ULOC_GERMANY
) != 0) {
394 errln("Differences for ULOC_GERMANY Locale");
396 if (strcmp(Locale::getItaly().getName(), ULOC_ITALY
) != 0) {
397 errln("Differences for ULOC_ITALY Locale");
399 if (strcmp(Locale::getJapan().getName(), ULOC_JAPAN
) != 0) {
400 errln("Differences for ULOC_JAPAN Locale");
402 if (strcmp(Locale::getKorea().getName(), ULOC_KOREA
) != 0) {
403 errln("Differences for ULOC_KOREA Locale");
405 if (strcmp(Locale::getTaiwan().getName(), ULOC_TAIWAN
) != 0) {
406 errln("Differences for ULOC_TAIWAN Locale");
408 if (strcmp(Locale::getUK().getName(), ULOC_UK
) != 0) {
409 errln("Differences for ULOC_UK Locale");
411 if (strcmp(Locale::getUS().getName(), ULOC_US
) != 0) {
412 errln("Differences for ULOC_US Locale");
417 void LocaleTest::TestSimpleResourceInfo() {
420 UErrorCode err
= U_ZERO_ERROR
;
423 for (i
= 0; i
<= MAX_LOCALES
; i
++) {
424 Locale
testLocale(rawData
[LANG
][i
], rawData
[CTRY
][i
], rawData
[VAR
][i
]);
425 logln("Testing " + (temp
=testLocale
.getName()) + "...");
427 if ( (temp
=testLocale
.getISO3Language()) != (dataTable
[LANG3
][i
]))
428 errln(" ISO-3 language code mismatch: " + temp
429 + " versus " + dataTable
[LANG3
][i
]);
430 if ( (temp
=testLocale
.getISO3Country()) != (dataTable
[CTRY3
][i
]))
431 errln(" ISO-3 country code mismatch: " + temp
432 + " versus " + dataTable
[CTRY3
][i
]);
434 sprintf(temp2
, "%x", (int)testLocale
.getLCID());
435 if (UnicodeString(temp2
) != dataTable
[LCID
][i
])
436 errln((UnicodeString
)" LCID mismatch: " + temp2
+ " versus "
437 + dataTable
[LCID
][i
]);
441 errln((UnicodeString
)"Some error on number " + i
+ u_errorName(err
));
447 if(strcmp(locale
.getName(), "en") != 0||
448 strcmp(locale
.getLanguage(), "en") != 0) {
449 errln("construction of Locale(en) failed\n");
456 * Jitterbug 2439 -- markus 20030425
458 * The lookup of display names must not fall back through the default
459 * locale because that yields useless results.
462 LocaleTest::TestDisplayNames()
464 Locale
english("en", "US");
465 Locale
french("fr", "FR");
466 Locale
croatian("ca", "ES");
467 Locale
greek("el", "GR");
469 logln(" In locale = en_US...");
470 doTestDisplayNames(english
, DLANG_EN
);
471 logln(" In locale = fr_FR...");
472 doTestDisplayNames(french
, DLANG_FR
);
473 logln(" In locale = ca_ES...");
474 doTestDisplayNames(croatian
, DLANG_CA
);
475 logln(" In locale = el_GR...");
476 doTestDisplayNames(greek
, DLANG_EL
);
479 UErrorCode status
= U_ZERO_ERROR
;
481 #if !UCONFIG_NO_FORMATTING
482 DecimalFormatSymbols
symb(status
);
483 /* Check to see if ICU supports this locale */
484 if (symb
.getLocale(ULOC_VALID_LOCALE
, status
) != Locale("root")) {
485 /* test that the default locale has a display name for its own language */
486 /* Currently, there is no language information in the "tl" data file so this test will fail if default locale is "tl" */
487 if (uprv_strcmp(Locale().getLanguage(), "tl") != 0) {
488 Locale().getDisplayLanguage(Locale(), s
);
489 if(s
.length()<=3 && s
.charAt(0)<=0x7f) {
490 /* check <=3 to reject getting the language code as a display name */
491 dataerrln("unable to get a display string for the language of the default locale: " + s
);
495 * API coverage improvements: call
496 * Locale::getDisplayLanguage(UnicodeString &) and
497 * Locale::getDisplayCountry(UnicodeString &)
500 Locale().getDisplayLanguage(s
);
501 if(s
.length()<=3 && s
.charAt(0)<=0x7f) {
502 dataerrln("unable to get a display string for the language of the default locale [2]: " + s
);
507 logln("Default locale %s is unsupported by ICU\n", Locale().getName());
512 french
.getDisplayCountry(s
);
514 errln("unable to get any default-locale display string for the country of fr_FR\n");
517 Locale("zh", "Hant").getDisplayScript(s
);
519 errln("unable to get any default-locale display string for the country of zh_Hant\n");
523 void LocaleTest::TestSimpleObjectStuff() {
524 Locale
test1("aa", "AA");
525 Locale
test2("aa", "AA");
527 Locale
test4("zz", "ZZ");
528 Locale
test5("aa", "AA", "");
529 Locale
test6("aa", "AA", "ANTARES");
530 Locale
test7("aa", "AA", "JUPITER");
531 Locale test8
= Locale::createFromName("aa-aa-jupiTER"); // was "aa-aa.utf8@jupiter" but in 3.0 getName won't normalize that
533 // now list them all for debugging usage.
534 test_dumpLocale(test1
);
535 test_dumpLocale(test2
);
536 test_dumpLocale(test3
);
537 test_dumpLocale(test4
);
538 test_dumpLocale(test5
);
539 test_dumpLocale(test6
);
540 test_dumpLocale(test7
);
541 test_dumpLocale(test8
);
543 // Make sure things compare to themselves!
544 test_assert(test1
== test1
);
545 test_assert(test2
== test2
);
546 test_assert(test3
== test3
);
547 test_assert(test4
== test4
);
548 test_assert(test5
== test5
);
549 test_assert(test6
== test6
);
550 test_assert(test7
== test7
);
551 test_assert(test8
== test8
);
553 // make sure things are not equal to themselves.
554 test_assert(!(test1
!= test1
));
555 test_assert(!(test2
!= test2
));
556 test_assert(!(test3
!= test3
));
557 test_assert(!(test4
!= test4
));
558 test_assert(!(test5
!= test5
));
559 test_assert(!(test6
!= test6
));
560 test_assert(!(test7
!= test7
));
561 test_assert(!(test8
!= test8
));
563 // make sure things that are equal to each other don't show up as unequal.
564 test_assert(!(test1
!= test2
));
565 test_assert(!(test2
!= test1
));
566 test_assert(!(test1
!= test3
));
567 test_assert(!(test2
!= test3
));
568 test_assert(test5
== test1
);
569 test_assert(test6
!= test2
);
570 test_assert(test6
!= test5
);
572 test_assert(test6
!= test7
);
574 // test for things that shouldn't compare equal.
575 test_assert(!(test1
== test4
));
576 test_assert(!(test2
== test4
));
577 test_assert(!(test3
== test4
));
579 test_assert(test7
== test8
);
581 // test for hash codes to be the same.
582 int32_t hash1
= test1
.hashCode();
583 int32_t hash2
= test2
.hashCode();
584 int32_t hash3
= test3
.hashCode();
586 test_assert(hash1
== hash2
);
587 test_assert(hash1
== hash3
);
588 test_assert(hash2
== hash3
);
590 // test that the assignment operator works.
592 logln("test4=test1;");
593 test_dumpLocale(test4
);
594 test_assert(test4
== test4
);
596 test_assert(!(test1
!= test4
));
597 test_assert(!(test2
!= test4
));
598 test_assert(!(test3
!= test4
));
599 test_assert(test1
== test4
);
600 test_assert(test4
== test1
);
602 // test assignments with a variant
603 logln("test7 = test6");
605 test_dumpLocale(test7
);
606 test_assert(test7
== test7
);
607 test_assert(test7
== test6
);
608 test_assert(test7
!= test5
);
610 logln("test6 = test1");
612 test_dumpLocale(test6
);
613 test_assert(test6
!= test7
);
614 test_assert(test6
== test1
);
615 test_assert(test6
== test6
);
618 // A class which exposes constructors that are implemented in terms of the POSIX parsing code.
619 class POSIXLocale
: public Locale
622 POSIXLocale(const UnicodeString
& l
)
626 ch
= new char[l
.length() + 1];
627 ch
[l
.extract(0, 0x7fffffff, ch
, "")] = 0;
631 POSIXLocale(const char *l
)
638 void LocaleTest::TestPOSIXParsing()
640 POSIXLocale
test1("ab_AB");
641 POSIXLocale
test2(UnicodeString("ab_AB"));
642 Locale
test3("ab","AB");
644 POSIXLocale
test4("ab_AB_Antares");
645 POSIXLocale
test5(UnicodeString("ab_AB_Antares"));
646 Locale
test6("ab", "AB", "Antares");
648 test_dumpLocale(test1
);
649 test_dumpLocale(test2
);
650 test_dumpLocale(test3
);
651 test_dumpLocale(test4
);
652 test_dumpLocale(test5
);
653 test_dumpLocale(test6
);
655 test_assert(test1
== test1
);
657 test_assert(test1
== test2
);
658 test_assert(test2
== test3
);
659 test_assert(test3
== test1
);
661 test_assert(test4
== test5
);
662 test_assert(test5
== test6
);
663 test_assert(test6
== test4
);
665 test_assert(test1
!= test4
);
666 test_assert(test5
!= test3
);
667 test_assert(test5
!= test2
);
669 int32_t hash1
= test1
.hashCode();
670 int32_t hash2
= test2
.hashCode();
671 int32_t hash3
= test3
.hashCode();
673 test_assert(hash1
== hash2
);
674 test_assert(hash2
== hash3
);
675 test_assert(hash3
== hash1
);
678 void LocaleTest::TestGetAvailableLocales()
680 int32_t locCount
= 0;
681 const Locale
* locList
= Locale::getAvailableLocales(locCount
);
684 dataerrln("getAvailableLocales() returned an empty list!");
686 logln(UnicodeString("Number of locales returned = ") + locCount
);
688 for(int32_t i
= 0; i
< locCount
; ++i
)
689 logln(locList
[i
].getName());
691 // I have no idea how to test this function...
694 // This test isn't applicable anymore - getISO3Language is
695 // independent of the data directory
696 void LocaleTest::TestDataDirectory()
699 char oldDirectory[80];
701 UErrorCode err = U_ZERO_ERROR;
702 UnicodeString testValue;
704 temp = Locale::getDataDirectory();
705 strcpy(oldDirectory, temp);
706 logln(UnicodeString("oldDirectory = ") + oldDirectory);
708 Locale test(Locale::US);
709 test.getISO3Language(testValue);
710 logln("first fetch of language retrieved " + testValue);
711 if (testValue != "eng")
712 errln("Initial check of ISO3 language failed: expected \"eng\", got \"" + testValue + "\"");
716 path=IntlTest::getTestDirectory();
717 Locale::setDataDirectory( path );
720 test.getISO3Language(testValue);
721 logln("second fetch of language retrieved " + testValue);
722 if (testValue != "xxx")
723 errln("setDataDirectory() failed: expected \"xxx\", got \"" + testValue + "\"");
725 Locale::setDataDirectory(oldDirectory);
726 test.getISO3Language(testValue);
727 logln("third fetch of language retrieved " + testValue);
728 if (testValue != "eng")
729 errln("get/setDataDirectory() failed: expected \"eng\", got \"" + testValue + "\"");
733 //===========================================================
735 void LocaleTest::doTestDisplayNames(Locale
& displayLocale
, int32_t compareIndex
) {
738 for (int32_t i
= 0; i
<= MAX_LOCALES
; i
++) {
739 Locale
testLocale("");
740 if (rawData
[SCRIPT
][i
] && rawData
[SCRIPT
][i
][0] != 0) {
741 testLocale
= Locale(rawData
[LANG
][i
], rawData
[SCRIPT
][i
], rawData
[CTRY
][i
], rawData
[VAR
][i
]);
744 testLocale
= Locale(rawData
[LANG
][i
], rawData
[CTRY
][i
], rawData
[VAR
][i
]);
746 logln(" Testing " + (temp
=testLocale
.getName()) + "...");
748 UnicodeString testLang
;
749 UnicodeString testScript
;
750 UnicodeString testCtry
;
751 UnicodeString testVar
;
752 UnicodeString testName
;
754 testLocale
.getDisplayLanguage(displayLocale
, testLang
);
755 testLocale
.getDisplayScript(displayLocale
, testScript
);
756 testLocale
.getDisplayCountry(displayLocale
, testCtry
);
757 testLocale
.getDisplayVariant(displayLocale
, testVar
);
758 testLocale
.getDisplayName(displayLocale
, testName
);
760 UnicodeString expectedLang
;
761 UnicodeString expectedScript
;
762 UnicodeString expectedCtry
;
763 UnicodeString expectedVar
;
764 UnicodeString expectedName
;
766 expectedLang
= dataTable
[compareIndex
][i
];
767 if (expectedLang
.length() == 0)
768 expectedLang
= dataTable
[DLANG_EN
][i
];
770 expectedScript
= dataTable
[compareIndex
+ 1][i
];
771 if (expectedScript
.length() == 0)
772 expectedScript
= dataTable
[DSCRIPT_EN
][i
];
774 expectedCtry
= dataTable
[compareIndex
+ 2][i
];
775 if (expectedCtry
.length() == 0)
776 expectedCtry
= dataTable
[DCTRY_EN
][i
];
778 expectedVar
= dataTable
[compareIndex
+ 3][i
];
779 if (expectedVar
.length() == 0)
780 expectedVar
= dataTable
[DVAR_EN
][i
];
782 expectedName
= dataTable
[compareIndex
+ 4][i
];
783 if (expectedName
.length() == 0)
784 expectedName
= dataTable
[DNAME_EN
][i
];
786 if (testLang
!= expectedLang
)
787 dataerrln("Display language (" + UnicodeString(displayLocale
.getName()) + ") of (" + UnicodeString(testLocale
.getName()) + ") got " + testLang
+ " expected " + expectedLang
);
788 if (testScript
!= expectedScript
)
789 dataerrln("Display script (" + UnicodeString(displayLocale
.getName()) + ") of (" + UnicodeString(testLocale
.getName()) + ") got " + testScript
+ " expected " + expectedScript
);
790 if (testCtry
!= expectedCtry
)
791 dataerrln("Display country (" + UnicodeString(displayLocale
.getName()) + ") of (" + UnicodeString(testLocale
.getName()) + ") got " + testCtry
+ " expected " + expectedCtry
);
792 if (testVar
!= expectedVar
)
793 dataerrln("Display variant (" + UnicodeString(displayLocale
.getName()) + ") of (" + UnicodeString(testLocale
.getName()) + ") got " + testVar
+ " expected " + expectedVar
);
794 if (testName
!= expectedName
)
795 dataerrln("Display name (" + UnicodeString(displayLocale
.getName()) + ") of (" + UnicodeString(testLocale
.getName()) + ") got " + testName
+ " expected " + expectedName
);
799 //---------------------------------------------------
800 // table of valid data
801 //---------------------------------------------------
805 void LocaleTest::setUpDataTable()
807 if (dataTable
== 0) {
808 dataTable
= new UnicodeString
*[33];
810 for (int32_t i
= 0; i
< 33; i
++) {
811 dataTable
[i
] = new UnicodeString
[8];
812 for (int32_t j
= 0; j
< 8; j
++) {
813 dataTable
[i
][j
] = CharsToUnicodeString(rawData
[i
][j
]);
819 // ====================
823 * @bug 4011756 4011380
826 LocaleTest::TestISO3Fallback()
828 Locale
test("xx", "YY");
832 result
= test
.getISO3Language();
834 // Conform to C API usage
836 if (!result
|| (result
[0] != 0))
837 errln("getISO3Language() on xx_YY returned " + UnicodeString(result
) + " instead of \"\"");
839 result
= test
.getISO3Country();
841 if (!result
|| (result
[0] != 0))
842 errln("getISO3Country() on xx_YY returned " + UnicodeString(result
) + " instead of \"\"");
846 * @bug 4106155 4118587
849 LocaleTest::TestGetLangsAndCountries()
851 // It didn't seem right to just do an exhaustive test of everything here, so I check
852 // for the following things:
853 // 1) Does each list have the right total number of entries?
854 // 2) Does each list contain certain language and country codes we think are important
855 // (the G7 countries, plus a couple others)?
856 // 3) Does each list have every entry formatted correctly? (i.e., two characters,
857 // all lower case for the language codes, all upper case for the country codes)
858 // 4) Is each list in sorted order?
859 int32_t testCount
= 0;
860 const char * const * test
= Locale::getISOLanguages();
861 const char spotCheck1
[ ][4] = { "en", "es", "fr", "de", "it",
862 "ja", "ko", "zh", "th", "he",
863 "id", "iu", "ug", "yi", "za" };
867 for(testCount
= 0;test
[testCount
];testCount
++)
870 /* TODO: Change this test to be more like the cloctst version? */
871 if (testCount
!= 536)
872 errln("Expected getISOLanguages() to return 536 languages; it returned %d", testCount
);
874 for (i
= 0; i
< 15; i
++) {
876 for (j
= 0; j
< testCount
; j
++)
877 if (uprv_strcmp(test
[j
],spotCheck1
[i
])== 0)
879 if (j
== testCount
|| (uprv_strcmp(test
[j
],spotCheck1
[i
])!=0))
880 errln("Couldn't find " + (UnicodeString
)spotCheck1
[i
] + " in language list.");
883 for (i
= 0; i
< testCount
; i
++) {
884 UnicodeString
testee(test
[i
],"");
885 UnicodeString
lc(test
[i
],"");
886 if (testee
!= lc
.toLower())
887 errln(lc
+ " is not all lower case.");
888 if ( (testee
.length() != 2) && (testee
.length() != 3))
889 errln(testee
+ " is not two or three characters long.");
890 if (i
> 0 && testee
.compare(test
[i
- 1]) <= 0)
891 errln(testee
+ " appears in an out-of-order position in the list.");
894 test
= Locale::getISOCountries();
895 UnicodeString spotCheck2
[] = { "US", "CA", "GB", "FR", "DE",
896 "IT", "JP", "KR", "CN", "TW",
898 int32_t spot2Len
= 11;
899 for(testCount
=0;test
[testCount
];testCount
++)
902 if (testCount
!= 246){
903 errln("Expected getISOCountries to return 246 countries; it returned %d", testCount
);
905 for (i
= 0; i
< spot2Len
; i
++) {
907 for (j
= 0; j
< testCount
; j
++)
909 UnicodeString
testee(test
[j
],"");
911 if (testee
== spotCheck2
[i
])
914 UnicodeString
testee(test
[j
],"");
915 if (j
== testCount
|| testee
!= spotCheck2
[i
])
916 errln("Couldn't find " + spotCheck2
[i
] + " in country list.");
919 for (i
= 0; i
< testCount
; i
++) {
920 UnicodeString
testee(test
[i
],"");
921 UnicodeString
uc(test
[i
],"");
922 if (testee
!= uc
.toUpper())
923 errln(testee
+ " is not all upper case.");
924 if (testee
.length() != 2)
925 errln(testee
+ " is not two characters long.");
926 if (i
> 0 && testee
.compare(test
[i
- 1]) <= 0)
927 errln(testee
+ " appears in an out-of-order position in the list.");
930 // This getAvailableLocales and getISO3Language
932 int32_t numOfLocales
;
934 const Locale
*pLocales
= Locale::getAvailableLocales(numOfLocales
);
936 for (int i
= 0; i
< numOfLocales
; i
++) {
937 const Locale
&loc(pLocales
[i
]);
941 loc
.getDisplayName (enLoc
, name
);
942 name
.extract (0, 200, szName
, sizeof(szName
));
944 if (strlen(loc
.getISO3Language()) == 0) {
945 errln("getISO3Language() returned an empty string for: " + name
);
955 LocaleTest::TestSimpleDisplayNames()
957 // This test is different from TestDisplayNames because TestDisplayNames checks
958 // fallback behavior, combination of language and country names to form locale
959 // names, and other stuff like that. This test just checks specific language
960 // and country codes to make sure we have the correct names for them.
961 char languageCodes
[] [4] = { "he", "id", "iu", "ug", "yi", "za" };
962 UnicodeString languageNames
[] = { "Hebrew", "Indonesian", "Inuktitut", "Uighur", "Yiddish",
965 for (int32_t i
= 0; i
< 6; i
++) {
967 Locale
l(languageCodes
[i
], "", "");
968 l
.getDisplayLanguage(Locale::getUS(), test
);
969 if (test
!= languageNames
[i
])
970 dataerrln("Got wrong display name for " + UnicodeString(languageCodes
[i
]) + ": Expected \"" +
971 languageNames
[i
] + "\", got \"" + test
+ "\".");
979 LocaleTest::TestUninstalledISO3Names()
981 // This test checks to make sure getISO3Language and getISO3Country work right
982 // even for locales that are not installed.
983 const char iso2Languages
[][4] = { "am", "ba", "fy", "mr", "rn",
985 const char iso3Languages
[][5] = { "amh", "bak", "fry", "mar", "run",
986 "ssw", "twi", "zul" };
990 for (i
= 0; i
< 8; i
++) {
991 UErrorCode err
= U_ZERO_ERROR
;
994 Locale
l(iso2Languages
[i
], "", "");
995 test
= l
.getISO3Language();
996 if((test
!= iso3Languages
[i
]) || U_FAILURE(err
))
997 errln("Got wrong ISO3 code for " + UnicodeString(iso2Languages
[i
]) + ": Expected \"" +
998 iso3Languages
[i
] + "\", got \"" + test
+ "\"." + UnicodeString(u_errorName(err
)));
1001 char iso2Countries
[][4] = { "AF", "BW", "KZ", "MO", "MN",
1003 char iso3Countries
[][4] = { "AFG", "BWA", "KAZ", "MAC", "MNG",
1004 "SLB", "TCA", "ZWE" };
1006 for (i
= 0; i
< 8; i
++) {
1007 UErrorCode err
= U_ZERO_ERROR
;
1008 Locale
l("", iso2Countries
[i
], "");
1009 UnicodeString
test(l
.getISO3Country(), "");
1010 if (test
!= iso3Countries
[i
])
1011 errln("Got wrong ISO3 code for " + UnicodeString(iso2Countries
[i
]) + ": Expected \"" +
1012 UnicodeString(iso3Countries
[i
]) + "\", got \"" + test
+ "\"." + u_errorName(err
));
1018 * I could not reproduce this bug. I'm pretty convinced it was fixed with the
1019 * big locale-data reorg of 10/28/97. The lookup logic for language and country
1020 * display names was also changed at that time in that check-in. --rtg 3/20/98
1023 LocaleTest::TestAtypicalLocales()
1025 Locale localesToTest
[] = { Locale("de", "CA"),
1035 UnicodeString englishDisplayNames
[] = { "German (Canada)",
1036 "Japanese (South Africa)",
1039 "Spanish (Germany)",
1042 "Dominican Republic",
1044 UnicodeString frenchDisplayNames
[]= { "allemand (Canada)",
1045 "japonais (Afrique du Sud)",
1048 "espagnol (Allemagne)",
1050 CharsToUnicodeString("Su\\u00E8de"),
1051 CharsToUnicodeString("R\\u00E9publique dominicaine"),
1053 UnicodeString spanishDisplayNames
[] = {
1054 CharsToUnicodeString("alem\\u00E1n (Canad\\u00E1)"),
1055 CharsToUnicodeString("japon\\u00E9s (Sud\\u00E1frica)"),
1056 CharsToUnicodeString("ruso (M\\u00E9xico)"),
1057 CharsToUnicodeString("ingl\\u00E9s (Francia)"),
1058 CharsToUnicodeString("espa\\u00F1ol (Alemania)"),
1061 CharsToUnicodeString("Rep\\u00FAblica Dominicana"),
1062 CharsToUnicodeString("B\\u00E9lgica") };
1063 // De-Anglicizing root required the change from
1064 // English display names to ISO Codes - ram 2003/09/26
1065 UnicodeString invDisplayNames
[] = { "German (Canada)",
1066 "Japanese (South Africa)",
1069 "Spanish (Germany)",
1072 "Dominican Republic",
1076 UErrorCode status
= U_ZERO_ERROR
;
1078 Locale::setDefault(Locale::getUS(), status
);
1079 for (i
= 0; i
< 9; ++i
) {
1081 localesToTest
[i
].getDisplayName(Locale::getUS(), name
);
1083 if (name
!= englishDisplayNames
[i
])
1085 dataerrln("Lookup in English failed: expected \"" + englishDisplayNames
[i
]
1086 + "\", got \"" + name
+ "\"");
1087 logln("Locale name was-> " + (name
=localesToTest
[i
].getName()));
1091 for (i
= 0; i
< 9; i
++) {
1093 localesToTest
[i
].getDisplayName(Locale("es", "ES"), name
);
1095 if (name
!= spanishDisplayNames
[i
])
1096 dataerrln("Lookup in Spanish failed: expected \"" + spanishDisplayNames
[i
]
1097 + "\", got \"" + name
+ "\"");
1100 for (i
= 0; i
< 9; i
++) {
1102 localesToTest
[i
].getDisplayName(Locale::getFrance(), name
);
1104 if (name
!= frenchDisplayNames
[i
])
1105 dataerrln("Lookup in French failed: expected \"" + frenchDisplayNames
[i
]
1106 + "\", got \"" + name
+ "\"");
1109 for (i
= 0; i
< 9; i
++) {
1111 localesToTest
[i
].getDisplayName(Locale("inv", "IN"), name
);
1112 logln(name
+ " Locale fallback to be, and data fallback to root");
1113 if (name
!= invDisplayNames
[i
])
1114 dataerrln("Lookup in INV failed: expected \"" + prettify(invDisplayNames
[i
])
1115 + "\", got \"" + prettify(name
) + "\"");
1116 localesToTest
[i
].getDisplayName(Locale("inv", "BD"), name
);
1117 logln(name
+ " Data fallback to root");
1118 if (name
!= invDisplayNames
[i
])
1119 dataerrln("Lookup in INV failed: expected \"" + prettify(invDisplayNames
[i
])
1120 + "\", got \"" + prettify(name
)+ "\"");
1122 Locale::setDefault(saveLocale
, status
);
1125 #if !UCONFIG_NO_FORMATTING
1129 * This would be better tested by the LocaleDataTest. Will move it when I
1130 * get the LocaleDataTest working again.
1133 LocaleTest::TestThaiCurrencyFormat()
1135 UErrorCode status
= U_ZERO_ERROR
;
1136 DecimalFormat
*thaiCurrency
= (DecimalFormat
*)NumberFormat::createCurrencyInstance(
1137 Locale("th", "TH"), status
);
1138 UChar posPrefix
= 0x0e3f;
1141 if(U_FAILURE(status
) || !thaiCurrency
)
1143 dataerrln("Couldn't get th_TH currency -> " + UnicodeString(u_errorName(status
)));
1146 if (thaiCurrency
->getPositivePrefix(temp
) != UnicodeString(&posPrefix
, 1, 1))
1147 errln("Thai currency prefix wrong: expected 0x0e3f, got \"" +
1148 thaiCurrency
->getPositivePrefix(temp
) + "\"");
1149 if (thaiCurrency
->getPositiveSuffix(temp
) != "")
1150 errln("Thai currency suffix wrong: expected \"\", got \"" +
1151 thaiCurrency
->getPositiveSuffix(temp
) + "\"");
1153 delete thaiCurrency
;
1158 * Confirm that Euro support works. This test is pretty rudimentary; all it does
1159 * is check that any locales with the EURO variant format a number using the
1160 * Euro currency symbol.
1162 * ASSUME: All locales encode the Euro character "\u20AC".
1163 * If this is changed to use the single-character Euro symbol, this
1164 * test must be updated.
1168 LocaleTest::TestEuroSupport()
1170 UChar euro
= 0x20ac;
1171 const UnicodeString
EURO_CURRENCY(&euro
, 1, 1); // Look for this UnicodeString in formatted Euro currency
1172 const char* localeArr
[] = {
1196 const char** locales
= localeArr
;
1198 UErrorCode status
= U_ZERO_ERROR
;
1202 for (;*locales
!=NULL
;locales
++) {
1203 Locale
loc (*locales
);
1205 NumberFormat
*nf
= NumberFormat::createCurrencyInstance(loc
, status
);
1208 if (U_FAILURE(status
)) {
1209 dataerrln("Error calling NumberFormat::createCurrencyInstance(%s)", *locales
);
1213 nf
->format(271828.182845, pos
);
1215 nf
->format(-271828.182845, neg
);
1216 if (pos
.indexOf(EURO_CURRENCY
) >= 0 &&
1217 neg
.indexOf(EURO_CURRENCY
) >= 0) {
1218 logln("Ok: " + (temp
=loc
.getName()) +
1219 ": " + pos
+ " / " + neg
);
1222 errln("Fail: " + (temp
=loc
.getName()) +
1223 " formats without " + EURO_CURRENCY
+
1224 ": " + pos
+ " / " + neg
+
1225 "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
1231 UnicodeString
dollarStr("USD", ""), euroStr("EUR", ""), genericStr((UChar
)0x00a4), resultStr
;
1233 status
= U_ZERO_ERROR
;
1235 ucurr_forLocale("en_US", tmp
, 4, &status
);
1236 resultStr
.setTo(tmp
);
1237 if (dollarStr
!= resultStr
) {
1238 errcheckln(status
, "Fail: en_US didn't return USD - %s", u_errorName(status
));
1240 ucurr_forLocale("en_US_EURO", tmp
, 4, &status
);
1241 resultStr
.setTo(tmp
);
1242 if (euroStr
!= resultStr
) {
1243 errcheckln(status
, "Fail: en_US_EURO didn't return EUR - %s", u_errorName(status
));
1245 ucurr_forLocale("en_GB_EURO", tmp
, 4, &status
);
1246 resultStr
.setTo(tmp
);
1247 if (euroStr
!= resultStr
) {
1248 errcheckln(status
, "Fail: en_GB_EURO didn't return EUR - %s", u_errorName(status
));
1250 ucurr_forLocale("en_US_PREEURO", tmp
, 4, &status
);
1251 resultStr
.setTo(tmp
);
1252 if (dollarStr
!= resultStr
) {
1253 errcheckln(status
, "Fail: en_US_PREEURO didn't fallback to en_US - %s", u_errorName(status
));
1255 ucurr_forLocale("en_US_Q", tmp
, 4, &status
);
1256 resultStr
.setTo(tmp
);
1257 if (dollarStr
!= resultStr
) {
1258 errcheckln(status
, "Fail: en_US_Q didn't fallback to en_US - %s", u_errorName(status
));
1260 int32_t invalidLen
= ucurr_forLocale("en_QQ", tmp
, 4, &status
);
1261 if (invalidLen
|| U_SUCCESS(status
)) {
1262 errln("Fail: en_QQ didn't return NULL");
1270 * toString() doesn't work with language_VARIANT.
1273 LocaleTest::TestToString() {
1275 Locale("xx", "", ""),
1276 Locale("", "YY", ""),
1277 Locale("", "", "ZZ"),
1278 Locale("xx", "YY", ""),
1279 Locale("xx", "", "ZZ"),
1280 Locale("", "YY", "ZZ"),
1281 Locale("xx", "YY", "ZZ"),
1284 const char DATA_S
[][20] = {
1294 for (int32_t i
=0; i
< 7; ++i
) {
1296 name
= DATA
[i
].getName();
1298 if (strcmp(name
, DATA_S
[i
]) != 0)
1300 errln("Fail: Locale.getName(), got:" + UnicodeString(name
) + ", expected: " + DATA_S
[i
]);
1303 logln("Pass: Locale.getName(), got:" + UnicodeString(name
) );
1307 #if !UCONFIG_NO_FORMATTING
1311 * Couldn't reproduce this bug -- probably was fixed earlier.
1313 * ORIGINAL BUG REPORT:
1314 * -- basically, hungarian for monday shouldn't have an \u00f4
1315 * (o circumflex)in it instead it should be an o with 2 inclined
1316 * (right) lines over it..
1318 * You may wonder -- why do all this -- why not just add a line to
1319 * LocaleData? Well, I could see by inspection that the locale file had the
1320 * right character in it, so I wanted to check the rest of the pipeline -- a
1321 * very remote possibility, but I wanted to be sure. The other possibility
1322 * is that something is wrong with the font mapping subsystem, but we can't
1326 LocaleTest::Test4139940()
1328 Locale
mylocale("hu", "", "");
1329 UDate mydate
= date(98,3,13); // A Monday
1330 UErrorCode status
= U_ZERO_ERROR
;
1331 SimpleDateFormat
df_full("EEEE", mylocale
, status
);
1332 if(U_FAILURE(status
)){
1333 dataerrln(UnicodeString("Could not create SimpleDateFormat object for locale hu. Error: ") + UnicodeString(u_errorName(status
)));
1337 FieldPosition
pos(FieldPosition::DONT_CARE
);
1338 df_full
.format(mydate
, str
, pos
);
1339 // Make sure that o circumflex (\u00F4) is NOT there, and
1340 // o double acute (\u0151) IS.
1343 if (str
.indexOf(oda
) < 0 || str
.indexOf(ocf
) >= 0) {
1344 /* If the default locale is "th" this test will fail because of the buddhist calendar. */
1345 if (strcmp(Locale::getDefault().getLanguage(), "th") != 0) {
1346 errln("Fail: Monday in Hungarian is wrong - oda's index is %d and ocf's is %d",
1347 str
.indexOf(oda
), str
.indexOf(ocf
));
1349 logln(UnicodeString("An error is produce in buddhist calendar."));
1351 logln(UnicodeString("String is: ") + str
);
1356 LocaleTest::date(int32_t y
, int32_t m
, int32_t d
, int32_t hr
, int32_t min
, int32_t sec
)
1358 UErrorCode status
= U_ZERO_ERROR
;
1359 Calendar
*cal
= Calendar::createInstance(status
);
1363 cal
->set(1900 + y
, m
, d
, hr
, min
, sec
); // Add 1900 to follow java.util.Date protocol
1364 UDate dt
= cal
->getTime(status
);
1365 if (U_FAILURE(status
))
1374 * Russian first day of week should be Monday. Confirmed.
1377 LocaleTest::Test4143951()
1379 UErrorCode status
= U_ZERO_ERROR
;
1380 Calendar
*cal
= Calendar::createInstance(Locale("ru", "", ""), status
);
1381 if(U_SUCCESS(status
)) {
1382 if (cal
->getFirstDayOfWeek(status
) != UCAL_MONDAY
) {
1383 dataerrln("Fail: First day of week in Russia should be Monday");
1393 * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
1394 * Should throw an exception for unknown locales
1397 LocaleTest::Test4147315()
1400 // Try with codes that are the wrong length but happen to match text
1401 // at a valid offset in the mapping table
1402 Locale
locale("aaa", "CCC");
1404 const char *result
= locale
.getISO3Country();
1406 // Change to conform to C api usage
1407 if((result
==NULL
)||(result
[0] != 0))
1408 errln("ERROR: getISO3Country() returns: " + UnicodeString(result
,"") +
1409 " for locale '" + (temp
=locale
.getName()) + "' rather than exception" );
1414 * java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes.
1415 * Should throw an exception for unknown locales
1418 LocaleTest::Test4147317()
1421 // Try with codes that are the wrong length but happen to match text
1422 // at a valid offset in the mapping table
1423 Locale
locale("aaa", "CCC");
1425 const char *result
= locale
.getISO3Language();
1427 // Change to conform to C api usage
1428 if((result
==NULL
)||(result
[0] != 0))
1429 errln("ERROR: getISO3Language() returns: " + UnicodeString(result
,"") +
1430 " for locale '" + (temp
=locale
.getName()) + "' rather than exception" );
1437 LocaleTest::Test4147552()
1439 Locale locales
[] = { Locale("no", "NO"),
1440 Locale("no", "NO", "B"),
1441 Locale("no", "NO", "NY")
1444 UnicodeString
edn("Norwegian (Norway, B)");
1445 UnicodeString englishDisplayNames
[] = {
1446 "Norwegian (Norway)",
1448 // "Norwegian (Norway,B)",
1449 //"Norwegian (Norway,NY)"
1450 "Norwegian (Norway, NY)"
1452 UnicodeString
ndn("norsk (Norge, B");
1453 UnicodeString norwegianDisplayNames
[] = {
1458 //"Norsk (Noreg, Nynorsk)"
1460 UErrorCode status
= U_ZERO_ERROR
;
1463 Locale::setDefault(Locale::getEnglish(), status
);
1464 for (int32_t i
= 0; i
< 3; ++i
) {
1465 Locale loc
= locales
[i
];
1467 if (loc
.getDisplayName(temp
) != englishDisplayNames
[i
])
1468 dataerrln("English display-name mismatch: expected " +
1469 englishDisplayNames
[i
] + ", got " + loc
.getDisplayName(temp
));
1470 if (loc
.getDisplayName(loc
, temp
) != norwegianDisplayNames
[i
])
1471 dataerrln("Norwegian display-name mismatch: expected " +
1472 norwegianDisplayNames
[i
] + ", got " +
1473 loc
.getDisplayName(loc
, temp
));
1475 Locale::setDefault(saveLocale
, status
);
1479 LocaleTest::TestVariantParsing()
1481 Locale
en_US_custom("en", "US", "De Anza_Cupertino_California_United States_Earth");
1483 UnicodeString
dispName("English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)");
1484 UnicodeString
dispVar("DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH");
1488 en_US_custom
.getDisplayVariant(Locale::getUS(), got
);
1489 if(got
!= dispVar
) {
1490 errln("FAIL: getDisplayVariant()");
1491 errln("Wanted: " + dispVar
);
1492 errln("Got : " + got
);
1495 en_US_custom
.getDisplayName(Locale::getUS(), got
);
1496 if(got
!= dispName
) {
1497 dataerrln("FAIL: getDisplayName()");
1498 dataerrln("Wanted: " + dispName
);
1499 dataerrln("Got : " + got
);
1502 Locale
shortVariant("fr", "FR", "foo");
1503 shortVariant
.getDisplayVariant(got
);
1506 errln("FAIL: getDisplayVariant()");
1507 errln("Wanted: foo");
1508 errln("Got : " + got
);
1511 Locale
bogusVariant("fr", "FR", "_foo");
1512 bogusVariant
.getDisplayVariant(got
);
1515 errln("FAIL: getDisplayVariant()");
1516 errln("Wanted: foo");
1517 errln("Got : " + got
);
1520 Locale
bogusVariant2("fr", "FR", "foo_");
1521 bogusVariant2
.getDisplayVariant(got
);
1524 errln("FAIL: getDisplayVariant()");
1525 errln("Wanted: foo");
1526 errln("Got : " + got
);
1529 Locale
bogusVariant3("fr", "FR", "_foo_");
1530 bogusVariant3
.getDisplayVariant(got
);
1533 errln("FAIL: getDisplayVariant()");
1534 errln("Wanted: foo");
1535 errln("Got : " + got
);
1539 #if !UCONFIG_NO_FORMATTING
1543 * Currency symbol in zh is wrong. We will test this at the NumberFormat
1544 * end to test the whole pipe.
1547 LocaleTest::Test4105828()
1549 Locale LOC
[] = { Locale::getChinese(), Locale("zh", "CN", ""),
1550 Locale("zh", "TW", ""), Locale("zh", "HK", "") };
1551 UErrorCode status
= U_ZERO_ERROR
;
1552 for (int32_t i
= 0; i
< 4; ++i
) {
1553 NumberFormat
*fmt
= NumberFormat::createPercentInstance(LOC
[i
], status
);
1554 if(U_FAILURE(status
)) {
1555 dataerrln("Couldn't create NumberFormat - %s", u_errorName(status
));
1558 UnicodeString result
;
1559 FieldPosition
pos(0);
1560 fmt
->format((int32_t)1, result
, pos
);
1562 if(result
!= "100%") {
1563 errln(UnicodeString("Percent for ") + LOC
[i
].getDisplayName(temp
) + " should be 100%, got " + result
);
1571 // Tests setBogus and isBogus APIs for Locale
1574 LocaleTest::TestSetIsBogus() {
1577 if(l
.isBogus() != TRUE
) {
1578 errln("After setting bogus, didn't return TRUE");
1580 l
= "en_US"; // This should reset bogus
1581 if(l
.isBogus() != FALSE
) {
1582 errln("After resetting bogus, didn't return FALSE");
1588 LocaleTest::TestKeywordVariants(void) {
1589 static const struct {
1590 const char *localeID
;
1591 const char *expectedLocaleID
;
1592 //const char *expectedLocaleIDNoKeywords;
1593 //const char *expectedCanonicalID;
1594 const char *expectedKeywords
[10];
1595 int32_t numKeywords
;
1596 UErrorCode expectedStatus
;
1599 "de_DE@ currency = euro; C o ll A t i o n = Phonebook ; C alen dar = buddhist ",
1600 "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
1602 //"de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
1603 {"calendar", "collation", "currency"},
1611 //"de_DE@currency=EUR",
1612 {"","","","","","",""},
1614 U_INVALID_FORMAT_ERROR
/* must have '=' after '@' */
1617 UErrorCode status
= U_ZERO_ERROR
;
1619 int32_t i
= 0, j
= 0;
1620 const char *result
= NULL
;
1621 StringEnumeration
*keywords
;
1622 int32_t keyCount
= 0;
1623 const char *keyword
= NULL
;
1624 const UnicodeString
*keywordString
;
1625 int32_t keywordLen
= 0;
1627 for(i
= 0; i
< (int32_t)(sizeof(testCases
)/sizeof(testCases
[0])); i
++) {
1628 status
= U_ZERO_ERROR
;
1629 Locale
l(testCases
[i
].localeID
);
1630 keywords
= l
.createKeywords(status
);
1632 if(status
!= testCases
[i
].expectedStatus
) {
1633 err("Expected to get status %s. Got %s instead\n",
1634 u_errorName(testCases
[i
].expectedStatus
), u_errorName(status
));
1636 status
= U_ZERO_ERROR
;
1638 if((keyCount
= keywords
->count(status
)) != testCases
[i
].numKeywords
) {
1639 err("Expected to get %i keywords, got %i\n", testCases
[i
].numKeywords
, keyCount
);
1644 if((keyword
= keywords
->next(&keywordLen
, status
)) == NULL
) {
1647 if(strcmp(keyword
, testCases
[i
].expectedKeywords
[j
]) != 0) {
1648 err("Expected to get keyword value %s, got %s\n", testCases
[i
].expectedKeywords
[j
], keyword
);
1651 if((keywordString
= keywords
->snext(status
)) == NULL
) {
1654 if(*keywordString
!= UnicodeString(testCases
[i
].expectedKeywords
[j
], "")) {
1655 err("Expected to get keyword UnicodeString %s, got %s\n", testCases
[i
].expectedKeywords
[j
], keyword
);
1660 if(j
== keyCount
/ 2) {
1661 // replace keywords with a clone of itself
1662 StringEnumeration
*k2
= keywords
->clone();
1663 if(k2
== NULL
|| keyCount
!= k2
->count(status
)) {
1664 errln("KeywordEnumeration.clone() failed");
1671 keywords
->reset(status
); // Make sure that reset works.
1673 if((keyword
= keywords
->next(&keywordLen
, status
)) == NULL
) {
1676 if(strcmp(keyword
, testCases
[i
].expectedKeywords
[j
]) != 0) {
1677 err("Expected to get keyword value %s, got %s\n", testCases
[i
].expectedKeywords
[j
], keyword
);
1684 result
= l
.getName();
1685 if(uprv_strcmp(testCases
[i
].expectedLocaleID
, result
) != 0) {
1686 err("Expected to get \"%s\" from \"%s\". Got \"%s\" instead\n",
1687 testCases
[i
].expectedLocaleID
, testCases
[i
].localeID
, result
);
1695 LocaleTest::TestKeywordVariantParsing(void) {
1696 static const struct {
1697 const char *localeID
;
1698 const char *keyword
;
1699 const char *expectedValue
;
1701 { "de_DE@ C o ll A t i o n = Phonebook ", "collation", "Phonebook" },
1702 { "de_DE", "collation", ""},
1703 { "de_DE@collation= PHONEBOOK", "collation", "PHONEBOOK" },
1704 { "de_DE@ currency = euro ; CoLLaTion = PHONEBOOk ", "collation", "PHONEBOOk" },
1707 UErrorCode status
= U_ZERO_ERROR
;
1710 int32_t resultLen
= 0;
1713 for(i
= 0; i
< (int32_t)(sizeof(testCases
)/sizeof(testCases
[0])); i
++) {
1715 Locale
l(testCases
[i
].localeID
);
1716 resultLen
= l
.getKeywordValue(testCases
[i
].keyword
, buffer
, 256, status
);
1717 if(uprv_strcmp(testCases
[i
].expectedValue
, buffer
) != 0) {
1718 err("Expected to extract \"%s\" from \"%s\" for keyword \"%s\". Got \"%s\" instead\n",
1719 testCases
[i
].expectedValue
, testCases
[i
].localeID
, testCases
[i
].keyword
, buffer
);
1725 LocaleTest::TestSetKeywordValue(void) {
1726 static const struct {
1727 const char *keyword
;
1730 { "collation", "phonebook" },
1731 { "currency", "euro" },
1732 { "calendar", "buddhist" }
1735 UErrorCode status
= U_ZERO_ERROR
;
1738 int32_t resultLen
= 0;
1741 Locale
l(Locale::getGerman());
1743 for(i
= 0; i
< (int32_t)(sizeof(testCases
)/sizeof(testCases
[0])); i
++) {
1744 l
.setKeywordValue(testCases
[i
].keyword
, testCases
[i
].value
, status
);
1745 if(U_FAILURE(status
)) {
1746 err("FAIL: Locale::setKeywordValue failed - %s\n", u_errorName(status
));
1750 resultLen
= l
.getKeywordValue(testCases
[i
].keyword
, buffer
, 256, status
);
1751 if(uprv_strcmp(testCases
[i
].value
, buffer
) != 0) {
1752 err("Expected to extract \"%s\" for keyword \"%s\". Got \"%s\" instead\n",
1753 testCases
[i
].value
, testCases
[i
].keyword
, buffer
);
1759 LocaleTest::TestGetBaseName(void) {
1760 static const struct {
1761 const char *localeID
;
1762 const char *baseName
;
1764 { "de_DE@ C o ll A t i o n = Phonebook ", "de_DE" },
1765 { "de@currency = euro; CoLLaTion = PHONEBOOk", "de" },
1766 { "ja@calendar = buddhist", "ja" }
1771 for(i
= 0; i
< (int32_t)(sizeof(testCases
)/sizeof(testCases
[0])); i
++) {
1772 Locale
loc(testCases
[i
].localeID
);
1773 if(strcmp(testCases
[i
].baseName
, loc
.getBaseName())) {
1774 errln("For locale \"%s\" expected baseName \"%s\", but got \"%s\"",
1775 testCases
[i
].localeID
, testCases
[i
].baseName
, loc
.getBaseName());
1782 * Compare two locale IDs. If they are equal, return 0. If `string'
1783 * starts with `prefix' plus an additional element, that is, string ==
1784 * prefix + '_' + x, then return 1. Otherwise return a value < 0.
1786 static UBool
_loccmp(const char* string
, const char* prefix
) {
1787 int32_t slen
= (int32_t)strlen(string
),
1788 plen
= (int32_t)strlen(prefix
);
1789 int32_t c
= uprv_strncmp(string
, prefix
, plen
);
1790 /* 'root' is "less than" everything */
1791 if (uprv_strcmp(prefix
, "root") == 0) {
1792 return (uprv_strcmp(string
, "root") == 0) ? 0 : 1;
1794 if (c
) return -1; /* mismatch */
1795 if (slen
== plen
) return 0;
1796 if (string
[plen
] == '_') return 1;
1797 return -2; /* false match, e.g. "en_USX" cmp "en_US" */
1801 * Check the relationship between requested locales, and report problems.
1802 * The caller specifies the expected relationships between requested
1803 * and valid (expReqValid) and between valid and actual (expValidActual).
1804 * Possible values are:
1805 * "gt" strictly greater than, e.g., en_US > en
1806 * "ge" greater or equal, e.g., en >= en
1807 * "eq" equal, e.g., en == en
1809 void LocaleTest::_checklocs(const char* label
,
1811 const Locale
& validLoc
,
1812 const Locale
& actualLoc
,
1813 const char* expReqValid
,
1814 const char* expValidActual
) {
1815 const char* valid
= validLoc
.getName();
1816 const char* actual
= actualLoc
.getName();
1817 int32_t reqValid
= _loccmp(req
, valid
);
1818 int32_t validActual
= _loccmp(valid
, actual
);
1819 if (((0 == uprv_strcmp(expReqValid
, "gt") && reqValid
> 0) ||
1820 (0 == uprv_strcmp(expReqValid
, "ge") && reqValid
>= 0) ||
1821 (0 == uprv_strcmp(expReqValid
, "eq") && reqValid
== 0)) &&
1822 ((0 == uprv_strcmp(expValidActual
, "gt") && validActual
> 0) ||
1823 (0 == uprv_strcmp(expValidActual
, "ge") && validActual
>= 0) ||
1824 (0 == uprv_strcmp(expValidActual
, "eq") && validActual
== 0))) {
1825 logln("%s; req=%s, valid=%s, actual=%s",
1826 label
, req
, valid
, actual
);
1828 dataerrln("FAIL: %s; req=%s, valid=%s, actual=%s. Require (R %s V) and (V %s A)",
1829 label
, req
, valid
, actual
,
1830 expReqValid
, expValidActual
);
1834 void LocaleTest::TestGetLocale(void) {
1835 #if !UCONFIG_NO_SERVICE
1836 UErrorCode ec
= U_ZERO_ERROR
;
1838 Locale valid
, actual
, reqLoc
;
1841 #if !UCONFIG_NO_FORMATTING
1842 req
= "en_US_BROOKLYN";
1843 Calendar
* cal
= Calendar::createInstance(Locale::createFromName(req
), ec
);
1844 if (U_FAILURE(ec
)) {
1845 dataerrln("FAIL: Calendar::createInstance failed - %s", u_errorName(ec
));
1847 valid
= cal
->getLocale(ULOC_VALID_LOCALE
, ec
);
1848 actual
= cal
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1849 if (U_FAILURE(ec
)) {
1850 errln("FAIL: Calendar::getLocale() failed");
1852 _checklocs("Calendar", req
, valid
, actual
);
1854 /* Make sure that it fails correctly */
1855 ec
= U_FILE_ACCESS_ERROR
;
1856 if (cal
->getLocale(ULOC_VALID_LOCALE
, ec
).getName()[0] != 0) {
1857 errln("FAIL: Calendar::getLocale() failed to fail correctly. It should have returned \"\"");
1864 // DecimalFormat, DecimalFormatSymbols
1865 #if !UCONFIG_NO_FORMATTING
1867 NumberFormat
* nf
= NumberFormat::createInstance(Locale::createFromName(req
), ec
);
1868 if (U_FAILURE(ec
)) {
1869 dataerrln("FAIL: NumberFormat::createInstance failed - %s", u_errorName(ec
));
1871 DecimalFormat
* dec
= dynamic_cast<DecimalFormat
*>(nf
);
1873 errln("FAIL: NumberFormat::createInstance does not return a DecimalFormat");
1876 valid
= dec
->getLocale(ULOC_VALID_LOCALE
, ec
);
1877 actual
= dec
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1878 if (U_FAILURE(ec
)) {
1879 errln("FAIL: DecimalFormat::getLocale() failed");
1881 _checklocs("DecimalFormat", req
, valid
, actual
);
1884 const DecimalFormatSymbols
* sym
= dec
->getDecimalFormatSymbols();
1886 errln("FAIL: getDecimalFormatSymbols returned NULL");
1889 valid
= sym
->getLocale(ULOC_VALID_LOCALE
, ec
);
1890 actual
= sym
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1891 if (U_FAILURE(ec
)) {
1892 errln("FAIL: DecimalFormatSymbols::getLocale() failed");
1894 _checklocs("DecimalFormatSymbols", req
, valid
, actual
);
1900 // DateFormat, DateFormatSymbols
1901 #if !UCONFIG_NO_FORMATTING
1902 req
= "de_CH_LUCERNE";
1904 DateFormat::createDateInstance(DateFormat::kDefault
,
1905 Locale::createFromName(req
));
1907 dataerrln("Error calling DateFormat::createDateInstance()");
1909 SimpleDateFormat
* dat
= dynamic_cast<SimpleDateFormat
*>(df
);
1911 errln("FAIL: DateFormat::createInstance does not return a SimpleDateFormat");
1914 valid
= dat
->getLocale(ULOC_VALID_LOCALE
, ec
);
1915 actual
= dat
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1916 if (U_FAILURE(ec
)) {
1917 errln("FAIL: SimpleDateFormat::getLocale() failed");
1919 _checklocs("SimpleDateFormat", req
, valid
, actual
);
1922 const DateFormatSymbols
* sym
= dat
->getDateFormatSymbols();
1924 errln("FAIL: getDateFormatSymbols returned NULL");
1927 valid
= sym
->getLocale(ULOC_VALID_LOCALE
, ec
);
1928 actual
= sym
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1929 if (U_FAILURE(ec
)) {
1930 errln("FAIL: DateFormatSymbols::getLocale() failed");
1932 _checklocs("DateFormatSymbols", req
, valid
, actual
);
1939 #if !UCONFIG_NO_BREAK_ITERATION
1940 req
= "es_ES_BARCELONA";
1941 reqLoc
= Locale::createFromName(req
);
1942 BreakIterator
* brk
= BreakIterator::createWordInstance(reqLoc
, ec
);
1943 if (U_FAILURE(ec
)) {
1944 dataerrln("FAIL: BreakIterator::createWordInstance failed - %s", u_errorName(ec
));
1946 valid
= brk
->getLocale(ULOC_VALID_LOCALE
, ec
);
1947 actual
= brk
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1948 if (U_FAILURE(ec
)) {
1949 errln("FAIL: BreakIterator::getLocale() failed");
1951 _checklocs("BreakIterator", req
, valid
, actual
);
1954 // After registering something, the behavior should be different
1955 URegistryKey key
= BreakIterator::registerInstance(brk
, reqLoc
, UBRK_WORD
, ec
);
1956 brk
= 0; // registerInstance adopts
1957 if (U_FAILURE(ec
)) {
1958 errln("FAIL: BreakIterator::registerInstance() failed");
1960 brk
= BreakIterator::createWordInstance(reqLoc
, ec
);
1961 if (U_FAILURE(ec
)) {
1962 errln("FAIL: BreakIterator::createWordInstance failed");
1964 valid
= brk
->getLocale(ULOC_VALID_LOCALE
, ec
);
1965 actual
= brk
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1966 if (U_FAILURE(ec
)) {
1967 errln("FAIL: BreakIterator::getLocale() failed");
1969 // N.B.: now expect valid==actual==req
1970 _checklocs("BreakIterator(registered)",
1971 req
, valid
, actual
, "eq", "eq");
1974 // No matter what, unregister
1975 BreakIterator::unregister(key
, ec
);
1976 if (U_FAILURE(ec
)) {
1977 errln("FAIL: BreakIterator::unregister() failed");
1983 // After unregistering, should behave normally again
1984 brk
= BreakIterator::createWordInstance(reqLoc
, ec
);
1985 if (U_FAILURE(ec
)) {
1986 errln("FAIL: BreakIterator::createWordInstance failed");
1988 valid
= brk
->getLocale(ULOC_VALID_LOCALE
, ec
);
1989 actual
= brk
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
1990 if (U_FAILURE(ec
)) {
1991 errln("FAIL: BreakIterator::getLocale() failed");
1993 _checklocs("BreakIterator(unregistered)", req
, valid
, actual
);
2001 #if !UCONFIG_NO_COLLATION
2002 req
= "hi_IN_BHOPAL";
2003 reqLoc
= Locale::createFromName(req
);
2004 Collator
* coll
= Collator::createInstance(reqLoc
, ec
);
2005 if (U_FAILURE(ec
)) {
2006 dataerrln("FAIL: Collator::createInstance failed - %s", u_errorName(ec
));
2008 valid
= coll
->getLocale(ULOC_VALID_LOCALE
, ec
);
2009 actual
= coll
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
2010 if (U_FAILURE(ec
)) {
2011 errln("FAIL: Collator::getLocale() failed");
2013 _checklocs("Collator", req
, valid
, actual
);
2016 // After registering something, the behavior should be different
2017 URegistryKey key
= Collator::registerInstance(coll
, reqLoc
, ec
);
2018 coll
= 0; // registerInstance adopts
2019 if (U_FAILURE(ec
)) {
2020 errln("FAIL: Collator::registerInstance() failed");
2022 coll
= Collator::createInstance(reqLoc
, ec
);
2023 if (U_FAILURE(ec
)) {
2024 errln("FAIL: Collator::createWordInstance failed");
2026 valid
= coll
->getLocale(ULOC_VALID_LOCALE
, ec
);
2027 actual
= coll
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
2028 if (U_FAILURE(ec
)) {
2029 errln("FAIL: Collator::getLocale() failed");
2031 // N.B.: now expect valid==actual==req
2032 _checklocs("Collator(registered)",
2033 req
, valid
, actual
, "eq", "eq");
2036 // No matter what, unregister
2037 Collator::unregister(key
, ec
);
2038 if (U_FAILURE(ec
)) {
2039 errln("FAIL: Collator::unregister() failed");
2045 // After unregistering, should behave normally again
2046 coll
= Collator::createInstance(reqLoc
, ec
);
2047 if (U_FAILURE(ec
)) {
2048 errln("FAIL: Collator::createInstance failed");
2050 valid
= coll
->getLocale(ULOC_VALID_LOCALE
, ec
);
2051 actual
= coll
->getLocale(ULOC_ACTUAL_LOCALE
, ec
);
2052 if (U_FAILURE(ec
)) {
2053 errln("FAIL: Collator::getLocale() failed");
2055 _checklocs("Collator(unregistered)", req
, valid
, actual
);
2064 void LocaleTest::TestVariantWithOutCountry(void) {
2065 Locale
loc("en","","POSIX");
2066 if (0 != strcmp(loc
.getVariant(), "POSIX")) {
2067 errln("FAIL: en__POSIX didn't get parsed correctly - name is %s - expected %s got %s", loc
.getName(), "POSIX", loc
.getVariant());
2069 Locale
loc2("en","","FOUR");
2070 if (0 != strcmp(loc2
.getVariant(), "FOUR")) {
2071 errln("FAIL: en__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc2
.getName(), "FOUR", loc2
.getVariant());
2073 Locale
loc3("en","Latn","","FOUR");
2074 if (0 != strcmp(loc3
.getVariant(), "FOUR")) {
2075 errln("FAIL: en_Latn__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc3
.getName(), "FOUR", loc3
.getVariant());
2077 Locale
loc4("","Latn","","FOUR");
2078 if (0 != strcmp(loc4
.getVariant(), "FOUR")) {
2079 errln("FAIL: _Latn__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc4
.getName(), "FOUR", loc4
.getVariant());
2081 Locale
loc5("","Latn","US","FOUR");
2082 if (0 != strcmp(loc5
.getVariant(), "FOUR")) {
2083 errln("FAIL: _Latn_US_FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc5
.getName(), "FOUR", loc5
.getVariant());
2085 Locale
loc6("de-1901");
2086 if (0 != strcmp(loc6
.getVariant(), "1901")) {
2087 errln("FAIL: de-1901 didn't get parsed correctly - name is %s - expected %s got %s", loc6
.getName(), "1901", loc6
.getVariant());
2091 static Locale
_canonicalize(int32_t selector
, /* 0==createFromName, 1==createCanonical, 2==Locale ct */
2092 const char* localeID
) {
2095 return Locale::createFromName(localeID
);
2097 return Locale::createCanonical(localeID
);
2099 return Locale(localeID
);
2105 void LocaleTest::TestCanonicalization(void)
2107 static const struct {
2108 const char *localeID
; /* input */
2109 const char *getNameID
; /* expected getName() result */
2110 const char *canonicalID
; /* expected canonicalize() result */
2112 { "", "", "en_US_POSIX" },
2113 { "C", "c", "en_US_POSIX" },
2114 { "POSIX", "posix", "en_US_POSIX" },
2115 { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage",
2116 "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE",
2117 "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"},
2118 { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" },
2119 { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" },
2120 { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" },
2121 { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=LUF" },
2122 { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" },
2123 { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" },
2124 { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" },
2125 { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" },
2126 { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" },
2127 { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" },
2128 { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" },
2129 { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" },
2130 { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" },
2131 { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" },
2132 { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" },
2133 { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" },
2134 { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" },
2135 { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" },
2136 { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" },
2137 { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" },
2138 { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" },
2139 { "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */
2140 { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" },
2141 { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" },
2142 { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" },
2143 { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" },
2144 { "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" },
2145 { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" },
2146 { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" },
2147 { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" },
2148 { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" },
2149 { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" },
2150 { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" },
2151 { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ },
2152 { "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */
2153 { "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */
2154 { "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */
2155 // NOTE: uloc_getName() works on en-BOONT, but Locale() parser considers it BOGUS
2156 // TODO: unify this behavior
2157 { "en-BOONT", "en_BOONT", "en_BOONT" }, /* registered name */
2158 { "de-1901", "de_1901", "de_1901" }, /* registered name */
2159 { "de-1906", "de_1906", "de_1906" }, /* registered name */
2160 { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_RS" }, /* .NET name */
2161 { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_RS" }, /* .NET name */
2162 { "sr_YU_CYRILLIC", "sr_YU_CYRILLIC", "sr_Cyrl_RS" }, /* Linux name */
2163 { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */
2164 { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */
2165 { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */
2166 { "zh-CHT", "zh_CHT", "zh_Hant" }, /* .NET name This may change back to zh_Hant */
2168 /* posix behavior that used to be performed by getName */
2169 { "mr.utf8", "mr.utf8", "mr" },
2170 { "de-tv.koi8r", "de_TV.koi8r", "de_TV" },
2171 { "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" },
2172 { "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" },
2173 { "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" },
2174 { "no-no-ny.utf8@B", "no_NO_NY.utf8@B", "no_NO_NY_B" /* not: "nn_NO" [alan ICU3.0] */ }, /* @ ignored unless variant is empty */
2176 /* fleshing out canonicalization */
2177 /* trim space and sort keywords, ';' is separator so not present at end in canonical form */
2178 { "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" },
2179 /* already-canonical ids are not changed */
2180 { "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" },
2181 /* PRE_EURO and EURO conversions don't affect other keywords */
2182 { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" },
2183 { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" },
2184 /* currency keyword overrides PRE_EURO and EURO currency */
2185 { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" },
2186 { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" },
2187 /* norwegian is just too weird, if we handle things in their full generality */
2188 { "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ },
2190 /* test cases reflecting internal resource bundle usage */
2191 { "root@kw=foo", "root@kw=foo", "root@kw=foo" },
2192 { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" },
2193 { "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese" }
2196 static const char* label
[] = { "createFromName", "createCanonical", "Locale" };
2200 for (i
=0; i
< (int)(sizeof(testCases
)/sizeof(testCases
[0])); i
++) {
2201 for (j
=0; j
<3; ++j
) {
2202 const char* expected
= (j
==1) ? testCases
[i
].canonicalID
: testCases
[i
].getNameID
;
2203 Locale loc
= _canonicalize(j
, testCases
[i
].localeID
);
2204 const char* getName
= loc
.isBogus() ? "BOGUS" : loc
.getName();
2205 if(uprv_strcmp(expected
, getName
) != 0) {
2206 errln("FAIL: %s(%s).getName() => \"%s\", expected \"%s\"",
2207 label
[j
], testCases
[i
].localeID
, getName
, expected
);
2209 logln("Ok: %s(%s) => \"%s\"",
2210 label
[j
], testCases
[i
].localeID
, getName
);
2216 void LocaleTest::TestCurrencyByDate(void)
2218 #if !UCONFIG_NO_FORMATTING
2219 UErrorCode status
= U_ZERO_ERROR
;
2220 UDate date
= uprv_getUTCtime();
2224 UnicodeString tempStr
, resultStr
;
2226 // Cycle through historical currencies
2227 date
= (UDate
)-630720000000.0; // pre 1961 - no currency defined
2228 index
= ucurr_countCurrencies("eo_AM", date
, &status
);
2231 errcheckln(status
, "FAIL: didn't return 0 for eo_AM - %s", u_errorName(status
));
2233 resLen
= ucurr_forLocaleAndDate("eo_AM", date
, index
, TMP
, 4, &status
);
2235 errcheckln(status
, "FAIL: eo_AM didn't return NULL - %s", u_errorName(status
));
2237 status
= U_ZERO_ERROR
;
2239 date
= (UDate
)0.0; // 1970 - one currency defined
2240 index
= ucurr_countCurrencies("eo_AM", date
, &status
);
2243 errcheckln(status
, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status
));
2245 resLen
= ucurr_forLocaleAndDate("eo_AM", date
, index
, TMP
, 4, &status
);
2247 resultStr
.setTo("SUR");
2248 if (resultStr
!= tempStr
) {
2249 errcheckln(status
, "FAIL: didn't return SUR for eo_AM - %s", u_errorName(status
));
2252 date
= (UDate
)693792000000.0; // 1992 - one currency defined
2253 index
= ucurr_countCurrencies("eo_AM", date
, &status
);
2256 errcheckln(status
, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status
));
2258 resLen
= ucurr_forLocaleAndDate("eo_AM", date
, index
, TMP
, 4, &status
);
2260 resultStr
.setTo("RUR");
2261 if (resultStr
!= tempStr
) {
2262 errcheckln(status
, "FAIL: didn't return RUR for eo_AM - %s", u_errorName(status
));
2265 date
= (UDate
)977616000000.0; // post 1993 - one currency defined
2266 index
= ucurr_countCurrencies("eo_AM", date
, &status
);
2269 errcheckln(status
, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status
));
2271 resLen
= ucurr_forLocaleAndDate("eo_AM", date
, index
, TMP
, 4, &status
);
2273 resultStr
.setTo("AMD");
2274 if (resultStr
!= tempStr
) {
2275 errcheckln(status
, "FAIL: didn't return AMD for eo_AM - %s", u_errorName(status
));
2278 // Locale AD has multiple currencies at once
2279 date
= (UDate
)977616000000.0; // year 2001
2280 index
= ucurr_countCurrencies("eo_AD", date
, &status
);
2283 errcheckln(status
, "FAIL: didn't return 4 for eo_AD - %s", u_errorName(status
));
2285 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 1, TMP
, 4, &status
);
2287 resultStr
.setTo("EUR");
2288 if (resultStr
!= tempStr
) {
2289 errcheckln(status
, "FAIL: didn't return EUR for eo_AD - %s", u_errorName(status
));
2291 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 2, TMP
, 4, &status
);
2293 resultStr
.setTo("ESP");
2294 if (resultStr
!= tempStr
) {
2295 errcheckln(status
, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status
));
2297 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 3, TMP
, 4, &status
);
2299 resultStr
.setTo("FRF");
2300 if (resultStr
!= tempStr
) {
2301 errcheckln(status
, "FAIL: didn't return FRF for eo_AD - %s", u_errorName(status
));
2303 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 4, TMP
, 4, &status
);
2305 resultStr
.setTo("ADP");
2306 if (resultStr
!= tempStr
) {
2307 errcheckln(status
, "FAIL: didn't return ADP for eo_AD - %s", u_errorName(status
));
2310 date
= (UDate
)0.0; // year 1970
2311 index
= ucurr_countCurrencies("eo_AD", date
, &status
);
2314 errcheckln(status
, "FAIL: didn't return 3 for eo_AD - %s", u_errorName(status
));
2316 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 1, TMP
, 4, &status
);
2318 resultStr
.setTo("ESP");
2319 if (resultStr
!= tempStr
) {
2320 errcheckln(status
, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status
));
2322 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 2, TMP
, 4, &status
);
2324 resultStr
.setTo("FRF");
2325 if (resultStr
!= tempStr
) {
2326 errcheckln(status
, "FAIL: didn't return FRF for eo_AD - %s", u_errorName(status
));
2328 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 3, TMP
, 4, &status
);
2330 resultStr
.setTo("ADP");
2331 if (resultStr
!= tempStr
) {
2332 errcheckln(status
, "FAIL: didn't return ADP for eo_AD - %s", u_errorName(status
));
2335 date
= (UDate
)-630720000000.0; // year 1950
2336 index
= ucurr_countCurrencies("eo_AD", date
, &status
);
2339 errcheckln(status
, "FAIL: didn't return 2 for eo_AD - %s", u_errorName(status
));
2341 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 1, TMP
, 4, &status
);
2343 resultStr
.setTo("ESP");
2344 if (resultStr
!= tempStr
) {
2345 errcheckln(status
, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status
));
2347 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 2, TMP
, 4, &status
);
2349 resultStr
.setTo("ADP");
2350 if (resultStr
!= tempStr
) {
2351 errcheckln(status
, "FAIL: didn't return ADP for eo_AD - %s", u_errorName(status
));
2354 date
= (UDate
)-2207520000000.0; // year 1900
2355 index
= ucurr_countCurrencies("eo_AD", date
, &status
);
2358 errcheckln(status
, "FAIL: didn't return 1 for eo_AD - %s", u_errorName(status
));
2360 resLen
= ucurr_forLocaleAndDate("eo_AD", date
, 1, TMP
, 4, &status
);
2362 resultStr
.setTo("ESP");
2363 if (resultStr
!= tempStr
) {
2364 errcheckln(status
, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status
));
2367 // Locale UA has gap between years 1994 - 1996
2368 date
= (UDate
)788400000000.0;
2369 index
= ucurr_countCurrencies("eo_UA", date
, &status
);
2372 errcheckln(status
, "FAIL: didn't return 0 for eo_UA - %s", u_errorName(status
));
2374 resLen
= ucurr_forLocaleAndDate("eo_UA", date
, index
, TMP
, 4, &status
);
2376 errcheckln(status
, "FAIL: eo_UA didn't return NULL - %s", u_errorName(status
));
2378 status
= U_ZERO_ERROR
;
2380 // Test index bounds
2381 resLen
= ucurr_forLocaleAndDate("eo_UA", date
, 100, TMP
, 4, &status
);
2383 errcheckln(status
, "FAIL: eo_UA didn't return NULL - %s", u_errorName(status
));
2385 status
= U_ZERO_ERROR
;
2387 resLen
= ucurr_forLocaleAndDate("eo_UA", date
, 0, TMP
, 4, &status
);
2389 errcheckln(status
, "FAIL: eo_UA didn't return NULL - %s", u_errorName(status
));
2391 status
= U_ZERO_ERROR
;
2393 // Test for bogus locale
2394 index
= ucurr_countCurrencies("eo_QQ", date
, &status
);
2397 errcheckln(status
, "FAIL: didn't return 0 for eo_QQ - %s", u_errorName(status
));
2399 status
= U_ZERO_ERROR
;
2400 resLen
= ucurr_forLocaleAndDate("eo_QQ", date
, 1, TMP
, 4, &status
);
2402 errcheckln(status
, "FAIL: eo_QQ didn't return NULL - %s", u_errorName(status
));
2404 status
= U_ZERO_ERROR
;
2405 resLen
= ucurr_forLocaleAndDate("eo_QQ", date
, 0, TMP
, 4, &status
);
2407 errcheckln(status
, "FAIL: eo_QQ didn't return NULL - %s", u_errorName(status
));
2409 status
= U_ZERO_ERROR
;
2411 // Cycle through histrocial currencies
2412 date
= (UDate
)977616000000.0; // 2001 - one currency
2413 index
= ucurr_countCurrencies("eo_AO", date
, &status
);
2416 errcheckln(status
, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status
));
2418 resLen
= ucurr_forLocaleAndDate("eo_AO", date
, 1, TMP
, 4, &status
);
2420 resultStr
.setTo("AOA");
2421 if (resultStr
!= tempStr
) {
2422 errcheckln(status
, "FAIL: didn't return AOA for eo_AO - %s", u_errorName(status
));
2425 date
= (UDate
)819936000000.0; // 1996 - 2 currencies
2426 index
= ucurr_countCurrencies("eo_AO", date
, &status
);
2429 errcheckln(status
, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status
));
2431 resLen
= ucurr_forLocaleAndDate("eo_AO", date
, 1, TMP
, 4, &status
);
2433 resultStr
.setTo("AOR");
2434 if (resultStr
!= tempStr
) {
2435 errcheckln(status
, "FAIL: didn't return AOR for eo_AO - %s", u_errorName(status
));
2437 resLen
= ucurr_forLocaleAndDate("eo_AO", date
, 2, TMP
, 4, &status
);
2439 resultStr
.setTo("AON");
2440 if (resultStr
!= tempStr
) {
2441 errcheckln(status
, "FAIL: didn't return AON for eo_AO - %s", u_errorName(status
));
2444 date
= (UDate
)662256000000.0; // 1991 - 2 currencies
2445 index
= ucurr_countCurrencies("eo_AO", date
, &status
);
2448 errcheckln(status
, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status
));
2450 resLen
= ucurr_forLocaleAndDate("eo_AO", date
, 1, TMP
, 4, &status
);
2452 resultStr
.setTo("AON");
2453 if (resultStr
!= tempStr
) {
2454 errcheckln(status
, "FAIL: didn't return AON for eo_AO - %s", u_errorName(status
));
2456 resLen
= ucurr_forLocaleAndDate("eo_AO", date
, 2, TMP
, 4, &status
);
2458 resultStr
.setTo("AOK");
2459 if (resultStr
!= tempStr
) {
2460 errcheckln(status
, "FAIL: didn't return AOK for eo_AO - %s", u_errorName(status
));
2463 date
= (UDate
)315360000000.0; // 1980 - one currency
2464 index
= ucurr_countCurrencies("eo_AO", date
, &status
);
2467 errcheckln(status
, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status
));
2469 resLen
= ucurr_forLocaleAndDate("eo_AO", date
, 1, TMP
, 4, &status
);
2471 resultStr
.setTo("AOK");
2472 if (resultStr
!= tempStr
) {
2473 errcheckln(status
, "FAIL: didn't return AOK for eo_AO - %s", u_errorName(status
));
2476 date
= (UDate
)0.0; // 1970 - no currencies
2477 index
= ucurr_countCurrencies("eo_AO", date
, &status
);
2480 errcheckln(status
, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status
));
2482 resLen
= ucurr_forLocaleAndDate("eo_AO", date
, 1, TMP
, 4, &status
);
2484 errcheckln(status
, "FAIL: eo_AO didn't return NULL - %s", u_errorName(status
));
2486 status
= U_ZERO_ERROR
;
2488 // Test with currency keyword override
2489 date
= (UDate
)977616000000.0; // 2001 - two currencies
2490 index
= ucurr_countCurrencies("eo_DE@currency=DEM", date
, &status
);
2493 errcheckln(status
, "FAIL: didn't return 2 for eo_DE@currency=DEM - %s", u_errorName(status
));
2495 resLen
= ucurr_forLocaleAndDate("eo_DE@currency=DEM", date
, 1, TMP
, 4, &status
);
2497 resultStr
.setTo("EUR");
2498 if (resultStr
!= tempStr
) {
2499 errcheckln(status
, "FAIL: didn't return EUR for eo_DE@currency=DEM - %s", u_errorName(status
));
2501 resLen
= ucurr_forLocaleAndDate("eo_DE@currency=DEM", date
, 2, TMP
, 4, &status
);
2503 resultStr
.setTo("DEM");
2504 if (resultStr
!= tempStr
) {
2505 errcheckln(status
, "FAIL: didn't return DEM for eo_DE@currency=DEM - %s", u_errorName(status
));
2508 // Test Euro Support
2509 status
= U_ZERO_ERROR
; // reset
2510 date
= uprv_getUTCtime();
2513 ucurr_forLocaleAndDate("en_US", date
, 1, USD
, 4, &status
);
2516 ucurr_forLocaleAndDate("ja_JP", date
, 1, YEN
, 4, &status
);
2518 ucurr_forLocaleAndDate("en_US", date
, 1, TMP
, 4, &status
);
2519 if (u_strcmp(USD
, TMP
) != 0) {
2520 errcheckln(status
, "Fail: en_US didn't return USD - %s", u_errorName(status
));
2522 ucurr_forLocaleAndDate("en_US_PREEURO", date
, 1, TMP
, 4, &status
);
2523 if (u_strcmp(USD
, TMP
) != 0) {
2524 errcheckln(status
, "Fail: en_US_PREEURO didn't fallback to en_US - %s", u_errorName(status
));
2526 ucurr_forLocaleAndDate("en_US_Q", date
, 1, TMP
, 4, &status
);
2527 if (u_strcmp(USD
, TMP
) != 0) {
2528 errcheckln(status
, "Fail: en_US_Q didn't fallback to en_US - %s", u_errorName(status
));
2530 status
= U_ZERO_ERROR
; // reset
2534 void LocaleTest::TestGetVariantWithKeywords(void)
2536 Locale
l("en_US_VALLEY@foo=value");
2537 const char *variant
= l
.getVariant();
2539 test_assert(strcmp("VALLEY", variant
) == 0);
2541 UErrorCode status
= U_ZERO_ERROR
;
2543 int32_t len
= l
.getKeywordValue("foo", buffer
, 50, status
);
2545 test_assert(strcmp("value", buffer
) == 0);