]>
Commit | Line | Data |
---|---|---|
b75a7d8f | 1 | /******************************************************************** |
374ca955 | 2 | * COPYRIGHT: |
2ca993e8 | 3 | * Copyright (c) 1997-2016, International Business Machines Corporation and |
b75a7d8f A |
4 | * others. All Rights Reserved. |
5 | ********************************************************************/ | |
6 | ||
7 | #include "loctest.h" | |
b75a7d8f | 8 | #include "unicode/decimfmt.h" |
374ca955 | 9 | #include "unicode/ucurr.h" |
b75a7d8f | 10 | #include "unicode/smpdtfmt.h" |
374ca955 A |
11 | #include "unicode/dtfmtsym.h" |
12 | #include "unicode/brkiter.h" | |
13 | #include "unicode/coll.h" | |
2ca993e8 | 14 | #include "cmemory.h" |
374ca955 | 15 | #include "cstring.h" |
73c04bcf | 16 | #include <stdio.h> |
4388f060 | 17 | #include <string.h> |
46f4442e A |
18 | #include "putilimp.h" |
19 | #include "unicode/ustring.h" | |
b331163b | 20 | #include "hash.h" |
b75a7d8f | 21 | |
46f4442e | 22 | static const char* const rawData[33][8] = { |
b75a7d8f A |
23 | |
24 | // language code | |
374ca955 A |
25 | { "en", "fr", "ca", "el", "no", "it", "xx", "zh" }, |
26 | // script code | |
27 | { "", "", "", "", "", "", "", "Hans" }, | |
b75a7d8f | 28 | // country code |
374ca955 | 29 | { "US", "FR", "ES", "GR", "NO", "", "YY", "CN" }, |
b75a7d8f | 30 | // variant code |
374ca955 | 31 | { "", "", "", "", "NY", "", "", "" }, |
b75a7d8f | 32 | // full name |
374ca955 | 33 | { "en_US", "fr_FR", "ca_ES", "el_GR", "no_NO_NY", "it", "xx_YY", "zh_Hans_CN" }, |
b75a7d8f | 34 | // ISO-3 language |
374ca955 | 35 | { "eng", "fra", "cat", "ell", "nor", "ita", "", "zho" }, |
b75a7d8f | 36 | // ISO-3 country |
374ca955 A |
37 | { "USA", "FRA", "ESP", "GRC", "NOR", "", "", "CHN" }, |
38 | // LCID | |
39 | { "409", "40c", "403", "408", "814", "10", "0", "804" }, | |
b75a7d8f A |
40 | |
41 | // display langage (English) | |
374ca955 A |
42 | { "English", "French", "Catalan", "Greek", "Norwegian", "Italian", "xx", "Chinese" }, |
43 | // display script (English) | |
44 | { "", "", "", "", "", "", "", "Simplified Han" }, | |
b75a7d8f | 45 | // display country (English) |
374ca955 | 46 | { "United States", "France", "Spain", "Greece", "Norway", "", "YY", "China" }, |
b75a7d8f | 47 | // display variant (English) |
374ca955 | 48 | { "", "", "", "", "NY", "", "", ""}, |
b75a7d8f A |
49 | // display name (English) |
50 | // Updated no_NO_NY English display name for new pattern-based algorithm | |
51 | // (part of Euro support). | |
4388f060 | 52 | { "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway, NY)", "Italian", "xx (YY)", "Chinese (Simplified, China)" }, |
b75a7d8f A |
53 | |
54 | // display langage (French) | |
374ca955 A |
55 | { "anglais", "fran\\u00E7ais", "catalan", "grec", "norv\\u00E9gien", "italien", "xx", "chinois" }, |
56 | // display script (French) | |
57a6839d | 57 | { "", "", "", "", "", "", "", "sinogrammes simplifi\\u00E9s" }, |
b75a7d8f | 58 | // display country (French) |
374ca955 | 59 | { "\\u00C9tats-Unis", "France", "Espagne", "Gr\\u00E8ce", "Norv\\u00E8ge", "", "YY", "Chine" }, |
b75a7d8f | 60 | // display variant (French) |
374ca955 | 61 | { "", "", "", "", "NY", "", "", "" }, |
b75a7d8f | 62 | // display name (French) |
374ca955 | 63 | //{ "anglais (Etats-Unis)", "francais (France)", "catalan (Espagne)", "grec (Grece)", "norvegien (Norvege,Nynorsk)", "italien", "xx (YY)" }, |
57a6839d | 64 | { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "italien", "xx (YY)", "chinois (simplifi\\u00E9, Chine)" }, |
374ca955 A |
65 | |
66 | ||
67 | /* display language (Catalan) */ | |
46f4442e | 68 | { "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec", "noruec", "itali\\u00E0", "", "xin\\u00E8s" }, |
374ca955 | 69 | /* display script (Catalan) */ |
57a6839d | 70 | { "", "", "", "", "", "", "", "han simplificat" }, |
374ca955 A |
71 | /* display country (Catalan) */ |
72 | { "Estats Units", "Fran\\u00E7a", "Espanya", "Gr\\u00E8cia", "Noruega", "", "", "Xina" }, | |
73 | /* display variant (Catalan) */ | |
74 | { "", "", "", "", "NY", "", "" }, | |
75 | /* display name (Catalan) */ | |
65298623 | 76 | { "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)", "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "itali\\u00E0", "", "xin\\u00E8s (simplificat, Xina)" }, |
b75a7d8f A |
77 | |
78 | // display langage (Greek)[actual values listed below] | |
374ca955 A |
79 | { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac", |
80 | "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac", | |
81 | "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac", | |
82 | "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac", | |
83 | "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac", | |
84 | "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac", | |
85 | "", | |
86 | "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC" | |
87 | }, | |
88 | // display script (Greek) | |
57a6839d | 89 | { "", "", "", "", "", "", "", "\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf \\u03a7\\u03b1\\u03bd" }, |
b75a7d8f | 90 | // display country (Greek)[actual values listed below] |
57a6839d | 91 | { "\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2", |
374ca955 A |
92 | "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1", |
93 | "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1", | |
94 | "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1", | |
95 | "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1", | |
96 | "", | |
97 | "", | |
98 | "\\u039A\\u03AF\\u03BD\\u03B1" | |
99 | }, | |
b75a7d8f | 100 | // display variant (Greek) |
374ca955 | 101 | { "", "", "", "", "NY", "", "" }, |
b75a7d8f | 102 | // display name (Greek)[actual values listed below] |
57a6839d | 103 | { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2)", |
374ca955 A |
104 | "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)", |
105 | "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)", | |
106 | "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)", | |
57a6839d | 107 | "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)", |
374ca955 A |
108 | "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac", |
109 | "", | |
57a6839d | 110 | "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC (\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf, \\u039A\\u03AF\\u03BD\\u03B1)" |
374ca955 | 111 | }, |
b75a7d8f A |
112 | |
113 | // display langage (<root>) | |
374ca955 A |
114 | { "English", "French", "Catalan", "Greek", "Norwegian", "Italian", "xx", "" }, |
115 | // display script (<root>) | |
116 | { "", "", "", "", "", "", "", ""}, | |
b75a7d8f | 117 | // display country (<root>) |
374ca955 | 118 | { "United States", "France", "Spain", "Greece", "Norway", "", "YY", "" }, |
b75a7d8f | 119 | // display variant (<root>) |
374ca955 | 120 | { "", "", "", "", "Nynorsk", "", "", ""}, |
b75a7d8f | 121 | // display name (<root>) |
374ca955 A |
122 | //{ "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" }, |
123 | { "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)", "" } | |
b75a7d8f A |
124 | }; |
125 | ||
73c04bcf | 126 | |
b75a7d8f A |
127 | /* |
128 | Usage: | |
73c04bcf | 129 | test_assert( Test (should be TRUE) ) |
b75a7d8f A |
130 | |
131 | Example: | |
73c04bcf | 132 | test_assert(i==3); |
b75a7d8f | 133 | |
73c04bcf | 134 | the macro is ugly but makes the tests pretty. |
b75a7d8f A |
135 | */ |
136 | ||
73c04bcf | 137 | #define test_assert(test) \ |
b75a7d8f | 138 | { \ |
73c04bcf A |
139 | if(!(test)) \ |
140 | errln("FAIL: " #test " was not true. In " __FILE__ " on line %d", __LINE__ ); \ | |
b75a7d8f | 141 | else \ |
73c04bcf | 142 | logln("PASS: asserted " #test); \ |
b75a7d8f A |
143 | } |
144 | ||
b75a7d8f A |
145 | /* |
146 | Usage: | |
147 | test_assert_print( Test (should be TRUE), printable ) | |
148 | ||
149 | Example: | |
150 | test_assert(i==3, toString(i)); | |
151 | ||
152 | the macro is ugly but makes the tests pretty. | |
153 | */ | |
154 | ||
155 | #define test_assert_print(test,print) \ | |
156 | { \ | |
157 | if(!(test)) \ | |
73c04bcf | 158 | errln("FAIL: " #test " was not true. " + UnicodeString(print) ); \ |
b75a7d8f | 159 | else \ |
73c04bcf | 160 | logln("PASS: asserted " #test "-> " + UnicodeString(print)); \ |
b75a7d8f A |
161 | } |
162 | ||
163 | ||
73c04bcf | 164 | #define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); } |
b75a7d8f A |
165 | |
166 | LocaleTest::LocaleTest() | |
167 | : dataTable(NULL) | |
168 | { | |
169 | setUpDataTable(); | |
170 | } | |
171 | ||
172 | LocaleTest::~LocaleTest() | |
173 | { | |
174 | if (dataTable != 0) { | |
374ca955 | 175 | for (int32_t i = 0; i < 33; i++) { |
b75a7d8f A |
176 | delete []dataTable[i]; |
177 | } | |
178 | delete []dataTable; | |
179 | dataTable = 0; | |
180 | } | |
181 | } | |
182 | ||
b75a7d8f A |
183 | void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) |
184 | { | |
b331163b A |
185 | TESTCASE_AUTO_BEGIN; |
186 | TESTCASE_AUTO(TestBug11421); // Must run early in list to trigger failure. | |
187 | TESTCASE_AUTO(TestBasicGetters); | |
188 | TESTCASE_AUTO(TestSimpleResourceInfo); | |
189 | TESTCASE_AUTO(TestDisplayNames); | |
190 | TESTCASE_AUTO(TestSimpleObjectStuff); | |
191 | TESTCASE_AUTO(TestPOSIXParsing); | |
192 | TESTCASE_AUTO(TestGetAvailableLocales); | |
193 | TESTCASE_AUTO(TestDataDirectory); | |
194 | TESTCASE_AUTO(TestISO3Fallback); | |
195 | TESTCASE_AUTO(TestGetLangsAndCountries); | |
196 | TESTCASE_AUTO(TestSimpleDisplayNames); | |
197 | TESTCASE_AUTO(TestUninstalledISO3Names); | |
198 | TESTCASE_AUTO(TestAtypicalLocales); | |
b75a7d8f | 199 | #if !UCONFIG_NO_FORMATTING |
b331163b A |
200 | TESTCASE_AUTO(TestThaiCurrencyFormat); |
201 | TESTCASE_AUTO(TestEuroSupport); | |
b75a7d8f | 202 | #endif |
b331163b | 203 | TESTCASE_AUTO(TestToString); |
b75a7d8f | 204 | #if !UCONFIG_NO_FORMATTING |
b331163b A |
205 | TESTCASE_AUTO(Test4139940); |
206 | TESTCASE_AUTO(Test4143951); | |
b75a7d8f | 207 | #endif |
b331163b A |
208 | TESTCASE_AUTO(Test4147315); |
209 | TESTCASE_AUTO(Test4147317); | |
210 | TESTCASE_AUTO(Test4147552); | |
211 | TESTCASE_AUTO(TestVariantParsing); | |
b75a7d8f | 212 | #if !UCONFIG_NO_FORMATTING |
b331163b | 213 | TESTCASE_AUTO(Test4105828); |
b75a7d8f | 214 | #endif |
b331163b A |
215 | TESTCASE_AUTO(TestSetIsBogus); |
216 | TESTCASE_AUTO(TestParallelAPIValues); | |
217 | TESTCASE_AUTO(TestKeywordVariants); | |
218 | TESTCASE_AUTO(TestKeywordVariantParsing); | |
219 | TESTCASE_AUTO(TestSetKeywordValue); | |
220 | TESTCASE_AUTO(TestGetBaseName); | |
729e4ab9 | 221 | #if !UCONFIG_NO_FILE_IO |
b331163b | 222 | TESTCASE_AUTO(TestGetLocale); |
729e4ab9 | 223 | #endif |
b331163b A |
224 | TESTCASE_AUTO(TestVariantWithOutCountry); |
225 | TESTCASE_AUTO(TestCanonicalization); | |
226 | TESTCASE_AUTO(TestCurrencyByDate); | |
227 | TESTCASE_AUTO(TestGetVariantWithKeywords); | |
228 | TESTCASE_AUTO(TestIsRightToLeft); | |
229 | TESTCASE_AUTO_END; | |
b75a7d8f A |
230 | } |
231 | ||
232 | void LocaleTest::TestBasicGetters() { | |
233 | UnicodeString temp; | |
234 | ||
235 | int32_t i; | |
236 | for (i = 0; i <= MAX_LOCALES; i++) { | |
374ca955 A |
237 | Locale testLocale(""); |
238 | if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) { | |
239 | testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i], rawData[VAR][i]); | |
240 | } | |
241 | else { | |
242 | testLocale = Locale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); | |
243 | } | |
b75a7d8f A |
244 | logln("Testing " + (UnicodeString)testLocale.getName() + "..."); |
245 | ||
246 | if ( (temp=testLocale.getLanguage()) != (dataTable[LANG][i])) | |
247 | errln(" Language code mismatch: " + temp + " versus " | |
248 | + dataTable[LANG][i]); | |
374ca955 A |
249 | if ( (temp=testLocale.getScript()) != (dataTable[SCRIPT][i])) |
250 | errln(" Script code mismatch: " + temp + " versus " | |
251 | + dataTable[SCRIPT][i]); | |
b75a7d8f A |
252 | if ( (temp=testLocale.getCountry()) != (dataTable[CTRY][i])) |
253 | errln(" Country code mismatch: " + temp + " versus " | |
254 | + dataTable[CTRY][i]); | |
255 | if ( (temp=testLocale.getVariant()) != (dataTable[VAR][i])) | |
256 | errln(" Variant code mismatch: " + temp + " versus " | |
257 | + dataTable[VAR][i]); | |
258 | if ( (temp=testLocale.getName()) != (dataTable[NAME][i])) | |
259 | errln(" Locale name mismatch: " + temp + " versus " | |
260 | + dataTable[NAME][i]); | |
261 | } | |
262 | ||
263 | logln("Same thing without variant codes..."); | |
264 | for (i = 0; i <= MAX_LOCALES; i++) { | |
374ca955 A |
265 | Locale testLocale(""); |
266 | if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) { | |
267 | testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i]); | |
268 | } | |
269 | else { | |
270 | testLocale = Locale(rawData[LANG][i], rawData[CTRY][i]); | |
271 | } | |
b75a7d8f A |
272 | logln("Testing " + (temp=testLocale.getName()) + "..."); |
273 | ||
274 | if ( (temp=testLocale.getLanguage()) != (dataTable[LANG][i])) | |
374ca955 | 275 | errln("Language code mismatch: " + temp + " versus " |
b75a7d8f | 276 | + dataTable[LANG][i]); |
374ca955 A |
277 | if ( (temp=testLocale.getScript()) != (dataTable[SCRIPT][i])) |
278 | errln("Script code mismatch: " + temp + " versus " | |
279 | + dataTable[SCRIPT][i]); | |
b75a7d8f | 280 | if ( (temp=testLocale.getCountry()) != (dataTable[CTRY][i])) |
374ca955 | 281 | errln("Country code mismatch: " + temp + " versus " |
b75a7d8f A |
282 | + dataTable[CTRY][i]); |
283 | if (testLocale.getVariant()[0] != 0) | |
374ca955 | 284 | errln("Variant code mismatch: something versus \"\""); |
b75a7d8f A |
285 | } |
286 | ||
287 | logln("Testing long language names and getters"); | |
374ca955 | 288 | Locale test8 = Locale::createFromName("x-klingon-latn-zx.utf32be@special"); |
b75a7d8f A |
289 | |
290 | temp = test8.getLanguage(); | |
291 | if (temp != UnicodeString("x-klingon") ) | |
374ca955 A |
292 | errln("Language code mismatch: " + temp + " versus \"x-klingon\""); |
293 | ||
294 | temp = test8.getScript(); | |
295 | if (temp != UnicodeString("Latn") ) | |
296 | errln("Script code mismatch: " + temp + " versus \"Latn\""); | |
b75a7d8f A |
297 | |
298 | temp = test8.getCountry(); | |
299 | if (temp != UnicodeString("ZX") ) | |
374ca955 | 300 | errln("Country code mismatch: " + temp + " versus \"ZX\""); |
b75a7d8f A |
301 | |
302 | temp = test8.getVariant(); | |
374ca955 A |
303 | //if (temp != UnicodeString("SPECIAL") ) |
304 | // errln("Variant code mismatch: " + temp + " versus \"SPECIAL\""); | |
305 | // As of 3.0, the "@special" will *not* be parsed by uloc_getName() | |
306 | if (temp != UnicodeString("") ) | |
307 | errln("Variant code mismatch: " + temp + " versus \"\""); | |
b75a7d8f A |
308 | |
309 | if (Locale::getDefault() != Locale::createFromName(NULL)) | |
374ca955 | 310 | errln("Locale::getDefault() == Locale::createFromName(NULL)"); |
b75a7d8f A |
311 | |
312 | /*----------*/ | |
313 | // NOTE: There used to be a special test for locale names that had language or | |
314 | // country codes that were longer than two letters. The new version of Locale | |
315 | // doesn't support anything that isn't an officially recognized language or | |
316 | // country code, so we no longer support this feature. | |
317 | ||
318 | Locale bogusLang("THISISABOGUSLANGUAGE"); // Jitterbug 2864: language code too long | |
319 | if(!bogusLang.isBogus()) { | |
320 | errln("Locale(\"THISISABOGUSLANGUAGE\").isBogus()==FALSE"); | |
321 | } | |
322 | ||
323 | bogusLang=Locale("eo"); | |
324 | if( bogusLang.isBogus() || | |
325 | strcmp(bogusLang.getLanguage(), "eo")!=0 || | |
326 | *bogusLang.getCountry()!=0 || | |
327 | *bogusLang.getVariant()!=0 || | |
328 | strcmp(bogusLang.getName(), "eo")!=0 | |
329 | ) { | |
330 | errln("assignment to bogus Locale does not unbogus it or sets bad data"); | |
331 | } | |
374ca955 A |
332 | |
333 | Locale a("eo_DE@currency=DEM"); | |
334 | Locale *pb=a.clone(); | |
335 | if(pb==&a || *pb!=a) { | |
336 | errln("Locale.clone() failed"); | |
337 | } | |
338 | delete pb; | |
b75a7d8f A |
339 | } |
340 | ||
341 | void LocaleTest::TestParallelAPIValues() { | |
342 | logln("Test synchronization between C and C++ API"); | |
343 | if (strcmp(Locale::getChinese().getName(), ULOC_CHINESE) != 0) { | |
344 | errln("Differences for ULOC_CHINESE Locale"); | |
345 | } | |
346 | if (strcmp(Locale::getEnglish().getName(), ULOC_ENGLISH) != 0) { | |
347 | errln("Differences for ULOC_ENGLISH Locale"); | |
348 | } | |
349 | if (strcmp(Locale::getFrench().getName(), ULOC_FRENCH) != 0) { | |
350 | errln("Differences for ULOC_FRENCH Locale"); | |
351 | } | |
352 | if (strcmp(Locale::getGerman().getName(), ULOC_GERMAN) != 0) { | |
353 | errln("Differences for ULOC_GERMAN Locale"); | |
354 | } | |
355 | if (strcmp(Locale::getItalian().getName(), ULOC_ITALIAN) != 0) { | |
356 | errln("Differences for ULOC_ITALIAN Locale"); | |
357 | } | |
358 | if (strcmp(Locale::getJapanese().getName(), ULOC_JAPANESE) != 0) { | |
359 | errln("Differences for ULOC_JAPANESE Locale"); | |
360 | } | |
361 | if (strcmp(Locale::getKorean().getName(), ULOC_KOREAN) != 0) { | |
362 | errln("Differences for ULOC_KOREAN Locale"); | |
363 | } | |
364 | if (strcmp(Locale::getSimplifiedChinese().getName(), ULOC_SIMPLIFIED_CHINESE) != 0) { | |
365 | errln("Differences for ULOC_SIMPLIFIED_CHINESE Locale"); | |
366 | } | |
367 | if (strcmp(Locale::getTraditionalChinese().getName(), ULOC_TRADITIONAL_CHINESE) != 0) { | |
368 | errln("Differences for ULOC_TRADITIONAL_CHINESE Locale"); | |
369 | } | |
370 | ||
371 | ||
372 | if (strcmp(Locale::getCanada().getName(), ULOC_CANADA) != 0) { | |
373 | errln("Differences for ULOC_CANADA Locale"); | |
374 | } | |
375 | if (strcmp(Locale::getCanadaFrench().getName(), ULOC_CANADA_FRENCH) != 0) { | |
376 | errln("Differences for ULOC_CANADA_FRENCH Locale"); | |
377 | } | |
378 | if (strcmp(Locale::getChina().getName(), ULOC_CHINA) != 0) { | |
379 | errln("Differences for ULOC_CHINA Locale"); | |
380 | } | |
381 | if (strcmp(Locale::getPRC().getName(), ULOC_PRC) != 0) { | |
382 | errln("Differences for ULOC_PRC Locale"); | |
383 | } | |
384 | if (strcmp(Locale::getFrance().getName(), ULOC_FRANCE) != 0) { | |
385 | errln("Differences for ULOC_FRANCE Locale"); | |
386 | } | |
387 | if (strcmp(Locale::getGermany().getName(), ULOC_GERMANY) != 0) { | |
388 | errln("Differences for ULOC_GERMANY Locale"); | |
389 | } | |
390 | if (strcmp(Locale::getItaly().getName(), ULOC_ITALY) != 0) { | |
391 | errln("Differences for ULOC_ITALY Locale"); | |
392 | } | |
393 | if (strcmp(Locale::getJapan().getName(), ULOC_JAPAN) != 0) { | |
394 | errln("Differences for ULOC_JAPAN Locale"); | |
395 | } | |
396 | if (strcmp(Locale::getKorea().getName(), ULOC_KOREA) != 0) { | |
397 | errln("Differences for ULOC_KOREA Locale"); | |
398 | } | |
399 | if (strcmp(Locale::getTaiwan().getName(), ULOC_TAIWAN) != 0) { | |
400 | errln("Differences for ULOC_TAIWAN Locale"); | |
401 | } | |
402 | if (strcmp(Locale::getUK().getName(), ULOC_UK) != 0) { | |
403 | errln("Differences for ULOC_UK Locale"); | |
404 | } | |
405 | if (strcmp(Locale::getUS().getName(), ULOC_US) != 0) { | |
406 | errln("Differences for ULOC_US Locale"); | |
407 | } | |
408 | } | |
409 | ||
410 | ||
411 | void LocaleTest::TestSimpleResourceInfo() { | |
374ca955 A |
412 | UnicodeString temp; |
413 | char temp2[20]; | |
414 | UErrorCode err = U_ZERO_ERROR; | |
415 | int32_t i = 0; | |
416 | ||
417 | for (i = 0; i <= MAX_LOCALES; i++) { | |
418 | Locale testLocale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); | |
419 | logln("Testing " + (temp=testLocale.getName()) + "..."); | |
420 | ||
421 | if ( (temp=testLocale.getISO3Language()) != (dataTable[LANG3][i])) | |
422 | errln(" ISO-3 language code mismatch: " + temp | |
423 | + " versus " + dataTable[LANG3][i]); | |
424 | if ( (temp=testLocale.getISO3Country()) != (dataTable[CTRY3][i])) | |
425 | errln(" ISO-3 country code mismatch: " + temp | |
426 | + " versus " + dataTable[CTRY3][i]); | |
427 | ||
428 | sprintf(temp2, "%x", (int)testLocale.getLCID()); | |
429 | if (UnicodeString(temp2) != dataTable[LCID][i]) | |
430 | errln((UnicodeString)" LCID mismatch: " + temp2 + " versus " | |
431 | + dataTable[LCID][i]); | |
b75a7d8f | 432 | |
374ca955 A |
433 | if(U_FAILURE(err)) |
434 | { | |
435 | errln((UnicodeString)"Some error on number " + i + u_errorName(err)); | |
436 | } | |
437 | err = U_ZERO_ERROR; | |
438 | } | |
439 | ||
440 | Locale locale("en"); | |
441 | if(strcmp(locale.getName(), "en") != 0|| | |
442 | strcmp(locale.getLanguage(), "en") != 0) { | |
443 | errln("construction of Locale(en) failed\n"); | |
444 | } | |
445 | /*-----*/ | |
b75a7d8f A |
446 | |
447 | } | |
448 | ||
449 | /* | |
450 | * Jitterbug 2439 -- markus 20030425 | |
451 | * | |
452 | * The lookup of display names must not fall back through the default | |
453 | * locale because that yields useless results. | |
454 | */ | |
374ca955 A |
455 | void |
456 | LocaleTest::TestDisplayNames() | |
b75a7d8f A |
457 | { |
458 | Locale english("en", "US"); | |
459 | Locale french("fr", "FR"); | |
374ca955 | 460 | Locale croatian("ca", "ES"); |
b75a7d8f A |
461 | Locale greek("el", "GR"); |
462 | ||
463 | logln(" In locale = en_US..."); | |
464 | doTestDisplayNames(english, DLANG_EN); | |
465 | logln(" In locale = fr_FR..."); | |
466 | doTestDisplayNames(french, DLANG_FR); | |
374ca955 A |
467 | logln(" In locale = ca_ES..."); |
468 | doTestDisplayNames(croatian, DLANG_CA); | |
b75a7d8f A |
469 | logln(" In locale = el_GR..."); |
470 | doTestDisplayNames(greek, DLANG_EL); | |
471 | ||
b75a7d8f | 472 | UnicodeString s; |
46f4442e | 473 | UErrorCode status = U_ZERO_ERROR; |
b75a7d8f | 474 | |
46f4442e A |
475 | #if !UCONFIG_NO_FORMATTING |
476 | DecimalFormatSymbols symb(status); | |
477 | /* Check to see if ICU supports this locale */ | |
478 | if (symb.getLocale(ULOC_VALID_LOCALE, status) != Locale("root")) { | |
479 | /* test that the default locale has a display name for its own language */ | |
729e4ab9 A |
480 | /* Currently, there is no language information in the "tl" data file so this test will fail if default locale is "tl" */ |
481 | if (uprv_strcmp(Locale().getLanguage(), "tl") != 0) { | |
482 | Locale().getDisplayLanguage(Locale(), s); | |
483 | if(s.length()<=3 && s.charAt(0)<=0x7f) { | |
484 | /* check <=3 to reject getting the language code as a display name */ | |
485 | dataerrln("unable to get a display string for the language of the default locale: " + s); | |
486 | } | |
46f4442e | 487 | |
729e4ab9 A |
488 | /* |
489 | * API coverage improvements: call | |
490 | * Locale::getDisplayLanguage(UnicodeString &) and | |
491 | * Locale::getDisplayCountry(UnicodeString &) | |
492 | */ | |
493 | s.remove(); | |
494 | Locale().getDisplayLanguage(s); | |
495 | if(s.length()<=3 && s.charAt(0)<=0x7f) { | |
496 | dataerrln("unable to get a display string for the language of the default locale [2]: " + s); | |
497 | } | |
46f4442e A |
498 | } |
499 | } | |
500 | else { | |
501 | logln("Default locale %s is unsupported by ICU\n", Locale().getName()); | |
b75a7d8f A |
502 | } |
503 | s.remove(); | |
46f4442e A |
504 | #endif |
505 | ||
b75a7d8f A |
506 | french.getDisplayCountry(s); |
507 | if(s.isEmpty()) { | |
508 | errln("unable to get any default-locale display string for the country of fr_FR\n"); | |
509 | } | |
73c04bcf A |
510 | s.remove(); |
511 | Locale("zh", "Hant").getDisplayScript(s); | |
512 | if(s.isEmpty()) { | |
513 | errln("unable to get any default-locale display string for the country of zh_Hant\n"); | |
b75a7d8f | 514 | } |
73c04bcf | 515 | } |
b75a7d8f A |
516 | |
517 | void LocaleTest::TestSimpleObjectStuff() { | |
518 | Locale test1("aa", "AA"); | |
519 | Locale test2("aa", "AA"); | |
520 | Locale test3(test1); | |
521 | Locale test4("zz", "ZZ"); | |
374ca955 A |
522 | Locale test5("aa", "AA", ""); |
523 | Locale test6("aa", "AA", "ANTARES"); | |
b75a7d8f | 524 | Locale test7("aa", "AA", "JUPITER"); |
374ca955 | 525 | Locale test8 = Locale::createFromName("aa-aa-jupiTER"); // was "aa-aa.utf8@jupiter" but in 3.0 getName won't normalize that |
b75a7d8f A |
526 | |
527 | // now list them all for debugging usage. | |
528 | test_dumpLocale(test1); | |
529 | test_dumpLocale(test2); | |
530 | test_dumpLocale(test3); | |
531 | test_dumpLocale(test4); | |
532 | test_dumpLocale(test5); | |
533 | test_dumpLocale(test6); | |
534 | test_dumpLocale(test7); | |
535 | test_dumpLocale(test8); | |
536 | ||
537 | // Make sure things compare to themselves! | |
538 | test_assert(test1 == test1); | |
539 | test_assert(test2 == test2); | |
540 | test_assert(test3 == test3); | |
541 | test_assert(test4 == test4); | |
542 | test_assert(test5 == test5); | |
543 | test_assert(test6 == test6); | |
544 | test_assert(test7 == test7); | |
545 | test_assert(test8 == test8); | |
546 | ||
547 | // make sure things are not equal to themselves. | |
548 | test_assert(!(test1 != test1)); | |
549 | test_assert(!(test2 != test2)); | |
550 | test_assert(!(test3 != test3)); | |
551 | test_assert(!(test4 != test4)); | |
552 | test_assert(!(test5 != test5)); | |
553 | test_assert(!(test6 != test6)); | |
554 | test_assert(!(test7 != test7)); | |
555 | test_assert(!(test8 != test8)); | |
556 | ||
557 | // make sure things that are equal to each other don't show up as unequal. | |
558 | test_assert(!(test1 != test2)); | |
559 | test_assert(!(test2 != test1)); | |
560 | test_assert(!(test1 != test3)); | |
561 | test_assert(!(test2 != test3)); | |
562 | test_assert(test5 == test1); | |
563 | test_assert(test6 != test2); | |
564 | test_assert(test6 != test5); | |
565 | ||
566 | test_assert(test6 != test7); | |
567 | ||
568 | // test for things that shouldn't compare equal. | |
569 | test_assert(!(test1 == test4)); | |
570 | test_assert(!(test2 == test4)); | |
571 | test_assert(!(test3 == test4)); | |
572 | ||
573 | test_assert(test7 == test8); | |
574 | ||
575 | // test for hash codes to be the same. | |
576 | int32_t hash1 = test1.hashCode(); | |
577 | int32_t hash2 = test2.hashCode(); | |
578 | int32_t hash3 = test3.hashCode(); | |
579 | ||
580 | test_assert(hash1 == hash2); | |
581 | test_assert(hash1 == hash3); | |
582 | test_assert(hash2 == hash3); | |
583 | ||
584 | // test that the assignment operator works. | |
585 | test4 = test1; | |
586 | logln("test4=test1;"); | |
587 | test_dumpLocale(test4); | |
588 | test_assert(test4 == test4); | |
589 | ||
590 | test_assert(!(test1 != test4)); | |
591 | test_assert(!(test2 != test4)); | |
592 | test_assert(!(test3 != test4)); | |
593 | test_assert(test1 == test4); | |
594 | test_assert(test4 == test1); | |
374ca955 | 595 | |
b75a7d8f A |
596 | // test assignments with a variant |
597 | logln("test7 = test6"); | |
598 | test7 = test6; | |
599 | test_dumpLocale(test7); | |
600 | test_assert(test7 == test7); | |
601 | test_assert(test7 == test6); | |
602 | test_assert(test7 != test5); | |
603 | ||
604 | logln("test6 = test1"); | |
605 | test6=test1; | |
606 | test_dumpLocale(test6); | |
607 | test_assert(test6 != test7); | |
608 | test_assert(test6 == test1); | |
609 | test_assert(test6 == test6); | |
610 | } | |
611 | ||
612 | // A class which exposes constructors that are implemented in terms of the POSIX parsing code. | |
613 | class POSIXLocale : public Locale | |
614 | { | |
615 | public: | |
616 | POSIXLocale(const UnicodeString& l) | |
617 | :Locale() | |
618 | { | |
619 | char *ch; | |
620 | ch = new char[l.length() + 1]; | |
621 | ch[l.extract(0, 0x7fffffff, ch, "")] = 0; | |
622 | setFromPOSIXID(ch); | |
623 | delete [] ch; | |
624 | } | |
625 | POSIXLocale(const char *l) | |
626 | :Locale() | |
627 | { | |
628 | setFromPOSIXID(l); | |
629 | } | |
630 | }; | |
631 | ||
632 | void LocaleTest::TestPOSIXParsing() | |
633 | { | |
634 | POSIXLocale test1("ab_AB"); | |
635 | POSIXLocale test2(UnicodeString("ab_AB")); | |
636 | Locale test3("ab","AB"); | |
637 | ||
638 | POSIXLocale test4("ab_AB_Antares"); | |
639 | POSIXLocale test5(UnicodeString("ab_AB_Antares")); | |
374ca955 | 640 | Locale test6("ab", "AB", "Antares"); |
b75a7d8f A |
641 | |
642 | test_dumpLocale(test1); | |
643 | test_dumpLocale(test2); | |
644 | test_dumpLocale(test3); | |
645 | test_dumpLocale(test4); | |
646 | test_dumpLocale(test5); | |
647 | test_dumpLocale(test6); | |
648 | ||
649 | test_assert(test1 == test1); | |
650 | ||
651 | test_assert(test1 == test2); | |
652 | test_assert(test2 == test3); | |
653 | test_assert(test3 == test1); | |
654 | ||
655 | test_assert(test4 == test5); | |
656 | test_assert(test5 == test6); | |
657 | test_assert(test6 == test4); | |
658 | ||
659 | test_assert(test1 != test4); | |
660 | test_assert(test5 != test3); | |
661 | test_assert(test5 != test2); | |
662 | ||
663 | int32_t hash1 = test1.hashCode(); | |
664 | int32_t hash2 = test2.hashCode(); | |
665 | int32_t hash3 = test3.hashCode(); | |
666 | ||
667 | test_assert(hash1 == hash2); | |
668 | test_assert(hash2 == hash3); | |
669 | test_assert(hash3 == hash1); | |
670 | } | |
671 | ||
672 | void LocaleTest::TestGetAvailableLocales() | |
673 | { | |
674 | int32_t locCount = 0; | |
675 | const Locale* locList = Locale::getAvailableLocales(locCount); | |
676 | ||
677 | if (locCount == 0) | |
729e4ab9 | 678 | dataerrln("getAvailableLocales() returned an empty list!"); |
b75a7d8f A |
679 | else { |
680 | logln(UnicodeString("Number of locales returned = ") + locCount); | |
681 | UnicodeString temp; | |
682 | for(int32_t i = 0; i < locCount; ++i) | |
683 | logln(locList[i].getName()); | |
684 | } | |
685 | // I have no idea how to test this function... | |
686 | } | |
687 | ||
688 | // This test isn't applicable anymore - getISO3Language is | |
689 | // independent of the data directory | |
690 | void LocaleTest::TestDataDirectory() | |
691 | { | |
692 | /* | |
693 | char oldDirectory[80]; | |
694 | const char* temp; | |
695 | UErrorCode err = U_ZERO_ERROR; | |
696 | UnicodeString testValue; | |
697 | ||
698 | temp = Locale::getDataDirectory(); | |
699 | strcpy(oldDirectory, temp); | |
700 | logln(UnicodeString("oldDirectory = ") + oldDirectory); | |
701 | ||
702 | Locale test(Locale::US); | |
703 | test.getISO3Language(testValue); | |
704 | logln("first fetch of language retrieved " + testValue); | |
705 | if (testValue != "eng") | |
706 | errln("Initial check of ISO3 language failed: expected \"eng\", got \"" + testValue + "\""); | |
707 | ||
708 | { | |
709 | char *path; | |
710 | path=IntlTest::getTestDirectory(); | |
711 | Locale::setDataDirectory( path ); | |
712 | } | |
713 | ||
714 | test.getISO3Language(testValue); | |
715 | logln("second fetch of language retrieved " + testValue); | |
716 | if (testValue != "xxx") | |
717 | errln("setDataDirectory() failed: expected \"xxx\", got \"" + testValue + "\""); | |
374ca955 | 718 | |
b75a7d8f A |
719 | Locale::setDataDirectory(oldDirectory); |
720 | test.getISO3Language(testValue); | |
721 | logln("third fetch of language retrieved " + testValue); | |
722 | if (testValue != "eng") | |
723 | errln("get/setDataDirectory() failed: expected \"eng\", got \"" + testValue + "\""); | |
724 | */ | |
725 | } | |
726 | ||
727 | //=========================================================== | |
728 | ||
729 | void LocaleTest::doTestDisplayNames(Locale& displayLocale, int32_t compareIndex) { | |
730 | UnicodeString temp; | |
374ca955 | 731 | |
b75a7d8f | 732 | for (int32_t i = 0; i <= MAX_LOCALES; i++) { |
374ca955 A |
733 | Locale testLocale(""); |
734 | if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) { | |
735 | testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i], rawData[VAR][i]); | |
736 | } | |
737 | else { | |
738 | testLocale = Locale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); | |
739 | } | |
b75a7d8f A |
740 | logln(" Testing " + (temp=testLocale.getName()) + "..."); |
741 | ||
742 | UnicodeString testLang; | |
374ca955 | 743 | UnicodeString testScript; |
b75a7d8f A |
744 | UnicodeString testCtry; |
745 | UnicodeString testVar; | |
746 | UnicodeString testName; | |
747 | ||
748 | testLocale.getDisplayLanguage(displayLocale, testLang); | |
374ca955 | 749 | testLocale.getDisplayScript(displayLocale, testScript); |
b75a7d8f A |
750 | testLocale.getDisplayCountry(displayLocale, testCtry); |
751 | testLocale.getDisplayVariant(displayLocale, testVar); | |
752 | testLocale.getDisplayName(displayLocale, testName); | |
753 | ||
754 | UnicodeString expectedLang; | |
374ca955 | 755 | UnicodeString expectedScript; |
b75a7d8f A |
756 | UnicodeString expectedCtry; |
757 | UnicodeString expectedVar; | |
758 | UnicodeString expectedName; | |
759 | ||
760 | expectedLang = dataTable[compareIndex][i]; | |
761 | if (expectedLang.length() == 0) | |
762 | expectedLang = dataTable[DLANG_EN][i]; | |
763 | ||
374ca955 A |
764 | expectedScript = dataTable[compareIndex + 1][i]; |
765 | if (expectedScript.length() == 0) | |
766 | expectedScript = dataTable[DSCRIPT_EN][i]; | |
767 | ||
768 | expectedCtry = dataTable[compareIndex + 2][i]; | |
b75a7d8f A |
769 | if (expectedCtry.length() == 0) |
770 | expectedCtry = dataTable[DCTRY_EN][i]; | |
771 | ||
374ca955 | 772 | expectedVar = dataTable[compareIndex + 3][i]; |
b75a7d8f A |
773 | if (expectedVar.length() == 0) |
774 | expectedVar = dataTable[DVAR_EN][i]; | |
775 | ||
374ca955 | 776 | expectedName = dataTable[compareIndex + 4][i]; |
b75a7d8f A |
777 | if (expectedName.length() == 0) |
778 | expectedName = dataTable[DNAME_EN][i]; | |
779 | ||
780 | if (testLang != expectedLang) | |
729e4ab9 | 781 | dataerrln("Display language (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testLang + " expected " + expectedLang); |
374ca955 | 782 | if (testScript != expectedScript) |
729e4ab9 | 783 | dataerrln("Display script (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testScript + " expected " + expectedScript); |
b75a7d8f | 784 | if (testCtry != expectedCtry) |
729e4ab9 | 785 | dataerrln("Display country (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testCtry + " expected " + expectedCtry); |
b75a7d8f | 786 | if (testVar != expectedVar) |
729e4ab9 | 787 | dataerrln("Display variant (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testVar + " expected " + expectedVar); |
b75a7d8f | 788 | if (testName != expectedName) |
729e4ab9 | 789 | dataerrln("Display name (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testName + " expected " + expectedName); |
b75a7d8f A |
790 | } |
791 | } | |
792 | ||
793 | //--------------------------------------------------- | |
794 | // table of valid data | |
795 | //--------------------------------------------------- | |
796 | ||
797 | ||
374ca955 | 798 | |
b75a7d8f A |
799 | void LocaleTest::setUpDataTable() |
800 | { | |
801 | if (dataTable == 0) { | |
374ca955 | 802 | dataTable = new UnicodeString*[33]; |
b75a7d8f | 803 | |
374ca955 A |
804 | for (int32_t i = 0; i < 33; i++) { |
805 | dataTable[i] = new UnicodeString[8]; | |
806 | for (int32_t j = 0; j < 8; j++) { | |
b75a7d8f A |
807 | dataTable[i][j] = CharsToUnicodeString(rawData[i][j]); |
808 | } | |
809 | } | |
b75a7d8f A |
810 | } |
811 | } | |
812 | ||
813 | // ==================== | |
814 | ||
815 | ||
816 | /** | |
817 | * @bug 4011756 4011380 | |
818 | */ | |
374ca955 A |
819 | void |
820 | LocaleTest::TestISO3Fallback() | |
b75a7d8f A |
821 | { |
822 | Locale test("xx", "YY"); | |
823 | ||
824 | const char * result; | |
825 | ||
826 | result = test.getISO3Language(); | |
827 | ||
374ca955 | 828 | // Conform to C API usage |
b75a7d8f A |
829 | |
830 | if (!result || (result[0] != 0)) | |
831 | errln("getISO3Language() on xx_YY returned " + UnicodeString(result) + " instead of \"\""); | |
832 | ||
833 | result = test.getISO3Country(); | |
834 | ||
835 | if (!result || (result[0] != 0)) | |
836 | errln("getISO3Country() on xx_YY returned " + UnicodeString(result) + " instead of \"\""); | |
837 | } | |
838 | ||
839 | /** | |
840 | * @bug 4106155 4118587 | |
841 | */ | |
374ca955 A |
842 | void |
843 | LocaleTest::TestGetLangsAndCountries() | |
b75a7d8f A |
844 | { |
845 | // It didn't seem right to just do an exhaustive test of everything here, so I check | |
846 | // for the following things: | |
847 | // 1) Does each list have the right total number of entries? | |
848 | // 2) Does each list contain certain language and country codes we think are important | |
849 | // (the G7 countries, plus a couple others)? | |
850 | // 3) Does each list have every entry formatted correctly? (i.e., two characters, | |
851 | // all lower case for the language codes, all upper case for the country codes) | |
852 | // 4) Is each list in sorted order? | |
853 | int32_t testCount = 0; | |
854 | const char * const * test = Locale::getISOLanguages(); | |
374ca955 A |
855 | const char spotCheck1[ ][4] = { "en", "es", "fr", "de", "it", |
856 | "ja", "ko", "zh", "th", "he", | |
b75a7d8f A |
857 | "id", "iu", "ug", "yi", "za" }; |
858 | ||
859 | int32_t i; | |
374ca955 | 860 | |
b75a7d8f A |
861 | for(testCount = 0;test[testCount];testCount++) |
862 | ; | |
863 | ||
374ca955 | 864 | /* TODO: Change this test to be more like the cloctst version? */ |
2ca993e8 A |
865 | if (testCount != 594) |
866 | errln("Expected getISOLanguages() to return 594 languages; it returned %d", testCount); | |
b75a7d8f A |
867 | else { |
868 | for (i = 0; i < 15; i++) { | |
869 | int32_t j; | |
870 | for (j = 0; j < testCount; j++) | |
871 | if (uprv_strcmp(test[j],spotCheck1[i])== 0) | |
872 | break; | |
873 | if (j == testCount || (uprv_strcmp(test[j],spotCheck1[i])!=0)) | |
874 | errln("Couldn't find " + (UnicodeString)spotCheck1[i] + " in language list."); | |
875 | } | |
876 | } | |
877 | for (i = 0; i < testCount; i++) { | |
878 | UnicodeString testee(test[i],""); | |
879 | UnicodeString lc(test[i],""); | |
880 | if (testee != lc.toLower()) | |
881 | errln(lc + " is not all lower case."); | |
882 | if ( (testee.length() != 2) && (testee.length() != 3)) | |
883 | errln(testee + " is not two or three characters long."); | |
884 | if (i > 0 && testee.compare(test[i - 1]) <= 0) | |
885 | errln(testee + " appears in an out-of-order position in the list."); | |
886 | } | |
887 | ||
888 | test = Locale::getISOCountries(); | |
374ca955 A |
889 | UnicodeString spotCheck2 [] = { "US", "CA", "GB", "FR", "DE", |
890 | "IT", "JP", "KR", "CN", "TW", | |
b75a7d8f A |
891 | "TH" }; |
892 | int32_t spot2Len = 11; | |
893 | for(testCount=0;test[testCount];testCount++) | |
894 | ; | |
895 | ||
2ca993e8 A |
896 | if (testCount != 256){ |
897 | errln("Expected getISOCountries to return 256 countries; it returned %d", testCount); | |
73c04bcf | 898 | }else { |
b75a7d8f A |
899 | for (i = 0; i < spot2Len; i++) { |
900 | int32_t j; | |
901 | for (j = 0; j < testCount; j++) | |
902 | { | |
903 | UnicodeString testee(test[j],""); | |
904 | ||
905 | if (testee == spotCheck2[i]) | |
906 | break; | |
907 | } | |
908 | UnicodeString testee(test[j],""); | |
909 | if (j == testCount || testee != spotCheck2[i]) | |
910 | errln("Couldn't find " + spotCheck2[i] + " in country list."); | |
911 | } | |
912 | } | |
4388f060 A |
913 | for (i = 0; i < testCount; i++) { |
914 | UnicodeString testee(test[i],""); | |
b75a7d8f A |
915 | UnicodeString uc(test[i],""); |
916 | if (testee != uc.toUpper()) | |
917 | errln(testee + " is not all upper case."); | |
918 | if (testee.length() != 2) | |
919 | errln(testee + " is not two characters long."); | |
920 | if (i > 0 && testee.compare(test[i - 1]) <= 0) | |
921 | errln(testee + " appears in an out-of-order position in the list."); | |
922 | } | |
4388f060 A |
923 | |
924 | // This getAvailableLocales and getISO3Language | |
925 | { | |
926 | int32_t numOfLocales; | |
927 | Locale enLoc ("en"); | |
928 | const Locale *pLocales = Locale::getAvailableLocales(numOfLocales); | |
929 | ||
930 | for (int i = 0; i < numOfLocales; i++) { | |
931 | const Locale &loc(pLocales[i]); | |
932 | UnicodeString name; | |
933 | char szName[200]; | |
934 | ||
935 | loc.getDisplayName (enLoc, name); | |
936 | name.extract (0, 200, szName, sizeof(szName)); | |
937 | ||
938 | if (strlen(loc.getISO3Language()) == 0) { | |
939 | errln("getISO3Language() returned an empty string for: " + name); | |
940 | } | |
941 | } | |
942 | } | |
b75a7d8f A |
943 | } |
944 | ||
945 | /** | |
946 | * @bug 4118587 | |
947 | */ | |
374ca955 A |
948 | void |
949 | LocaleTest::TestSimpleDisplayNames() | |
b75a7d8f A |
950 | { |
951 | // This test is different from TestDisplayNames because TestDisplayNames checks | |
952 | // fallback behavior, combination of language and country names to form locale | |
953 | // names, and other stuff like that. This test just checks specific language | |
954 | // and country codes to make sure we have the correct names for them. | |
955 | char languageCodes[] [4] = { "he", "id", "iu", "ug", "yi", "za" }; | |
51004dcb | 956 | UnicodeString languageNames [] = { "Hebrew", "Indonesian", "Inuktitut", "Uyghur", "Yiddish", |
b75a7d8f A |
957 | "Zhuang" }; |
958 | ||
959 | for (int32_t i = 0; i < 6; i++) { | |
960 | UnicodeString test; | |
961 | Locale l(languageCodes[i], "", ""); | |
962 | l.getDisplayLanguage(Locale::getUS(), test); | |
963 | if (test != languageNames[i]) | |
729e4ab9 | 964 | dataerrln("Got wrong display name for " + UnicodeString(languageCodes[i]) + ": Expected \"" + |
b75a7d8f A |
965 | languageNames[i] + "\", got \"" + test + "\"."); |
966 | } | |
967 | } | |
968 | ||
969 | /** | |
970 | * @bug 4118595 | |
971 | */ | |
374ca955 A |
972 | void |
973 | LocaleTest::TestUninstalledISO3Names() | |
b75a7d8f A |
974 | { |
975 | // This test checks to make sure getISO3Language and getISO3Country work right | |
976 | // even for locales that are not installed. | |
374ca955 | 977 | const char iso2Languages [][4] = { "am", "ba", "fy", "mr", "rn", |
b75a7d8f | 978 | "ss", "tw", "zu" }; |
374ca955 | 979 | const char iso3Languages [][5] = { "amh", "bak", "fry", "mar", "run", |
b75a7d8f A |
980 | "ssw", "twi", "zul" }; |
981 | ||
982 | int32_t i; | |
983 | ||
984 | for (i = 0; i < 8; i++) { | |
985 | UErrorCode err = U_ZERO_ERROR; | |
986 | ||
987 | UnicodeString test; | |
988 | Locale l(iso2Languages[i], "", ""); | |
989 | test = l.getISO3Language(); | |
990 | if((test != iso3Languages[i]) || U_FAILURE(err)) | |
991 | errln("Got wrong ISO3 code for " + UnicodeString(iso2Languages[i]) + ": Expected \"" + | |
992 | iso3Languages[i] + "\", got \"" + test + "\"." + UnicodeString(u_errorName(err))); | |
993 | } | |
994 | ||
374ca955 | 995 | char iso2Countries [][4] = { "AF", "BW", "KZ", "MO", "MN", |
b75a7d8f | 996 | "SB", "TC", "ZW" }; |
374ca955 | 997 | char iso3Countries [][4] = { "AFG", "BWA", "KAZ", "MAC", "MNG", |
b75a7d8f A |
998 | "SLB", "TCA", "ZWE" }; |
999 | ||
1000 | for (i = 0; i < 8; i++) { | |
1001 | UErrorCode err = U_ZERO_ERROR; | |
1002 | Locale l("", iso2Countries[i], ""); | |
1003 | UnicodeString test(l.getISO3Country(), ""); | |
1004 | if (test != iso3Countries[i]) | |
1005 | errln("Got wrong ISO3 code for " + UnicodeString(iso2Countries[i]) + ": Expected \"" + | |
1006 | UnicodeString(iso3Countries[i]) + "\", got \"" + test + "\"." + u_errorName(err)); | |
1007 | } | |
1008 | } | |
1009 | ||
1010 | /** | |
1011 | * @bug 4092475 | |
1012 | * I could not reproduce this bug. I'm pretty convinced it was fixed with the | |
1013 | * big locale-data reorg of 10/28/97. The lookup logic for language and country | |
1014 | * display names was also changed at that time in that check-in. --rtg 3/20/98 | |
1015 | */ | |
374ca955 A |
1016 | void |
1017 | LocaleTest::TestAtypicalLocales() | |
b75a7d8f A |
1018 | { |
1019 | Locale localesToTest [] = { Locale("de", "CA"), | |
1020 | Locale("ja", "ZA"), | |
1021 | Locale("ru", "MX"), | |
1022 | Locale("en", "FR"), | |
1023 | Locale("es", "DE"), | |
1024 | Locale("", "HR"), | |
1025 | Locale("", "SE"), | |
1026 | Locale("", "DO"), | |
1027 | Locale("", "BE") }; | |
1028 | ||
1029 | UnicodeString englishDisplayNames [] = { "German (Canada)", | |
1030 | "Japanese (South Africa)", | |
1031 | "Russian (Mexico)", | |
1032 | "English (France)", | |
1033 | "Spanish (Germany)", | |
1034 | "Croatia", | |
1035 | "Sweden", | |
1036 | "Dominican Republic", | |
1037 | "Belgium" }; | |
1038 | UnicodeString frenchDisplayNames []= { "allemand (Canada)", | |
1039 | "japonais (Afrique du Sud)", | |
1040 | "russe (Mexique)", | |
1041 | "anglais (France)", | |
1042 | "espagnol (Allemagne)", | |
1043 | "Croatie", | |
1044 | CharsToUnicodeString("Su\\u00E8de"), | |
46f4442e | 1045 | CharsToUnicodeString("R\\u00E9publique dominicaine"), |
b75a7d8f A |
1046 | "Belgique" }; |
1047 | UnicodeString spanishDisplayNames [] = { | |
1048 | CharsToUnicodeString("alem\\u00E1n (Canad\\u00E1)"), | |
1049 | CharsToUnicodeString("japon\\u00E9s (Sud\\u00E1frica)"), | |
1050 | CharsToUnicodeString("ruso (M\\u00E9xico)"), | |
1051 | CharsToUnicodeString("ingl\\u00E9s (Francia)"), | |
1052 | CharsToUnicodeString("espa\\u00F1ol (Alemania)"), | |
1053 | "Croacia", | |
1054 | "Suecia", | |
1055 | CharsToUnicodeString("Rep\\u00FAblica Dominicana"), | |
1056 | CharsToUnicodeString("B\\u00E9lgica") }; | |
374ca955 A |
1057 | // De-Anglicizing root required the change from |
1058 | // English display names to ISO Codes - ram 2003/09/26 | |
73c04bcf A |
1059 | UnicodeString invDisplayNames [] = { "German (Canada)", |
1060 | "Japanese (South Africa)", | |
1061 | "Russian (Mexico)", | |
1062 | "English (France)", | |
1063 | "Spanish (Germany)", | |
1064 | "Croatia", | |
1065 | "Sweden", | |
1066 | "Dominican Republic", | |
1067 | "Belgium" }; | |
b75a7d8f A |
1068 | |
1069 | int32_t i; | |
1070 | UErrorCode status = U_ZERO_ERROR; | |
73c04bcf | 1071 | Locale saveLocale; |
b75a7d8f A |
1072 | Locale::setDefault(Locale::getUS(), status); |
1073 | for (i = 0; i < 9; ++i) { | |
1074 | UnicodeString name; | |
1075 | localesToTest[i].getDisplayName(Locale::getUS(), name); | |
1076 | logln(name); | |
1077 | if (name != englishDisplayNames[i]) | |
1078 | { | |
729e4ab9 | 1079 | dataerrln("Lookup in English failed: expected \"" + englishDisplayNames[i] |
b75a7d8f A |
1080 | + "\", got \"" + name + "\""); |
1081 | logln("Locale name was-> " + (name=localesToTest[i].getName())); | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | for (i = 0; i < 9; i++) { | |
1086 | UnicodeString name; | |
1087 | localesToTest[i].getDisplayName(Locale("es", "ES"), name); | |
1088 | logln(name); | |
1089 | if (name != spanishDisplayNames[i]) | |
729e4ab9 | 1090 | dataerrln("Lookup in Spanish failed: expected \"" + spanishDisplayNames[i] |
b75a7d8f A |
1091 | + "\", got \"" + name + "\""); |
1092 | } | |
1093 | ||
1094 | for (i = 0; i < 9; i++) { | |
1095 | UnicodeString name; | |
1096 | localesToTest[i].getDisplayName(Locale::getFrance(), name); | |
1097 | logln(name); | |
1098 | if (name != frenchDisplayNames[i]) | |
729e4ab9 | 1099 | dataerrln("Lookup in French failed: expected \"" + frenchDisplayNames[i] |
b75a7d8f A |
1100 | + "\", got \"" + name + "\""); |
1101 | } | |
1102 | ||
1103 | for (i = 0; i < 9; i++) { | |
1104 | UnicodeString name; | |
73c04bcf | 1105 | localesToTest[i].getDisplayName(Locale("inv", "IN"), name); |
374ca955 | 1106 | logln(name + " Locale fallback to be, and data fallback to root"); |
73c04bcf | 1107 | if (name != invDisplayNames[i]) |
729e4ab9 | 1108 | dataerrln("Lookup in INV failed: expected \"" + prettify(invDisplayNames[i]) |
73c04bcf A |
1109 | + "\", got \"" + prettify(name) + "\""); |
1110 | localesToTest[i].getDisplayName(Locale("inv", "BD"), name); | |
b75a7d8f | 1111 | logln(name + " Data fallback to root"); |
73c04bcf | 1112 | if (name != invDisplayNames[i]) |
729e4ab9 | 1113 | dataerrln("Lookup in INV failed: expected \"" + prettify(invDisplayNames[i]) |
73c04bcf | 1114 | + "\", got \"" + prettify(name )+ "\""); |
b75a7d8f | 1115 | } |
73c04bcf | 1116 | Locale::setDefault(saveLocale, status); |
b75a7d8f A |
1117 | } |
1118 | ||
1119 | #if !UCONFIG_NO_FORMATTING | |
1120 | ||
1121 | /** | |
1122 | * @bug 4135752 | |
1123 | * This would be better tested by the LocaleDataTest. Will move it when I | |
1124 | * get the LocaleDataTest working again. | |
1125 | */ | |
374ca955 A |
1126 | void |
1127 | LocaleTest::TestThaiCurrencyFormat() | |
b75a7d8f A |
1128 | { |
1129 | UErrorCode status = U_ZERO_ERROR; | |
1130 | DecimalFormat *thaiCurrency = (DecimalFormat*)NumberFormat::createCurrencyInstance( | |
1131 | Locale("th", "TH"), status); | |
b331163b | 1132 | UnicodeString posPrefix("THB", 3, US_INV); // per cldrbug 7618 |
b75a7d8f A |
1133 | UnicodeString temp; |
1134 | ||
1135 | if(U_FAILURE(status) || !thaiCurrency) | |
1136 | { | |
729e4ab9 | 1137 | dataerrln("Couldn't get th_TH currency -> " + UnicodeString(u_errorName(status))); |
b75a7d8f A |
1138 | return; |
1139 | } | |
b331163b A |
1140 | if (thaiCurrency->getPositivePrefix(temp) != posPrefix) |
1141 | errln("Thai currency prefix wrong: expected THB, got \"" + | |
b75a7d8f A |
1142 | thaiCurrency->getPositivePrefix(temp) + "\""); |
1143 | if (thaiCurrency->getPositiveSuffix(temp) != "") | |
1144 | errln("Thai currency suffix wrong: expected \"\", got \"" + | |
1145 | thaiCurrency->getPositiveSuffix(temp) + "\""); | |
1146 | ||
1147 | delete thaiCurrency; | |
1148 | } | |
1149 | ||
1150 | /** | |
1151 | * @bug 4122371 | |
1152 | * Confirm that Euro support works. This test is pretty rudimentary; all it does | |
1153 | * is check that any locales with the EURO variant format a number using the | |
1154 | * Euro currency symbol. | |
1155 | * | |
1156 | * ASSUME: All locales encode the Euro character "\u20AC". | |
1157 | * If this is changed to use the single-character Euro symbol, this | |
1158 | * test must be updated. | |
1159 | * | |
1160 | */ | |
374ca955 A |
1161 | void |
1162 | LocaleTest::TestEuroSupport() | |
b75a7d8f A |
1163 | { |
1164 | UChar euro = 0x20ac; | |
1165 | const UnicodeString EURO_CURRENCY(&euro, 1, 1); // Look for this UnicodeString in formatted Euro currency | |
1166 | const char* localeArr[] = { | |
1167 | "ca_ES", | |
1168 | "de_AT", | |
1169 | "de_DE", | |
1170 | "de_LU", | |
1171 | "el_GR", | |
1172 | "en_BE", | |
1173 | "en_IE", | |
374ca955 A |
1174 | "en_GB_EURO", |
1175 | "en_US_EURO", | |
b75a7d8f A |
1176 | "es_ES", |
1177 | "eu_ES", | |
1178 | "fi_FI", | |
1179 | "fr_BE", | |
1180 | "fr_FR", | |
1181 | "fr_LU", | |
1182 | "ga_IE", | |
1183 | "gl_ES", | |
1184 | "it_IT", | |
1185 | "nl_BE", | |
1186 | "nl_NL", | |
1187 | "pt_PT", | |
1188 | NULL | |
1189 | }; | |
1190 | const char** locales = localeArr; | |
1191 | ||
1192 | UErrorCode status = U_ZERO_ERROR; | |
1193 | ||
1194 | UnicodeString temp; | |
1195 | ||
1196 | for (;*locales!=NULL;locales++) { | |
1197 | Locale loc (*locales); | |
1198 | UnicodeString temp; | |
374ca955 A |
1199 | NumberFormat *nf = NumberFormat::createCurrencyInstance(loc, status); |
1200 | UnicodeString pos; | |
73c04bcf A |
1201 | |
1202 | if (U_FAILURE(status)) { | |
1203 | dataerrln("Error calling NumberFormat::createCurrencyInstance(%s)", *locales); | |
1204 | continue; | |
1205 | } | |
1206 | ||
374ca955 A |
1207 | nf->format(271828.182845, pos); |
1208 | UnicodeString neg; | |
1209 | nf->format(-271828.182845, neg); | |
1210 | if (pos.indexOf(EURO_CURRENCY) >= 0 && | |
1211 | neg.indexOf(EURO_CURRENCY) >= 0) { | |
1212 | logln("Ok: " + (temp=loc.getName()) + | |
1213 | ": " + pos + " / " + neg); | |
1214 | } | |
1215 | else { | |
1216 | errln("Fail: " + (temp=loc.getName()) + | |
1217 | " formats without " + EURO_CURRENCY + | |
1218 | ": " + pos + " / " + neg + | |
1219 | "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***"); | |
1220 | } | |
1221 | ||
1222 | delete nf; | |
1223 | } | |
1224 | ||
1225 | UnicodeString dollarStr("USD", ""), euroStr("EUR", ""), genericStr((UChar)0x00a4), resultStr; | |
1226 | UChar tmp[4]; | |
1227 | status = U_ZERO_ERROR; | |
1228 | ||
1229 | ucurr_forLocale("en_US", tmp, 4, &status); | |
1230 | resultStr.setTo(tmp); | |
1231 | if (dollarStr != resultStr) { | |
729e4ab9 | 1232 | errcheckln(status, "Fail: en_US didn't return USD - %s", u_errorName(status)); |
374ca955 A |
1233 | } |
1234 | ucurr_forLocale("en_US_EURO", tmp, 4, &status); | |
1235 | resultStr.setTo(tmp); | |
1236 | if (euroStr != resultStr) { | |
729e4ab9 | 1237 | errcheckln(status, "Fail: en_US_EURO didn't return EUR - %s", u_errorName(status)); |
374ca955 A |
1238 | } |
1239 | ucurr_forLocale("en_GB_EURO", tmp, 4, &status); | |
1240 | resultStr.setTo(tmp); | |
1241 | if (euroStr != resultStr) { | |
729e4ab9 | 1242 | errcheckln(status, "Fail: en_GB_EURO didn't return EUR - %s", u_errorName(status)); |
374ca955 A |
1243 | } |
1244 | ucurr_forLocale("en_US_PREEURO", tmp, 4, &status); | |
1245 | resultStr.setTo(tmp); | |
1246 | if (dollarStr != resultStr) { | |
729e4ab9 | 1247 | errcheckln(status, "Fail: en_US_PREEURO didn't fallback to en_US - %s", u_errorName(status)); |
374ca955 A |
1248 | } |
1249 | ucurr_forLocale("en_US_Q", tmp, 4, &status); | |
1250 | resultStr.setTo(tmp); | |
1251 | if (dollarStr != resultStr) { | |
729e4ab9 | 1252 | errcheckln(status, "Fail: en_US_Q didn't fallback to en_US - %s", u_errorName(status)); |
374ca955 A |
1253 | } |
1254 | int32_t invalidLen = ucurr_forLocale("en_QQ", tmp, 4, &status); | |
1255 | if (invalidLen || U_SUCCESS(status)) { | |
1256 | errln("Fail: en_QQ didn't return NULL"); | |
b75a7d8f A |
1257 | } |
1258 | } | |
1259 | ||
1260 | #endif | |
1261 | ||
1262 | /** | |
1263 | * @bug 4139504 | |
1264 | * toString() doesn't work with language_VARIANT. | |
1265 | */ | |
374ca955 | 1266 | void |
b75a7d8f A |
1267 | LocaleTest::TestToString() { |
1268 | Locale DATA [] = { | |
1269 | Locale("xx", "", ""), | |
1270 | Locale("", "YY", ""), | |
1271 | Locale("", "", "ZZ"), | |
1272 | Locale("xx", "YY", ""), | |
1273 | Locale("xx", "", "ZZ"), | |
1274 | Locale("", "YY", "ZZ"), | |
1275 | Locale("xx", "YY", "ZZ"), | |
1276 | }; | |
1277 | ||
1278 | const char DATA_S [][20] = { | |
1279 | "xx", | |
1280 | "_YY", | |
1281 | "__ZZ", | |
1282 | "xx_YY", | |
1283 | "xx__ZZ", | |
1284 | "_YY_ZZ", | |
1285 | "xx_YY_ZZ", | |
1286 | }; | |
374ca955 | 1287 | |
b75a7d8f A |
1288 | for (int32_t i=0; i < 7; ++i) { |
1289 | const char *name; | |
1290 | name = DATA[i].getName(); | |
1291 | ||
1292 | if (strcmp(name, DATA_S[i]) != 0) | |
1293 | { | |
1294 | errln("Fail: Locale.getName(), got:" + UnicodeString(name) + ", expected: " + DATA_S[i]); | |
1295 | } | |
1296 | else | |
1297 | logln("Pass: Locale.getName(), got:" + UnicodeString(name) ); | |
1298 | } | |
1299 | } | |
1300 | ||
1301 | #if !UCONFIG_NO_FORMATTING | |
1302 | ||
1303 | /** | |
1304 | * @bug 4139940 | |
1305 | * Couldn't reproduce this bug -- probably was fixed earlier. | |
1306 | * | |
1307 | * ORIGINAL BUG REPORT: | |
374ca955 A |
1308 | * -- basically, hungarian for monday shouldn't have an \u00f4 |
1309 | * (o circumflex)in it instead it should be an o with 2 inclined | |
b75a7d8f A |
1310 | * (right) lines over it.. |
1311 | * | |
1312 | * You may wonder -- why do all this -- why not just add a line to | |
1313 | * LocaleData? Well, I could see by inspection that the locale file had the | |
1314 | * right character in it, so I wanted to check the rest of the pipeline -- a | |
1315 | * very remote possibility, but I wanted to be sure. The other possibility | |
1316 | * is that something is wrong with the font mapping subsystem, but we can't | |
1317 | * test that here. | |
1318 | */ | |
374ca955 A |
1319 | void |
1320 | LocaleTest::Test4139940() | |
b75a7d8f | 1321 | { |
374ca955 | 1322 | Locale mylocale("hu", "", ""); |
b75a7d8f A |
1323 | UDate mydate = date(98,3,13); // A Monday |
1324 | UErrorCode status = U_ZERO_ERROR; | |
1325 | SimpleDateFormat df_full("EEEE", mylocale, status); | |
73c04bcf | 1326 | if(U_FAILURE(status)){ |
729e4ab9 | 1327 | dataerrln(UnicodeString("Could not create SimpleDateFormat object for locale hu. Error: ") + UnicodeString(u_errorName(status))); |
73c04bcf A |
1328 | return; |
1329 | } | |
b75a7d8f A |
1330 | UnicodeString str; |
1331 | FieldPosition pos(FieldPosition::DONT_CARE); | |
1332 | df_full.format(mydate, str, pos); | |
1333 | // Make sure that o circumflex (\u00F4) is NOT there, and | |
1334 | // o double acute (\u0151) IS. | |
1335 | UChar ocf = 0x00f4; | |
1336 | UChar oda = 0x0151; | |
374ca955 | 1337 | if (str.indexOf(oda) < 0 || str.indexOf(ocf) >= 0) { |
729e4ab9 A |
1338 | /* If the default locale is "th" this test will fail because of the buddhist calendar. */ |
1339 | if (strcmp(Locale::getDefault().getLanguage(), "th") != 0) { | |
1340 | errln("Fail: Monday in Hungarian is wrong - oda's index is %d and ocf's is %d", | |
1341 | str.indexOf(oda), str.indexOf(ocf)); | |
1342 | } else { | |
1343 | logln(UnicodeString("An error is produce in buddhist calendar.")); | |
1344 | } | |
374ca955 A |
1345 | logln(UnicodeString("String is: ") + str ); |
1346 | } | |
b75a7d8f A |
1347 | } |
1348 | ||
1349 | UDate | |
1350 | LocaleTest::date(int32_t y, int32_t m, int32_t d, int32_t hr, int32_t min, int32_t sec) | |
1351 | { | |
1352 | UErrorCode status = U_ZERO_ERROR; | |
1353 | Calendar *cal = Calendar::createInstance(status); | |
374ca955 | 1354 | if (cal == 0) |
b75a7d8f A |
1355 | return 0.0; |
1356 | cal->clear(); | |
1357 | cal->set(1900 + y, m, d, hr, min, sec); // Add 1900 to follow java.util.Date protocol | |
1358 | UDate dt = cal->getTime(status); | |
1359 | if (U_FAILURE(status)) | |
1360 | return 0.0; | |
374ca955 | 1361 | |
b75a7d8f A |
1362 | delete cal; |
1363 | return dt; | |
1364 | } | |
1365 | ||
1366 | /** | |
1367 | * @bug 4143951 | |
1368 | * Russian first day of week should be Monday. Confirmed. | |
1369 | */ | |
374ca955 A |
1370 | void |
1371 | LocaleTest::Test4143951() | |
b75a7d8f A |
1372 | { |
1373 | UErrorCode status = U_ZERO_ERROR; | |
1374 | Calendar *cal = Calendar::createInstance(Locale("ru", "", ""), status); | |
1375 | if(U_SUCCESS(status)) { | |
1376 | if (cal->getFirstDayOfWeek(status) != UCAL_MONDAY) { | |
729e4ab9 | 1377 | dataerrln("Fail: First day of week in Russia should be Monday"); |
b75a7d8f A |
1378 | } |
1379 | } | |
1380 | delete cal; | |
1381 | } | |
1382 | ||
1383 | #endif | |
1384 | ||
1385 | /** | |
1386 | * @bug 4147315 | |
1387 | * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes. | |
1388 | * Should throw an exception for unknown locales | |
1389 | */ | |
374ca955 A |
1390 | void |
1391 | LocaleTest::Test4147315() | |
b75a7d8f A |
1392 | { |
1393 | UnicodeString temp; | |
1394 | // Try with codes that are the wrong length but happen to match text | |
1395 | // at a valid offset in the mapping table | |
51004dcb | 1396 | Locale locale("xxx", "CCC"); |
374ca955 | 1397 | |
b75a7d8f A |
1398 | const char *result = locale.getISO3Country(); |
1399 | ||
1400 | // Change to conform to C api usage | |
1401 | if((result==NULL)||(result[0] != 0)) | |
374ca955 | 1402 | errln("ERROR: getISO3Country() returns: " + UnicodeString(result,"") + |
b75a7d8f A |
1403 | " for locale '" + (temp=locale.getName()) + "' rather than exception" ); |
1404 | } | |
1405 | ||
1406 | /** | |
1407 | * @bug 4147317 | |
1408 | * java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes. | |
1409 | * Should throw an exception for unknown locales | |
1410 | */ | |
374ca955 A |
1411 | void |
1412 | LocaleTest::Test4147317() | |
b75a7d8f A |
1413 | { |
1414 | UnicodeString temp; | |
1415 | // Try with codes that are the wrong length but happen to match text | |
1416 | // at a valid offset in the mapping table | |
51004dcb | 1417 | Locale locale("xxx", "CCC"); |
374ca955 | 1418 | |
b75a7d8f A |
1419 | const char *result = locale.getISO3Language(); |
1420 | ||
1421 | // Change to conform to C api usage | |
1422 | if((result==NULL)||(result[0] != 0)) | |
374ca955 | 1423 | errln("ERROR: getISO3Language() returns: " + UnicodeString(result,"") + |
b75a7d8f A |
1424 | " for locale '" + (temp=locale.getName()) + "' rather than exception" ); |
1425 | } | |
1426 | ||
1427 | /* | |
1428 | * @bug 4147552 | |
1429 | */ | |
374ca955 A |
1430 | void |
1431 | LocaleTest::Test4147552() | |
b75a7d8f | 1432 | { |
374ca955 | 1433 | Locale locales [] = { Locale("no", "NO"), |
b75a7d8f | 1434 | Locale("no", "NO", "B"), |
374ca955 | 1435 | Locale("no", "NO", "NY") |
b75a7d8f | 1436 | }; |
374ca955 A |
1437 | |
1438 | UnicodeString edn("Norwegian (Norway, B)"); | |
1439 | UnicodeString englishDisplayNames [] = { | |
b75a7d8f A |
1440 | "Norwegian (Norway)", |
1441 | edn, | |
1442 | // "Norwegian (Norway,B)", | |
374ca955 A |
1443 | //"Norwegian (Norway,NY)" |
1444 | "Norwegian (Norway, NY)" | |
b75a7d8f | 1445 | }; |
374ca955 A |
1446 | UnicodeString ndn("norsk (Norge, B"); |
1447 | UnicodeString norwegianDisplayNames [] = { | |
b75a7d8f | 1448 | "norsk (Norge)", |
374ca955 A |
1449 | "norsk (Norge, B)", |
1450 | //ndn, | |
1451 | "norsk (Noreg, NY)" | |
1452 | //"Norsk (Noreg, Nynorsk)" | |
b75a7d8f | 1453 | }; |
73c04bcf | 1454 | UErrorCode status = U_ZERO_ERROR; |
b75a7d8f | 1455 | |
73c04bcf A |
1456 | Locale saveLocale; |
1457 | Locale::setDefault(Locale::getEnglish(), status); | |
b75a7d8f A |
1458 | for (int32_t i = 0; i < 3; ++i) { |
1459 | Locale loc = locales[i]; | |
1460 | UnicodeString temp; | |
1461 | if (loc.getDisplayName(temp) != englishDisplayNames[i]) | |
729e4ab9 | 1462 | dataerrln("English display-name mismatch: expected " + |
b75a7d8f A |
1463 | englishDisplayNames[i] + ", got " + loc.getDisplayName(temp)); |
1464 | if (loc.getDisplayName(loc, temp) != norwegianDisplayNames[i]) | |
729e4ab9 | 1465 | dataerrln("Norwegian display-name mismatch: expected " + |
b75a7d8f A |
1466 | norwegianDisplayNames[i] + ", got " + |
1467 | loc.getDisplayName(loc, temp)); | |
1468 | } | |
73c04bcf | 1469 | Locale::setDefault(saveLocale, status); |
b75a7d8f A |
1470 | } |
1471 | ||
1472 | void | |
1473 | LocaleTest::TestVariantParsing() | |
1474 | { | |
1475 | Locale en_US_custom("en", "US", "De Anza_Cupertino_California_United States_Earth"); | |
1476 | ||
1477 | UnicodeString dispName("English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)"); | |
1478 | UnicodeString dispVar("DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH"); | |
374ca955 | 1479 | |
b75a7d8f | 1480 | UnicodeString got; |
374ca955 | 1481 | |
b75a7d8f A |
1482 | en_US_custom.getDisplayVariant(Locale::getUS(), got); |
1483 | if(got != dispVar) { | |
1484 | errln("FAIL: getDisplayVariant()"); | |
1485 | errln("Wanted: " + dispVar); | |
1486 | errln("Got : " + got); | |
1487 | } | |
1488 | ||
1489 | en_US_custom.getDisplayName(Locale::getUS(), got); | |
1490 | if(got != dispName) { | |
729e4ab9 A |
1491 | dataerrln("FAIL: getDisplayName()"); |
1492 | dataerrln("Wanted: " + dispName); | |
1493 | dataerrln("Got : " + got); | |
b75a7d8f A |
1494 | } |
1495 | ||
1496 | Locale shortVariant("fr", "FR", "foo"); | |
1497 | shortVariant.getDisplayVariant(got); | |
374ca955 | 1498 | |
b75a7d8f A |
1499 | if(got != "FOO") { |
1500 | errln("FAIL: getDisplayVariant()"); | |
1501 | errln("Wanted: foo"); | |
1502 | errln("Got : " + got); | |
1503 | } | |
1504 | ||
1505 | Locale bogusVariant("fr", "FR", "_foo"); | |
1506 | bogusVariant.getDisplayVariant(got); | |
374ca955 | 1507 | |
b75a7d8f A |
1508 | if(got != "FOO") { |
1509 | errln("FAIL: getDisplayVariant()"); | |
1510 | errln("Wanted: foo"); | |
1511 | errln("Got : " + got); | |
1512 | } | |
1513 | ||
1514 | Locale bogusVariant2("fr", "FR", "foo_"); | |
1515 | bogusVariant2.getDisplayVariant(got); | |
374ca955 | 1516 | |
b75a7d8f A |
1517 | if(got != "FOO") { |
1518 | errln("FAIL: getDisplayVariant()"); | |
1519 | errln("Wanted: foo"); | |
1520 | errln("Got : " + got); | |
1521 | } | |
1522 | ||
1523 | Locale bogusVariant3("fr", "FR", "_foo_"); | |
1524 | bogusVariant3.getDisplayVariant(got); | |
374ca955 | 1525 | |
b75a7d8f A |
1526 | if(got != "FOO") { |
1527 | errln("FAIL: getDisplayVariant()"); | |
1528 | errln("Wanted: foo"); | |
1529 | errln("Got : " + got); | |
1530 | } | |
1531 | } | |
1532 | ||
1533 | #if !UCONFIG_NO_FORMATTING | |
1534 | ||
1535 | /** | |
1536 | * @bug 4105828 | |
1537 | * Currency symbol in zh is wrong. We will test this at the NumberFormat | |
1538 | * end to test the whole pipe. | |
1539 | */ | |
374ca955 A |
1540 | void |
1541 | LocaleTest::Test4105828() | |
b75a7d8f A |
1542 | { |
1543 | Locale LOC [] = { Locale::getChinese(), Locale("zh", "CN", ""), | |
1544 | Locale("zh", "TW", ""), Locale("zh", "HK", "") }; | |
1545 | UErrorCode status = U_ZERO_ERROR; | |
1546 | for (int32_t i = 0; i < 4; ++i) { | |
1547 | NumberFormat *fmt = NumberFormat::createPercentInstance(LOC[i], status); | |
1548 | if(U_FAILURE(status)) { | |
729e4ab9 | 1549 | dataerrln("Couldn't create NumberFormat - %s", u_errorName(status)); |
b75a7d8f A |
1550 | return; |
1551 | } | |
1552 | UnicodeString result; | |
1553 | FieldPosition pos(0); | |
1554 | fmt->format((int32_t)1, result, pos); | |
1555 | UnicodeString temp; | |
1556 | if(result != "100%") { | |
1557 | errln(UnicodeString("Percent for ") + LOC[i].getDisplayName(temp) + " should be 100%, got " + result); | |
1558 | } | |
1559 | delete fmt; | |
1560 | } | |
1561 | } | |
1562 | ||
1563 | #endif | |
1564 | ||
1565 | // Tests setBogus and isBogus APIs for Locale | |
1566 | // Jitterbug 1735 | |
1567 | void | |
1568 | LocaleTest::TestSetIsBogus() { | |
374ca955 A |
1569 | Locale l("en_US"); |
1570 | l.setToBogus(); | |
1571 | if(l.isBogus() != TRUE) { | |
1572 | errln("After setting bogus, didn't return TRUE"); | |
1573 | } | |
1574 | l = "en_US"; // This should reset bogus | |
1575 | if(l.isBogus() != FALSE) { | |
1576 | errln("After resetting bogus, didn't return FALSE"); | |
1577 | } | |
b75a7d8f A |
1578 | } |
1579 | ||
374ca955 A |
1580 | |
1581 | void | |
1582 | LocaleTest::TestKeywordVariants(void) { | |
46f4442e | 1583 | static const struct { |
374ca955 A |
1584 | const char *localeID; |
1585 | const char *expectedLocaleID; | |
1586 | //const char *expectedLocaleIDNoKeywords; | |
1587 | //const char *expectedCanonicalID; | |
1588 | const char *expectedKeywords[10]; | |
1589 | int32_t numKeywords; | |
1590 | UErrorCode expectedStatus; | |
1591 | } testCases[] = { | |
1592 | { | |
1593 | "de_DE@ currency = euro; C o ll A t i o n = Phonebook ; C alen dar = buddhist ", | |
1594 | "de_DE@calendar=buddhist;collation=Phonebook;currency=euro", | |
1595 | //"de_DE", | |
1596 | //"de_DE@calendar=buddhist;collation=Phonebook;currency=euro", | |
1597 | {"calendar", "collation", "currency"}, | |
1598 | 3, | |
1599 | U_ZERO_ERROR | |
1600 | }, | |
1601 | { | |
1602 | "de_DE@euro", | |
1603 | "de_DE@euro", | |
1604 | //"de_DE", | |
1605 | //"de_DE@currency=EUR", | |
1606 | {"","","","","","",""}, | |
1607 | 0, | |
1608 | U_INVALID_FORMAT_ERROR /* must have '=' after '@' */ | |
1609 | } | |
1610 | }; | |
1611 | UErrorCode status = U_ZERO_ERROR; | |
1612 | ||
1613 | int32_t i = 0, j = 0; | |
1614 | const char *result = NULL; | |
1615 | StringEnumeration *keywords; | |
1616 | int32_t keyCount = 0; | |
1617 | const char *keyword = NULL; | |
1618 | const UnicodeString *keywordString; | |
1619 | int32_t keywordLen = 0; | |
1620 | ||
2ca993e8 | 1621 | for(i = 0; i < UPRV_LENGTHOF(testCases); i++) { |
374ca955 A |
1622 | status = U_ZERO_ERROR; |
1623 | Locale l(testCases[i].localeID); | |
1624 | keywords = l.createKeywords(status); | |
1625 | ||
1626 | if(status != testCases[i].expectedStatus) { | |
1627 | err("Expected to get status %s. Got %s instead\n", | |
1628 | u_errorName(testCases[i].expectedStatus), u_errorName(status)); | |
1629 | } | |
1630 | status = U_ZERO_ERROR; | |
1631 | if(keywords) { | |
1632 | if((keyCount = keywords->count(status)) != testCases[i].numKeywords) { | |
1633 | err("Expected to get %i keywords, got %i\n", testCases[i].numKeywords, keyCount); | |
1634 | } | |
1635 | if(keyCount) { | |
1636 | for(j = 0;;) { | |
1637 | if((j&1)==0) { | |
1638 | if((keyword = keywords->next(&keywordLen, status)) == NULL) { | |
1639 | break; | |
1640 | } | |
1641 | if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) { | |
1642 | err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword); | |
1643 | } | |
1644 | } else { | |
1645 | if((keywordString = keywords->snext(status)) == NULL) { | |
1646 | break; | |
1647 | } | |
1648 | if(*keywordString != UnicodeString(testCases[i].expectedKeywords[j], "")) { | |
1649 | err("Expected to get keyword UnicodeString %s, got %s\n", testCases[i].expectedKeywords[j], keyword); | |
1650 | } | |
1651 | } | |
1652 | j++; | |
1653 | ||
1654 | if(j == keyCount / 2) { | |
1655 | // replace keywords with a clone of itself | |
1656 | StringEnumeration *k2 = keywords->clone(); | |
1657 | if(k2 == NULL || keyCount != k2->count(status)) { | |
1658 | errln("KeywordEnumeration.clone() failed"); | |
1659 | } else { | |
1660 | delete keywords; | |
1661 | keywords = k2; | |
1662 | } | |
1663 | } | |
1664 | } | |
73c04bcf A |
1665 | keywords->reset(status); // Make sure that reset works. |
1666 | for(j = 0;;) { | |
1667 | if((keyword = keywords->next(&keywordLen, status)) == NULL) { | |
1668 | break; | |
1669 | } | |
1670 | if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) { | |
1671 | err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword); | |
1672 | } | |
1673 | j++; | |
1674 | } | |
374ca955 A |
1675 | } |
1676 | delete keywords; | |
1677 | } | |
1678 | result = l.getName(); | |
1679 | if(uprv_strcmp(testCases[i].expectedLocaleID, result) != 0) { | |
1680 | err("Expected to get \"%s\" from \"%s\". Got \"%s\" instead\n", | |
1681 | testCases[i].expectedLocaleID, testCases[i].localeID, result); | |
1682 | } | |
1683 | ||
1684 | } | |
1685 | ||
1686 | } | |
1687 | ||
1688 | void | |
1689 | LocaleTest::TestKeywordVariantParsing(void) { | |
46f4442e | 1690 | static const struct { |
374ca955 A |
1691 | const char *localeID; |
1692 | const char *keyword; | |
1693 | const char *expectedValue; | |
1694 | } testCases[] = { | |
1695 | { "de_DE@ C o ll A t i o n = Phonebook ", "collation", "Phonebook" }, | |
1696 | { "de_DE", "collation", ""}, | |
1697 | { "de_DE@collation= PHONEBOOK", "collation", "PHONEBOOK" }, | |
1698 | { "de_DE@ currency = euro ; CoLLaTion = PHONEBOOk ", "collation", "PHONEBOOk" }, | |
1699 | }; | |
1700 | ||
1701 | UErrorCode status = U_ZERO_ERROR; | |
1702 | ||
1703 | int32_t i = 0; | |
1704 | int32_t resultLen = 0; | |
1705 | char buffer[256]; | |
1706 | ||
2ca993e8 | 1707 | for(i = 0; i < UPRV_LENGTHOF(testCases); i++) { |
374ca955 A |
1708 | *buffer = 0; |
1709 | Locale l(testCases[i].localeID); | |
1710 | resultLen = l.getKeywordValue(testCases[i].keyword, buffer, 256, status); | |
57a6839d | 1711 | (void)resultLen; // Suppress unused variable warning. |
374ca955 A |
1712 | if(uprv_strcmp(testCases[i].expectedValue, buffer) != 0) { |
1713 | err("Expected to extract \"%s\" from \"%s\" for keyword \"%s\". Got \"%s\" instead\n", | |
1714 | testCases[i].expectedValue, testCases[i].localeID, testCases[i].keyword, buffer); | |
1715 | } | |
1716 | } | |
1717 | } | |
1718 | ||
729e4ab9 A |
1719 | void |
1720 | LocaleTest::TestSetKeywordValue(void) { | |
1721 | static const struct { | |
1722 | const char *keyword; | |
1723 | const char *value; | |
1724 | } testCases[] = { | |
1725 | { "collation", "phonebook" }, | |
1726 | { "currency", "euro" }, | |
1727 | { "calendar", "buddhist" } | |
1728 | }; | |
1729 | ||
1730 | UErrorCode status = U_ZERO_ERROR; | |
1731 | ||
1732 | int32_t i = 0; | |
1733 | int32_t resultLen = 0; | |
1734 | char buffer[256]; | |
1735 | ||
1736 | Locale l(Locale::getGerman()); | |
1737 | ||
2ca993e8 | 1738 | for(i = 0; i < UPRV_LENGTHOF(testCases); i++) { |
729e4ab9 A |
1739 | l.setKeywordValue(testCases[i].keyword, testCases[i].value, status); |
1740 | if(U_FAILURE(status)) { | |
1741 | err("FAIL: Locale::setKeywordValue failed - %s\n", u_errorName(status)); | |
1742 | } | |
1743 | ||
1744 | *buffer = 0; | |
1745 | resultLen = l.getKeywordValue(testCases[i].keyword, buffer, 256, status); | |
57a6839d | 1746 | (void)resultLen; // Suppress unused variable warning. |
729e4ab9 A |
1747 | if(uprv_strcmp(testCases[i].value, buffer) != 0) { |
1748 | err("Expected to extract \"%s\" for keyword \"%s\". Got \"%s\" instead\n", | |
1749 | testCases[i].value, testCases[i].keyword, buffer); | |
1750 | } | |
1751 | } | |
1752 | } | |
1753 | ||
374ca955 A |
1754 | void |
1755 | LocaleTest::TestGetBaseName(void) { | |
46f4442e | 1756 | static const struct { |
374ca955 A |
1757 | const char *localeID; |
1758 | const char *baseName; | |
1759 | } testCases[] = { | |
1760 | { "de_DE@ C o ll A t i o n = Phonebook ", "de_DE" }, | |
1761 | { "de@currency = euro; CoLLaTion = PHONEBOOk", "de" }, | |
b331163b A |
1762 | { "ja@calendar = buddhist", "ja" }, |
1763 | { "de-u-co-phonebk", "de"} | |
374ca955 A |
1764 | }; |
1765 | ||
1766 | int32_t i = 0; | |
1767 | ||
b331163b | 1768 | for(i = 0; i < UPRV_LENGTHOF(testCases); i++) { |
374ca955 A |
1769 | Locale loc(testCases[i].localeID); |
1770 | if(strcmp(testCases[i].baseName, loc.getBaseName())) { | |
1771 | errln("For locale \"%s\" expected baseName \"%s\", but got \"%s\"", | |
1772 | testCases[i].localeID, testCases[i].baseName, loc.getBaseName()); | |
1773 | return; | |
1774 | } | |
1775 | } | |
b331163b A |
1776 | |
1777 | // Verify that adding a keyword to an existing Locale doesn't change the base name. | |
1778 | UErrorCode status = U_ZERO_ERROR; | |
1779 | Locale loc2("en-US"); | |
1780 | if (strcmp("en_US", loc2.getBaseName())) { | |
1781 | errln("%s:%d Expected \"en_US\", got \"%s\"", __FILE__, __LINE__, loc2.getBaseName()); | |
1782 | } | |
1783 | loc2.setKeywordValue("key", "value", status); | |
1784 | if (strcmp("en_US@key=value", loc2.getName())) { | |
1785 | errln("%s:%d Expected \"en_US@key=value\", got \"%s\"", __FILE__, __LINE__, loc2.getName()); | |
1786 | } | |
1787 | if (strcmp("en_US", loc2.getBaseName())) { | |
1788 | errln("%s:%d Expected \"en_US\", got \"%s\"", __FILE__, __LINE__, loc2.getBaseName()); | |
1789 | } | |
374ca955 A |
1790 | } |
1791 | ||
1792 | /** | |
1793 | * Compare two locale IDs. If they are equal, return 0. If `string' | |
1794 | * starts with `prefix' plus an additional element, that is, string == | |
1795 | * prefix + '_' + x, then return 1. Otherwise return a value < 0. | |
1796 | */ | |
1797 | static UBool _loccmp(const char* string, const char* prefix) { | |
1798 | int32_t slen = (int32_t)strlen(string), | |
1799 | plen = (int32_t)strlen(prefix); | |
1800 | int32_t c = uprv_strncmp(string, prefix, plen); | |
1801 | /* 'root' is "less than" everything */ | |
1802 | if (uprv_strcmp(prefix, "root") == 0) { | |
1803 | return (uprv_strcmp(string, "root") == 0) ? 0 : 1; | |
1804 | } | |
1805 | if (c) return -1; /* mismatch */ | |
1806 | if (slen == plen) return 0; | |
1807 | if (string[plen] == '_') return 1; | |
1808 | return -2; /* false match, e.g. "en_USX" cmp "en_US" */ | |
1809 | } | |
1810 | ||
1811 | /** | |
1812 | * Check the relationship between requested locales, and report problems. | |
1813 | * The caller specifies the expected relationships between requested | |
1814 | * and valid (expReqValid) and between valid and actual (expValidActual). | |
1815 | * Possible values are: | |
1816 | * "gt" strictly greater than, e.g., en_US > en | |
1817 | * "ge" greater or equal, e.g., en >= en | |
1818 | * "eq" equal, e.g., en == en | |
1819 | */ | |
1820 | void LocaleTest::_checklocs(const char* label, | |
1821 | const char* req, | |
1822 | const Locale& validLoc, | |
1823 | const Locale& actualLoc, | |
1824 | const char* expReqValid, | |
1825 | const char* expValidActual) { | |
1826 | const char* valid = validLoc.getName(); | |
1827 | const char* actual = actualLoc.getName(); | |
1828 | int32_t reqValid = _loccmp(req, valid); | |
1829 | int32_t validActual = _loccmp(valid, actual); | |
1830 | if (((0 == uprv_strcmp(expReqValid, "gt") && reqValid > 0) || | |
1831 | (0 == uprv_strcmp(expReqValid, "ge") && reqValid >= 0) || | |
1832 | (0 == uprv_strcmp(expReqValid, "eq") && reqValid == 0)) && | |
1833 | ((0 == uprv_strcmp(expValidActual, "gt") && validActual > 0) || | |
1834 | (0 == uprv_strcmp(expValidActual, "ge") && validActual >= 0) || | |
1835 | (0 == uprv_strcmp(expValidActual, "eq") && validActual == 0))) { | |
1836 | logln("%s; req=%s, valid=%s, actual=%s", | |
1837 | label, req, valid, actual); | |
1838 | } else { | |
729e4ab9 | 1839 | dataerrln("FAIL: %s; req=%s, valid=%s, actual=%s. Require (R %s V) and (V %s A)", |
374ca955 A |
1840 | label, req, valid, actual, |
1841 | expReqValid, expValidActual); | |
1842 | } | |
1843 | } | |
1844 | ||
1845 | void LocaleTest::TestGetLocale(void) { | |
1846 | #if !UCONFIG_NO_SERVICE | |
374ca955 A |
1847 | const char *req; |
1848 | Locale valid, actual, reqLoc; | |
1849 | ||
1850 | // Calendar | |
1851 | #if !UCONFIG_NO_FORMATTING | |
b331163b A |
1852 | { |
1853 | UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code | |
1854 | req = "en_US_BROOKLYN"; | |
1855 | Calendar* cal = Calendar::createInstance(Locale::createFromName(req), ec); | |
374ca955 | 1856 | if (U_FAILURE(ec)) { |
b331163b | 1857 | dataerrln("FAIL: Calendar::createInstance failed - %s", u_errorName(ec)); |
374ca955 | 1858 | } else { |
b331163b A |
1859 | valid = cal->getLocale(ULOC_VALID_LOCALE, ec); |
1860 | actual = cal->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1861 | if (U_FAILURE(ec)) { | |
1862 | errln("FAIL: Calendar::getLocale() failed"); | |
1863 | } else { | |
1864 | _checklocs("Calendar", req, valid, actual); | |
1865 | } | |
1866 | /* Make sure that it fails correctly */ | |
1867 | ec = U_FILE_ACCESS_ERROR; | |
1868 | if (cal->getLocale(ULOC_VALID_LOCALE, ec).getName()[0] != 0) { | |
1869 | errln("FAIL: Calendar::getLocale() failed to fail correctly. It should have returned \"\""); | |
1870 | } | |
1871 | ec = U_ZERO_ERROR; | |
73c04bcf | 1872 | } |
b331163b | 1873 | delete cal; |
374ca955 | 1874 | } |
374ca955 A |
1875 | #endif |
1876 | ||
1877 | // DecimalFormat, DecimalFormatSymbols | |
1878 | #if !UCONFIG_NO_FORMATTING | |
b331163b A |
1879 | { |
1880 | UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code | |
1881 | req = "fr_FR_NICE"; | |
1882 | NumberFormat* nf = NumberFormat::createInstance(Locale::createFromName(req), ec); | |
374ca955 | 1883 | if (U_FAILURE(ec)) { |
b331163b | 1884 | dataerrln("FAIL: NumberFormat::createInstance failed - %s", u_errorName(ec)); |
374ca955 | 1885 | } else { |
b331163b A |
1886 | DecimalFormat* dec = dynamic_cast<DecimalFormat*>(nf); |
1887 | if (dec == NULL) { | |
1888 | errln("FAIL: NumberFormat::createInstance does not return a DecimalFormat"); | |
1889 | return; | |
1890 | } | |
1891 | valid = dec->getLocale(ULOC_VALID_LOCALE, ec); | |
1892 | actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1893 | if (U_FAILURE(ec)) { | |
1894 | errln("FAIL: DecimalFormat::getLocale() failed"); | |
1895 | } else { | |
1896 | _checklocs("DecimalFormat", req, valid, actual); | |
1897 | } | |
374ca955 | 1898 | |
b331163b A |
1899 | const DecimalFormatSymbols* sym = dec->getDecimalFormatSymbols(); |
1900 | if (sym == NULL) { | |
1901 | errln("FAIL: getDecimalFormatSymbols returned NULL"); | |
1902 | return; | |
1903 | } | |
1904 | valid = sym->getLocale(ULOC_VALID_LOCALE, ec); | |
1905 | actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1906 | if (U_FAILURE(ec)) { | |
1907 | errln("FAIL: DecimalFormatSymbols::getLocale() failed"); | |
1908 | } else { | |
1909 | _checklocs("DecimalFormatSymbols", req, valid, actual); | |
1910 | } | |
73c04bcf | 1911 | } |
b331163b | 1912 | delete nf; |
374ca955 | 1913 | } |
374ca955 A |
1914 | #endif |
1915 | ||
1916 | // DateFormat, DateFormatSymbols | |
1917 | #if !UCONFIG_NO_FORMATTING | |
b331163b A |
1918 | { |
1919 | UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code | |
1920 | req = "de_CH_LUCERNE"; | |
1921 | DateFormat* df = | |
1922 | DateFormat::createDateInstance(DateFormat::kDefault, | |
1923 | Locale::createFromName(req)); | |
1924 | if (df == 0){ | |
1925 | dataerrln("Error calling DateFormat::createDateInstance()"); | |
73c04bcf | 1926 | } else { |
b331163b A |
1927 | SimpleDateFormat* dat = dynamic_cast<SimpleDateFormat*>(df); |
1928 | if (dat == NULL) { | |
1929 | errln("FAIL: DateFormat::createInstance does not return a SimpleDateFormat"); | |
1930 | return; | |
1931 | } | |
1932 | valid = dat->getLocale(ULOC_VALID_LOCALE, ec); | |
1933 | actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1934 | if (U_FAILURE(ec)) { | |
1935 | errln("FAIL: SimpleDateFormat::getLocale() failed"); | |
1936 | } else { | |
1937 | _checklocs("SimpleDateFormat", req, valid, actual); | |
1938 | } | |
374ca955 | 1939 | |
b331163b A |
1940 | const DateFormatSymbols* sym = dat->getDateFormatSymbols(); |
1941 | if (sym == NULL) { | |
1942 | errln("FAIL: getDateFormatSymbols returned NULL"); | |
1943 | return; | |
1944 | } | |
1945 | valid = sym->getLocale(ULOC_VALID_LOCALE, ec); | |
1946 | actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1947 | if (U_FAILURE(ec)) { | |
1948 | errln("FAIL: DateFormatSymbols::getLocale() failed"); | |
1949 | } else { | |
1950 | _checklocs("DateFormatSymbols", req, valid, actual); | |
1951 | } | |
73c04bcf | 1952 | } |
b331163b | 1953 | delete df; |
73c04bcf | 1954 | } |
374ca955 A |
1955 | #endif |
1956 | ||
1957 | // BreakIterator | |
1958 | #if !UCONFIG_NO_BREAK_ITERATION | |
b331163b A |
1959 | { |
1960 | UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code | |
1961 | req = "es_ES_BARCELONA"; | |
1962 | reqLoc = Locale::createFromName(req); | |
1963 | BreakIterator* brk = BreakIterator::createWordInstance(reqLoc, ec); | |
374ca955 | 1964 | if (U_FAILURE(ec)) { |
b331163b | 1965 | dataerrln("FAIL: BreakIterator::createWordInstance failed - %s", u_errorName(ec)); |
374ca955 | 1966 | } else { |
b331163b A |
1967 | valid = brk->getLocale(ULOC_VALID_LOCALE, ec); |
1968 | actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1969 | if (U_FAILURE(ec)) { | |
1970 | errln("FAIL: BreakIterator::getLocale() failed"); | |
1971 | } else { | |
1972 | _checklocs("BreakIterator", req, valid, actual); | |
1973 | } | |
374ca955 | 1974 | |
b331163b A |
1975 | // After registering something, the behavior should be different |
1976 | URegistryKey key = BreakIterator::registerInstance(brk, reqLoc, UBRK_WORD, ec); | |
1977 | brk = 0; // registerInstance adopts | |
1978 | if (U_FAILURE(ec)) { | |
1979 | errln("FAIL: BreakIterator::registerInstance() failed"); | |
1980 | } else { | |
1981 | brk = BreakIterator::createWordInstance(reqLoc, ec); | |
1982 | if (U_FAILURE(ec)) { | |
1983 | errln("FAIL: BreakIterator::createWordInstance failed"); | |
1984 | } else { | |
1985 | valid = brk->getLocale(ULOC_VALID_LOCALE, ec); | |
1986 | actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
1987 | if (U_FAILURE(ec)) { | |
1988 | errln("FAIL: BreakIterator::getLocale() failed"); | |
1989 | } else { | |
1990 | // N.B.: now expect valid==actual==req | |
1991 | _checklocs("BreakIterator(registered)", | |
1992 | req, valid, actual, "eq", "eq"); | |
1993 | } | |
1994 | } | |
1995 | // No matter what, unregister | |
1996 | BreakIterator::unregister(key, ec); | |
1997 | if (U_FAILURE(ec)) { | |
1998 | errln("FAIL: BreakIterator::unregister() failed"); | |
1999 | } | |
2000 | delete brk; | |
2001 | brk = 0; | |
2002 | } | |
2003 | ||
2004 | // After unregistering, should behave normally again | |
374ca955 A |
2005 | brk = BreakIterator::createWordInstance(reqLoc, ec); |
2006 | if (U_FAILURE(ec)) { | |
2007 | errln("FAIL: BreakIterator::createWordInstance failed"); | |
2008 | } else { | |
2009 | valid = brk->getLocale(ULOC_VALID_LOCALE, ec); | |
2010 | actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
2011 | if (U_FAILURE(ec)) { | |
2012 | errln("FAIL: BreakIterator::getLocale() failed"); | |
2013 | } else { | |
b331163b | 2014 | _checklocs("BreakIterator(unregistered)", req, valid, actual); |
374ca955 A |
2015 | } |
2016 | } | |
374ca955 | 2017 | } |
b331163b | 2018 | delete brk; |
374ca955 | 2019 | } |
374ca955 A |
2020 | #endif |
2021 | ||
2022 | // Collator | |
2023 | #if !UCONFIG_NO_COLLATION | |
b331163b A |
2024 | { |
2025 | UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code | |
374ca955 | 2026 | |
b331163b A |
2027 | checkRegisteredCollators(NULL); // Don't expect any extras |
2028 | ||
2029 | req = "hi_IN_BHOPAL"; | |
2030 | reqLoc = Locale::createFromName(req); | |
2031 | Collator* coll = Collator::createInstance(reqLoc, ec); | |
374ca955 | 2032 | if (U_FAILURE(ec)) { |
b331163b | 2033 | dataerrln("FAIL: Collator::createInstance failed - %s", u_errorName(ec)); |
374ca955 | 2034 | } else { |
b331163b A |
2035 | valid = coll->getLocale(ULOC_VALID_LOCALE, ec); |
2036 | actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
2037 | if (U_FAILURE(ec)) { | |
2038 | errln("FAIL: Collator::getLocale() failed"); | |
2039 | } else { | |
2040 | _checklocs("Collator", req, valid, actual); | |
2041 | } | |
2042 | ||
2043 | // After registering something, the behavior should be different | |
2044 | URegistryKey key = Collator::registerInstance(coll, reqLoc, ec); | |
2045 | coll = 0; // registerInstance adopts | |
2046 | if (U_FAILURE(ec)) { | |
2047 | errln("FAIL: Collator::registerInstance() failed"); | |
2048 | } else { | |
2049 | coll = Collator::createInstance(reqLoc, ec); | |
2050 | if (U_FAILURE(ec)) { | |
2051 | errln("FAIL: Collator::createWordInstance failed"); | |
2052 | } else { | |
2053 | valid = coll->getLocale(ULOC_VALID_LOCALE, ec); | |
2054 | actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
2055 | if (U_FAILURE(ec)) { | |
2056 | errln("FAIL: Collator::getLocale() failed"); | |
2057 | } else { | |
2058 | // N.B.: now expect valid==actual==req | |
2059 | _checklocs("Collator(registered)", | |
2060 | req, valid, actual, "eq", "eq"); | |
2061 | } | |
2062 | } | |
2063 | checkRegisteredCollators(req); // include hi_IN_BHOPAL | |
2064 | ||
2065 | // No matter what, unregister | |
2066 | Collator::unregister(key, ec); | |
2067 | if (U_FAILURE(ec)) { | |
2068 | errln("FAIL: Collator::unregister() failed"); | |
2069 | } | |
2070 | delete coll; | |
2071 | coll = 0; | |
2072 | } | |
2073 | ||
2074 | // After unregistering, should behave normally again | |
374ca955 A |
2075 | coll = Collator::createInstance(reqLoc, ec); |
2076 | if (U_FAILURE(ec)) { | |
b331163b | 2077 | errln("FAIL: Collator::createInstance failed"); |
374ca955 A |
2078 | } else { |
2079 | valid = coll->getLocale(ULOC_VALID_LOCALE, ec); | |
2080 | actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); | |
2081 | if (U_FAILURE(ec)) { | |
2082 | errln("FAIL: Collator::getLocale() failed"); | |
2083 | } else { | |
b331163b | 2084 | _checklocs("Collator(unregistered)", req, valid, actual); |
374ca955 A |
2085 | } |
2086 | } | |
374ca955 | 2087 | } |
b331163b | 2088 | delete coll; |
374ca955 | 2089 | |
b331163b A |
2090 | checkRegisteredCollators(NULL); // extra should be gone again |
2091 | } | |
2092 | #endif | |
2093 | #endif | |
2094 | } | |
2095 | ||
2096 | #if !UCONFIG_NO_COLLATION | |
2097 | /** | |
2098 | * Compare Collator::getAvailableLocales(int) [ "old", returning an array ] | |
2099 | * with Collator::getAvailableLocales() [ "new", returning a StringEnumeration ] | |
2100 | * These should be identical (check their API docs) EXCEPT that | |
2101 | * if expectExtra is non-NULL, it will be in the "new" array but not "old". | |
2102 | * Does not return any status but calls errln on error. | |
2103 | * @param expectExtra an extra locale, will be in "new" but not "old". Or NULL. | |
2104 | */ | |
2105 | void LocaleTest::checkRegisteredCollators(const char *expectExtra) { | |
2106 | UErrorCode status = U_ZERO_ERROR; | |
2107 | int32_t count1=0,count2=0; | |
2108 | Hashtable oldHash(status); | |
2109 | Hashtable newHash(status); | |
2110 | TEST_ASSERT_STATUS(status); | |
2111 | ||
2112 | UnicodeString expectStr(expectExtra?expectExtra:"n/a", ""); | |
2113 | ||
2114 | // the 'old' list (non enumeration) | |
2115 | const Locale* oldList = Collator::getAvailableLocales(count1); | |
2116 | if(oldList == NULL) { | |
2117 | dataerrln("Error: Collator::getAvailableLocales(count) returned NULL"); | |
2118 | return; | |
2119 | } | |
2120 | ||
2121 | // the 'new' list (enumeration) | |
2122 | LocalPointer<StringEnumeration> newEnum(Collator::getAvailableLocales()); | |
2123 | if(newEnum.isNull()) { | |
2124 | errln("Error: collator::getAvailableLocales() returned NULL"); | |
2125 | return; | |
2126 | } | |
2127 | ||
2128 | // OK. Let's add all of the OLD | |
2129 | // then check for any in the NEW not in OLD | |
2130 | // then check for any in OLD not in NEW. | |
2131 | ||
2132 | // 1. add all of OLD | |
2133 | for(int32_t i=0;i<count1;i++) { | |
2134 | const UnicodeString key(oldList[i].getName(), ""); | |
2135 | int32_t oldI = oldHash.puti(key, 1, status); | |
2136 | if( oldI == 1 ){ | |
2137 | errln("Error: duplicate key %s in Collator::getAvailableLocales(count) list.\n", | |
2138 | oldList[i].getName()); | |
2139 | return; | |
2140 | } | |
2141 | if(expectExtra != NULL && !strcmp(expectExtra, oldList[i].getName())) { | |
2142 | errln("Inexplicably, Collator::getAvailableCollators(count) had registered collator %s. This shouldn't happen, so I am going to consider it an error.\n", expectExtra); | |
2143 | } | |
2144 | } | |
2145 | ||
2146 | // 2. add all of NEW | |
2147 | const UnicodeString *locStr; | |
2148 | UBool foundExpected = FALSE; | |
2149 | while((locStr = newEnum->snext(status)) && U_SUCCESS(status)) { | |
2150 | count2++; | |
2151 | ||
2152 | if(expectExtra != NULL && expectStr == *locStr) { | |
2153 | foundExpected = TRUE; | |
2154 | logln(UnicodeString("Found expected registered collator: ","") + expectStr); | |
2155 | } | |
2156 | (void)foundExpected; // Hush unused variable compiler warning. | |
2157 | ||
2158 | if( oldHash.geti(*locStr) == 0 ) { | |
2159 | if(expectExtra != NULL && expectStr==*locStr) { | |
2160 | logln(UnicodeString("As expected, Collator::getAvailableLocales(count) is missing registered collator ") + expectStr); | |
374ca955 | 2161 | } else { |
b331163b A |
2162 | errln(UnicodeString("Error: Collator::getAvailableLocales(count) is missing: ","") |
2163 | + *locStr); | |
374ca955 A |
2164 | } |
2165 | } | |
b331163b | 2166 | newHash.puti(*locStr, 1, status); |
374ca955 | 2167 | } |
b331163b A |
2168 | |
2169 | // 3. check all of OLD again | |
2170 | for(int32_t i=0;i<count1;i++) { | |
2171 | const UnicodeString key(oldList[i].getName(), ""); | |
2172 | int32_t newI = newHash.geti(key); | |
2173 | if(newI == 0) { | |
2174 | errln(UnicodeString("Error: Collator::getAvailableLocales() is missing: ","") | |
2175 | + key); | |
2176 | } | |
2177 | } | |
2178 | ||
2179 | int32_t expectCount2 = count1; | |
2180 | if(expectExtra != NULL) { | |
2181 | expectCount2 ++; // if an extra item registered, bump the expect count | |
2182 | } | |
2183 | ||
2184 | assertEquals("Collator::getAvail() count", expectCount2, count2); | |
374ca955 | 2185 | } |
b331163b A |
2186 | #endif |
2187 | ||
2188 | ||
374ca955 A |
2189 | |
2190 | void LocaleTest::TestVariantWithOutCountry(void) { | |
2191 | Locale loc("en","","POSIX"); | |
2192 | if (0 != strcmp(loc.getVariant(), "POSIX")) { | |
4388f060 | 2193 | errln("FAIL: en__POSIX didn't get parsed correctly - name is %s - expected %s got %s", loc.getName(), "POSIX", loc.getVariant()); |
374ca955 A |
2194 | } |
2195 | Locale loc2("en","","FOUR"); | |
2196 | if (0 != strcmp(loc2.getVariant(), "FOUR")) { | |
4388f060 | 2197 | errln("FAIL: en__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc2.getName(), "FOUR", loc2.getVariant()); |
374ca955 A |
2198 | } |
2199 | Locale loc3("en","Latn","","FOUR"); | |
2200 | if (0 != strcmp(loc3.getVariant(), "FOUR")) { | |
4388f060 | 2201 | errln("FAIL: en_Latn__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc3.getName(), "FOUR", loc3.getVariant()); |
374ca955 A |
2202 | } |
2203 | Locale loc4("","Latn","","FOUR"); | |
2204 | if (0 != strcmp(loc4.getVariant(), "FOUR")) { | |
4388f060 | 2205 | errln("FAIL: _Latn__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc4.getName(), "FOUR", loc4.getVariant()); |
374ca955 A |
2206 | } |
2207 | Locale loc5("","Latn","US","FOUR"); | |
2208 | if (0 != strcmp(loc5.getVariant(), "FOUR")) { | |
4388f060 A |
2209 | errln("FAIL: _Latn_US_FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc5.getName(), "FOUR", loc5.getVariant()); |
2210 | } | |
2211 | Locale loc6("de-1901"); | |
2212 | if (0 != strcmp(loc6.getVariant(), "1901")) { | |
2213 | errln("FAIL: de-1901 didn't get parsed correctly - name is %s - expected %s got %s", loc6.getName(), "1901", loc6.getVariant()); | |
374ca955 A |
2214 | } |
2215 | } | |
2216 | ||
2217 | static Locale _canonicalize(int32_t selector, /* 0==createFromName, 1==createCanonical, 2==Locale ct */ | |
2218 | const char* localeID) { | |
2219 | switch (selector) { | |
2220 | case 0: | |
2221 | return Locale::createFromName(localeID); | |
2222 | case 1: | |
2223 | return Locale::createCanonical(localeID); | |
2224 | case 2: | |
2225 | return Locale(localeID); | |
2226 | default: | |
2227 | return Locale(""); | |
2228 | } | |
2229 | } | |
2230 | ||
2231 | void LocaleTest::TestCanonicalization(void) | |
2232 | { | |
46f4442e | 2233 | static const struct { |
374ca955 A |
2234 | const char *localeID; /* input */ |
2235 | const char *getNameID; /* expected getName() result */ | |
2236 | const char *canonicalID; /* expected canonicalize() result */ | |
2237 | } testCases[] = { | |
729e4ab9 A |
2238 | { "", "", "en_US_POSIX" }, |
2239 | { "C", "c", "en_US_POSIX" }, | |
2240 | { "POSIX", "posix", "en_US_POSIX" }, | |
374ca955 A |
2241 | { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage", |
2242 | "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE", | |
2243 | "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"}, | |
2244 | { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" }, | |
2245 | { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" }, | |
2246 | { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" }, | |
2247 | { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=LUF" }, | |
2248 | { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" }, | |
2249 | { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" }, | |
2250 | { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" }, | |
2251 | { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" }, | |
2252 | { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" }, | |
2253 | { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" }, | |
2254 | { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" }, | |
2255 | { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" }, | |
2256 | { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" }, | |
2257 | { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" }, | |
2258 | { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" }, | |
2259 | { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" }, | |
2260 | { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" }, | |
2261 | { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" }, | |
2262 | { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" }, | |
2263 | { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" }, | |
2264 | { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" }, | |
2265 | { "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */ | |
2266 | { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" }, | |
2267 | { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" }, | |
2268 | { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" }, | |
2269 | { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" }, | |
46f4442e | 2270 | { "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" }, |
374ca955 A |
2271 | { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" }, |
2272 | { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" }, | |
2273 | { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" }, | |
2274 | { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" }, | |
2275 | { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" }, | |
2276 | { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" }, | |
2277 | { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ }, | |
2278 | { "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */ | |
2279 | { "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */ | |
2280 | { "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */ | |
2281 | // NOTE: uloc_getName() works on en-BOONT, but Locale() parser considers it BOGUS | |
2282 | // TODO: unify this behavior | |
51004dcb A |
2283 | { "en-BOONT", "en__BOONT", "en__BOONT" }, /* registered name */ |
2284 | { "de-1901", "de__1901", "de__1901" }, /* registered name */ | |
2285 | { "de-1906", "de__1906", "de__1906" }, /* registered name */ | |
46f4442e A |
2286 | { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_RS" }, /* .NET name */ |
2287 | { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_RS" }, /* .NET name */ | |
2288 | { "sr_YU_CYRILLIC", "sr_YU_CYRILLIC", "sr_Cyrl_RS" }, /* Linux name */ | |
374ca955 A |
2289 | { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */ |
2290 | { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */ | |
2291 | { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */ | |
73c04bcf | 2292 | { "zh-CHT", "zh_CHT", "zh_Hant" }, /* .NET name This may change back to zh_Hant */ |
374ca955 A |
2293 | |
2294 | /* posix behavior that used to be performed by getName */ | |
2295 | { "mr.utf8", "mr.utf8", "mr" }, | |
2296 | { "de-tv.koi8r", "de_TV.koi8r", "de_TV" }, | |
2297 | { "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" }, | |
2298 | { "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" }, | |
2299 | { "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" }, | |
2300 | { "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 */ | |
2301 | ||
2302 | /* fleshing out canonicalization */ | |
2303 | /* trim space and sort keywords, ';' is separator so not present at end in canonical form */ | |
2304 | { "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" }, | |
2305 | /* already-canonical ids are not changed */ | |
2306 | { "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" }, | |
2307 | /* PRE_EURO and EURO conversions don't affect other keywords */ | |
2308 | { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" }, | |
2309 | { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" }, | |
2310 | /* currency keyword overrides PRE_EURO and EURO currency */ | |
2311 | { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" }, | |
2312 | { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" }, | |
2313 | /* norwegian is just too weird, if we handle things in their full generality */ | |
2314 | { "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ }, | |
2315 | ||
2316 | /* test cases reflecting internal resource bundle usage */ | |
2317 | { "root@kw=foo", "root@kw=foo", "root@kw=foo" }, | |
2318 | { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" }, | |
2319 | { "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese" } | |
2320 | }; | |
2321 | ||
2322 | static const char* label[] = { "createFromName", "createCanonical", "Locale" }; | |
2323 | ||
2324 | int32_t i, j; | |
2325 | ||
2ca993e8 | 2326 | for (i=0; i < UPRV_LENGTHOF(testCases); i++) { |
374ca955 A |
2327 | for (j=0; j<3; ++j) { |
2328 | const char* expected = (j==1) ? testCases[i].canonicalID : testCases[i].getNameID; | |
2329 | Locale loc = _canonicalize(j, testCases[i].localeID); | |
2330 | const char* getName = loc.isBogus() ? "BOGUS" : loc.getName(); | |
2331 | if(uprv_strcmp(expected, getName) != 0) { | |
2332 | errln("FAIL: %s(%s).getName() => \"%s\", expected \"%s\"", | |
2333 | label[j], testCases[i].localeID, getName, expected); | |
2334 | } else { | |
2335 | logln("Ok: %s(%s) => \"%s\"", | |
2336 | label[j], testCases[i].localeID, getName); | |
2337 | } | |
2338 | } | |
2339 | } | |
2340 | } | |
46f4442e A |
2341 | |
2342 | void LocaleTest::TestCurrencyByDate(void) | |
2343 | { | |
2344 | #if !UCONFIG_NO_FORMATTING | |
2345 | UErrorCode status = U_ZERO_ERROR; | |
2346 | UDate date = uprv_getUTCtime(); | |
2347 | UChar TMP[4]; | |
2348 | int32_t index = 0; | |
2349 | int32_t resLen = 0; | |
2350 | UnicodeString tempStr, resultStr; | |
2351 | ||
2352 | // Cycle through historical currencies | |
2353 | date = (UDate)-630720000000.0; // pre 1961 - no currency defined | |
729e4ab9 | 2354 | index = ucurr_countCurrencies("eo_AM", date, &status); |
46f4442e A |
2355 | if (index != 0) |
2356 | { | |
729e4ab9 | 2357 | errcheckln(status, "FAIL: didn't return 0 for eo_AM - %s", u_errorName(status)); |
46f4442e A |
2358 | } |
2359 | resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status); | |
2360 | if (resLen != 0) { | |
729e4ab9 | 2361 | errcheckln(status, "FAIL: eo_AM didn't return NULL - %s", u_errorName(status)); |
46f4442e A |
2362 | } |
2363 | status = U_ZERO_ERROR; | |
2364 | ||
2365 | date = (UDate)0.0; // 1970 - one currency defined | |
729e4ab9 | 2366 | index = ucurr_countCurrencies("eo_AM", date, &status); |
46f4442e A |
2367 | if (index != 1) |
2368 | { | |
729e4ab9 | 2369 | errcheckln(status, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status)); |
46f4442e A |
2370 | } |
2371 | resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status); | |
2372 | tempStr.setTo(TMP); | |
2373 | resultStr.setTo("SUR"); | |
2374 | if (resultStr != tempStr) { | |
729e4ab9 | 2375 | errcheckln(status, "FAIL: didn't return SUR for eo_AM - %s", u_errorName(status)); |
46f4442e A |
2376 | } |
2377 | ||
2378 | date = (UDate)693792000000.0; // 1992 - one currency defined | |
2379 | index = ucurr_countCurrencies("eo_AM", date, &status); | |
2380 | if (index != 1) | |
2381 | { | |
729e4ab9 | 2382 | errcheckln(status, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status)); |
46f4442e A |
2383 | } |
2384 | resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status); | |
2385 | tempStr.setTo(TMP); | |
2386 | resultStr.setTo("RUR"); | |
2387 | if (resultStr != tempStr) { | |
729e4ab9 | 2388 | errcheckln(status, "FAIL: didn't return RUR for eo_AM - %s", u_errorName(status)); |
46f4442e A |
2389 | } |
2390 | ||
2391 | date = (UDate)977616000000.0; // post 1993 - one currency defined | |
2392 | index = ucurr_countCurrencies("eo_AM", date, &status); | |
2393 | if (index != 1) | |
2394 | { | |
729e4ab9 | 2395 | errcheckln(status, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status)); |
46f4442e A |
2396 | } |
2397 | resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status); | |
2398 | tempStr.setTo(TMP); | |
2399 | resultStr.setTo("AMD"); | |
2400 | if (resultStr != tempStr) { | |
729e4ab9 | 2401 | errcheckln(status, "FAIL: didn't return AMD for eo_AM - %s", u_errorName(status)); |
46f4442e A |
2402 | } |
2403 | ||
2404 | // Locale AD has multiple currencies at once | |
2405 | date = (UDate)977616000000.0; // year 2001 | |
2406 | index = ucurr_countCurrencies("eo_AD", date, &status); | |
2407 | if (index != 4) | |
2408 | { | |
729e4ab9 | 2409 | errcheckln(status, "FAIL: didn't return 4 for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2410 | } |
2411 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 1, TMP, 4, &status); | |
2412 | tempStr.setTo(TMP); | |
2413 | resultStr.setTo("EUR"); | |
2414 | if (resultStr != tempStr) { | |
729e4ab9 | 2415 | errcheckln(status, "FAIL: didn't return EUR for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2416 | } |
2417 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 2, TMP, 4, &status); | |
2418 | tempStr.setTo(TMP); | |
2419 | resultStr.setTo("ESP"); | |
2420 | if (resultStr != tempStr) { | |
729e4ab9 | 2421 | errcheckln(status, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2422 | } |
2423 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 3, TMP, 4, &status); | |
2424 | tempStr.setTo(TMP); | |
2425 | resultStr.setTo("FRF"); | |
2426 | if (resultStr != tempStr) { | |
729e4ab9 | 2427 | errcheckln(status, "FAIL: didn't return FRF for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2428 | } |
2429 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 4, TMP, 4, &status); | |
2430 | tempStr.setTo(TMP); | |
2431 | resultStr.setTo("ADP"); | |
2432 | if (resultStr != tempStr) { | |
729e4ab9 | 2433 | errcheckln(status, "FAIL: didn't return ADP for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2434 | } |
2435 | ||
2436 | date = (UDate)0.0; // year 1970 | |
2437 | index = ucurr_countCurrencies("eo_AD", date, &status); | |
2438 | if (index != 3) | |
2439 | { | |
729e4ab9 | 2440 | errcheckln(status, "FAIL: didn't return 3 for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2441 | } |
2442 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 1, TMP, 4, &status); | |
2443 | tempStr.setTo(TMP); | |
2444 | resultStr.setTo("ESP"); | |
2445 | if (resultStr != tempStr) { | |
729e4ab9 | 2446 | errcheckln(status, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2447 | } |
2448 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 2, TMP, 4, &status); | |
2449 | tempStr.setTo(TMP); | |
2450 | resultStr.setTo("FRF"); | |
2451 | if (resultStr != tempStr) { | |
729e4ab9 | 2452 | errcheckln(status, "FAIL: didn't return FRF for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2453 | } |
2454 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 3, TMP, 4, &status); | |
2455 | tempStr.setTo(TMP); | |
2456 | resultStr.setTo("ADP"); | |
2457 | if (resultStr != tempStr) { | |
729e4ab9 | 2458 | errcheckln(status, "FAIL: didn't return ADP for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2459 | } |
2460 | ||
2461 | date = (UDate)-630720000000.0; // year 1950 | |
2462 | index = ucurr_countCurrencies("eo_AD", date, &status); | |
2463 | if (index != 2) | |
2464 | { | |
729e4ab9 | 2465 | errcheckln(status, "FAIL: didn't return 2 for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2466 | } |
2467 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 1, TMP, 4, &status); | |
2468 | tempStr.setTo(TMP); | |
2469 | resultStr.setTo("ESP"); | |
2470 | if (resultStr != tempStr) { | |
729e4ab9 | 2471 | errcheckln(status, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2472 | } |
2473 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 2, TMP, 4, &status); | |
2474 | tempStr.setTo(TMP); | |
2475 | resultStr.setTo("ADP"); | |
2476 | if (resultStr != tempStr) { | |
729e4ab9 | 2477 | errcheckln(status, "FAIL: didn't return ADP for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2478 | } |
2479 | ||
2480 | date = (UDate)-2207520000000.0; // year 1900 | |
2481 | index = ucurr_countCurrencies("eo_AD", date, &status); | |
2482 | if (index != 1) | |
2483 | { | |
729e4ab9 | 2484 | errcheckln(status, "FAIL: didn't return 1 for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2485 | } |
2486 | resLen = ucurr_forLocaleAndDate("eo_AD", date, 1, TMP, 4, &status); | |
2487 | tempStr.setTo(TMP); | |
2488 | resultStr.setTo("ESP"); | |
2489 | if (resultStr != tempStr) { | |
729e4ab9 | 2490 | errcheckln(status, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status)); |
46f4442e A |
2491 | } |
2492 | ||
2493 | // Locale UA has gap between years 1994 - 1996 | |
2494 | date = (UDate)788400000000.0; | |
2495 | index = ucurr_countCurrencies("eo_UA", date, &status); | |
2496 | if (index != 0) | |
2497 | { | |
729e4ab9 | 2498 | errcheckln(status, "FAIL: didn't return 0 for eo_UA - %s", u_errorName(status)); |
46f4442e A |
2499 | } |
2500 | resLen = ucurr_forLocaleAndDate("eo_UA", date, index, TMP, 4, &status); | |
2501 | if (resLen != 0) { | |
729e4ab9 | 2502 | errcheckln(status, "FAIL: eo_UA didn't return NULL - %s", u_errorName(status)); |
46f4442e A |
2503 | } |
2504 | status = U_ZERO_ERROR; | |
2505 | ||
2506 | // Test index bounds | |
2507 | resLen = ucurr_forLocaleAndDate("eo_UA", date, 100, TMP, 4, &status); | |
2508 | if (resLen != 0) { | |
729e4ab9 | 2509 | errcheckln(status, "FAIL: eo_UA didn't return NULL - %s", u_errorName(status)); |
46f4442e A |
2510 | } |
2511 | status = U_ZERO_ERROR; | |
2512 | ||
2513 | resLen = ucurr_forLocaleAndDate("eo_UA", date, 0, TMP, 4, &status); | |
2514 | if (resLen != 0) { | |
729e4ab9 | 2515 | errcheckln(status, "FAIL: eo_UA didn't return NULL - %s", u_errorName(status)); |
46f4442e A |
2516 | } |
2517 | status = U_ZERO_ERROR; | |
2518 | ||
2519 | // Test for bogus locale | |
2520 | index = ucurr_countCurrencies("eo_QQ", date, &status); | |
2521 | if (index != 0) | |
2522 | { | |
729e4ab9 | 2523 | errcheckln(status, "FAIL: didn't return 0 for eo_QQ - %s", u_errorName(status)); |
46f4442e A |
2524 | } |
2525 | status = U_ZERO_ERROR; | |
2526 | resLen = ucurr_forLocaleAndDate("eo_QQ", date, 1, TMP, 4, &status); | |
2527 | if (resLen != 0) { | |
729e4ab9 | 2528 | errcheckln(status, "FAIL: eo_QQ didn't return NULL - %s", u_errorName(status)); |
46f4442e A |
2529 | } |
2530 | status = U_ZERO_ERROR; | |
2531 | resLen = ucurr_forLocaleAndDate("eo_QQ", date, 0, TMP, 4, &status); | |
2532 | if (resLen != 0) { | |
729e4ab9 | 2533 | errcheckln(status, "FAIL: eo_QQ didn't return NULL - %s", u_errorName(status)); |
46f4442e A |
2534 | } |
2535 | status = U_ZERO_ERROR; | |
2536 | ||
2537 | // Cycle through histrocial currencies | |
2538 | date = (UDate)977616000000.0; // 2001 - one currency | |
2539 | index = ucurr_countCurrencies("eo_AO", date, &status); | |
2540 | if (index != 1) | |
2541 | { | |
729e4ab9 | 2542 | errcheckln(status, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2543 | } |
2544 | resLen = ucurr_forLocaleAndDate("eo_AO", date, 1, TMP, 4, &status); | |
2545 | tempStr.setTo(TMP); | |
2546 | resultStr.setTo("AOA"); | |
2547 | if (resultStr != tempStr) { | |
729e4ab9 | 2548 | errcheckln(status, "FAIL: didn't return AOA for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2549 | } |
2550 | ||
2551 | date = (UDate)819936000000.0; // 1996 - 2 currencies | |
2552 | index = ucurr_countCurrencies("eo_AO", date, &status); | |
2553 | if (index != 2) | |
2554 | { | |
729e4ab9 | 2555 | errcheckln(status, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2556 | } |
2557 | resLen = ucurr_forLocaleAndDate("eo_AO", date, 1, TMP, 4, &status); | |
2558 | tempStr.setTo(TMP); | |
2559 | resultStr.setTo("AOR"); | |
2560 | if (resultStr != tempStr) { | |
729e4ab9 | 2561 | errcheckln(status, "FAIL: didn't return AOR for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2562 | } |
2563 | resLen = ucurr_forLocaleAndDate("eo_AO", date, 2, TMP, 4, &status); | |
2564 | tempStr.setTo(TMP); | |
2565 | resultStr.setTo("AON"); | |
2566 | if (resultStr != tempStr) { | |
729e4ab9 | 2567 | errcheckln(status, "FAIL: didn't return AON for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2568 | } |
2569 | ||
2570 | date = (UDate)662256000000.0; // 1991 - 2 currencies | |
2571 | index = ucurr_countCurrencies("eo_AO", date, &status); | |
2572 | if (index != 2) | |
2573 | { | |
729e4ab9 | 2574 | errcheckln(status, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2575 | } |
2576 | resLen = ucurr_forLocaleAndDate("eo_AO", date, 1, TMP, 4, &status); | |
2577 | tempStr.setTo(TMP); | |
2578 | resultStr.setTo("AON"); | |
2579 | if (resultStr != tempStr) { | |
729e4ab9 | 2580 | errcheckln(status, "FAIL: didn't return AON for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2581 | } |
2582 | resLen = ucurr_forLocaleAndDate("eo_AO", date, 2, TMP, 4, &status); | |
2583 | tempStr.setTo(TMP); | |
2584 | resultStr.setTo("AOK"); | |
2585 | if (resultStr != tempStr) { | |
729e4ab9 | 2586 | errcheckln(status, "FAIL: didn't return AOK for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2587 | } |
2588 | ||
2589 | date = (UDate)315360000000.0; // 1980 - one currency | |
2590 | index = ucurr_countCurrencies("eo_AO", date, &status); | |
2591 | if (index != 1) | |
2592 | { | |
729e4ab9 | 2593 | errcheckln(status, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2594 | } |
2595 | resLen = ucurr_forLocaleAndDate("eo_AO", date, 1, TMP, 4, &status); | |
2596 | tempStr.setTo(TMP); | |
2597 | resultStr.setTo("AOK"); | |
2598 | if (resultStr != tempStr) { | |
729e4ab9 | 2599 | errcheckln(status, "FAIL: didn't return AOK for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2600 | } |
2601 | ||
2602 | date = (UDate)0.0; // 1970 - no currencies | |
2603 | index = ucurr_countCurrencies("eo_AO", date, &status); | |
2604 | if (index != 0) | |
2605 | { | |
729e4ab9 | 2606 | errcheckln(status, "FAIL: didn't return 1 for eo_AO - %s", u_errorName(status)); |
46f4442e A |
2607 | } |
2608 | resLen = ucurr_forLocaleAndDate("eo_AO", date, 1, TMP, 4, &status); | |
2609 | if (resLen != 0) { | |
729e4ab9 | 2610 | errcheckln(status, "FAIL: eo_AO didn't return NULL - %s", u_errorName(status)); |
46f4442e A |
2611 | } |
2612 | status = U_ZERO_ERROR; | |
2613 | ||
2614 | // Test with currency keyword override | |
2615 | date = (UDate)977616000000.0; // 2001 - two currencies | |
2616 | index = ucurr_countCurrencies("eo_DE@currency=DEM", date, &status); | |
2617 | if (index != 2) | |
2618 | { | |
729e4ab9 | 2619 | errcheckln(status, "FAIL: didn't return 2 for eo_DE@currency=DEM - %s", u_errorName(status)); |
46f4442e A |
2620 | } |
2621 | resLen = ucurr_forLocaleAndDate("eo_DE@currency=DEM", date, 1, TMP, 4, &status); | |
2622 | tempStr.setTo(TMP); | |
2623 | resultStr.setTo("EUR"); | |
2624 | if (resultStr != tempStr) { | |
729e4ab9 | 2625 | errcheckln(status, "FAIL: didn't return EUR for eo_DE@currency=DEM - %s", u_errorName(status)); |
46f4442e A |
2626 | } |
2627 | resLen = ucurr_forLocaleAndDate("eo_DE@currency=DEM", date, 2, TMP, 4, &status); | |
2628 | tempStr.setTo(TMP); | |
2629 | resultStr.setTo("DEM"); | |
2630 | if (resultStr != tempStr) { | |
729e4ab9 | 2631 | errcheckln(status, "FAIL: didn't return DEM for eo_DE@currency=DEM - %s", u_errorName(status)); |
46f4442e A |
2632 | } |
2633 | ||
2634 | // Test Euro Support | |
2635 | status = U_ZERO_ERROR; // reset | |
2636 | date = uprv_getUTCtime(); | |
2637 | ||
2638 | UChar USD[4]; | |
2639 | ucurr_forLocaleAndDate("en_US", date, 1, USD, 4, &status); | |
2640 | ||
2641 | UChar YEN[4]; | |
2642 | ucurr_forLocaleAndDate("ja_JP", date, 1, YEN, 4, &status); | |
2643 | ||
2644 | ucurr_forLocaleAndDate("en_US", date, 1, TMP, 4, &status); | |
2645 | if (u_strcmp(USD, TMP) != 0) { | |
729e4ab9 | 2646 | errcheckln(status, "Fail: en_US didn't return USD - %s", u_errorName(status)); |
46f4442e A |
2647 | } |
2648 | ucurr_forLocaleAndDate("en_US_PREEURO", date, 1, TMP, 4, &status); | |
2649 | if (u_strcmp(USD, TMP) != 0) { | |
729e4ab9 | 2650 | errcheckln(status, "Fail: en_US_PREEURO didn't fallback to en_US - %s", u_errorName(status)); |
46f4442e A |
2651 | } |
2652 | ucurr_forLocaleAndDate("en_US_Q", date, 1, TMP, 4, &status); | |
2653 | if (u_strcmp(USD, TMP) != 0) { | |
729e4ab9 | 2654 | errcheckln(status, "Fail: en_US_Q didn't fallback to en_US - %s", u_errorName(status)); |
46f4442e A |
2655 | } |
2656 | status = U_ZERO_ERROR; // reset | |
2657 | #endif | |
2658 | } | |
729e4ab9 A |
2659 | |
2660 | void LocaleTest::TestGetVariantWithKeywords(void) | |
2661 | { | |
2662 | Locale l("en_US_VALLEY@foo=value"); | |
2663 | const char *variant = l.getVariant(); | |
2664 | logln(variant); | |
2665 | test_assert(strcmp("VALLEY", variant) == 0); | |
2666 | ||
2667 | UErrorCode status = U_ZERO_ERROR; | |
2668 | char buffer[50]; | |
2669 | int32_t len = l.getKeywordValue("foo", buffer, 50, status); | |
2670 | buffer[len] = '\0'; | |
2671 | test_assert(strcmp("value", buffer) == 0); | |
2672 | } | |
b331163b A |
2673 | |
2674 | void LocaleTest::TestIsRightToLeft() { | |
2675 | assertFalse("root LTR", Locale::getRoot().isRightToLeft()); | |
2676 | assertFalse("zh LTR", Locale::getChinese().isRightToLeft()); | |
2677 | assertTrue("ar RTL", Locale("ar").isRightToLeft()); | |
2678 | assertTrue("und-EG RTL", Locale("und-EG").isRightToLeft(), FALSE, TRUE); | |
2679 | assertFalse("fa-Cyrl LTR", Locale("fa-Cyrl").isRightToLeft()); | |
2680 | assertTrue("en-Hebr RTL", Locale("en-Hebr").isRightToLeft()); | |
2681 | assertTrue("ckb RTL", Locale("ckb").isRightToLeft(), FALSE, TRUE); // Sorani Kurdish | |
2682 | assertFalse("fil LTR", Locale("fil").isRightToLeft()); | |
2683 | assertFalse("he-Zyxw LTR", Locale("he-Zyxw").isRightToLeft()); | |
2684 | } | |
2685 | ||
2686 | void LocaleTest::TestBug11421() { | |
2687 | Locale::getDefault().getBaseName(); | |
2688 | int32_t numLocales; | |
2689 | const Locale *localeList = Locale::getAvailableLocales(numLocales); | |
2690 | for (int localeIndex = 0; localeIndex < numLocales; localeIndex++) { | |
2691 | const Locale &loc = localeList[localeIndex]; | |
2692 | if (strncmp(loc.getName(), loc.getBaseName(), strlen(loc.getBaseName()))) { | |
2693 | errln("%s:%d loc.getName=\"%s\"; loc.getBaseName=\"%s\"", | |
2694 | __FILE__, __LINE__, loc.getName(), loc.getBaseName()); | |
2695 | break; | |
2696 | } | |
2697 | } | |
2698 | } |