1 /********************************************************************
3 * Copyright (c) 1997-2007, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /*******************************************************************************
10 * Modification History:
12 * Madhu Katragadda Ported for C API
13 ********************************************************************************
24 #include "unicode/putil.h"
25 #include "unicode/ubrk.h"
26 #include "unicode/uchar.h"
27 #include "unicode/ucol.h"
28 #include "unicode/udat.h"
29 #include "unicode/uloc.h"
30 #include "unicode/umsg.h"
31 #include "unicode/ures.h"
32 #include "unicode/uset.h"
33 #include "unicode/ustring.h"
34 #include "unicode/utypes.h"
35 #include "unicode/ulocdata.h"
36 #include "unicode/parseerr.h" /* may not be included with some uconfig switches */
37 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
39 static void TestNullDefault(void);
40 static void TestNonexistentLanguageExemplars(void);
41 static void TestLanguageExemplarsFallbacks(void);
43 void PrintDataTable();
45 /*---------------------------------------------------
47 --------------------------------------------------- */
49 #define LOCALE_INFO_SIZE 28
51 static const char* rawData2
[LOCALE_INFO_SIZE
][LOCALE_SIZE
] = {
53 { "en", "fr", "ca", "el", "no", "zh", "de", "es", "ja" },
55 { "", "", "", "", "", "Hans", "", "", "" },
57 { "US", "FR", "ES", "GR", "NO", "CN", "DE", "", "JP" },
59 { "", "", "", "", "NY", "", "", "", "" },
61 { "en_US", "fr_FR", "ca_ES",
62 "el_GR", "no_NO_NY", "zh_Hans_CN",
63 "de_DE@collation=phonebook", "es@collation=traditional", "ja_JP@calendar=japanese" },
65 { "eng", "fra", "cat", "ell", "nor", "zho", "deu", "spa", "jpn" },
67 { "USA", "FRA", "ESP", "GRC", "NOR", "CHN", "DEU", "", "JPN" },
69 { "409", "40c", "403", "408", "814", "804", "10407", "40a", "411" },
71 /* display language (English) */
72 { "English", "French", "Catalan", "Greek", "Norwegian", "Chinese", "German", "Spanish", "Japanese" },
73 /* display script code (English) */
74 { "", "", "", "", "", "Simplified Han", "", "", "" },
75 /* display country (English) */
76 { "United States", "France", "Spain", "Greece", "Norway", "China", "Germany", "", "Japan" },
77 /* display variant (English) */
78 { "", "", "", "", "NY", "", "", "", "" },
79 /* display name (English) */
80 { "English (United States)", "French (France)", "Catalan (Spain)",
81 "Greek (Greece)", "Norwegian (Norway, NY)", "Chinese (Simplified Han, China)",
82 "German (Germany, Collation=Phonebook Order)", "Spanish (Collation=Traditional)", "Japanese (Japan, Calendar=Japanese Calendar)" },
84 /* display language (French) */
85 { "anglais", "fran\\u00E7ais", "catalan", "grec", "norv\\u00E9gien", "chinois", "allemand", "espagnol", "japonais" },
86 /* display script code (French) */
87 { "", "", "", "", "", "id\\u00e9ogrammes han (variante simplifi\\u00e9e)", "", "", "" },
88 /* display country (French) */
89 { "\\u00C9tats-Unis", "France", "Espagne", "Gr\\u00E8ce", "Norv\\u00E8ge", "Chine", "Allemagne", "", "Japon" },
90 /* display variant (French) */
91 { "", "", "", "", "NY", "", "", "", "" },
92 /* display name (French) */
93 { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)",
94 "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "chinois (id\\u00e9ogrammes han (variante simplifi\\u00e9e), Chine)",
95 "allemand (Allemagne, Ordonnancement=Ordre de l\\u2019annuaire)", "espagnol (Ordonnancement=Ordre traditionnel)", "japonais (Japon, Calendrier=Calendrier japonais)" },
97 /* display language (Catalan) */
98 { "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec", "noruec", "xin\\u00E9s", "alemany", "espanyol", "japon\\u00E8s" },
99 /* display script code (Catalan) */
100 { "", "", "", "", "", "Hans", "", "", "" },
101 /* display country (Catalan) */
102 { "Estats Units", "Fran\\u00E7a", "Espanya", "Gr\\u00E8cia", "Noruega", "Xina", "Alemanya", "", "Jap\\u00F3" },
103 /* display variant (Catalan) */
104 { "", "", "", "", "NY", "", "", "", "" },
105 /* display name (Catalan) */
106 { "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)",
107 "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "xin\\u00E9s (Hans, Xina)",
108 "alemany (Alemanya, collation=phonebook)", "espanyol (collation=traditional)", "japon\\u00E8s (Jap\\u00F3, calendar=japanese)" },
110 /* display language (Greek) */
112 "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac",
113 "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac",
114 "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac",
115 "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac",
116 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac",
117 "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC",
118 "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
119 "\\u0399\\u03C3\\u03C0\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
120 "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03AC"
122 /* display script code (Greek) */
123 { "", "", "", "", "", "Hans", "", "", "" },
124 /* display country (Greek) */
126 "\\u0397\\u03bd\\u03c9\\u03bc\\u03ad\\u03bd\\u03b5\\u03c2 \\u03a0\\u03bf\\u03bb\\u03b9\\u03c4\\u03b5\\u03af\\u03b5\\u03c2",
127 "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1",
128 "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1",
129 "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1",
130 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1",
131 "\\u039A\\u03AF\\u03BD\\u03B1",
132 "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03AF\\u03B1",
134 "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03AF\\u03B1"
136 /* display variant (Greek) */
137 { "", "", "", "", "NY", "", "", "", "" }, /* TODO: currently there is no translation for NY in Greek fix this test when we have it */
138 /* display name (Greek) */
140 "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03bd\\u03c9\\u03bc\\u03ad\\u03bd\\u03b5\\u03c2 \\u03a0\\u03bf\\u03bb\\u03b9\\u03c4\\u03b5\\u03af\\u03b5\\u03c2)",
141 "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)",
142 "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)",
143 "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)",
144 "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)",
145 "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC (Hans, \\u039A\\u03AF\\u03BD\\u03B1)",
146 "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC (\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03AF\\u03B1, \\u03A4\\u03B1\\u03BA\\u03C4\\u03BF\\u03C0\\u03BF\\u03AF\\u03B7\\u03C3\\u03B7=\\u03A3\\u03B5\\u03B9\\u03C1\\u03AC \\u03A4\\u03B7\\u03BB\\u03B5\\u03C6\\u03C9\\u03BD\\u03B9\\u03BA\\u03BF\\u03CD \\u039A\\u03B1\\u03C4\\u03B1\\u03BB\\u03CC\\u03B3\\u03BF\\u03C5)",
147 "\\u0399\\u03C3\\u03C0\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC (\\u03A4\\u03B1\\u03BA\\u03C4\\u03BF\\u03C0\\u03BF\\u03AF\\u03B7\\u03C3\\u03B7\\u003D\\u03A0\\u03B1\\u03C1\\u03B1\\u03B4\\u03BF\\u03C3\\u03B9\\u03B1\\u03BA\\u03AE)",
148 "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03AC (\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03AF\\u03B1, \\u0397\\u03BC\\u03B5\\u03C1\\u03BF\\u03BB\\u03CC\\u03B3\\u03B9\\u03BF=\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03CC \\u0397\\u03BC\\u03B5\\u03C1\\u03BF\\u03BB\\u03CC\\u03B3\\u03B9\\u03BF)"
152 static UChar
*** dataTable
=0;
192 #define TESTCASE(name) addTest(root, &name, "tsutil/cloctst/" #name)
194 void addLocaleTest(TestNode
** root
);
196 void addLocaleTest(TestNode
** root
)
198 TESTCASE(TestObsoleteNames
); /* srl- move */
199 TESTCASE(TestBasicGetters
);
200 TESTCASE(TestNullDefault
);
201 TESTCASE(TestPrefixes
);
202 TESTCASE(TestSimpleResourceInfo
);
203 TESTCASE(TestDisplayNames
);
204 TESTCASE(TestGetAvailableLocales
);
205 TESTCASE(TestDataDirectory
);
206 TESTCASE(TestISOFunctions
);
207 TESTCASE(TestISO3Fallback
);
208 TESTCASE(TestUninstalledISO3Names
);
209 TESTCASE(TestSimpleDisplayNames
);
210 TESTCASE(TestVariantParsing
);
211 TESTCASE(TestKeywordVariants
);
212 TESTCASE(TestKeywordVariantParsing
);
213 TESTCASE(TestCanonicalization
);
214 TESTCASE(TestKeywordSet
);
215 TESTCASE(TestKeywordSetError
);
216 TESTCASE(TestDisplayKeywords
);
217 TESTCASE(TestDisplayKeywordValues
);
218 TESTCASE(TestGetBaseName
);
219 TESTCASE(TestGetLocale
);
220 TESTCASE(TestDisplayNameWarning
);
221 TESTCASE(TestNonexistentLanguageExemplars
);
222 TESTCASE(TestLanguageExemplarsFallbacks
);
223 TESTCASE(TestCalendar
);
224 TESTCASE(TestDateFormat
);
225 TESTCASE(TestCollation
);
226 TESTCASE(TestULocale
);
227 TESTCASE(TestUResourceBundle
);
228 TESTCASE(TestDisplayName
);
229 TESTCASE(TestAcceptLanguage
);
230 TESTCASE(TestGetLocaleForLCID
);
234 /* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_getCountry() */
235 static void TestBasicGetters() {
238 UErrorCode status
= U_ZERO_ERROR
;
239 char *testLocale
= 0;
240 char *temp
= 0, *name
= 0;
241 log_verbose("Testing Basic Getters\n");
242 for (i
= 0; i
< LOCALE_SIZE
; i
++) {
243 testLocale
=(char*)malloc(sizeof(char) * (strlen(rawData2
[NAME
][i
])+1));
244 strcpy(testLocale
,rawData2
[NAME
][i
]);
246 log_verbose("Testing %s .....\n", testLocale
);
247 cap
=uloc_getLanguage(testLocale
, NULL
, 0, &status
);
248 if(status
==U_BUFFER_OVERFLOW_ERROR
){
250 temp
=(char*)malloc(sizeof(char) * (cap
+1));
251 uloc_getLanguage(testLocale
, temp
, cap
+1, &status
);
253 if(U_FAILURE(status
)){
254 log_err("ERROR: in uloc_getLanguage %s\n", myErrorName(status
));
256 if (0 !=strcmp(temp
,rawData2
[LANG
][i
])) {
257 log_err(" Language code mismatch: %s versus %s\n", temp
, rawData2
[LANG
][i
]);
261 cap
=uloc_getCountry(testLocale
, temp
, cap
, &status
);
262 if(status
==U_BUFFER_OVERFLOW_ERROR
){
264 temp
=(char*)realloc(temp
, sizeof(char) * (cap
+1));
265 uloc_getCountry(testLocale
, temp
, cap
+1, &status
);
267 if(U_FAILURE(status
)){
268 log_err("ERROR: in uloc_getCountry %s\n", myErrorName(status
));
270 if (0 != strcmp(temp
, rawData2
[CTRY
][i
])) {
271 log_err(" Country code mismatch: %s versus %s\n", temp
, rawData2
[CTRY
][i
]);
275 cap
=uloc_getVariant(testLocale
, temp
, cap
, &status
);
276 if(status
==U_BUFFER_OVERFLOW_ERROR
){
278 temp
=(char*)realloc(temp
, sizeof(char) * (cap
+1));
279 uloc_getVariant(testLocale
, temp
, cap
+1, &status
);
281 if(U_FAILURE(status
)){
282 log_err("ERROR: in uloc_getVariant %s\n", myErrorName(status
));
284 if (0 != strcmp(temp
, rawData2
[VAR
][i
])) {
285 log_err("Variant code mismatch: %s versus %s\n", temp
, rawData2
[VAR
][i
]);
288 cap
=uloc_getName(testLocale
, NULL
, 0, &status
);
289 if(status
==U_BUFFER_OVERFLOW_ERROR
){
291 name
=(char*)malloc(sizeof(char) * (cap
+1));
292 uloc_getName(testLocale
, name
, cap
+1, &status
);
293 } else if(status
==U_ZERO_ERROR
) {
294 log_err("ERROR: in uloc_getName(%s,NULL,0,..), expected U_BUFFER_OVERFLOW_ERROR!\n", testLocale
);
296 if(U_FAILURE(status
)){
297 log_err("ERROR: in uloc_getName %s\n", myErrorName(status
));
299 if (0 != strcmp(name
, rawData2
[NAME
][i
])){
300 log_err(" Mismatch in getName: %s versus %s\n", name
, rawData2
[NAME
][i
]);
310 static void TestNullDefault() {
311 UErrorCode status
= U_ZERO_ERROR
;
312 char original
[ULOC_FULLNAME_CAPACITY
];
314 uprv_strcpy(original
, uloc_getDefault());
315 uloc_setDefault("qq_BLA", &status
);
316 if (uprv_strcmp(uloc_getDefault(), "qq_BLA") != 0) {
317 log_err(" Mismatch in uloc_setDefault: qq_BLA versus %s\n", uloc_getDefault());
319 uloc_setDefault(NULL
, &status
);
320 if (uprv_strcmp(uloc_getDefault(), original
) != 0) {
321 log_err(" uloc_setDefault(NULL, &status) didn't get the default locale back!\n");
325 /* Test that set & get of default locale work, and that
326 * default locales are cached and reused, and not overwritten.
330 const char *n2_en_US
;
332 status
= U_ZERO_ERROR
;
333 uloc_setDefault("en_US", &status
);
334 n_en_US
= uloc_getDefault();
335 if (strcmp(n_en_US
, "en_US") != 0) {
336 log_err("Wrong result from uloc_getDefault(). Expected \"en_US\", got \"%s\"\n", n_en_US
);
339 uloc_setDefault("fr_FR", &status
);
340 n_fr_FR
= uloc_getDefault();
341 if (strcmp(n_en_US
, "en_US") != 0) {
342 log_err("uloc_setDefault altered previously default string."
343 "Expected \"en_US\", got \"%s\"\n", n_en_US
);
345 if (strcmp(n_fr_FR
, "fr_FR") != 0) {
346 log_err("Wrong result from uloc_getDefault(). Expected \"fr_FR\", got %s\n", n_fr_FR
);
349 uloc_setDefault("en_US", &status
);
350 n2_en_US
= uloc_getDefault();
351 if (strcmp(n2_en_US
, "en_US") != 0) {
352 log_err("Wrong result from uloc_getDefault(). Expected \"en_US\", got \"%s\"\n", n_en_US
);
354 if (n2_en_US
!= n_en_US
) {
355 log_err("Default locale cache failed to reuse en_US locale.\n");
358 if (U_FAILURE(status
)) {
359 log_err("Failure returned from uloc_setDefault - \"%s\"\n", u_errorName(status
));
365 /* Test the i- and x- and @ and . functionality
368 #define PREFIXBUFSIZ 128
370 static void TestPrefixes() {
373 const char *loc
, *expected
;
375 const char *testData
[][7] =
377 /* NULL canonicalize() column means "expect same as getName()" */
378 {"sv", "", "FI", "AL", "sv-fi-al", "sv_FI_AL", NULL
},
379 {"en", "", "GB", "", "en-gb", "en_GB", NULL
},
380 {"i-hakka", "", "MT", "XEMXIJA", "i-hakka_MT_XEMXIJA", "i-hakka_MT_XEMXIJA", NULL
},
381 {"i-hakka", "", "CN", "", "i-hakka_CN", "i-hakka_CN", NULL
},
382 {"i-hakka", "", "MX", "", "I-hakka_MX", "i-hakka_MX", NULL
},
383 {"x-klingon", "", "US", "SANJOSE", "X-KLINGON_us_SANJOSE", "x-klingon_US_SANJOSE", NULL
},
385 {"mr", "", "", "", "mr.utf8", "mr.utf8", "mr"},
386 {"de", "", "TV", "", "de-tv.koi8r", "de_TV.koi8r", "de_TV"},
387 {"x-piglatin", "", "ML", "", "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML"}, /* Multibyte English */
388 {"i-cherokee", "","US", "", "i-Cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US"},
389 {"x-filfli", "", "MT", "FILFLA", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA"},
390 {"no", "", "NO", "NY", "no-no-ny.utf32@B", "no_NO_NY.utf32@B", "no_NO_NY_B"},
391 {"no", "", "NO", "", "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B"},
392 {"no", "", "", "NY", "no__ny", "no__NY", NULL
},
393 {"no", "", "", "", "no@ny", "no@ny", "no__NY"},
394 {"el", "Latn", "", "", "el-latn", "el_Latn", NULL
},
395 {"en", "Cyrl", "RU", "", "en-cyrl-ru", "en_Cyrl_RU", NULL
},
396 {"zh", "Hant", "TW", "STROKE", "zh-hant_TW_STROKE", "zh_Hant_TW_STROKE", NULL
},
397 {"qq", "Qqqq", "QQ", "QQ", "qq_Qqqq_QQ_QQ", "qq_Qqqq_QQ_QQ", NULL
},
398 {"qq", "Qqqq", "", "QQ", "qq_Qqqq__QQ", "qq_Qqqq__QQ", NULL
},
399 {"12", "3456", "78", "90", "12_3456_78_90", "12_3456_78_90", NULL
}, /* total garbage */
401 {NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
}
404 const char *testTitles
[] = {
405 "uloc_getLanguage()",
411 "uloc_canonicalize()"
414 char buf
[PREFIXBUFSIZ
];
419 for(row
=0;testData
[row
][0] != NULL
;row
++) {
420 loc
= testData
[row
][NAME
];
421 log_verbose("Test #%d: %s\n", row
, loc
);
426 for(n
=0;n
<=(NAME
+2);n
++) {
427 if(n
==NAME
) continue;
429 for(len
=0;len
<PREFIXBUFSIZ
;len
++) {
430 buf
[len
] = '%'; /* Set a tripwire.. */
436 len
= uloc_getLanguage(loc
, buf
, PREFIXBUFSIZ
, &err
);
440 len
= uloc_getScript(loc
, buf
, PREFIXBUFSIZ
, &err
);
444 len
= uloc_getCountry(loc
, buf
, PREFIXBUFSIZ
, &err
);
448 len
= uloc_getVariant(loc
, buf
, PREFIXBUFSIZ
, &err
);
452 len
= uloc_getName(loc
, buf
, PREFIXBUFSIZ
, &err
);
456 len
= uloc_canonicalize(loc
, buf
, PREFIXBUFSIZ
, &err
);
465 log_err("#%d: %s on %s: err %s\n",
466 row
, testTitles
[n
], loc
, u_errorName(err
));
468 log_verbose("#%d: %s on %s: -> [%s] (length %d)\n",
469 row
, testTitles
[n
], loc
, buf
, len
);
471 if(len
!= (int32_t)strlen(buf
)) {
472 log_err("#%d: %s on %s: -> [%s] (length returned %d, actual %d!)\n",
473 row
, testTitles
[n
], loc
, buf
, len
, strlen(buf
)+1);
477 /* see if they smashed something */
478 if(buf
[len
+1] != '%') {
479 log_err("#%d: %s on %s: -> [%s] - wrote [%X] out ofbounds!\n",
480 row
, testTitles
[n
], loc
, buf
, buf
[len
+1]);
483 expected
= testData
[row
][n
];
484 if (expected
== NULL
&& n
== (NAME
+2)) {
485 /* NULL expected canonicalize() means "expect same as getName()" */
486 expected
= testData
[row
][NAME
+1];
488 if(strcmp(buf
, expected
)) {
489 log_err("#%d: %s on %s: -> [%s] (expected '%s'!)\n",
490 row
, testTitles
[n
], loc
, buf
, expected
);
499 /* testing uloc_getISO3Language(), uloc_getISO3Country(), */
500 static void TestSimpleResourceInfo() {
502 char* testLocale
= 0;
507 testLocale
=(char*)malloc(sizeof(char) * 1);
508 expected
=(UChar
*)malloc(sizeof(UChar
) * 1);
511 log_verbose("Testing getISO3Language and getISO3Country\n");
512 for (i
= 0; i
< LOCALE_SIZE
; i
++) {
514 testLocale
=(char*)realloc(testLocale
, sizeof(char) * (u_strlen(dataTable
[NAME
][i
])+1));
515 u_austrcpy(testLocale
, dataTable
[NAME
][i
]);
517 log_verbose("Testing %s ......\n", testLocale
);
519 temp
=uloc_getISO3Language(testLocale
);
520 expected
=(UChar
*)realloc(expected
, sizeof(UChar
) * (strlen(temp
) + 1));
521 u_uastrcpy(expected
,temp
);
522 if (0 != u_strcmp(expected
, dataTable
[LANG3
][i
])) {
523 log_err(" ISO-3 language code mismatch: %s versus %s\n", austrdup(expected
),
524 austrdup(dataTable
[LANG3
][i
]));
527 temp
=uloc_getISO3Country(testLocale
);
528 expected
=(UChar
*)realloc(expected
, sizeof(UChar
) * (strlen(temp
) + 1));
529 u_uastrcpy(expected
,temp
);
530 if (0 != u_strcmp(expected
, dataTable
[CTRY3
][i
])) {
531 log_err(" ISO-3 Country code mismatch: %s versus %s\n", austrdup(expected
),
532 austrdup(dataTable
[CTRY3
][i
]));
534 sprintf(temp2
, "%x", (int)uloc_getLCID(testLocale
));
535 if (strcmp(temp2
, rawData2
[LCID
][i
]) != 0) {
536 log_err("LCID mismatch: %s versus %s\n", temp2
, rawData2
[LCID
][i
]);
546 * Jitterbug 2439 -- markus 20030425
548 * The lookup of display names must not fall back through the default
549 * locale because that yields useless results.
551 static void TestDisplayNames()
554 UErrorCode errorCode
=U_ZERO_ERROR
;
556 log_verbose("Testing getDisplayName for different locales\n");
558 log_verbose(" In locale = en_US...\n");
559 doTestDisplayNames("en_US", DLANG_EN
);
560 log_verbose(" In locale = fr_FR....\n");
561 doTestDisplayNames("fr_FR", DLANG_FR
);
562 log_verbose(" In locale = ca_ES...\n");
563 doTestDisplayNames("ca_ES", DLANG_CA
);
564 log_verbose(" In locale = gr_EL..\n");
565 doTestDisplayNames("el_GR", DLANG_EL
);
567 /* test that the default locale has a display name for its own language */
568 errorCode
=U_ZERO_ERROR
;
569 length
=uloc_getDisplayLanguage(NULL
, NULL
, buffer
, LENGTHOF(buffer
), &errorCode
);
570 if(U_FAILURE(errorCode
) || (length
<=3 && buffer
[0]<=0x7f)) {
571 /* check <=3 to reject getting the language code as a display name */
572 log_err("unable to get a display string for the language of the default locale - %s\n", u_errorName(errorCode
));
575 /* test that we get the language code itself for an unknown language, and a default warning */
576 errorCode
=U_ZERO_ERROR
;
577 length
=uloc_getDisplayLanguage("qq", "rr", buffer
, LENGTHOF(buffer
), &errorCode
);
578 if(errorCode
!=U_USING_DEFAULT_WARNING
|| length
!=2 || buffer
[0]!=0x71 || buffer
[1]!=0x71) {
579 log_err("error getting the display string for an unknown language - %s\n", u_errorName(errorCode
));
582 /* test that we get a default warning for a display name where one component is unknown (4255) */
583 errorCode
=U_ZERO_ERROR
;
584 length
=uloc_getDisplayName("qq_US_POSIX", "en_US", buffer
, LENGTHOF(buffer
), &errorCode
);
585 if(errorCode
!=U_USING_DEFAULT_WARNING
) {
586 log_err("error getting the display name for a locale with an unknown language - %s\n", u_errorName(errorCode
));
591 const char *aLocale
= "es@collation=traditional;calendar=japanese";
592 const char *testL
[] = { "en_US",
596 const char *expect
[] = { "Spanish (Calendar=Japanese Calendar, Collation=Traditional)", /* note sorted order of keywords */
597 "espagnol (Calendrier=Calendrier japonais, Ordonnancement=Ordre traditionnel)",
598 "espanyol (calendar=japanese, collation=traditional)",
599 "\\u0399\\u03C3\\u03C0\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC (\\u0397\\u03BC\\u03B5\\u03C1\\u03BF\\u03BB\\u03CC\\u03B3\\u03B9\\u03BF=\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03CC \\u0397\\u03BC\\u03B5\\u03C1\\u03BF\\u03BB\\u03CC\\u03B3\\u03B9\\u03BF, \\u03A4\\u03B1\\u03BA\\u03C4\\u03BF\\u03C0\\u03BF\\u03AF\\u03B7\\u03C3\\u03B7=\\u03A0\\u03B1\\u03C1\\u03B1\\u03B4\\u03BF\\u03C3\\u03B9\\u03B1\\u03BA\\u03AE)" };
602 for(i
=0;i
<LENGTHOF(testL
);i
++) {
603 errorCode
= U_ZERO_ERROR
;
604 uloc_getDisplayName(aLocale
, testL
[i
], buffer
, LENGTHOF(buffer
), &errorCode
);
605 if(U_FAILURE(errorCode
)) {
606 log_err("FAIL in uloc_getDisplayName(%s,%s,..) -> %s\n", aLocale
, testL
[i
], u_errorName(errorCode
));
608 expectBuffer
= CharsToUChars(expect
[i
]);
609 if(u_strcmp(buffer
,expectBuffer
)) {
610 log_err("FAIL in uloc_getDisplayName(%s,%s,..) expected '%s' got '%s'\n", aLocale
, testL
[i
], expect
[i
], austrdup(buffer
));
612 log_verbose("pass in uloc_getDisplayName(%s,%s,..) got '%s'\n", aLocale
, testL
[i
], expect
[i
]);
621 /* test for uloc_getAvialable() and uloc_countAvilable()*/
622 static void TestGetAvailableLocales()
628 log_verbose("Testing the no of avialable locales\n");
629 locCount
=uloc_countAvailable();
631 log_data_err("countAvailable() returned an empty list!\n");
633 /* use something sensible w/o hardcoding the count */
634 else if(locCount
< 0){
635 log_data_err("countAvailable() returned a wrong value!= %d\n", locCount
);
638 log_info("Number of locales returned = %d\n", locCount
);
640 for(i
=0;i
<locCount
;i
++){
641 locList
=uloc_getAvailable(i
);
643 log_verbose(" %s\n", locList
);
647 /* test for u_getDataDirectory, u_setDataDirectory, uloc_getISO3Language */
648 static void TestDataDirectory()
651 char oldDirectory
[512];
652 const char *temp
,*testValue1
,*testValue2
,*testValue3
;
653 const char path
[40] ="d:\\icu\\source\\test\\intltest" U_FILE_SEP_STRING
; /*give the required path */
655 log_verbose("Testing getDataDirectory()\n");
656 temp
= u_getDataDirectory();
657 strcpy(oldDirectory
, temp
);
659 testValue1
=uloc_getISO3Language("en_US");
660 log_verbose("first fetch of language retrieved %s\n", testValue1
);
662 if (0 != strcmp(testValue1
,"eng")){
663 log_err("Initial check of ISO3 language failed: expected \"eng\", got %s \n", testValue1
);
666 /*defining the path for DataDirectory */
667 log_verbose("Testing setDataDirectory\n");
668 u_setDataDirectory( path
);
669 if(strcmp(path
, u_getDataDirectory())==0)
670 log_verbose("setDataDirectory working fine\n");
672 log_err("Error in setDataDirectory. Directory not set correctly - came back as [%s], expected [%s]\n", u_getDataDirectory(), path
);
674 testValue2
=uloc_getISO3Language("en_US");
675 log_verbose("second fetch of language retrieved %s \n", testValue2
);
677 u_setDataDirectory(oldDirectory
);
678 testValue3
=uloc_getISO3Language("en_US");
679 log_verbose("third fetch of language retrieved %s \n", testValue3
);
681 if (0 != strcmp(testValue3
,"eng")) {
682 log_err("get/setDataDirectory() failed: expected \"eng\", got \" %s \" \n", testValue3
);
688 /*=========================================================== */
692 static void doTestDisplayNames(const char* displayLocale
, int32_t compareIndex
)
694 UErrorCode status
= U_ZERO_ERROR
;
696 int32_t maxresultsize
;
698 const char *testLocale
;
702 UChar
*testScript
= 0;
708 UChar
* expectedLang
= 0;
709 UChar
* expectedScript
= 0;
710 UChar
* expectedCtry
= 0;
711 UChar
* expectedVar
= 0;
712 UChar
* expectedName
= 0;
716 for(i
=0;i
<LOCALE_SIZE
; ++i
)
718 testLocale
=rawData2
[NAME
][i
];
720 log_verbose("Testing..... %s\n", testLocale
);
723 maxresultsize
=uloc_getDisplayLanguage(testLocale
, displayLocale
, NULL
, maxresultsize
, &status
);
724 if(status
==U_BUFFER_OVERFLOW_ERROR
)
727 testLang
=(UChar
*)malloc(sizeof(UChar
) * (maxresultsize
+1));
728 uloc_getDisplayLanguage(testLocale
, displayLocale
, testLang
, maxresultsize
+ 1, &status
);
734 if(U_FAILURE(status
)){
735 log_err("Error in getDisplayLanguage() %s\n", myErrorName(status
));
739 maxresultsize
=uloc_getDisplayScript(testLocale
, displayLocale
, NULL
, maxresultsize
, &status
);
740 if(status
==U_BUFFER_OVERFLOW_ERROR
)
743 testScript
=(UChar
*)malloc(sizeof(UChar
) * (maxresultsize
+1));
744 uloc_getDisplayScript(testLocale
, displayLocale
, testScript
, maxresultsize
+ 1, &status
);
750 if(U_FAILURE(status
)){
751 log_err("Error in getDisplayScript() %s\n", myErrorName(status
));
755 maxresultsize
=uloc_getDisplayCountry(testLocale
, displayLocale
, NULL
, maxresultsize
, &status
);
756 if(status
==U_BUFFER_OVERFLOW_ERROR
)
759 testCtry
=(UChar
*)malloc(sizeof(UChar
) * (maxresultsize
+1));
760 uloc_getDisplayCountry(testLocale
, displayLocale
, testCtry
, maxresultsize
+ 1, &status
);
766 if(U_FAILURE(status
)){
767 log_err("Error in getDisplayCountry() %s\n", myErrorName(status
));
771 maxresultsize
=uloc_getDisplayVariant(testLocale
, displayLocale
, NULL
, maxresultsize
, &status
);
772 if(status
==U_BUFFER_OVERFLOW_ERROR
)
775 testVar
=(UChar
*)malloc(sizeof(UChar
) * (maxresultsize
+1));
776 uloc_getDisplayVariant(testLocale
, displayLocale
, testVar
, maxresultsize
+ 1, &status
);
782 if(U_FAILURE(status
)){
783 log_err("Error in getDisplayVariant() %s\n", myErrorName(status
));
787 maxresultsize
=uloc_getDisplayName(testLocale
, displayLocale
, NULL
, maxresultsize
, &status
);
788 if(status
==U_BUFFER_OVERFLOW_ERROR
)
791 testName
=(UChar
*)malloc(sizeof(UChar
) * (maxresultsize
+1));
792 uloc_getDisplayName(testLocale
, displayLocale
, testName
, maxresultsize
+ 1, &status
);
798 if(U_FAILURE(status
)){
799 log_err("Error in getDisplayName() %s\n", myErrorName(status
));
802 expectedLang
=dataTable
[compareIndex
][i
];
803 if(u_strlen(expectedLang
)== 0)
804 expectedLang
=dataTable
[DLANG_EN
][i
];
806 expectedScript
=dataTable
[compareIndex
+ 1][i
];
807 if(u_strlen(expectedScript
)== 0)
808 expectedScript
=dataTable
[DSCRIPT_EN
][i
];
810 expectedCtry
=dataTable
[compareIndex
+ 2][i
];
811 if(u_strlen(expectedCtry
)== 0)
812 expectedCtry
=dataTable
[DCTRY_EN
][i
];
814 expectedVar
=dataTable
[compareIndex
+ 3][i
];
815 if(u_strlen(expectedVar
)== 0)
816 expectedVar
=dataTable
[DVAR_EN
][i
];
818 expectedName
=dataTable
[compareIndex
+ 4][i
];
819 if(u_strlen(expectedName
) == 0)
820 expectedName
=dataTable
[DNAME_EN
][i
];
822 if (0 !=u_strcmp(testLang
,expectedLang
)) {
823 log_data_err(" Display Language mismatch: got %s expected %s displayLocale=%s\n", austrdup(testLang
), austrdup(expectedLang
), displayLocale
);
826 if (0 != u_strcmp(testScript
,expectedScript
)) {
827 log_data_err(" Display Script mismatch: got %s expected %s displayLocale=%s\n", austrdup(testScript
), austrdup(expectedScript
), displayLocale
);
830 if (0 != u_strcmp(testCtry
,expectedCtry
)) {
831 log_data_err(" Display Country mismatch: got %s expected %s displayLocale=%s\n", austrdup(testCtry
), austrdup(expectedCtry
), displayLocale
);
834 if (0 != u_strcmp(testVar
,expectedVar
)) {
835 log_data_err(" Display Variant mismatch: got %s expected %s displayLocale=%s\n", austrdup(testVar
), austrdup(expectedVar
), displayLocale
);
838 if(0 != u_strcmp(testName
, expectedName
)) {
839 log_data_err(" Display Name mismatch: got %s expected %s displayLocale=%s\n", austrdup(testName
), austrdup(expectedName
), displayLocale
);
842 if(testName
!=&_NUL
) {
845 if(testLang
!=&_NUL
) {
848 if(testScript
!=&_NUL
) {
851 if(testCtry
!=&_NUL
) {
861 /* test for uloc_getISOLanguages, uloc_getISOCountries */
862 static void TestISOFunctions()
864 const char* const* str
=uloc_getISOLanguages();
865 const char* const* str1
=uloc_getISOCountries();
869 UResourceBundle
*res
;
870 UErrorCode status
= U_ZERO_ERROR
;
872 /* test getISOLanguages*/
873 /*str=uloc_getISOLanguages(); */
874 log_verbose("Testing ISO Languages: \n");
876 /* use structLocale - this data is no longer in root */
877 res
= ures_openDirect(loadTestData(&status
), "structLocale", &status
);
878 ures_getByKey(res
, "Languages", res
, &status
);
879 if (U_FAILURE(status
)) {
880 log_err("There is an error in structLocale's ures_getByKey(\"Languages\"), status=%s\n", u_errorName(status
));
881 status
= U_ZERO_ERROR
;
884 for(count
= 0; *(str
+count
) != 0; count
++)
888 #if U_CHARSET_FAMILY==U_ASCII_FAMILY
890 /* This code only works on ASCII machines where the keys are stored in ASCII order */
892 ures_getNextString(res
, NULL
, &key
, &status
);
893 if(!strcmp(key
,"root"))
894 ures_getNextString(res
, NULL
, &key
, &status
);
895 if(!strcmp(key
,"Fallback"))
896 ures_getNextString(res
, NULL
, &key
, &status
);
897 if(!strcmp(key
,"sh")) /* Remove this once sh is removed. */
898 ures_getNextString(res
, NULL
, &key
, &status
);
899 if(!key
|| strcmp(test
,key
)) {
900 /* The first difference usually implies the place where things get out of sync */
901 log_err("FAIL diff at offset %d, \"%s\" != \"%s\"\n", count
, test
, key
);
903 status
= U_ZERO_ERROR
;
907 if(!strcmp(test
,"in"))
908 log_err("FAIL getISOLanguages() has obsolete language code %s\n", test
);
909 if(!strcmp(test
,"iw"))
910 log_err("FAIL getISOLanguages() has obsolete language code %s\n", test
);
911 if(!strcmp(test
,"ji"))
912 log_err("FAIL getISOLanguages() has obsolete language code %s\n", test
);
913 if(!strcmp(test
,"jw"))
914 log_err("FAIL getISOLanguages() has obsolete language code %s\n", test
);
915 if(!strcmp(test
,"sh"))
916 log_err("FAIL getISOLanguages() has obsolete language code %s\n", test
);
919 /* We check root, just in case the en locale is removed. The en locale should have the same number of resources. */
920 expect
= ures_getSize(res
) - 1; /* Ignore root */
921 expect
-= 1; /* TODO: Remove this line once sh goes away. */
925 log_err("There is an error in getISOLanguages, got %d, expected %d (as per structLocale)\n", count
, expect
);
928 log_verbose("Testing ISO Countries");
929 for(count
= 0; *(str1
+count
) != 0; count
++)
931 test
= *(str1
+count
);
932 if(!strcmp(test
,"FX"))
933 log_err("FAIL getISOCountries() has obsolete country code %s\n", test
);
934 if(!strcmp(test
,"ZR"))
935 log_err("FAIL getISOCountries() has obsolete country code %s\n", test
);
940 log_err("There is an error in getISOCountries, got %d, expected %d \n", count
, expect
);
944 static void setUpDataTable()
947 dataTable
= (UChar
***)(calloc(sizeof(UChar
**),LOCALE_INFO_SIZE
));
949 for (i
= 0; i
< LOCALE_INFO_SIZE
; i
++) {
950 dataTable
[i
] = (UChar
**)(calloc(sizeof(UChar
*),LOCALE_SIZE
));
951 for (j
= 0; j
< LOCALE_SIZE
; j
++){
952 dataTable
[i
][j
] = CharsToUChars(rawData2
[i
][j
]);
957 static void cleanUpDataTable()
960 if(dataTable
!= NULL
) {
961 for (i
=0; i
<LOCALE_INFO_SIZE
; i
++) {
962 for(j
= 0; j
< LOCALE_SIZE
; j
++) {
963 free(dataTable
[i
][j
]);
973 * @bug 4011756 4011380
975 static void TestISO3Fallback()
977 const char* test
="xx_YY";
981 result
= uloc_getISO3Language(test
);
983 /* Conform to C API usage */
985 if (!result
|| (result
[0] != 0))
986 log_err("getISO3Language() on xx_YY returned %s instead of \"\"");
988 result
= uloc_getISO3Country(test
);
990 if (!result
|| (result
[0] != 0))
991 log_err("getISO3Country() on xx_YY returned %s instead of \"\"");
997 static void TestSimpleDisplayNames()
1000 This test is different from TestDisplayNames because TestDisplayNames checks
1001 fallback behavior, combination of language and country names to form locale
1002 names, and other stuff like that. This test just checks specific language
1003 and country codes to make sure we have the correct names for them.
1005 char languageCodes
[] [4] = { "he", "id", "iu", "ug", "yi", "za" };
1006 const char* languageNames
[] = { "Hebrew", "Indonesian", "Inuktitut", "Uighur", "Yiddish",
1008 UErrorCode status
=U_ZERO_ERROR
;
1011 for (i
= 0; i
< 6; i
++) {
1013 UChar
*expectedLang
=0;
1015 size
=uloc_getDisplayLanguage(languageCodes
[i
], "en_US", NULL
, size
, &status
);
1016 if(status
==U_BUFFER_OVERFLOW_ERROR
) {
1017 status
=U_ZERO_ERROR
;
1018 testLang
=(UChar
*)malloc(sizeof(UChar
) * (size
+ 1));
1019 uloc_getDisplayLanguage(languageCodes
[i
], "en_US", testLang
, size
+ 1, &status
);
1021 expectedLang
=(UChar
*)malloc(sizeof(UChar
) * (strlen(languageNames
[i
])+1));
1022 u_uastrcpy(expectedLang
, languageNames
[i
]);
1023 if (u_strcmp(testLang
, expectedLang
) != 0)
1024 log_data_err("Got wrong display name for %s : Expected \"%s\", got \"%s\".\n",
1025 languageCodes
[i
], languageNames
[i
], austrdup(testLang
));
1035 static void TestUninstalledISO3Names()
1037 /* This test checks to make sure getISO3Language and getISO3Country work right
1038 even for locales that are not installed. */
1039 const char iso2Languages
[][4] = { "am", "ba", "fy", "mr", "rn",
1041 const char iso3Languages
[][5] = { "amh", "bak", "fry", "mar", "run",
1042 "ssw", "twi", "zul" };
1043 char iso2Countries
[][6] = { "am_AF", "ba_BW", "fy_KZ", "mr_MO", "rn_MN",
1044 "ss_SB", "tw_TC", "zu_ZW" };
1045 char iso3Countries
[][4] = { "AFG", "BWA", "KAZ", "MAC", "MNG",
1046 "SLB", "TCA", "ZWE" };
1049 for (i
= 0; i
< 8; i
++) {
1050 UErrorCode err
= U_ZERO_ERROR
;
1052 test
= uloc_getISO3Language(iso2Languages
[i
]);
1053 if(strcmp(test
, iso3Languages
[i
]) !=0 || U_FAILURE(err
))
1054 log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
1055 iso2Languages
[i
], iso3Languages
[i
], test
, myErrorName(err
));
1057 for (i
= 0; i
< 8; i
++) {
1058 UErrorCode err
= U_ZERO_ERROR
;
1060 test
= uloc_getISO3Country(iso2Countries
[i
]);
1061 if(strcmp(test
, iso3Countries
[i
]) !=0 || U_FAILURE(err
))
1062 log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
1063 iso2Countries
[i
], iso3Countries
[i
], test
, myErrorName(err
));
1068 static void TestVariantParsing()
1070 const char* en_US_custom
="en_US_De Anza_Cupertino_California_United States_Earth";
1071 const char* dispName
="English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)";
1072 const char* dispVar
="DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH";
1073 const char* shortVariant
="fr_FR_foo";
1074 const char* bogusVariant
="fr_FR__foo";
1075 const char* bogusVariant2
="fr_FR_foo_";
1076 const char* bogusVariant3
="fr_FR__foo_";
1079 UChar displayVar
[100];
1080 UChar displayName
[100];
1081 UErrorCode status
=U_ZERO_ERROR
;
1084 size
=uloc_getDisplayVariant(en_US_custom
, "en_US", NULL
, size
, &status
);
1085 if(status
==U_BUFFER_OVERFLOW_ERROR
) {
1086 status
=U_ZERO_ERROR
;
1087 got
=(UChar
*)realloc(got
, sizeof(UChar
) * (size
+1));
1088 uloc_getDisplayVariant(en_US_custom
, "en_US", got
, size
+ 1, &status
);
1091 log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1093 u_uastrcpy(displayVar
, dispVar
);
1094 if(u_strcmp(got
,displayVar
)!=0) {
1095 log_err("FAIL: getDisplayVariant() Wanted %s, got %s\n", dispVar
, austrdup(got
));
1098 size
=uloc_getDisplayName(en_US_custom
, "en_US", NULL
, size
, &status
);
1099 if(status
==U_BUFFER_OVERFLOW_ERROR
) {
1100 status
=U_ZERO_ERROR
;
1101 got
=(UChar
*)realloc(got
, sizeof(UChar
) * (size
+1));
1102 uloc_getDisplayName(en_US_custom
, "en_US", got
, size
+ 1, &status
);
1105 log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1107 u_uastrcpy(displayName
, dispName
);
1108 if(u_strcmp(got
,displayName
)!=0) {
1109 log_err("FAIL: getDisplayName() Wanted %s, got %s\n", dispName
, austrdup(got
));
1113 status
=U_ZERO_ERROR
;
1114 size
=uloc_getDisplayVariant(shortVariant
, NULL
, NULL
, size
, &status
);
1115 if(status
==U_BUFFER_OVERFLOW_ERROR
) {
1116 status
=U_ZERO_ERROR
;
1117 got
=(UChar
*)realloc(got
, sizeof(UChar
) * (size
+1));
1118 uloc_getDisplayVariant(shortVariant
, NULL
, got
, size
+ 1, &status
);
1121 log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1123 if(strcmp(austrdup(got
),"FOO")!=0) {
1124 log_err("FAIL: getDisplayVariant() Wanted: foo Got: %s\n", austrdup(got
));
1127 status
=U_ZERO_ERROR
;
1128 size
=uloc_getDisplayVariant(bogusVariant
, NULL
, NULL
, size
, &status
);
1129 if(status
==U_BUFFER_OVERFLOW_ERROR
) {
1130 status
=U_ZERO_ERROR
;
1131 got
=(UChar
*)realloc(got
, sizeof(UChar
) * (size
+1));
1132 uloc_getDisplayVariant(bogusVariant
, NULL
, got
, size
+ 1, &status
);
1135 log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1137 if(strcmp(austrdup(got
),"_FOO")!=0) {
1138 log_err("FAIL: getDisplayVariant() Wanted: _FOO Got: %s\n", austrdup(got
));
1141 status
=U_ZERO_ERROR
;
1142 size
=uloc_getDisplayVariant(bogusVariant2
, NULL
, NULL
, size
, &status
);
1143 if(status
==U_BUFFER_OVERFLOW_ERROR
) {
1144 status
=U_ZERO_ERROR
;
1145 got
=(UChar
*)realloc(got
, sizeof(UChar
) * (size
+1));
1146 uloc_getDisplayVariant(bogusVariant2
, NULL
, got
, size
+ 1, &status
);
1149 log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1151 if(strcmp(austrdup(got
),"FOO_")!=0) {
1152 log_err("FAIL: getDisplayVariant() Wanted: FOO_ Got: %s\n", austrdup(got
));
1155 status
=U_ZERO_ERROR
;
1156 size
=uloc_getDisplayVariant(bogusVariant3
, NULL
, NULL
, size
, &status
);
1157 if(status
==U_BUFFER_OVERFLOW_ERROR
) {
1158 status
=U_ZERO_ERROR
;
1159 got
=(UChar
*)realloc(got
, sizeof(UChar
) * (size
+1));
1160 uloc_getDisplayVariant(bogusVariant3
, NULL
, got
, size
+ 1, &status
);
1163 log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1165 if(strcmp(austrdup(got
),"_FOO_")!=0) {
1166 log_err("FAIL: getDisplayVariant() Wanted: _FOO_ Got: %s\n", austrdup(got
));
1172 static void TestObsoleteNames(void)
1175 UErrorCode status
= U_ZERO_ERROR
;
1187 { "eng_USA", "eng", "en", "USA", "US" },
1188 { "kok", "kok", "kok", "", "" },
1189 { "in", "ind", "in", "", "" },
1190 { "id", "ind", "id", "", "" }, /* NO aliasing */
1191 { "sh", "srp", "sh", "", "" },
1192 { "zz_FX", "", "zz", "FXX", "FX" },
1193 { "zz_RO", "", "zz", "ROU", "RO" },
1194 { "zz_TP", "", "zz", "TMP", "TP" },
1195 { "zz_TL", "", "zz", "TLS", "TL" },
1196 { "zz_ZR", "", "zz", "ZAR", "ZR" },
1197 { "zz_FXX", "", "zz", "FXX", "FX" }, /* no aliasing. Doesn't go to PS(PSE). */
1198 { "zz_ROM", "", "zz", "ROU", "RO" },
1199 { "zz_ROU", "", "zz", "ROU", "RO" },
1200 { "zz_ZAR", "", "zz", "ZAR", "ZR" },
1201 { "zz_TMP", "", "zz", "TMP", "TP" },
1202 { "zz_TLS", "", "zz", "TLS", "TL" },
1203 { "mlt_PSE", "mlt", "mt", "PSE", "PS" },
1204 { "iw", "heb", "iw", "", "" },
1205 { "ji", "yid", "ji", "", "" },
1206 { "jw", "jaw", "jw", "", "" },
1207 { "sh", "srp", "sh", "", "" },
1208 { "", "", "", "", "" }
1211 for(i
=0;tests
[i
].locale
[0];i
++)
1215 locale
= tests
[i
].locale
;
1216 log_verbose("** %s:\n", locale
);
1218 status
= U_ZERO_ERROR
;
1219 if(strcmp(tests
[i
].lang3
,uloc_getISO3Language(locale
)))
1221 log_err("FAIL: uloc_getISO3Language(%s)==\t\"%s\",\t expected \"%s\"\n",
1222 locale
, uloc_getISO3Language(locale
), tests
[i
].lang3
);
1226 log_verbose(" uloc_getISO3Language()==\t\"%s\"\n",
1227 uloc_getISO3Language(locale
) );
1230 status
= U_ZERO_ERROR
;
1231 uloc_getLanguage(locale
, buff
, 256, &status
);
1232 if(U_FAILURE(status
))
1234 log_err("FAIL: error getting language from %s\n", locale
);
1238 if(strcmp(buff
,tests
[i
].lang
))
1240 log_err("FAIL: uloc_getLanguage(%s)==\t\"%s\"\t expected \"%s\"\n",
1241 locale
, buff
, tests
[i
].lang
);
1245 log_verbose(" uloc_getLanguage(%s)==\t%s\n", locale
, buff
);
1248 if(strcmp(tests
[i
].lang3
,uloc_getISO3Language(locale
)))
1250 log_err("FAIL: uloc_getISO3Language(%s)==\t\"%s\",\t expected \"%s\"\n",
1251 locale
, uloc_getISO3Language(locale
), tests
[i
].lang3
);
1255 log_verbose(" uloc_getISO3Language()==\t\"%s\"\n",
1256 uloc_getISO3Language(locale
) );
1259 if(strcmp(tests
[i
].ctry3
,uloc_getISO3Country(locale
)))
1261 log_err("FAIL: uloc_getISO3Country(%s)==\t\"%s\",\t expected \"%s\"\n",
1262 locale
, uloc_getISO3Country(locale
), tests
[i
].ctry3
);
1266 log_verbose(" uloc_getISO3Country()==\t\"%s\"\n",
1267 uloc_getISO3Country(locale
) );
1270 status
= U_ZERO_ERROR
;
1271 uloc_getCountry(locale
, buff
, 256, &status
);
1272 if(U_FAILURE(status
))
1274 log_err("FAIL: error getting country from %s\n", locale
);
1278 if(strcmp(buff
,tests
[i
].ctry
))
1280 log_err("FAIL: uloc_getCountry(%s)==\t\"%s\"\t expected \"%s\"\n",
1281 locale
, buff
, tests
[i
].ctry
);
1285 log_verbose(" uloc_getCountry(%s)==\t%s\n", locale
, buff
);
1290 if (uloc_getLCID("iw_IL") != uloc_getLCID("he_IL")) {
1291 log_err("he,iw LCID mismatch: %X versus %X\n", uloc_getLCID("iw_IL"), uloc_getLCID("he_IL"));
1294 if (uloc_getLCID("iw") != uloc_getLCID("he")) {
1295 log_err("he,iw LCID mismatch: %X versus %X\n", uloc_getLCID("iw"), uloc_getLCID("he"));
1300 i
= uloc_getLanguage("kok",NULL
,0,&icu_err
);
1301 if(U_FAILURE(icu_err
))
1303 log_err("FAIL: Got %s trying to do uloc_getLanguage(kok)\n", u_errorName(icu_err
));
1306 icu_err
= U_ZERO_ERROR
;
1307 uloc_getLanguage("kok",r1_buff
,12,&icu_err
);
1308 if(U_FAILURE(icu_err
))
1310 log_err("FAIL: Got %s trying to do uloc_getLanguage(kok, buff)\n", u_errorName(icu_err
));
1313 r1_addr
= (char *)uloc_getISO3Language("kok");
1315 icu_err
= U_ZERO_ERROR
;
1316 if (strcmp(r1_buff
,"kok") != 0)
1318 log_err("FAIL: uloc_getLanguage(kok)==%s not kok\n",r1_buff
);
1321 r1_addr
= (char *)uloc_getISO3Language("in");
1322 i
= uloc_getLanguage(r1_addr
,r1_buff
,12,&icu_err
);
1323 if (strcmp(r1_buff
,"id") != 0)
1325 printf("uloc_getLanguage error (%s)\n",r1_buff
);
1328 r1_addr
= (char *)uloc_getISO3Language("sh");
1329 i
= uloc_getLanguage(r1_addr
,r1_buff
,12,&icu_err
);
1330 if (strcmp(r1_buff
,"sr") != 0)
1332 printf("uloc_getLanguage error (%s)\n",r1_buff
);
1336 r1_addr
= (char *)uloc_getISO3Country("zz_ZR");
1337 strcpy(p1_buff
,"zz_");
1338 strcat(p1_buff
,r1_addr
);
1339 i
= uloc_getCountry(p1_buff
,r1_buff
,12,&icu_err
);
1340 if (strcmp(r1_buff
,"ZR") != 0)
1342 printf("uloc_getCountry error (%s)\n",r1_buff
);
1345 r1_addr
= (char *)uloc_getISO3Country("zz_FX");
1346 strcpy(p1_buff
,"zz_");
1347 strcat(p1_buff
,r1_addr
);
1348 i
= uloc_getCountry(p1_buff
,r1_buff
,12,&icu_err
);
1349 if (strcmp(r1_buff
,"FX") != 0)
1351 printf("uloc_getCountry error (%s)\n",r1_buff
);
1359 static void TestKeywordVariants(void)
1362 const char *localeID
;
1363 const char *expectedLocaleID
;
1364 const char *expectedLocaleIDNoKeywords
;
1365 const char *expectedCanonicalID
;
1366 const char *expectedKeywords
[10];
1367 int32_t numKeywords
;
1368 UErrorCode expectedStatus
; /* from uloc_openKeywords */
1371 "de_DE@ currency = euro; C o ll A t i o n = Phonebook ; C alen dar = buddhist ",
1372 "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
1374 "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
1375 {"calendar", "collation", "currency"},
1383 "de_DE@currency=EUR",
1384 {"","","","","","",""},
1386 U_INVALID_FORMAT_ERROR
/* must have '=' after '@' */
1389 "de_DE@euro;collation=phonebook",
1390 "de_DE", /* error result; bad format */
1391 "de_DE", /* error result; bad format */
1392 "de_DE", /* error result; bad format */
1393 {"","","","","","",""},
1395 U_INVALID_FORMAT_ERROR
1398 UErrorCode status
= U_ZERO_ERROR
;
1400 int32_t i
= 0, j
= 0;
1401 int32_t resultLen
= 0;
1403 UEnumeration
*keywords
;
1404 int32_t keyCount
= 0;
1405 const char *keyword
= NULL
;
1406 int32_t keywordLen
= 0;
1408 for(i
= 0; i
< sizeof(testCases
)/sizeof(testCases
[0]); i
++) {
1409 status
= U_ZERO_ERROR
;
1411 keywords
= uloc_openKeywords(testCases
[i
].localeID
, &status
);
1413 if(status
!= testCases
[i
].expectedStatus
) {
1414 log_err("Expected to uloc_openKeywords(\"%s\") => status %s. Got %s instead\n",
1415 testCases
[i
].localeID
,
1416 u_errorName(testCases
[i
].expectedStatus
), u_errorName(status
));
1418 status
= U_ZERO_ERROR
;
1420 if((keyCount
= uenum_count(keywords
, &status
)) != testCases
[i
].numKeywords
) {
1421 log_err("Expected to get %i keywords, got %i\n", testCases
[i
].numKeywords
, keyCount
);
1425 while((keyword
= uenum_next(keywords
, &keywordLen
, &status
))) {
1426 if(strcmp(keyword
, testCases
[i
].expectedKeywords
[j
]) != 0) {
1427 log_err("Expected to get keyword value %s, got %s\n", testCases
[i
].expectedKeywords
[j
], keyword
);
1432 uenum_reset(keywords
, &status
);
1433 while((keyword
= uenum_next(keywords
, &keywordLen
, &status
))) {
1434 if(strcmp(keyword
, testCases
[i
].expectedKeywords
[j
]) != 0) {
1435 log_err("Expected to get keyword value %s, got %s\n", testCases
[i
].expectedKeywords
[j
], keyword
);
1440 uenum_close(keywords
);
1442 resultLen
= uloc_getName(testCases
[i
].localeID
, buffer
, 256, &status
);
1443 if (uprv_strcmp(testCases
[i
].expectedLocaleID
, buffer
) != 0) {
1444 log_err("Expected uloc_getName(\"%s\") => \"%s\"; got \"%s\"\n",
1445 testCases
[i
].localeID
, testCases
[i
].expectedLocaleID
, buffer
);
1447 resultLen
= uloc_canonicalize(testCases
[i
].localeID
, buffer
, 256, &status
);
1448 if (uprv_strcmp(testCases
[i
].expectedCanonicalID
, buffer
) != 0) {
1449 log_err("Expected uloc_canonicalize(\"%s\") => \"%s\"; got \"%s\"\n",
1450 testCases
[i
].localeID
, testCases
[i
].expectedCanonicalID
, buffer
);
1456 static void TestKeywordVariantParsing(void)
1459 const char *localeID
;
1460 const char *keyword
;
1461 const char *expectedValue
;
1463 { "de_DE@ C o ll A t i o n = Phonebook ", "c o ll a t i o n", "Phonebook" },
1464 { "de_DE", "collation", ""},
1465 { "de_DE@collation=PHONEBOOK", "collation", "PHONEBOOK" },
1466 { "de_DE@currency = euro; CoLLaTion = PHONEBOOk", "collatiON", "PHONEBOOk" },
1469 UErrorCode status
= U_ZERO_ERROR
;
1472 int32_t resultLen
= 0;
1475 for(i
= 0; i
< sizeof(testCases
)/sizeof(testCases
[0]); i
++) {
1477 resultLen
= uloc_getKeywordValue(testCases
[i
].localeID
, testCases
[i
].keyword
, buffer
, 256, &status
);
1478 if(uprv_strcmp(testCases
[i
].expectedValue
, buffer
) != 0) {
1479 log_err("Expected to extract \"%s\" from \"%s\" for keyword \"%s\". Got \"%s\" instead\n",
1480 testCases
[i
].expectedValue
, testCases
[i
].localeID
, testCases
[i
].keyword
, buffer
);
1486 const char *l
; /* locale */
1487 const char *k
; /* kw */
1488 const char *v
; /* value */
1489 const char *x
; /* expected */
1490 } kwSetTestCases
[] = {
1492 { "en_US", "calendar", "japanese", "en_US@calendar=japanese" },
1493 { "en_US@", "calendar", "japanese", "en_US@calendar=japanese" },
1494 { "en_US@calendar=islamic", "calendar", "japanese", "en_US@calendar=japanese" },
1495 { "en_US@calendar=slovakian", "calendar", "gregorian", "en_US@calendar=gregorian" }, /* don't know what this means, but it has the same # of chars as gregorian */
1496 { "en_US@calendar=gregorian", "calendar", "japanese", "en_US@calendar=japanese" },
1497 { "de", "Currency", "CHF", "de@currency=CHF" },
1498 { "de", "Currency", "CHF", "de@currency=CHF" },
1500 { "en_US@collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
1501 { "en_US@calendar=japanese", "collation", "phonebook", "en_US@calendar=japanese;collation=phonebook" },
1502 { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" },
1503 { "en_US@calendar=gregorian;collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
1504 { "en_US@calendar=slovakian;collation=phonebook", "calendar", "gregorian", "en_US@calendar=gregorian;collation=phonebook" }, /* don't know what this means, but it has the same # of chars as gregorian */
1505 { "en_US@calendar=slovakian;collation=videobook", "collation", "phonebook", "en_US@calendar=slovakian;collation=phonebook" }, /* don't know what this means, but it has the same # of chars as gregorian */
1506 { "en_US@calendar=islamic;collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
1507 { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" },
1510 { "mt@a=0;b=1;c=2;d=3", "c","j", "mt@a=0;b=1;c=j;d=3" },
1511 { "mt@a=0;b=1;c=2;d=3", "x","j", "mt@a=0;b=1;c=2;d=3;x=j" },
1512 { "mt@a=0;b=1;c=2;d=3", "a","f", "mt@a=f;b=1;c=2;d=3" },
1513 { "mt@a=0;aa=1;aaa=3", "a","x", "mt@a=x;aa=1;aaa=3" },
1514 { "mt@a=0;aa=1;aaa=3", "aa","x", "mt@a=0;aa=x;aaa=3" },
1515 { "mt@a=0;aa=1;aaa=3", "aaa","x", "mt@a=0;aa=1;aaa=x" },
1516 { "mt@a=0;aa=1;aaa=3", "a","yy", "mt@a=yy;aa=1;aaa=3" },
1517 { "mt@a=0;aa=1;aaa=3", "aa","yy", "mt@a=0;aa=yy;aaa=3" },
1518 { "mt@a=0;aa=1;aaa=3", "aaa","yy", "mt@a=0;aa=1;aaa=yy" },
1522 /* 1. removal of item at end */
1523 { "de@collation=phonebook;currency=CHF", "currency", "", "de@collation=phonebook" },
1524 { "de@collation=phonebook;currency=CHF", "currency", NULL
, "de@collation=phonebook" },
1525 /* 2. removal of item at beginning */
1526 { "de@collation=phonebook;currency=CHF", "collation", "", "de@currency=CHF" },
1527 { "de@collation=phonebook;currency=CHF", "collation", NULL
, "de@currency=CHF" },
1528 /* 3. removal of an item not there */
1529 { "de@collation=phonebook;currency=CHF", "calendar", NULL
, "de@collation=phonebook;currency=CHF" },
1530 /* 4. removal of only item */
1531 { "de@collation=phonebook", "collation", NULL
, "de" },
1533 { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" }
1537 static void TestKeywordSet(void)
1540 int32_t resultLen
= 0;
1545 for(i
= 0; i
< sizeof(kwSetTestCases
)/sizeof(kwSetTestCases
[0]); i
++) {
1546 UErrorCode status
= U_ZERO_ERROR
;
1547 memset(buffer
,'%',1023);
1548 strcpy(buffer
, kwSetTestCases
[i
].l
);
1550 uloc_canonicalize(kwSetTestCases
[i
].l
, cbuffer
, 1023, &status
);
1551 if(strcmp(buffer
,cbuffer
)) {
1552 log_verbose("note: [%d] wasn't canonical, should be: '%s' not '%s'. Won't check for canonicity in output.\n", i
, cbuffer
, buffer
);
1554 /* sanity check test case results for canonicity */
1555 uloc_canonicalize(kwSetTestCases
[i
].x
, cbuffer
, 1023, &status
);
1556 if(strcmp(kwSetTestCases
[i
].x
,cbuffer
)) {
1557 log_err("%s:%d: ERROR: kwSetTestCases[%d].x = '%s', should be %s (must be canonical)\n", __FILE__
, __LINE__
, i
, kwSetTestCases
[i
].x
, cbuffer
);
1560 resultLen
= uloc_setKeywordValue(kwSetTestCases
[i
].k
, kwSetTestCases
[i
].v
, buffer
, 1023, &status
);
1561 if(U_FAILURE(status
)) {
1562 log_err("Err on test case %d: got error %s\n", i
, u_errorName(status
));
1565 if(strcmp(buffer
,kwSetTestCases
[i
].x
) || ((int32_t)strlen(buffer
)!=resultLen
)) {
1566 log_err("FAIL: #%d: %s + [%s=%s] -> %s (%d) expected %s (%d)\n", i
, kwSetTestCases
[i
].l
, kwSetTestCases
[i
].k
,
1567 kwSetTestCases
[i
].v
, buffer
, resultLen
, kwSetTestCases
[i
].x
, strlen(buffer
));
1569 log_verbose("pass: #%d: %s + [%s=%s] -> %s\n", i
, kwSetTestCases
[i
].l
, kwSetTestCases
[i
].k
, kwSetTestCases
[i
].v
,buffer
);
1574 static void TestKeywordSetError(void)
1582 /* 0-test whether an error condition modifies the buffer at all */
1585 memset(buffer
,'%',1023);
1586 status
= U_ZERO_ERROR
;
1587 res
= uloc_setKeywordValue(kwSetTestCases
[i
].k
, kwSetTestCases
[i
].v
, buffer
, blen
, &status
);
1588 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
1589 log_err("expected illegal err got %s\n", u_errorName(status
));
1592 /* if(res!=strlen(kwSetTestCases[i].x)) {
1593 log_err("expected result %d got %d\n", strlen(kwSetTestCases[i].x), res);
1596 if(buffer
[blen
]!='%') {
1597 log_err("Buffer byte %d was modified: now %c\n", blen
, buffer
[blen
]);
1600 log_verbose("0-buffer modify OK\n");
1603 /* 1- test a short buffer with growing text */
1604 blen
=(int32_t)strlen(kwSetTestCases
[i
].l
)+1;
1605 memset(buffer
,'%',1023);
1606 strcpy(buffer
,kwSetTestCases
[i
].l
);
1607 status
= U_ZERO_ERROR
;
1608 res
= uloc_setKeywordValue(kwSetTestCases
[i
].k
, kwSetTestCases
[i
].v
, buffer
, blen
, &status
);
1609 if(status
!= U_BUFFER_OVERFLOW_ERROR
) {
1610 log_err("expected buffer overflow on buffer %d got %s, len %d (%s + [%s=%s])\n", blen
, u_errorName(status
), res
, kwSetTestCases
[i
].l
, kwSetTestCases
[i
].k
, kwSetTestCases
[i
].v
);
1613 if(res
!=(int32_t)strlen(kwSetTestCases
[i
].x
)) {
1614 log_err("expected result %d got %d\n", strlen(kwSetTestCases
[i
].x
), res
);
1617 if(buffer
[blen
]!='%') {
1618 log_err("Buffer byte %d was modified: now %c\n", blen
, buffer
[blen
]);
1621 log_verbose("1/%d-buffer modify OK\n",i
);
1625 /* 2- test a short buffer - text the same size or shrinking */
1626 blen
=(int32_t)strlen(kwSetTestCases
[i
].l
)+1;
1627 memset(buffer
,'%',1023);
1628 strcpy(buffer
,kwSetTestCases
[i
].l
);
1629 status
= U_ZERO_ERROR
;
1630 res
= uloc_setKeywordValue(kwSetTestCases
[i
].k
, kwSetTestCases
[i
].v
, buffer
, blen
, &status
);
1631 if(status
!= U_ZERO_ERROR
) {
1632 log_err("expected zero error got %s\n", u_errorName(status
));
1635 if(buffer
[blen
+1]!='%') {
1636 log_err("Buffer byte %d was modified: now %c\n", blen
+1, buffer
[blen
+1]);
1639 if(res
!=(int32_t)strlen(kwSetTestCases
[i
].x
)) {
1640 log_err("expected result %d got %d\n", strlen(kwSetTestCases
[i
].x
), res
);
1643 if(strcmp(buffer
,kwSetTestCases
[i
].x
) || ((int32_t)strlen(buffer
)!=res
)) {
1644 log_err("FAIL: #%d: %s + [%s=%s] -> %s (%d) expected %s (%d)\n", i
, kwSetTestCases
[i
].l
, kwSetTestCases
[i
].k
,
1645 kwSetTestCases
[i
].v
, buffer
, res
, kwSetTestCases
[i
].x
, strlen(buffer
));
1647 log_verbose("pass: #%d: %s + [%s=%s] -> %s\n", i
, kwSetTestCases
[i
].l
, kwSetTestCases
[i
].k
, kwSetTestCases
[i
].v
,
1650 log_verbose("2/%d-buffer modify OK\n",i
);
1654 static int32_t _canonicalize(int32_t selector
, /* 0==getName, 1==canonicalize */
1655 const char* localeID
,
1657 int32_t resultCapacity
,
1659 /* YOU can change this to use function pointers if you like */
1662 return uloc_getName(localeID
, result
, resultCapacity
, ec
);
1664 return uloc_canonicalize(localeID
, result
, resultCapacity
, ec
);
1670 static void TestCanonicalization(void)
1673 const char *localeID
; /* input */
1674 const char *getNameID
; /* expected getName() result */
1675 const char *canonicalID
; /* expected canonicalize() result */
1677 { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage",
1678 "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE",
1679 "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"},
1680 { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" },
1681 { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" },
1682 { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" },
1683 { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=LUF" },
1684 { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" },
1685 { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" },
1686 { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" },
1687 { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" },
1688 { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" },
1689 { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" },
1690 { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" },
1691 { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" },
1692 { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" },
1693 { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" },
1694 { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" },
1695 { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" },
1696 { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" },
1697 { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" },
1698 { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" },
1699 { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" },
1700 { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" },
1701 { "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */
1702 { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" },
1703 { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" },
1704 { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" },
1705 { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" },
1706 { "zh_TW_STROKE", "zh_TW_STROKE", "zh_Hant_TW@collation=stroke" },
1707 { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" },
1708 { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" },
1709 { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" },
1710 { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" },
1711 { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" },
1712 { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" },
1713 { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ },
1714 { "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */
1715 { "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */
1716 { "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */
1717 { "en-BOONT", "en_BOONT", "en__BOONT" }, /* registered name */
1718 { "de-1901", "de_1901", "de__1901" }, /* registered name */
1719 { "de-1906", "de_1906", "de__1906" }, /* registered name */
1720 { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_CS" }, /* .NET name */
1721 { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_CS" }, /* .NET name */
1722 { "sr_YU_CYRILLIC", "sr_YU_CYRILLIC", "sr_Cyrl_CS" }, /* Linux name */
1723 { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */
1724 { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */
1725 { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */
1726 { "zh-CHT", "zh_CHT", "zh_Hant" }, /* .NET name This may change back to zh_Hant */
1728 /* posix behavior that used to be performed by getName */
1729 { "mr.utf8", "mr.utf8", "mr" },
1730 { "de-tv.koi8r", "de_TV.koi8r", "de_TV" },
1731 { "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" },
1732 { "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" },
1733 { "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" },
1734 { "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 */
1736 /* fleshing out canonicalization */
1737 /* trim space and sort keywords, ';' is separator so not present at end in canonical form */
1738 { "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" },
1739 /* already-canonical ids are not changed */
1740 { "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" },
1741 /* PRE_EURO and EURO conversions don't affect other keywords */
1742 { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" },
1743 { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" },
1744 /* currency keyword overrides PRE_EURO and EURO currency */
1745 { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" },
1746 { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" },
1747 /* norwegian is just too weird, if we handle things in their full generality */
1748 { "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ },
1750 /* test cases reflecting internal resource bundle usage */
1751 { "root@kw=foo", "root@kw=foo", "root@kw=foo" },
1752 { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" },
1753 { "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese" },
1754 { "ja_JP", "ja_JP", "ja_JP" },
1756 /* test case for "i-default" */
1757 { "i-default", NULL
, NULL
}
1760 static const char* label
[] = { "getName", "canonicalize" };
1762 UErrorCode status
= U_ZERO_ERROR
;
1763 int32_t i
, j
, resultLen
= 0, origResultLen
;
1766 for (i
=0; i
< sizeof(testCases
)/sizeof(testCases
[0]); i
++) {
1767 for (j
=0; j
<2; ++j
) {
1768 const char* expected
= (j
==0) ? testCases
[i
].getNameID
: testCases
[i
].canonicalID
;
1770 status
= U_ZERO_ERROR
;
1772 if (expected
== NULL
) {
1773 expected
= uloc_getDefault();
1776 /* log_verbose("testing %s -> %s\n", testCases[i], testCases[i].canonicalID); */
1777 origResultLen
= _canonicalize(j
, testCases
[i
].localeID
, NULL
, 0, &status
);
1778 if (status
!= U_BUFFER_OVERFLOW_ERROR
) {
1779 log_err("FAIL: uloc_%s(%s) => %s, expected U_BUFFER_OVERFLOW_ERROR\n",
1780 label
[j
], testCases
[i
].localeID
, u_errorName(status
));
1783 status
= U_ZERO_ERROR
;
1784 resultLen
= _canonicalize(j
, testCases
[i
].localeID
, buffer
, sizeof(buffer
), &status
);
1785 if (U_FAILURE(status
)) {
1786 log_err("FAIL: uloc_%s(%s) => %s, expected U_ZERO_ERROR\n",
1787 label
[j
], testCases
[i
].localeID
, u_errorName(status
));
1790 if(uprv_strcmp(expected
, buffer
) != 0) {
1791 log_err("FAIL: uloc_%s(%s) => \"%s\", expected \"%s\"\n",
1792 label
[j
], testCases
[i
].localeID
, buffer
, expected
);
1794 log_verbose("Ok: uloc_%s(%s) => \"%s\"\n",
1795 label
[j
], testCases
[i
].localeID
, buffer
);
1797 if (resultLen
!= (int32_t)strlen(buffer
)) {
1798 log_err("FAIL: uloc_%s(%s) => len %d, expected len %d\n",
1799 label
[j
], testCases
[i
].localeID
, resultLen
, strlen(buffer
));
1801 if (origResultLen
!= resultLen
) {
1802 log_err("FAIL: uloc_%s(%s) => preflight len %d != actual len %d\n",
1803 label
[j
], testCases
[i
].localeID
, origResultLen
, resultLen
);
1809 static void TestDisplayKeywords(void)
1813 static const struct {
1814 const char *localeID
;
1815 const char *displayLocale
;
1816 UChar displayKeyword
[200];
1818 { "ca_ES@currency=ESP", "de_AT",
1819 {0x0057, 0x00e4, 0x0068, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000},
1821 { "ja_JP@calendar=japanese", "de",
1822 { 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000}
1824 { "de_DE@collation=traditional", "de_DE",
1825 {0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000}
1828 for(i
= 0; i
< sizeof(testCases
)/sizeof(testCases
[0]); i
++) {
1829 UErrorCode status
= U_ZERO_ERROR
;
1830 const char* keyword
=NULL
;
1831 int32_t keywordLen
= 0;
1832 int32_t keywordCount
= 0;
1833 UChar
*displayKeyword
=NULL
;
1834 int32_t displayKeywordLen
= 0;
1835 UEnumeration
* keywordEnum
= uloc_openKeywords(testCases
[i
].localeID
, &status
);
1836 for(keywordCount
= uenum_count(keywordEnum
, &status
); keywordCount
> 0 ; keywordCount
--){
1837 if(U_FAILURE(status
)){
1838 log_err("uloc_getKeywords failed for locale id: %s with error : %s \n", testCases
[i
].localeID
, u_errorName(status
));
1841 /* the uenum_next returns NUL terminated string */
1842 keyword
= uenum_next(keywordEnum
, &keywordLen
, &status
);
1843 /* fetch the displayKeyword */
1844 displayKeywordLen
= uloc_getDisplayKeyword(keyword
, testCases
[i
].displayLocale
, displayKeyword
, displayKeywordLen
, &status
);
1845 if(status
==U_BUFFER_OVERFLOW_ERROR
){
1846 status
= U_ZERO_ERROR
;
1847 displayKeywordLen
++; /* for null termination */
1848 displayKeyword
= (UChar
*) malloc(displayKeywordLen
* U_SIZEOF_UCHAR
);
1849 displayKeywordLen
= uloc_getDisplayKeyword(keyword
, testCases
[i
].displayLocale
, displayKeyword
, displayKeywordLen
, &status
);
1850 if(U_FAILURE(status
)){
1851 log_err("uloc_getDisplayKeyword filed for keyword : %s in locale id: %s for display locale: %s \n", testCases
[i
].localeID
, keyword
, testCases
[i
].displayLocale
, u_errorName(status
));
1854 if(u_strncmp(displayKeyword
, testCases
[i
].displayKeyword
, displayKeywordLen
)!=0){
1855 log_err("uloc_getDisplayKeyword did not get the expected value for keyword : %s in locale id: %s for display locale: %s \n", testCases
[i
].localeID
, keyword
, testCases
[i
].displayLocale
);
1859 log_err("uloc_getDisplayKeyword did not return the expected error. Error: %s\n", u_errorName(status
));
1862 free(displayKeyword
);
1865 uenum_close(keywordEnum
);
1869 static void TestDisplayKeywordValues(void){
1873 const char *localeID
;
1874 const char *displayLocale
;
1875 UChar displayKeywordValue
[500];
1877 { "ca_ES@currency=ESP", "de_AT",
1878 {0x0053, 0x0070, 0x0061, 0x006e, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0020, 0x0050, 0x0065, 0x0073, 0x0065, 0x0074, 0x0065, 0x0000}
1880 { "de_AT@currency=ATS", "fr_FR",
1881 {0x0073, 0x0063, 0x0068, 0x0069, 0x006c, 0x006c, 0x0069, 0x006e, 0x0067, 0x0020, 0x0061, 0x0075, 0x0074, 0x0072, 0x0069, 0x0063, 0x0068, 0x0069, 0x0065, 0x006e, 0x0000}
1883 { "de_DE@currency=DEM", "it",
1884 {0x004d, 0x0061, 0x0072, 0x0063, 0x006f, 0x0020, 0x0054, 0x0065, 0x0064, 0x0065, 0x0073, 0x0063, 0x006f, 0x0000}
1886 { "el_GR@currency=GRD", "en",
1887 {0x0047, 0x0072, 0x0065, 0x0065, 0x006b, 0x0020, 0x0044, 0x0072, 0x0061, 0x0063, 0x0068, 0x006d, 0x0061, 0x0000}
1889 { "eu_ES@currency=ESP", "it_IT",
1890 {0x0050, 0x0065, 0x0073, 0x0065, 0x0074, 0x0061, 0x0020, 0x0053, 0x0070, 0x0061, 0x0067, 0x006e, 0x006f, 0x006c, 0x0061, 0x0000}
1892 { "de@collation=phonebook", "es",
1893 {0x006F, 0x0072, 0x0064, 0x0065, 0x006E, 0x0020, 0x0064, 0x0065, 0x0020, 0x006C, 0x0069, 0x0073, 0x0074, 0x00ED, 0x006E, 0x0020, 0x0074, 0x0065, 0x006C, 0x0065, 0x0066, 0x00F3, 0x006E, 0x0069, 0x0063, 0x006F, 0x0000}
1896 { "de_DE@collation=phonebook", "es",
1897 {0x006F, 0x0072, 0x0064, 0x0065, 0x006E, 0x0020, 0x0064, 0x0065, 0x0020, 0x006C, 0x0069, 0x0073, 0x0074, 0x00ED, 0x006E, 0x0020, 0x0074, 0x0065, 0x006C, 0x0065, 0x0066, 0x00F3, 0x006E, 0x0069, 0x0063, 0x006F, 0x0000}
1899 { "es_ES@collation=traditional","de",
1900 {0x0054, 0x0072, 0x0061, 0x0064, 0x0069, 0x0074, 0x0069, 0x006f, 0x006e, 0x0065, 0x006c, 0x006c, 0x0065, 0x0020, 0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0072, 0x0065, 0x0067, 0x0065, 0x006c, 0x006e, 0x0000}
1902 { "ja_JP@calendar=japanese", "de",
1903 {0x004a, 0x0061, 0x0070, 0x0061, 0x006e, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0072, 0x0020, 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000}
1906 for(i
= 0; i
< sizeof(testCases
)/sizeof(testCases
[0]); i
++) {
1907 UErrorCode status
= U_ZERO_ERROR
;
1908 const char* keyword
=NULL
;
1909 int32_t keywordLen
= 0;
1910 int32_t keywordCount
= 0;
1911 UChar
*displayKeywordValue
= NULL
;
1912 int32_t displayKeywordValueLen
= 0;
1913 UEnumeration
* keywordEnum
= uloc_openKeywords(testCases
[i
].localeID
, &status
);
1914 for(keywordCount
= uenum_count(keywordEnum
, &status
); keywordCount
> 0 ; keywordCount
--){
1915 if(U_FAILURE(status
)){
1916 log_err("uloc_getKeywords failed for locale id: %s in display locale: % with error : %s \n", testCases
[i
].localeID
, testCases
[i
].displayLocale
, u_errorName(status
));
1919 /* the uenum_next returns NUL terminated string */
1920 keyword
= uenum_next(keywordEnum
, &keywordLen
, &status
);
1922 /* fetch the displayKeywordValue */
1923 displayKeywordValueLen
= uloc_getDisplayKeywordValue(testCases
[i
].localeID
, keyword
, testCases
[i
].displayLocale
, displayKeywordValue
, displayKeywordValueLen
, &status
);
1924 if(status
==U_BUFFER_OVERFLOW_ERROR
){
1925 status
= U_ZERO_ERROR
;
1926 displayKeywordValueLen
++; /* for null termination */
1927 displayKeywordValue
= (UChar
*)malloc(displayKeywordValueLen
* U_SIZEOF_UCHAR
);
1928 displayKeywordValueLen
= uloc_getDisplayKeywordValue(testCases
[i
].localeID
, keyword
, testCases
[i
].displayLocale
, displayKeywordValue
, displayKeywordValueLen
, &status
);
1929 if(U_FAILURE(status
)){
1930 log_err("uloc_getDisplayKeywordValue failed for keyword : %s in locale id: %s for display locale: %s with error : %s \n", testCases
[i
].localeID
, keyword
, testCases
[i
].displayLocale
, u_errorName(status
));
1933 if(u_strncmp(displayKeywordValue
, testCases
[i
].displayKeywordValue
, displayKeywordValueLen
)!=0){
1934 log_err("uloc_getDisplayKeywordValue did not return the expected value keyword : %s in locale id: %s for display locale: %s with error : %s \n", testCases
[i
].localeID
, keyword
, testCases
[i
].displayLocale
, u_errorName(status
));
1938 log_err("uloc_getDisplayKeywordValue did not return the expected error. Error: %s\n", u_errorName(status
));
1940 free(displayKeywordValue
);
1942 uenum_close(keywordEnum
);
1945 /* test a multiple keywords */
1946 UErrorCode status
= U_ZERO_ERROR
;
1947 const char* keyword
=NULL
;
1948 int32_t keywordLen
= 0;
1949 int32_t keywordCount
= 0;
1950 const char* localeID
= "es@collation=phonebook;calendar=buddhist;currency=DEM";
1951 const char* displayLocale
= "de";
1952 const UChar expected
[][50] = {
1953 {0x0042, 0x0075, 0x0064, 0x0064, 0x0068, 0x0069, 0x0073, 0x0074, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0072, 0x0020, 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000},
1955 {0x0054, 0x0065, 0x006c, 0x0065, 0x0066, 0x006f, 0x006e, 0x0062, 0x0075, 0x0063, 0x0068, 0x002d, 0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0072, 0x0065, 0x0067, 0x0065, 0x006c, 0x006e, 0x0000},
1956 {0x0044, 0x0065, 0x0075, 0x0074, 0x0073, 0x0063, 0x0068, 0x0065, 0x0020, 0x004d, 0x0061, 0x0072, 0x006b, 0x0000},
1959 UEnumeration
* keywordEnum
= uloc_openKeywords(localeID
, &status
);
1961 for(keywordCount
= 0; keywordCount
< uenum_count(keywordEnum
, &status
) ; keywordCount
++){
1962 UChar
*displayKeywordValue
= NULL
;
1963 int32_t displayKeywordValueLen
= 0;
1964 if(U_FAILURE(status
)){
1965 log_err("uloc_getKeywords failed for locale id: %s in display locale: % with error : %s \n", localeID
, displayLocale
, u_errorName(status
));
1968 /* the uenum_next returns NUL terminated string */
1969 keyword
= uenum_next(keywordEnum
, &keywordLen
, &status
);
1971 /* fetch the displayKeywordValue */
1972 displayKeywordValueLen
= uloc_getDisplayKeywordValue(localeID
, keyword
, displayLocale
, displayKeywordValue
, displayKeywordValueLen
, &status
);
1973 if(status
==U_BUFFER_OVERFLOW_ERROR
){
1974 status
= U_ZERO_ERROR
;
1975 displayKeywordValueLen
++; /* for null termination */
1976 displayKeywordValue
= (UChar
*)malloc(displayKeywordValueLen
* U_SIZEOF_UCHAR
);
1977 displayKeywordValueLen
= uloc_getDisplayKeywordValue(localeID
, keyword
, displayLocale
, displayKeywordValue
, displayKeywordValueLen
, &status
);
1978 if(U_FAILURE(status
)){
1979 log_err("uloc_getDisplayKeywordValue failed for keyword : %s in locale id: %s for display locale: %s with error : %s \n", localeID
, keyword
, displayLocale
, u_errorName(status
));
1982 if(u_strncmp(displayKeywordValue
, expected
[keywordCount
], displayKeywordValueLen
)!=0){
1983 log_err("uloc_getDisplayKeywordValue did not return the expected value keyword : %s in locale id: %s for display locale: %s \n", localeID
, keyword
, displayLocale
);
1987 log_err("uloc_getDisplayKeywordValue did not return the expected error. Error: %s\n", u_errorName(status
));
1989 free(displayKeywordValue
);
1991 uenum_close(keywordEnum
);
1995 /* Test non existent keywords */
1996 UErrorCode status
= U_ZERO_ERROR
;
1997 const char* localeID
= "es";
1998 const char* displayLocale
= "de";
1999 UChar
*displayKeywordValue
= NULL
;
2000 int32_t displayKeywordValueLen
= 0;
2002 /* fetch the displayKeywordValue */
2003 displayKeywordValueLen
= uloc_getDisplayKeywordValue(localeID
, "calendar", displayLocale
, displayKeywordValue
, displayKeywordValueLen
, &status
);
2004 if(U_FAILURE(status
)) {
2005 log_err("uloc_getDisplaykeywordValue returned error status %s\n", u_errorName(status
));
2006 } else if(displayKeywordValueLen
!= 0) {
2007 log_err("uloc_getDisplaykeywordValue returned %d should be 0 \n", displayKeywordValueLen
);
2013 static void TestGetBaseName(void) {
2015 const char *localeID
;
2016 const char *baseName
;
2018 { "de_DE@ C o ll A t i o n = Phonebook ", "de_DE" },
2019 { "de@currency = euro; CoLLaTion = PHONEBOOk", "de" },
2020 { "ja@calendar = buddhist", "ja" }
2023 int32_t i
= 0, baseNameLen
= 0;
2025 UErrorCode status
= U_ZERO_ERROR
;
2027 for(i
= 0; i
< sizeof(testCases
)/sizeof(testCases
[0]); i
++) {
2028 baseNameLen
= uloc_getBaseName(testCases
[i
].localeID
, baseName
, 256, &status
);
2029 if(strcmp(testCases
[i
].baseName
, baseName
)) {
2030 log_err("For locale \"%s\" expected baseName \"%s\", but got \"%s\"\n",
2031 testCases
[i
].localeID
, testCases
[i
].baseName
, baseName
);
2039 /* Jitterbug 4115 */
2040 static void TestDisplayNameWarning(void) {
2043 UErrorCode status
= U_ZERO_ERROR
;
2045 size
= uloc_getDisplayLanguage("qqq", "kl", name
, sizeof(name
)/sizeof(name
[0]), &status
);
2046 if (status
!= U_USING_DEFAULT_WARNING
) {
2047 log_err("For language \"qqq\" in locale \"kl\", expecting U_USING_DEFAULT_WARNING, but got %s\n",
2048 u_errorName(status
));
2054 * Compare two locale IDs. If they are equal, return 0. If `string'
2055 * starts with `prefix' plus an additional element, that is, string ==
2056 * prefix + '_' + x, then return 1. Otherwise return a value < 0.
2058 static UBool
_loccmp(const char* string
, const char* prefix
) {
2059 int32_t slen
= (int32_t)uprv_strlen(string
),
2060 plen
= (int32_t)uprv_strlen(prefix
);
2061 int32_t c
= uprv_strncmp(string
, prefix
, plen
);
2062 /* 'root' is less than everything */
2063 if (uprv_strcmp(prefix
, "root") == 0) {
2064 return (uprv_strcmp(string
, "root") == 0) ? 0 : 1;
2066 if (c
) return -1; /* mismatch */
2067 if (slen
== plen
) return 0;
2068 if (string
[plen
] == '_') return 1;
2069 return -2; /* false match, e.g. "en_USX" cmp "en_US" */
2072 static void _checklocs(const char* label
,
2075 const char* actual
) {
2076 /* We want the valid to be strictly > the bogus requested locale,
2077 and the valid to be >= the actual. */
2078 if (_loccmp(req
, valid
) > 0 &&
2079 _loccmp(valid
, actual
) >= 0) {
2080 log_verbose("%s; req=%s, valid=%s, actual=%s\n",
2081 label
, req
, valid
, actual
);
2083 log_err("FAIL: %s; req=%s, valid=%s, actual=%s\n",
2084 label
, req
, valid
, actual
);
2088 static void TestGetLocale(void) {
2089 UErrorCode ec
= U_ZERO_ERROR
;
2091 UChar EMPTY
[1] = {0};
2094 #if !UCONFIG_NO_FORMATTING
2097 const char *req
= "en_US_REDWOODSHORES", *valid
, *actual
;
2098 obj
= udat_open(UDAT_DEFAULT
, UDAT_DEFAULT
,
2102 if (U_FAILURE(ec
)) {
2103 log_err("udat_open failed.Error %s\n", u_errorName(ec
));
2106 valid
= udat_getLocaleByType(obj
, ULOC_VALID_LOCALE
, &ec
);
2107 actual
= udat_getLocaleByType(obj
, ULOC_ACTUAL_LOCALE
, &ec
);
2108 if (U_FAILURE(ec
)) {
2109 log_err("udat_getLocaleByType() failed\n");
2112 _checklocs("udat", req
, valid
, actual
);
2118 #if !UCONFIG_NO_FORMATTING
2121 const char *req
= "fr_FR_PROVENCAL", *valid
, *actual
;
2122 obj
= ucal_open(NULL
, 0,
2126 if (U_FAILURE(ec
)) {
2127 log_err("ucal_open failed with error: %s\n", u_errorName(ec
));
2130 valid
= ucal_getLocaleByType(obj
, ULOC_VALID_LOCALE
, &ec
);
2131 actual
= ucal_getLocaleByType(obj
, ULOC_ACTUAL_LOCALE
, &ec
);
2132 if (U_FAILURE(ec
)) {
2133 log_err("ucal_getLocaleByType() failed\n");
2136 _checklocs("ucal", req
, valid
, actual
);
2142 #if !UCONFIG_NO_FORMATTING
2145 const char *req
= "zh_Hant_TW_TAINAN", *valid
, *actual
;
2146 obj
= unum_open(UNUM_DECIMAL
,
2150 if (U_FAILURE(ec
)) {
2151 log_err("unum_open failed\n");
2154 valid
= unum_getLocaleByType(obj
, ULOC_VALID_LOCALE
, &ec
);
2155 actual
= unum_getLocaleByType(obj
, ULOC_ACTUAL_LOCALE
, &ec
);
2156 if (U_FAILURE(ec
)) {
2157 log_err("unum_getLocaleByType() failed\n");
2160 _checklocs("unum", req
, valid
, actual
);
2167 /* commented out by weiv 01/12/2005. umsg_getLocaleByType is to be removed */
2168 #if !UCONFIG_NO_FORMATTING
2170 UMessageFormat
*obj
;
2171 const char *req
= "ja_JP_TAKAYAMA", *valid
, *actual
;
2173 obj
= umsg_open(EMPTY
, 0,
2176 if (U_FAILURE(ec
)) {
2177 log_err("umsg_open failed\n");
2180 valid
= umsg_getLocaleByType(obj
, ULOC_VALID_LOCALE
, &ec
);
2181 actual
= umsg_getLocaleByType(obj
, ULOC_ACTUAL_LOCALE
, &ec
);
2182 if (U_FAILURE(ec
)) {
2183 log_err("umsg_getLocaleByType() failed\n");
2186 /* We want the valid to be strictly > the bogus requested locale,
2187 and the valid to be >= the actual. */
2188 /* TODO MessageFormat is currently just storing the locale it is given.
2189 As a result, it will return whatever it was given, even if the
2190 locale is invalid. */
2191 test
= (_cmpversion("3.2") <= 0) ?
2192 /* Here is the weakened test for 3.0: */
2193 (_loccmp(req
, valid
) >= 0) :
2194 /* Here is what the test line SHOULD be: */
2195 (_loccmp(req
, valid
) > 0);
2198 _loccmp(valid
, actual
) >= 0) {
2199 log_verbose("umsg; req=%s, valid=%s, actual=%s\n", req
, valid
, actual
);
2201 log_err("FAIL: umsg; req=%s, valid=%s, actual=%s\n", req
, valid
, actual
);
2209 #if !UCONFIG_NO_BREAK_ITERATION
2211 UBreakIterator
*obj
;
2212 const char *req
= "ar_KW_ABDALI", *valid
, *actual
;
2213 obj
= ubrk_open(UBRK_WORD
,
2218 if (U_FAILURE(ec
)) {
2219 log_err("ubrk_open failed. Error: %s \n", u_errorName(ec
));
2222 valid
= ubrk_getLocaleByType(obj
, ULOC_VALID_LOCALE
, &ec
);
2223 actual
= ubrk_getLocaleByType(obj
, ULOC_ACTUAL_LOCALE
, &ec
);
2224 if (U_FAILURE(ec
)) {
2225 log_err("ubrk_getLocaleByType() failed\n");
2228 _checklocs("ubrk", req
, valid
, actual
);
2234 #if !UCONFIG_NO_COLLATION
2237 const char *req
= "es_AR_BUENOSAIRES", *valid
, *actual
;
2238 obj
= ucol_open(req
, &ec
);
2239 if (U_FAILURE(ec
)) {
2240 log_err("ucol_open failed\n");
2243 valid
= ucol_getLocaleByType(obj
, ULOC_VALID_LOCALE
, &ec
);
2244 actual
= ucol_getLocaleByType(obj
, ULOC_ACTUAL_LOCALE
, &ec
);
2245 if (U_FAILURE(ec
)) {
2246 log_err("ucol_getLocaleByType() failed\n");
2249 _checklocs("ucol", req
, valid
, actual
);
2255 static void TestNonexistentLanguageExemplars(void) {
2256 /* JB 4068 - Nonexistent language */
2257 UErrorCode ec
= U_ZERO_ERROR
;
2258 ULocaleData
*uld
= ulocdata_open("qqq",&ec
);
2259 if (ec
!= U_USING_DEFAULT_WARNING
) {
2260 log_err("Exemplar set for \"qqq\", expecting U_USING_DEFAULT_WARNING, but got %s\n",
2263 uset_close(ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &ec
));
2264 ulocdata_close(uld
);
2267 static void TestLanguageExemplarsFallbacks(void) {
2268 /* Test that en_US fallsback, but en doesn't fallback. */
2269 UErrorCode ec
= U_ZERO_ERROR
;
2270 ULocaleData
*uld
= ulocdata_open("en_US",&ec
);
2271 uset_close(ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &ec
));
2272 if (ec
!= U_USING_FALLBACK_WARNING
) {
2273 log_err("Exemplar set for \"en_US\", expecting U_USING_FALLBACK_WARNING, but got %s\n",
2276 ulocdata_close(uld
);
2278 uld
= ulocdata_open("en",&ec
);
2279 uset_close(ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &ec
));
2280 if (ec
!= U_ZERO_ERROR
) {
2281 log_err("Exemplar set for \"en\", expecting U_ZERO_ERROR, but got %s\n",
2284 ulocdata_close(uld
);
2287 static void TestAcceptLanguage(void) {
2288 UErrorCode status
= U_ZERO_ERROR
;
2289 UAcceptResult outResult
;
2290 UEnumeration
*available
;
2301 /*0*/{ 0, NULL
, "mt_MT", ULOC_ACCEPT_VALID
},
2302 /*1*/{ 1, NULL
, "en", ULOC_ACCEPT_VALID
},
2303 /*2*/{ 2, NULL
, "en", ULOC_ACCEPT_FALLBACK
},
2304 /*3*/{ 3, NULL
, "", ULOC_ACCEPT_FAILED
},
2305 /*4*/{ 4, NULL
, "es", ULOC_ACCEPT_VALID
},
2307 const int32_t numTests
= sizeof(tests
)/sizeof(tests
[0]);
2308 const char *http
[] = { /*0*/ "mt-mt, ja;q=0.76, en-us;q=0.95, en;q=0.92, en-gb;q=0.89, fr;q=0.87, iu-ca;q=0.84, iu;q=0.82, ja-jp;q=0.79, mt;q=0.97, de-de;q=0.74, de;q=0.71, es;q=0.68, it-it;q=0.66, it;q=0.63, vi-vn;q=0.61, vi;q=0.58, nl-nl;q=0.55, nl;q=0.53, th-th-traditional;q=.01",
2309 /*1*/ "ja;q=0.5, en;q=0.8, tlh",
2310 /*2*/ "en-wf, de-lx;q=0.8",
2311 /*3*/ "mga-ie;q=0.9, tlh",
2312 /*4*/ "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2313 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2314 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2315 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2316 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2317 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2318 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2319 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2320 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2321 "xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, xxx-yyy;q=.01, "
2325 for(i
=0;i
<numTests
;i
++) {
2327 status
=U_ZERO_ERROR
;
2328 log_verbose("test #%d: http[%s], ICU[%s], expect %s, %d\n",
2329 i
, http
[tests
[i
].httpSet
], tests
[i
].icuSet
, tests
[i
].expect
, tests
[i
].res
);
2331 available
= ures_openAvailableLocales(tests
[i
].icuSet
, &status
);
2333 rc
= uloc_acceptLanguageFromHTTP(tmp
, 199, &outResult
, http
[tests
[i
].httpSet
], available
, &status
);
2334 uenum_close(available
);
2335 log_verbose(" got %s, %d [%s]\n", tmp
[0]?tmp
:"(EMPTY)", outResult
, u_errorName(status
));
2336 if(outResult
!= tests
[i
].res
) {
2337 log_err("FAIL: #%d: expected outResult of %d but got %d\n", i
, tests
[i
].res
, outResult
);
2338 log_info("test #%d: http[%s], ICU[%s], expect %s, %d\n",
2339 i
, http
[tests
[i
].httpSet
], tests
[i
].icuSet
, tests
[i
].expect
, tests
[i
].res
);
2341 if((outResult
>0)&&uprv_strcmp(tmp
, tests
[i
].expect
)) {
2342 log_err("FAIL: #%d: expected %s but got %s\n", i
, tests
[i
].expect
, tmp
);
2343 log_info("test #%d: http[%s], ICU[%s], expect %s, %d\n",
2344 i
, http
[tests
[i
].httpSet
], tests
[i
].icuSet
, tests
[i
].expect
, tests
[i
].res
);
2349 static const char* LOCALE_ALIAS
[][2] = {
2363 static UBool
isLocaleAvailable(UResourceBundle
* resIndex
, const char* loc
){
2364 UErrorCode status
= U_ZERO_ERROR
;
2366 ures_getStringByKey(resIndex
, loc
,&len
, &status
);
2367 if(U_FAILURE(status
)){
2373 static void TestCalendar() {
2374 #if !UCONFIG_NO_FORMATTING
2376 UErrorCode status
= U_ZERO_ERROR
;
2377 UResourceBundle
*resIndex
= ures_open(NULL
,"res_index", &status
);
2378 if(U_FAILURE(status
)){
2379 log_err("Could not open res_index.res. Exiting. Error: %s\n", u_errorName(status
));
2382 for (i
=0; i
<LENGTHOF(LOCALE_ALIAS
); i
++) {
2383 const char* oldLoc
= LOCALE_ALIAS
[i
][0];
2384 const char* newLoc
= LOCALE_ALIAS
[i
][1];
2385 UCalendar
* c1
= NULL
;
2386 UCalendar
* c2
= NULL
;
2388 /*Test function "getLocale(ULocale.VALID_LOCALE)"*/
2389 const char* l1
= ucal_getLocaleByType(c1
, ULOC_VALID_LOCALE
, &status
);
2390 const char* l2
= ucal_getLocaleByType(c2
, ULOC_VALID_LOCALE
, &status
);
2392 if(!isLocaleAvailable(resIndex
, newLoc
)){
2395 c1
= ucal_open(NULL
, -1, oldLoc
, UCAL_GREGORIAN
, &status
);
2396 c2
= ucal_open(NULL
, -1, newLoc
, UCAL_GREGORIAN
, &status
);
2398 if (strcmp(newLoc
,l1
)!=0 || strcmp(l1
,l2
)!=0 || status
!=U_ZERO_ERROR
) {
2399 log_err("The locales are not equal!.Old: %s, New: %s \n", oldLoc
, newLoc
);
2401 log_verbose("ucal_getLocaleByType old:%s new:%s\n", l1
, l2
);
2405 ures_close(resIndex
);
2409 static void TestDateFormat() {
2410 #if !UCONFIG_NO_FORMATTING
2412 UErrorCode status
= U_ZERO_ERROR
;
2413 UResourceBundle
*resIndex
= ures_open(NULL
,"res_index", &status
);
2414 if(U_FAILURE(status
)){
2415 log_err("Could not open res_index.res. Exiting. Error: %s\n", u_errorName(status
));
2418 for (i
=0; i
<LENGTHOF(LOCALE_ALIAS
); i
++) {
2419 const char* oldLoc
= LOCALE_ALIAS
[i
][0];
2420 const char* newLoc
= LOCALE_ALIAS
[i
][1];
2421 UDateFormat
* df1
= NULL
;
2422 UDateFormat
* df2
= NULL
;
2423 const char* l1
= NULL
;
2424 const char* l2
= NULL
;
2426 if(!isLocaleAvailable(resIndex
, newLoc
)){
2429 df1
= udat_open(UDAT_FULL
, UDAT_FULL
,oldLoc
, NULL
, 0, NULL
, -1, &status
);
2430 df2
= udat_open(UDAT_FULL
, UDAT_FULL
,newLoc
, NULL
, 0, NULL
, -1, &status
);
2431 if(U_FAILURE(status
)){
2432 log_err("Creation of date format failed %s\n", u_errorName(status
));
2435 /*Test function "getLocale"*/
2436 l1
= udat_getLocaleByType(df1
, ULOC_VALID_LOCALE
, &status
);
2437 l2
= udat_getLocaleByType(df2
, ULOC_VALID_LOCALE
, &status
);
2438 if(U_FAILURE(status
)){
2439 log_err("Fetching the locale by type failed. %s\n", u_errorName(status
));
2441 if (strcmp(newLoc
,l1
)!=0 || strcmp(l1
,l2
)!=0) {
2442 log_err("The locales are not equal!.Old: %s, New: %s \n", oldLoc
, newLoc
);
2444 log_verbose("udat_getLocaleByType old:%s new:%s\n", l1
, l2
);
2448 ures_close(resIndex
);
2452 static void TestCollation() {
2453 #if !UCONFIG_NO_COLLATION
2455 UErrorCode status
= U_ZERO_ERROR
;
2456 UResourceBundle
*resIndex
= ures_open(NULL
,"res_index", &status
);
2457 if(U_FAILURE(status
)){
2458 log_err("Could not open res_index.res. Exiting. Error: %s\n", u_errorName(status
));
2461 for (i
=0; i
<LENGTHOF(LOCALE_ALIAS
); i
++) {
2462 const char* oldLoc
= LOCALE_ALIAS
[i
][0];
2463 const char* newLoc
= LOCALE_ALIAS
[i
][1];
2464 UCollator
* c1
= NULL
;
2465 UCollator
* c2
= NULL
;
2466 const char* l1
= NULL
;
2467 const char* l2
= NULL
;
2469 status
= U_ZERO_ERROR
;
2470 if(!isLocaleAvailable(resIndex
, newLoc
)){
2473 if(U_FAILURE(status
)){
2474 log_err("Creation of collators failed %s\n", u_errorName(status
));
2477 c1
= ucol_open(oldLoc
, &status
);
2478 c2
= ucol_open(newLoc
, &status
);
2479 l1
= ucol_getLocaleByType(c1
, ULOC_VALID_LOCALE
, &status
);
2480 l2
= ucol_getLocaleByType(c2
, ULOC_VALID_LOCALE
, &status
);
2481 if(U_FAILURE(status
)){
2482 log_err("Fetching the locale names failed failed %s\n", u_errorName(status
));
2484 if (strcmp(newLoc
,l1
)!=0 || strcmp(l1
,l2
)!=0) {
2485 log_err("The locales are not equal!.Old: %s, New: %s \n", oldLoc
, newLoc
);
2487 log_verbose("ucol_getLocaleByType old:%s new:%s\n", l1
, l2
);
2491 ures_close(resIndex
);
2495 static void TestULocale() {
2497 UErrorCode status
= U_ZERO_ERROR
;
2498 UResourceBundle
*resIndex
= ures_open(NULL
,"res_index", &status
);
2499 if(U_FAILURE(status
)){
2500 log_err("Could not open res_index.res. Exiting. Error: %s\n", u_errorName(status
));
2503 for (i
=0; i
<LENGTHOF(LOCALE_ALIAS
); i
++) {
2504 const char* oldLoc
= LOCALE_ALIAS
[i
][0];
2505 const char* newLoc
= LOCALE_ALIAS
[i
][1];
2506 UChar name1
[256], name2
[256];
2507 char names1
[256], names2
[256];
2508 int32_t capacity
= 256;
2510 status
= U_ZERO_ERROR
;
2511 if(!isLocaleAvailable(resIndex
, newLoc
)){
2514 uloc_getDisplayName(oldLoc
, ULOC_US
, name1
, capacity
, &status
);
2515 if(U_FAILURE(status
)){
2516 log_err("uloc_getDisplayName(%s) failed %s\n", oldLoc
, u_errorName(status
));
2519 uloc_getDisplayName(newLoc
, ULOC_US
, name2
, capacity
, &status
);
2520 if(U_FAILURE(status
)){
2521 log_err("uloc_getDisplayName(%s) failed %s\n", newLoc
, u_errorName(status
));
2524 if (u_strcmp(name1
, name2
)!=0) {
2525 log_err("The locales are not equal!.Old: %s, New: %s \n", oldLoc
, newLoc
);
2527 u_austrcpy(names1
, name1
);
2528 u_austrcpy(names2
, name2
);
2529 log_verbose("uloc_getDisplayName old:%s new:%s\n", names1
, names2
);
2531 ures_close(resIndex
);
2535 static void TestUResourceBundle() {
2539 UResourceBundle
* rb1
= NULL
;
2540 UResourceBundle
* rb2
= NULL
;
2541 UErrorCode status
= U_ZERO_ERROR
;
2543 UResourceBundle
*resIndex
= NULL
;
2544 if(U_FAILURE(status
)){
2545 log_err("Could not open res_index.res. Exiting. Error: %s\n", u_errorName(status
));
2548 resIndex
= ures_open(NULL
,"res_index", &status
);
2549 for (i
=0; i
<LENGTHOF(LOCALE_ALIAS
); i
++) {
2551 const char* oldLoc
= LOCALE_ALIAS
[i
][0];
2552 const char* newLoc
= LOCALE_ALIAS
[i
][1];
2553 if(!isLocaleAvailable(resIndex
, newLoc
)){
2556 rb1
= ures_open(NULL
, oldLoc
, &status
);
2557 if (U_FAILURE(U_ZERO_ERROR
)) {
2558 log_err("ures_open(%s) failed %s\n", oldLoc
, u_errorName(status
));
2561 us1
= ures_getLocale(rb1
, &status
);
2563 status
= U_ZERO_ERROR
;
2564 rb2
= ures_open(NULL
, newLoc
, &status
);
2565 if (U_FAILURE(U_ZERO_ERROR
)) {
2566 log_err("ures_open(%s) failed %s\n", oldLoc
, u_errorName(status
));
2568 us2
= ures_getLocale(rb2
, &status
);
2570 if (strcmp(us1
,newLoc
)!=0 || strcmp(us1
,us2
)!=0 ) {
2571 log_err("The locales are not equal!.Old: %s, New: %s \n", oldLoc
, newLoc
);
2574 log_verbose("ures_getStringByKey old:%s new:%s\n", us1
, us2
);
2580 ures_close(resIndex
);
2583 static void TestDisplayName() {
2585 UChar oldCountry
[256] = {'\0'};
2586 UChar newCountry
[256] = {'\0'};
2587 UChar oldLang
[256] = {'\0'};
2588 UChar newLang
[256] = {'\0'};
2589 char country
[256] ={'\0'};
2590 char language
[256] ={'\0'};
2591 int32_t capacity
= 256;
2594 for (i
=0; i
<LENGTHOF(LOCALE_ALIAS
); i
++) {
2595 const char* oldLoc
= LOCALE_ALIAS
[i
][0];
2596 const char* newLoc
= LOCALE_ALIAS
[i
][1];
2597 UErrorCode status
= U_ZERO_ERROR
;
2598 int32_t available
= uloc_countAvailable();
2600 for(j
=0; j
<available
; j
++){
2602 const char* dispLoc
= uloc_getAvailable(j
);
2603 int32_t oldCountryLen
= uloc_getDisplayCountry(oldLoc
,dispLoc
, oldCountry
, capacity
, &status
);
2604 int32_t newCountryLen
= uloc_getDisplayCountry(newLoc
, dispLoc
, newCountry
, capacity
, &status
);
2605 int32_t oldLangLen
= uloc_getDisplayLanguage(oldLoc
, dispLoc
, oldLang
, capacity
, &status
);
2606 int32_t newLangLen
= uloc_getDisplayLanguage(newLoc
, dispLoc
, newLang
, capacity
, &status
);
2608 int32_t countryLen
= uloc_getCountry(newLoc
, country
, capacity
, &status
);
2609 int32_t langLen
= uloc_getLanguage(newLoc
, language
, capacity
, &status
);
2610 /* there is a display name for the current country ID */
2611 if(countryLen
!= newCountryLen
){
2612 if(u_strncmp(oldCountry
,newCountry
,oldCountryLen
)!=0){
2613 log_err("uloc_getDisplayCountry() failed for %s in display locale %s \n", oldLoc
, dispLoc
);
2616 /* there is a display name for the current lang ID */
2617 if(langLen
!=newLangLen
){
2618 if(u_strncmp(oldLang
,newLang
,oldLangLen
)){
2619 log_err("uloc_getDisplayLanguage() failed for %s in display locale %s \n", oldLoc
, dispLoc
); }
2625 static void TestGetLocaleForLCID() {
2626 int32_t i
, length
, lengthPre
;
2627 const char* testLocale
= 0;
2628 UErrorCode status
= U_ZERO_ERROR
;
2630 char temp2
[40], temp3
[40];
2633 lcid
= uloc_getLCID("en_US");
2634 if (lcid
!= 0x0409) {
2635 log_err(" uloc_getLCID(\"en_US\") = %d, expected 0x0409\n", lcid
);
2638 lengthPre
= uloc_getLocaleForLCID(lcid
, temp2
, 4, &status
);
2639 if (status
!= U_BUFFER_OVERFLOW_ERROR
) {
2640 log_err(" unexpected result from uloc_getLocaleForLCID with small buffer: %s\n", u_errorName(status
));
2643 status
= U_ZERO_ERROR
;
2646 length
= uloc_getLocaleForLCID(lcid
, temp2
, sizeof(temp2
)/sizeof(char), &status
);
2647 if (U_FAILURE(status
)) {
2648 log_err(" unexpected result from uloc_getLocaleForLCID(0x0409): %s\n", u_errorName(status
));
2649 status
= U_ZERO_ERROR
;
2652 if (length
!= lengthPre
) {
2653 log_err(" uloc_getLocaleForLCID(0x0409): returned length %d does not match preflight length %d\n", length
, lengthPre
);
2656 length
= uloc_getLocaleForLCID(0x12345, temp2
, sizeof(temp2
)/sizeof(char), &status
);
2657 if (U_SUCCESS(status
)) {
2658 log_err(" unexpected result from uloc_getLocaleForLCID(0x12345): %s, status %s\n", temp2
, u_errorName(status
));
2660 status
= U_ZERO_ERROR
;
2662 log_verbose("Testing getLocaleForLCID vs. locale data\n");
2663 for (i
= 0; i
< LOCALE_SIZE
; i
++) {
2665 testLocale
=rawData2
[NAME
][i
];
2667 log_verbose("Testing %s ......\n", testLocale
);
2669 sscanf(rawData2
[LCID
][i
], "%x", &lcid
);
2670 length
= uloc_getLocaleForLCID(lcid
, temp2
, sizeof(temp2
)/sizeof(char), &status
);
2671 if (U_FAILURE(status
)) {
2672 log_err(" unexpected failure of uloc_getLocaleForLCID(%#04x), status %s\n", lcid
, u_errorName(status
));
2673 status
= U_ZERO_ERROR
;
2677 if (length
!= uprv_strlen(temp2
)) {
2678 log_err(" returned length %d not correct for uloc_getLocaleForLCID(%#04x), expected %d\n", length
, lcid
, uprv_strlen(temp2
));
2681 /* Compare language, country, script */
2682 length
= uloc_getLanguage(temp2
, temp3
, sizeof(temp3
)/sizeof(char), &status
);
2683 if (U_FAILURE(status
)) {
2684 log_err(" couldn't get language in uloc_getLocaleForLCID(%#04x) = %s, status %s\n", lcid
, temp2
, u_errorName(status
));
2685 status
= U_ZERO_ERROR
;
2687 else if (uprv_strcmp(temp3
, rawData2
[LANG
][i
]) && !(uprv_strcmp(temp3
, "nn") == 0 && uprv_strcmp(rawData2
[VAR
][i
], "NY") == 0)) {
2688 log_err(" language doesn't match expected %s in in uloc_getLocaleForLCID(%#04x) = %s\n", rawData2
[LANG
][i
], lcid
, temp2
);
2691 length
= uloc_getScript(temp2
, temp3
, sizeof(temp3
)/sizeof(char), &status
);
2692 if (U_FAILURE(status
)) {
2693 log_err(" couldn't get script in uloc_getLocaleForLCID(%#04x) = %s, status %s\n", lcid
, temp2
, u_errorName(status
));
2694 status
= U_ZERO_ERROR
;
2696 else if (uprv_strcmp(temp3
, rawData2
[SCRIPT
][i
])) {
2697 log_err(" script doesn't match expected %s in in uloc_getLocaleForLCID(%#04x) = %s\n", rawData2
[SCRIPT
][i
], lcid
, temp2
);
2700 length
= uloc_getCountry(temp2
, temp3
, sizeof(temp3
)/sizeof(char), &status
);
2701 if (U_FAILURE(status
)) {
2702 log_err(" couldn't get country in uloc_getLocaleForLCID(%#04x) = %s, status %s\n", lcid
, temp2
, u_errorName(status
));
2703 status
= U_ZERO_ERROR
;
2705 else if (uprv_strlen(rawData2
[CTRY
][i
]) && uprv_strcmp(temp3
, rawData2
[CTRY
][i
])) {
2706 log_err(" country doesn't match expected %s in in uloc_getLocaleForLCID(%#04x) = %s\n", rawData2
[CTRY
][i
], lcid
, temp2
);