Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: source/test/intltest/numfmtst.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/intltest/numfmtst.h ('k') | source/test/intltest/numrgts.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
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 /* Modification History: 6 /* Modification History:
7 * Date Name Description 7 * Date Name Description
8 * 07/15/99 helena Ported to HPUX 10/11 CC. 8 * 07/15/99 helena Ported to HPUX 10/11 CC.
9 */ 9 */
10 10
11 #include "unicode/utypes.h" 11 #include "unicode/utypes.h"
12 12
13 #if !UCONFIG_NO_FORMATTING 13 #if !UCONFIG_NO_FORMATTING
(...skipping 11 matching lines...) Expand all
25 #include "tokiter.h" 25 #include "tokiter.h"
26 #include "charstr.h" 26 #include "charstr.h"
27 #include "putilimp.h" 27 #include "putilimp.h"
28 #include "winnmtst.h" 28 #include "winnmtst.h"
29 #include <float.h> 29 #include <float.h>
30 #include <string.h> 30 #include <string.h>
31 #include <stdlib.h> 31 #include <stdlib.h>
32 #include "cstring.h" 32 #include "cstring.h"
33 #include "unicode/numsys.h" 33 #include "unicode/numsys.h"
34 #include "fmtableimp.h" 34 #include "fmtableimp.h"
35 #include "numberformattesttuple.h"
36 #include "datadrivennumberformattestsuite.h"
37 #include "unicode/msgfmt.h"
38
39 class NumberFormatTestDataDriven : public DataDrivenNumberFormatTestSuite {
40 protected:
41 UBool isFormatPass(
42 const NumberFormatTestTuple &tuple,
43 UnicodeString &appendErrorMessage,
44 UErrorCode &status);
45 UBool isToPatternPass(
46 const NumberFormatTestTuple &tuple,
47 UnicodeString &appendErrorMessage,
48 UErrorCode &status);
49 UBool isParsePass(
50 const NumberFormatTestTuple &tuple,
51 UnicodeString &appendErrorMessage,
52 UErrorCode &status);
53 UBool isParseCurrencyPass(
54 const NumberFormatTestTuple &tuple,
55 UnicodeString &appendErrorMessage,
56 UErrorCode &status);
57 };
58
59 static DigitList &strToDigitList(
60 const UnicodeString &str,
61 DigitList &digitList,
62 UErrorCode &status) {
63 if (U_FAILURE(status)) {
64 return digitList;
65 }
66 if (str == "NaN") {
67 digitList.set(uprv_getNaN());
68 return digitList;
69 }
70 if (str == "-Inf") {
71 digitList.set(-1*uprv_getInfinity());
72 return digitList;
73 }
74 if (str == "Inf") {
75 digitList.set(uprv_getInfinity());
76 return digitList;
77 }
78 CharString formatValue;
79 formatValue.appendInvariantChars(str, status);
80 digitList.set(StringPiece(formatValue.data()), status, 0);
81 return digitList;
82 }
83
84 static UnicodeString &format(
85 const DecimalFormat &fmt,
86 const DigitList &digitList,
87 UnicodeString &appendTo,
88 UErrorCode &status) {
89 if (U_FAILURE(status)) {
90 return appendTo;
91 }
92 FieldPosition fpos(FieldPosition::DONT_CARE);
93 return fmt.format(digitList, appendTo, fpos, status);
94 }
95
96 template<class T>
97 static UnicodeString &format(
98 const DecimalFormat &fmt,
99 T value,
100 UnicodeString &appendTo,
101 UErrorCode &status) {
102 if (U_FAILURE(status)) {
103 return appendTo;
104 }
105 FieldPosition fpos(FieldPosition::DONT_CARE);
106 return fmt.format(value, appendTo, fpos, status);
107 }
108
109 static void adjustDecimalFormat(
110 const NumberFormatTestTuple &tuple,
111 DecimalFormat &fmt,
112 UnicodeString &appendErrorMessage) {
113 if (tuple.minIntegerDigitsFlag) {
114 fmt.setMinimumIntegerDigits(tuple.minIntegerDigits);
115 }
116 if (tuple.maxIntegerDigitsFlag) {
117 fmt.setMaximumIntegerDigits(tuple.maxIntegerDigits);
118 }
119 if (tuple.minFractionDigitsFlag) {
120 fmt.setMinimumFractionDigits(tuple.minFractionDigits);
121 }
122 if (tuple.maxFractionDigitsFlag) {
123 fmt.setMaximumFractionDigits(tuple.maxFractionDigits);
124 }
125 if (tuple.currencyFlag) {
126 UErrorCode status = U_ZERO_ERROR;
127 UnicodeString currency(tuple.currency);
128 const UChar *terminatedCurrency = currency.getTerminatedBuffer();
129 fmt.setCurrency(terminatedCurrency, status);
130 if (U_FAILURE(status)) {
131 appendErrorMessage.append("Error setting currency.");
132 }
133 }
134 if (tuple.minGroupingDigitsFlag) {
135 fmt.setMinimumGroupingDigits(tuple.minGroupingDigits);
136 }
137 if (tuple.useSigDigitsFlag) {
138 fmt.setSignificantDigitsUsed(tuple.useSigDigits != 0);
139 }
140 if (tuple.minSigDigitsFlag) {
141 fmt.setMinimumSignificantDigits(tuple.minSigDigits);
142 }
143 if (tuple.maxSigDigitsFlag) {
144 fmt.setMaximumSignificantDigits(tuple.maxSigDigits);
145 }
146 if (tuple.useGroupingFlag) {
147 fmt.setGroupingUsed(tuple.useGrouping != 0);
148 }
149 if (tuple.multiplierFlag) {
150 fmt.setMultiplier(tuple.multiplier);
151 }
152 if (tuple.roundingIncrementFlag) {
153 fmt.setRoundingIncrement(tuple.roundingIncrement);
154 }
155 if (tuple.formatWidthFlag) {
156 fmt.setFormatWidth(tuple.formatWidth);
157 }
158 if (tuple.padCharacterFlag) {
159 fmt.setPadCharacter(tuple.padCharacter);
160 }
161 if (tuple.useScientificFlag) {
162 fmt.setScientificNotation(tuple.useScientific != 0);
163 }
164 if (tuple.groupingFlag) {
165 fmt.setGroupingSize(tuple.grouping);
166 }
167 if (tuple.grouping2Flag) {
168 fmt.setSecondaryGroupingSize(tuple.grouping2);
169 }
170 if (tuple.roundingModeFlag) {
171 fmt.setRoundingMode(tuple.roundingMode);
172 }
173 if (tuple.currencyUsageFlag) {
174 UErrorCode status = U_ZERO_ERROR;
175 fmt.setCurrencyUsage(tuple.currencyUsage, &status);
176 if (U_FAILURE(status)) {
177 appendErrorMessage.append("CurrencyUsage: error setting.");
178 }
179 }
180 if (tuple.minimumExponentDigitsFlag) {
181 fmt.setMinimumExponentDigits(tuple.minimumExponentDigits);
182 }
183 if (tuple.exponentSignAlwaysShownFlag) {
184 fmt.setExponentSignAlwaysShown(tuple.exponentSignAlwaysShown != 0);
185 }
186 if (tuple.decimalSeparatorAlwaysShownFlag) {
187 fmt.setDecimalSeparatorAlwaysShown(
188 tuple.decimalSeparatorAlwaysShown != 0);
189 }
190 if (tuple.padPositionFlag) {
191 fmt.setPadPosition(tuple.padPosition);
192 }
193 if (tuple.positivePrefixFlag) {
194 fmt.setPositivePrefix(tuple.positivePrefix);
195 }
196 if (tuple.positiveSuffixFlag) {
197 fmt.setPositiveSuffix(tuple.positiveSuffix);
198 }
199 if (tuple.negativePrefixFlag) {
200 fmt.setNegativePrefix(tuple.negativePrefix);
201 }
202 if (tuple.negativeSuffixFlag) {
203 fmt.setNegativeSuffix(tuple.negativeSuffix);
204 }
205 if (tuple.localizedPatternFlag) {
206 UErrorCode status = U_ZERO_ERROR;
207 fmt.applyLocalizedPattern(tuple.localizedPattern, status);
208 if (U_FAILURE(status)) {
209 appendErrorMessage.append("Error setting localized pattern.");
210 }
211 }
212 fmt.setLenient(NFTT_GET_FIELD(tuple, lenient, 1) != 0);
213 if (tuple.parseIntegerOnlyFlag) {
214 fmt.setParseIntegerOnly(tuple.parseIntegerOnly != 0);
215 }
216 if (tuple.decimalPatternMatchRequiredFlag) {
217 fmt.setDecimalPatternMatchRequired(
218 tuple.decimalPatternMatchRequired != 0);
219 }
220 if (tuple.parseNoExponentFlag) {
221 UErrorCode status = U_ZERO_ERROR;
222 fmt.setAttribute(
223 UNUM_PARSE_NO_EXPONENT,
224 tuple.parseNoExponent,
225 status);
226 if (U_FAILURE(status)) {
227 appendErrorMessage.append("Error setting parse no exponent flag.");
228 }
229 }
230 }
231
232 static DecimalFormat *newDecimalFormat(
233 const Locale &locale,
234 const UnicodeString &pattern,
235 UErrorCode &status) {
236 if (U_FAILURE(status)) {
237 return NULL;
238 }
239 LocalPointer<DecimalFormatSymbols> symbols(
240 new DecimalFormatSymbols(locale, status), status);
241 if (U_FAILURE(status)) {
242 return NULL;
243 }
244 UParseError perror;
245 LocalPointer<DecimalFormat> result(new DecimalFormat(
246 pattern, symbols.getAlias(), perror, status), status);
247 if (!result.isNull()) {
248 symbols.orphan();
249 }
250 if (U_FAILURE(status)) {
251 return NULL;
252 }
253 return result.orphan();
254 }
255
256 static DecimalFormat *newDecimalFormat(
257 const NumberFormatTestTuple &tuple,
258 UErrorCode &status) {
259 if (U_FAILURE(status)) {
260 return NULL;
261 }
262 Locale en("en");
263 return newDecimalFormat(
264 NFTT_GET_FIELD(tuple, locale, en),
265 NFTT_GET_FIELD(tuple, pattern, "0"),
266 status);
267 }
268
269 UBool NumberFormatTestDataDriven::isFormatPass(
270 const NumberFormatTestTuple &tuple,
271 UnicodeString &appendErrorMessage,
272 UErrorCode &status) {
273 if (U_FAILURE(status)) {
274 return FALSE;
275 }
276 LocalPointer<DecimalFormat> fmtPtr(newDecimalFormat(tuple, status));
277 if (U_FAILURE(status)) {
278 appendErrorMessage.append("Error creating DecimalFormat.");
279 return FALSE;
280 }
281 adjustDecimalFormat(tuple, *fmtPtr, appendErrorMessage);
282 if (appendErrorMessage.length() > 0) {
283 return FALSE;
284 }
285 DigitList digitList;
286 strToDigitList(tuple.format, digitList, status);
287 {
288 UnicodeString appendTo;
289 format(*fmtPtr, digitList, appendTo, status);
290 if (U_FAILURE(status)) {
291 appendErrorMessage.append("Error formatting.");
292 return FALSE;
293 }
294 if (appendTo != tuple.output) {
295 appendErrorMessage.append(
296 UnicodeString("Expected: ") + tuple.output + ", got: " + app endTo);
297 return FALSE;
298 }
299 }
300 double doubleVal = digitList.getDouble();
301 {
302 UnicodeString appendTo;
303 format(*fmtPtr, doubleVal, appendTo, status);
304 if (U_FAILURE(status)) {
305 appendErrorMessage.append("Error formatting.");
306 return FALSE;
307 }
308 if (appendTo != tuple.output) {
309 appendErrorMessage.append(
310 UnicodeString("double Expected: ") + tuple.output + ", got: " + appendTo);
311 return FALSE;
312 }
313 }
314 if (!uprv_isNaN(doubleVal) && !uprv_isInfinite(doubleVal) && doubleVal == up rv_floor(doubleVal)) {
315 int64_t intVal = digitList.getInt64();
316 {
317 UnicodeString appendTo;
318 format(*fmtPtr, intVal, appendTo, status);
319 if (U_FAILURE(status)) {
320 appendErrorMessage.append("Error formatting.");
321 return FALSE;
322 }
323 if (appendTo != tuple.output) {
324 appendErrorMessage.append(
325 UnicodeString("int64 Expected: ") + tuple.output + ", go t: " + appendTo);
326 return FALSE;
327 }
328 }
329 }
330 return TRUE;
331 }
332
333 UBool NumberFormatTestDataDriven::isToPatternPass(
334 const NumberFormatTestTuple &tuple,
335 UnicodeString &appendErrorMessage,
336 UErrorCode &status) {
337 if (U_FAILURE(status)) {
338 return FALSE;
339 }
340 LocalPointer<DecimalFormat> fmtPtr(newDecimalFormat(tuple, status));
341 if (U_FAILURE(status)) {
342 appendErrorMessage.append("Error creating DecimalFormat.");
343 return FALSE;
344 }
345 adjustDecimalFormat(tuple, *fmtPtr, appendErrorMessage);
346 if (appendErrorMessage.length() > 0) {
347 return FALSE;
348 }
349 if (tuple.toPatternFlag) {
350 UnicodeString actual;
351 fmtPtr->toPattern(actual);
352 if (actual != tuple.toPattern) {
353 appendErrorMessage.append(
354 UnicodeString("Expected: ") + tuple.toPattern + ", got: " + actual + ". ");
355 }
356 }
357 if (tuple.toLocalizedPatternFlag) {
358 UnicodeString actual;
359 fmtPtr->toLocalizedPattern(actual);
360 if (actual != tuple.toLocalizedPattern) {
361 appendErrorMessage.append(
362 UnicodeString("Expected: ") + tuple.toLocalizedPattern + ", got: " + actual + ". ");
363 }
364 }
365 return appendErrorMessage.length() == 0;
366 }
367
368 UBool NumberFormatTestDataDriven::isParsePass(
369 const NumberFormatTestTuple &tuple,
370 UnicodeString &appendErrorMessage,
371 UErrorCode &status) {
372 if (U_FAILURE(status)) {
373 return FALSE;
374 }
375 LocalPointer<DecimalFormat> fmtPtr(newDecimalFormat(tuple, status));
376 if (U_FAILURE(status)) {
377 appendErrorMessage.append("Error creating DecimalFormat.");
378 return FALSE;
379 }
380 adjustDecimalFormat(tuple, *fmtPtr, appendErrorMessage);
381 if (appendErrorMessage.length() > 0) {
382 return FALSE;
383 }
384 Formattable result;
385 ParsePosition ppos;
386 fmtPtr->parse(tuple.parse, result, ppos);
387 if (ppos.getIndex() == 0) {
388 if (tuple.output != "fail") {
389 appendErrorMessage.append("Parse failed but was expected to succeed. ");
390 return FALSE;
391 }
392 return TRUE;
393 }
394 UnicodeString resultStr(UnicodeString::fromUTF8(result.getDecimalNumber(stat us)));
395 if (tuple.output == "fail") {
396 appendErrorMessage.append(UnicodeString("Parse succeeded: ") + resultStr + ", but was expected to fail.");
397 return FALSE;
398 }
399 DigitList expected;
400 strToDigitList(tuple.output, expected, status);
401 if (U_FAILURE(status)) {
402 appendErrorMessage.append("Error parsing.");
403 return FALSE;
404 }
405 if (expected != *result.getDigitList()) {
406 appendErrorMessage.append(
407 UnicodeString("Expected: ") + tuple.output + ", got: " + res ultStr + ". ");
408 return FALSE;
409 }
410 return TRUE;
411 }
412
413 UBool NumberFormatTestDataDriven::isParseCurrencyPass(
414 const NumberFormatTestTuple &tuple,
415 UnicodeString &appendErrorMessage,
416 UErrorCode &status) {
417 if (U_FAILURE(status)) {
418 return FALSE;
419 }
420 LocalPointer<DecimalFormat> fmtPtr(newDecimalFormat(tuple, status));
421 if (U_FAILURE(status)) {
422 appendErrorMessage.append("Error creating DecimalFormat.");
423 return FALSE;
424 }
425 adjustDecimalFormat(tuple, *fmtPtr, appendErrorMessage);
426 if (appendErrorMessage.length() > 0) {
427 return FALSE;
428 }
429 ParsePosition ppos;
430 LocalPointer<CurrencyAmount> currAmt(
431 fmtPtr->parseCurrency(tuple.parse, ppos));
432 if (ppos.getIndex() == 0) {
433 if (tuple.output != "fail") {
434 appendErrorMessage.append("Parse failed but was expected to succeed. ");
435 return FALSE;
436 }
437 return TRUE;
438 }
439 UnicodeString currStr(currAmt->getISOCurrency());
440 Formattable resultFormattable(currAmt->getNumber());
441 UnicodeString resultStr(UnicodeString::fromUTF8(resultFormattable.getDecimal Number(status)));
442 if (tuple.output == "fail") {
443 appendErrorMessage.append(UnicodeString("Parse succeeded: ") + resultStr + ", but was expected to fail.");
444 return FALSE;
445 }
446 DigitList expected;
447 strToDigitList(tuple.output, expected, status);
448 if (U_FAILURE(status)) {
449 appendErrorMessage.append("Error parsing.");
450 return FALSE;
451 }
452 if (expected != *currAmt->getNumber().getDigitList()) {
453 appendErrorMessage.append(
454 UnicodeString("Expected: ") + tuple.output + ", got: " + res ultStr + ". ");
455 return FALSE;
456 }
457 if (currStr != tuple.outputCurrency) {
458 appendErrorMessage.append(UnicodeString(
459 "Expected currency: ") + tuple.outputCurrency + ", got: " + curr Str + ". ");
460 return FALSE;
461 }
462 return TRUE;
463 }
35 464
36 //#define NUMFMTST_CACHE_DEBUG 1 465 //#define NUMFMTST_CACHE_DEBUG 1
37 #include "stdio.h" /* for sprintf */ 466 #include "stdio.h" /* for sprintf */
38 // #include "iostream" // for cout 467 // #include "iostream" // for cout
39 468
40 //#define NUMFMTST_DEBUG 1 469 //#define NUMFMTST_DEBUG 1
41 470
42 static const UChar EUR[] = {69,85,82,0}; // "EUR" 471 static const UChar EUR[] = {69,85,82,0}; // "EUR"
43 static const UChar ISO_CURRENCY_USD[] = {0x55, 0x53, 0x44, 0}; // "USD" 472 static const UChar ISO_CURRENCY_USD[] = {0x55, 0x53, 0x44, 0}; // "USD"
44 473
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign); 555 TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign);
127 TESTCASE_AUTO(TestCustomCurrencySignAndSeparator); 556 TESTCASE_AUTO(TestCustomCurrencySignAndSeparator);
128 TESTCASE_AUTO(TestParseSignsAndMarks); 557 TESTCASE_AUTO(TestParseSignsAndMarks);
129 TESTCASE_AUTO(Test10419RoundingWith0FractionDigits); 558 TESTCASE_AUTO(Test10419RoundingWith0FractionDigits);
130 TESTCASE_AUTO(Test10468ApplyPattern); 559 TESTCASE_AUTO(Test10468ApplyPattern);
131 TESTCASE_AUTO(TestRoundingScientific10542); 560 TESTCASE_AUTO(TestRoundingScientific10542);
132 TESTCASE_AUTO(TestZeroScientific10547); 561 TESTCASE_AUTO(TestZeroScientific10547);
133 TESTCASE_AUTO(TestAccountingCurrency); 562 TESTCASE_AUTO(TestAccountingCurrency);
134 TESTCASE_AUTO(TestEquality); 563 TESTCASE_AUTO(TestEquality);
135 TESTCASE_AUTO(TestCurrencyUsage); 564 TESTCASE_AUTO(TestCurrencyUsage);
565 TESTCASE_AUTO(TestNumberFormatTestTuple);
566 TESTCASE_AUTO(TestDataDriven);
567 TESTCASE_AUTO(TestDoubleLimit11439);
568 TESTCASE_AUTO(TestFastPathConsistent11524);
569 TESTCASE_AUTO(TestGetAffixes);
570 TESTCASE_AUTO(TestToPatternScientific11648);
571 TESTCASE_AUTO(TestBenchmark);
572 TESTCASE_AUTO(TestCtorApplyPatternDifference);
573 TESTCASE_AUTO(TestFractionalDigitsForCurrency);
574 TESTCASE_AUTO(TestFormatCurrencyPlural);
575 TESTCASE_AUTO(Test11868);
576 TESTCASE_AUTO(Test10727_RoundingZero);
577 TESTCASE_AUTO(Test11376_getAndSetPositivePrefix);
578 TESTCASE_AUTO(Test11475_signRecognition);
579 TESTCASE_AUTO(Test11640_getAffixes);
580 TESTCASE_AUTO(Test11649_toPatternWithMultiCurrency);
136 TESTCASE_AUTO_END; 581 TESTCASE_AUTO_END;
137 } 582 }
138 583
139 // ------------------------------------- 584 // -------------------------------------
140 585
141 // Test API (increase code coverage) 586 // Test API (increase code coverage)
142 void 587 void
143 NumberFormatTest::TestAPI(void) 588 NumberFormatTest::TestAPI(void)
144 { 589 {
145 logln("Test API"); 590 logln("Test API");
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 953 }
509 if (!decimalSet) { 954 if (!decimalSet) {
510 dl.fDecimalAt = dl.fCount; 955 dl.fDecimalAt = dl.fCount;
511 } 956 }
512 }*/ 957 }*/
513 958
514 void 959 void
515 NumberFormatTest::TestInt64() { 960 NumberFormatTest::TestInt64() {
516 UErrorCode status = U_ZERO_ERROR; 961 UErrorCode status = U_ZERO_ERROR;
517 DecimalFormat fmt("#.#E0",status); 962 DecimalFormat fmt("#.#E0",status);
963 if (U_FAILURE(status)) {
964 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
965 return;
966 }
518 fmt.setMaximumFractionDigits(20); 967 fmt.setMaximumFractionDigits(20);
519 if (U_SUCCESS(status)) { 968 if (U_SUCCESS(status)) {
520 expect(fmt, (Formattable)(int64_t)0, "0E0"); 969 expect(fmt, (Formattable)(int64_t)0, "0E0");
521 expect(fmt, (Formattable)(int64_t)-1, "-1E0"); 970 expect(fmt, (Formattable)(int64_t)-1, "-1E0");
522 expect(fmt, (Formattable)(int64_t)1, "1E0"); 971 expect(fmt, (Formattable)(int64_t)1, "1E0");
523 expect(fmt, (Formattable)(int64_t)2147483647, "2.147483647E9"); 972 expect(fmt, (Formattable)(int64_t)2147483647, "2.147483647E9");
524 expect(fmt, (Formattable)((int64_t)-2147483647-1), "-2.147483648E9"); 973 expect(fmt, (Formattable)((int64_t)-2147483647-1), "-2.147483648E9");
525 expect(fmt, (Formattable)(int64_t)U_INT64_MAX, "9.223372036854775807E18" ); 974 expect(fmt, (Formattable)(int64_t)U_INT64_MAX, "9.223372036854775807E18" );
526 expect(fmt, (Formattable)(int64_t)U_INT64_MIN, "-9.223372036854775808E18 "); 975 expect(fmt, (Formattable)(int64_t)U_INT64_MIN, "-9.223372036854775808E18 ");
527 } 976 }
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 UnicodeString(ucurr_getName(CAD, "en", 2285 UnicodeString(ucurr_getName(CAD, "en",
1837 UCURR_SYMBOL_NAME, 2286 UCURR_SYMBOL_NAME,
1838 &isChoiceFormat, &len, &ec)), 2287 &isChoiceFormat, &len, &ec)),
1839 possibleDataError); 2288 possibleDataError);
1840 assertEquals("CAD.getName(SYMBOL_NAME)", 2289 assertEquals("CAD.getName(SYMBOL_NAME)",
1841 UnicodeString("$"), 2290 UnicodeString("$"),
1842 UnicodeString(ucurr_getName(CAD, "en_CA", 2291 UnicodeString(ucurr_getName(CAD, "en_CA",
1843 UCURR_SYMBOL_NAME, 2292 UCURR_SYMBOL_NAME,
1844 &isChoiceFormat, &len, &ec)), 2293 &isChoiceFormat, &len, &ec)),
1845 possibleDataError); 2294 possibleDataError);
1846 assertEquals("USD.getName(SYMBOL_NAME) in en_AU", 2295 assertEquals("USD.getName(SYMBOL_NAME) in en_NZ",
1847 UnicodeString("US$"), 2296 UnicodeString("US$"),
1848 UnicodeString(ucurr_getName(USD, "en_AU", 2297 UnicodeString(ucurr_getName(USD, "en_NZ",
1849 UCURR_SYMBOL_NAME, 2298 UCURR_SYMBOL_NAME,
1850 &isChoiceFormat, &len, &ec)), 2299 &isChoiceFormat, &len, &ec)),
1851 possibleDataError); 2300 possibleDataError);
1852 assertEquals("CAD.getName(SYMBOL_NAME)", 2301 assertEquals("CAD.getName(SYMBOL_NAME)",
1853 UnicodeString("CA$"), 2302 UnicodeString("CA$"),
1854 UnicodeString(ucurr_getName(CAD, "en_AU", 2303 UnicodeString(ucurr_getName(CAD, "en_NZ",
1855 UCURR_SYMBOL_NAME, 2304 UCURR_SYMBOL_NAME,
1856 &isChoiceFormat, &len, &ec)), 2305 &isChoiceFormat, &len, &ec)),
1857 possibleDataError); 2306 possibleDataError);
1858 assertEquals("USX.getName(LONG_NAME)", 2307 assertEquals("USX.getName(LONG_NAME)",
1859 UnicodeString("USX"), 2308 UnicodeString("USX"),
1860 UnicodeString(ucurr_getName(USX, "en_US", 2309 UnicodeString(ucurr_getName(USX, "en_US",
1861 UCURR_LONG_NAME, 2310 UCURR_LONG_NAME,
1862 &isChoiceFormat, &len, &ec)), 2311 &isChoiceFormat, &len, &ec)),
1863 possibleDataError); 2312 possibleDataError);
1864 assertSuccess("ucurr_getName", ec); 2313 assertSuccess("ucurr_getName", ec);
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
3380 // locale, 3829 // locale,
3381 // currency amount to be formatted, 3830 // currency amount to be formatted,
3382 // currency ISO code to be formatted, 3831 // currency ISO code to be formatted,
3383 // format result using CURRENCYSTYLE, 3832 // format result using CURRENCYSTYLE,
3384 // format result using ISOCURRENCYSTYLE, 3833 // format result using ISOCURRENCYSTYLE,
3385 // format result using PLURALCURRENCYSTYLE, 3834 // format result using PLURALCURRENCYSTYLE,
3386 3835
3387 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollars"}, 3836 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollars"},
3388 {"en_US", "1234.56", "USD", "$1,234.56", "USD1,234.56", "1,234.56 US dol lars"}, 3837 {"en_US", "1234.56", "USD", "$1,234.56", "USD1,234.56", "1,234.56 US dol lars"},
3389 {"en_US", "-1234.56", "USD", "-$1,234.56", "-USD1,234.56", "-1,234.56 US dollars"}, 3838 {"en_US", "-1234.56", "USD", "-$1,234.56", "-USD1,234.56", "-1,234.56 US dollars"},
3390 {"zh_CN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00\\u7F8E\\ u5143"}, 3839 {"zh_CN", "1", "USD", "US$1.00", "USD1.00", "1.00\\u7F8E\\u5143"},
3391 {"zh_CN", "1234.56", "USD", "US$\\u00A01,234.56", "USD\\u00A01,234.56", "1,234.56\\u7F8E\\u5143"}, 3840 {"zh_CN", "1234.56", "USD", "US$1,234.56", "USD1,234.56", "1,234.56\\u7F 8E\\u5143"},
3392 // wrong ISO code {"zh_CN", "1", "CHY", "CHY1.00", "CHY1.00", "1.00 CHY" }, 3841 {"zh_CN", "1", "CNY", "\\uFFE51.00", "CNY1.00", "1.00\\u4EBA\\u6C11\\u5E 01"},
3393 // wrong ISO code {"zh_CN", "1234.56", "CHY", "CHY1,234.56", "CHY1,234.5 6", "1,234.56 CHY"}, 3842 {"zh_CN", "1234.56", "CNY", "\\uFFE51,234.56", "CNY1,234.56", "1,234.56\ \u4EBA\\u6C11\\u5E01"},
3394 {"zh_CN", "1", "CNY", "\\uFFE5\\u00A01.00", "CNY\\u00A01.00", "1.00\\u4E BA\\u6C11\\u5E01"}, 3843 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u20BD", "1,00\\u00A0RUB", "1,00 \\u0 440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u044 0\\u0443\\u0431\\u043B\\u044F"},
3395 {"zh_CN", "1234.56", "CNY", "\\uFFE5\\u00A01,234.56", "CNY\\u00A01,234.5 6", "1,234.56\\u4EBA\\u6C11\\u5E01"}, 3844 {"ru_RU", "2", "RUB", "2,00\\u00A0\\u20BD", "2,00\\u00A0RUB", "2,00 \\u0 440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u044 0\\u0443\\u0431\\u043B\\u044F"},
3396 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u0440\\u0443\\u0431.", "1,00\\u00A0R UB", "1,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u043 3\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"}, 3845 {"ru_RU", "5", "RUB", "5,00\\u00A0\\u20BD", "5,00\\u00A0RUB", "5,00 \\u0 440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u044 0\\u0443\\u0431\\u043B\\u044F"},
3397 {"ru_RU", "2", "RUB", "2,00\\u00A0\\u0440\\u0443\\u0431.", "2,00\\u00A0R UB", "2,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u043 3\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3398 {"ru_RU", "5", "RUB", "5,00\\u00A0\\u0440\\u0443\\u0431.", "5,00\\u00A0R UB", "5,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u043 3\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3399 // test locale without currency information 3846 // test locale without currency information
3400 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 US D"}, 3847 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 US D"},
3401 // test choice format 3848 // test choice format
3402 {"es_AR", "1", "INR", "INR1,00", "INR1,00", "1,00 rupia india"}, 3849 {"es_AR", "1", "INR", "INR\\u00A01,00", "INR\\u00A01,00", "1,00 rupia in dia"},
3403 }; 3850 };
3404 static const UNumberFormatStyle currencyStyles[] = { 3851 static const UNumberFormatStyle currencyStyles[] = {
3405 UNUM_CURRENCY, 3852 UNUM_CURRENCY,
3406 UNUM_CURRENCY_ISO, 3853 UNUM_CURRENCY_ISO,
3407 UNUM_CURRENCY_PLURAL 3854 UNUM_CURRENCY_PLURAL
3408 }; 3855 };
3409 3856
3410 for (int32_t i=0; i<UPRV_LENGTHOF(DATA); ++i) { 3857 for (int32_t i=0; i<UPRV_LENGTHOF(DATA); ++i) {
3411 for (int32_t kIndex = 0; kIndex < UPRV_LENGTHOF(currencyStyles); ++kIndex) { 3858 for (int32_t kIndex = 0; kIndex < UPRV_LENGTHOF(currencyStyles); ++kIndex) {
3412 UNumberFormatStyle k = currencyStyles[kIndex]; 3859 UNumberFormatStyle k = currencyStyles[kIndex];
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 static const char* DATA[][6] = { 3922 static const char* DATA[][6] = {
3476 // the data are: 3923 // the data are:
3477 // locale, 3924 // locale,
3478 // currency amount to be formatted, 3925 // currency amount to be formatted,
3479 // currency ISO code to be formatted, 3926 // currency ISO code to be formatted,
3480 // format result using CURRENCYSTYLE, 3927 // format result using CURRENCYSTYLE,
3481 // format result using ISOCURRENCYSTYLE, 3928 // format result using ISOCURRENCYSTYLE,
3482 // format result using PLURALCURRENCYSTYLE, 3929 // format result using PLURALCURRENCYSTYLE,
3483 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollar"}, 3930 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollar"},
3484 {"pa_IN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00 \\u0a2f\ \u0a42.\\u0a10\\u0a38. \\u0a21\\u0a3e\\u0a32\\u0a30"}, 3931 {"pa_IN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00 \\u0a2f\ \u0a42.\\u0a10\\u0a38. \\u0a21\\u0a3e\\u0a32\\u0a30"},
3485 {"es_AR", "1", "USD", "US$1,00", "USD1,00", "1,00 d\\u00f3lar estadounid ense"}, 3932 {"es_AR", "1", "USD", "US$\\u00A01,00", "USD\\u00A01,00", "1,00 d\\u00f3 lar estadounidense"},
3486 {"ar_EG", "1", "USD", "US$\\u00a0\\u0661\\u066b\\u0660\\u0660", "USD\\u0 0a0\\u0661\\u066b\\u0660\\u0660", "\\u0661\\u066b\\u0660\\u0660 \\u062f\\u0648\\ u0644\\u0627\\u0631 \\u0623\\u0645\\u0631\\u064a\\u0643\\u064a"}, 3933 {"ar_EG", "1", "USD", "US$\\u00a0\\u0661\\u066b\\u0660\\u0660", "USD\\u0 0a0\\u0661\\u066b\\u0660\\u0660", "\\u0661\\u066b\\u0660\\u0660 \\u062f\\u0648\\ u0644\\u0627\\u0631 \\u0623\\u0645\\u0631\\u064a\\u0643\\u064a"},
3487 {"fa_CA", "1", "USD", "\\u200e$\\u06f1\\u066b\\u06f0\\u06f0", "\\u200eUS D\\u06f1\\u066b\\u06f0\\u06f0", "\\u200e\\u062f\\u0644\\u0627\\u0631 \\u0627\\u0 645\\u0631\\u06cc\\u06a9\\u0627\\u06f1\\u066b\\u06f0\\u06f0"}, 3934 {"fa_CA", "1", "USD", "\\u200e$\\u06f1\\u066b\\u06f0\\u06f0", "\\u200eUS D\\u06f1\\u066b\\u06f0\\u06f0", "\\u200e\\u062f\\u0644\\u0627\\u0631 \\u0627\\u0 645\\u0631\\u06cc\\u06a9\\u0627\\u06f1\\u066b\\u06f0\\u06f0"},
3488 {"he_IL", "1", "USD", "1.00\\u00a0$", "1.00\\u00a0USD", "1.00 \\u05d3\\u 05d5\\u05dc\\u05e8 \\u05d0\\u05de\\u05e8\\u05d9\\u05e7\\u05d0\\u05d9"}, 3935 {"he_IL", "1", "USD", "1.00\\u00a0$", "1.00\\u00a0USD", "1.00 \\u05d3\\u 05d5\\u05dc\\u05e8 \\u05d0\\u05de\\u05e8\\u05d9\\u05e7\\u05d0\\u05d9"},
3489 {"hr_HR", "1", "USD", "1,00\\u00a0USD", "1,00\\u00a0USD", "1,00 Ameri\\u 010dki dolar"}, 3936 {"hr_HR", "1", "USD", "1,00\\u00a0USD", "1,00\\u00a0USD", "1,00 Ameri\\u 010dki dolar"},
3490 {"id_ID", "1", "USD", "US$1,00", "USD1,00", "1,00 Dolar Amerika Serikat" }, 3937 {"id_ID", "1", "USD", "US$1,00", "USD1,00", "1,00 Dolar Amerika Serikat" },
3491 {"it_IT", "1", "USD", "1,00\\u00a0US$", "1,00\\u00a0USD", "1,00 Dollaro Statunitense"}, 3938 {"it_IT", "1", "USD", "1,00\\u00a0US$", "1,00\\u00a0USD", "1,00 Dollaro Statunitense"},
3492 {"ko_KR", "1", "USD", "US$1.00", "USD1.00", "1.00 \\ubbf8\\uad6d \\ub2ec \\ub7ec"}, 3939 {"ko_KR", "1", "USD", "US$1.00", "USD1.00", "1.00 \\ubbf8\\uad6d \\ub2ec \\ub7ec"},
3493 {"ja_JP", "1", "USD", "$1.00", "USD1.00", "1.00 \\u7c73\\u30c9\\u30eb"}, 3940 {"ja_JP", "1", "USD", "$1.00", "USD1.00", "1.00\\u7c73\\u30c9\\u30eb"},
3494 {"zh_CN", "1", "CNY", "\\uFFE5\\u00a01.00", "CNY\\u00a01.00", "1.00\\u4E BA\\u6C11\\u5E01"}, 3941 {"zh_CN", "1", "CNY", "\\uFFE51.00", "CNY01.00", "1.00\\u4EBA\\u6C11\\u5 E01"},
3495 {"zh_TW", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\ u5e63"}, 3942 {"zh_TW", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\ u5e63"},
3496 {"zh_Hant", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11 \\u5e63"}, 3943 {"zh_Hant", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11 \\u5e63"},
3497 {"zh_Hant", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u5713"} , 3944 {"zh_Hant", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u5713"} ,
3498 {"ja_JP", "1", "JPY", "\\uFFE51.00", "JPY1.00", "1.00 \\u65e5\\u672c\\u5 186"}, 3945 {"ja_JP", "1", "JPY", "\\uFFE51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u51 86"},
3499 {"ja_JP", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u672c\\u5 186"}, 3946 {"ja_JP", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u51 86"},
3500 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u0440\\u0443\\u0431.", "1,00\\u00A0R UB", "1,00 \\u0420\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u0438\\u043 9 \\u0440\\u0443\\u0431\\u043B\\u044C"} 3947 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u20BD", "1,00\\u00A0RUB", "1,00 \\u0 420\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u0438\\u0439 \\u0440\\u044 3\\u0431\\u043B\\u044C"}
3501 }; 3948 };
3502 static const UNumberFormatStyle currencyStyles[] = { 3949 static const UNumberFormatStyle currencyStyles[] = {
3503 UNUM_CURRENCY, 3950 UNUM_CURRENCY,
3504 UNUM_CURRENCY_ISO, 3951 UNUM_CURRENCY_ISO,
3505 UNUM_CURRENCY_PLURAL 3952 UNUM_CURRENCY_PLURAL
3506 }; 3953 };
3507 static const char* currencyStyleNames[] = { 3954 static const char* currencyStyleNames[] = {
3508 "UNUM_CURRENCY", 3955 "UNUM_CURRENCY",
3509 "UNUM_CURRENCY_ISO", 3956 "UNUM_CURRENCY_ISO",
3510 "UNUM_CURRENCY_PLURAL" 3957 "UNUM_CURRENCY_PLURAL"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
3789 "Brazilian cruzado (1986\\u20131989)1.00", 4236 "Brazilian cruzado (1986\\u20131989)1.00",
3790 "Brazilian cruzados (1986\\u20131989)1.00", 4237 "Brazilian cruzados (1986\\u20131989)1.00",
3791 "Brazilian cruzeiro (1990\\u20131993)1.00", 4238 "Brazilian cruzeiro (1990\\u20131993)1.00",
3792 "Brazilian new cruzeiro (1967\\u20131986)1.00", 4239 "Brazilian new cruzeiro (1967\\u20131986)1.00",
3793 "Brazilian cruzeiro (1993\\u20131994)1.00", 4240 "Brazilian cruzeiro (1993\\u20131994)1.00",
3794 "Brazilian cruzeiros (1990\\u20131993)1.00", 4241 "Brazilian cruzeiros (1990\\u20131993)1.00",
3795 "Brazilian new cruzeiros (1967\\u20131986)1.00", 4242 "Brazilian new cruzeiros (1967\\u20131986)1.00",
3796 "Brazilian cruzeiros (1993\\u20131994)1.00", 4243 "Brazilian cruzeiros (1993\\u20131994)1.00",
3797 "Brazilian real1.00", 4244 "Brazilian real1.00",
3798 "Brazilian reals1.00", 4245 "Brazilian reals1.00",
3799 "British Pound Sterling1.00", 4246 "British Pound1.00",
3800 "British pound sterling1.00", 4247 "British pound1.00",
3801 "British pounds sterling1.00", 4248 "British pounds1.00",
3802 "Brunei Dollar1.00", 4249 "Brunei Dollar1.00",
3803 "Brunei dollar1.00", 4250 "Brunei dollar1.00",
3804 "Brunei dollars1.00", 4251 "Brunei dollars1.00",
3805 "Bulgarian Hard Lev1.00", 4252 "Bulgarian Hard Lev1.00",
3806 "Bulgarian Lev1.00", 4253 "Bulgarian Lev1.00",
3807 "Bulgarian Leva1.00", 4254 "Bulgarian Leva1.00",
3808 "Bulgarian hard lev1.00", 4255 "Bulgarian hard lev1.00",
3809 "Bulgarian hard leva1.00", 4256 "Bulgarian hard leva1.00",
3810 "Bulgarian lev1.00", 4257 "Bulgarian lev1.00",
3811 "Burmese Kyat1.00", 4258 "Burmese Kyat1.00",
3812 "Burmese kyat1.00", 4259 "Burmese kyat1.00",
3813 "Burmese kyats1.00", 4260 "Burmese kyats1.00",
3814 "Burundian Franc1.00", 4261 "Burundian Franc1.00",
3815 "Burundian franc1.00", 4262 "Burundian franc1.00",
3816 "Burundian francs1.00", 4263 "Burundian francs1.00",
3817 "CA$1.00", 4264 "CA$1.00",
3818 "CAD1.00", 4265 "CAD1.00",
3819 "CDF1.00", 4266 "CDF1.00",
3820 "CDF1.00", 4267 "CDF1.00",
3821 "CFA Franc BCEAO1.00", 4268 "West African CFA Franc1.00",
3822 "CFA Franc BEAC1.00", 4269 "Central African CFA Franc1.00",
3823 "CFA franc BCEAO1.00", 4270 "West African CFA franc1.00",
3824 "CFA franc BEAC1.00", 4271 "Central African CFA franc1.00",
3825 "CFA francs BCEAO1.00", 4272 "West African CFA francs1.00",
3826 "CFA francs BEAC1.00", 4273 "Central African CFA francs1.00",
3827 "CFP Franc1.00", 4274 "CFP Franc1.00",
3828 "CFP franc1.00", 4275 "CFP franc1.00",
3829 "CFP francs1.00", 4276 "CFP francs1.00",
3830 "CFPF1.00", 4277 "CFPF1.00",
3831 "CHE1.00", 4278 "CHE1.00",
3832 "CHE1.00", 4279 "CHE1.00",
3833 "CHF1.00", 4280 "CHF1.00",
3834 "CHW1.00", 4281 "CHW1.00",
3835 "CHW1.00", 4282 "CHW1.00",
3836 "CLF1.00", 4283 "CLF1.00",
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
4459 "RINET Funds1.00", 4906 "RINET Funds1.00",
4460 "RINET Funds1.00", 4907 "RINET Funds1.00",
4461 "CN\\u00a51.00", 4908 "CN\\u00a51.00",
4462 "ROL1.00", 4909 "ROL1.00",
4463 "ROL1.00", 4910 "ROL1.00",
4464 "RON1.00", 4911 "RON1.00",
4465 "RON1.00", 4912 "RON1.00",
4466 "RSD1.00", 4913 "RSD1.00",
4467 "RSD1.00", 4914 "RSD1.00",
4468 "RUB1.00", 4915 "RUB1.00",
4469 "RUB1.00",
4470 "RUR1.00", 4916 "RUR1.00",
4471 "RUR1.00", 4917 "RUR1.00",
4472 "RWF1.00", 4918 "RWF1.00",
4473 "RWF1.00", 4919 "RWF1.00",
4474 "Rhodesian Dollar1.00", 4920 "Rhodesian Dollar1.00",
4475 "Rhodesian dollar1.00", 4921 "Rhodesian dollar1.00",
4476 "Rhodesian dollars1.00", 4922 "Rhodesian dollars1.00",
4477 "Romanian Leu1.00", 4923 "Romanian Leu1.00",
4478 "Romanian lei1.00", 4924 "Romanian lei1.00",
4479 "Romanian leu1.00", 4925 "Romanian leu1.00",
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
4695 "Unknown Currency1.00", 5141 "Unknown Currency1.00",
4696 "Uruguayan Peso (1975\\u20131993)1.00", 5142 "Uruguayan Peso (1975\\u20131993)1.00",
4697 "Uruguayan Peso1.00", 5143 "Uruguayan Peso1.00",
4698 "Uruguayan Peso (Indexed Units)1.00", 5144 "Uruguayan Peso (Indexed Units)1.00",
4699 "Uruguayan peso (1975\\u20131993)1.00", 5145 "Uruguayan peso (1975\\u20131993)1.00",
4700 "Uruguayan peso (indexed units)1.00", 5146 "Uruguayan peso (indexed units)1.00",
4701 "Uruguayan peso1.00", 5147 "Uruguayan peso1.00",
4702 "Uruguayan pesos (1975\\u20131993)1.00", 5148 "Uruguayan pesos (1975\\u20131993)1.00",
4703 "Uruguayan pesos (indexed units)1.00", 5149 "Uruguayan pesos (indexed units)1.00",
4704 "Uruguayan pesos1.00", 5150 "Uruguayan pesos1.00",
4705 "Uzbekistan Som1.00", 5151 "Uzbekistani Som1.00",
4706 "Uzbekistan som1.00", 5152 "Uzbekistani som1.00",
4707 "Uzbekistan som1.00", 5153 "Uzbekistani som1.00",
4708 "VEB1.00", 5154 "VEB1.00",
4709 "VEF1.00", 5155 "VEF1.00",
4710 "VND1.00", 5156 "VND1.00",
4711 "VUV1.00", 5157 "VUV1.00",
4712 "Vanuatu Vatu1.00", 5158 "Vanuatu Vatu1.00",
4713 "Vanuatu vatu1.00", 5159 "Vanuatu vatu1.00",
4714 "Vanuatu vatus1.00", 5160 "Vanuatu vatus1.00",
4715 "Venezuelan Bol\\u00edvar1.00", 5161 "Venezuelan Bol\\u00edvar1.00",
4716 "Venezuelan Bol\\u00edvar (1871\\u20132008)1.00", 5162 "Venezuelan Bol\\u00edvar (1871\\u20132008)1.00",
4717 "Venezuelan bol\\u00edvar1.00", 5163 "Venezuelan bol\\u00edvar1.00",
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
4949 "1.00 Brazilian cruzado (1986\\u20131989) random", 5395 "1.00 Brazilian cruzado (1986\\u20131989) random",
4950 "1.00 Brazilian cruzados (1986\\u20131989) random", 5396 "1.00 Brazilian cruzados (1986\\u20131989) random",
4951 "1.00 Brazilian cruzeiro (1990\\u20131993) random", 5397 "1.00 Brazilian cruzeiro (1990\\u20131993) random",
4952 "1.00 Brazilian new cruzeiro (1967\\u20131986) random", 5398 "1.00 Brazilian new cruzeiro (1967\\u20131986) random",
4953 "1.00 Brazilian cruzeiro (1993\\u20131994) random", 5399 "1.00 Brazilian cruzeiro (1993\\u20131994) random",
4954 "1.00 Brazilian cruzeiros (1990\\u20131993) random", 5400 "1.00 Brazilian cruzeiros (1990\\u20131993) random",
4955 "1.00 Brazilian new cruzeiros (1967\\u20131986) random", 5401 "1.00 Brazilian new cruzeiros (1967\\u20131986) random",
4956 "1.00 Brazilian cruzeiros (1993\\u20131994) random", 5402 "1.00 Brazilian cruzeiros (1993\\u20131994) random",
4957 "1.00 Brazilian real random", 5403 "1.00 Brazilian real random",
4958 "1.00 Brazilian reals random", 5404 "1.00 Brazilian reals random",
4959 "1.00 British Pound Sterling random", 5405 "1.00 British Pound random",
4960 "1.00 British pound sterling random", 5406 "1.00 British pound random",
4961 "1.00 British pounds sterling random", 5407 "1.00 British pounds random",
4962 "1.00 Brunei Dollar random", 5408 "1.00 Brunei Dollar random",
4963 "1.00 Brunei dollar random", 5409 "1.00 Brunei dollar random",
4964 "1.00 Brunei dollars random", 5410 "1.00 Brunei dollars random",
4965 "1.00 Bulgarian Hard Lev random", 5411 "1.00 Bulgarian Hard Lev random",
4966 "1.00 Bulgarian Lev random", 5412 "1.00 Bulgarian Lev random",
4967 "1.00 Bulgarian Leva random", 5413 "1.00 Bulgarian Leva random",
4968 "1.00 Bulgarian hard lev random", 5414 "1.00 Bulgarian hard lev random",
4969 "1.00 Bulgarian hard leva random", 5415 "1.00 Bulgarian hard leva random",
4970 "1.00 Bulgarian lev random", 5416 "1.00 Bulgarian lev random",
4971 "1.00 Burmese Kyat random", 5417 "1.00 Burmese Kyat random",
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
5543 "1.00 United Arab Emirates Dirham random", 5989 "1.00 United Arab Emirates Dirham random",
5544 "1.00 Unknown Currency random", 5990 "1.00 Unknown Currency random",
5545 "1.00 Uruguayan Peso (1975\\u20131993) random", 5991 "1.00 Uruguayan Peso (1975\\u20131993) random",
5546 "1.00 Uruguayan Peso random", 5992 "1.00 Uruguayan Peso random",
5547 "1.00 Uruguayan Peso (Indexed Units) random", 5993 "1.00 Uruguayan Peso (Indexed Units) random",
5548 "1.00 Uruguayan peso (1975\\u20131993) random", 5994 "1.00 Uruguayan peso (1975\\u20131993) random",
5549 "1.00 Uruguayan peso (indexed units) random", 5995 "1.00 Uruguayan peso (indexed units) random",
5550 "1.00 Uruguayan peso random", 5996 "1.00 Uruguayan peso random",
5551 "1.00 Uruguayan pesos (1975\\u20131993) random", 5997 "1.00 Uruguayan pesos (1975\\u20131993) random",
5552 "1.00 Uruguayan pesos (indexed units) random", 5998 "1.00 Uruguayan pesos (indexed units) random",
5553 "1.00 Uzbekistan Som random", 5999 "1.00 Uzbekistani Som random",
5554 "1.00 Uzbekistan som random", 6000 "1.00 Uzbekistani som random",
5555 "1.00 Uzbekistan som random", 6001 "1.00 Uzbekistani som random",
5556 "1.00 Vanuatu Vatu random", 6002 "1.00 Vanuatu Vatu random",
5557 "1.00 Vanuatu vatu random", 6003 "1.00 Vanuatu vatu random",
5558 "1.00 Vanuatu vatus random", 6004 "1.00 Vanuatu vatus random",
5559 "1.00 Venezuelan Bol\\u00edvar random", 6005 "1.00 Venezuelan Bol\\u00edvar random",
5560 "1.00 Venezuelan Bol\\u00edvar (1871\\u20132008) random", 6006 "1.00 Venezuelan Bol\\u00edvar (1871\\u20132008) random",
5561 "1.00 Venezuelan bol\\u00edvar random", 6007 "1.00 Venezuelan bol\\u00edvar random",
5562 "1.00 Venezuelan bol\\u00edvars random", 6008 "1.00 Venezuelan bol\\u00edvars random",
5563 "1.00 Venezuelan bol\\u00edvar (1871\\u20132008) random", 6009 "1.00 Venezuelan bol\\u00edvar (1871\\u20132008) random",
5564 "1.00 Venezuelan bol\\u00edvars (1871\\u20132008) random", 6010 "1.00 Venezuelan bol\\u00edvars (1871\\u20132008) random",
5565 "1.00 Vietnamese Dong random", 6011 "1.00 Vietnamese Dong random",
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
5710 "Brazilian Rea1.00", 6156 "Brazilian Rea1.00",
5711 "British Pound Sterlin1.00", 6157 "British Pound Sterlin1.00",
5712 "Brunei Dolla1.00", 6158 "Brunei Dolla1.00",
5713 "Bulgarian Hard Le1.00", 6159 "Bulgarian Hard Le1.00",
5714 "Bulgarian Le1.00", 6160 "Bulgarian Le1.00",
5715 "Burmese Kya1.00", 6161 "Burmese Kya1.00",
5716 "Burundian Fran1.00", 6162 "Burundian Fran1.00",
5717 "C1.00", 6163 "C1.00",
5718 "CA1.00", 6164 "CA1.00",
5719 "CD1.00", 6165 "CD1.00",
5720 "CFA Franc BCEA1.00",
5721 "CFA Franc BEA1.00",
5722 "CFP Fran1.00", 6166 "CFP Fran1.00",
5723 "CFP1.00", 6167 "CFP1.00",
5724 "CH1.00", 6168 "CH1.00",
5725 "CL1.00", 6169 "CL1.00",
5726 "CN1.00", 6170 "CN1.00",
5727 "CO1.00", 6171 "CO1.00",
5728 "CS1.00", 6172 "CS1.00",
5729 "CU1.00", 6173 "CU1.00",
5730 "CV1.00", 6174 "CV1.00",
5731 "CY1.00", 6175 "CY1.00",
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
6081 "Ugandan Shilling (1966\\u201319871.00", 6525 "Ugandan Shilling (1966\\u201319871.00",
6082 "Ukrainian Hryvni1.00", 6526 "Ukrainian Hryvni1.00",
6083 "Ukrainian Karbovanet1.00", 6527 "Ukrainian Karbovanet1.00",
6084 "Colombian Real Value Uni1.00", 6528 "Colombian Real Value Uni1.00",
6085 "United Arab Emirates Dirha1.00", 6529 "United Arab Emirates Dirha1.00",
6086 "Unknown Currenc1.00", 6530 "Unknown Currenc1.00",
6087 "Ur1.00", 6531 "Ur1.00",
6088 "Uruguay Peso (1975\\u201319931.00", 6532 "Uruguay Peso (1975\\u201319931.00",
6089 "Uruguay Peso Uruguay1.00", 6533 "Uruguay Peso Uruguay1.00",
6090 "Uruguay Peso (Indexed Units1.00", 6534 "Uruguay Peso (Indexed Units1.00",
6091 "Uzbekistan So1.00", 6535 "Uzbekistani So1.00",
6092 "V1.00", 6536 "V1.00",
6093 "VE1.00", 6537 "VE1.00",
6094 "VN1.00", 6538 "VN1.00",
6095 "VU1.00", 6539 "VU1.00",
6096 "Vanuatu Vat1.00", 6540 "Vanuatu Vat1.00",
6097 "Venezuelan Bol\\u00edva1.00", 6541 "Venezuelan Bol\\u00edva1.00",
6098 "Venezuelan Bol\\u00edvar Fuert1.00", 6542 "Venezuelan Bol\\u00edvar Fuert1.00",
6099 "Vietnamese Don1.00", 6543 "Vietnamese Don1.00",
6544 "West African CFA Fran1.00",
6545 "Central African CFA Fran1.00",
6100 "WIR Eur1.00", 6546 "WIR Eur1.00",
6101 "WIR Fran1.00", 6547 "WIR Fran1.00",
6102 "WS1.00", 6548 "WS1.00",
6103 "Samoa Tal1.00", 6549 "Samoa Tal1.00",
6104 "XA1.00", 6550 "XA1.00",
6105 "XB1.00", 6551 "XB1.00",
6106 "XC1.00", 6552 "XC1.00",
6107 "XD1.00", 6553 "XD1.00",
6108 "XE1.00", 6554 "XE1.00",
6109 "XF1.00", 6555 "XF1.00",
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
6587 } 7033 }
6588 } 7034 }
6589 7035
6590 void NumberFormatTest::TestExplicitParents() { 7036 void NumberFormatTest::TestExplicitParents() {
6591 7037
6592 /* Test that number formats are properly inherited from es_419 */ 7038 /* Test that number formats are properly inherited from es_419 */
6593 /* These could be subject to change if the CLDR data changes */ 7039 /* These could be subject to change if the CLDR data changes */
6594 static const char* parentLocaleTests[][2]= { 7040 static const char* parentLocaleTests[][2]= {
6595 /* locale ID */ /* expected */ 7041 /* locale ID */ /* expected */
6596 {"es_CO", "1.250,75" }, 7042 {"es_CO", "1.250,75" },
6597 {"es_CR", "1.250,75" },
6598 {"es_ES", "1.250,75" }, 7043 {"es_ES", "1.250,75" },
6599 {"es_GQ", "1.250,75" }, 7044 {"es_GQ", "1.250,75" },
6600 {"es_MX", "1,250.75" }, 7045 {"es_MX", "1,250.75" },
6601 {"es_US", "1,250.75" }, 7046 {"es_US", "1,250.75" },
6602 {"es_VE", "1.250,75" }, 7047 {"es_VE", "1.250,75" },
6603 }; 7048 };
6604 7049
6605 UnicodeString s; 7050 UnicodeString s;
6606 7051
6607 for(int i=0; i < (int)(sizeof(parentLocaleTests)/sizeof(parentLocaleTests[i] )); i++){ 7052 for(int i=0; i < (int)(sizeof(parentLocaleTests)/sizeof(parentLocaleTests[i] )); i++){
(...skipping 25 matching lines...) Expand all
6633 7078
6634 /** 7079 /**
6635 * Test available numbering systems API. 7080 * Test available numbering systems API.
6636 */ 7081 */
6637 void NumberFormatTest::TestAvailableNumberingSystems() { 7082 void NumberFormatTest::TestAvailableNumberingSystems() {
6638 UErrorCode status = U_ZERO_ERROR; 7083 UErrorCode status = U_ZERO_ERROR;
6639 StringEnumeration *availableNumberingSystems = NumberingSystem::getAvailable Names(status); 7084 StringEnumeration *availableNumberingSystems = NumberingSystem::getAvailable Names(status);
6640 CHECK_DATA(status, "NumberingSystem::getAvailableNames()") 7085 CHECK_DATA(status, "NumberingSystem::getAvailableNames()")
6641 7086
6642 int32_t nsCount = availableNumberingSystems->count(status); 7087 int32_t nsCount = availableNumberingSystems->count(status);
6643 if ( nsCount < 36 ) { 7088 if ( nsCount < 74 ) {
6644 errln("FAIL: Didn't get as many numbering systems as we had hoped for. N eed at least 36, got %d",nsCount); 7089 errln("FAIL: Didn't get as many numbering systems as we had hoped for. N eed at least 74, got %d",nsCount);
6645 } 7090 }
6646 7091
6647 /* A relatively simple test of the API. We call getAvailableNames() and cyc le through */ 7092 /* A relatively simple test of the API. We call getAvailableNames() and cyc le through */
6648 /* each name returned, attempting to create a numbering system based on that name and */ 7093 /* each name returned, attempting to create a numbering system based on that name and */
6649 /* verifying that the name returned from the resulting numbering system is t he same */ 7094 /* verifying that the name returned from the resulting numbering system is t he same */
6650 /* one that we initially thought. */ 7095 /* one that we initially thought. */
6651 7096
6652 int32_t len; 7097 int32_t len;
6653 for ( int32_t i = 0 ; i < nsCount ; i++ ) { 7098 for ( int32_t i = 0 ; i < nsCount ; i++ ) {
6654 const char *nsname = availableNumberingSystems->next(&len,status); 7099 const char *nsname = availableNumberingSystems->next(&len,status);
6655 NumberingSystem* ns = NumberingSystem::createInstanceByName(nsname,statu s); 7100 NumberingSystem* ns = NumberingSystem::createInstanceByName(nsname,statu s);
7101 logln("OK for ns = %s",nsname);
6656 if ( uprv_strcmp(nsname,ns->getName()) ) { 7102 if ( uprv_strcmp(nsname,ns->getName()) ) {
6657 errln("FAIL: Numbering system name didn't match for name = %s\n",nsn ame); 7103 errln("FAIL: Numbering system name didn't match for name = %s\n",nsn ame);
6658 } 7104 }
6659 7105
6660 delete ns; 7106 delete ns;
6661 } 7107 }
6662 7108
6663 delete availableNumberingSystems; 7109 delete availableNumberingSystems;
6664 } 7110 }
6665 7111
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
6716 infoln("Note: sizeof(DecimalFormatInternal)=%d but UNUM_DECIMALFORMAT_IN TERNAL_SIZE is %d. Decrease the #define? sizeof(DecimalFormat)=%d\n", sizeof(Dec imalFormatInternal), UNUM_DECIMALFORMAT_INTERNAL_SIZE, sizeof(DecimalFormat)); 7162 infoln("Note: sizeof(DecimalFormatInternal)=%d but UNUM_DECIMALFORMAT_IN TERNAL_SIZE is %d. Decrease the #define? sizeof(DecimalFormat)=%d\n", sizeof(Dec imalFormatInternal), UNUM_DECIMALFORMAT_INTERNAL_SIZE, sizeof(DecimalFormat));
6717 } 7163 }
6718 #else 7164 #else
6719 infoln("NOTE: UCONFIG_FORMAT_FASTPATHS not set, test skipped."); 7165 infoln("NOTE: UCONFIG_FORMAT_FASTPATHS not set, test skipped.");
6720 #endif 7166 #endif
6721 7167
6722 // get some additional case 7168 // get some additional case
6723 { 7169 {
6724 UErrorCode status=U_ZERO_ERROR; 7170 UErrorCode status=U_ZERO_ERROR;
6725 DecimalFormat df(UnicodeString("0000",""),status); 7171 DecimalFormat df(UnicodeString("0000",""),status);
6726 int64_t long_number = 1; 7172 if (U_FAILURE(status)) {
6727 UnicodeString expect = "0001"; 7173 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
6728 UnicodeString result;
6729 FieldPosition pos;
6730 df.format(long_number, result, pos);
6731 if(U_FAILURE(status)||expect!=result) {
6732 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' sta tus "+UnicodeString(u_errorName(status),""));
6733 } else { 7174 } else {
6734 logln("OK: got expected '"+result+"' status "+UnicodeString(u_error Name(status),"")); 7175 int64_t long_number = 1;
7176 UnicodeString expect = "0001";
7177 UnicodeString result;
7178 FieldPosition pos;
7179 df.format(long_number, result, pos);
7180 if(U_FAILURE(status)||expect!=result) {
7181 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),""));
7182 } else {
7183 logln("OK: got expected '"+result+"' status "+UnicodeString(u_e rrorName(status),""));
7184 }
6735 } 7185 }
6736 } 7186 }
6737 { 7187 {
6738 UErrorCode status=U_ZERO_ERROR; 7188 UErrorCode status=U_ZERO_ERROR;
6739 DecimalFormat df(UnicodeString("0000000000000000000",""),status); 7189 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6740 int64_t long_number = U_INT64_MIN; // -9223372036854775808L; 7190 if (U_FAILURE(status)) {
6741 // uint8_t bits[8]; 7191 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
6742 // memcpy(bits,&long_number,8);
6743 // for(int i=0;i<8;i++) {
6744 // logln("bits: %02X", (unsigned int)bits[i]);
6745 // }
6746 UnicodeString expect = "-9223372036854775808";
6747 UnicodeString result;
6748 FieldPosition pos;
6749 df.format(long_number, result, pos);
6750 if(U_FAILURE(status)||expect!=result) {
6751 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' sta tus "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
6752 } else { 7192 } else {
6753 logln("OK: got expected '"+result+"' status "+UnicodeString(u_error Name(status),"")+" on -9223372036854775808"); 7193 int64_t long_number = U_INT64_MIN; // -9223372036854775808L;
7194 // uint8_t bits[8];
7195 // memcpy(bits,&long_number,8);
7196 // for(int i=0;i<8;i++) {
7197 // logln("bits: %02X", (unsigned int)bits[i]);
7198 // }
7199 UnicodeString expect = "-9223372036854775808";
7200 UnicodeString result;
7201 FieldPosition pos;
7202 df.format(long_number, result, pos);
7203 if(U_FAILURE(status)||expect!=result) {
7204 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
7205 } else {
7206 logln("OK: got expected '"+result+"' status "+UnicodeString(u_e rrorName(status),"")+" on -9223372036854775808");
7207 }
6754 } 7208 }
6755 } 7209 }
6756 { 7210 {
6757 UErrorCode status=U_ZERO_ERROR; 7211 UErrorCode status=U_ZERO_ERROR;
6758 DecimalFormat df(UnicodeString("0000000000000000000",""),status); 7212 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6759 int64_t long_number = U_INT64_MAX; // -9223372036854775808L; 7213 if (U_FAILURE(status)) {
6760 // uint8_t bits[8]; 7214 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
6761 // memcpy(bits,&long_number,8);
6762 // for(int i=0;i<8;i++) {
6763 // logln("bits: %02X", (unsigned int)bits[i]);
6764 // }
6765 UnicodeString expect = "9223372036854775807";
6766 UnicodeString result;
6767 FieldPosition pos;
6768 df.format(long_number, result, pos);
6769 if(U_FAILURE(status)||expect!=result) {
6770 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' sta tus "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
6771 } else { 7215 } else {
6772 logln("OK: got expected '"+result+"' status "+UnicodeString(u_error Name(status),"")+" on U_INT64_MAX"); 7216 int64_t long_number = U_INT64_MAX; // -9223372036854775808L;
7217 // uint8_t bits[8];
7218 // memcpy(bits,&long_number,8);
7219 // for(int i=0;i<8;i++) {
7220 // logln("bits: %02X", (unsigned int)bits[i]);
7221 // }
7222 UnicodeString expect = "9223372036854775807";
7223 UnicodeString result;
7224 FieldPosition pos;
7225 df.format(long_number, result, pos);
7226 if(U_FAILURE(status)||expect!=result) {
7227 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
7228 } else {
7229 logln("OK: got expected '"+result+"' status "+UnicodeString(u_e rrorName(status),"")+" on U_INT64_MAX");
7230 }
6773 } 7231 }
6774 } 7232 }
6775 { 7233 {
6776 UErrorCode status=U_ZERO_ERROR; 7234 UErrorCode status=U_ZERO_ERROR;
6777 DecimalFormat df(UnicodeString("0000000000000000000",""),status); 7235 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6778 int64_t long_number = 0; 7236 if (U_FAILURE(status)) {
6779 // uint8_t bits[8]; 7237 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
6780 // memcpy(bits,&long_number,8);
6781 // for(int i=0;i<8;i++) {
6782 // logln("bits: %02X", (unsigned int)bits[i]);
6783 // }
6784 UnicodeString expect = "0000000000000000000";
6785 UnicodeString result;
6786 FieldPosition pos;
6787 df.format(long_number, result, pos);
6788 if(U_FAILURE(status)||expect!=result) {
6789 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' sta tus "+UnicodeString(u_errorName(status),"")+" on 0");
6790 } else { 7238 } else {
6791 logln("OK: got expected '"+result+"' status "+UnicodeString(u_error Name(status),"")+" on 0"); 7239 int64_t long_number = 0;
7240 // uint8_t bits[8];
7241 // memcpy(bits,&long_number,8);
7242 // for(int i=0;i<8;i++) {
7243 // logln("bits: %02X", (unsigned int)bits[i]);
7244 // }
7245 UnicodeString expect = "0000000000000000000";
7246 UnicodeString result;
7247 FieldPosition pos;
7248 df.format(long_number, result, pos);
7249 if(U_FAILURE(status)||expect!=result) {
7250 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
7251 } else {
7252 logln("OK: got expected '"+result+"' status "+UnicodeString(u_e rrorName(status),"")+" on 0");
7253 }
6792 } 7254 }
6793 } 7255 }
6794 { 7256 {
6795 UErrorCode status=U_ZERO_ERROR; 7257 UErrorCode status=U_ZERO_ERROR;
6796 DecimalFormat df(UnicodeString("0000000000000000000",""),status); 7258 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6797 int64_t long_number = U_INT64_MIN + 1; 7259 if (U_FAILURE(status)) {
6798 UnicodeString expect = "-9223372036854775807"; 7260 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
6799 UnicodeString result;
6800 FieldPosition pos;
6801 df.format(long_number, result, pos);
6802 if(U_FAILURE(status)||expect!=result) {
6803 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' sta tus "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
6804 } else { 7261 } else {
6805 logln("OK: got expected '"+result+"' status "+UnicodeString(u_error Name(status),"")+" on -9223372036854775807"); 7262 int64_t long_number = U_INT64_MIN + 1;
7263 UnicodeString expect = "-9223372036854775807";
7264 UnicodeString result;
7265 FieldPosition pos;
7266 df.format(long_number, result, pos);
7267 if(U_FAILURE(status)||expect!=result) {
7268 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
7269 } else {
7270 logln("OK: got expected '"+result+"' status "+UnicodeString(u_e rrorName(status),"")+" on -9223372036854775807");
7271 }
6806 } 7272 }
6807 } 7273 }
6808 } 7274 }
6809 7275
6810 7276
6811 void NumberFormatTest::TestFormattableSize(void) { 7277 void NumberFormatTest::TestFormattableSize(void) {
6812 if(sizeof(FmtStackData) > UNUM_INTERNAL_STACKARRAY_SIZE) { 7278 if(sizeof(FmtStackData) > UNUM_INTERNAL_STACKARRAY_SIZE) {
6813 errln("Error: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n", 7279 errln("Error: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
6814 sizeof(FmtStackData), UNUM_INTERNAL_STACKARRAY_SIZE); 7280 sizeof(FmtStackData), UNUM_INTERNAL_STACKARRAY_SIZE);
6815 } else if(sizeof(FmtStackData) < UNUM_INTERNAL_STACKARRAY_SIZE) { 7281 } else if(sizeof(FmtStackData) < UNUM_INTERNAL_STACKARRAY_SIZE) {
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
7364 if (fmt.getPadCharacterString() != UnicodeString("a")) { 7830 if (fmt.getPadCharacterString() != UnicodeString("a")) {
7365 errln("Padding character should be 'a'."); 7831 errln("Padding character should be 'a'.");
7366 return; 7832 return;
7367 } 7833 }
7368 7834
7369 // Padding char of fmt ought to be '*' since that is the default and no 7835 // Padding char of fmt ought to be '*' since that is the default and no
7370 // explicit padding char is specified in the new pattern. 7836 // explicit padding char is specified in the new pattern.
7371 fmt.applyPattern("AA#,##0.00ZZ", status); 7837 fmt.applyPattern("AA#,##0.00ZZ", status);
7372 7838
7373 // Oops this still prints 'a' even though we changed the pattern. 7839 // Oops this still prints 'a' even though we changed the pattern.
7374 if (fmt.getPadCharacterString() != UnicodeString("*")) { 7840 if (fmt.getPadCharacterString() != UnicodeString(" ")) {
7375 errln("applyPattern did not clear padding character."); 7841 errln("applyPattern did not clear padding character.");
7376 } 7842 }
7377 } 7843 }
7378 7844
7379 void NumberFormatTest::TestRoundingScientific10542() { 7845 void NumberFormatTest::TestRoundingScientific10542() {
7380 UErrorCode status = U_ZERO_ERROR; 7846 UErrorCode status = U_ZERO_ERROR;
7381 DecimalFormat format("0.00E0", status); 7847 DecimalFormat format("0.00E0", status);
7382 if (U_FAILURE(status)) { 7848 if (U_FAILURE(status)) {
7383 errcheckln(status, "DecimalFormat constructor failed - %s", u_errorName( status)); 7849 errcheckln(status, "DecimalFormat constructor failed - %s", u_errorName( status));
7384 return; 7850 return;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
7729 8195
7730 fmt->setCurrency(CUR_PKR, status); 8196 fmt->setCurrency(CUR_PKR, status);
7731 assertSuccess("Set currency to PKR", status); 8197 assertSuccess("Set currency to PKR", status);
7732 8198
7733 UnicodeString PKR_changed; 8199 UnicodeString PKR_changed;
7734 fmt->format(agent, PKR_changed); 8200 fmt->format(agent, PKR_changed);
7735 assertEquals("Test Currency Usage 6", UnicodeString("PKR124"), PKR_chang ed); 8201 assertEquals("Test Currency Usage 6", UnicodeString("PKR124"), PKR_chang ed);
7736 delete fmt; 8202 delete fmt;
7737 } 8203 }
7738 } 8204 }
8205
8206 void NumberFormatTest::TestNumberFormatTestTuple() {
8207 NumberFormatTestTuple tuple;
8208 UErrorCode status = U_ZERO_ERROR;
8209
8210 tuple.setField(
8211 NumberFormatTestTuple::getFieldByName("locale"),
8212 "en",
8213 status);
8214 tuple.setField(
8215 NumberFormatTestTuple::getFieldByName("pattern"),
8216 "#,##0.00",
8217 status);
8218 tuple.setField(
8219 NumberFormatTestTuple::getFieldByName("minIntegerDigits"),
8220 "-10",
8221 status);
8222 if (!assertSuccess("", status)) {
8223 return;
8224 }
8225
8226 // only what we set should be set.
8227 assertEquals("", "en", tuple.locale.getName());
8228 assertEquals("", "#,##0.00", tuple.pattern);
8229 assertEquals("", -10, tuple.minIntegerDigits);
8230 assertTrue("", tuple.localeFlag);
8231 assertTrue("", tuple.patternFlag);
8232 assertTrue("", tuple.minIntegerDigitsFlag);
8233 assertFalse("", tuple.formatFlag);
8234
8235 UnicodeString appendTo;
8236 assertEquals(
8237 "",
8238 "{locale: en, pattern: #,##0.00, minIntegerDigits: -10}",
8239 tuple.toString(appendTo));
8240
8241 tuple.clear();
8242 appendTo.remove();
8243 assertEquals(
8244 "",
8245 "{}",
8246 tuple.toString(appendTo));
8247 tuple.setField(
8248 NumberFormatTestTuple::getFieldByName("aBadFieldName"),
8249 "someValue",
8250 status);
8251 if (status != U_ILLEGAL_ARGUMENT_ERROR) {
8252 errln("Expected U_ILLEGAL_ARGUMENT_ERROR");
8253 }
8254 status = U_ZERO_ERROR;
8255 tuple.setField(
8256 NumberFormatTestTuple::getFieldByName("minIntegerDigits"),
8257 "someBadValue",
8258 status);
8259 if (status != U_ILLEGAL_ARGUMENT_ERROR) {
8260 errln("Expected U_ILLEGAL_ARGUMENT_ERROR");
8261 }
8262 }
8263
8264 void
8265 NumberFormatTest::TestDataDriven() {
8266 NumberFormatTestDataDriven dd;
8267 dd.setCaller(this);
8268 dd.run("numberformattestspecification.txt", FALSE);
8269 }
8270
8271
8272 // Check the constant MAX_INT64_IN_DOUBLE.
8273 // The value should convert to a double with no loss of precision.
8274 // A failure may indicate a platform with a different double format, requiring
8275 // a revision to the constant.
8276 //
8277 // Note that this is actually hard to test, because the language standard gives
8278 // compilers considerable flexibility to do unexpected things with rounding and
8279 // with overflow in simple int to/from float conversions. Some compilers will c ompletely optimize
8280 // away a simple round-trip conversion from int64_t -> double -> int64_t.
8281
8282 void NumberFormatTest::TestDoubleLimit11439() {
8283 char buf[50];
8284 for (int64_t num = MAX_INT64_IN_DOUBLE-10; num<=MAX_INT64_IN_DOUBLE; num++) {
8285 sprintf(buf, "%lld", (long long)num);
8286 double fNum = 0.0;
8287 sscanf(buf, "%lf", &fNum);
8288 int64_t rtNum = fNum;
8289 if (num != rtNum) {
8290 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__, __LINE__, (long long)num, (long long)rtNum);
8291 return;
8292 }
8293 }
8294 for (int64_t num = -MAX_INT64_IN_DOUBLE+10; num>=-MAX_INT64_IN_DOUBLE; num-- ) {
8295 sprintf(buf, "%lld", (long long)num);
8296 double fNum = 0.0;
8297 sscanf(buf, "%lf", &fNum);
8298 int64_t rtNum = fNum;
8299 if (num != rtNum) {
8300 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__, __LINE__, (long long)num, (long long)rtNum);
8301 return;
8302 }
8303 }
8304 }
8305
8306 void NumberFormatTest::TestFastPathConsistent11524() {
8307 UErrorCode status = U_ZERO_ERROR;
8308 NumberFormat *fmt = NumberFormat::createInstance("en", status);
8309 if (U_FAILURE(status) || fmt == NULL) {
8310 dataerrln("Failed call to NumberFormat::createInstance() - %s", u_errorN ame(status));
8311 return;
8312 }
8313 fmt->setMaximumIntegerDigits(INT32_MIN);
8314 UnicodeString appendTo;
8315 assertEquals("", "0", fmt->format(123, appendTo));
8316 appendTo.remove();
8317 assertEquals("", "0", fmt->format(12345, appendTo));
8318 delete fmt;
8319 }
8320
8321 void NumberFormatTest::TestGetAffixes() {
8322 UErrorCode status = U_ZERO_ERROR;
8323 DecimalFormatSymbols sym("en_US", status);
8324 UnicodeString pattern("\\u00a4\\u00a4\\u00a4 0.00 %\\u00a4\\u00a4");
8325 pattern = pattern.unescape();
8326 DecimalFormat fmt(pattern, sym, status);
8327 if (U_FAILURE(status)) {
8328 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
8329 return;
8330 }
8331 UnicodeString affixStr;
8332 assertEquals("", "US dollars ", fmt.getPositivePrefix(affixStr));
8333 assertEquals("", " %USD", fmt.getPositiveSuffix(affixStr));
8334 assertEquals("", "-US dollars ", fmt.getNegativePrefix(affixStr));
8335 assertEquals("", " %USD", fmt.getNegativeSuffix(affixStr));
8336
8337 // Test equality with affixes. set affix methods can't capture special
8338 // characters which is why equality should fail.
8339 {
8340 DecimalFormat fmtCopy(fmt);
8341 assertTrue("", fmt == fmtCopy);
8342 UnicodeString someAffix;
8343 fmtCopy.setPositivePrefix(fmtCopy.getPositivePrefix(someAffix));
8344 assertTrue("", fmt != fmtCopy);
8345 }
8346 {
8347 DecimalFormat fmtCopy(fmt);
8348 assertTrue("", fmt == fmtCopy);
8349 UnicodeString someAffix;
8350 fmtCopy.setPositiveSuffix(fmtCopy.getPositiveSuffix(someAffix));
8351 assertTrue("", fmt != fmtCopy);
8352 }
8353 {
8354 DecimalFormat fmtCopy(fmt);
8355 assertTrue("", fmt == fmtCopy);
8356 UnicodeString someAffix;
8357 fmtCopy.setNegativePrefix(fmtCopy.getNegativePrefix(someAffix));
8358 assertTrue("", fmt != fmtCopy);
8359 }
8360 {
8361 DecimalFormat fmtCopy(fmt);
8362 assertTrue("", fmt == fmtCopy);
8363 UnicodeString someAffix;
8364 fmtCopy.setNegativeSuffix(fmtCopy.getNegativeSuffix(someAffix));
8365 assertTrue("", fmt != fmtCopy);
8366 }
8367 fmt.setPositivePrefix("Don't");
8368 fmt.setPositiveSuffix("do");
8369 UnicodeString someAffix("be''eet\\u00a4\\u00a4\\u00a4 it.");
8370 someAffix = someAffix.unescape();
8371 fmt.setNegativePrefix(someAffix);
8372 fmt.setNegativeSuffix("%");
8373 assertEquals("", "Don't", fmt.getPositivePrefix(affixStr));
8374 assertEquals("", "do", fmt.getPositiveSuffix(affixStr));
8375 assertEquals("", someAffix, fmt.getNegativePrefix(affixStr));
8376 assertEquals("", "%", fmt.getNegativeSuffix(affixStr));
8377 }
8378
8379 void NumberFormatTest::TestToPatternScientific11648() {
8380 UErrorCode status = U_ZERO_ERROR;
8381 Locale en("en");
8382 DecimalFormatSymbols sym(en, status);
8383 DecimalFormat fmt("0.00", sym, status);
8384 if (U_FAILURE(status)) {
8385 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
8386 return;
8387 }
8388 fmt.setScientificNotation(TRUE);
8389 UnicodeString pattern;
8390 assertEquals("", "0.00E0", fmt.toPattern(pattern));
8391 DecimalFormat fmt2(pattern, sym, status);
8392 assertSuccess("", status);
8393 }
8394
8395 void NumberFormatTest::TestBenchmark() {
8396 /*
8397 UErrorCode status = U_ZERO_ERROR;
8398 Locale en("en");
8399 DecimalFormatSymbols sym(en, status);
8400 DecimalFormat fmt("0.0000000", new DecimalFormatSymbols(sym), status);
8401 // DecimalFormat fmt("0.00000E0", new DecimalFormatSymbols(sym), status);
8402 // DecimalFormat fmt("0", new DecimalFormatSymbols(sym), status);
8403 FieldPosition fpos(0);
8404 clock_t start = clock();
8405 for (int32_t i = 0; i < 1000000; ++i) {
8406 UnicodeString append;
8407 fmt.format(3.0, append, fpos, status);
8408 // fmt.format(4.6692016, append, fpos, status);
8409 // fmt.format(1234567.8901, append, fpos, status);
8410 // fmt.format(2.99792458E8, append, fpos, status);
8411 // fmt.format(31, append);
8412 }
8413 errln("Took %f", (double) (clock() - start) / CLOCKS_PER_SEC);
8414 assertSuccess("", status);
8415
8416 UErrorCode status = U_ZERO_ERROR;
8417 MessageFormat fmt("{0, plural, one {I have # friend.} other {I have # friend s.}}", status);
8418 FieldPosition fpos(0);
8419 Formattable one(1.0);
8420 Formattable three(3.0);
8421 clock_t start = clock();
8422 for (int32_t i = 0; i < 500000; ++i) {
8423 UnicodeString append;
8424 fmt.format(&one, 1, append, fpos, status);
8425 UnicodeString append2;
8426 fmt.format(&three, 1, append2, fpos, status);
8427 }
8428 errln("Took %f", (double) (clock() - start) / CLOCKS_PER_SEC);
8429 assertSuccess("", status);
8430
8431 UErrorCode status = U_ZERO_ERROR;
8432 Locale en("en");
8433 Measure measureC(23, MeasureUnit::createCelsius(status), status);
8434 MeasureFormat fmt(en, UMEASFMT_WIDTH_WIDE, status);
8435 FieldPosition fpos(0);
8436 clock_t start = clock();
8437 for (int32_t i = 0; i < 1000000; ++i) {
8438 UnicodeString appendTo;
8439 fmt.formatMeasures(
8440 &measureC, 1, appendTo, fpos, status);
8441 }
8442 errln("Took %f", (double) (clock() - start) / CLOCKS_PER_SEC);
8443 assertSuccess("", status);
8444 */
8445 }
8446
8447 void NumberFormatTest::TestFractionalDigitsForCurrency() {
8448 UErrorCode status = U_ZERO_ERROR;
8449 LocalPointer<NumberFormat> fmt(NumberFormat::createCurrencyInstance("en", st atus));
8450 if (U_FAILURE(status)) {
8451 dataerrln("Error creating NumberFormat - %s", u_errorName(status));
8452 return;
8453 }
8454 UChar JPY[] = {0x4A, 0x50, 0x59, 0x0};
8455 fmt->setCurrency(JPY, status);
8456 if (!assertSuccess("", status)) {
8457 return;
8458 }
8459 assertEquals("", 0, fmt->getMaximumFractionDigits());
8460 }
8461
8462
8463 void NumberFormatTest::TestFormatCurrencyPlural() {
8464 UErrorCode status = U_ZERO_ERROR;
8465 Locale locale = Locale::createCanonical("en_US");
8466 NumberFormat *fmt = NumberFormat::createInstance(locale, UNUM_CURRENCY_PLURA L, status);
8467 if (U_FAILURE(status)) {
8468 dataerrln("Error creating NumberFormat - %s", u_errorName(status));
8469 return;
8470 }
8471 UnicodeString formattedNum;
8472 fmt->format(11234.567, formattedNum, NULL, status);
8473 assertEquals("", "11,234.57 US dollars", formattedNum);
8474 delete fmt;
8475 }
8476
8477 void NumberFormatTest::TestCtorApplyPatternDifference() {
8478 UErrorCode status = U_ZERO_ERROR;
8479 DecimalFormatSymbols sym("en_US", status);
8480 UnicodeString pattern("\\u00a40");
8481 DecimalFormat fmt(pattern.unescape(), sym, status);
8482 if (U_FAILURE(status)) {
8483 dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
8484 return;
8485 }
8486 UnicodeString result;
8487 assertEquals(
8488 "ctor favors precision of currency",
8489 "$5.00",
8490 fmt.format(5, result));
8491 result.remove();
8492 fmt.applyPattern(pattern.unescape(), status);
8493 assertEquals(
8494 "applyPattern favors precision of pattern",
8495 "$5",
8496 fmt.format(5, result));
8497 }
8498
8499 void NumberFormatTest::Test11868() {
8500 double posAmt = 34.567;
8501 double negAmt = -9876.543;
8502
8503 Locale selectedLocale("en_US");
8504 UErrorCode status = U_ZERO_ERROR;
8505
8506 UnicodeString result;
8507 FieldPosition fpCurr(UNUM_CURRENCY_FIELD);
8508 LocalPointer<NumberFormat> fmt(
8509 NumberFormat::createInstance(
8510 selectedLocale, UNUM_CURRENCY_PLURAL, status));
8511 if (!assertSuccess("Format creation", status)) {
8512 return;
8513 }
8514 fmt->format(posAmt, result, fpCurr, status);
8515 assertEquals("", "34.57 US dollars", result);
8516 assertEquals("begin index", 6, fpCurr.getBeginIndex());
8517 assertEquals("end index", 16, fpCurr.getEndIndex());
8518
8519 // Test field position iterator
8520 {
8521 NumberFormatTest_Attributes attributes[] = {
8522 {UNUM_INTEGER_FIELD, 0, 2},
8523 {UNUM_DECIMAL_SEPARATOR_FIELD, 2, 3},
8524 {UNUM_FRACTION_FIELD, 3, 5},
8525 {UNUM_CURRENCY_FIELD, 6, 16},
8526 {0, -1, 0}};
8527 UnicodeString result;
8528 FieldPositionIterator iter;
8529 fmt->format(posAmt, result, &iter, status);
8530 assertEquals("", "34.57 US dollars", result);
8531 verifyFieldPositionIterator(attributes, iter);
8532 }
8533
8534 result.remove();
8535 fmt->format(negAmt, result, fpCurr, status);
8536 assertEquals("", "-9,876.54 US dollars", result);
8537 assertEquals("begin index", 10, fpCurr.getBeginIndex());
8538 assertEquals("end index", 20, fpCurr.getEndIndex());
8539
8540 // Test field position iterator
8541 {
8542 NumberFormatTest_Attributes attributes[] = {
8543 {UNUM_SIGN_FIELD, 0, 1},
8544 {UNUM_GROUPING_SEPARATOR_FIELD, 2, 3},
8545 {UNUM_INTEGER_FIELD, 1, 6},
8546 {UNUM_DECIMAL_SEPARATOR_FIELD, 6, 7},
8547 {UNUM_FRACTION_FIELD, 7, 9},
8548 {UNUM_CURRENCY_FIELD, 10, 20},
8549 {0, -1, 0}};
8550 UnicodeString result;
8551 FieldPositionIterator iter;
8552 fmt->format(negAmt, result, &iter, status);
8553 assertEquals("", "-9,876.54 US dollars", result);
8554 verifyFieldPositionIterator(attributes, iter);
8555 }
8556 }
8557
8558 void NumberFormatTest::Test10727_RoundingZero() {
8559 DigitList d;
8560 d.set(-0.0);
8561 assertFalse("", d.isPositive());
8562 d.round(3);
8563 assertFalse("", d.isPositive());
8564 }
8565
8566 void NumberFormatTest::Test11376_getAndSetPositivePrefix() {
8567 {
8568 const UChar USD[] = {0x55, 0x53, 0x44, 0x0};
8569 UErrorCode status = U_ZERO_ERROR;
8570 LocalPointer<NumberFormat> fmt(
8571 NumberFormat::createCurrencyInstance("en", status));
8572 if (!assertSuccess("", status)) {
8573 return;
8574 }
8575 DecimalFormat *dfmt = (DecimalFormat *) fmt.getAlias();
8576 dfmt->setCurrency(USD);
8577 UnicodeString result;
8578
8579 // This line should be a no-op. I am setting the positive prefix
8580 // to be the same thing it was before.
8581 dfmt->setPositivePrefix(dfmt->getPositivePrefix(result));
8582
8583 UnicodeString appendTo;
8584 assertEquals("", "$3.78", dfmt->format(3.78, appendTo, status));
8585 assertSuccess("", status);
8586 }
8587 {
8588 const UChar USD[] = {0x55, 0x53, 0x44, 0x0};
8589 UErrorCode status = U_ZERO_ERROR;
8590 LocalPointer<NumberFormat> fmt(
8591 NumberFormat::createInstance("en", UNUM_CURRENCY_PLURAL, status) );
8592 if (!assertSuccess("", status)) {
8593 return;
8594 }
8595 DecimalFormat *dfmt = (DecimalFormat *) fmt.getAlias();
8596 UnicodeString result;
8597 UnicodeString tripleIntlCurrency(" \\u00a4\\u00a4\\u00a4");
8598 tripleIntlCurrency = tripleIntlCurrency.unescape();
8599 assertEquals("", tripleIntlCurrency, dfmt->getPositiveSuffix(result));
8600 dfmt->setCurrency(USD);
8601
8602 // getPositiveSuffix() always returns the suffix for the
8603 // "other" plural category
8604 assertEquals("", " US dollars", dfmt->getPositiveSuffix(result));
8605 UnicodeString appendTo;
8606 assertEquals("", "3.78 US dollars", dfmt->format(3.78, appendTo, status) );
8607 assertEquals("", " US dollars", dfmt->getPositiveSuffix(result));
8608 dfmt->setPositiveSuffix("booya");
8609 appendTo.remove();
8610 assertEquals("", "3.78booya", dfmt->format(3.78, appendTo, status));
8611 assertEquals("", "booya", dfmt->getPositiveSuffix(result));
8612 }
8613 }
8614
8615 void NumberFormatTest::Test11475_signRecognition() {
8616 UErrorCode status = U_ZERO_ERROR;
8617 DecimalFormatSymbols sym("en", status);
8618 UnicodeString result;
8619 {
8620 DecimalFormat fmt("+0.00", sym, status);
8621 if (!assertSuccess("", status)) {
8622 return;
8623 }
8624 NumberFormatTest_Attributes attributes[] = {
8625 {UNUM_SIGN_FIELD, 0, 1},
8626 {UNUM_INTEGER_FIELD, 1, 2},
8627 {UNUM_DECIMAL_SEPARATOR_FIELD, 2, 3},
8628 {UNUM_FRACTION_FIELD, 3, 5},
8629 {0, -1, 0}};
8630 UnicodeString result;
8631 FieldPositionIterator iter;
8632 fmt.format(2.3, result, &iter, status);
8633 assertEquals("", "+2.30", result);
8634 verifyFieldPositionIterator(attributes, iter);
8635 }
8636 {
8637 DecimalFormat fmt("++0.00+;-(#)--", sym, status);
8638 if (!assertSuccess("", status)) {
8639 return;
8640 }
8641 {
8642 NumberFormatTest_Attributes attributes[] = {
8643 {UNUM_SIGN_FIELD, 0, 2},
8644 {UNUM_INTEGER_FIELD, 2, 3},
8645 {UNUM_DECIMAL_SEPARATOR_FIELD, 3, 4},
8646 {UNUM_FRACTION_FIELD, 4, 6},
8647 {UNUM_SIGN_FIELD, 6, 7},
8648 {0, -1, 0}};
8649 UnicodeString result;
8650 FieldPositionIterator iter;
8651 fmt.format(2.3, result, &iter, status);
8652 assertEquals("", "++2.30+", result);
8653 verifyFieldPositionIterator(attributes, iter);
8654 }
8655 {
8656 NumberFormatTest_Attributes attributes[] = {
8657 {UNUM_SIGN_FIELD, 0, 1},
8658 {UNUM_INTEGER_FIELD, 2, 3},
8659 {UNUM_DECIMAL_SEPARATOR_FIELD, 3, 4},
8660 {UNUM_FRACTION_FIELD, 4, 6},
8661 {UNUM_SIGN_FIELD, 7, 9},
8662 {0, -1, 0}};
8663 UnicodeString result;
8664 FieldPositionIterator iter;
8665 fmt.format(-2.3, result, &iter, status);
8666 assertEquals("", "-(2.30)--", result);
8667 verifyFieldPositionIterator(attributes, iter);
8668 }
8669 }
8670 }
8671
8672 void NumberFormatTest::Test11640_getAffixes() {
8673 UErrorCode status = U_ZERO_ERROR;
8674 DecimalFormatSymbols symbols("en_US", status);
8675 if (!assertSuccess("", status)) {
8676 return;
8677 }
8678 UnicodeString pattern("\\u00a4\\u00a4\\u00a4 0.00 %\\u00a4\\u00a4");
8679 pattern = pattern.unescape();
8680 DecimalFormat fmt(pattern, symbols, status);
8681 if (!assertSuccess("", status)) {
8682 return;
8683 }
8684 UnicodeString affixStr;
8685 assertEquals("", "US dollars ", fmt.getPositivePrefix(affixStr));
8686 assertEquals("", " %USD", fmt.getPositiveSuffix(affixStr));
8687 assertEquals("", "-US dollars ", fmt.getNegativePrefix(affixStr));
8688 assertEquals("", " %USD", fmt.getNegativeSuffix(affixStr));
8689 }
8690
8691 void NumberFormatTest::Test11649_toPatternWithMultiCurrency() {
8692 UnicodeString pattern("\\u00a4\\u00a4\\u00a4 0.00");
8693 pattern = pattern.unescape();
8694 UErrorCode status = U_ZERO_ERROR;
8695 DecimalFormat fmt(pattern, status);
8696 if (!assertSuccess("", status)) {
8697 return;
8698 }
8699 static UChar USD[] = {0x55, 0x53, 0x44, 0x0};
8700 fmt.setCurrency(USD);
8701 UnicodeString appendTo;
8702
8703 assertEquals("", "US dollars 12.34", fmt.format(12.34, appendTo));
8704
8705 UnicodeString topattern;
8706 fmt.toPattern(topattern);
8707 DecimalFormat fmt2(topattern, status);
8708 if (!assertSuccess("", status)) {
8709 return;
8710 }
8711 fmt2.setCurrency(USD);
8712
8713 appendTo.remove();
8714 assertEquals("", "US dollars 12.34", fmt2.format(12.34, appendTo));
8715 }
8716
8717
8718 void NumberFormatTest::verifyFieldPositionIterator(
8719 NumberFormatTest_Attributes *expected, FieldPositionIterator &iter) {
8720 int32_t idx = 0;
8721 FieldPosition fp;
8722 while (iter.next(fp)) {
8723 if (expected[idx].spos == -1) {
8724 errln("Iterator should have ended. got %d", fp.getField());
8725 return;
8726 }
8727 assertEquals("id", expected[idx].id, fp.getField());
8728 assertEquals("start", expected[idx].spos, fp.getBeginIndex());
8729 assertEquals("end", expected[idx].epos, fp.getEndIndex());
8730 ++idx;
8731 }
8732 if (expected[idx].spos != -1) {
8733 errln("Premature end of iterator. expected %d", expected[idx].id);
8734 }
8735 }
8736
8737
8738
7739 #endif /* #if !UCONFIG_NO_FORMATTING */ 8739 #endif /* #if !UCONFIG_NO_FORMATTING */
OLDNEW
« no previous file with comments | « source/test/intltest/numfmtst.h ('k') | source/test/intltest/numrgts.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698