1 /*********************************************************************
3 * Copyright (c) 2010, 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
);
83 #if !UCONFIG_NO_FORMATTING
84 void LocaleDisplayNamesTest::TestCreate() {
86 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getGermany());
87 ldn
->localeDisplayName("de_DE", temp
);
89 test_assert_equal("Deutsch (Deutschland)", temp
);
92 void LocaleDisplayNamesTest::TestCreateDialect() {
94 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS(), ULDN_DIALECT_NAMES
);
95 ldn
->localeDisplayName("en_GB", temp
);
97 test_assert_equal("British English", temp
);
100 void LocaleDisplayNamesTest::TestWithKeywordsAndEverything() {
102 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
103 const char *locname
= "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
104 const char *target
= "English (Traditional Han, United States, VALLEY, "
105 "Calendar=Gregorian Calendar, Collation=Phonebook Sort Order)";
106 ldn
->localeDisplayName(locname
, temp
);
108 test_assert_equal(target
, temp
);
111 void LocaleDisplayNamesTest::TestUldnOpen() {
112 UErrorCode status
= U_ZERO_ERROR
;
113 const int32_t kMaxResultSize
= 150; // long enough
115 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
116 int32_t len
= uldn_localeDisplayName(ldn
, "de_DE", result
, kMaxResultSize
, &status
);
118 test_assert(U_SUCCESS(status
));
120 UnicodeString
str(result
, len
, kMaxResultSize
);
121 test_assert_equal("Deutsch (Deutschland)", str
);
123 // make sure that NULL gives us the default locale as usual
124 ldn
= uldn_open(NULL
, ULDN_STANDARD_NAMES
, &status
);
125 const char *locale
= uldn_getLocale(ldn
);
126 if(0 != uprv_strcmp(uloc_getDefault(), locale
)) {
127 errln("uldn_getLocale(uldn_open(NULL))=%s != default locale %s\n", locale
, uloc_getDefault());
130 test_assert(U_SUCCESS(status
));
133 void LocaleDisplayNamesTest::TestUldnOpenDialect() {
134 UErrorCode status
= U_ZERO_ERROR
;
135 const int32_t kMaxResultSize
= 150; // long enough
137 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getUS().getName(), ULDN_DIALECT_NAMES
, &status
);
138 int32_t len
= uldn_localeDisplayName(ldn
, "en_GB", result
, kMaxResultSize
, &status
);
140 test_assert(U_SUCCESS(status
));
142 UnicodeString
str(result
, len
, kMaxResultSize
);
143 test_assert_equal("British English", str
);
146 void LocaleDisplayNamesTest::TestUldnWithKeywordsAndEverything() {
147 UErrorCode status
= U_ZERO_ERROR
;
148 const int32_t kMaxResultSize
= 150; // long enough
150 const char *locname
= "en_Hant_US_VALLEY@calendar=gregorian;collation=phonebook";
151 const char *target
= "English (Traditional Han, United States, VALLEY, "
152 "Calendar=Gregorian Calendar, Collation=Phonebook Sort Order)";
153 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getUS().getName(), ULDN_STANDARD_NAMES
, &status
);
154 int32_t len
= uldn_localeDisplayName(ldn
, locname
, result
, kMaxResultSize
, &status
);
156 test_assert(U_SUCCESS(status
));
158 UnicodeString
str(result
, len
, kMaxResultSize
);
159 test_assert_equal(target
, str
);
162 void LocaleDisplayNamesTest::TestUldnComponents() {
163 UErrorCode status
= U_ZERO_ERROR
;
164 const int32_t kMaxResultSize
= 150; // long enough
167 ULocaleDisplayNames
*ldn
= uldn_open(Locale::getGermany().getName(), ULDN_STANDARD_NAMES
, &status
);
168 test_assert(U_SUCCESS(status
));
169 if (U_FAILURE(status
)) {
173 // "en_Hant_US_PRE_EURO@calendar=gregorian";
176 int32_t len
= uldn_languageDisplayName(ldn
, "en", result
, kMaxResultSize
, &status
);
177 UnicodeString
str(result
, len
, kMaxResultSize
);
178 test_assert_equal("Englisch", str
);
183 int32_t len
= uldn_scriptDisplayName(ldn
, "Hant", result
, kMaxResultSize
, &status
);
184 UnicodeString
str(result
, len
, kMaxResultSize
);
185 test_assert_equal("Traditionelle Chinesische Schrift", str
);
189 int32_t len
= uldn_scriptCodeDisplayName(ldn
, USCRIPT_TRADITIONAL_HAN
, result
, kMaxResultSize
,
191 UnicodeString
str(result
, len
, kMaxResultSize
);
192 test_assert_equal("Traditionelle Chinesische Schrift", str
);
196 int32_t len
= uldn_regionDisplayName(ldn
, "US", result
, kMaxResultSize
, &status
);
197 UnicodeString
str(result
, len
, kMaxResultSize
);
198 test_assert_equal("Vereinigte Staaten", str
);
202 int32_t len
= uldn_variantDisplayName(ldn
, "PRE_EURO", result
, kMaxResultSize
, &status
);
203 UnicodeString
str(result
, len
, kMaxResultSize
);
204 test_assert_equal("PRE_EURO", str
);
208 int32_t len
= uldn_keyDisplayName(ldn
, "calendar", result
, kMaxResultSize
, &status
);
209 UnicodeString
str(result
, len
, kMaxResultSize
);
210 test_assert_equal("Kalender", str
);
214 int32_t len
= uldn_keyValueDisplayName(ldn
, "calendar", "gregorian", result
,
215 kMaxResultSize
, &status
);
216 UnicodeString
str(result
, len
, kMaxResultSize
);
217 test_assert_equal("Gregorianischer Kalender", str
);
223 void LocaleDisplayNamesTest::TestRootEtc() {
225 LocaleDisplayNames
*ldn
= LocaleDisplayNames::createInstance(Locale::getUS());
226 const char *locname
= "@collation=phonebook";
227 const char *target
= "Root (Collation=Phonebook Sort Order)";
228 ldn
->localeDisplayName(locname
, temp
);
229 test_assert_equal(target
, temp
);
231 ldn
->languageDisplayName("root", temp
);
232 test_assert_equal("root", temp
);
234 ldn
->languageDisplayName("en_GB", temp
);
235 test_assert_equal("en_GB", temp
);
240 #endif /* UCONFIG_NO_FORMATTING */