]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/locnmtst.cpp
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / locnmtst.cpp
1 /*********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 2010-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *********************************************************************/
6
7 #include "locnmtst.h"
8 #include "cstring.h"
9
10 /*
11 Usage:
12 test_assert( Test (should be TRUE) )
13
14 Example:
15 test_assert(i==3);
16
17 the macro is ugly but makes the tests pretty.
18 */
19
20 #define test_assert(test) \
21 { \
22 if(!(test)) \
23 errln("FAIL: " #test " was not true. In " __FILE__ " on line %d", __LINE__ ); \
24 else \
25 logln("PASS: asserted " #test); \
26 }
27
28 /*
29 Usage:
30 test_assert_print( Test (should be TRUE), printable )
31
32 Example:
33 test_assert(i==3, toString(i));
34
35 the macro is ugly but makes the tests pretty.
36 */
37
38 #define test_assert_print(test,print) \
39 { \
40 if(!(test)) \
41 errln("FAIL: " #test " was not true. " + UnicodeString(print) ); \
42 else \
43 logln("PASS: asserted " #test "-> " + UnicodeString(print)); \
44 }
45
46 #define test_assert_equal(target,value) \
47 { \
48 if (UnicodeString(target)!=(value)) { \
49 logln("unexpected value '" + (value) + "'"); \
50 dataerrln("FAIL: " #target " == " #value " was not true. In " __FILE__ " on line %d", __LINE__); \
51 } else { \
52 logln("PASS: asserted " #target " == " #value); \
53 } \
54 }
55
56 #define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
57
58 LocaleDisplayNamesTest::LocaleDisplayNamesTest() {
59 }
60
61 LocaleDisplayNamesTest::~LocaleDisplayNamesTest() {
62 }
63
64 void LocaleDisplayNamesTest::runIndexedTest(int32_t index, UBool exec, const char* &name,
65 char* /*par*/) {
66 switch (index) {
67 #if !UCONFIG_NO_FORMATTING
68 TESTCASE(0, TestCreate);
69 TESTCASE(1, TestCreateDialect);
70 TESTCASE(2, TestWithKeywordsAndEverything);
71 TESTCASE(3, TestUldnOpen);
72 TESTCASE(4, TestUldnOpenDialect);
73 TESTCASE(5, TestUldnWithKeywordsAndEverything);
74 TESTCASE(6, TestUldnComponents);
75 TESTCASE(7, TestRootEtc);
76 TESTCASE(8, TestCurrencyKeyword);
77 TESTCASE(9, TestUnknownCurrencyKeyword);
78 TESTCASE(10, TestUntranslatedKeywords);
79 TESTCASE(11, TestPrivateUse);
80 TESTCASE(12, TestUldnDisplayContext);
81 TESTCASE(13, TestUldnWithGarbage);
82 #endif
83 default:
84 name = "";
85 break;
86 }
87 }
88
89 #if !UCONFIG_NO_FORMATTING
90 void LocaleDisplayNamesTest::TestCreate() {
91 UnicodeString temp;
92 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getGermany());
93 ldn->localeDisplayName("de_DE", temp);
94 delete ldn;
95 test_assert_equal("Deutsch (Deutschland)", temp);
96 }
97
98 void LocaleDisplayNamesTest::TestCreateDialect() {
99 UnicodeString temp;
100 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS(), ULDN_DIALECT_NAMES);
101 ldn->localeDisplayName("en_GB", temp);
102 delete ldn;
103 test_assert_equal("British English", temp);
104 }
105
106 void LocaleDisplayNamesTest::TestWithKeywordsAndEverything() {
107 UnicodeString temp;
108 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
109 const char *locname = "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
110 const char *target = "English (Traditional, US, VALLEY, "
111 "Gregorian Calendar, Phonebook Sort Order)"; // Apple change
112 ldn->localeDisplayName(locname, temp);
113 delete ldn;
114 test_assert_equal(target, temp);
115 }
116
117 void LocaleDisplayNamesTest::TestCurrencyKeyword() {
118 UnicodeString temp;
119 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
120 const char *locname = "ja@currency=JPY";
121 const char *target = "Japanese (Japanese Yen)";
122 ldn->localeDisplayName(locname, temp);
123 delete ldn;
124 test_assert_equal(target, temp);
125 }
126
127 void LocaleDisplayNamesTest::TestUnknownCurrencyKeyword() {
128 UnicodeString temp;
129 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
130 const char *locname = "de@currency=XYZ";
131 const char *target = "German (Currency: XYZ)";
132 ldn->localeDisplayName(locname, temp);
133 delete ldn;
134 test_assert_equal(target, temp);
135 }
136
137 void LocaleDisplayNamesTest::TestUntranslatedKeywords() {
138 UnicodeString temp;
139 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
140 const char *locname = "de@foo=bar";
141 const char *target = "German (foo=bar)";
142 ldn->localeDisplayName(locname, temp);
143 delete ldn;
144 test_assert_equal(target, temp);
145 }
146
147 void LocaleDisplayNamesTest::TestPrivateUse() {
148 UnicodeString temp;
149 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
150 const char *locname = "de@x=foobar";
151 const char *target = "German (Private-Use: foobar)";
152 ldn->localeDisplayName(locname, temp);
153 delete ldn;
154 test_assert_equal(target, temp);
155 }
156
157 void LocaleDisplayNamesTest::TestUldnOpen() {
158 UErrorCode status = U_ZERO_ERROR;
159 const int32_t kMaxResultSize = 150; // long enough
160 UChar result[150];
161 ULocaleDisplayNames *ldn = uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES, &status);
162 int32_t len = uldn_localeDisplayName(ldn, "de_DE", result, kMaxResultSize, &status);
163 uldn_close(ldn);
164 test_assert(U_SUCCESS(status));
165
166 UnicodeString str(result, len, kMaxResultSize);
167 test_assert_equal("Deutsch (Deutschland)", str);
168
169 // make sure that NULL gives us the default locale as usual
170 ldn = uldn_open(NULL, ULDN_STANDARD_NAMES, &status);
171 const char *locale = uldn_getLocale(ldn);
172 if(0 != uprv_strcmp(uloc_getDefault(), locale)) {
173 errln("uldn_getLocale(uldn_open(NULL))=%s != default locale %s\n", locale, uloc_getDefault());
174 }
175 uldn_close(ldn);
176 test_assert(U_SUCCESS(status));
177 }
178
179 void LocaleDisplayNamesTest::TestUldnOpenDialect() {
180 UErrorCode status = U_ZERO_ERROR;
181 const int32_t kMaxResultSize = 150; // long enough
182 UChar result[150];
183 ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES, &status);
184 int32_t len = uldn_localeDisplayName(ldn, "en_GB", result, kMaxResultSize, &status);
185 uldn_close(ldn);
186 test_assert(U_SUCCESS(status));
187
188 UnicodeString str(result, len, kMaxResultSize);
189 test_assert_equal("British English", str);
190 }
191
192 void LocaleDisplayNamesTest::TestUldnWithGarbage() {
193 UErrorCode status = U_ZERO_ERROR;
194 const int32_t kMaxResultSize = 150; // long enough
195 UChar result[150];
196 ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES, &status);
197 int32_t len = uldn_localeDisplayName(ldn, "english (United States) [w", result, kMaxResultSize, &status);
198 uldn_close(ldn);
199 test_assert(U_FAILURE(status) && len == 0);
200 }
201
202 void LocaleDisplayNamesTest::TestUldnWithKeywordsAndEverything() {
203 UErrorCode status = U_ZERO_ERROR;
204 const int32_t kMaxResultSize = 150; // long enough
205 UChar result[150];
206 const char *locname = "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
207 const char *target = "English (Traditional, US, VALLEY, "
208 "Gregorian Calendar, Phonebook Sort Order)"; // Apple change
209 ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_STANDARD_NAMES, &status);
210 int32_t len = uldn_localeDisplayName(ldn, locname, result, kMaxResultSize, &status);
211 uldn_close(ldn);
212 test_assert(U_SUCCESS(status));
213
214 UnicodeString str(result, len, kMaxResultSize);
215 test_assert_equal(target, str);
216 }
217
218 void LocaleDisplayNamesTest::TestUldnComponents() {
219 UErrorCode status = U_ZERO_ERROR;
220 const int32_t kMaxResultSize = 150; // long enough
221 UChar result[150];
222
223 ULocaleDisplayNames *ldn = uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES, &status);
224 test_assert(U_SUCCESS(status));
225 if (U_FAILURE(status)) {
226 return;
227 }
228
229 // "en_Hant_US_PRE_EURO@calendar=gregorian";
230
231 {
232 int32_t len = uldn_languageDisplayName(ldn, "en", result, kMaxResultSize, &status);
233 UnicodeString str(result, len, kMaxResultSize);
234 test_assert_equal("Englisch", str);
235 }
236
237
238 {
239 int32_t len = uldn_scriptDisplayName(ldn, "Hant", result, kMaxResultSize, &status);
240 UnicodeString str(result, len, kMaxResultSize);
241 test_assert_equal("Traditionelles Chinesisch", str);
242 }
243
244 {
245 int32_t len = uldn_scriptCodeDisplayName(ldn, USCRIPT_TRADITIONAL_HAN, result, kMaxResultSize,
246 &status);
247 UnicodeString str(result, len, kMaxResultSize);
248 test_assert_equal("Traditionelles Chinesisch", str);
249 }
250
251 {
252 int32_t len = uldn_regionDisplayName(ldn, "US", result, kMaxResultSize, &status);
253 UnicodeString str(result, len, kMaxResultSize);
254 test_assert_equal("Vereinigte Staaten", str);
255 }
256
257 {
258 int32_t len = uldn_variantDisplayName(ldn, "PRE_EURO", result, kMaxResultSize, &status);
259 UnicodeString str(result, len, kMaxResultSize);
260 test_assert_equal("PRE_EURO", str);
261 }
262
263 {
264 int32_t len = uldn_keyDisplayName(ldn, "calendar", result, kMaxResultSize, &status);
265 UnicodeString str(result, len, kMaxResultSize);
266 test_assert_equal("Kalender", str);
267 }
268
269 {
270 int32_t len = uldn_keyValueDisplayName(ldn, "calendar", "gregorian", result,
271 kMaxResultSize, &status);
272 UnicodeString str(result, len, kMaxResultSize);
273 test_assert_equal("Gregorianischer Kalender", str);
274 }
275
276 uldn_close(ldn);
277 }
278
279
280 typedef struct {
281 const char * displayLocale;
282 UDisplayContext dialectHandling;
283 UDisplayContext capitalization;
284 UDisplayContext displayLength;
285 const char * localeToBeNamed;
286 const UChar * result;
287 } LocNameDispContextItem;
288
289 static char en[] = "en";
290 static char en_cabud[] = "en@calendar=buddhist";
291 static char en_GB[] = "en_GB";
292 static char uz_Latn[] = "uz_Latn";
293
294 static UChar daFor_en[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"engelsk"
295 static UChar daFor_en_cabud[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x62,0x75,0x64,0x64,0x68,0x69,0x73,0x74,0x69,0x73,0x6B,0x20,
296 0x6B,0x61,0x6C,0x65,0x6E,0x64,0x65,0x72,0x29,0}; //"engelsk (buddhistisk kalender)"
297 static UChar daFor_en_GB[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"engelsk (UK)" // Apple change
298 static UChar daFor_en_GB_S[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"engelsk (UK)"
299 static UChar daFor_en_GB_D[] = {0x62,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"britisk engelsk"
300 static UChar esFor_en[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0}; //"ingles" with acute on the e
301 static UChar esFor_en_GB[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"ingles (RU)" ... // Apple change
302 static UChar esFor_en_GB_S[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"ingles (RU)" ...
303 static UChar esFor_en_GB_D[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x62,0x72,0x69,0x74,0xE1,0x6E,0x69,0x63,0x6F,0}; //"ingles britanico" with acute on the e, a
304 static UChar ruFor_uz_Latn[] = {0x0443,0x0437,0x0431,0x0435,0x043A,0x0441,0x043A,0x0438,0x0439,0x20,0x28,0x043B,0x0430,0x0442,0x0438,0x043D,0x0438,0x0446,0x0430,0x29,0}; // all lowercase
305 #if !UCONFIG_NO_BREAK_ITERATION
306 static UChar daFor_en_T[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Engelsk"
307 static UChar daFor_en_cabudT[]= {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x62,0x75,0x64,0x64,0x68,0x69,0x73,0x74,0x69,0x73,0x6B,0x20,
308 0x6B,0x61,0x6C,0x65,0x6E,0x64,0x65,0x72,0x29,0}; //"Engelsk (buddhistisk kalender)"
309 static UChar daFor_en_GB_T[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"Engelsk (UK)" // Apple change
310 static UChar daFor_en_GB_ST[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"Engelsk (UK)"
311 static UChar daFor_en_GB_DT[] = {0x42,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Britisk engelsk"
312 static UChar esFor_en_T[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0}; //"Ingles" with acute on the e
313 static UChar esFor_en_GB_T[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"Ingles (RU)" ... // Apple change
314 static UChar esFor_en_GB_ST[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"Ingles (RU)" ...
315 static UChar esFor_en_GB_DT[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x62,0x72,0x69,0x74,0xE1,0x6E,0x69,0x63,0x6F,0}; //"Ingles britanico" with acute on the e, a
316 static UChar ruFor_uz_Latn_T[]= {0x0423,0x0437,0x0431,0x0435,0x043A,0x0441,0x043A,0x0438,0x0439,0x20,0x28,0x043B,0x0430,0x0442,0x0438,0x043D,0x0438,0x0446,0x0430,0x29,0}; // first char upper
317 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
318
319 static const LocNameDispContextItem ctxtItems[] = {
320 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en, daFor_en },
321 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_cabud, daFor_en_cabud },
322 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB },
323 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_S },
324 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_D },
325 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en, esFor_en },
326 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB },
327 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_S },
328 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_D },
329 { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDISPCTX_LENGTH_FULL, uz_Latn, ruFor_uz_Latn },
330 #if !UCONFIG_NO_BREAK_ITERATION
331 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en, daFor_en_T },
332 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_cabud, daFor_en_cabudT },
333 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_T },
334 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_ST },
335 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_DT },
336 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en, esFor_en_T },
337 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_T },
338 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_ST },
339 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_DT },
340 { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, UDISPCTX_LENGTH_FULL, uz_Latn, ruFor_uz_Latn_T },
341
342 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, en, daFor_en_T },
343 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, en_cabud, daFor_en_cabudT },
344 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_T },
345 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_ST },
346 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_DT },
347 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, en, esFor_en_T },
348 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_T },
349 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_ST },
350 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_DT },
351 { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, UDISPCTX_LENGTH_FULL, uz_Latn, ruFor_uz_Latn_T },
352
353 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, en, daFor_en },
354 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, en_cabud, daFor_en_cabud },
355 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB },
356 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_S },
357 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_D },
358 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, en, esFor_en_T },
359 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_T },
360 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_ST },
361 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_DT },
362 { "ru", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, UDISPCTX_LENGTH_FULL, uz_Latn, ruFor_uz_Latn_T },
363 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
364 { NULL, (UDisplayContext)0, (UDisplayContext)0, (UDisplayContext)0, NULL, NULL }
365 };
366
367 void LocaleDisplayNamesTest::TestUldnDisplayContext() {
368 const LocNameDispContextItem * ctxtItemPtr;
369 for (ctxtItemPtr = ctxtItems; ctxtItemPtr->displayLocale != NULL; ctxtItemPtr++) {
370 UDisplayContext contexts[3] = {ctxtItemPtr->dialectHandling, ctxtItemPtr->capitalization, ctxtItemPtr->displayLength};
371 UErrorCode status = U_ZERO_ERROR;
372 ULocaleDisplayNames * uldn = uldn_openForContext(ctxtItemPtr->displayLocale, contexts, 3, &status);
373 if (U_FAILURE(status)) {
374 errln(UnicodeString("FAIL: uldn_openForContext failed for locale ") + ctxtItemPtr->displayLocale +
375 ", dialectHandling " + ctxtItemPtr->dialectHandling +
376 ", capitalization " + ctxtItemPtr->capitalization +
377 ", displayLength " + ctxtItemPtr->displayLength);
378 } else {
379 UDisplayContext dialectHandling = uldn_getContext(uldn, UDISPCTX_TYPE_DIALECT_HANDLING, &status);
380 UDisplayContext capitalization = uldn_getContext(uldn, UDISPCTX_TYPE_CAPITALIZATION, &status);
381 UDisplayContext displayLength = uldn_getContext(uldn, UDISPCTX_TYPE_DISPLAY_LENGTH, &status);
382 if (U_FAILURE(status)) {
383 errln(UnicodeString("FAIL: uldn_getContext status ") + (int)status);
384 } else if (dialectHandling != ctxtItemPtr->dialectHandling ||
385 capitalization != ctxtItemPtr->capitalization ||
386 displayLength != ctxtItemPtr->displayLength) {
387 errln("FAIL: uldn_getContext retrieved incorrect dialectHandling, capitalization, or displayLength");
388 } else {
389 UChar nameBuf[ULOC_FULLNAME_CAPACITY];
390 int32_t len = uldn_localeDisplayName(uldn, ctxtItemPtr->localeToBeNamed, nameBuf, ULOC_FULLNAME_CAPACITY, &status);
391 if (U_FAILURE(status)) {
392 dataerrln(UnicodeString("FAIL: uldn_localeDisplayName status: ") + u_errorName(status));
393 } else if (u_strcmp(ctxtItemPtr->result, nameBuf) != 0) {
394 UnicodeString exp(ctxtItemPtr->result, u_strlen(ctxtItemPtr->result));
395 UnicodeString got(nameBuf, len);
396 dataerrln(UnicodeString("FAIL: uldn_localeDisplayName, capitalization ") + ctxtItemPtr->capitalization +
397 ", expected " + exp + ", got " + got );
398 }
399 }
400 uldn_close(uldn);
401 }
402 }
403 }
404
405 void LocaleDisplayNamesTest::TestRootEtc() {
406 UnicodeString temp;
407 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS());
408 const char *locname = "@collation=phonebook";
409 const char *target = "Root (Phonebook Sort Order)";
410 ldn->localeDisplayName(locname, temp);
411 test_assert_equal(target, temp);
412
413 ldn->languageDisplayName("root", temp);
414 test_assert_equal("root", temp);
415
416 ldn->languageDisplayName("en_GB", temp);
417 test_assert_equal("en_GB", temp);
418
419 delete ldn;
420 }
421
422 #endif /* UCONFIG_NO_FORMATTING */