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