1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*********************************************************************
5 * Copyright (c) 2010-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *********************************************************************/
10 #include "unicode/ustring.h"
15 test_assert( Test (should be TRUE) )
20 the macro is ugly but makes the tests pretty.
23 #define test_assert(test) \
26 errln("FAIL: " #test " was not true. In " __FILE__ " on line %d", __LINE__ ); \
28 logln("PASS: asserted " #test); \
33 test_assert_print( Test (should be TRUE), printable )
36 test_assert(i==3, toString(i));
38 the macro is ugly but makes the tests pretty.
41 #define test_assert_print(test,print) \
44 errln("FAIL: " #test " was not true. " + UnicodeString(print) ); \
46 logln("PASS: asserted " #test "-> " + UnicodeString(print)); \
49 #define test_assert_equal(target,value) \
51 if (UnicodeString(target)!=(value)) { \
52 logln("unexpected value '" + (value) + "'"); \
53 dataerrln("FAIL: " #target " == " #value " was not true. In " __FILE__ " on line %d", __LINE__); \
55 logln("PASS: asserted " #target " == " #value); \
59 #define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
61 LocaleDisplayNamesTest::LocaleDisplayNamesTest() {
64 LocaleDisplayNamesTest::~LocaleDisplayNamesTest() {
67 void LocaleDisplayNamesTest::runIndexedTest(int32_t index
, UBool exec
, const char* &name
,
70 #if !UCONFIG_NO_FORMATTING
71 TESTCASE(0, TestCreate
);
72 TESTCASE(1, TestCreateDialect
);
73 TESTCASE(2, TestWithKeywordsAndEverything
);
74 TESTCASE(3, TestUldnOpen
);
75 TESTCASE(4, TestUldnOpenDialect
);
76 TESTCASE(5, TestUldnWithKeywordsAndEverything
);
77 TESTCASE(6, TestUldnComponents
);
78 TESTCASE(7, TestRootEtc
);
79 TESTCASE(8, TestCurrencyKeyword
);
80 TESTCASE(9, TestUnknownCurrencyKeyword
);
81 TESTCASE(10, TestUntranslatedKeywords
);
82 TESTCASE(11, TestPrivateUse
);
83 TESTCASE(12, TestUldnDisplayContext
);
84 TESTCASE(13, TestUldnWithGarbage
);
92 #if !UCONFIG_NO_FORMATTING
93 void LocaleDisplayNamesTest::TestCreate() {
95 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getGermany());
96 ldn
->localeDisplayName("de_DE", temp
);
98 test_assert_equal("Deutsch (Deutschland)", temp
);
101 void LocaleDisplayNamesTest::TestCreateDialect() {
103 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS(), ULDN_DIALECT_NAMES
);
104 ldn
->localeDisplayName("en_GB", temp
);
106 test_assert_equal("British English", temp
);
109 void LocaleDisplayNamesTest::TestWithKeywordsAndEverything() {
111 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
112 const char *locname
= "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
113 const char *target
= "English (Traditional, US, VALLEY, "
114 "Gregorian Calendar, Phonebook Sort Order)"; // Apple change
115 ldn
->localeDisplayName(locname
, temp
);
117 test_assert_equal(target
, temp
);
120 void LocaleDisplayNamesTest::TestCurrencyKeyword() {
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
);
127 test_assert_equal(target
, temp
);
130 void LocaleDisplayNamesTest::TestUnknownCurrencyKeyword() {
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
);
137 test_assert_equal(target
, temp
);
140 void LocaleDisplayNamesTest::TestUntranslatedKeywords() {
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
);
147 test_assert_equal(target
, temp
);
150 void LocaleDisplayNamesTest::TestPrivateUse() {
152 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
153 const char *locname
= "de@x=foobar";
154 const char *target
= "German (Private-Use: foobar)";
155 ldn
->localeDisplayName(locname
, temp
);
157 test_assert_equal(target
, temp
);
160 void LocaleDisplayNamesTest::TestUldnOpen() {
161 UErrorCode status
= U_ZERO_ERROR
;
162 const int32_t kMaxResultSize
= 150; // long enough
164 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
165 int32_t len
= uldn_localeDisplayName(ldn
, "de_DE", result
, kMaxResultSize
, &status
);
167 test_assert(U_SUCCESS(status
));
169 UnicodeString
str(result
, len
, kMaxResultSize
);
170 test_assert_equal("Deutsch (Deutschland)", str
);
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());
179 test_assert(U_SUCCESS(status
));
182 void LocaleDisplayNamesTest::TestUldnOpenDialect() {
183 UErrorCode status
= U_ZERO_ERROR
;
184 const int32_t kMaxResultSize
= 150; // long enough
186 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES
, &status
);
187 int32_t len
= uldn_localeDisplayName(ldn
, "en_GB", result
, kMaxResultSize
, &status
);
189 test_assert(U_SUCCESS(status
));
191 UnicodeString
str(result
, len
, kMaxResultSize
);
192 test_assert_equal("British English", str
);
195 void LocaleDisplayNamesTest::TestUldnWithGarbage() {
196 UErrorCode status
= U_ZERO_ERROR
;
197 const int32_t kMaxResultSize
= 150; // long enough
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
);
202 test_assert(U_FAILURE(status
) && len
== 0);
205 void LocaleDisplayNamesTest::TestUldnWithKeywordsAndEverything() {
206 UErrorCode status
= U_ZERO_ERROR
;
207 const int32_t kMaxResultSize
= 150; // long enough
209 const char *locname
= "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
210 const char *target
= "English (Traditional, US, VALLEY, "
211 "Gregorian Calendar, Phonebook Sort Order)"; // Apple change
212 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getUS().getName(), ULDN_STANDARD_NAMES
, &status
);
213 int32_t len
= uldn_localeDisplayName(ldn
, locname
, result
, kMaxResultSize
, &status
);
215 test_assert(U_SUCCESS(status
));
217 UnicodeString
str(result
, len
, kMaxResultSize
);
218 test_assert_equal(target
, str
);
221 void LocaleDisplayNamesTest::TestUldnComponents() {
222 UErrorCode status
= U_ZERO_ERROR
;
223 const int32_t kMaxResultSize
= 150; // long enough
226 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
227 test_assert(U_SUCCESS(status
));
228 if (U_FAILURE(status
)) {
232 // "en_Hant_US_PRE_EURO@calendar=gregorian";
235 int32_t len
= uldn_languageDisplayName(ldn
, "en", result
, kMaxResultSize
, &status
);
236 UnicodeString
str(result
, len
, kMaxResultSize
);
237 test_assert_equal("Englisch", str
);
242 int32_t len
= uldn_scriptDisplayName(ldn
, "Hant", result
, kMaxResultSize
, &status
);
243 UnicodeString
str(result
, len
, kMaxResultSize
);
244 test_assert_equal("Traditionelles Chinesisch", str
);
248 int32_t len
= uldn_scriptCodeDisplayName(ldn
, USCRIPT_TRADITIONAL_HAN
, result
, kMaxResultSize
,
250 UnicodeString
str(result
, len
, kMaxResultSize
);
251 test_assert_equal("Traditionelles Chinesisch", str
);
255 int32_t len
= uldn_regionDisplayName(ldn
, "US", result
, kMaxResultSize
, &status
);
256 UnicodeString
str(result
, len
, kMaxResultSize
);
257 test_assert_equal("Vereinigte Staaten", str
);
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
);
267 int32_t len
= uldn_keyDisplayName(ldn
, "calendar", result
, kMaxResultSize
, &status
);
268 UnicodeString
str(result
, len
, kMaxResultSize
);
269 test_assert_equal("Kalender", str
);
273 int32_t len
= uldn_keyValueDisplayName(ldn
, "calendar", "gregorian", result
,
274 kMaxResultSize
, &status
);
275 UnicodeString
str(result
, len
, kMaxResultSize
);
276 test_assert_equal("Gregorianischer Kalender", str
);
284 const char * displayLocale
;
285 UDisplayContext dialectHandling
;
286 UDisplayContext capitalization
;
287 UDisplayContext displayLength
;
288 const char * localeToBeNamed
;
289 const UChar
* result
;
290 } LocNameDispContextItem
;
292 static char en
[] = "en";
293 static char en_cabud
[] = "en@calendar=buddhist";
294 static char en_GB
[] = "en_GB";
295 static char uz_Latn
[] = "uz_Latn";
297 static UChar daFor_en
[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"engelsk"
298 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,
299 0x6B,0x61,0x6C,0x65,0x6E,0x64,0x65,0x72,0x29,0}; //"engelsk (buddhistisk kalender)"
300 static UChar daFor_en_GB
[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"engelsk (UK)" // Apple change
301 static UChar daFor_en_GB_S
[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"engelsk (UK)"
302 static UChar daFor_en_GB_D
[] = {0x62,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"britisk engelsk"
303 static UChar esFor_en
[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0}; //"ingles" with acute on the e
304 static UChar esFor_en_GB
[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"ingles (RU)" ... // Apple change
305 static UChar esFor_en_GB_S
[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"ingles (RU)" ...
306 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
307 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
308 #if !UCONFIG_NO_BREAK_ITERATION
309 static UChar daFor_en_T
[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Engelsk"
310 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,
311 0x6B,0x61,0x6C,0x65,0x6E,0x64,0x65,0x72,0x29,0}; //"Engelsk (buddhistisk kalender)"
312 static UChar daFor_en_GB_T
[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"Engelsk (UK)" // Apple change
313 static UChar daFor_en_GB_ST
[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x55,0x4B,0x29,0}; //"Engelsk (UK)"
314 static UChar daFor_en_GB_DT
[] = {0x42,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Britisk engelsk"
315 static UChar esFor_en_T
[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0}; //"Ingles" with acute on the e
316 static UChar esFor_en_GB_T
[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"Ingles (RU)" ... // Apple change
317 static UChar esFor_en_GB_ST
[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x55,0x29,0}; //"Ingles (RU)" ...
318 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
319 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
320 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
322 static const LocNameDispContextItem ctxtItems
[] = {
323 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDISPCTX_LENGTH_FULL
, en
, daFor_en
},
324 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDISPCTX_LENGTH_FULL
, en_cabud
, daFor_en_cabud
},
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
},
332 { "ru", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDISPCTX_LENGTH_FULL
, uz_Latn
, ruFor_uz_Latn
},
333 #if !UCONFIG_NO_BREAK_ITERATION
334 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE
, UDISPCTX_LENGTH_FULL
, en
, daFor_en_T
},
335 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE
, UDISPCTX_LENGTH_FULL
, en_cabud
, daFor_en_cabudT
},
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
},
343 { "ru", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE
, UDISPCTX_LENGTH_FULL
, uz_Latn
, ruFor_uz_Latn_T
},
345 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL
, en
, daFor_en_T
},
346 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL
, en_cabud
, daFor_en_cabudT
},
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
},
354 { "ru", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL
, uz_Latn
, ruFor_uz_Latn_T
},
356 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_STANDALONE
, UDISPCTX_LENGTH_FULL
, en
, daFor_en
},
357 { "da", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_STANDALONE
, UDISPCTX_LENGTH_FULL
, en_cabud
, daFor_en_cabud
},
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
},
365 { "ru", UDISPCTX_STANDARD_NAMES
, UDISPCTX_CAPITALIZATION_FOR_STANDALONE
, UDISPCTX_LENGTH_FULL
, uz_Latn
, ruFor_uz_Latn_T
},
366 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
367 { NULL
, (UDisplayContext
)0, (UDisplayContext
)0, (UDisplayContext
)0, NULL
, NULL
}
370 void LocaleDisplayNamesTest::TestUldnDisplayContext() {
371 const LocNameDispContextItem
* ctxtItemPtr
;
372 for (ctxtItemPtr
= ctxtItems
; ctxtItemPtr
->displayLocale
!= NULL
; ctxtItemPtr
++) {
373 UDisplayContext contexts
[3] = {ctxtItemPtr
->dialectHandling
, ctxtItemPtr
->capitalization
, ctxtItemPtr
->displayLength
};
374 UErrorCode status
= U_ZERO_ERROR
;
375 ULocaleDisplayNames
* uldn
= uldn_openForContext(ctxtItemPtr
->displayLocale
, contexts
, 3, &status
);
376 if (U_FAILURE(status
)) {
377 errln(UnicodeString("FAIL: uldn_openForContext failed for locale ") + ctxtItemPtr
->displayLocale
+
378 ", dialectHandling " + ctxtItemPtr
->dialectHandling
+
379 ", capitalization " + ctxtItemPtr
->capitalization
+
380 ", displayLength " + ctxtItemPtr
->displayLength
);
382 UDisplayContext dialectHandling
= uldn_getContext(uldn
, UDISPCTX_TYPE_DIALECT_HANDLING
, &status
);
383 UDisplayContext capitalization
= uldn_getContext(uldn
, UDISPCTX_TYPE_CAPITALIZATION
, &status
);
384 UDisplayContext displayLength
= uldn_getContext(uldn
, UDISPCTX_TYPE_DISPLAY_LENGTH
, &status
);
385 if (U_FAILURE(status
)) {
386 errln(UnicodeString("FAIL: uldn_getContext status ") + (int)status
);
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");
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
);
408 void LocaleDisplayNamesTest::TestRootEtc() {
410 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
411 const char *locname
= "@collation=phonebook";
412 const char *target
= "Root (Phonebook Sort Order)";
413 ldn
->localeDisplayName(locname
, temp
);
414 test_assert_equal(target
, temp
);
416 ldn
->languageDisplayName("root", temp
);
417 test_assert_equal("root", temp
);
419 ldn
->languageDisplayName("en_GB", temp
);
420 test_assert_equal("en_GB", temp
);
425 #endif /* UCONFIG_NO_FORMATTING */