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