1 /*********************************************************************
3 * Copyright (c) 2010-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *********************************************************************/
12 test_assert( Test (should be TRUE) )
17 the macro is ugly but makes the tests pretty.
20 #define test_assert(test) \
23 errln("FAIL: " #test " was not true. In " __FILE__ " on line %d", __LINE__ ); \
25 logln("PASS: asserted " #test); \
30 test_assert_print( Test (should be TRUE), printable )
33 test_assert(i==3, toString(i));
35 the macro is ugly but makes the tests pretty.
38 #define test_assert_print(test,print) \
41 errln("FAIL: " #test " was not true. " + UnicodeString(print) ); \
43 logln("PASS: asserted " #test "-> " + UnicodeString(print)); \
46 #define test_assert_equal(target,value) \
48 if (UnicodeString(target)!=(value)) { \
49 logln("unexpected value '" + (value) + "'"); \
50 dataerrln("FAIL: " #target " == " #value " was not true. In " __FILE__ " on line %d", __LINE__); \
52 logln("PASS: asserted " #target " == " #value); \
56 #define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
58 LocaleDisplayNamesTest::LocaleDisplayNamesTest() {
61 LocaleDisplayNamesTest::~LocaleDisplayNamesTest() {
64 void LocaleDisplayNamesTest::runIndexedTest(int32_t index
, UBool exec
, const char* &name
,
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
);
89 #if !UCONFIG_NO_FORMATTING
90 void LocaleDisplayNamesTest::TestCreate() {
92 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getGermany());
93 ldn
->localeDisplayName("de_DE", temp
);
95 test_assert_equal("Deutsch (Deutschland)", temp
);
98 void LocaleDisplayNamesTest::TestCreateDialect() {
100 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS(), ULDN_DIALECT_NAMES
);
101 ldn
->localeDisplayName("en_GB", temp
);
103 test_assert_equal("British English", temp
);
106 void LocaleDisplayNamesTest::TestWithKeywordsAndEverything() {
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
);
114 test_assert_equal(target
, temp
);
117 void LocaleDisplayNamesTest::TestCurrencyKeyword() {
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
);
124 test_assert_equal(target
, temp
);
127 void LocaleDisplayNamesTest::TestUnknownCurrencyKeyword() {
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
);
134 test_assert_equal(target
, temp
);
137 void LocaleDisplayNamesTest::TestUntranslatedKeywords() {
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
);
144 test_assert_equal(target
, temp
);
147 void LocaleDisplayNamesTest::TestPrivateUse() {
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
);
154 test_assert_equal(target
, temp
);
157 void LocaleDisplayNamesTest::TestUldnOpen() {
158 UErrorCode status
= U_ZERO_ERROR
;
159 const int32_t kMaxResultSize
= 150; // long enough
161 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
162 int32_t len
= uldn_localeDisplayName(ldn
, "de_DE", result
, kMaxResultSize
, &status
);
164 test_assert(U_SUCCESS(status
));
166 UnicodeString
str(result
, len
, kMaxResultSize
);
167 test_assert_equal("Deutsch (Deutschland)", str
);
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());
176 test_assert(U_SUCCESS(status
));
179 void LocaleDisplayNamesTest::TestUldnOpenDialect() {
180 UErrorCode status
= U_ZERO_ERROR
;
181 const int32_t kMaxResultSize
= 150; // long enough
183 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES
, &status
);
184 int32_t len
= uldn_localeDisplayName(ldn
, "en_GB", result
, kMaxResultSize
, &status
);
186 test_assert(U_SUCCESS(status
));
188 UnicodeString
str(result
, len
, kMaxResultSize
);
189 test_assert_equal("British English", str
);
192 void LocaleDisplayNamesTest::TestUldnWithGarbage() {
193 UErrorCode status
= U_ZERO_ERROR
;
194 const int32_t kMaxResultSize
= 150; // long enough
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
);
199 test_assert(U_FAILURE(status
) && len
== 0);
202 void LocaleDisplayNamesTest::TestUldnWithKeywordsAndEverything() {
203 UErrorCode status
= U_ZERO_ERROR
;
204 const int32_t kMaxResultSize
= 150; // long enough
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
);
212 test_assert(U_SUCCESS(status
));
214 UnicodeString
str(result
, len
, kMaxResultSize
);
215 test_assert_equal(target
, str
);
218 void LocaleDisplayNamesTest::TestUldnComponents() {
219 UErrorCode status
= U_ZERO_ERROR
;
220 const int32_t kMaxResultSize
= 150; // long enough
223 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
224 test_assert(U_SUCCESS(status
));
225 if (U_FAILURE(status
)) {
229 // "en_Hant_US_PRE_EURO@calendar=gregorian";
232 int32_t len
= uldn_languageDisplayName(ldn
, "en", result
, kMaxResultSize
, &status
);
233 UnicodeString
str(result
, len
, kMaxResultSize
);
234 test_assert_equal("Englisch", str
);
239 int32_t len
= uldn_scriptDisplayName(ldn
, "Hant", result
, kMaxResultSize
, &status
);
240 UnicodeString
str(result
, len
, kMaxResultSize
);
241 test_assert_equal("Traditionelles Chinesisch", str
);
245 int32_t len
= uldn_scriptCodeDisplayName(ldn
, USCRIPT_TRADITIONAL_HAN
, result
, kMaxResultSize
,
247 UnicodeString
str(result
, len
, kMaxResultSize
);
248 test_assert_equal("Traditionelles Chinesisch", str
);
252 int32_t len
= uldn_regionDisplayName(ldn
, "US", result
, kMaxResultSize
, &status
);
253 UnicodeString
str(result
, len
, kMaxResultSize
);
254 test_assert_equal("Vereinigte Staaten", str
);
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
);
264 int32_t len
= uldn_keyDisplayName(ldn
, "calendar", result
, kMaxResultSize
, &status
);
265 UnicodeString
str(result
, len
, kMaxResultSize
);
266 test_assert_equal("Kalender", str
);
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
);
281 const char * displayLocale
;
282 UDisplayContext dialectHandling
;
283 UDisplayContext capitalization
;
284 UDisplayContext displayLength
;
285 const char * localeToBeNamed
;
286 const UChar
* result
;
287 } LocNameDispContextItem
;
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";
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 */
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
},
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
},
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
}
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
);
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");
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
);
405 void LocaleDisplayNamesTest::TestRootEtc() {
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
);
413 ldn
->languageDisplayName("root", temp
);
414 test_assert_equal("root", temp
);
416 ldn
->languageDisplayName("en_GB", temp
);
417 test_assert_equal("en_GB", temp
);
422 #endif /* UCONFIG_NO_FORMATTING */