OLD | NEW |
| (Empty) |
1 /********************************************************************* | |
2 * COPYRIGHT: | |
3 * Copyright (c) 2010-2014, 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__ " o
n 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 cha
r* &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 #endif | |
82 default: | |
83 name = ""; | |
84 break; | |
85 } | |
86 } | |
87 | |
88 #if !UCONFIG_NO_FORMATTING | |
89 void LocaleDisplayNamesTest::TestCreate() { | |
90 UnicodeString temp; | |
91 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getGerman
y()); | |
92 ldn->localeDisplayName("de_DE", temp); | |
93 delete ldn; | |
94 test_assert_equal("Deutsch (Deutschland)", temp); | |
95 } | |
96 | |
97 void LocaleDisplayNamesTest::TestCreateDialect() { | |
98 UnicodeString temp; | |
99 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS(),
ULDN_DIALECT_NAMES); | |
100 ldn->localeDisplayName("en_GB", temp); | |
101 delete ldn; | |
102 test_assert_equal("British English", temp); | |
103 } | |
104 | |
105 void LocaleDisplayNamesTest::TestWithKeywordsAndEverything() { | |
106 UnicodeString temp; | |
107 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS()); | |
108 const char *locname = "en_Hant_US_VALLEY@calendar=gregorian;collation=phoneboo
k"; | |
109 const char *target = "English (Traditional, United States, VALLEY, " | |
110 "Gregorian Calendar, Phonebook Sort Order)"; | |
111 ldn->localeDisplayName(locname, temp); | |
112 delete ldn; | |
113 test_assert_equal(target, temp); | |
114 } | |
115 | |
116 void LocaleDisplayNamesTest::TestCurrencyKeyword() { | |
117 UnicodeString temp; | |
118 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS()); | |
119 const char *locname = "ja@currency=JPY"; | |
120 const char *target = "Japanese (Japanese Yen)"; | |
121 ldn->localeDisplayName(locname, temp); | |
122 delete ldn; | |
123 test_assert_equal(target, temp); | |
124 } | |
125 | |
126 void LocaleDisplayNamesTest::TestUnknownCurrencyKeyword() { | |
127 UnicodeString temp; | |
128 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS()); | |
129 const char *locname = "de@currency=XYZ"; | |
130 const char *target = "German (Currency: XYZ)"; | |
131 ldn->localeDisplayName(locname, temp); | |
132 delete ldn; | |
133 test_assert_equal(target, temp); | |
134 } | |
135 | |
136 void LocaleDisplayNamesTest::TestUntranslatedKeywords() { | |
137 UnicodeString temp; | |
138 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS()); | |
139 const char *locname = "de@foo=bar"; | |
140 const char *target = "German (foo=bar)"; | |
141 ldn->localeDisplayName(locname, temp); | |
142 delete ldn; | |
143 test_assert_equal(target, temp); | |
144 } | |
145 | |
146 void LocaleDisplayNamesTest::TestPrivateUse() { | |
147 UnicodeString temp; | |
148 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS()); | |
149 const char *locname = "de@x=foobar"; | |
150 const char *target = "German (Private-Use: foobar)"; | |
151 ldn->localeDisplayName(locname, temp); | |
152 delete ldn; | |
153 test_assert_equal(target, temp); | |
154 } | |
155 | |
156 void LocaleDisplayNamesTest::TestUldnOpen() { | |
157 UErrorCode status = U_ZERO_ERROR; | |
158 const int32_t kMaxResultSize = 150; // long enough | |
159 UChar result[150]; | |
160 ULocaleDisplayNames *ldn = uldn_open(Locale::getGermany().getName(), ULDN_STAN
DARD_NAMES, &status); | |
161 int32_t len = uldn_localeDisplayName(ldn, "de_DE", result, kMaxResultSize, &st
atus); | |
162 uldn_close(ldn); | |
163 test_assert(U_SUCCESS(status)); | |
164 | |
165 UnicodeString str(result, len, kMaxResultSize); | |
166 test_assert_equal("Deutsch (Deutschland)", str); | |
167 | |
168 // make sure that NULL gives us the default locale as usual | |
169 ldn = uldn_open(NULL, ULDN_STANDARD_NAMES, &status); | |
170 const char *locale = uldn_getLocale(ldn); | |
171 if(0 != uprv_strcmp(uloc_getDefault(), locale)) { | |
172 errln("uldn_getLocale(uldn_open(NULL))=%s != default locale %s\n", locale, u
loc_getDefault()); | |
173 } | |
174 uldn_close(ldn); | |
175 test_assert(U_SUCCESS(status)); | |
176 } | |
177 | |
178 void LocaleDisplayNamesTest::TestUldnOpenDialect() { | |
179 UErrorCode status = U_ZERO_ERROR; | |
180 const int32_t kMaxResultSize = 150; // long enough | |
181 UChar result[150]; | |
182 ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_DIALECT_N
AMES, &status); | |
183 int32_t len = uldn_localeDisplayName(ldn, "en_GB", result, kMaxResultSize, &st
atus); | |
184 uldn_close(ldn); | |
185 test_assert(U_SUCCESS(status)); | |
186 | |
187 UnicodeString str(result, len, kMaxResultSize); | |
188 test_assert_equal("British English", str); | |
189 } | |
190 | |
191 void LocaleDisplayNamesTest::TestUldnWithKeywordsAndEverything() { | |
192 UErrorCode status = U_ZERO_ERROR; | |
193 const int32_t kMaxResultSize = 150; // long enough | |
194 UChar result[150]; | |
195 const char *locname = "en_Hant_US_VALLEY@calendar=gregorian;collation=phoneboo
k"; | |
196 const char *target = "English (Traditional, United States, VALLEY, " | |
197 "Gregorian Calendar, Phonebook Sort Order)"; | |
198 ULocaleDisplayNames *ldn = uldn_open(Locale::getUS().getName(), ULDN_STANDARD_
NAMES, &status); | |
199 int32_t len = uldn_localeDisplayName(ldn, locname, result, kMaxResultSize, &st
atus); | |
200 uldn_close(ldn); | |
201 test_assert(U_SUCCESS(status)); | |
202 | |
203 UnicodeString str(result, len, kMaxResultSize); | |
204 test_assert_equal(target, str); | |
205 } | |
206 | |
207 void LocaleDisplayNamesTest::TestUldnComponents() { | |
208 UErrorCode status = U_ZERO_ERROR; | |
209 const int32_t kMaxResultSize = 150; // long enough | |
210 UChar result[150]; | |
211 | |
212 ULocaleDisplayNames *ldn = uldn_open(Locale::getGermany().getName(), ULDN_STAN
DARD_NAMES, &status); | |
213 test_assert(U_SUCCESS(status)); | |
214 if (U_FAILURE(status)) { | |
215 return; | |
216 } | |
217 | |
218 // "en_Hant_US_PRE_EURO@calendar=gregorian"; | |
219 | |
220 { | |
221 int32_t len = uldn_languageDisplayName(ldn, "en", result, kMaxResultSize, &s
tatus); | |
222 UnicodeString str(result, len, kMaxResultSize); | |
223 test_assert_equal("Englisch", str); | |
224 } | |
225 | |
226 | |
227 { | |
228 int32_t len = uldn_scriptDisplayName(ldn, "Hant", result, kMaxResultSize, &s
tatus); | |
229 UnicodeString str(result, len, kMaxResultSize); | |
230 test_assert_equal("Traditionell", str); | |
231 } | |
232 | |
233 { | |
234 int32_t len = uldn_scriptCodeDisplayName(ldn, USCRIPT_TRADITIONAL_HAN, resul
t, kMaxResultSize, | |
235 &status); | |
236 UnicodeString str(result, len, kMaxResultSize); | |
237 test_assert_equal("Traditionell", str); | |
238 } | |
239 | |
240 { | |
241 int32_t len = uldn_regionDisplayName(ldn, "US", result, kMaxResultSize, &sta
tus); | |
242 UnicodeString str(result, len, kMaxResultSize); | |
243 test_assert_equal("Vereinigte Staaten", str); | |
244 } | |
245 | |
246 { | |
247 int32_t len = uldn_variantDisplayName(ldn, "PRE_EURO", result, kMaxResultSiz
e, &status); | |
248 UnicodeString str(result, len, kMaxResultSize); | |
249 test_assert_equal("PRE_EURO", str); | |
250 } | |
251 | |
252 { | |
253 int32_t len = uldn_keyDisplayName(ldn, "calendar", result, kMaxResultSize, &
status); | |
254 UnicodeString str(result, len, kMaxResultSize); | |
255 test_assert_equal("Kalender", str); | |
256 } | |
257 | |
258 { | |
259 int32_t len = uldn_keyValueDisplayName(ldn, "calendar", "gregorian", result,
| |
260 kMaxResultSize, &status); | |
261 UnicodeString str(result, len, kMaxResultSize); | |
262 test_assert_equal("Gregorianischer Kalender", str); | |
263 } | |
264 | |
265 uldn_close(ldn); | |
266 } | |
267 | |
268 | |
269 typedef struct { | |
270 const char * displayLocale; | |
271 UDisplayContext dialectHandling; | |
272 UDisplayContext capitalization; | |
273 UDisplayContext displayLength; | |
274 const char * localeToBeNamed; | |
275 const UChar * result; | |
276 } LocNameDispContextItem; | |
277 | |
278 static char en[] = "en"; | |
279 static char en_GB[] = "en_GB"; | |
280 | |
281 static UChar daFor_en[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"engel
sk" | |
282 static UChar daFor_en_GB[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x
53,0x74,0x6F,0x72,0x62,0x72,0x69,0x74,0x61,0x6E,0x6E,0x69,0x65,0x6E,0x29,0}; //"
engelsk (Storbritannien)" | |
283 static UChar daFor_en_GB_S[] = {0x65,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x
55,0x4B,0x29,0}; //"engelsk (UK)" | |
284 static UChar daFor_en_GB_D[] = {0x62,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x
6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"britisk engelsk" | |
285 static UChar esFor_en[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0}; //"ingles" wi
th acute on the e | |
286 static UChar esFor_en_GB[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x
65,0x69,0x6E,0x6F,0x20,0x55,0x6E,0x69,0x64,0x6F,0x29,0}; //"ingles (Reino Unido)
" ... | |
287 static UChar esFor_en_GB_S[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x
55,0x29,0}; //"ingles (RU)" ... | |
288 static UChar esFor_en_GB_D[] = {0x69,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x62,0x72,0x
69,0x74,0xE1,0x6E,0x69,0x63,0x6F,0}; //"ingles britanico" with acute on the e, a | |
289 #if !UCONFIG_NO_BREAK_ITERATION | |
290 static UChar daFor_en_T[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Engel
sk" | |
291 static UChar daFor_en_GB_T[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x
53,0x74,0x6F,0x72,0x62,0x72,0x69,0x74,0x61,0x6E,0x6E,0x69,0x65,0x6E,0x29,0}; //"
Engelsk (Storbritannien)" | |
292 static UChar daFor_en_GB_ST[] = {0x45,0x6E,0x67,0x65,0x6C,0x73,0x6B,0x20,0x28,0x
55,0x4B,0x29,0}; //"Engelsk (UK)" | |
293 static UChar daFor_en_GB_DT[] = {0x42,0x72,0x69,0x74,0x69,0x73,0x6B,0x20,0x65,0x
6E,0x67,0x65,0x6C,0x73,0x6B,0}; //"Britisk engelsk" | |
294 static UChar esFor_en_T[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0}; //"Ingles" wi
th acute on the e | |
295 static UChar esFor_en_GB_T[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x
65,0x69,0x6E,0x6F,0x20,0x55,0x6E,0x69,0x64,0x6F,0x29,0}; //"Ingles (Reino Unido)
" ... | |
296 static UChar esFor_en_GB_ST[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x28,0x52,0x
55,0x29,0}; //"Ingles (RU)" ... | |
297 static UChar esFor_en_GB_DT[] = {0x49,0x6E,0x67,0x6C,0xE9,0x73,0x20,0x62,0x72,0x
69,0x74,0xE1,0x6E,0x69,0x63,0x6F,0}; //"Ingles britanico" with acute on the e, a | |
298 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ | |
299 | |
300 static const LocNameDispContextItem ctxtItems[] = { | |
301 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_FULL, en, daFor_en }, | |
302 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB }, | |
303 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_S }, | |
304 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_D }, | |
305 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_FULL, en, esFor_en }, | |
306 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB }, | |
307 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_S }, | |
308 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTE
NCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_D }, | |
309 #if !UCONFIG_NO_BREAK_ITERATION | |
310 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_FULL, en, daFor_en_T }, | |
311 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_T }, | |
312 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_ST }, | |
313 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_DT }, | |
314 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_FULL, en, esFor_en_T }, | |
315 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_T }, | |
316 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_ST }, | |
317 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SE
NTENCE, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_DT }, | |
318 | |
319 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL, en, daFor_en_T }, | |
320 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_T }, | |
321 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_ST }, | |
322 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_DT }, | |
323 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL, en, esFor_en_T }, | |
324 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_T }, | |
325 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_ST }, | |
326 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
, UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_DT }, | |
327 | |
328 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_FULL, en, daFor_en }, | |
329 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB }, | |
330 { "da", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_SHORT, en_GB, daFor_en_GB_S }, | |
331 { "da", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_FULL, en_GB, daFor_en_GB_D }, | |
332 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_FULL, en, esFor_en_T }, | |
333 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_T }, | |
334 { "es", UDISPCTX_STANDARD_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_SHORT, en_GB, esFor_en_GB_ST }, | |
335 { "es", UDISPCTX_DIALECT_NAMES, UDISPCTX_CAPITALIZATION_FOR_STANDALONE,
UDISPCTX_LENGTH_FULL, en_GB, esFor_en_GB_DT }, | |
336 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ | |
337 { NULL, (UDisplayContext)0, (UDisplayContext)0,
(UDisplayContext)0, NULL, NULL } | |
338 }; | |
339 | |
340 void LocaleDisplayNamesTest::TestUldnDisplayContext() { | |
341 const LocNameDispContextItem * ctxtItemPtr; | |
342 for (ctxtItemPtr = ctxtItems; ctxtItemPtr->displayLocale != NULL; ctxtItemPt
r++) { | |
343 UDisplayContext contexts[3] = {ctxtItemPtr->dialectHandling, ctxtItemPtr
->capitalization, ctxtItemPtr->displayLength}; | |
344 UErrorCode status = U_ZERO_ERROR; | |
345 ULocaleDisplayNames * uldn = uldn_openForContext(ctxtItemPtr->displayLoc
ale, contexts, 3, &status); | |
346 if (U_FAILURE(status)) { | |
347 errln(UnicodeString("FAIL: uldn_openForContext failed for locale ")
+ ctxtItemPtr->displayLocale + | |
348 ", dialectHandling " + ctxtItemPtr->dialectHandling + | |
349 ", capitalization " + ctxtItemPtr->capitalization + | |
350 ", displayLength " + ctxtItemPtr->displayLength); | |
351 } else { | |
352 UDisplayContext dialectHandling = uldn_getContext(uldn, UDISPCTX_TYP
E_DIALECT_HANDLING, &status); | |
353 UDisplayContext capitalization = uldn_getContext(uldn, UDISPCTX_TYPE
_CAPITALIZATION, &status); | |
354 UDisplayContext displayLength = uldn_getContext(uldn, UDISPCTX_TYPE_
DISPLAY_LENGTH, &status); | |
355 if (U_FAILURE(status)) { | |
356 errln(UnicodeString("FAIL: uldn_getContext status ") + (int)stat
us); | |
357 } else if (dialectHandling != ctxtItemPtr->dialectHandling || | |
358 capitalization != ctxtItemPtr->capitalization || | |
359 displayLength != ctxtItemPtr->displayLength) { | |
360 errln("FAIL: uldn_getContext retrieved incorrect dialectHandling
, capitalization, or displayLength"); | |
361 } else { | |
362 UChar nameBuf[ULOC_FULLNAME_CAPACITY]; | |
363 int32_t len = uldn_localeDisplayName(uldn, ctxtItemPtr->localeTo
BeNamed, nameBuf, ULOC_FULLNAME_CAPACITY, &status); | |
364 if (U_FAILURE(status)) { | |
365 dataerrln(UnicodeString("FAIL: uldn_localeDisplayName status
: ") + u_errorName(status)); | |
366 } else if (u_strcmp(ctxtItemPtr->result, nameBuf) != 0) { | |
367 UnicodeString exp(ctxtItemPtr->result, u_strlen(ctxtItemPtr-
>result)); | |
368 UnicodeString got(nameBuf, len); | |
369 dataerrln(UnicodeString("FAIL: uldn_localeDisplayName, capit
alization ") + ctxtItemPtr->capitalization + | |
370 ", expected " + exp + ", got " + got ); | |
371 } | |
372 } | |
373 uldn_close(uldn); | |
374 } | |
375 } | |
376 } | |
377 | |
378 void LocaleDisplayNamesTest::TestRootEtc() { | |
379 UnicodeString temp; | |
380 LocaleDisplayNames *ldn = LocaleDisplayNames::createInstance(Locale::getUS()); | |
381 const char *locname = "@collation=phonebook"; | |
382 const char *target = "Root (Phonebook Sort Order)"; | |
383 ldn->localeDisplayName(locname, temp); | |
384 test_assert_equal(target, temp); | |
385 | |
386 ldn->languageDisplayName("root", temp); | |
387 test_assert_equal("root", temp); | |
388 | |
389 ldn->languageDisplayName("en_GB", temp); | |
390 test_assert_equal("en_GB", temp); | |
391 | |
392 delete ldn; | |
393 } | |
394 | |
395 #endif /* UCONFIG_NO_FORMATTING */ | |
OLD | NEW |