OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 1997-2014, International Business Machines Corporation and * | 3 * Copyright (C) 1997-2015, International Business Machines Corporation and * |
4 * others. All Rights Reserved. * | 4 * others. All Rights Reserved. * |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 * | 6 * |
7 * File COMPACTDECIMALFORMATTEST.CPP | 7 * File COMPACTDECIMALFORMATTEST.CPP |
8 * | 8 * |
9 ******************************************************************************** | 9 ******************************************************************************** |
10 */ | 10 */ |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 | 13 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 {-1.23456789E10, "-12 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434
\\u0438"}, | 93 {-1.23456789E10, "-12 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434
\\u0438"}, |
94 {-2.08901234E10, "-21 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434
\\u0430"}, | 94 {-2.08901234E10, "-21 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434
\\u0430"}, |
95 {-2.18901234E10, "-22 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434
\\u0435"}, | 95 {-2.18901234E10, "-22 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434
\\u0435"}, |
96 {-1.23456789E11, "-120 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u043
4\\u0438"}, | 96 {-1.23456789E11, "-120 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u043
4\\u0438"}, |
97 {-1.23456789E12, "-1,2 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u043
0"}, | 97 {-1.23456789E12, "-1,2 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u043
0"}, |
98 {-1.23456789E13, "-12 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430
"}, | 98 {-1.23456789E13, "-12 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430
"}, |
99 {-1.23456789E14, "-120 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u043
0"}, | 99 {-1.23456789E14, "-120 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u043
0"}, |
100 {-1.23456789E15, "-1200 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u04
30"}}; | 100 {-1.23456789E15, "-1200 \\u0442\\u0440\\u0438\\u043B\\u0438\\u043E\\u043D\\u04
30"}}; |
101 | 101 |
102 static ExpectedResult kJapaneseShort[] = { | 102 static ExpectedResult kJapaneseShort[] = { |
103 {1234.0, "1.2\\u5343"}, | 103 {1234.0, "1200"}, |
104 {12345.0, "1.2\\u4E07"}, | 104 {12345.0, "1.2\\u4E07"}, |
105 {123456.0, "12\\u4E07"}, | 105 {123456.0, "12\\u4E07"}, |
106 {1234567.0, "120\\u4E07"}, | 106 {1234567.0, "120\\u4E07"}, |
107 {12345678.0, "1200\\u4E07"}, | 107 {12345678.0, "1200\\u4E07"}, |
108 {123456789.0, "1.2\\u5104"}, | 108 {123456789.0, "1.2\\u5104"}, |
109 {1.23456789E9, "12\\u5104"}, | 109 {1.23456789E9, "12\\u5104"}, |
110 {1.23456789E10, "120\\u5104"}, | 110 {1.23456789E10, "120\\u5104"}, |
111 {1.23456789E11, "1200\\u5104"}, | 111 {1.23456789E11, "1200\\u5104"}, |
112 {1.23456789E12, "1.2\\u5146"}, | 112 {1.23456789E12, "1.2\\u5146"}, |
113 {1.23456789E13, "12\\u5146"}, | 113 {1.23456789E13, "12\\u5146"}, |
(...skipping 24 matching lines...) Expand all Loading... |
138 {127123456.0, "130\\u00a0mil."}, | 138 {127123456.0, "130\\u00a0mil."}, |
139 {1.27123456E9, "1,3\\u00a0mld."}, | 139 {1.27123456E9, "1,3\\u00a0mld."}, |
140 {1.27123456E10, "13\\u00a0mld."}, | 140 {1.27123456E10, "13\\u00a0mld."}, |
141 {1.27123456E11, "130\\u00a0mld."}, | 141 {1.27123456E11, "130\\u00a0mld."}, |
142 {1.27123456E12, "1,3\\u00a0bil."}, | 142 {1.27123456E12, "1,3\\u00a0bil."}, |
143 {1.27123456E13, "13\\u00a0bil."}, | 143 {1.27123456E13, "13\\u00a0bil."}, |
144 {1.27123456E14, "130\\u00a0bil."}}; | 144 {1.27123456E14, "130\\u00a0bil."}}; |
145 | 145 |
146 static ExpectedResult kSkLong[] = { | 146 static ExpectedResult kSkLong[] = { |
147 {1000.0, "1 tis\\u00edc"}, | 147 {1000.0, "1 tis\\u00edc"}, |
148 {1572.0, "1,6 tis\\u00edc"}, | 148 {1572.0, "1,6 tis\\u00edca"}, |
149 {5184.0, "5,2 tis\\u00edc"}}; | 149 {5184.0, "5,2 tis\\u00edca"}}; |
150 | 150 |
151 static ExpectedResult kSwahiliShortNegative[] = { | 151 static ExpectedResult kSwahiliShortNegative[] = { |
152 {-1234.0, "elfu\\u00a0-1.2"}, | 152 {-1234.0, "elfu\\u00a0-1.2"}, |
153 {-12345.0, "elfu\\u00a0-12"}, | 153 {-12345.0, "elfu\\u00a0-12"}, |
154 {-123456.0, "elfu\\u00a0-120"}, | 154 {-123456.0, "elfu\\u00a0-120"}, |
155 {-1234567.0, "M-1.2"}, | 155 {-1234567.0, "M-1.2"}, |
156 {-12345678.0, "M-12"}, | 156 {-12345678.0, "M-12"}, |
157 {-123456789.0, "M-120"}, | 157 {-123456789.0, "M-120"}, |
158 {-1.23456789E9, "B-1.2"}, | 158 {-1.23456789E9, "B-1.2"}, |
159 {-1.23456789E10, "B-12"}, | 159 {-1.23456789E10, "B-12"}, |
(...skipping 18 matching lines...) Expand all Loading... |
178 void TestSerbianLong(); | 178 void TestSerbianLong(); |
179 void TestSerbianLongNegative(); | 179 void TestSerbianLongNegative(); |
180 void TestJapaneseShort(); | 180 void TestJapaneseShort(); |
181 void TestSwahiliShort(); | 181 void TestSwahiliShort(); |
182 void TestCsShort(); | 182 void TestCsShort(); |
183 void TestSkLong(); | 183 void TestSkLong(); |
184 void TestSwahiliShortNegative(); | 184 void TestSwahiliShortNegative(); |
185 void TestArabicLong(); | 185 void TestArabicLong(); |
186 void TestFieldPosition(); | 186 void TestFieldPosition(); |
187 void TestSignificantDigits(); | 187 void TestSignificantDigits(); |
| 188 void TestAPIVariants(); |
188 void CheckLocale( | 189 void CheckLocale( |
189 const Locale& locale, UNumberCompactStyle style, | 190 const Locale& locale, UNumberCompactStyle style, |
190 const ExpectedResult* expectedResult, int32_t expectedResultLength); | 191 const ExpectedResult* expectedResult, int32_t expectedResultLength); |
191 void CheckExpectedResult( | 192 void CheckExpectedResult( |
192 const CompactDecimalFormat* cdf, const ExpectedResult* expectedResult, | 193 const CompactDecimalFormat* cdf, const ExpectedResult* expectedResult, |
193 const char* description); | 194 const char* description); |
194 CompactDecimalFormat* createCDFInstance(const Locale& locale, UNumberCompact
Style style, UErrorCode& status); | 195 CompactDecimalFormat* createCDFInstance(const Locale& locale, UNumberCompact
Style style, UErrorCode& status); |
195 static const char *StyleStr(UNumberCompactStyle style); | 196 static const char *StyleStr(UNumberCompactStyle style); |
196 }; | 197 }; |
197 | 198 |
198 void CompactDecimalFormatTest::runIndexedTest( | 199 void CompactDecimalFormatTest::runIndexedTest( |
199 int32_t index, UBool exec, const char *&name, char *) { | 200 int32_t index, UBool exec, const char *&name, char *) { |
200 if (exec) { | 201 if (exec) { |
201 logln("TestSuite CompactDecimalFormatTest: "); | 202 logln("TestSuite CompactDecimalFormatTest: "); |
202 } | 203 } |
203 TESTCASE_AUTO_BEGIN; | 204 TESTCASE_AUTO_BEGIN; |
204 TESTCASE_AUTO(TestEnglishShort); | 205 TESTCASE_AUTO(TestEnglishShort); |
205 TESTCASE_AUTO(TestSerbianShort); | 206 TESTCASE_AUTO(TestSerbianShort); |
206 TESTCASE_AUTO(TestSerbianLong); | 207 TESTCASE_AUTO(TestSerbianLong); |
207 TESTCASE_AUTO(TestSerbianLongNegative); | 208 TESTCASE_AUTO(TestSerbianLongNegative); |
208 TESTCASE_AUTO(TestJapaneseShort); | 209 TESTCASE_AUTO(TestJapaneseShort); |
209 TESTCASE_AUTO(TestSwahiliShort); | 210 TESTCASE_AUTO(TestSwahiliShort); |
210 TESTCASE_AUTO(TestCsShort); | 211 TESTCASE_AUTO(TestCsShort); |
211 TESTCASE_AUTO(TestSkLong); | 212 TESTCASE_AUTO(TestSkLong); |
212 TESTCASE_AUTO(TestSwahiliShortNegative); | 213 TESTCASE_AUTO(TestSwahiliShortNegative); |
213 TESTCASE_AUTO(TestArabicLong); | 214 TESTCASE_AUTO(TestArabicLong); |
214 TESTCASE_AUTO(TestFieldPosition); | 215 TESTCASE_AUTO(TestFieldPosition); |
215 TESTCASE_AUTO(TestSignificantDigits); | 216 TESTCASE_AUTO(TestSignificantDigits); |
| 217 TESTCASE_AUTO(TestAPIVariants); |
216 TESTCASE_AUTO_END; | 218 TESTCASE_AUTO_END; |
217 } | 219 } |
218 | 220 |
219 void CompactDecimalFormatTest::TestEnglishShort() { | 221 void CompactDecimalFormatTest::TestEnglishShort() { |
220 CheckLocale("en", UNUM_SHORT, kEnglishShort, UPRV_LENGTHOF(kEnglishShort)); | 222 CheckLocale("en", UNUM_SHORT, kEnglishShort, UPRV_LENGTHOF(kEnglishShort)); |
221 } | 223 } |
222 | 224 |
223 void CompactDecimalFormatTest::TestSerbianShort() { | 225 void CompactDecimalFormatTest::TestSerbianShort() { |
224 CheckLocale("sr", UNUM_SHORT, kSerbianShort, UPRV_LENGTHOF(kSerbianShort)); | 226 CheckLocale("sr", UNUM_SHORT, kSerbianShort, UPRV_LENGTHOF(kSerbianShort)); |
225 } | 227 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 289 } |
288 UnicodeString actual; | 290 UnicodeString actual; |
289 cdf->format(123456.0, actual); | 291 cdf->format(123456.0, actual); |
290 // We expect 3 significant digits by default | 292 // We expect 3 significant digits by default |
291 UnicodeString expected("123K", -1, US_INV); | 293 UnicodeString expected("123K", -1, US_INV); |
292 if (actual != expected) { | 294 if (actual != expected) { |
293 errln(UnicodeString("Fail: Expected: ") + expected + UnicodeString(" Got: ")
+ actual); | 295 errln(UnicodeString("Fail: Expected: ") + expected + UnicodeString(" Got: ")
+ actual); |
294 } | 296 } |
295 } | 297 } |
296 | 298 |
| 299 void CompactDecimalFormatTest::TestAPIVariants() { |
| 300 UErrorCode status = U_ZERO_ERROR; |
| 301 LocalPointer<CompactDecimalFormat> cdf(CompactDecimalFormat::createInstance("e
n", UNUM_SHORT, status)); |
| 302 if (U_FAILURE(status)) { |
| 303 dataerrln("Unable to create format object - %s", u_errorName(status)); |
| 304 return; |
| 305 } |
| 306 UnicodeString actual; |
| 307 FieldPosition pos; |
| 308 FieldPositionIterator posIter; |
| 309 UnicodeString expected("123K", -1, US_INV); |
| 310 pos.setField(UNUM_INTEGER_FIELD); |
| 311 |
| 312 actual.remove(); |
| 313 pos.setBeginIndex(0); |
| 314 pos.setEndIndex(0); |
| 315 cdf->format((double)123456.0, actual, pos); |
| 316 if (actual != expected || pos.getEndIndex() != 3) { |
| 317 errln(UnicodeString("Fail format(double,UnicodeString&,FieldPosition&): Expe
cted: \"") + expected + "\", pos 3; " + |
| 318 "Got:
\"" + actual + "\", pos " + pos.getEndIndex()); |
| 319 } |
| 320 |
| 321 actual.remove(); |
| 322 pos.setBeginIndex(0); |
| 323 pos.setEndIndex(0); |
| 324 status = U_ZERO_ERROR; |
| 325 cdf->format((double)123456.0, actual, pos, status); |
| 326 if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { |
| 327 errln(UnicodeString("Fail format(double,UnicodeString&,FieldPosition&,UError
Code&): Expected: \"") + expected + "\", pos 3, status U_ZERO_ERROR; " + |
| 328 "Got: \"" + actual
+ "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); |
| 329 } |
| 330 |
| 331 actual.remove(); |
| 332 status = U_ZERO_ERROR; |
| 333 cdf->format((double)123456.0, actual, &posIter, status); |
| 334 if (status != U_UNSUPPORTED_ERROR) { |
| 335 errln(UnicodeString("Fail format(double,UnicodeString&,FieldPositionIterator
*,UErrorCode&): Expected status U_UNSUPPORTED_ERROR;") + |
| 336 "Got status " + u_
errorName(status)); |
| 337 } |
| 338 |
| 339 actual.remove(); |
| 340 pos.setBeginIndex(0); |
| 341 pos.setEndIndex(0); |
| 342 cdf->format((int32_t)123456, actual, pos); |
| 343 if (actual != expected || pos.getEndIndex() != 3) { |
| 344 errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&): Exp
ected: \"") + expected + "\", pos 3; " + |
| 345 "Got:
\"" + actual + "\", pos " + pos.getEndIndex()); |
| 346 } |
| 347 |
| 348 actual.remove(); |
| 349 pos.setBeginIndex(0); |
| 350 pos.setEndIndex(0); |
| 351 status = U_ZERO_ERROR; |
| 352 cdf->format((int32_t)123456, actual, pos, status); |
| 353 if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { |
| 354 errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErro
rCode&): Expected: \"") + expected + "\", pos 3, status U_ZERO_ERROR; " + |
| 355 "Got: \"" + actual
+ "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); |
| 356 } |
| 357 |
| 358 actual.remove(); |
| 359 status = U_ZERO_ERROR; |
| 360 cdf->format((int32_t)123456, actual, &posIter, status); |
| 361 if (status != U_UNSUPPORTED_ERROR) { |
| 362 errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPositionIterato
r*,UErrorCode&): Expected status U_UNSUPPORTED_ERROR;") + |
| 363 "Got status " + u_
errorName(status)); |
| 364 } |
| 365 |
| 366 actual.remove(); |
| 367 pos.setBeginIndex(0); |
| 368 pos.setEndIndex(0); |
| 369 cdf->format((int64_t)123456, actual, pos); |
| 370 if (actual != expected || pos.getEndIndex() != 3) { |
| 371 errln(UnicodeString("Fail format(int64_t,UnicodeString&,FieldPosition&): Exp
ected: \"") + expected + "\", pos 3; " + |
| 372 "Got:
\"" + actual + "\", pos " + pos.getEndIndex()); |
| 373 } |
| 374 |
| 375 actual.remove(); |
| 376 pos.setBeginIndex(0); |
| 377 pos.setEndIndex(0); |
| 378 status = U_ZERO_ERROR; |
| 379 cdf->format((int64_t)123456, actual, pos, status); |
| 380 if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { |
| 381 errln(UnicodeString("Fail format(int64_t,UnicodeString&,FieldPosition&,UErro
rCode&): Expected: \"") + expected + "\", pos 3, status U_ZERO_ERROR; " + |
| 382 "Got: \"" + actual
+ "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); |
| 383 } |
| 384 |
| 385 actual.remove(); |
| 386 status = U_ZERO_ERROR; |
| 387 cdf->format((int64_t)123456, actual, &posIter, status); |
| 388 if (status != U_UNSUPPORTED_ERROR) { |
| 389 errln(UnicodeString("Fail format(int64_t,UnicodeString&,FieldPositionIterato
r*,UErrorCode&): Expected status U_UNSUPPORTED_ERROR;") + |
| 390 "Got status " + u_
errorName(status)); |
| 391 } |
| 392 |
| 393 } |
| 394 |
297 void CompactDecimalFormatTest::CheckLocale(const Locale& locale, UNumberCompactS
tyle style, const ExpectedResult* expectedResults, int32_t expectedResultLength)
{ | 395 void CompactDecimalFormatTest::CheckLocale(const Locale& locale, UNumberCompactS
tyle style, const ExpectedResult* expectedResults, int32_t expectedResultLength)
{ |
298 UErrorCode status = U_ZERO_ERROR; | 396 UErrorCode status = U_ZERO_ERROR; |
299 LocalPointer<CompactDecimalFormat> cdf(createCDFInstance(locale, style, status
)); | 397 LocalPointer<CompactDecimalFormat> cdf(createCDFInstance(locale, style, status
)); |
300 if (U_FAILURE(status)) { | 398 if (U_FAILURE(status)) { |
301 dataerrln("Unable to create format object - %s", u_errorName(status)); | 399 dataerrln("Unable to create format object - %s", u_errorName(status)); |
302 return; | 400 return; |
303 } | 401 } |
304 char description[256]; | 402 char description[256]; |
305 sprintf(description,"%s - %s", locale.getName(), StyleStr(style)); | 403 sprintf(description,"%s - %s", locale.getName(), StyleStr(style)); |
306 for (int32_t i = 0; i < expectedResultLength; i++) { | 404 for (int32_t i = 0; i < expectedResultLength; i++) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 return kShortStr; | 436 return kShortStr; |
339 } | 437 } |
340 return kLongStr; | 438 return kLongStr; |
341 } | 439 } |
342 | 440 |
343 extern IntlTest *createCompactDecimalFormatTest() { | 441 extern IntlTest *createCompactDecimalFormatTest() { |
344 return new CompactDecimalFormatTest(); | 442 return new CompactDecimalFormatTest(); |
345 } | 443 } |
346 | 444 |
347 #endif | 445 #endif |
OLD | NEW |