1 /*********************************************************************
3 * Copyright (c) 2010-2012, 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, TestKeywords
);
77 TESTCASE(9, TestUntranslatedKeywords
);
78 TESTCASE(10, TestPrivateUse
);
86 #if !UCONFIG_NO_FORMATTING
87 void LocaleDisplayNamesTest::TestCreate() {
89 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getGermany());
90 ldn
->localeDisplayName("de_DE", temp
);
92 test_assert_equal("Deutsch (Deutschland)", temp
);
95 void LocaleDisplayNamesTest::TestCreateDialect() {
97 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS(), ULDN_DIALECT_NAMES
);
98 ldn
->localeDisplayName("en_GB", temp
);
100 test_assert_equal("British English", temp
);
103 void LocaleDisplayNamesTest::TestWithKeywordsAndEverything() {
105 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
106 const char *locname
= "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
107 const char *target
= "English (Traditional, United States, VALLEY, "
108 "Gregorian Calendar, Phonebook Sort Order)";
109 ldn
->localeDisplayName(locname
, temp
);
111 test_assert_equal(target
, temp
);
114 void LocaleDisplayNamesTest::TestKeywords() {
116 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
117 const char *locname
= "de@currency=XYZ";
118 const char *target
= "German (Currency: XYZ)";
119 ldn
->localeDisplayName(locname
, temp
);
121 test_assert_equal(target
, temp
);
124 void LocaleDisplayNamesTest::TestUntranslatedKeywords() {
126 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
127 const char *locname
= "de@foo=bar";
128 const char *target
= "German (foo=bar)";
129 ldn
->localeDisplayName(locname
, temp
);
131 test_assert_equal(target
, temp
);
134 void LocaleDisplayNamesTest::TestPrivateUse() {
136 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
137 const char *locname
= "de@x=foobar";
138 const char *target
= "German (Private-Use: foobar)";
139 ldn
->localeDisplayName(locname
, temp
);
141 test_assert_equal(target
, temp
);
144 void LocaleDisplayNamesTest::TestUldnOpen() {
145 UErrorCode status
= U_ZERO_ERROR
;
146 const int32_t kMaxResultSize
= 150; // long enough
148 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
149 int32_t len
= uldn_localeDisplayName(ldn
, "de_DE", result
, kMaxResultSize
, &status
);
151 test_assert(U_SUCCESS(status
));
153 UnicodeString
str(result
, len
, kMaxResultSize
);
154 test_assert_equal("Deutsch (Deutschland)", str
);
156 // make sure that NULL gives us the default locale as usual
157 ldn
= uldn_open(NULL
, ULDN_STANDARD_NAMES
, &status
);
158 const char *locale
= uldn_getLocale(ldn
);
159 if(0 != uprv_strcmp(uloc_getDefault(), locale
)) {
160 errln("uldn_getLocale(uldn_open(NULL))=%s != default locale %s\n", locale
, uloc_getDefault());
163 test_assert(U_SUCCESS(status
));
166 void LocaleDisplayNamesTest::TestUldnOpenDialect() {
167 UErrorCode status
= U_ZERO_ERROR
;
168 const int32_t kMaxResultSize
= 150; // long enough
170 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES
, &status
);
171 int32_t len
= uldn_localeDisplayName(ldn
, "en_GB", result
, kMaxResultSize
, &status
);
173 test_assert(U_SUCCESS(status
));
175 UnicodeString
str(result
, len
, kMaxResultSize
);
176 test_assert_equal("British English", str
);
179 void LocaleDisplayNamesTest::TestUldnWithKeywordsAndEverything() {
180 UErrorCode status
= U_ZERO_ERROR
;
181 const int32_t kMaxResultSize
= 150; // long enough
183 const char *locname
= "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
184 const char *target
= "English (Traditional, United States, VALLEY, "
185 "Gregorian Calendar, Phonebook Sort Order)";
186 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getUS().getName(), ULDN_STANDARD_NAMES
, &status
);
187 int32_t len
= uldn_localeDisplayName(ldn
, locname
, result
, kMaxResultSize
, &status
);
189 test_assert(U_SUCCESS(status
));
191 UnicodeString
str(result
, len
, kMaxResultSize
);
192 test_assert_equal(target
, str
);
195 void LocaleDisplayNamesTest::TestUldnComponents() {
196 UErrorCode status
= U_ZERO_ERROR
;
197 const int32_t kMaxResultSize
= 150; // long enough
200 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
201 test_assert(U_SUCCESS(status
));
202 if (U_FAILURE(status
)) {
206 // "en_Hant_US_PRE_EURO@calendar=gregorian";
209 int32_t len
= uldn_languageDisplayName(ldn
, "en", result
, kMaxResultSize
, &status
);
210 UnicodeString
str(result
, len
, kMaxResultSize
);
211 test_assert_equal("Englisch", str
);
216 int32_t len
= uldn_scriptDisplayName(ldn
, "Hant", result
, kMaxResultSize
, &status
);
217 UnicodeString
str(result
, len
, kMaxResultSize
);
218 test_assert_equal("Traditionell", str
);
222 int32_t len
= uldn_scriptCodeDisplayName(ldn
, USCRIPT_TRADITIONAL_HAN
, result
, kMaxResultSize
,
224 UnicodeString
str(result
, len
, kMaxResultSize
);
225 test_assert_equal("Traditionell", str
);
229 int32_t len
= uldn_regionDisplayName(ldn
, "US", result
, kMaxResultSize
, &status
);
230 UnicodeString
str(result
, len
, kMaxResultSize
);
231 test_assert_equal("Vereinigte Staaten", str
);
235 int32_t len
= uldn_variantDisplayName(ldn
, "PRE_EURO", result
, kMaxResultSize
, &status
);
236 UnicodeString
str(result
, len
, kMaxResultSize
);
237 test_assert_equal("PRE_EURO", str
);
241 int32_t len
= uldn_keyDisplayName(ldn
, "calendar", result
, kMaxResultSize
, &status
);
242 UnicodeString
str(result
, len
, kMaxResultSize
);
243 test_assert_equal("Kalender", str
);
247 int32_t len
= uldn_keyValueDisplayName(ldn
, "calendar", "gregorian", result
,
248 kMaxResultSize
, &status
);
249 UnicodeString
str(result
, len
, kMaxResultSize
);
250 test_assert_equal("Gregorianischer Kalender", str
);
256 void LocaleDisplayNamesTest::TestRootEtc() {
258 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
259 const char *locname
= "@collation=phonebook";
260 const char *target
= "Root (Phonebook Sort Order)";
261 ldn
->localeDisplayName(locname
, temp
);
262 test_assert_equal(target
, temp
);
264 ldn
->languageDisplayName("root", temp
);
265 test_assert_equal("root", temp
);
267 ldn
->languageDisplayName("en_GB", temp
);
268 test_assert_equal("en_GB", temp
);
273 #endif /* UCONFIG_NO_FORMATTING */