1 /********************************************************************
3 * Copyright (c) 1997-2015, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /* Modification History:
7 * Date Name Description
8 * 07/15/99 helena Ported to HPUX 10/11 CC.
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_FORMATTING
16 #include "unicode/dcfmtsym.h"
17 #include "unicode/decimfmt.h"
18 #include "unicode/localpointer.h"
19 #include "unicode/ucurr.h"
20 #include "unicode/ustring.h"
21 #include "unicode/measfmt.h"
22 #include "unicode/curramt.h"
33 #include "unicode/numsys.h"
34 #include "fmtableimp.h"
36 //#define NUMFMTST_CACHE_DEBUG 1
37 #include "stdio.h" /* for sprintf */
38 // #include "iostream" // for cout
40 //#define NUMFMTST_DEBUG 1
42 static const UChar EUR
[] = {69,85,82,0}; // "EUR"
43 static const UChar ISO_CURRENCY_USD
[] = {0x55, 0x53, 0x44, 0}; // "USD"
46 // *****************************************************************************
47 // class NumberFormatTest
48 // *****************************************************************************
50 #define CHECK(status,str) if (U_FAILURE(status)) { errcheckln(status, UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
51 #define CHECK_DATA(status,str) if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
53 void NumberFormatTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
56 TESTCASE_AUTO(TestCurrencySign
);
57 TESTCASE_AUTO(TestCurrency
);
58 TESTCASE_AUTO(TestParse
);
59 TESTCASE_AUTO(TestRounding487
);
60 TESTCASE_AUTO(TestQuotes
);
61 TESTCASE_AUTO(TestExponential
);
62 TESTCASE_AUTO(TestPatterns
);
64 // Upgrade to alphaWorks - liu 5/99
65 TESTCASE_AUTO(TestExponent
);
66 TESTCASE_AUTO(TestScientific
);
67 TESTCASE_AUTO(TestPad
);
68 TESTCASE_AUTO(TestPatterns2
);
69 TESTCASE_AUTO(TestSecondaryGrouping
);
70 TESTCASE_AUTO(TestSurrogateSupport
);
71 TESTCASE_AUTO(TestAPI
);
73 TESTCASE_AUTO(TestCurrencyObject
);
74 TESTCASE_AUTO(TestCurrencyPatterns
);
75 //TESTCASE_AUTO(TestDigitList);
76 TESTCASE_AUTO(TestWhiteSpaceParsing
);
77 TESTCASE_AUTO(TestComplexCurrency
); // This test removed because CLDR no longer uses choice formats in currency symbols.
78 TESTCASE_AUTO(TestRegCurrency
);
79 TESTCASE_AUTO(TestSymbolsWithBadLocale
);
80 TESTCASE_AUTO(TestAdoptDecimalFormatSymbols
);
82 TESTCASE_AUTO(TestScientific2
);
83 TESTCASE_AUTO(TestScientificGrouping
);
84 TESTCASE_AUTO(TestInt64
);
86 TESTCASE_AUTO(TestPerMill
);
87 TESTCASE_AUTO(TestIllegalPatterns
);
88 TESTCASE_AUTO(TestCases
);
90 TESTCASE_AUTO(TestCurrencyNames
);
91 TESTCASE_AUTO(TestCurrencyAmount
);
92 TESTCASE_AUTO(TestCurrencyUnit
);
93 TESTCASE_AUTO(TestCoverage
);
94 TESTCASE_AUTO(TestJB3832
);
95 TESTCASE_AUTO(TestHost
);
96 TESTCASE_AUTO(TestHostClone
);
97 TESTCASE_AUTO(TestCurrencyFormat
);
98 TESTCASE_AUTO(TestRounding
);
99 TESTCASE_AUTO(TestNonpositiveMultiplier
);
100 TESTCASE_AUTO(TestNumberingSystems
);
101 TESTCASE_AUTO(TestSpaceParsing
);
102 TESTCASE_AUTO(TestMultiCurrencySign
);
103 TESTCASE_AUTO(TestCurrencyFormatForMixParsing
);
104 TESTCASE_AUTO(TestDecimalFormatCurrencyParse
);
105 TESTCASE_AUTO(TestCurrencyIsoPluralFormat
);
106 TESTCASE_AUTO(TestCurrencyParsing
);
107 TESTCASE_AUTO(TestParseCurrencyInUCurr
);
108 TESTCASE_AUTO(TestFormatAttributes
);
109 TESTCASE_AUTO(TestFieldPositionIterator
);
110 TESTCASE_AUTO(TestDecimal
);
111 TESTCASE_AUTO(TestCurrencyFractionDigits
);
112 TESTCASE_AUTO(TestExponentParse
);
113 TESTCASE_AUTO(TestExplicitParents
);
114 TESTCASE_AUTO(TestLenientParse
);
115 TESTCASE_AUTO(TestAvailableNumberingSystems
);
116 TESTCASE_AUTO(TestRoundingPattern
);
117 TESTCASE_AUTO(Test9087
);
118 TESTCASE_AUTO(TestFormatFastpaths
);
119 TESTCASE_AUTO(TestFormattableSize
);
120 TESTCASE_AUTO(TestUFormattable
);
121 TESTCASE_AUTO(TestSignificantDigits
);
122 TESTCASE_AUTO(TestShowZero
);
123 TESTCASE_AUTO(TestCompatibleCurrencies
);
124 TESTCASE_AUTO(TestBug9936
);
125 TESTCASE_AUTO(TestParseNegativeWithFaLocale
);
126 TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign
);
127 TESTCASE_AUTO(TestCustomCurrencySignAndSeparator
);
128 TESTCASE_AUTO(TestParseSignsAndMarks
);
129 TESTCASE_AUTO(Test10419RoundingWith0FractionDigits
);
130 TESTCASE_AUTO(Test10468ApplyPattern
);
131 TESTCASE_AUTO(TestRoundingScientific10542
);
132 TESTCASE_AUTO(TestZeroScientific10547
);
133 TESTCASE_AUTO(TestAccountingCurrency
);
134 TESTCASE_AUTO(TestEquality
);
135 TESTCASE_AUTO(TestCurrencyUsage
);
136 TESTCASE_AUTO(TestDoubleLimit11439
);
137 TESTCASE_AUTO(TestFastPathConsistent11524
);
141 // -------------------------------------
143 // Test API (increase code coverage)
145 NumberFormatTest::TestAPI(void)
148 UErrorCode status
= U_ZERO_ERROR
;
149 NumberFormat
*test
= NumberFormat::createInstance("root", status
);
150 if(U_FAILURE(status
)) {
151 dataerrln("unable to create format object - %s", u_errorName(status
));
154 test
->setMinimumIntegerDigits(10);
155 test
->setMaximumIntegerDigits(2);
157 test
->setMinimumFractionDigits(10);
158 test
->setMaximumFractionDigits(2);
160 UnicodeString result
;
162 Formattable
bla("Paja Patak"); // Donald Duck for non Serbian speakers
163 test
->format(bla
, result
, pos
, status
);
164 if(U_SUCCESS(status
)) {
165 errln("Yuck... Formatted a duck... As a number!");
167 status
= U_ZERO_ERROR
;
172 test
->format(ll
, result
);
173 if (result
!= "12.00"){
174 errln("format int64_t error");
178 LocalPointer
<CurrencyAmount
> currAmt(test
->parseCurrency("",ppos
));
179 // old test for (U_FAILURE(status)) was bogus here, method does not set status!
180 if (ppos
.getIndex()) {
181 errln("Parsed empty string as currency");
188 class StubNumberFormat
:public NumberFormat
{
190 StubNumberFormat(){};
191 virtual UnicodeString
& format(double ,UnicodeString
& appendTo
,FieldPosition
& ) const {
194 virtual UnicodeString
& format(int32_t ,UnicodeString
& appendTo
,FieldPosition
& ) const {
195 return appendTo
.append((UChar
)0x0033);
197 virtual UnicodeString
& format(int64_t number
,UnicodeString
& appendTo
,FieldPosition
& pos
) const {
198 return NumberFormat::format(number
, appendTo
, pos
);
200 virtual UnicodeString
& format(const Formattable
& , UnicodeString
& appendTo
, FieldPosition
& , UErrorCode
& ) const {
203 virtual void parse(const UnicodeString
& ,
205 ParsePosition
& ) const {}
206 virtual void parse( const UnicodeString
& ,
208 UErrorCode
& ) const {}
209 virtual UClassID
getDynamicClassID(void) const {
210 static char classID
= 0;
211 return (UClassID
)&classID
;
213 virtual Format
* clone() const {return NULL
;}
217 NumberFormatTest::TestCoverage(void){
218 StubNumberFormat stub
;
219 UnicodeString
agent("agent");
222 if (stub
.format(num
, agent
, pos
) != UnicodeString("agent3")){
223 errln("NumberFormat::format(int64, UnicodString&, FieldPosition&) should delegate to (int32, ,)");
227 // Test various patterns
229 NumberFormatTest::TestPatterns(void)
231 UErrorCode status
= U_ZERO_ERROR
;
232 DecimalFormatSymbols
sym(Locale::getUS(), status
);
233 if (U_FAILURE(status
)) { errcheckln(status
, "FAIL: Could not construct DecimalFormatSymbols - %s", u_errorName(status
)); return; }
235 const char* pat
[] = { "#.#", "#.", ".#", "#" };
236 int32_t pat_length
= (int32_t)(sizeof(pat
) / sizeof(pat
[0]));
237 const char* newpat
[] = { "#0.#", "#0.", "#.0", "#" };
238 const char* num
[] = { "0", "0.", ".0", "0" };
239 for (int32_t i
=0; i
<pat_length
; ++i
)
241 status
= U_ZERO_ERROR
;
242 DecimalFormat
fmt(pat
[i
], sym
, status
);
243 if (U_FAILURE(status
)) { errln((UnicodeString
)"FAIL: DecimalFormat constructor failed for " + pat
[i
]); continue; }
244 UnicodeString newp
; fmt
.toPattern(newp
);
245 if (!(newp
== newpat
[i
]))
246 errln((UnicodeString
)"FAIL: Pattern " + pat
[i
] + " should transmute to " + newpat
[i
] +
247 "; " + newp
+ " seen instead");
249 UnicodeString s
; (*(NumberFormat
*)&fmt
).format((int32_t)0, s
);
252 errln((UnicodeString
)"FAIL: Pattern " + pat
[i
] + " should format zero as " + num
[i
] +
253 "; " + s
+ " seen instead");
254 logln((UnicodeString
)"Min integer digits = " + fmt
.getMinimumIntegerDigits());
260 icu_2_4::DigitList::operator== 0 0 2 icuuc24d.dll digitlst.cpp Doug
261 icu_2_4::DigitList::append 0 0 4 icuin24d.dll digitlst.h Doug
262 icu_2_4::DigitList::operator!= 0 0 1 icuuc24d.dll digitlst.h Doug
266 NumberFormatTest::TestDigitList(void)
268 // API coverage for DigitList
271 list1.fDecimalAt = 1;
273 list2.set((int32_t)1);
274 if (list1 != list2) {
275 errln("digitlist append, operator!= or set failed ");
277 if (!(list1 == list2)) {
278 errln("digitlist append, operator== or set failed ");
283 // -------------------------------------
285 // Test exponential pattern
287 NumberFormatTest::TestExponential(void)
289 UErrorCode status
= U_ZERO_ERROR
;
290 DecimalFormatSymbols
sym(Locale::getUS(), status
);
291 if (U_FAILURE(status
)) { errcheckln(status
, "FAIL: Bad status returned by DecimalFormatSymbols ct - %s", u_errorName(status
)); return; }
292 const char* pat
[] = { "0.####E0", "00.000E00", "##0.######E000", "0.###E0;[0.###E0]" };
293 int32_t pat_length
= (int32_t)(sizeof(pat
) / sizeof(pat
[0]));
295 // The following #if statements allow this test to be built and run on
296 // platforms that do not have standard IEEE numerics. For example,
297 // S/390 doubles have an exponent range of -78 to +75. For the
298 // following #if statements to work, float.h must define
299 // DBL_MAX_10_EXP to be a compile-time constant.
301 // This section may be expanded as needed.
303 #if DBL_MAX_10_EXP > 300
304 double val
[] = { 0.01234, 123456789, 1.23e300
, -3.141592653e-271 };
305 int32_t val_length
= (int32_t)(sizeof(val
) / sizeof(val
[0]));
306 const char* valFormat
[] =
309 "1.234E-2", "1.2346E8", "1.23E300", "-3.1416E-271",
311 "12.340E-03", "12.346E07", "12.300E299", "-31.416E-272",
313 "12.34E-003", "123.4568E006", "1.23E300", "-314.1593E-273",
315 "1.234E-2", "1.235E8", "1.23E300", "[3.142E-271]"
319 0.01234, 123460000, 1.23E300
, -3.1416E-271,
320 0.01234, 123460000, 1.23E300
, -3.1416E-271,
321 0.01234, 123456800, 1.23E300
, -3.141593E-271,
322 0.01234, 123500000, 1.23E300
, -3.142E-271,
324 #elif DBL_MAX_10_EXP > 70
325 double val
[] = { 0.01234, 123456789, 1.23e70
, -3.141592653e-71 };
326 int32_t val_length
= sizeof(val
) / sizeof(val
[0]);
330 "1.234E-2", "1.2346E8", "1.23E70", "-3.1416E-71",
332 "12.340E-03", "12.346E07", "12.300E69", "-31.416E-72",
334 "12.34E-003", "123.4568E006", "12.3E069", "-31.41593E-072",
336 "1.234E-2", "1.235E8", "1.23E70", "[3.142E-71]"
340 0.01234, 123460000, 1.23E70
, -3.1416E-71,
341 0.01234, 123460000, 1.23E70
, -3.1416E-71,
342 0.01234, 123456800, 1.23E70
, -3.141593E-71,
343 0.01234, 123500000, 1.23E70
, -3.142E-71,
346 // Don't test double conversion
348 int32_t val_length
= 0;
349 char** valFormat
= 0;
350 double* valParse
= 0;
351 logln("Warning: Skipping double conversion tests");
354 int32_t lval
[] = { 0, -1, 1, 123456789 };
355 int32_t lval_length
= (int32_t)(sizeof(lval
) / sizeof(lval
[0]));
356 const char* lvalFormat
[] =
359 "0E0", "-1E0", "1E0", "1.2346E8",
361 "00.000E00", "-10.000E-01", "10.000E-01", "12.346E07",
363 "0E000", "-1E000", "1E000", "123.4568E006",
365 "0E0", "[1E0]", "1E0", "1.235E8"
367 int32_t lvalParse
[] =
374 int32_t ival
= 0, ilval
= 0;
375 for (int32_t p
=0; p
<pat_length
; ++p
)
377 DecimalFormat
fmt(pat
[p
], sym
, status
);
378 if (U_FAILURE(status
)) { errln("FAIL: Bad status returned by DecimalFormat ct"); continue; }
379 UnicodeString pattern
;
380 logln((UnicodeString
)"Pattern \"" + pat
[p
] + "\" -toPattern-> \"" +
381 fmt
.toPattern(pattern
) + "\"");
383 for (v
=0; v
<val_length
; ++v
)
385 UnicodeString s
; (*(NumberFormat
*)&fmt
).format(val
[v
], s
);
386 logln((UnicodeString
)" " + val
[v
] + " -format-> " + s
);
387 if (s
!= valFormat
[v
+ival
])
388 errln((UnicodeString
)"FAIL: Expected " + valFormat
[v
+ival
]);
390 ParsePosition
pos(0);
392 fmt
.parse(s
, af
, pos
);
394 UBool useEpsilon
= FALSE
;
395 if (af
.getType() == Formattable::kLong
)
397 else if (af
.getType() == Formattable::kDouble
) {
399 #if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
400 // S/390 will show a failure like this:
401 //| -3.141592652999999e-271 -format-> -3.1416E-271
402 //| -parse-> -3.1416e-271
403 //| FAIL: Expected -3.141599999999999e-271
404 // To compensate, we use an epsilon-based equality
405 // test on S/390 only. We don't want to do this in
406 // general because it's less exacting.
411 errln((UnicodeString
)"FAIL: Non-numeric Formattable returned");
414 if (pos
.getIndex() == s
.length())
416 logln((UnicodeString
)" -parse-> " + a
);
417 // Use epsilon comparison as necessary
419 (uprv_fabs(a
- valParse
[v
+ival
]) / a
> (2*DBL_EPSILON
))) ||
420 (!useEpsilon
&& a
!= valParse
[v
+ival
]))
422 errln((UnicodeString
)"FAIL: Expected " + valParse
[v
+ival
]);
426 errln((UnicodeString
)"FAIL: Partial parse (" + pos
.getIndex() + " chars) -> " + a
);
427 errln((UnicodeString
)" should be (" + s
.length() + " chars) -> " + valParse
[v
+ival
]);
430 for (v
=0; v
<lval_length
; ++v
)
433 (*(NumberFormat
*)&fmt
).format(lval
[v
], s
);
434 logln((UnicodeString
)" " + lval
[v
] + "L -format-> " + s
);
435 if (s
!= lvalFormat
[v
+ilval
])
436 errln((UnicodeString
)"ERROR: Expected " + lvalFormat
[v
+ilval
] + " Got: " + s
);
438 ParsePosition
pos(0);
440 fmt
.parse(s
, af
, pos
);
441 if (af
.getType() == Formattable::kLong
||
442 af
.getType() == Formattable::kInt64
) {
443 UErrorCode status
= U_ZERO_ERROR
;
444 int32_t a
= af
.getLong(status
);
445 if (pos
.getIndex() == s
.length())
447 logln((UnicodeString
)" -parse-> " + a
);
448 if (a
!= lvalParse
[v
+ilval
])
449 errln((UnicodeString
)"FAIL: Expected " + lvalParse
[v
+ilval
]);
452 errln((UnicodeString
)"FAIL: Partial parse (" + pos
.getIndex() + " chars) -> " + a
);
455 errln((UnicodeString
)"FAIL: Non-long Formattable returned for " + s
456 + " Double: " + af
.getDouble()
457 + ", Long: " + af
.getLong());
460 ilval
+= lval_length
;
465 NumberFormatTest::TestScientific2() {
467 UErrorCode status
= U_ZERO_ERROR
;
468 DecimalFormat
* fmt
= (DecimalFormat
*)NumberFormat::createCurrencyInstance("en_US", status
);
469 if (U_SUCCESS(status
)) {
471 expect(*fmt
, num
, "$12.34");
472 fmt
->setScientificNotation(TRUE
);
473 expect(*fmt
, num
, "$1.23E1");
474 fmt
->setScientificNotation(FALSE
);
475 expect(*fmt
, num
, "$12.34");
481 NumberFormatTest::TestScientificGrouping() {
483 UErrorCode status
= U_ZERO_ERROR
;
484 DecimalFormat
fmt("##0.00E0",status
);
485 if (U_SUCCESS(status
)) {
486 expect(fmt
, .01234, "12.3E-3");
487 expect(fmt
, .1234, "123E-3");
488 expect(fmt
, 1.234, "1.23E0");
489 expect(fmt
, 12.34, "12.3E0");
490 expect(fmt
, 123.4, "123E0");
491 expect(fmt
, 1234., "1.23E3");
495 /*static void setFromString(DigitList& dl, const char* str) {
497 UBool decimalSet = FALSE;
499 while ((c = *str++)) {
501 dl.fIsPositive = FALSE;
502 } else if (c == '+') {
503 dl.fIsPositive = TRUE;
504 } else if (c == '.') {
505 dl.fDecimalAt = dl.fCount;
512 dl.fDecimalAt = dl.fCount;
517 NumberFormatTest::TestInt64() {
518 UErrorCode status
= U_ZERO_ERROR
;
519 DecimalFormat
fmt("#.#E0",status
);
520 fmt
.setMaximumFractionDigits(20);
521 if (U_SUCCESS(status
)) {
522 expect(fmt
, (Formattable
)(int64_t)0, "0E0");
523 expect(fmt
, (Formattable
)(int64_t)-1, "-1E0");
524 expect(fmt
, (Formattable
)(int64_t)1, "1E0");
525 expect(fmt
, (Formattable
)(int64_t)2147483647, "2.147483647E9");
526 expect(fmt
, (Formattable
)((int64_t)-2147483647-1), "-2.147483648E9");
527 expect(fmt
, (Formattable
)(int64_t)U_INT64_MAX
, "9.223372036854775807E18");
528 expect(fmt
, (Formattable
)(int64_t)U_INT64_MIN
, "-9.223372036854775808E18");
531 // also test digitlist
532 /* int64_t int64max = U_INT64_MAX;
533 int64_t int64min = U_INT64_MIN;
534 const char* int64maxstr = "9223372036854775807";
535 const char* int64minstr = "-9223372036854775808";
536 UnicodeString fail("fail: ");
538 // test max int64 value
540 setFromString(dl, int64maxstr);
542 if (!dl.fitsIntoInt64(FALSE)) {
543 errln(fail + int64maxstr + " didn't fit");
545 int64_t int64Value = dl.getInt64();
546 if (int64Value != int64max) {
547 errln(fail + int64maxstr);
550 int64Value = dl.getInt64();
551 if (int64Value != int64max) {
552 errln(fail + int64maxstr);
555 // test negative of max int64 value (1 shy of min int64 value)
556 dl.fIsPositive = FALSE;
558 if (!dl.fitsIntoInt64(FALSE)) {
559 errln(fail + "-" + int64maxstr + " didn't fit");
561 int64_t int64Value = dl.getInt64();
562 if (int64Value != -int64max) {
563 errln(fail + "-" + int64maxstr);
566 int64Value = dl.getInt64();
567 if (int64Value != -int64max) {
568 errln(fail + "-" + int64maxstr);
571 // test min int64 value
572 setFromString(dl, int64minstr);
574 if (!dl.fitsIntoInt64(FALSE)) {
575 errln(fail + "-" + int64minstr + " didn't fit");
577 int64_t int64Value = dl.getInt64();
578 if (int64Value != int64min) {
579 errln(fail + int64minstr);
582 int64Value = dl.getInt64();
583 if (int64Value != int64min) {
584 errln(fail + int64minstr);
587 // test negative of min int 64 value (1 more than max int64 value)
588 dl.fIsPositive = TRUE; // won't fit
590 if (dl.fitsIntoInt64(FALSE)) {
591 errln(fail + "-(" + int64minstr + ") didn't fit");
596 // -------------------------------------
598 // Test the handling of quotes
600 NumberFormatTest::TestQuotes(void)
602 UErrorCode status
= U_ZERO_ERROR
;
604 DecimalFormatSymbols
*sym
= new DecimalFormatSymbols(Locale::getUS(), status
);
605 if (U_FAILURE(status
)) {
606 errcheckln(status
, "Fail to create DecimalFormatSymbols - %s", u_errorName(status
));
610 pat
= new UnicodeString("a'fo''o'b#");
611 DecimalFormat
*fmt
= new DecimalFormat(*pat
, *sym
, status
);
613 ((NumberFormat
*)fmt
)->format((int32_t)123, s
);
614 logln((UnicodeString
)"Pattern \"" + *pat
+ "\"");
615 logln((UnicodeString
)" Format 123 -> " + escape(s
));
616 if (!(s
=="afo'ob123"))
617 errln((UnicodeString
)"FAIL: Expected afo'ob123");
623 pat
= new UnicodeString("a''b#");
624 fmt
= new DecimalFormat(*pat
, *sym
, status
);
625 ((NumberFormat
*)fmt
)->format((int32_t)123, s
);
626 logln((UnicodeString
)"Pattern \"" + *pat
+ "\"");
627 logln((UnicodeString
)" Format 123 -> " + escape(s
));
629 errln((UnicodeString
)"FAIL: Expected a'b123");
636 * Test the handling of the currency symbol in patterns.
639 NumberFormatTest::TestCurrencySign(void)
641 UErrorCode status
= U_ZERO_ERROR
;
642 DecimalFormatSymbols
* sym
= new DecimalFormatSymbols(Locale::getUS(), status
);
644 UChar currency
= 0x00A4;
645 if (U_FAILURE(status
)) {
646 errcheckln(status
, "Fail to create DecimalFormatSymbols - %s", u_errorName(status
));
650 // "\xA4#,##0.00;-\xA4#,##0.00"
651 pat
.append(currency
).append("#,##0.00;-").
652 append(currency
).append("#,##0.00");
653 DecimalFormat
*fmt
= new DecimalFormat(pat
, *sym
, status
);
654 UnicodeString s
; ((NumberFormat
*)fmt
)->format(1234.56, s
);
656 logln((UnicodeString
)"Pattern \"" + fmt
->toPattern(pat
) + "\"");
657 logln((UnicodeString
)" Format " + 1234.56 + " -> " + escape(s
));
658 if (s
!= "$1,234.56") dataerrln((UnicodeString
)"FAIL: Expected $1,234.56");
660 ((NumberFormat
*)fmt
)->format(- 1234.56, s
);
661 logln((UnicodeString
)" Format " + (-1234.56) + " -> " + escape(s
));
662 if (s
!= "-$1,234.56") dataerrln((UnicodeString
)"FAIL: Expected -$1,234.56");
665 // "\xA4\xA4 #,##0.00;\xA4\xA4 -#,##0.00"
666 pat
.append(currency
).append(currency
).
667 append(" #,##0.00;").
668 append(currency
).append(currency
).
669 append(" -#,##0.00");
670 fmt
= new DecimalFormat(pat
, *sym
, status
);
672 ((NumberFormat
*)fmt
)->format(1234.56, s
);
673 logln((UnicodeString
)"Pattern \"" + fmt
->toPattern(pat
) + "\"");
674 logln((UnicodeString
)" Format " + 1234.56 + " -> " + escape(s
));
675 if (s
!= "USD 1,234.56") dataerrln((UnicodeString
)"FAIL: Expected USD 1,234.56");
677 ((NumberFormat
*)fmt
)->format(-1234.56, s
);
678 logln((UnicodeString
)" Format " + (-1234.56) + " -> " + escape(s
));
679 if (s
!= "USD -1,234.56") dataerrln((UnicodeString
)"FAIL: Expected USD -1,234.56");
682 if (U_FAILURE(status
)) errln((UnicodeString
)"FAIL: Status " + u_errorName(status
));
685 // -------------------------------------
687 static UChar
toHexString(int32_t i
) { return (UChar
)(i
+ (i
< 10 ? 0x30 : (0x41 - 10))); }
690 NumberFormatTest::escape(UnicodeString
& s
)
693 for (int32_t i
=0; i
<s
.length(); ++i
)
695 UChar c
= s
[(int32_t)i
];
696 if (c
<= (UChar
)0x7F) buf
+= c
;
698 buf
+= (UChar
)0x5c; buf
+= (UChar
)0x55;
699 buf
+= toHexString((c
& 0xF000) >> 12);
700 buf
+= toHexString((c
& 0x0F00) >> 8);
701 buf
+= toHexString((c
& 0x00F0) >> 4);
702 buf
+= toHexString(c
& 0x000F);
709 // -------------------------------------
710 static const char* testCases
[][2]= {
711 /* locale ID */ /* expected */
712 {"ca_ES_PREEURO", "\\u20A7\\u00A01.150" },
713 {"de_LU_PREEURO", "1,150\\u00A0F" },
714 {"el_GR_PREEURO", "1.150,50\\u00A0\\u0394\\u03C1\\u03C7" },
715 {"en_BE_PREEURO", "1.150,50\\u00A0BEF" },
716 {"es_ES_PREEURO", "1.150\\u00A0\\u20A7" },
717 {"eu_ES_PREEURO", "\\u20A7\\u00A01.150" },
718 {"gl_ES_PREEURO", "1.150\\u00A0\\u20A7" },
719 {"it_IT_PREEURO", "ITL\\u00A01.150" },
720 {"pt_PT_PREEURO", "1,150$50\\u00A0\\u200B"}, // per cldrbug 7670
721 {"en_US@currency=JPY", "\\u00A51,150"},
722 {"en_US@currency=jpy", "\\u00A51,150"},
723 {"en-US-u-cu-jpy", "\\u00A51,150"}
726 * Test localized currency patterns.
729 NumberFormatTest::TestCurrency(void)
731 UErrorCode status
= U_ZERO_ERROR
;
732 NumberFormat
* currencyFmt
= NumberFormat::createCurrencyInstance(Locale::getCanadaFrench(), status
);
733 if (U_FAILURE(status
)) {
734 dataerrln("Error calling NumberFormat::createCurrencyInstance()");
738 UnicodeString s
; currencyFmt
->format(1.50, s
);
739 logln((UnicodeString
)"Un pauvre ici a..........." + s
);
740 if (!(s
==CharsToUnicodeString("1,50\\u00A0$")))
741 errln((UnicodeString
)"FAIL: Expected 1,50<nbsp>$");
745 int len
= uloc_canonicalize("de_DE_PREEURO", loc
, 256, &status
);
746 (void)len
; // Suppress unused variable warning.
747 currencyFmt
= NumberFormat::createCurrencyInstance(Locale(loc
),status
);
748 currencyFmt
->format(1.50, s
);
749 logln((UnicodeString
)"Un pauvre en Allemagne a.." + s
);
750 if (!(s
==CharsToUnicodeString("1,50\\u00A0DM")))
751 errln((UnicodeString
)"FAIL: Expected 1,50<nbsp>DM");
754 len
= uloc_canonicalize("fr_FR_PREEURO", loc
, 256, &status
);
755 currencyFmt
= NumberFormat::createCurrencyInstance(Locale(loc
), status
);
756 currencyFmt
->format(1.50, s
);
757 logln((UnicodeString
)"Un pauvre en France a....." + s
);
758 if (!(s
==CharsToUnicodeString("1,50\\u00A0F")))
759 errln((UnicodeString
)"FAIL: Expected 1,50<nbsp>F");
761 if (U_FAILURE(status
))
762 errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
764 for(int i
=0; i
< (int)(sizeof(testCases
)/sizeof(testCases
[i
])); i
++){
765 status
= U_ZERO_ERROR
;
766 const char *localeID
= testCases
[i
][0];
767 UnicodeString
expected(testCases
[i
][1], -1, US_INV
);
768 expected
= expected
.unescape();
771 uloc_canonicalize(localeID
, loc
, 256, &status
);
772 currencyFmt
= NumberFormat::createCurrencyInstance(Locale(loc
), status
);
773 if(U_FAILURE(status
)){
774 errln("Could not create currency formatter for locale %s",localeID
);
777 currencyFmt
->format(1150.50, s
);
779 errln(UnicodeString("FAIL: Expected: ")+expected
780 + UnicodeString(" Got: ") + s
781 + UnicodeString( " for locale: ")+ UnicodeString(localeID
) );
783 if (U_FAILURE(status
)){
784 errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
790 // -------------------------------------
793 * Test the Currency object handling, new as of ICU 2.2.
795 void NumberFormatTest::TestCurrencyObject() {
796 UErrorCode ec
= U_ZERO_ERROR
;
798 NumberFormat::createCurrencyInstance(Locale::getUS(), ec
);
801 dataerrln("FAIL: getCurrencyInstance(US) - %s", u_errorName(ec
));
806 Locale
null("", "", "");
808 expectCurrency(*fmt
, null
, 1234.56, "$1,234.56");
810 expectCurrency(*fmt
, Locale::getFrance(),
811 1234.56, CharsToUnicodeString("\\u20AC1,234.56")); // Euro
813 expectCurrency(*fmt
, Locale::getJapan(),
814 1234.56, CharsToUnicodeString("\\u00A51,235")); // Yen
816 expectCurrency(*fmt
, Locale("fr", "CH", ""),
817 1234.56, "CHF1,234.56"); // no more 0.05 rounding here, see cldrbug 5548
819 expectCurrency(*fmt
, Locale::getUS(),
820 1234.56, "$1,234.56");
823 fmt
= NumberFormat::createCurrencyInstance(Locale::getFrance(), ec
);
826 errln("FAIL: getCurrencyInstance(FRANCE)");
831 expectCurrency(*fmt
, null
, 1234.56, CharsToUnicodeString("1 234,56 \\u20AC"));
833 expectCurrency(*fmt
, Locale::getJapan(),
834 1234.56, CharsToUnicodeString("1 235 JPY")); // Yen
836 expectCurrency(*fmt
, Locale("fr", "CH", ""),
837 1234.56, "1 234,56 CHF"); // no more 0.05 rounding here, see cldrbug 5548
839 expectCurrency(*fmt
, Locale::getUS(),
840 1234.56, "1 234,56 $US");
842 expectCurrency(*fmt
, Locale::getFrance(),
843 1234.56, CharsToUnicodeString("1 234,56 \\u20AC")); // Euro
848 // -------------------------------------
851 * Do rudimentary testing of parsing.
854 NumberFormatTest::TestParse(void)
856 UErrorCode status
= U_ZERO_ERROR
;
857 UnicodeString
arg("0");
858 DecimalFormat
* format
= new DecimalFormat("00", status
);
860 Formattable n
; format
->parse(arg
, n
, status
);
861 logln((UnicodeString
)"parse(" + arg
+ ") = " + n
.getLong());
862 if (n
.getType() != Formattable::kLong
||
863 n
.getLong() != 0) errln((UnicodeString
)"FAIL: Expected 0");
865 if (U_FAILURE(status
)) errcheckln(status
, (UnicodeString
)"FAIL: Status " + u_errorName(status
));
867 //catch(Exception e) {
868 // errln((UnicodeString)"Exception caught: " + e);
872 // -------------------------------------
874 static const char *lenientAffixTestCases
[] = {
881 static const char *lenientMinusTestCases
[] = {
887 static const char *lenientCurrencyTestCases
[] = {
898 // changed from () to - per cldrbug 5674
899 static const char *lenientNegativeCurrencyTestCases
[] = {
911 static const char *lenientPercentTestCases
[] = {
920 static const char *lenientNegativePercentTestCases
[] = {
932 static const char *strictFailureTestCases
[] = {
938 #define ARRAY_SIZE(array) ((int32_t) (sizeof (array) / sizeof(array[0])))
941 * Test lenient parsing.
944 NumberFormatTest::TestLenientParse(void)
946 UErrorCode status
= U_ZERO_ERROR
;
947 DecimalFormat
*format
= new DecimalFormat("(#,##0)", status
);
950 if (format
== NULL
|| U_FAILURE(status
)) {
951 dataerrln("Unable to create DecimalFormat (#,##0) - %s", u_errorName(status
));
953 format
->setLenient(TRUE
);
954 for (int32_t t
= 0; t
< ARRAY_SIZE (lenientAffixTestCases
); t
+= 1) {
955 UnicodeString testCase
= ctou(lenientAffixTestCases
[t
]);
957 format
->parse(testCase
, n
, status
);
958 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
960 if (U_FAILURE(status
) || n
.getType() != Formattable::kLong
||
962 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientAffixTestCases
[t
] + (UnicodeString
) "\"");
963 status
= U_ZERO_ERROR
;
969 Locale
en_US("en_US");
970 Locale
sv_SE("sv_SE");
972 NumberFormat
*mFormat
= NumberFormat::createInstance(sv_SE
, UNUM_DECIMAL
, status
);
974 if (mFormat
== NULL
|| U_FAILURE(status
)) {
975 dataerrln("Unable to create NumberFormat (sv_SE, UNUM_DECIMAL) - %s", u_errorName(status
));
977 mFormat
->setLenient(TRUE
);
978 for (int32_t t
= 0; t
< ARRAY_SIZE(lenientMinusTestCases
); t
+= 1) {
979 UnicodeString testCase
= ctou(lenientMinusTestCases
[t
]);
981 mFormat
->parse(testCase
, n
, status
);
982 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
984 if (U_FAILURE(status
) || n
.getType() != Formattable::kLong
|| n
.getLong() != -5) {
985 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientMinusTestCases
[t
] + (UnicodeString
) "\"");
986 status
= U_ZERO_ERROR
;
992 mFormat
= NumberFormat::createInstance(en_US
, UNUM_DECIMAL
, status
);
994 if (mFormat
== NULL
|| U_FAILURE(status
)) {
995 dataerrln("Unable to create NumberFormat (en_US, UNUM_DECIMAL) - %s", u_errorName(status
));
997 mFormat
->setLenient(TRUE
);
998 for (int32_t t
= 0; t
< ARRAY_SIZE(lenientMinusTestCases
); t
+= 1) {
999 UnicodeString testCase
= ctou(lenientMinusTestCases
[t
]);
1001 mFormat
->parse(testCase
, n
, status
);
1002 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1004 if (U_FAILURE(status
) || n
.getType() != Formattable::kLong
|| n
.getLong() != -5) {
1005 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientMinusTestCases
[t
] + (UnicodeString
) "\"");
1006 status
= U_ZERO_ERROR
;
1012 NumberFormat
*cFormat
= NumberFormat::createInstance(en_US
, UNUM_CURRENCY
, status
);
1014 if (cFormat
== NULL
|| U_FAILURE(status
)) {
1015 dataerrln("Unable to create NumberFormat (en_US, UNUM_CURRENCY) - %s", u_errorName(status
));
1017 cFormat
->setLenient(TRUE
);
1018 for (int32_t t
= 0; t
< ARRAY_SIZE (lenientCurrencyTestCases
); t
+= 1) {
1019 UnicodeString testCase
= ctou(lenientCurrencyTestCases
[t
]);
1021 cFormat
->parse(testCase
, n
, status
);
1022 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1024 if (U_FAILURE(status
) ||n
.getType() != Formattable::kLong
||
1025 n
.getLong() != 1000) {
1026 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientCurrencyTestCases
[t
] + (UnicodeString
) "\"");
1027 status
= U_ZERO_ERROR
;
1031 for (int32_t t
= 0; t
< ARRAY_SIZE (lenientNegativeCurrencyTestCases
); t
+= 1) {
1032 UnicodeString testCase
= ctou(lenientNegativeCurrencyTestCases
[t
]);
1034 cFormat
->parse(testCase
, n
, status
);
1035 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1037 if (U_FAILURE(status
) ||n
.getType() != Formattable::kLong
||
1038 n
.getLong() != -1000) {
1039 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientNegativeCurrencyTestCases
[t
] + (UnicodeString
) "\"");
1040 status
= U_ZERO_ERROR
;
1047 NumberFormat
*pFormat
= NumberFormat::createPercentInstance(en_US
, status
);
1049 if (pFormat
== NULL
|| U_FAILURE(status
)) {
1050 dataerrln("Unable to create NumberFormat::createPercentInstance (en_US) - %s", u_errorName(status
));
1052 pFormat
->setLenient(TRUE
);
1053 for (int32_t t
= 0; t
< ARRAY_SIZE (lenientPercentTestCases
); t
+= 1) {
1054 UnicodeString testCase
= ctou(lenientPercentTestCases
[t
]);
1056 pFormat
->parse(testCase
, n
, status
);
1057 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getDouble());
1059 if (U_FAILURE(status
) ||n
.getType() != Formattable::kDouble
||
1060 n
.getDouble() != 0.25) {
1061 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientPercentTestCases
[t
] + (UnicodeString
) "\"");
1062 status
= U_ZERO_ERROR
;
1066 for (int32_t t
= 0; t
< ARRAY_SIZE (lenientNegativePercentTestCases
); t
+= 1) {
1067 UnicodeString testCase
= ctou(lenientNegativePercentTestCases
[t
]);
1069 pFormat
->parse(testCase
, n
, status
);
1070 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getDouble());
1072 if (U_FAILURE(status
) ||n
.getType() != Formattable::kDouble
||
1073 n
.getDouble() != -0.25) {
1074 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientNegativePercentTestCases
[t
] + (UnicodeString
) "\"");
1075 status
= U_ZERO_ERROR
;
1082 // Test cases that should fail with a strict parse and pass with a
1084 NumberFormat
*nFormat
= NumberFormat::createInstance(en_US
, status
);
1086 if (nFormat
== NULL
|| U_FAILURE(status
)) {
1087 dataerrln("Unable to create NumberFormat (en_US) - %s", u_errorName(status
));
1089 // first, make sure that they fail with a strict parse
1090 for (int32_t t
= 0; t
< ARRAY_SIZE(strictFailureTestCases
); t
+= 1) {
1091 UnicodeString testCase
= ctou(strictFailureTestCases
[t
]);
1093 nFormat
->parse(testCase
, n
, status
);
1094 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1096 if (! U_FAILURE(status
)) {
1097 errln((UnicodeString
)"Strict Parse succeeded for \"" + (UnicodeString
) strictFailureTestCases
[t
] + (UnicodeString
) "\"");
1100 status
= U_ZERO_ERROR
;
1103 // then, make sure that they pass with a lenient parse
1104 nFormat
->setLenient(TRUE
);
1105 for (int32_t t
= 0; t
< ARRAY_SIZE(strictFailureTestCases
); t
+= 1) {
1106 UnicodeString testCase
= ctou(strictFailureTestCases
[t
]);
1108 nFormat
->parse(testCase
, n
, status
);
1109 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1111 if (U_FAILURE(status
) ||n
.getType() != Formattable::kLong
||
1112 n
.getLong() != 1000) {
1113 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) strictFailureTestCases
[t
] + (UnicodeString
) "\"");
1114 status
= U_ZERO_ERROR
;
1122 // -------------------------------------
1125 * Test proper rounding by the format method.
1128 NumberFormatTest::TestRounding487(void)
1130 UErrorCode status
= U_ZERO_ERROR
;
1131 NumberFormat
*nf
= NumberFormat::createInstance(status
);
1132 if (U_FAILURE(status
)) {
1133 dataerrln("Error calling NumberFormat::createInstance()");
1137 roundingTest(*nf
, 0.00159999, 4, "0.0016");
1138 roundingTest(*nf
, 0.00995, 4, "0.01");
1140 roundingTest(*nf
, 12.3995, 3, "12.4");
1142 roundingTest(*nf
, 12.4999, 0, "12");
1143 roundingTest(*nf
, - 19.5, 0, "-20");
1145 if (U_FAILURE(status
)) errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
1149 * Test the functioning of the secondary grouping value.
1151 void NumberFormatTest::TestSecondaryGrouping(void) {
1152 UErrorCode status
= U_ZERO_ERROR
;
1153 DecimalFormatSymbols
US(Locale::getUS(), status
);
1154 CHECK(status
, "DecimalFormatSymbols ct");
1156 DecimalFormat
f("#,##,###", US
, status
);
1157 CHECK(status
, "DecimalFormat ct");
1159 expect2(f
, (int32_t)123456789L, "12,34,56,789");
1160 expectPat(f
, "#,##,###");
1161 f
.applyPattern("#,###", status
);
1162 CHECK(status
, "applyPattern");
1164 f
.setSecondaryGroupingSize(4);
1165 expect2(f
, (int32_t)123456789L, "12,3456,789");
1166 expectPat(f
, "#,####,###");
1167 NumberFormat
*g
= NumberFormat::createInstance(Locale("hi", "IN"), status
);
1168 CHECK_DATA(status
, "createInstance(hi_IN)");
1171 int32_t l
= (int32_t)1876543210L;
1174 // expect "1,87,65,43,210", but with Hindi digits
1177 if (out
.length() != 14) {
1180 for (int32_t i
=0; i
<out
.length(); ++i
) {
1181 UBool expectGroup
= FALSE
;
1190 // Later -- fix this to get the actual grouping
1191 // character from the resource bundle.
1192 UBool isGroup
= (out
.charAt(i
) == 0x002C);
1193 if (isGroup
!= expectGroup
) {
1200 errln((UnicodeString
)"FAIL Expected " + l
+
1201 " x hi_IN -> \"1,87,65,43,210\" (with Hindi digits), got \"" +
1202 escape(out
) + "\"");
1204 logln((UnicodeString
)"Ok " + l
+
1206 escape(out
) + "\"");
1210 void NumberFormatTest::TestWhiteSpaceParsing(void) {
1211 UErrorCode ec
= U_ZERO_ERROR
;
1212 DecimalFormatSymbols
US(Locale::getUS(), ec
);
1213 DecimalFormat
fmt("a b#0c ", US
, ec
);
1214 if (U_FAILURE(ec
)) {
1215 errcheckln(ec
, "FAIL: Constructor - %s", u_errorName(ec
));
1219 expect(fmt
, "a b1234c ", n
);
1220 expect(fmt
, "a b1234c ", n
);
1224 * Test currencies whose display name is a ChoiceFormat.
1226 void NumberFormatTest::TestComplexCurrency() {
1228 // UErrorCode ec = U_ZERO_ERROR;
1229 // Locale loc("kn", "IN", "");
1230 // NumberFormat* fmt = NumberFormat::createCurrencyInstance(loc, ec);
1231 // if (U_SUCCESS(ec)) {
1232 // expect2(*fmt, 1.0, CharsToUnicodeString("Re.\\u00A01.00"));
1233 // Use .00392625 because that's 2^-8. Any value less than 0.005 is fine.
1234 // expect(*fmt, 1.00390625, CharsToUnicodeString("Re.\\u00A01.00")); // tricky
1235 // expect2(*fmt, 12345678.0, CharsToUnicodeString("Rs.\\u00A01,23,45,678.00"));
1236 // expect2(*fmt, 0.5, CharsToUnicodeString("Rs.\\u00A00.50"));
1237 // expect2(*fmt, -1.0, CharsToUnicodeString("-Re.\\u00A01.00"));
1238 // expect2(*fmt, -10.0, CharsToUnicodeString("-Rs.\\u00A010.00"));
1240 // errln("FAIL: getCurrencyInstance(kn_IN)");
1246 // -------------------------------------
1249 NumberFormatTest::roundingTest(NumberFormat
& nf
, double x
, int32_t maxFractionDigits
, const char* expected
)
1251 nf
.setMaximumFractionDigits(maxFractionDigits
);
1252 UnicodeString out
; nf
.format(x
, out
);
1253 logln((UnicodeString
)"" + x
+ " formats with " + maxFractionDigits
+ " fractional digits to " + out
);
1254 if (!(out
==expected
)) errln((UnicodeString
)"FAIL: Expected " + expected
);
1258 * Upgrade to alphaWorks
1260 void NumberFormatTest::TestExponent(void) {
1261 UErrorCode status
= U_ZERO_ERROR
;
1262 DecimalFormatSymbols
US(Locale::getUS(), status
);
1263 CHECK(status
, "DecimalFormatSymbols constructor");
1264 DecimalFormat
fmt1(UnicodeString("0.###E0"), US
, status
);
1265 CHECK(status
, "DecimalFormat(0.###E0)");
1266 DecimalFormat
fmt2(UnicodeString("0.###E+0"), US
, status
);
1267 CHECK(status
, "DecimalFormat(0.###E+0)");
1269 expect2(fmt1
, n
, "1.234E3");
1270 expect2(fmt2
, n
, "1.234E+3");
1271 expect(fmt1
, "1.234E+3", n
); // Either format should parse "E+3"
1275 * Upgrade to alphaWorks
1277 void NumberFormatTest::TestScientific(void) {
1278 UErrorCode status
= U_ZERO_ERROR
;
1279 DecimalFormatSymbols
US(Locale::getUS(), status
);
1280 CHECK(status
, "DecimalFormatSymbols constructor");
1282 // Test pattern round-trip
1283 const char* PAT
[] = { "#E0", "0.####E0", "00.000E00", "##0.####E000",
1284 "0.###E0;[0.###E0]" };
1285 int32_t PAT_length
= (int32_t)(sizeof(PAT
) / sizeof(PAT
[0]));
1286 int32_t DIGITS
[] = {
1287 // min int, max int, min frac, max frac
1288 0, 1, 0, 0, // "#E0"
1289 1, 1, 0, 4, // "0.####E0"
1290 2, 2, 3, 3, // "00.000E00"
1291 1, 3, 0, 4, // "##0.####E000"
1292 1, 1, 0, 3, // "0.###E0;[0.###E0]"
1294 for (int32_t i
=0; i
<PAT_length
; ++i
) {
1295 UnicodeString
pat(PAT
[i
]);
1296 DecimalFormat
df(pat
, US
, status
);
1297 CHECK(status
, "DecimalFormat constructor");
1301 logln(UnicodeString("Ok Pattern rt \"") +
1305 errln(UnicodeString("FAIL Pattern rt \"") +
1309 // Make sure digit counts match what we expect
1310 if (df
.getMinimumIntegerDigits() != DIGITS
[4*i
] ||
1311 df
.getMaximumIntegerDigits() != DIGITS
[4*i
+1] ||
1312 df
.getMinimumFractionDigits() != DIGITS
[4*i
+2] ||
1313 df
.getMaximumFractionDigits() != DIGITS
[4*i
+3]) {
1314 errln(UnicodeString("FAIL \"" + pat
+
1315 "\" min/max int; min/max frac = ") +
1316 df
.getMinimumIntegerDigits() + "/" +
1317 df
.getMaximumIntegerDigits() + ";" +
1318 df
.getMinimumFractionDigits() + "/" +
1319 df
.getMaximumFractionDigits() + ", expect " +
1321 DIGITS
[4*i
+1] + ";" +
1322 DIGITS
[4*i
+2] + "/" +
1328 // Test the constructor for default locale. We have to
1329 // manually set the default locale, as there is no
1330 // guarantee that the default locale has the same
1331 // scientific format.
1332 Locale def
= Locale::getDefault();
1333 Locale::setDefault(Locale::getUS(), status
);
1334 expect2(NumberFormat::createScientificInstance(status
),
1336 "1.2345678901E4", status
);
1337 Locale::setDefault(def
, status
);
1339 expect2(new DecimalFormat("#E0", US
, status
),
1341 "1.2345E4", status
);
1342 expect(new DecimalFormat("0E0", US
, status
),
1345 expect2(NumberFormat::createScientificInstance(Locale::getUS(), status
),
1347 "1.2345678901E4", status
);
1348 expect(new DecimalFormat("##0.###E0", US
, status
),
1351 expect(new DecimalFormat("##0.###E0", US
, status
),
1354 expect2(new DecimalFormat("##0.####E0", US
, status
),
1356 "12.345E3", status
);
1357 expect2(NumberFormat::createScientificInstance(Locale::getFrance(), status
),
1359 "1,2345678901E4", status
);
1360 expect(new DecimalFormat("##0.####E0", US
, status
),
1362 "789.12E-9", status
);
1363 expect2(new DecimalFormat("##0.####E0", US
, status
),
1366 expect(new DecimalFormat(".###E0", US
, status
),
1369 expect2(new DecimalFormat(".###E0", US
, status
),
1373 expect(new DecimalFormat[] { new DecimalFormat("#E0", US),
1374 new DecimalFormat("##E0", US),
1375 new DecimalFormat("####E0", US),
1376 new DecimalFormat("0E0", US),
1377 new DecimalFormat("00E0", US),
1378 new DecimalFormat("000E0", US),
1381 new String[] { "4.5678E7",
1390 ! Unroll this test into individual tests below...
1393 expect2(new DecimalFormat("#E0", US
, status
),
1394 (int32_t) 45678000, "4.5678E7", status
);
1395 expect2(new DecimalFormat("##E0", US
, status
),
1396 (int32_t) 45678000, "45.678E6", status
);
1397 expect2(new DecimalFormat("####E0", US
, status
),
1398 (int32_t) 45678000, "4567.8E4", status
);
1399 expect(new DecimalFormat("0E0", US
, status
),
1400 (int32_t) 45678000, "5E7", status
);
1401 expect(new DecimalFormat("00E0", US
, status
),
1402 (int32_t) 45678000, "46E6", status
);
1403 expect(new DecimalFormat("000E0", US
, status
),
1404 (int32_t) 45678000, "457E5", status
);
1406 expect(new DecimalFormat("###E0", US, status),
1407 new Object[] { new Double(0.0000123), "12.3E-6",
1408 new Double(0.000123), "123E-6",
1409 new Double(0.00123), "1.23E-3",
1410 new Double(0.0123), "12.3E-3",
1411 new Double(0.123), "123E-3",
1412 new Double(1.23), "1.23E0",
1413 new Double(12.3), "12.3E0",
1414 new Double(123), "123E0",
1415 new Double(1230), "1.23E3",
1418 ! Unroll this test into individual tests below...
1421 expect2(new DecimalFormat("###E0", US
, status
),
1422 0.0000123, "12.3E-6", status
);
1423 expect2(new DecimalFormat("###E0", US
, status
),
1424 0.000123, "123E-6", status
);
1425 expect2(new DecimalFormat("###E0", US
, status
),
1426 0.00123, "1.23E-3", status
);
1427 expect2(new DecimalFormat("###E0", US
, status
),
1428 0.0123, "12.3E-3", status
);
1429 expect2(new DecimalFormat("###E0", US
, status
),
1430 0.123, "123E-3", status
);
1431 expect2(new DecimalFormat("###E0", US
, status
),
1432 1.23, "1.23E0", status
);
1433 expect2(new DecimalFormat("###E0", US
, status
),
1434 12.3, "12.3E0", status
);
1435 expect2(new DecimalFormat("###E0", US
, status
),
1436 123.0, "123E0", status
);
1437 expect2(new DecimalFormat("###E0", US
, status
),
1438 1230.0, "1.23E3", status
);
1440 expect(new DecimalFormat("0.#E+00", US, status),
1441 new Object[] { new Double(0.00012), "1.2E-04",
1442 new Long(12000), "1.2E+04",
1445 ! Unroll this test into individual tests below...
1448 expect2(new DecimalFormat("0.#E+00", US
, status
),
1449 0.00012, "1.2E-04", status
);
1450 expect2(new DecimalFormat("0.#E+00", US
, status
),
1451 (int32_t) 12000, "1.2E+04", status
);
1455 * Upgrade to alphaWorks
1457 void NumberFormatTest::TestPad(void) {
1458 UErrorCode status
= U_ZERO_ERROR
;
1459 DecimalFormatSymbols
US(Locale::getUS(), status
);
1460 CHECK(status
, "DecimalFormatSymbols constructor");
1462 expect2(new DecimalFormat("*^##.##", US
, status
),
1463 int32_t(0), "^^^^0", status
);
1464 expect2(new DecimalFormat("*^##.##", US
, status
),
1465 -1.3, "^-1.3", status
);
1466 expect2(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US
, status
),
1467 int32_t(0), "0.0E0______ g-m/s^2", status
);
1468 expect(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US
, status
),
1469 1.0/3, "333.333E-3_ g-m/s^2", status
);
1470 expect2(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US
, status
),
1471 int32_t(0), "0.0______ g-m/s^2", status
);
1472 expect(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US
, status
),
1473 1.0/3, "0.33333__ g-m/s^2", status
);
1475 // Test padding before a sign
1476 const char *formatStr
= "*x#,###,###,##0.0#;*x(###,###,##0.0#)";
1477 expect2(new DecimalFormat(formatStr
, US
, status
),
1478 int32_t(-10), "xxxxxxxxxx(10.0)", status
);
1479 expect2(new DecimalFormat(formatStr
, US
, status
),
1480 int32_t(-1000),"xxxxxxx(1,000.0)", status
);
1481 expect2(new DecimalFormat(formatStr
, US
, status
),
1482 int32_t(-1000000),"xxx(1,000,000.0)", status
);
1483 expect2(new DecimalFormat(formatStr
, US
, status
),
1484 -100.37, "xxxxxxxx(100.37)", status
);
1485 expect2(new DecimalFormat(formatStr
, US
, status
),
1486 -10456.37, "xxxxx(10,456.37)", status
);
1487 expect2(new DecimalFormat(formatStr
, US
, status
),
1488 -1120456.37, "xx(1,120,456.37)", status
);
1489 expect2(new DecimalFormat(formatStr
, US
, status
),
1490 -112045600.37, "(112,045,600.37)", status
);
1491 expect2(new DecimalFormat(formatStr
, US
, status
),
1492 -1252045600.37,"(1,252,045,600.37)", status
);
1494 expect2(new DecimalFormat(formatStr
, US
, status
),
1495 int32_t(10), "xxxxxxxxxxxx10.0", status
);
1496 expect2(new DecimalFormat(formatStr
, US
, status
),
1497 int32_t(1000),"xxxxxxxxx1,000.0", status
);
1498 expect2(new DecimalFormat(formatStr
, US
, status
),
1499 int32_t(1000000),"xxxxx1,000,000.0", status
);
1500 expect2(new DecimalFormat(formatStr
, US
, status
),
1501 100.37, "xxxxxxxxxx100.37", status
);
1502 expect2(new DecimalFormat(formatStr
, US
, status
),
1503 10456.37, "xxxxxxx10,456.37", status
);
1504 expect2(new DecimalFormat(formatStr
, US
, status
),
1505 1120456.37, "xxxx1,120,456.37", status
);
1506 expect2(new DecimalFormat(formatStr
, US
, status
),
1507 112045600.37, "xx112,045,600.37", status
);
1508 expect2(new DecimalFormat(formatStr
, US
, status
),
1509 10252045600.37,"10,252,045,600.37", status
);
1512 // Test padding between a sign and a number
1513 const char *formatStr2
= "#,###,###,##0.0#*x;(###,###,##0.0#*x)";
1514 expect2(new DecimalFormat(formatStr2
, US
, status
),
1515 int32_t(-10), "(10.0xxxxxxxxxx)", status
);
1516 expect2(new DecimalFormat(formatStr2
, US
, status
),
1517 int32_t(-1000),"(1,000.0xxxxxxx)", status
);
1518 expect2(new DecimalFormat(formatStr2
, US
, status
),
1519 int32_t(-1000000),"(1,000,000.0xxx)", status
);
1520 expect2(new DecimalFormat(formatStr2
, US
, status
),
1521 -100.37, "(100.37xxxxxxxx)", status
);
1522 expect2(new DecimalFormat(formatStr2
, US
, status
),
1523 -10456.37, "(10,456.37xxxxx)", status
);
1524 expect2(new DecimalFormat(formatStr2
, US
, status
),
1525 -1120456.37, "(1,120,456.37xx)", status
);
1526 expect2(new DecimalFormat(formatStr2
, US
, status
),
1527 -112045600.37, "(112,045,600.37)", status
);
1528 expect2(new DecimalFormat(formatStr2
, US
, status
),
1529 -1252045600.37,"(1,252,045,600.37)", status
);
1531 expect2(new DecimalFormat(formatStr2
, US
, status
),
1532 int32_t(10), "10.0xxxxxxxxxxxx", status
);
1533 expect2(new DecimalFormat(formatStr2
, US
, status
),
1534 int32_t(1000),"1,000.0xxxxxxxxx", status
);
1535 expect2(new DecimalFormat(formatStr2
, US
, status
),
1536 int32_t(1000000),"1,000,000.0xxxxx", status
);
1537 expect2(new DecimalFormat(formatStr2
, US
, status
),
1538 100.37, "100.37xxxxxxxxxx", status
);
1539 expect2(new DecimalFormat(formatStr2
, US
, status
),
1540 10456.37, "10,456.37xxxxxxx", status
);
1541 expect2(new DecimalFormat(formatStr2
, US
, status
),
1542 1120456.37, "1,120,456.37xxxx", status
);
1543 expect2(new DecimalFormat(formatStr2
, US
, status
),
1544 112045600.37, "112,045,600.37xx", status
);
1545 expect2(new DecimalFormat(formatStr2
, US
, status
),
1546 10252045600.37,"10,252,045,600.37", status
);
1548 //testing the setPadCharacter(UnicodeString) and getPadCharacterString()
1549 DecimalFormat
fmt("#", US
, status
);
1550 CHECK(status
, "DecimalFormat constructor");
1551 UnicodeString
padString("P");
1552 fmt
.setPadCharacter(padString
);
1553 expectPad(fmt
, "*P##.##", DecimalFormat::kPadBeforePrefix
, 5, padString
);
1554 fmt
.setPadCharacter((UnicodeString
)"^");
1555 expectPad(fmt
, "*^#", DecimalFormat::kPadBeforePrefix
, 1, (UnicodeString
)"^");
1556 //commented untill implementation is complete
1557 /* fmt.setPadCharacter((UnicodeString)"^^^");
1558 expectPad(fmt, "*^^^#", DecimalFormat::kPadBeforePrefix, 3, (UnicodeString)"^^^");
1560 padString.append((UChar)0x0061);
1561 padString.append((UChar)0x0302);
1562 fmt.setPadCharacter(padString);
1563 UChar patternChars[]={0x002a, 0x0061, 0x0302, 0x0061, 0x0302, 0x0023, 0x0000};
1564 UnicodeString pattern(patternChars);
1565 expectPad(fmt, pattern , DecimalFormat::kPadBeforePrefix, 4, padString);
1571 * Upgrade to alphaWorks
1573 void NumberFormatTest::TestPatterns2(void) {
1574 UErrorCode status
= U_ZERO_ERROR
;
1575 DecimalFormatSymbols
US(Locale::getUS(), status
);
1576 CHECK(status
, "DecimalFormatSymbols constructor");
1578 DecimalFormat
fmt("#", US
, status
);
1579 CHECK(status
, "DecimalFormat constructor");
1581 UChar hat
= 0x005E; /*^*/
1583 expectPad(fmt
, "*^#", DecimalFormat::kPadBeforePrefix
, 1, hat
);
1584 expectPad(fmt
, "$*^#", DecimalFormat::kPadAfterPrefix
, 2, hat
);
1585 expectPad(fmt
, "#*^", DecimalFormat::kPadBeforeSuffix
, 1, hat
);
1586 expectPad(fmt
, "#$*^", DecimalFormat::kPadAfterSuffix
, 2, hat
);
1587 expectPad(fmt
, "$*^$#", ILLEGAL
);
1588 expectPad(fmt
, "#$*^$", ILLEGAL
);
1589 expectPad(fmt
, "'pre'#,##0*x'post'", DecimalFormat::kPadBeforeSuffix
,
1590 12, (UChar
)0x0078 /*x*/);
1591 expectPad(fmt
, "''#0*x", DecimalFormat::kPadBeforeSuffix
,
1592 3, (UChar
)0x0078 /*x*/);
1593 expectPad(fmt
, "'I''ll'*a###.##", DecimalFormat::kPadAfterPrefix
,
1594 10, (UChar
)0x0061 /*a*/);
1596 fmt
.applyPattern("AA#,##0.00ZZ", status
);
1597 CHECK(status
, "applyPattern");
1598 fmt
.setPadCharacter(hat
);
1600 fmt
.setFormatWidth(10);
1602 fmt
.setPadPosition(DecimalFormat::kPadBeforePrefix
);
1603 expectPat(fmt
, "*^AA#,##0.00ZZ");
1605 fmt
.setPadPosition(DecimalFormat::kPadBeforeSuffix
);
1606 expectPat(fmt
, "AA#,##0.00*^ZZ");
1608 fmt
.setPadPosition(DecimalFormat::kPadAfterSuffix
);
1609 expectPat(fmt
, "AA#,##0.00ZZ*^");
1612 UnicodeString
exp("AA*^#,##0.00ZZ", "");
1613 fmt
.setFormatWidth(12);
1614 fmt
.setPadPosition(DecimalFormat::kPadAfterPrefix
);
1615 expectPat(fmt
, exp
);
1617 fmt
.setFormatWidth(13);
1619 expectPat(fmt
, "AA*^##,##0.00ZZ");
1621 fmt
.setFormatWidth(14);
1623 expectPat(fmt
, "AA*^###,##0.00ZZ");
1625 fmt
.setFormatWidth(15);
1627 expectPat(fmt
, "AA*^####,##0.00ZZ"); // This is the interesting case
1629 fmt
.setFormatWidth(16);
1630 // 12 34567890123456
1631 expectPat(fmt
, "AA*^#,###,##0.00ZZ");
1634 void NumberFormatTest::TestSurrogateSupport(void) {
1635 UErrorCode status
= U_ZERO_ERROR
;
1636 DecimalFormatSymbols
custom(Locale::getUS(), status
);
1637 CHECK(status
, "DecimalFormatSymbols constructor");
1639 custom
.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol
, "decimal");
1640 custom
.setSymbol(DecimalFormatSymbols::kPlusSignSymbol
, "plus");
1641 custom
.setSymbol(DecimalFormatSymbols::kMinusSignSymbol
, " minus ");
1642 custom
.setSymbol(DecimalFormatSymbols::kExponentialSymbol
, "exponent");
1644 UnicodeString
patternStr("*\\U00010000##.##", "");
1645 patternStr
= patternStr
.unescape();
1646 UnicodeString
expStr("\\U00010000\\U00010000\\U00010000\\U000100000", "");
1647 expStr
= expStr
.unescape();
1648 expect2(new DecimalFormat(patternStr
, custom
, status
),
1649 int32_t(0), expStr
, status
);
1651 status
= U_ZERO_ERROR
;
1652 expect2(new DecimalFormat("*^##.##", custom
, status
),
1653 int32_t(0), "^^^^0", status
);
1654 status
= U_ZERO_ERROR
;
1655 expect2(new DecimalFormat("##.##", custom
, status
),
1656 -1.3, " minus 1decimal3", status
);
1657 status
= U_ZERO_ERROR
;
1658 expect2(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom
, status
),
1659 int32_t(0), "0decimal0exponent0 g-m/s^2", status
);
1660 status
= U_ZERO_ERROR
;
1661 expect(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom
, status
),
1662 1.0/3, "333decimal333exponent minus 3 g-m/s^2", status
);
1663 status
= U_ZERO_ERROR
;
1664 expect2(new DecimalFormat("##0.0#### 'g-m/s^2'", custom
, status
),
1665 int32_t(0), "0decimal0 g-m/s^2", status
);
1666 status
= U_ZERO_ERROR
;
1667 expect(new DecimalFormat("##0.0#### 'g-m/s^2'", custom
, status
),
1668 1.0/3, "0decimal33333 g-m/s^2", status
);
1670 UnicodeString
zero((UChar32
)0x10000);
1671 UnicodeString
one((UChar32
)0x10001);
1672 UnicodeString
two((UChar32
)0x10002);
1673 UnicodeString
five((UChar32
)0x10005);
1674 custom
.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol
, zero
);
1675 custom
.setSymbol(DecimalFormatSymbols::kOneDigitSymbol
, one
);
1676 custom
.setSymbol(DecimalFormatSymbols::kTwoDigitSymbol
, two
);
1677 custom
.setSymbol(DecimalFormatSymbols::kFiveDigitSymbol
, five
);
1678 expStr
= UnicodeString("\\U00010001decimal\\U00010002\\U00010005\\U00010000", "");
1679 expStr
= expStr
.unescape();
1680 status
= U_ZERO_ERROR
;
1681 expect2(new DecimalFormat("##0.000", custom
, status
),
1682 1.25, expStr
, status
);
1684 custom
.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol
, (UChar
)0x30);
1685 custom
.setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "units of money");
1686 custom
.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol
, "money separator");
1687 patternStr
= UNICODE_STRING_SIMPLE("0.00 \\u00A4' in your bank account'");
1688 patternStr
= patternStr
.unescape();
1689 expStr
= UnicodeString(" minus 20money separator00 units of money in your bank account", "");
1690 status
= U_ZERO_ERROR
;
1691 expect2(new DecimalFormat(patternStr
, custom
, status
),
1692 int32_t(-20), expStr
, status
);
1694 custom
.setSymbol(DecimalFormatSymbols::kPercentSymbol
, "percent");
1695 patternStr
= "'You''ve lost ' -0.00 %' of your money today'";
1696 patternStr
= patternStr
.unescape();
1697 expStr
= UnicodeString(" minus You've lost minus 2000decimal00 percent of your money today", "");
1698 status
= U_ZERO_ERROR
;
1699 expect2(new DecimalFormat(patternStr
, custom
, status
),
1700 int32_t(-20), expStr
, status
);
1703 void NumberFormatTest::TestCurrencyPatterns(void) {
1704 int32_t i
, locCount
;
1705 const Locale
* locs
= NumberFormat::getAvailableLocales(locCount
);
1706 for (i
=0; i
<locCount
; ++i
) {
1707 UErrorCode ec
= U_ZERO_ERROR
;
1708 NumberFormat
* nf
= NumberFormat::createCurrencyInstance(locs
[i
], ec
);
1709 if (U_FAILURE(ec
)) {
1710 errln("FAIL: Can't create NumberFormat(%s) - %s", locs
[i
].getName(), u_errorName(ec
));
1712 // Make sure currency formats do not have a variable number
1713 // of fraction digits
1714 int32_t min
= nf
->getMinimumFractionDigits();
1715 int32_t max
= nf
->getMaximumFractionDigits();
1719 nf
->format(1.125, b
);
1720 errln((UnicodeString
)"FAIL: " + locs
[i
].getName() +
1721 " min fraction digits != max fraction digits; "
1722 "x 1.0 => " + escape(a
) +
1723 "; x 1.125 => " + escape(b
));
1726 // Make sure EURO currency formats have exactly 2 fraction digits
1727 DecimalFormat
* df
= dynamic_cast<DecimalFormat
*>(nf
);
1729 if (u_strcmp(EUR
, df
->getCurrency()) == 0) {
1730 if (min
!= 2 || max
!= 2) {
1733 errln((UnicodeString
)"FAIL: " + locs
[i
].getName() +
1734 " is a EURO format but it does not have 2 fraction digits; "
1745 void NumberFormatTest::TestRegCurrency(void) {
1746 #if !UCONFIG_NO_SERVICE
1747 UErrorCode status
= U_ZERO_ERROR
;
1749 ucurr_forLocale("en_US", USD
, 4, &status
);
1751 ucurr_forLocale("ja_JP", YEN
, 4, &status
);
1753 static const UChar QQQ
[] = {0x51, 0x51, 0x51, 0};
1754 if(U_FAILURE(status
)) {
1755 errcheckln(status
, "Unable to get currency for locale, error %s", u_errorName(status
));
1759 UCurrRegistryKey enkey
= ucurr_register(YEN
, "en_US", &status
);
1760 UCurrRegistryKey enUSEUROkey
= ucurr_register(QQQ
, "en_US_EURO", &status
);
1762 ucurr_forLocale("en_US", TMP
, 4, &status
);
1763 if (u_strcmp(YEN
, TMP
) != 0) {
1764 errln("FAIL: didn't return YEN registered for en_US");
1767 ucurr_forLocale("en_US_EURO", TMP
, 4, &status
);
1768 if (u_strcmp(QQQ
, TMP
) != 0) {
1769 errln("FAIL: didn't return QQQ for en_US_EURO");
1772 int32_t fallbackLen
= ucurr_forLocale("en_XX_BAR", TMP
, 4, &status
);
1774 errln("FAIL: tried to fallback en_XX_BAR");
1776 status
= U_ZERO_ERROR
; // reset
1778 if (!ucurr_unregister(enkey
, &status
)) {
1779 errln("FAIL: couldn't unregister enkey");
1782 ucurr_forLocale("en_US", TMP
, 4, &status
);
1783 if (u_strcmp(USD
, TMP
) != 0) {
1784 errln("FAIL: didn't return USD for en_US after unregister of en_US");
1786 status
= U_ZERO_ERROR
; // reset
1788 ucurr_forLocale("en_US_EURO", TMP
, 4, &status
);
1789 if (u_strcmp(QQQ
, TMP
) != 0) {
1790 errln("FAIL: didn't return QQQ for en_US_EURO after unregister of en_US");
1793 ucurr_forLocale("en_US_BLAH", TMP
, 4, &status
);
1794 if (u_strcmp(USD
, TMP
) != 0) {
1795 errln("FAIL: could not find USD for en_US_BLAH after unregister of en");
1797 status
= U_ZERO_ERROR
; // reset
1799 if (!ucurr_unregister(enUSEUROkey
, &status
)) {
1800 errln("FAIL: couldn't unregister enUSEUROkey");
1803 ucurr_forLocale("en_US_EURO", TMP
, 4, &status
);
1804 if (u_strcmp(EUR
, TMP
) != 0) {
1805 errln("FAIL: didn't return EUR for en_US_EURO after unregister of en_US_EURO");
1807 status
= U_ZERO_ERROR
; // reset
1811 void NumberFormatTest::TestCurrencyNames(void) {
1812 // Do a basic check of getName()
1813 // USD { "US$", "US Dollar" } // 04/04/1792-
1814 UErrorCode ec
= U_ZERO_ERROR
;
1815 static const UChar USD
[] = {0x55, 0x53, 0x44, 0}; /*USD*/
1816 static const UChar USX
[] = {0x55, 0x53, 0x58, 0}; /*USX*/
1817 static const UChar CAD
[] = {0x43, 0x41, 0x44, 0}; /*CAD*/
1818 static const UChar ITL
[] = {0x49, 0x54, 0x4C, 0}; /*ITL*/
1819 UBool isChoiceFormat
;
1821 const UBool possibleDataError
= TRUE
;
1822 // Warning: HARD-CODED LOCALE DATA in this test. If it fails, CHECK
1823 // THE LOCALE DATA before diving into the code.
1824 assertEquals("USD.getName(SYMBOL_NAME)",
1826 UnicodeString(ucurr_getName(USD
, "en",
1828 &isChoiceFormat
, &len
, &ec
)),
1830 assertEquals("USD.getName(LONG_NAME)",
1831 UnicodeString("US Dollar"),
1832 UnicodeString(ucurr_getName(USD
, "en",
1834 &isChoiceFormat
, &len
, &ec
)),
1836 assertEquals("CAD.getName(SYMBOL_NAME)",
1837 UnicodeString("CA$"),
1838 UnicodeString(ucurr_getName(CAD
, "en",
1840 &isChoiceFormat
, &len
, &ec
)),
1842 assertEquals("CAD.getName(SYMBOL_NAME)",
1844 UnicodeString(ucurr_getName(CAD
, "en_CA",
1846 &isChoiceFormat
, &len
, &ec
)),
1848 assertEquals("USD.getName(SYMBOL_NAME) in en_AU",
1849 UnicodeString("US$"),
1850 UnicodeString(ucurr_getName(USD
, "en_AU",
1852 &isChoiceFormat
, &len
, &ec
)),
1854 assertEquals("CAD.getName(SYMBOL_NAME)",
1855 UnicodeString("CA$"),
1856 UnicodeString(ucurr_getName(CAD
, "en_AU",
1858 &isChoiceFormat
, &len
, &ec
)),
1860 assertEquals("USX.getName(LONG_NAME)",
1861 UnicodeString("USX"),
1862 UnicodeString(ucurr_getName(USX
, "en_US",
1864 &isChoiceFormat
, &len
, &ec
)),
1866 assertSuccess("ucurr_getName", ec
);
1870 // Test that a default or fallback warning is being returned. JB 4239.
1871 ucurr_getName(CAD
, "es_ES", UCURR_LONG_NAME
, &isChoiceFormat
,
1873 assertTrue("ucurr_getName (es_ES fallback)",
1874 U_USING_FALLBACK_WARNING
== ec
, TRUE
, possibleDataError
);
1876 ucurr_getName(CAD
, "zh_TW", UCURR_LONG_NAME
, &isChoiceFormat
,
1878 assertTrue("ucurr_getName (zh_TW fallback)",
1879 U_USING_FALLBACK_WARNING
== ec
, TRUE
, possibleDataError
);
1881 ucurr_getName(CAD
, "en_US", UCURR_LONG_NAME
, &isChoiceFormat
,
1883 assertTrue("ucurr_getName (en_US default)",
1884 U_USING_DEFAULT_WARNING
== ec
|| U_USING_FALLBACK_WARNING
== ec
, TRUE
);
1886 ucurr_getName(CAD
, "ti", UCURR_LONG_NAME
, &isChoiceFormat
,
1888 assertTrue("ucurr_getName (ti default)",
1889 U_USING_DEFAULT_WARNING
== ec
, TRUE
);
1891 // Test that a default warning is being returned when falling back to root. JB 4536.
1892 ucurr_getName(ITL
, "cy", UCURR_LONG_NAME
, &isChoiceFormat
,
1894 assertTrue("ucurr_getName (cy default to root)",
1895 U_USING_DEFAULT_WARNING
== ec
, TRUE
);
1897 // TODO add more tests later
1900 void NumberFormatTest::TestCurrencyUnit(void){
1901 UErrorCode ec
= U_ZERO_ERROR
;
1902 static const UChar USD
[] = {85, 83, 68, 0}; /*USD*/
1903 static const UChar BAD
[] = {63, 63, 63, 0}; /*???*/
1904 static const UChar BAD2
[] = {63, 63, 65, 0}; /*???*/
1905 CurrencyUnit
cu(USD
, ec
);
1906 assertSuccess("CurrencyUnit", ec
);
1908 const UChar
* r
= cu
.getISOCurrency(); // who is the buffer owner ?
1909 assertEquals("getISOCurrency()", USD
, r
);
1911 CurrencyUnit
cu2(cu
);
1913 errln("CurrencyUnit copy constructed object should be same");
1916 CurrencyUnit
* cu3
= (CurrencyUnit
*)cu
.clone();
1918 errln("CurrencyUnit cloned object should be same");
1920 CurrencyUnit
bad(BAD
, ec
);
1921 assertSuccess("CurrencyUnit", ec
);
1922 if (cu
.getIndex() == bad
.getIndex()) {
1923 errln("Indexes of different currencies should differ.");
1925 CurrencyUnit
bad2(BAD2
, ec
);
1926 assertSuccess("CurrencyUnit", ec
);
1927 if (bad2
.getIndex() != bad
.getIndex()) {
1928 errln("Indexes of unrecognized currencies should be the same.");
1931 errln("Different unrecognized currencies should not be equal.");
1935 errln("Currency unit assignment should be the same.");
1940 void NumberFormatTest::TestCurrencyAmount(void){
1941 UErrorCode ec
= U_ZERO_ERROR
;
1942 static const UChar USD
[] = {85, 83, 68, 0}; /*USD*/
1943 CurrencyAmount
ca(9, USD
, ec
);
1944 assertSuccess("CurrencyAmount", ec
);
1946 CurrencyAmount
ca2(ca
);
1948 errln("CurrencyAmount copy constructed object should be same");
1953 errln("CurrencyAmount assigned object should be same");
1956 CurrencyAmount
*ca3
= (CurrencyAmount
*)ca
.clone();
1958 errln("CurrencyAmount cloned object should be same");
1963 void NumberFormatTest::TestSymbolsWithBadLocale(void) {
1965 static const char *badLocales
[] = {
1966 // length < ULOC_FULLNAME_CAPACITY
1967 "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME",
1969 // length > ULOC_FULLNAME_CAPACITY
1970 "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME"
1971 }; // expect U_USING_DEFAULT_WARNING for both
1974 for (i
= 0; i
< sizeof(badLocales
) / sizeof(char*); i
++) {
1975 const char *localeName
= badLocales
[i
];
1976 Locale
locBad(localeName
);
1977 UErrorCode status
= U_ZERO_ERROR
;
1978 UnicodeString
intlCurrencySymbol((UChar
)0xa4);
1980 intlCurrencySymbol
.append((UChar
)0xa4);
1982 logln("Current locale is %s", Locale::getDefault().getName());
1983 Locale::setDefault(locBad
, status
);
1984 logln("Current locale is %s", Locale::getDefault().getName());
1985 DecimalFormatSymbols
mySymbols(status
);
1986 if (status
!= U_USING_DEFAULT_WARNING
) {
1987 errln("DecimalFormatSymbols should return U_USING_DEFAULT_WARNING.");
1989 if (strcmp(mySymbols
.getLocale().getName(), locBad
.getName()) != 0) {
1990 errln("DecimalFormatSymbols does not have the right locale.", locBad
.getName());
1992 int symbolEnum
= (int)DecimalFormatSymbols::kDecimalSeparatorSymbol
;
1993 for (; symbolEnum
< (int)DecimalFormatSymbols::kFormatSymbolCount
; symbolEnum
++) {
1994 UnicodeString symbolString
= mySymbols
.getSymbol((DecimalFormatSymbols::ENumberFormatSymbol
)symbolEnum
);
1995 logln(UnicodeString("DecimalFormatSymbols[") + symbolEnum
+ UnicodeString("] = ") + prettify(symbolString
));
1996 if (symbolString
.length() == 0
1997 && symbolEnum
!= (int)DecimalFormatSymbols::kGroupingSeparatorSymbol
1998 && symbolEnum
!= (int)DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
)
2000 errln("DecimalFormatSymbols has an empty string at index %d.", symbolEnum
);
2004 status
= U_ZERO_ERROR
;
2005 Locale::setDefault(locDefault
, status
);
2006 logln("Current locale is %s", Locale::getDefault().getName());
2011 * Check that adoptDecimalFormatSymbols and setDecimalFormatSymbols
2012 * behave the same, except for memory ownership semantics. (No
2013 * version of this test on Java, since Java has only one method.)
2015 void NumberFormatTest::TestAdoptDecimalFormatSymbols(void) {
2016 UErrorCode ec
= U_ZERO_ERROR
;
2017 DecimalFormatSymbols
*sym
= new DecimalFormatSymbols(Locale::getUS(), ec
);
2018 if (U_FAILURE(ec
)) {
2019 errcheckln(ec
, "Fail: DecimalFormatSymbols constructor - %s", u_errorName(ec
));
2023 UnicodeString
pat(" #,##0.00");
2024 pat
.insert(0, (UChar
)0x00A4);
2025 DecimalFormat
fmt(pat
, sym
, ec
);
2026 if (U_FAILURE(ec
)) {
2027 errln("Fail: DecimalFormat constructor");
2032 fmt
.format(2350.75, str
);
2033 if (str
== "$ 2,350.75") {
2036 dataerrln("Fail: " + str
+ ", expected $ 2,350.75");
2039 sym
= new DecimalFormatSymbols(Locale::getUS(), ec
);
2040 if (U_FAILURE(ec
)) {
2041 errln("Fail: DecimalFormatSymbols constructor");
2045 sym
->setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "Q");
2046 fmt
.adoptDecimalFormatSymbols(sym
);
2049 fmt
.format(2350.75, str
);
2050 if (str
== "Q 2,350.75") {
2053 dataerrln("Fail: adoptDecimalFormatSymbols -> " + str
+ ", expected Q 2,350.75");
2056 sym
= new DecimalFormatSymbols(Locale::getUS(), ec
);
2057 if (U_FAILURE(ec
)) {
2058 errln("Fail: DecimalFormatSymbols constructor");
2062 DecimalFormat
fmt2(pat
, sym
, ec
);
2063 if (U_FAILURE(ec
)) {
2064 errln("Fail: DecimalFormat constructor");
2068 DecimalFormatSymbols
sym2(Locale::getUS(), ec
);
2069 if (U_FAILURE(ec
)) {
2070 errln("Fail: DecimalFormatSymbols constructor");
2073 sym2
.setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "Q");
2074 fmt2
.setDecimalFormatSymbols(sym2
);
2077 fmt2
.format(2350.75, str
);
2078 if (str
== "Q 2,350.75") {
2081 dataerrln("Fail: setDecimalFormatSymbols -> " + str
+ ", expected Q 2,350.75");
2085 void NumberFormatTest::TestPerMill() {
2086 UErrorCode ec
= U_ZERO_ERROR
;
2088 DecimalFormat
fmt(ctou("###.###\\u2030"), ec
);
2089 if (!assertSuccess("DecimalFormat ct", ec
)) return;
2090 assertEquals("0.4857 x ###.###\\u2030",
2091 ctou("485.7\\u2030"), fmt
.format(0.4857, str
));
2093 DecimalFormatSymbols
sym(Locale::getUS(), ec
);
2094 sym
.setSymbol(DecimalFormatSymbols::kPerMillSymbol
, ctou("m"));
2095 DecimalFormat
fmt2("", sym
, ec
);
2096 fmt2
.applyLocalizedPattern("###.###m", ec
);
2097 if (!assertSuccess("setup", ec
)) return;
2099 assertEquals("0.4857 x ###.###m",
2100 "485.7m", fmt2
.format(0.4857, str
));
2104 * Generic test for patterns that should be legal/illegal.
2106 void NumberFormatTest::TestIllegalPatterns() {
2108 // Prefix with "-:" for illegal patterns
2109 // Prefix with "+:" for legal patterns
2110 const char* DATA
[] = {
2111 // Unquoted special characters in the suffix are illegal
2116 for (int32_t i
=0; DATA
[i
]; ++i
) {
2117 const char* pat
=DATA
[i
];
2118 UBool valid
= (*pat
) == '+';
2120 UErrorCode ec
= U_ZERO_ERROR
;
2121 DecimalFormat
fmt(pat
, ec
); // locale doesn't matter here
2122 if (U_SUCCESS(ec
) == valid
) {
2123 logln("Ok: pattern \"%s\": %s",
2124 pat
, u_errorName(ec
));
2126 errcheckln(ec
, "FAIL: pattern \"%s\" should have %s; got %s",
2127 pat
, (valid
?"succeeded":"failed"),
2133 //----------------------------------------------------------------------
2135 static const char* KEYWORDS
[] = {
2136 /*0*/ "ref=", // <reference pattern to parse numbers>
2137 /*1*/ "loc=", // <locale for formats>
2138 /*2*/ "f:", // <pattern or '-'> <number> <exp. string>
2139 /*3*/ "fp:", // <pattern or '-'> <number> <exp. string> <exp. number>
2140 /*4*/ "rt:", // <pattern or '-'> <(exp.) number> <(exp.) string>
2141 /*5*/ "p:", // <pattern or '-'> <string> <exp. number>
2142 /*6*/ "perr:", // <pattern or '-'> <invalid string>
2143 /*7*/ "pat:", // <pattern or '-'> <exp. toPattern or '-' or 'err'>
2144 /*8*/ "fpc:", // <pattern or '-'> <curr.amt> <exp. string> <exp. curr.amt>
2149 * Return an integer representing the next token from this
2150 * iterator. The integer will be an index into the given list, or
2151 * -1 if there are no more tokens, or -2 if the token is not on
2154 static int32_t keywordIndex(const UnicodeString
& tok
) {
2155 for (int32_t i
=0; KEYWORDS
[i
]!=0; ++i
) {
2156 if (tok
==KEYWORDS
[i
]) {
2164 * Parse a CurrencyAmount using the given NumberFormat, with
2165 * the 'delim' character separating the number and the currency.
2167 static void parseCurrencyAmount(const UnicodeString
& str
,
2168 const NumberFormat
& fmt
,
2170 Formattable
& result
,
2172 UnicodeString num
, cur
;
2173 int32_t i
= str
.indexOf(delim
);
2174 str
.extractBetween(0, i
, num
);
2175 str
.extractBetween(i
+1, INT32_MAX
, cur
);
2177 fmt
.parse(num
, n
, ec
);
2178 result
.adoptObject(new CurrencyAmount(n
, cur
.getTerminatedBuffer(), ec
));
2181 void NumberFormatTest::TestCases() {
2182 UErrorCode ec
= U_ZERO_ERROR
;
2183 TextFile
reader("NumberFormatTestCases.txt", "UTF8", ec
);
2184 if (U_FAILURE(ec
)) {
2185 dataerrln("Couldn't open NumberFormatTestCases.txt");
2188 TokenIterator
tokens(&reader
);
2190 Locale
loc("en", "US", "");
2191 DecimalFormat
*ref
= 0, *fmt
= 0;
2192 MeasureFormat
*mfmt
= 0;
2193 UnicodeString pat
, tok
, mloc
, str
, out
, where
, currAmt
;
2198 if (!tokens
.next(tok
, ec
)) {
2201 where
= UnicodeString("(") + tokens
.getLineNumber() + ") ";
2202 int32_t cmd
= keywordIndex(tok
);
2205 // ref= <reference pattern>
2206 if (!tokens
.next(tok
, ec
)) goto error
;
2208 ref
= new DecimalFormat(tok
,
2209 new DecimalFormatSymbols(Locale::getUS(), ec
), ec
);
2210 if (U_FAILURE(ec
)) {
2211 dataerrln("Error constructing DecimalFormat");
2217 if (!tokens
.next(tok
, ec
)) goto error
;
2218 loc
= Locale::createFromName(CharString().appendInvariantChars(tok
, ec
).data());
2224 if (!tokens
.next(tok
, ec
)) goto error
;
2228 fmt
= new DecimalFormat(pat
, new DecimalFormatSymbols(loc
, ec
), ec
);
2229 if (U_FAILURE(ec
)) {
2230 errln("FAIL: " + where
+ "Pattern \"" + pat
+ "\": " + u_errorName(ec
));
2232 if (!tokens
.next(tok
, ec
)) goto error
;
2233 if (!tokens
.next(tok
, ec
)) goto error
;
2235 if (!tokens
.next(tok
, ec
)) goto error
;
2240 if (cmd
== 2 || cmd
== 3 || cmd
== 4) {
2241 // f: <pattern or '-'> <number> <exp. string>
2242 // fp: <pattern or '-'> <number> <exp. string> <exp. number>
2243 // rt: <pattern or '-'> <number> <string>
2245 if (!tokens
.next(num
, ec
)) goto error
;
2246 if (!tokens
.next(str
, ec
)) goto error
;
2247 ref
->parse(num
, n
, ec
);
2248 assertSuccess("parse", ec
);
2249 assertEquals(where
+ "\"" + pat
+ "\".format(" + num
+ ")",
2250 str
, fmt
->format(n
, out
.remove(), ec
));
2251 assertSuccess("format", ec
);
2252 if (cmd
== 3) { // fp:
2253 if (!tokens
.next(num
, ec
)) goto error
;
2254 ref
->parse(num
, n
, ec
);
2255 assertSuccess("parse", ec
);
2257 if (cmd
!= 2) { // != f:
2259 fmt
->parse(str
, m
, ec
);
2260 assertSuccess("parse", ec
);
2261 assertEquals(where
+ "\"" + pat
+ "\".parse(\"" + str
+ "\")",
2265 // p: <pattern or '-'> <string to parse> <exp. number>
2267 UnicodeString expstr
;
2268 if (!tokens
.next(str
, ec
)) goto error
;
2269 if (!tokens
.next(expstr
, ec
)) goto error
;
2271 ref
->parse(expstr
, exp
, ec
);
2272 assertSuccess("parse", ec
);
2273 fmt
->parse(str
, n
, ec
);
2274 assertSuccess("parse", ec
);
2275 assertEquals(where
+ "\"" + pat
+ "\".parse(\"" + str
+ "\")",
2280 if (!tokens
.next(tok
, ec
)) goto error
;
2284 mfmt
= MeasureFormat::createCurrencyFormat(
2285 Locale::createFromName(
2286 CharString().appendInvariantChars(mloc
, ec
).data()), ec
);
2287 if (U_FAILURE(ec
)) {
2288 errln("FAIL: " + where
+ "Loc \"" + mloc
+ "\": " + u_errorName(ec
));
2290 if (!tokens
.next(tok
, ec
)) goto error
;
2291 if (!tokens
.next(tok
, ec
)) goto error
;
2292 if (!tokens
.next(tok
, ec
)) goto error
;
2295 } else if (mfmt
== NULL
) {
2296 errln("FAIL: " + where
+ "Loc \"" + mloc
+ "\": skip case using previous locale, no valid MeasureFormat");
2297 if (!tokens
.next(tok
, ec
)) goto error
;
2298 if (!tokens
.next(tok
, ec
)) goto error
;
2299 if (!tokens
.next(tok
, ec
)) goto error
;
2302 // fpc: <loc or '-'> <curr.amt> <exp. string> <exp. curr.amt>
2303 if (!tokens
.next(currAmt
, ec
)) goto error
;
2304 if (!tokens
.next(str
, ec
)) goto error
;
2305 parseCurrencyAmount(currAmt
, *ref
, (UChar
)0x2F/*'/'*/, n
, ec
);
2306 if (assertSuccess("parseCurrencyAmount", ec
)) {
2307 assertEquals(where
+ "getCurrencyFormat(" + mloc
+ ").format(" + currAmt
+ ")",
2308 str
, mfmt
->format(n
, out
.remove(), ec
));
2309 assertSuccess("format", ec
);
2311 if (!tokens
.next(currAmt
, ec
)) goto error
;
2312 parseCurrencyAmount(currAmt
, *ref
, (UChar
)0x2F/*'/'*/, n
, ec
);
2313 if (assertSuccess("parseCurrencyAmount", ec
)) {
2316 mfmt
->parseObject(str
, m
, ec
);
2317 if (assertSuccess("parseCurrency", ec
)) {
2318 assertEquals(where
+ "getCurrencyFormat(" + mloc
+ ").parse(\"" + str
+ "\")",
2321 errln("FAIL: source " + str
);
2326 // perr: <pattern or '-'> <invalid string>
2327 errln("FAIL: Under construction");
2330 // pat: <pattern> <exp. toPattern, or '-' or 'err'>
2331 UnicodeString testpat
;
2332 UnicodeString exppat
;
2333 if (!tokens
.next(testpat
, ec
)) goto error
;
2334 if (!tokens
.next(exppat
, ec
)) goto error
;
2335 UBool err
= exppat
== "err";
2336 UBool existingPat
= FALSE
;
2337 if (testpat
== "-") {
2339 errln("FAIL: " + where
+ "Invalid command \"pat: - err\"");
2345 if (exppat
== "-") exppat
= testpat
;
2346 DecimalFormat
* f
= 0;
2347 UErrorCode ec2
= U_ZERO_ERROR
;
2351 f
= new DecimalFormat(testpat
, ec2
);
2353 if (U_SUCCESS(ec2
)) {
2355 errln("FAIL: " + where
+ "Invalid pattern \"" + testpat
+
2359 assertEquals(where
+ "\"" + testpat
+ "\".toPattern()",
2360 exppat
, f
->toPattern(pat2
));
2364 logln("Ok: " + where
+ "Invalid pattern \"" + testpat
+
2365 "\" failed: " + u_errorName(ec2
));
2367 errln("FAIL: " + where
+ "Valid pattern \"" + testpat
+
2368 "\" failed: " + u_errorName(ec2
));
2371 if (!existingPat
) delete f
;
2374 errln("FAIL: " + where
+ "Unknown command \"" + tok
+ "\"");
2381 if (U_SUCCESS(ec
)) {
2382 errln("FAIL: Unexpected EOF");
2384 errcheckln(ec
, "FAIL: " + where
+ "Unexpected " + u_errorName(ec
));
2394 //----------------------------------------------------------------------
2396 //----------------------------------------------------------------------
2398 UBool
NumberFormatTest::equalValue(const Formattable
& a
, const Formattable
& b
) {
2399 if (a
.getType() == b
.getType()) {
2403 if (a
.getType() == Formattable::kLong
) {
2404 if (b
.getType() == Formattable::kInt64
) {
2405 return a
.getLong() == b
.getLong();
2406 } else if (b
.getType() == Formattable::kDouble
) {
2407 return (double) a
.getLong() == b
.getDouble(); // TODO check use of double instead of long
2409 } else if (a
.getType() == Formattable::kDouble
) {
2410 if (b
.getType() == Formattable::kLong
) {
2411 return a
.getDouble() == (double) b
.getLong();
2412 } else if (b
.getType() == Formattable::kInt64
) {
2413 return a
.getDouble() == (double)b
.getInt64();
2415 } else if (a
.getType() == Formattable::kInt64
) {
2416 if (b
.getType() == Formattable::kLong
) {
2417 return a
.getInt64() == (int64_t)b
.getLong();
2418 } else if (b
.getType() == Formattable::kDouble
) {
2419 return a
.getInt64() == (int64_t)b
.getDouble();
2425 void NumberFormatTest::expect3(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
) {
2426 // Don't round-trip format test, since we explicitly do it
2427 expect_rbnf(fmt
, n
, str
, FALSE
);
2428 expect_rbnf(fmt
, str
, n
);
2431 void NumberFormatTest::expect2(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
) {
2432 // Don't round-trip format test, since we explicitly do it
2433 expect(fmt
, n
, str
, FALSE
);
2434 expect(fmt
, str
, n
);
2437 void NumberFormatTest::expect2(NumberFormat
* fmt
, const Formattable
& n
,
2438 const UnicodeString
& exp
,
2439 UErrorCode status
) {
2440 if (fmt
== NULL
|| U_FAILURE(status
)) {
2441 dataerrln("FAIL: NumberFormat constructor");
2443 expect2(*fmt
, n
, exp
);
2448 void NumberFormatTest::expect(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
) {
2449 UErrorCode status
= U_ZERO_ERROR
;
2451 fmt
.parse(str
, num
, status
);
2452 if (U_FAILURE(status
)) {
2453 dataerrln(UnicodeString("FAIL: Parse failed for \"") + str
+ "\" - " + u_errorName(status
));
2457 ((DecimalFormat
*) &fmt
)->toPattern(pat
);
2458 if (equalValue(num
, n
)) {
2459 logln(UnicodeString("Ok \"") + str
+ "\" x " +
2463 dataerrln(UnicodeString("FAIL \"") + str
+ "\" x " +
2465 toString(num
) + ", expected " + toString(n
));
2469 void NumberFormatTest::expect_rbnf(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
) {
2470 UErrorCode status
= U_ZERO_ERROR
;
2472 fmt
.parse(str
, num
, status
);
2473 if (U_FAILURE(status
)) {
2474 errln(UnicodeString("FAIL: Parse failed for \"") + str
+ "\"");
2477 if (equalValue(num
, n
)) {
2478 logln(UnicodeString("Ok \"") + str
+ " = " +
2481 errln(UnicodeString("FAIL \"") + str
+ " = " +
2482 toString(num
) + ", expected " + toString(n
));
2486 void NumberFormatTest::expect_rbnf(NumberFormat
& fmt
, const Formattable
& n
,
2487 const UnicodeString
& exp
, UBool rt
) {
2490 UErrorCode status
= U_ZERO_ERROR
;
2491 fmt
.format(n
, saw
, pos
, status
);
2492 CHECK(status
, "NumberFormat::format");
2494 logln(UnicodeString("Ok ") + toString(n
) +
2496 escape(saw
) + "\"");
2497 // We should be able to round-trip the formatted string =>
2498 // number => string (but not the other way around: number
2499 // => string => number2, might have number2 != number):
2502 fmt
.parse(exp
, n2
, status
);
2503 if (U_FAILURE(status
)) {
2504 errln(UnicodeString("FAIL: Parse failed for \"") + exp
+ "\"");
2508 fmt
.format(n2
, saw2
, pos
, status
);
2509 CHECK(status
, "NumberFormat::format");
2511 errln((UnicodeString
)"FAIL \"" + exp
+ "\" => " + toString(n2
) +
2512 " => \"" + saw2
+ "\"");
2516 errln(UnicodeString("FAIL ") + toString(n
) +
2518 escape(saw
) + "\", expected \"" + exp
+ "\"");
2522 void NumberFormatTest::expect(NumberFormat
& fmt
, const Formattable
& n
,
2523 const UnicodeString
& exp
, UBool rt
) {
2526 UErrorCode status
= U_ZERO_ERROR
;
2527 fmt
.format(n
, saw
, pos
, status
);
2528 CHECK(status
, "NumberFormat::format");
2530 ((DecimalFormat
*) &fmt
)->toPattern(pat
);
2532 logln(UnicodeString("Ok ") + toString(n
) + " x " +
2533 escape(pat
) + " = \"" +
2534 escape(saw
) + "\"");
2535 // We should be able to round-trip the formatted string =>
2536 // number => string (but not the other way around: number
2537 // => string => number2, might have number2 != number):
2540 fmt
.parse(exp
, n2
, status
);
2541 if (U_FAILURE(status
)) {
2542 errln(UnicodeString("FAIL: Parse failed for \"") + exp
+ "\" - " + u_errorName(status
));
2546 fmt
.format(n2
, saw2
, pos
, status
);
2547 CHECK(status
, "NumberFormat::format");
2549 errln((UnicodeString
)"FAIL \"" + exp
+ "\" => " + toString(n2
) +
2550 " => \"" + saw2
+ "\"");
2554 dataerrln(UnicodeString("FAIL ") + toString(n
) + " x " +
2555 escape(pat
) + " = \"" +
2556 escape(saw
) + "\", expected \"" + exp
+ "\"");
2560 void NumberFormatTest::expect(NumberFormat
* fmt
, const Formattable
& n
,
2561 const UnicodeString
& exp
, UBool rt
,
2562 UErrorCode status
) {
2563 if (fmt
== NULL
|| U_FAILURE(status
)) {
2564 dataerrln("FAIL: NumberFormat constructor");
2566 expect(*fmt
, n
, exp
, rt
);
2571 void NumberFormatTest::expectCurrency(NumberFormat
& nf
, const Locale
& locale
,
2572 double value
, const UnicodeString
& string
) {
2573 UErrorCode ec
= U_ZERO_ERROR
;
2574 DecimalFormat
& fmt
= * (DecimalFormat
*) &nf
;
2575 const UChar DEFAULT_CURR
[] = {45/*-*/,0};
2577 u_strcpy(curr
, DEFAULT_CURR
);
2578 if (*locale
.getLanguage() != 0) {
2579 ucurr_forLocale(locale
.getName(), curr
, 4, &ec
);
2580 assertSuccess("ucurr_forLocale", ec
);
2581 fmt
.setCurrency(curr
, ec
);
2582 assertSuccess("DecimalFormat::setCurrency", ec
);
2583 fmt
.setCurrency(curr
); //Deprecated variant, for coverage only
2586 fmt
.format(value
, s
);
2587 s
.findAndReplace((UChar32
)0x00A0, (UChar32
)0x0020);
2589 // Default display of the number yields "1234.5599999999999"
2590 // instead of "1234.56". Use a formatter to fix this.
2592 NumberFormat::createInstance(Locale::getUS(), ec
);
2594 if (U_FAILURE(ec
)) {
2595 // Oops; bad formatter. Use default op+= display.
2596 v
= (UnicodeString
)"" + value
;
2598 f
->setMaximumFractionDigits(4);
2599 f
->setGroupingUsed(FALSE
);
2600 f
->format(value
, v
);
2605 logln((UnicodeString
)"Ok: " + v
+ " x " + curr
+ " => " + prettify(s
));
2607 errln((UnicodeString
)"FAIL: " + v
+ " x " + curr
+ " => " + prettify(s
) +
2608 ", expected " + prettify(string
));
2612 void NumberFormatTest::expectPat(DecimalFormat
& fmt
, const UnicodeString
& exp
) {
2616 logln(UnicodeString("Ok \"") + pat
+ "\"");
2618 errln(UnicodeString("FAIL \"") + pat
+ "\", expected \"" + exp
+ "\"");
2622 void NumberFormatTest::expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
2624 expectPad(fmt
, pat
, pos
, 0, (UnicodeString
)"");
2626 void NumberFormatTest::expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
2627 int32_t pos
, int32_t width
, UChar pad
) {
2628 expectPad(fmt
, pat
, pos
, width
, UnicodeString(pad
));
2630 void NumberFormatTest::expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
2631 int32_t pos
, int32_t width
, const UnicodeString
& pad
) {
2632 int32_t apos
= 0, awidth
= 0;
2633 UnicodeString apadStr
;
2634 UErrorCode status
= U_ZERO_ERROR
;
2635 fmt
.applyPattern(pat
, status
);
2636 if (U_SUCCESS(status
)) {
2637 apos
= fmt
.getPadPosition();
2638 awidth
= fmt
.getFormatWidth();
2639 apadStr
=fmt
.getPadCharacterString();
2645 if (apos
== pos
&& awidth
== width
&& apadStr
== pad
) {
2646 UnicodeString infoStr
;
2647 if (pos
== ILLEGAL
) {
2648 infoStr
= UnicodeString(" width=", "") + awidth
+ UnicodeString(" pad=", "") + apadStr
;
2650 logln(UnicodeString("Ok \"") + pat
+ "\" pos=" + apos
+ infoStr
);
2652 errln(UnicodeString("FAIL \"") + pat
+ "\" pos=" + apos
+
2653 " width=" + awidth
+ " pad=" + apadStr
+
2654 ", expected " + pos
+ " " + width
+ " " + pad
);
2658 // This test is flaky b/c the symbols for CNY and JPY are equivalent in this locale - FIXME
2659 void NumberFormatTest::TestCompatibleCurrencies() {
2661 static const UChar JPY[] = {0x4A, 0x50, 0x59, 0};
2662 static const UChar CNY[] = {0x43, 0x4E, 0x59, 0};
2663 UErrorCode status = U_ZERO_ERROR;
2664 LocalPointer<NumberFormat> fmt(
2665 NumberFormat::createCurrencyInstance(Locale::getUS(), status));
2666 if (U_FAILURE(status)) {
2667 errln("Could not create number format instance.");
2670 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__);
2671 expectParseCurrency(*fmt, JPY, 1235, "\\u00A51,235");
2672 logln("%s:%d - testing parse of fullwidth yen sign\n", __FILE__, __LINE__);
2673 expectParseCurrency(*fmt, JPY, 1235, "\\uFFE51,235");
2674 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__);
2675 expectParseCurrency(*fmt, CNY, 1235, "CN\\u00A51,235");
2677 LocalPointer<NumberFormat> fmtTW(
2678 NumberFormat::createCurrencyInstance(Locale::getTaiwan(), status));
2680 logln("%s:%d - testing parse of halfwidth yen sign in TW\n", __FILE__, __LINE__);
2681 expectParseCurrency(*fmtTW, CNY, 1235, "\\u00A51,235");
2682 logln("%s:%d - testing parse of fullwidth yen sign in TW\n", __FILE__, __LINE__);
2683 expectParseCurrency(*fmtTW, CNY, 1235, "\\uFFE51,235");
2685 LocalPointer<NumberFormat> fmtJP(
2686 NumberFormat::createCurrencyInstance(Locale::getJapan(), status));
2688 logln("%s:%d - testing parse of halfwidth yen sign in JP\n", __FILE__, __LINE__);
2689 expectParseCurrency(*fmtJP, JPY, 1235, "\\u00A51,235");
2690 logln("%s:%d - testing parse of fullwidth yen sign in JP\n", __FILE__, __LINE__);
2691 expectParseCurrency(*fmtJP, JPY, 1235, "\\uFFE51,235");
2697 void NumberFormatTest::expectParseCurrency(const NumberFormat
&fmt
, const UChar
* currency
, double amount
, const char *text
) {
2699 UnicodeString utext
= ctou(text
);
2700 LocalPointer
<CurrencyAmount
> currencyAmount(fmt
.parseCurrency(utext
, ppos
));
2701 if (!ppos
.getIndex()) {
2702 errln(UnicodeString("Parse of ") + utext
+ " should have succeeded.");
2705 UErrorCode status
= U_ZERO_ERROR
;
2708 sprintf(theInfo
, "For locale %s, string \"%s\", currency ",
2709 fmt
.getLocale(ULOC_ACTUAL_LOCALE
, status
).getBaseName(),
2711 u_austrcpy(theInfo
+uprv_strlen(theInfo
), currency
);
2713 char theOperation
[100];
2715 uprv_strcpy(theOperation
, theInfo
);
2716 uprv_strcat(theOperation
, ", check amount:");
2717 assertTrue(theOperation
, amount
== currencyAmount
->getNumber().getDouble(status
));
2719 uprv_strcpy(theOperation
, theInfo
);
2720 uprv_strcat(theOperation
, ", check currency:");
2721 assertEquals(theOperation
, currency
, currencyAmount
->getISOCurrency());
2725 void NumberFormatTest::TestJB3832(){
2726 const char* localeID
= "pt_PT@currency=PTE";
2727 Locale
loc(localeID
);
2728 UErrorCode status
= U_ZERO_ERROR
;
2729 UnicodeString
expected(CharsToUnicodeString("1,150$50\\u00A0\\u200B")); // per cldrbug 7670
2731 NumberFormat
* currencyFmt
= NumberFormat::createCurrencyInstance(loc
, status
);
2732 if(U_FAILURE(status
)){
2733 dataerrln("Could not create currency formatter for locale %s - %s", localeID
, u_errorName(status
));
2736 currencyFmt
->format(1150.50, s
);
2738 errln(UnicodeString("FAIL: Expected: ")+expected
2739 + UnicodeString(" Got: ") + s
2740 + UnicodeString( " for locale: ")+ UnicodeString(localeID
) );
2742 if (U_FAILURE(status
)){
2743 errln("FAIL: Status %s", u_errorName(status
));
2748 void NumberFormatTest::TestHost()
2750 #if U_PLATFORM_USES_ONLY_WIN32_API
2751 Win32NumberTest::testLocales(this);
2753 Locale
loc("en_US@compat=host");
2754 for (UNumberFormatStyle k
= UNUM_DECIMAL
;
2755 k
< UNUM_FORMAT_STYLE_COUNT
; k
= (UNumberFormatStyle
)(k
+1)) {
2756 UErrorCode status
= U_ZERO_ERROR
;
2757 LocalPointer
<NumberFormat
> full(NumberFormat::createInstance(loc
, k
, status
));
2758 if (!NumberFormat::isStyleSupported(k
)) {
2759 if (status
!= U_UNSUPPORTED_ERROR
) {
2760 errln("FAIL: expected style %d to be unsupported - %s",
2761 k
, u_errorName(status
));
2765 if (full
.isNull() || U_FAILURE(status
)) {
2766 dataerrln("FAIL: Can't create number instance of style %d for host - %s",
2767 k
, u_errorName(status
));
2770 UnicodeString result1
;
2771 Formattable
number(10.00);
2772 full
->format(number
, result1
, status
);
2773 if (U_FAILURE(status
)) {
2774 errln("FAIL: Can't format for host");
2777 Formattable formattable
;
2778 full
->parse(result1
, formattable
, status
);
2779 if (U_FAILURE(status
)) {
2780 errln("FAIL: Can't parse for host");
2786 void NumberFormatTest::TestHostClone()
2789 Verify that a cloned formatter gives the same results
2790 and is useable after the original has been deleted.
2792 // This is mainly important on Windows.
2793 UErrorCode status
= U_ZERO_ERROR
;
2794 Locale
loc("en_US@compat=host");
2795 UDate now
= Calendar::getNow();
2796 NumberFormat
*full
= NumberFormat::createInstance(loc
, status
);
2797 if (full
== NULL
|| U_FAILURE(status
)) {
2798 dataerrln("FAIL: Can't create Relative date instance - %s", u_errorName(status
));
2801 UnicodeString result1
;
2802 full
->format(now
, result1
, status
);
2803 Format
*fullClone
= full
->clone();
2807 UnicodeString result2
;
2808 fullClone
->format(now
, result2
, status
);
2809 if (U_FAILURE(status
)) {
2810 errln("FAIL: format failure.");
2812 if (result1
!= result2
) {
2813 errln("FAIL: Clone returned different result from non-clone.");
2818 void NumberFormatTest::TestCurrencyFormat()
2820 // This test is here to increase code coverage.
2821 UErrorCode status
= U_ZERO_ERROR
;
2822 MeasureFormat
*cloneObj
;
2824 Formattable toFormat
, result
;
2825 static const UChar ISO_CODE
[4] = {0x0047, 0x0042, 0x0050, 0};
2827 Locale saveDefaultLocale
= Locale::getDefault();
2828 Locale::setDefault( Locale::getUK(), status
);
2829 if (U_FAILURE(status
)) {
2830 errln("couldn't set default Locale!");
2834 MeasureFormat
*measureObj
= MeasureFormat::createCurrencyFormat(status
);
2835 Locale::setDefault( saveDefaultLocale
, status
);
2836 if (U_FAILURE(status
)){
2837 dataerrln("FAIL: Status %s", u_errorName(status
));
2840 cloneObj
= (MeasureFormat
*)measureObj
->clone();
2841 if (cloneObj
== NULL
) {
2842 errln("Clone doesn't work");
2845 toFormat
.adoptObject(new CurrencyAmount(1234.56, ISO_CODE
, status
));
2846 measureObj
->format(toFormat
, str
, status
);
2847 measureObj
->parseObject(str
, result
, status
);
2848 if (U_FAILURE(status
)){
2849 errln("FAIL: Status %s", u_errorName(status
));
2851 if (result
!= toFormat
) {
2852 errln("measureObj does not round trip. Formatted string was \"" + str
+ "\" Got: " + toString(result
) + " Expected: " + toString(toFormat
));
2854 status
= U_ZERO_ERROR
;
2856 cloneObj
->format(toFormat
, str
, status
);
2857 cloneObj
->parseObject(str
, result
, status
);
2858 if (U_FAILURE(status
)){
2859 errln("FAIL: Status %s", u_errorName(status
));
2861 if (result
!= toFormat
) {
2862 errln("Clone does not round trip. Formatted string was \"" + str
+ "\" Got: " + toString(result
) + " Expected: " + toString(toFormat
));
2864 if (*measureObj
!= *cloneObj
) {
2865 errln("Cloned object is not equal to the original object");
2870 status
= U_USELESS_COLLATOR_ERROR
;
2871 if (MeasureFormat::createCurrencyFormat(status
) != NULL
) {
2872 errln("createCurrencyFormat should have returned NULL.");
2876 /* Port of ICU4J rounding test. */
2877 void NumberFormatTest::TestRounding() {
2878 UErrorCode status
= U_ZERO_ERROR
;
2879 DecimalFormat
*df
= (DecimalFormat
*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status
);
2881 if (U_FAILURE(status
)) {
2882 dataerrln("Unable to create decimal formatter. - %s", u_errorName(status
));
2886 int roundingIncrements
[]={1, 2, 5, 20, 50, 100};
2887 int testValues
[]={0, 300};
2889 for (int j
=0; j
<2; j
++) {
2890 for (int mode
=DecimalFormat::kRoundUp
;mode
<DecimalFormat::kRoundHalfEven
;mode
++) {
2891 df
->setRoundingMode((DecimalFormat::ERoundingMode
)mode
);
2892 for (int increment
=0; increment
<6; increment
++) {
2893 double base
=testValues
[j
];
2894 double rInc
=roundingIncrements
[increment
];
2895 checkRounding(df
, base
, 20, rInc
);
2896 rInc
=1.000000000/rInc
;
2897 checkRounding(df
, base
, 20, rInc
);
2904 void NumberFormatTest::TestRoundingPattern() {
2905 UErrorCode status
= U_ZERO_ERROR
;
2907 UnicodeString pattern
;
2909 UnicodeString expected
;
2911 { (UnicodeString
)"##0.65", 1.234, (UnicodeString
)"1.30" },
2912 { (UnicodeString
)"#50", 1230, (UnicodeString
)"1250" }
2914 int32_t numOfTests
= (sizeof(tests
)/sizeof(tests
[0]));
2915 UnicodeString result
;
2917 DecimalFormat
*df
= (DecimalFormat
*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status
);
2918 if (U_FAILURE(status
)) {
2919 dataerrln("Unable to create decimal formatter. - %s", u_errorName(status
));
2923 for (int32_t i
= 0; i
< numOfTests
; i
++) {
2926 df
->applyPattern(tests
[i
].pattern
, status
);
2927 if (U_FAILURE(status
)) {
2928 errln("Unable to apply pattern to decimal formatter. - %s", u_errorName(status
));
2931 df
->format(tests
[i
].testCase
, result
);
2933 if (result
!= tests
[i
].expected
) {
2934 errln("String Pattern Rounding Test Failed: Pattern: \"" + tests
[i
].pattern
+ "\" Number: " + tests
[i
].testCase
+ " - Got: " + result
+ " Expected: " + tests
[i
].expected
);
2941 void NumberFormatTest::checkRounding(DecimalFormat
* df
, double base
, int iterations
, double increment
) {
2942 df
->setRoundingIncrement(increment
);
2943 double lastParsed
=INT32_MIN
; //Intger.MIN_VALUE
2944 for (int i
=-iterations
; i
<=iterations
;i
++) {
2945 double iValue
=base
+(increment
*(i
*0.1));
2946 double smallIncrement
=0.00000001;
2948 smallIncrement
*=iValue
;
2950 //we not only test the value, but some values in a small range around it
2951 lastParsed
=checkRound(df
, iValue
-smallIncrement
, lastParsed
);
2952 lastParsed
=checkRound(df
, iValue
, lastParsed
);
2953 lastParsed
=checkRound(df
, iValue
+smallIncrement
, lastParsed
);
2957 double NumberFormatTest::checkRound(DecimalFormat
* df
, double iValue
, double lastParsed
) {
2958 UErrorCode status
=U_ZERO_ERROR
;
2959 UnicodeString formattedDecimal
;
2962 df
->format(iValue
, formattedDecimal
, status
);
2964 if (U_FAILURE(status
)) {
2965 errln("Error formatting number.");
2968 df
->parse(formattedDecimal
, result
, status
);
2970 if (U_FAILURE(status
)) {
2971 errln("Error parsing number.");
2974 parsed
=result
.getDouble();
2976 if (lastParsed
>parsed
) {
2977 errln("Rounding wrong direction! %d > %d", lastParsed
, parsed
);
2983 void NumberFormatTest::TestNonpositiveMultiplier() {
2984 UErrorCode status
= U_ZERO_ERROR
;
2985 DecimalFormatSymbols
US(Locale::getUS(), status
);
2986 CHECK(status
, "DecimalFormatSymbols constructor");
2987 DecimalFormat
df(UnicodeString("0"), US
, status
);
2988 CHECK(status
, "DecimalFormat(0)");
2990 // test zero multiplier
2992 int32_t mult
= df
.getMultiplier();
2993 df
.setMultiplier(0);
2994 if (df
.getMultiplier() != mult
) {
2995 errln("DecimalFormat.setMultiplier(0) did not ignore its zero input");
2998 // test negative multiplier
3000 df
.setMultiplier(-1);
3001 if (df
.getMultiplier() != -1) {
3002 errln("DecimalFormat.setMultiplier(-1) ignored its negative input");
3006 expect(df
, "1122.123", -1122.123);
3007 expect(df
, "-1122.123", 1122.123);
3008 expect(df
, "1.2", -1.2);
3009 expect(df
, "-1.2", 1.2);
3011 // Note: the tests with the final parameter of FALSE will not round trip.
3012 // The initial numeric value will format correctly, after the multiplier.
3013 // Parsing the formatted text will be out-of-range for an int64, however.
3014 // The expect() function could be modified to detect this and fall back
3015 // to looking at the decimal parsed value, but it doesn't.
3016 expect(df
, U_INT64_MIN
, "9223372036854775808", FALSE
);
3017 expect(df
, U_INT64_MIN
+1, "9223372036854775807");
3018 expect(df
, (int64_t)-123, "123");
3019 expect(df
, (int64_t)123, "-123");
3020 expect(df
, U_INT64_MAX
-1, "-9223372036854775806");
3021 expect(df
, U_INT64_MAX
, "-9223372036854775807");
3023 df
.setMultiplier(-2);
3024 expect(df
, -(U_INT64_MIN
/2)-1, "-9223372036854775806");
3025 expect(df
, -(U_INT64_MIN
/2), "-9223372036854775808");
3026 expect(df
, -(U_INT64_MIN
/2)+1, "-9223372036854775810", FALSE
);
3028 df
.setMultiplier(-7);
3029 expect(df
, -(U_INT64_MAX
/7)-1, "9223372036854775814", FALSE
);
3030 expect(df
, -(U_INT64_MAX
/7), "9223372036854775807");
3031 expect(df
, -(U_INT64_MAX
/7)+1, "9223372036854775800");
3033 // TODO: uncomment (and fix up) all the following int64_t tests once BigInteger is ported
3034 // (right now the big numbers get turned into doubles and lose tons of accuracy)
3035 //expect2(df, U_INT64_MAX, Int64ToUnicodeString(-U_INT64_MAX));
3036 //expect2(df, U_INT64_MIN, UnicodeString(Int64ToUnicodeString(U_INT64_MIN), 1));
3037 //expect2(df, U_INT64_MAX / 2, Int64ToUnicodeString(-(U_INT64_MAX / 2)));
3038 //expect2(df, U_INT64_MIN / 2, Int64ToUnicodeString(-(U_INT64_MIN / 2)));
3040 // TODO: uncomment (and fix up) once BigDecimal is ported and DecimalFormat can handle it
3041 //expect2(df, BigDecimal.valueOf(Long.MAX_VALUE), BigDecimal.valueOf(Long.MAX_VALUE).negate().toString());
3042 //expect2(df, BigDecimal.valueOf(Long.MIN_VALUE), BigDecimal.valueOf(Long.MIN_VALUE).negate().toString());
3043 //expect2(df, java.math.BigDecimal.valueOf(Long.MAX_VALUE), java.math.BigDecimal.valueOf(Long.MAX_VALUE).negate().toString());
3044 //expect2(df, java.math.BigDecimal.valueOf(Long.MIN_VALUE), java.math.BigDecimal.valueOf(Long.MIN_VALUE).negate().toString());
3048 const char * stringToParse
;
3052 } TestSpaceParsingItem
;
3055 NumberFormatTest::TestSpaceParsing() {
3057 // the string to be parsed, parsed position, parsed error index
3058 const TestSpaceParsingItem DATA
[] = {
3059 // TOTO: Update the following TODOs, some may be handled now
3060 {"$124", 4, -1, FALSE
},
3061 {"$124 $124", 4, -1, FALSE
},
3062 {"$124 ", 4, -1, FALSE
},
3063 //{"$ 124 ", 5, -1, FALSE}, // TODO: need to handle space correctly
3064 //{"$\\u00A0124 ", 5, -1, FALSE}, // TODO: need to handle space correctly
3065 {"$ 124 ", 0, 1, FALSE
}, // errorIndex used to be 0, now 1 (better)
3066 {"$\\u00A0124 ", 5, -1, FALSE
}, // errorIndex used to be 0, now 1 (better) *Apple change from open source*
3067 {" $ 124 ", 0, 0, FALSE
}, // TODO: need to handle space correctly
3068 {"124$", 0, 3, FALSE
}, // TODO: need to handle space correctly
3069 // {"124 $", 5, -1, FALSE}, // TODO: OK or not, need currency spacing rule
3070 {"124 $", 0, 3, FALSE
},
3071 {"$124", 4, -1, TRUE
},
3072 {"$124 $124", 4, -1, TRUE
},
3073 {"$124 ", 4, -1, TRUE
},
3074 {"$ 124 ", 5, -1, TRUE
},
3075 {"$\\u00A0124 ", 5, -1, TRUE
},
3076 {" $ 124 ", 6, -1, TRUE
},
3077 //{"124$", 4, -1, TRUE}, // TODO: need to handle trailing currency correctly
3078 {"124$", 3, -1, TRUE
},
3079 //{"124 $", 5, -1, TRUE}, // TODO: OK or not, need currency spacing rule
3080 {"124 $", 4, -1, TRUE
},
3082 UErrorCode status
= U_ZERO_ERROR
;
3083 Locale
locale("en_US");
3084 NumberFormat
* foo
= NumberFormat::createCurrencyInstance(locale
, status
);
3086 if (U_FAILURE(status
)) {
3090 for (uint32_t i
= 0; i
< sizeof(DATA
)/sizeof(DATA
[0]); ++i
) {
3091 ParsePosition
parsePosition(0);
3092 UnicodeString stringToBeParsed
= ctou(DATA
[i
].stringToParse
);
3093 int parsedPosition
= DATA
[i
].parsedPos
;
3094 int errorIndex
= DATA
[i
].errorIndex
;
3095 foo
->setLenient(DATA
[i
].lenient
);
3097 foo
->parse(stringToBeParsed
, result
, parsePosition
);
3098 if (parsePosition
.getIndex() != parsedPosition
||
3099 parsePosition
.getErrorIndex() != errorIndex
) {
3100 errln("FAILED parse " + stringToBeParsed
+ "; lenient: " + DATA
[i
].lenient
+ "; wrong position, expected: (" + parsedPosition
+ ", " + errorIndex
+ "); got (" + parsePosition
.getIndex() + ", " + parsePosition
.getErrorIndex() + ")");
3102 if (parsePosition
.getErrorIndex() == -1 &&
3103 result
.getType() == Formattable::kLong
&&
3104 result
.getLong() != 124) {
3105 errln("FAILED parse " + stringToBeParsed
+ "; wrong number, expect: 124, got " + result
.getLong());
3112 * Test using various numbering systems and numbering system keyword.
3115 const char *localeName
;
3118 const char *expectedResult
;
3119 } TestNumberingSystemItem
;
3121 void NumberFormatTest::TestNumberingSystems() {
3123 const TestNumberingSystemItem DATA
[] = {
3124 { "en_US@numbers=thai", 1234.567, FALSE
, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" },
3125 { "en_US@numbers=hebr", 5678.0, TRUE
, "\\u05D4\\u05F3\\u05EA\\u05E8\\u05E2\\u05F4\\u05D7" },
3126 { "en_US@numbers=arabext", 1234.567, FALSE
, "\\u06F1\\u066c\\u06F2\\u06F3\\u06F4\\u066b\\u06F5\\u06F6\\u06F7" },
3127 { "ar_EG", 1234.567, FALSE
, "\\u0661\\u066C\\u0662\\u0663\\u0664\\u066b\\u0665\\u0666\\u0667" },
3128 { "th_TH@numbers=traditional", 1234.567, FALSE
, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" }, // fall back to native per TR35
3129 { "ar_MA", 1234.567, FALSE
, "1.234,567" },
3130 { "en_US@numbers=hanidec", 1234.567, FALSE
, "\\u4e00,\\u4e8c\\u4e09\\u56db.\\u4e94\\u516d\\u4e03" },
3131 { "ta_IN@numbers=native", 1234.567, FALSE
, "\\u0BE7,\\u0BE8\\u0BE9\\u0BEA.\\u0BEB\\u0BEC\\u0BED" },
3132 { "ta_IN@numbers=traditional", 1235.0, TRUE
, "\\u0BF2\\u0BE8\\u0BF1\\u0BE9\\u0BF0\\u0BEB" },
3133 { "ta_IN@numbers=finance", 1234.567, FALSE
, "1,234.567" }, // fall back to default per TR35
3134 { "zh_TW@numbers=native", 1234.567, FALSE
, "\\u4e00,\\u4e8c\\u4e09\\u56db.\\u4e94\\u516d\\u4e03" },
3135 { "zh_TW@numbers=traditional", 1234.567, TRUE
, "\\u4E00\\u5343\\u4E8C\\u767E\\u4E09\\u5341\\u56DB\\u9EDE\\u4E94\\u516D\\u4E03" },
3136 { "zh_TW@numbers=finance", 1234.567, TRUE
, "\\u58F9\\u4EDF\\u8CB3\\u4F70\\u53C3\\u62FE\\u8086\\u9EDE\\u4F0D\\u9678\\u67D2" },
3137 { NULL
, 0, FALSE
, NULL
}
3142 const TestNumberingSystemItem
*item
;
3143 for (item
= DATA
; item
->localeName
!= NULL
; item
++) {
3145 Locale loc
= Locale::createFromName(item
->localeName
);
3147 NumberFormat
*origFmt
= NumberFormat::createInstance(loc
,ec
);
3148 if (U_FAILURE(ec
)) {
3149 dataerrln("FAIL: getInstance(%s) - %s", item
->localeName
, u_errorName(ec
));
3152 // Clone to test ticket #10682
3153 NumberFormat
*fmt
= (NumberFormat
*) origFmt
->clone();
3158 expect3(*fmt
,item
->value
,CharsToUnicodeString(item
->expectedResult
));
3160 expect2(*fmt
,item
->value
,CharsToUnicodeString(item
->expectedResult
));
3166 // Test bogus keyword value
3168 Locale loc4
= Locale::createFromName("en_US@numbers=foobar");
3169 NumberFormat
* fmt4
= NumberFormat::createInstance(loc4
, ec
);
3170 if ( ec
!= U_UNSUPPORTED_ERROR
) {
3171 errln("FAIL: getInstance(en_US@numbers=foobar) should have returned U_UNSUPPORTED_ERROR");
3176 NumberingSystem
*ns
= NumberingSystem::createInstance(ec
);
3177 if (U_FAILURE(ec
)) {
3178 dataerrln("FAIL: NumberingSystem::createInstance(ec); - %s", u_errorName(ec
));
3182 ns
->getDynamicClassID();
3183 ns
->getStaticClassID();
3185 errln("FAIL: getInstance() returned NULL.");
3188 NumberingSystem
*ns1
= new NumberingSystem(*ns
);
3190 errln("FAIL: NumberSystem copy constructor returned NULL.");
3200 NumberFormatTest::TestMultiCurrencySign() {
3201 const char* DATA
[][6] = {
3202 // the fields in the following test are:
3204 // currency pattern (with negative pattern),
3205 // currency number to be formatted,
3206 // currency format using currency symbol name, such as "$" for USD,
3207 // currency format using currency ISO name, such as "USD",
3208 // currency format using plural name, such as "US dollars".
3210 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "1234.56", "$1,234.56", "USD1,234.56", "US dollars1,234.56"},
3211 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "-1234.56", "-$1,234.56", "-USD1,234.56", "-US dollars1,234.56"},
3212 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "1", "$1.00", "USD1.00", "US dollars1.00"},
3214 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "1234.56", "\\uFFE51,234.56", "CNY1,234.56", "\\u4EBA\\u6C11\\u5E011,234.56"},
3215 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "-1234.56", "(\\uFFE51,234.56)", "(CNY1,234.56)", "(\\u4EBA\\u6C11\\u5E011,234.56)"},
3216 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "1", "\\uFFE51.00", "CNY1.00", "\\u4EBA\\u6C11\\u5E011.00"}
3219 const UChar doubleCurrencySign
[] = {0xA4, 0xA4, 0};
3220 UnicodeString
doubleCurrencyStr(doubleCurrencySign
);
3221 const UChar tripleCurrencySign
[] = {0xA4, 0xA4, 0xA4, 0};
3222 UnicodeString
tripleCurrencyStr(tripleCurrencySign
);
3224 for (uint32_t i
=0; i
<sizeof(DATA
)/sizeof(DATA
[0]); ++i
) {
3225 const char* locale
= DATA
[i
][0];
3226 UnicodeString pat
= ctou(DATA
[i
][1]);
3227 double numberToBeFormat
= atof(DATA
[i
][2]);
3228 UErrorCode status
= U_ZERO_ERROR
;
3229 DecimalFormatSymbols
* sym
= new DecimalFormatSymbols(Locale(locale
), status
);
3230 if (U_FAILURE(status
)) {
3234 for (int j
=1; j
<=3; ++j
) {
3235 // j represents the number of currency sign in the pattern.
3237 pat
= pat
.findAndReplace(ctou("\\u00A4"), doubleCurrencyStr
);
3238 } else if (j
== 3) {
3239 pat
= pat
.findAndReplace(ctou("\\u00A4\\u00A4"), tripleCurrencyStr
);
3242 DecimalFormat
* fmt
= new DecimalFormat(pat
, new DecimalFormatSymbols(*sym
), status
);
3243 if (U_FAILURE(status
)) {
3244 errln("FAILED init DecimalFormat ");
3249 ((NumberFormat
*) fmt
)->format(numberToBeFormat
, s
);
3250 // DATA[i][3] is the currency format result using a
3251 // single currency sign.
3252 // DATA[i][4] is the currency format result using
3253 // double currency sign.
3254 // DATA[i][5] is the currency format result using
3255 // triple currency sign.
3256 // DATA[i][j+2] is the currency format result using
3257 // 'j' number of currency sign.
3258 UnicodeString currencyFormatResult
= ctou(DATA
[i
][2+j
]);
3259 if (s
.compare(currencyFormatResult
)) {
3260 errln("FAIL format: Expected " + currencyFormatResult
+ "; Got " + s
);
3262 // mix style parsing
3263 for (int k
=3; k
<=5; ++k
) {
3264 // DATA[i][3] is the currency format result using a
3265 // single currency sign.
3266 // DATA[i][4] is the currency format result using
3267 // double currency sign.
3268 // DATA[i][5] is the currency format result using
3269 // triple currency sign.
3270 UnicodeString oneCurrencyFormat
= ctou(DATA
[i
][k
]);
3271 UErrorCode status
= U_ZERO_ERROR
;
3272 Formattable parseRes
;
3273 fmt
->parse(oneCurrencyFormat
, parseRes
, status
);
3274 if (U_FAILURE(status
) ||
3275 (parseRes
.getType() == Formattable::kDouble
&&
3276 parseRes
.getDouble() != numberToBeFormat
) ||
3277 (parseRes
.getType() == Formattable::kLong
&&
3278 parseRes
.getLong() != numberToBeFormat
)) {
3279 errln("FAILED parse " + oneCurrencyFormat
+ "; (i, j, k): " +
3280 i
+ ", " + j
+ ", " + k
);
3291 NumberFormatTest::TestCurrencyFormatForMixParsing() {
3292 UErrorCode status
= U_ZERO_ERROR
;
3293 MeasureFormat
* curFmt
= MeasureFormat::createCurrencyFormat(Locale("en_US"), status
);
3294 if (U_FAILURE(status
)) {
3298 const char* formats
[] = {
3299 "$1,234.56", // string to be parsed
3301 "US dollars1,234.56",
3302 "1,234.56 US dollars"
3304 const CurrencyAmount
* curramt
= NULL
;
3305 for (uint32_t i
= 0; i
< sizeof(formats
)/sizeof(formats
[0]); ++i
) {
3306 UnicodeString stringToBeParsed
= ctou(formats
[i
]);
3307 logln(UnicodeString("stringToBeParsed: ") + stringToBeParsed
);
3309 UErrorCode status
= U_ZERO_ERROR
;
3310 curFmt
->parseObject(stringToBeParsed
, result
, status
);
3311 if (U_FAILURE(status
)) {
3312 errln("FAIL: measure format parsing: '%s' ec: %s", formats
[i
], u_errorName(status
));
3313 } else if (result
.getType() != Formattable::kObject
||
3314 (curramt
= dynamic_cast<const CurrencyAmount
*>(result
.getObject())) == NULL
||
3315 curramt
->getNumber().getDouble() != 1234.56 ||
3316 UnicodeString(curramt
->getISOCurrency()).compare(ISO_CURRENCY_USD
)
3318 errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the number ");
3319 if (curramt
->getNumber().getDouble() != 1234.56) {
3320 errln((UnicodeString
)"wong number, expect: 1234.56" + ", got: " + curramt
->getNumber().getDouble());
3322 if (curramt
->getISOCurrency() != ISO_CURRENCY_USD
) {
3323 errln((UnicodeString
)"wong currency, expect: USD" + ", got: " + curramt
->getISOCurrency());
3332 NumberFormatTest::TestDecimalFormatCurrencyParse() {
3334 UErrorCode status
= U_ZERO_ERROR
;
3335 DecimalFormatSymbols
* sym
= new DecimalFormatSymbols(Locale("en_US"), status
);
3336 if (U_FAILURE(status
)) {
3341 UChar currency
= 0x00A4;
3342 // "\xA4#,##0.00;-\xA4#,##0.00"
3343 pat
.append(currency
).append(currency
).append(currency
).append("#,##0.00;-").append(currency
).append(currency
).append(currency
).append("#,##0.00");
3344 DecimalFormat
* fmt
= new DecimalFormat(pat
, sym
, status
);
3345 if (U_FAILURE(status
)) {
3347 errln("failed to new DecimalFormat in TestDecimalFormatCurrencyParse");
3350 const char* DATA
[][2] = {
3352 // string to be parsed, the parsed result (number)
3355 {"1.00 US dollar", "1"},
3356 {"$1,234.56", "1234.56"},
3357 {"USD1,234.56", "1234.56"},
3358 {"1,234.56 US dollar", "1234.56"},
3360 for (uint32_t i
= 0; i
< sizeof(DATA
)/sizeof(DATA
[0]); ++i
) {
3361 UnicodeString stringToBeParsed
= ctou(DATA
[i
][0]);
3362 double parsedResult
= atof(DATA
[i
][1]);
3363 UErrorCode status
= U_ZERO_ERROR
;
3365 fmt
->parse(stringToBeParsed
, result
, status
);
3366 if (U_FAILURE(status
) ||
3367 (result
.getType() == Formattable::kDouble
&&
3368 result
.getDouble() != parsedResult
) ||
3369 (result
.getType() == Formattable::kLong
&&
3370 result
.getLong() != parsedResult
)) {
3371 errln((UnicodeString
)"FAIL parse: Expected " + parsedResult
);
3379 NumberFormatTest::TestCurrencyIsoPluralFormat() {
3380 static const char* DATA
[][6] = {
3383 // currency amount to be formatted,
3384 // currency ISO code to be formatted,
3385 // format result using CURRENCYSTYLE,
3386 // format result using ISOCURRENCYSTYLE,
3387 // format result using PLURALCURRENCYSTYLE,
3389 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollars"},
3390 {"en_US", "1234.56", "USD", "$1,234.56", "USD1,234.56", "1,234.56 US dollars"},
3391 {"en_US", "-1234.56", "USD", "-$1,234.56", "-USD1,234.56", "-1,234.56 US dollars"},
3392 {"zh_CN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00\\u7F8E\\u5143"},
3393 {"zh_CN", "1234.56", "USD", "US$\\u00A01,234.56", "USD\\u00A01,234.56", "1,234.56\\u7F8E\\u5143"},
3394 // wrong ISO code {"zh_CN", "1", "CHY", "CHY1.00", "CHY1.00", "1.00 CHY"},
3395 // wrong ISO code {"zh_CN", "1234.56", "CHY", "CHY1,234.56", "CHY1,234.56", "1,234.56 CHY"},
3396 {"zh_CN", "1", "CNY", "\\uFFE5\\u00A01.00", "CNY\\u00A01.00", "1.00\\u4EBA\\u6C11\\u5E01"},
3397 {"zh_CN", "1234.56", "CNY", "\\uFFE5\\u00A01,234.56", "CNY\\u00A01,234.56", "1,234.56\\u4EBA\\u6C11\\u5E01"},
3398 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u20BD", "1,00\\u00A0RUB", "1,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3399 {"ru_RU", "2", "RUB", "2,00\\u00A0\\u20BD", "2,00\\u00A0RUB", "2,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3400 {"ru_RU", "5", "RUB", "5,00\\u00A0\\u20BD", "5,00\\u00A0RUB", "5,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3401 // test locale without currency information
3402 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 USD"},
3403 // test choice format
3404 {"es_AR", "1", "INR", "INR1,00", "INR1,00", "1,00 rupia india"},
3406 static const UNumberFormatStyle currencyStyles
[] = {
3409 UNUM_CURRENCY_PLURAL
3412 for (int32_t i
=0; i
<UPRV_LENGTHOF(DATA
); ++i
) {
3413 for (int32_t kIndex
= 0; kIndex
< UPRV_LENGTHOF(currencyStyles
); ++kIndex
) {
3414 UNumberFormatStyle k
= currencyStyles
[kIndex
];
3415 const char* localeString
= DATA
[i
][0];
3416 double numberToBeFormat
= atof(DATA
[i
][1]);
3417 const char* currencyISOCode
= DATA
[i
][2];
3418 Locale
locale(localeString
);
3419 UErrorCode status
= U_ZERO_ERROR
;
3420 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, k
, status
);
3421 if (U_FAILURE(status
)) {
3423 dataerrln((UnicodeString
)"can not create instance, locale:" + localeString
+ ", style: " + k
+ " - " + u_errorName(status
));
3426 UChar currencyCode
[4];
3427 u_charsToUChars(currencyISOCode
, currencyCode
, 4);
3428 numFmt
->setCurrency(currencyCode
, status
);
3429 if (U_FAILURE(status
)) {
3431 errln((UnicodeString
)"can not set currency:" + currencyISOCode
);
3435 UnicodeString strBuf
;
3436 numFmt
->format(numberToBeFormat
, strBuf
);
3437 int resultDataIndex
= 3 + kIndex
;
3438 // DATA[i][resultDataIndex] is the currency format result
3439 // using 'k' currency style.
3440 UnicodeString formatResult
= ctou(DATA
[i
][resultDataIndex
]);
3441 if (strBuf
.compare(formatResult
)) {
3442 errln("FAIL: Expected " + formatResult
+ " actual: " + strBuf
);
3444 // test parsing, and test parsing for all currency formats.
3445 for (int j
= 3; j
< 6; ++j
) {
3446 // DATA[i][3] is the currency format result using
3447 // CURRENCYSTYLE formatter.
3448 // DATA[i][4] is the currency format result using
3449 // ISOCURRENCYSTYLE formatter.
3450 // DATA[i][5] is the currency format result using
3451 // PLURALCURRENCYSTYLE formatter.
3452 UnicodeString oneCurrencyFormatResult
= ctou(DATA
[i
][j
]);
3453 UErrorCode status
= U_ZERO_ERROR
;
3454 Formattable parseResult
;
3455 numFmt
->parse(oneCurrencyFormatResult
, parseResult
, status
);
3456 if (U_FAILURE(status
) ||
3457 (parseResult
.getType() == Formattable::kDouble
&&
3458 parseResult
.getDouble() != numberToBeFormat
) ||
3459 (parseResult
.getType() == Formattable::kLong
&&
3460 parseResult
.getLong() != numberToBeFormat
)) {
3461 errln((UnicodeString
)"FAIL: getCurrencyFormat of locale " +
3462 localeString
+ " failed roundtripping the number");
3463 if (parseResult
.getType() == Formattable::kDouble
) {
3464 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual: " +parseResult
.getDouble());
3466 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual: " +parseResult
.getLong());
3476 NumberFormatTest::TestCurrencyParsing() {
3477 static const char* DATA
[][6] = {
3480 // currency amount to be formatted,
3481 // currency ISO code to be formatted,
3482 // format result using CURRENCYSTYLE,
3483 // format result using ISOCURRENCYSTYLE,
3484 // format result using PLURALCURRENCYSTYLE,
3485 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollar"},
3486 {"pa_IN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00 \\u0a2f\\u0a42.\\u0a10\\u0a38. \\u0a21\\u0a3e\\u0a32\\u0a30"},
3487 {"es_AR", "1", "USD", "US$1,00", "USD1,00", "1,00 d\\u00f3lar estadounidense"},
3488 {"ar_EG", "1", "USD", "\\u0661\\u066b\\u0660\\u0660\\u00a0US$", "\\u0661\\u066b\\u0660\\u0660\\u00a0USD", "\\u0661\\u066b\\u0660\\u0660 \\u062f\\u0648\\u0644\\u0627\\u0631 \\u0623\\u0645\\u0631\\u064a\\u0643\\u064a"},
3489 {"fa_CA", "1", "USD", "\\u200e$\\u06f1\\u066b\\u06f0\\u06f0", "\\u200eUSD\\u06f1\\u066b\\u06f0\\u06f0", "\\u200e\\u062f\\u0644\\u0627\\u0631 \\u0627\\u0645\\u0631\\u06cc\\u06a9\\u0627\\u06f1\\u066b\\u06f0\\u06f0"},
3490 {"he_IL", "1", "USD", "1.00\\u00a0$", "1.00\\u00a0USD", "1.00 \\u05d3\\u05d5\\u05dc\\u05e8 \\u05d0\\u05de\\u05e8\\u05d9\\u05e7\\u05d0\\u05d9"},
3491 {"hr_HR", "1", "USD", "1,00\\u00a0USD", "1,00\\u00a0USD", "1,00 Ameri\\u010dki dolar"},
3492 {"id_ID", "1", "USD", "US$1,00", "USD1,00", "1,00 Dolar Amerika Serikat"},
3493 {"it_IT", "1", "USD", "1,00\\u00a0US$", "1,00\\u00a0USD", "1,00 Dollaro Statunitense"},
3494 {"ko_KR", "1", "USD", "US$1.00", "USD1.00", "1.00\\ubbf8\\uad6d \\ub2ec\\ub7ec"},
3495 {"ja_JP", "1", "USD", "$1.00", "USD1.00", "1.00\\u7c73\\u30c9\\u30eb"},
3496 {"zh_CN", "1", "CNY", "\\uFFE5\\u00a01.00", "CNY\\u00a01.00", "1.00\\u4EBA\\u6C11\\u5E01"},
3497 {"zh_TW", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\u5e63"},
3498 {"zh_Hant", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\u5e63"},
3499 {"zh_Hant", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u5713"},
3500 {"ja_JP", "1", "JPY", "\\uFFE51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u5186"},
3501 {"ja_JP", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u5186"},
3502 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u20BD", "1,00\\u00A0RUB", "1,00 \\u0420\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u0438\\u0439 \\u0440\\u0443\\u0431\\u043B\\u044C"}
3504 static const UNumberFormatStyle currencyStyles
[] = {
3507 UNUM_CURRENCY_PLURAL
3509 static const char* currencyStyleNames
[] = {
3511 "UNUM_CURRENCY_ISO",
3512 "UNUM_CURRENCY_PLURAL"
3515 #ifdef NUMFMTST_CACHE_DEBUG
3518 printf("loop: %d\n", deadloop
++);
3520 for (uint32_t i
=0; i
< sizeof(DATA
)/sizeof(DATA
[0]); ++i
) { /* i = test case # - should be i=0*/
3521 for (int32_t kIndex
= 2; kIndex
< UPRV_LENGTHOF(currencyStyles
); ++kIndex
) {
3522 UNumberFormatStyle k
= currencyStyles
[kIndex
]; /* k = style */
3523 const char* localeString
= DATA
[i
][0];
3524 double numberToBeFormat
= atof(DATA
[i
][1]);
3525 const char* currencyISOCode
= DATA
[i
][2];
3526 Locale
locale(localeString
);
3527 UErrorCode status
= U_ZERO_ERROR
;
3528 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, k
, status
);
3529 logln("#%d NumberFormat(%s, %s) Currency=%s\n",
3530 i
, localeString
, currencyStyleNames
[kIndex
],
3533 if (U_FAILURE(status
)) {
3535 dataerrln((UnicodeString
)"can not create instance, locale:" + localeString
+ ", style: " + k
+ " - " + u_errorName(status
));
3538 UChar currencyCode
[4];
3539 u_charsToUChars(currencyISOCode
, currencyCode
, 4);
3540 numFmt
->setCurrency(currencyCode
, status
);
3541 if (U_FAILURE(status
)) {
3543 errln((UnicodeString
)"can not set currency:" + currencyISOCode
);
3547 UnicodeString strBuf
;
3548 numFmt
->format(numberToBeFormat
, strBuf
);
3550 int resultDataIndex = 3 + kIndex;
3551 // DATA[i][resultDataIndex] is the currency format result
3552 // using 'k' currency style.
3553 UnicodeString formatResult = ctou(DATA[i][resultDataIndex]);
3554 if (strBuf.compare(formatResult)) {
3555 errln("FAIL: Expected " + formatResult + " actual: " + strBuf);
3558 // test parsing, and test parsing for all currency formats.
3559 for (int j
= 3; j
< 6; ++j
) {
3560 // DATA[i][3] is the currency format result using
3561 // CURRENCYSTYLE formatter.
3562 // DATA[i][4] is the currency format result using
3563 // ISOCURRENCYSTYLE formatter.
3564 // DATA[i][5] is the currency format result using
3565 // PLURALCURRENCYSTYLE formatter.
3566 UnicodeString oneCurrencyFormatResult
= ctou(DATA
[i
][j
]);
3567 UErrorCode status
= U_ZERO_ERROR
;
3568 Formattable parseResult
;
3569 logln("parse(%s)", DATA
[i
][j
]);
3570 numFmt
->parse(oneCurrencyFormatResult
, parseResult
, status
);
3571 if (U_FAILURE(status
) ||
3572 (parseResult
.getType() == Formattable::kDouble
&&
3573 parseResult
.getDouble() != numberToBeFormat
) ||
3574 (parseResult
.getType() == Formattable::kLong
&&
3575 parseResult
.getLong() != numberToBeFormat
)) {
3576 errln((UnicodeString
)"FAIL: NumberFormat(" + localeString
+", " + currencyStyleNames
[kIndex
] +
3577 "), Currency="+currencyISOCode
+", parse("+DATA
[i
][j
]+") returned error " + (UnicodeString
)u_errorName(status
)+". Testcase: data[" + i
+ "][" + currencyStyleNames
[j
-3] +"="+j
+"]");
3578 if (parseResult
.getType() == Formattable::kDouble
) {
3579 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual (double): " +parseResult
.getDouble());
3581 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual (long): " +parseResult
.getLong());
3583 errln((UnicodeString
)" round-trip would be: " + strBuf
);
3589 #ifdef NUMFMTST_CACHE_DEBUG
3596 NumberFormatTest::TestParseCurrencyInUCurr() {
3597 const char* DATA
[] = {
3598 "1.00 US DOLLAR", // case in-sensitive
3635 "Afghan Afghani (1927\\u20132002)1.00",
3636 "Afghan afghani (1927\\u20132002)1.00",
3637 "Afghan Afghani1.00",
3638 "Afghan Afghanis1.00",
3641 "Albanian lek\\u00eb1.00",
3642 "Algerian Dinar1.00",
3643 "Algerian dinar1.00",
3644 "Algerian dinars1.00",
3645 "Andorran Peseta1.00",
3646 "Andorran peseta1.00",
3647 "Andorran pesetas1.00",
3648 "Angolan Kwanza (1977\\u20131991)1.00",
3649 "Angolan Readjusted Kwanza (1995\\u20131999)1.00",
3650 "Angolan Kwanza1.00",
3651 "Angolan New Kwanza (1990\\u20132000)1.00",
3652 "Angolan kwanza (1977\\u20131991)1.00",
3653 "Angolan readjusted kwanza (1995\\u20131999)1.00",
3654 "Angolan kwanza1.00",
3655 "Angolan kwanzas (1977\\u20131991)1.00",
3656 "Angolan readjusted kwanzas (1995\\u20131999)1.00",
3657 "Angolan kwanzas1.00",
3658 "Angolan new kwanza (1990\\u20132000)1.00",
3659 "Angolan new kwanzas (1990\\u20132000)1.00",
3660 "Argentine Austral1.00",
3661 "Argentine Peso (1983\\u20131985)1.00",
3662 "Argentine Peso1.00",
3663 "Argentine austral1.00",
3664 "Argentine australs1.00",
3665 "Argentine peso (1983\\u20131985)1.00",
3666 "Argentine peso1.00",
3667 "Argentine pesos (1983\\u20131985)1.00",
3668 "Argentine pesos1.00",
3669 "Armenian Dram1.00",
3670 "Armenian dram1.00",
3671 "Armenian drams1.00",
3672 "Aruban Florin1.00",
3673 "Aruban florin1.00",
3674 "Australian Dollar1.00",
3675 "Australian dollar1.00",
3676 "Australian dollars1.00",
3677 "Austrian Schilling1.00",
3678 "Austrian schilling1.00",
3679 "Austrian schillings1.00",
3680 "Azerbaijani Manat (1993\\u20132006)1.00",
3681 "Azerbaijani Manat1.00",
3682 "Azerbaijani manat (1993\\u20132006)1.00",
3683 "Azerbaijani manat1.00",
3684 "Azerbaijani manats (1993\\u20132006)1.00",
3685 "Azerbaijani manats1.00",
3729 "Bahamian Dollar1.00",
3730 "Bahamian dollar1.00",
3731 "Bahamian dollars1.00",
3732 "Bahraini Dinar1.00",
3733 "Bahraini dinar1.00",
3734 "Bahraini dinars1.00",
3735 "Bangladeshi Taka1.00",
3736 "Bangladeshi taka1.00",
3737 "Bangladeshi takas1.00",
3738 "Barbadian Dollar1.00",
3739 "Barbadian dollar1.00",
3740 "Barbadian dollars1.00",
3741 "Belarusian New Ruble (1994\\u20131999)1.00",
3742 "Belarusian Ruble1.00",
3743 "Belarusian new ruble (1994\\u20131999)1.00",
3744 "Belarusian new rubles (1994\\u20131999)1.00",
3745 "Belarusian ruble1.00",
3746 "Belarusian rubles1.00",
3747 "Belgian Franc (convertible)1.00",
3748 "Belgian Franc (financial)1.00",
3749 "Belgian Franc1.00",
3750 "Belgian franc (convertible)1.00",
3751 "Belgian franc (financial)1.00",
3752 "Belgian franc1.00",
3753 "Belgian francs (convertible)1.00",
3754 "Belgian francs (financial)1.00",
3755 "Belgian francs1.00",
3756 "Belize Dollar1.00",
3757 "Belize dollar1.00",
3758 "Belize dollars1.00",
3759 "Bermudan Dollar1.00",
3760 "Bermudan dollar1.00",
3761 "Bermudan dollars1.00",
3762 "Bhutanese Ngultrum1.00",
3763 "Bhutanese ngultrum1.00",
3764 "Bhutanese ngultrums1.00",
3765 "Bolivian Mvdol1.00",
3766 "Bolivian Peso1.00",
3767 "Bolivian mvdol1.00",
3768 "Bolivian mvdols1.00",
3769 "Bolivian peso1.00",
3770 "Bolivian pesos1.00",
3771 "Bolivian Boliviano1.00",
3772 "Bolivian Boliviano1.00",
3773 "Bolivian Bolivianos1.00",
3774 "Bosnia-Herzegovina Convertible Mark1.00",
3775 "Bosnia-Herzegovina Dinar (1992\\u20131994)1.00",
3776 "Bosnia-Herzegovina convertible mark1.00",
3777 "Bosnia-Herzegovina convertible marks1.00",
3778 "Bosnia-Herzegovina dinar (1992\\u20131994)1.00",
3779 "Bosnia-Herzegovina dinars (1992\\u20131994)1.00",
3780 "Botswanan Pula1.00",
3781 "Botswanan pula1.00",
3782 "Botswanan pulas1.00",
3783 "Brazilian New Cruzado (1989\\u20131990)1.00",
3784 "Brazilian Cruzado (1986\\u20131989)1.00",
3785 "Brazilian Cruzeiro (1990\\u20131993)1.00",
3786 "Brazilian New Cruzeiro (1967\\u20131986)1.00",
3787 "Brazilian Cruzeiro (1993\\u20131994)1.00",
3788 "Brazilian Real1.00",
3789 "Brazilian new cruzado (1989\\u20131990)1.00",
3790 "Brazilian new cruzados (1989\\u20131990)1.00",
3791 "Brazilian cruzado (1986\\u20131989)1.00",
3792 "Brazilian cruzados (1986\\u20131989)1.00",
3793 "Brazilian cruzeiro (1990\\u20131993)1.00",
3794 "Brazilian new cruzeiro (1967\\u20131986)1.00",
3795 "Brazilian cruzeiro (1993\\u20131994)1.00",
3796 "Brazilian cruzeiros (1990\\u20131993)1.00",
3797 "Brazilian new cruzeiros (1967\\u20131986)1.00",
3798 "Brazilian cruzeiros (1993\\u20131994)1.00",
3799 "Brazilian real1.00",
3800 "Brazilian reals1.00",
3801 "British Pound1.00",
3802 "British pound1.00",
3803 "British pounds1.00",
3804 "Brunei Dollar1.00",
3805 "Brunei dollar1.00",
3806 "Brunei dollars1.00",
3807 "Bulgarian Hard Lev1.00",
3808 "Bulgarian Lev1.00",
3809 "Bulgarian Leva1.00",
3810 "Bulgarian hard lev1.00",
3811 "Bulgarian hard leva1.00",
3812 "Bulgarian lev1.00",
3815 "Burmese kyats1.00",
3816 "Burundian Franc1.00",
3817 "Burundian franc1.00",
3818 "Burundian francs1.00",
3823 "West African CFA Franc1.00",
3824 "Central African CFA Franc1.00",
3825 "West African CFA franc1.00",
3826 "Central African CFA franc1.00",
3827 "West African CFA francs1.00",
3828 "Central African CFA francs1.00",
3855 "Cambodian Riel1.00",
3856 "Cambodian riel1.00",
3857 "Cambodian riels1.00",
3858 "Canadian Dollar1.00",
3859 "Canadian dollar1.00",
3860 "Canadian dollars1.00",
3861 "Cape Verdean Escudo1.00",
3862 "Cape Verdean escudo1.00",
3863 "Cape Verdean escudos1.00",
3864 "Cayman Islands Dollar1.00",
3865 "Cayman Islands dollar1.00",
3866 "Cayman Islands dollars1.00",
3868 "Chilean Unit of Account (UF)1.00",
3870 "Chilean pesos1.00",
3871 "Chilean unit of account (UF)1.00",
3872 "Chilean units of account (UF)1.00",
3875 "Colombian Peso1.00",
3876 "Colombian peso1.00",
3877 "Colombian pesos1.00",
3878 "Comorian Franc1.00",
3879 "Comorian franc1.00",
3880 "Comorian francs1.00",
3881 "Congolese Franc1.00",
3882 "Congolese franc1.00",
3883 "Congolese francs1.00",
3884 "Costa Rican Col\\u00f3n1.00",
3885 "Costa Rican col\\u00f3n1.00",
3886 "Costa Rican col\\u00f3ns1.00",
3887 "Croatian Dinar1.00",
3888 "Croatian Kuna1.00",
3889 "Croatian dinar1.00",
3890 "Croatian dinars1.00",
3891 "Croatian kuna1.00",
3892 "Croatian kunas1.00",
3896 "Cypriot Pound1.00",
3897 "Cypriot pound1.00",
3898 "Cypriot pounds1.00",
3899 "Czech Republic Koruna1.00",
3900 "Czech Republic koruna1.00",
3901 "Czech Republic korunas1.00",
3902 "Czechoslovak Hard Koruna1.00",
3903 "Czechoslovak hard koruna1.00",
3904 "Czechoslovak hard korunas1.00",
3915 "Danish kroner1.00",
3919 "Djiboutian Franc1.00",
3920 "Djiboutian franc1.00",
3921 "Djiboutian francs1.00",
3922 "Dominican Peso1.00",
3923 "Dominican peso1.00",
3924 "Dominican pesos1.00",
3943 "East Caribbean Dollar1.00",
3944 "East Caribbean dollar1.00",
3945 "East Caribbean dollars1.00",
3946 "East German Mark1.00",
3947 "East German mark1.00",
3948 "East German marks1.00",
3949 "Ecuadorian Sucre1.00",
3950 "Ecuadorian Unit of Constant Value1.00",
3951 "Ecuadorian sucre1.00",
3952 "Ecuadorian sucres1.00",
3953 "Ecuadorian unit of constant value1.00",
3954 "Ecuadorian units of constant value1.00",
3955 "Egyptian Pound1.00",
3956 "Egyptian pound1.00",
3957 "Egyptian pounds1.00",
3958 "Salvadoran Col\\u00f3n1.00",
3959 "Salvadoran col\\u00f3n1.00",
3960 "Salvadoran colones1.00",
3961 "Equatorial Guinean Ekwele1.00",
3962 "Equatorial Guinean ekwele1.00",
3963 "Eritrean Nakfa1.00",
3964 "Eritrean nakfa1.00",
3965 "Eritrean nakfas1.00",
3966 "Estonian Kroon1.00",
3967 "Estonian kroon1.00",
3968 "Estonian kroons1.00",
3969 "Ethiopian Birr1.00",
3970 "Ethiopian birr1.00",
3971 "Ethiopian birrs1.00",
3973 "European Composite Unit1.00",
3974 "European Currency Unit1.00",
3975 "European Monetary Unit1.00",
3976 "European Unit of Account (XBC)1.00",
3977 "European Unit of Account (XBD)1.00",
3978 "European composite unit1.00",
3979 "European composite units1.00",
3980 "European currency unit1.00",
3981 "European currency units1.00",
3982 "European monetary unit1.00",
3983 "European monetary units1.00",
3984 "European unit of account (XBC)1.00",
3985 "European unit of account (XBD)1.00",
3986 "European units of account (XBC)1.00",
3987 "European units of account (XBD)1.00",
3995 "Falkland Islands Pound1.00",
3996 "Falkland Islands pound1.00",
3997 "Falkland Islands pounds1.00",
3998 "Fijian Dollar1.00",
3999 "Fijian dollar1.00",
4000 "Fijian dollars1.00",
4001 "Finnish Markka1.00",
4002 "Finnish markka1.00",
4003 "Finnish markkas1.00",
4006 "French Gold Franc1.00",
4007 "French UIC-Franc1.00",
4008 "French UIC-franc1.00",
4009 "French UIC-francs1.00",
4011 "French francs1.00",
4012 "French gold franc1.00",
4013 "French gold francs1.00",
4038 "Gambian Dalasi1.00",
4039 "Gambian dalasi1.00",
4040 "Gambian dalasis1.00",
4041 "Georgian Kupon Larit1.00",
4042 "Georgian Lari1.00",
4043 "Georgian kupon larit1.00",
4044 "Georgian kupon larits1.00",
4045 "Georgian lari1.00",
4046 "Georgian laris1.00",
4047 "Ghanaian Cedi (1979\\u20132007)1.00",
4048 "Ghanaian Cedi1.00",
4049 "Ghanaian cedi (1979\\u20132007)1.00",
4050 "Ghanaian cedi1.00",
4051 "Ghanaian cedis (1979\\u20132007)1.00",
4052 "Ghanaian cedis1.00",
4053 "Gibraltar Pound1.00",
4054 "Gibraltar pound1.00",
4055 "Gibraltar pounds1.00",
4058 "Greek Drachma1.00",
4059 "Greek drachma1.00",
4060 "Greek drachmas1.00",
4061 "Guatemalan Quetzal1.00",
4062 "Guatemalan quetzal1.00",
4063 "Guatemalan quetzals1.00",
4064 "Guinean Franc1.00",
4066 "Guinean franc1.00",
4067 "Guinean francs1.00",
4069 "Guinean sylis1.00",
4070 "Guinea-Bissau Peso1.00",
4071 "Guinea-Bissau peso1.00",
4072 "Guinea-Bissau pesos1.00",
4073 "Guyanaese Dollar1.00",
4074 "Guyanaese dollar1.00",
4075 "Guyanaese dollars1.00",
4086 "Haitian Gourde1.00",
4087 "Haitian gourde1.00",
4088 "Haitian gourdes1.00",
4089 "Honduran Lempira1.00",
4090 "Honduran lempira1.00",
4091 "Honduran lempiras1.00",
4092 "Hong Kong Dollar1.00",
4093 "Hong Kong dollar1.00",
4094 "Hong Kong dollars1.00",
4095 "Hungarian Forint1.00",
4096 "Hungarian forint1.00",
4097 "Hungarian forints1.00",
4109 "Icelandic Kr\\u00f3na1.00",
4110 "Icelandic kr\\u00f3na1.00",
4111 "Icelandic kr\\u00f3nur1.00",
4114 "Indian rupees1.00",
4115 "Indonesian Rupiah1.00",
4116 "Indonesian rupiah1.00",
4117 "Indonesian rupiahs1.00",
4120 "Iranian rials1.00",
4127 "Israeli Pound1.00",
4128 "Israeli new sheqel1.00",
4129 "Israeli pound1.00",
4130 "Israeli pounds1.00",
4133 "Italian liras1.00",
4137 "Jamaican Dollar1.00",
4138 "Jamaican dollar1.00",
4139 "Jamaican dollars1.00",
4142 "Jordanian Dinar1.00",
4143 "Jordanian dinar1.00",
4144 "Jordanian dinars1.00",
4156 "Kazakhstani Tenge1.00",
4157 "Kazakhstani tenge1.00",
4158 "Kazakhstani tenges1.00",
4159 "Kenyan Shilling1.00",
4160 "Kenyan shilling1.00",
4161 "Kenyan shillings1.00",
4162 "Kuwaiti Dinar1.00",
4163 "Kuwaiti dinar1.00",
4164 "Kuwaiti dinars1.00",
4165 "Kyrgystani Som1.00",
4166 "Kyrgystani som1.00",
4167 "Kyrgystani soms1.00",
4195 "Latvian Ruble1.00",
4198 "Latvian ruble1.00",
4199 "Latvian rubles1.00",
4200 "Lebanese Pound1.00",
4201 "Lebanese pound1.00",
4202 "Lebanese pounds1.00",
4205 "Lesotho lotis1.00",
4206 "Liberian Dollar1.00",
4207 "Liberian dollar1.00",
4208 "Liberian dollars1.00",
4211 "Libyan dinars1.00",
4212 "Lithuanian Litas1.00",
4213 "Lithuanian Talonas1.00",
4214 "Lithuanian litas1.00",
4215 "Lithuanian litai1.00",
4216 "Lithuanian talonas1.00",
4217 "Lithuanian talonases1.00",
4218 "Luxembourgian Convertible Franc1.00",
4219 "Luxembourg Financial Franc1.00",
4220 "Luxembourgian Franc1.00",
4221 "Luxembourgian convertible franc1.00",
4222 "Luxembourgian convertible francs1.00",
4223 "Luxembourg financial franc1.00",
4224 "Luxembourg financial francs1.00",
4225 "Luxembourgian franc1.00",
4226 "Luxembourgian francs1.00",
4265 "Macanese Pataca1.00",
4266 "Macanese pataca1.00",
4267 "Macanese patacas1.00",
4268 "Macedonian Denar1.00",
4269 "Macedonian denar1.00",
4270 "Macedonian denari1.00",
4271 "Malagasy Ariaries1.00",
4272 "Malagasy Ariary1.00",
4273 "Malagasy Ariary1.00",
4274 "Malagasy Franc1.00",
4275 "Malagasy franc1.00",
4276 "Malagasy francs1.00",
4277 "Malawian Kwacha1.00",
4278 "Malawian Kwacha1.00",
4279 "Malawian Kwachas1.00",
4280 "Malaysian Ringgit1.00",
4281 "Malaysian ringgit1.00",
4282 "Malaysian ringgits1.00",
4283 "Maldivian Rufiyaa1.00",
4284 "Maldivian rufiyaa1.00",
4285 "Maldivian rufiyaas1.00",
4288 "Malian francs1.00",
4290 "Maltese Pound1.00",
4293 "Maltese pound1.00",
4294 "Maltese pounds1.00",
4295 "Mauritanian Ouguiya1.00",
4296 "Mauritanian ouguiya1.00",
4297 "Mauritanian ouguiyas1.00",
4298 "Mauritian Rupee1.00",
4299 "Mauritian rupee1.00",
4300 "Mauritian rupees1.00",
4302 "Mexican Silver Peso (1861\\u20131992)1.00",
4303 "Mexican Investment Unit1.00",
4305 "Mexican pesos1.00",
4306 "Mexican silver peso (1861\\u20131992)1.00",
4307 "Mexican silver pesos (1861\\u20131992)1.00",
4308 "Mexican investment unit1.00",
4309 "Mexican investment units1.00",
4313 "Mongolian Tugrik1.00",
4314 "Mongolian tugrik1.00",
4315 "Mongolian tugriks1.00",
4316 "Moroccan Dirham1.00",
4317 "Moroccan Franc1.00",
4318 "Moroccan dirham1.00",
4319 "Moroccan dirhams1.00",
4320 "Moroccan franc1.00",
4321 "Moroccan francs1.00",
4322 "Mozambican Escudo1.00",
4323 "Mozambican Metical1.00",
4324 "Mozambican escudo1.00",
4325 "Mozambican escudos1.00",
4326 "Mozambican metical1.00",
4327 "Mozambican meticals1.00",
4330 "Myanmar kyats1.00",
4343 "Namibian Dollar1.00",
4344 "Namibian dollar1.00",
4345 "Namibian dollars1.00",
4346 "Nepalese Rupee1.00",
4347 "Nepalese rupee1.00",
4348 "Nepalese rupees1.00",
4349 "Netherlands Antillean Guilder1.00",
4350 "Netherlands Antillean guilder1.00",
4351 "Netherlands Antillean guilders1.00",
4352 "Dutch Guilder1.00",
4353 "Dutch guilder1.00",
4354 "Dutch guilders1.00",
4355 "Israeli New Sheqel1.00",
4356 "Israeli New Sheqels1.00",
4357 "New Zealand Dollar1.00",
4358 "New Zealand dollar1.00",
4359 "New Zealand dollars1.00",
4360 "Nicaraguan C\\u00f3rdoba1.00",
4361 "Nicaraguan C\\u00f3rdoba (1988\\u20131991)1.00",
4362 "Nicaraguan c\\u00f3rdoba1.00",
4363 "Nicaraguan c\\u00f3rdobas1.00",
4364 "Nicaraguan c\\u00f3rdoba (1988\\u20131991)1.00",
4365 "Nicaraguan c\\u00f3rdobas (1988\\u20131991)1.00",
4366 "Nigerian Naira1.00",
4367 "Nigerian naira1.00",
4368 "Nigerian nairas1.00",
4369 "North Korean Won1.00",
4370 "North Korean won1.00",
4371 "North Korean won1.00",
4372 "Norwegian Krone1.00",
4373 "Norwegian krone1.00",
4374 "Norwegian kroner1.00",
4376 "Mozambican Metical (1980\\u20132006)1.00",
4377 "Mozambican metical (1980\\u20132006)1.00",
4378 "Mozambican meticals (1980\\u20132006)1.00",
4379 "Romanian Lei (1952\\u20132006)1.00",
4380 "Romanian Leu (1952\\u20132006)1.00",
4381 "Romanian leu (1952\\u20132006)1.00",
4382 "Serbian Dinar (2002\\u20132006)1.00",
4383 "Serbian dinar (2002\\u20132006)1.00",
4384 "Serbian dinars (2002\\u20132006)1.00",
4385 "Sudanese Dinar (1992\\u20132007)1.00",
4386 "Sudanese Pound (1957\\u20131998)1.00",
4387 "Sudanese dinar (1992\\u20132007)1.00",
4388 "Sudanese dinars (1992\\u20132007)1.00",
4389 "Sudanese pound (1957\\u20131998)1.00",
4390 "Sudanese pounds (1957\\u20131998)1.00",
4391 "Turkish Lira (1922\\u20132005)1.00",
4392 "Turkish Lira (1922\\u20132005)1.00",
4414 "Pakistani Rupee1.00",
4415 "Pakistani rupee1.00",
4416 "Pakistani rupees1.00",
4419 "Panamanian Balboa1.00",
4420 "Panamanian balboa1.00",
4421 "Panamanian balboas1.00",
4422 "Papua New Guinean Kina1.00",
4423 "Papua New Guinean kina1.00",
4424 "Papua New Guinean kina1.00",
4425 "Paraguayan Guarani1.00",
4426 "Paraguayan guarani1.00",
4427 "Paraguayan guaranis1.00",
4428 "Peruvian Inti1.00",
4429 "Peruvian Nuevo Sol1.00",
4430 "Peruvian Sol (1863\\u20131965)1.00",
4431 "Peruvian inti1.00",
4432 "Peruvian intis1.00",
4433 "Peruvian nuevo sol1.00",
4434 "Peruvian nuevos soles1.00",
4435 "Peruvian sol (1863\\u20131965)1.00",
4436 "Peruvian soles (1863\\u20131965)1.00",
4437 "Philippine Peso1.00",
4438 "Philippine peso1.00",
4439 "Philippine pesos1.00",
4442 "Polish Zloty (1950\\u20131995)1.00",
4444 "Polish zlotys1.00",
4445 "Polish zloty (PLZ)1.00",
4447 "Polish zlotys (PLZ)1.00",
4448 "Portuguese Escudo1.00",
4449 "Portuguese Guinea Escudo1.00",
4450 "Portuguese Guinea escudo1.00",
4451 "Portuguese Guinea escudos1.00",
4452 "Portuguese escudo1.00",
4453 "Portuguese escudos1.00",
4476 "Rhodesian Dollar1.00",
4477 "Rhodesian dollar1.00",
4478 "Rhodesian dollars1.00",
4482 "Russian Ruble (1991\\u20131998)1.00",
4483 "Russian Ruble1.00",
4484 "Russian ruble (1991\\u20131998)1.00",
4485 "Russian ruble1.00",
4486 "Russian rubles (1991\\u20131998)1.00",
4487 "Russian rubles1.00",
4488 "Rwandan Franc1.00",
4489 "Rwandan franc1.00",
4490 "Rwandan francs1.00",
4520 "St. Helena Pound1.00",
4521 "St. Helena pound1.00",
4522 "St. Helena pounds1.00",
4523 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra1.00",
4524 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra1.00",
4525 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras1.00",
4529 "Serbian Dinar1.00",
4530 "Serbian dinar1.00",
4531 "Serbian dinars1.00",
4532 "Seychellois Rupee1.00",
4533 "Seychellois rupee1.00",
4534 "Seychellois rupees1.00",
4535 "Sierra Leonean Leone1.00",
4536 "Sierra Leonean leone1.00",
4537 "Sierra Leonean leones1.00",
4540 "Singapore Dollar1.00",
4541 "Singapore dollar1.00",
4542 "Singapore dollars1.00",
4543 "Slovak Koruna1.00",
4544 "Slovak koruna1.00",
4545 "Slovak korunas1.00",
4546 "Slovenian Tolar1.00",
4547 "Slovenian tolar1.00",
4548 "Slovenian tolars1.00",
4549 "Solomon Islands Dollar1.00",
4550 "Solomon Islands dollar1.00",
4551 "Solomon Islands dollars1.00",
4552 "Somali Shilling1.00",
4553 "Somali shilling1.00",
4554 "Somali shillings1.00",
4555 "South African Rand (financial)1.00",
4556 "South African Rand1.00",
4557 "South African rand (financial)1.00",
4558 "South African rand1.00",
4559 "South African rands (financial)1.00",
4560 "South African rand1.00",
4561 "South Korean Won1.00",
4562 "South Korean won1.00",
4563 "South Korean won1.00",
4564 "Soviet Rouble1.00",
4565 "Soviet rouble1.00",
4566 "Soviet roubles1.00",
4567 "Spanish Peseta (A account)1.00",
4568 "Spanish Peseta (convertible account)1.00",
4569 "Spanish Peseta1.00",
4570 "Spanish peseta (A account)1.00",
4571 "Spanish peseta (convertible account)1.00",
4572 "Spanish peseta1.00",
4573 "Spanish pesetas (A account)1.00",
4574 "Spanish pesetas (convertible account)1.00",
4575 "Spanish pesetas1.00",
4576 "Special Drawing Rights1.00",
4577 "Sri Lankan Rupee1.00",
4578 "Sri Lankan rupee1.00",
4579 "Sri Lankan rupees1.00",
4580 "Sudanese Pound1.00",
4581 "Sudanese pound1.00",
4582 "Sudanese pounds1.00",
4583 "Surinamese Dollar1.00",
4584 "Surinamese dollar1.00",
4585 "Surinamese dollars1.00",
4586 "Surinamese Guilder1.00",
4587 "Surinamese guilder1.00",
4588 "Surinamese guilders1.00",
4589 "Swazi Lilangeni1.00",
4590 "Swazi lilangeni1.00",
4591 "Swazi emalangeni1.00",
4592 "Swedish Krona1.00",
4593 "Swedish krona1.00",
4594 "Swedish kronor1.00",
4600 "Syrian pounds1.00",
4619 "New Taiwan Dollar1.00",
4620 "New Taiwan dollar1.00",
4621 "New Taiwan dollars1.00",
4622 "Tajikistani Ruble1.00",
4623 "Tajikistani Somoni1.00",
4624 "Tajikistani ruble1.00",
4625 "Tajikistani rubles1.00",
4626 "Tajikistani somoni1.00",
4627 "Tajikistani somonis1.00",
4628 "Tanzanian Shilling1.00",
4629 "Tanzanian shilling1.00",
4630 "Tanzanian shillings1.00",
4631 "Testing Currency Code1.00",
4632 "Testing Currency Code1.00",
4636 "Timorese Escudo1.00",
4637 "Timorese escudo1.00",
4638 "Timorese escudos1.00",
4639 "Tongan Pa\\u02bbanga1.00",
4640 "Tongan pa\\u02bbanga1.00",
4641 "Tongan pa\\u02bbanga1.00",
4642 "Trinidad & Tobago Dollar1.00",
4643 "Trinidad & Tobago dollar1.00",
4644 "Trinidad & Tobago dollars1.00",
4645 "Tunisian Dinar1.00",
4646 "Tunisian dinar1.00",
4647 "Tunisian dinars1.00",
4651 "Turkmenistani Manat1.00",
4652 "Turkmenistani manat1.00",
4653 "Turkmenistani manat1.00",
4662 "US Dollar (Next day)1.00",
4663 "US Dollar (Same day)1.00",
4665 "US dollar (next day)1.00",
4666 "US dollar (same day)1.00",
4668 "US dollars (next day)1.00",
4669 "US dollars (same day)1.00",
4683 "Ugandan Shilling (1966\\u20131987)1.00",
4684 "Ugandan Shilling1.00",
4685 "Ugandan shilling (1966\\u20131987)1.00",
4686 "Ugandan shilling1.00",
4687 "Ugandan shillings (1966\\u20131987)1.00",
4688 "Ugandan shillings1.00",
4689 "Ukrainian Hryvnia1.00",
4690 "Ukrainian Karbovanets1.00",
4691 "Ukrainian hryvnia1.00",
4692 "Ukrainian hryvnias1.00",
4693 "Ukrainian karbovanets1.00",
4694 "Ukrainian karbovantsiv1.00",
4695 "Colombian Real Value Unit1.00",
4696 "United Arab Emirates Dirham1.00",
4697 "Unknown Currency1.00",
4698 "Uruguayan Peso (1975\\u20131993)1.00",
4699 "Uruguayan Peso1.00",
4700 "Uruguayan Peso (Indexed Units)1.00",
4701 "Uruguayan peso (1975\\u20131993)1.00",
4702 "Uruguayan peso (indexed units)1.00",
4703 "Uruguayan peso1.00",
4704 "Uruguayan pesos (1975\\u20131993)1.00",
4705 "Uruguayan pesos (indexed units)1.00",
4706 "Uruguayan pesos1.00",
4707 "Uzbekistani Som1.00",
4708 "Uzbekistani som1.00",
4709 "Uzbekistani som1.00",
4716 "Vanuatu vatus1.00",
4717 "Venezuelan Bol\\u00edvar1.00",
4718 "Venezuelan Bol\\u00edvar (1871\\u20132008)1.00",
4719 "Venezuelan bol\\u00edvar1.00",
4720 "Venezuelan bol\\u00edvars1.00",
4721 "Venezuelan bol\\u00edvar (1871\\u20132008)1.00",
4722 "Venezuelan bol\\u00edvars (1871\\u20132008)1.00",
4723 "Vietnamese Dong1.00",
4724 "Vietnamese dong1.00",
4725 "Vietnamese dong1.00",
4785 "Yemeni dinars1.00",
4788 "Yugoslavian Convertible Dinar (1990\\u20131992)1.00",
4789 "Yugoslavian Hard Dinar (1966\\u20131990)1.00",
4790 "Yugoslavian New Dinar (1994\\u20132002)1.00",
4791 "Yugoslavian convertible dinar (1990\\u20131992)1.00",
4792 "Yugoslavian convertible dinars (1990\\u20131992)1.00",
4793 "Yugoslavian hard dinar (1966\\u20131990)1.00",
4794 "Yugoslavian hard dinars (1966\\u20131990)1.00",
4795 "Yugoslavian new dinar (1994\\u20132002)1.00",
4796 "Yugoslavian new dinars (1994\\u20132002)1.00",
4807 "Zairean New Zaire (1993\\u20131998)1.00",
4808 "Zairean Zaire (1971\\u20131993)1.00",
4809 "Zairean new zaire (1993\\u20131998)1.00",
4810 "Zairean new zaires (1993\\u20131998)1.00",
4811 "Zairean zaire (1971\\u20131993)1.00",
4812 "Zairean zaires (1971\\u20131993)1.00",
4813 "Zambian Kwacha1.00",
4814 "Zambian kwacha1.00",
4815 "Zambian kwachas1.00",
4816 "Zimbabwean Dollar (1980\\u20132008)1.00",
4817 "Zimbabwean dollar (1980\\u20132008)1.00",
4818 "Zimbabwean dollars (1980\\u20132008)1.00",
4821 "Turkish lira (1922\\u20132005)1.00",
4822 "special drawing rights1.00",
4823 "Colombian real value unit1.00",
4824 "Colombian real value units1.00",
4825 "unknown currency1.00",
4833 // Following has extra text, should be parsed correctly too
4836 "1.00 US dollar random",
4837 "1.00 US dollars random",
4838 "1.00 Afghan Afghani random",
4839 "1.00 Afghan Afghani random",
4840 "1.00 Afghan Afghanis (1927\\u20131992) random",
4841 "1.00 Afghan Afghanis random",
4842 "1.00 Albanian Lek random",
4843 "1.00 Albanian lek random",
4844 "1.00 Albanian lek\\u00eb random",
4845 "1.00 Algerian Dinar random",
4846 "1.00 Algerian dinar random",
4847 "1.00 Algerian dinars random",
4848 "1.00 Andorran Peseta random",
4849 "1.00 Andorran peseta random",
4850 "1.00 Andorran pesetas random",
4851 "1.00 Angolan Kwanza (1977\\u20131990) random",
4852 "1.00 Angolan Readjusted Kwanza (1995\\u20131999) random",
4853 "1.00 Angolan Kwanza random",
4854 "1.00 Angolan New Kwanza (1990\\u20132000) random",
4855 "1.00 Angolan kwanza (1977\\u20131991) random",
4856 "1.00 Angolan readjusted kwanza (1995\\u20131999) random",
4857 "1.00 Angolan kwanza random",
4858 "1.00 Angolan kwanzas (1977\\u20131991) random",
4859 "1.00 Angolan readjusted kwanzas (1995\\u20131999) random",
4860 "1.00 Angolan kwanzas random",
4861 "1.00 Angolan new kwanza (1990\\u20132000) random",
4862 "1.00 Angolan new kwanzas (1990\\u20132000) random",
4863 "1.00 Argentine Austral random",
4864 "1.00 Argentine Peso (1983\\u20131985) random",
4865 "1.00 Argentine Peso random",
4866 "1.00 Argentine austral random",
4867 "1.00 Argentine australs random",
4868 "1.00 Argentine peso (1983\\u20131985) random",
4869 "1.00 Argentine peso random",
4870 "1.00 Argentine pesos (1983\\u20131985) random",
4871 "1.00 Argentine pesos random",
4872 "1.00 Armenian Dram random",
4873 "1.00 Armenian dram random",
4874 "1.00 Armenian drams random",
4875 "1.00 Aruban Florin random",
4876 "1.00 Aruban florin random",
4877 "1.00 Australian Dollar random",
4878 "1.00 Australian dollar random",
4879 "1.00 Australian dollars random",
4880 "1.00 Austrian Schilling random",
4881 "1.00 Austrian schilling random",
4882 "1.00 Austrian schillings random",
4883 "1.00 Azerbaijani Manat (1993\\u20132006) random",
4884 "1.00 Azerbaijani Manat random",
4885 "1.00 Azerbaijani manat (1993\\u20132006) random",
4886 "1.00 Azerbaijani manat random",
4887 "1.00 Azerbaijani manats (1993\\u20132006) random",
4888 "1.00 Azerbaijani manats random",
4889 "1.00 Bahamian Dollar random",
4890 "1.00 Bahamian dollar random",
4891 "1.00 Bahamian dollars random",
4892 "1.00 Bahraini Dinar random",
4893 "1.00 Bahraini dinar random",
4894 "1.00 Bahraini dinars random",
4895 "1.00 Bangladeshi Taka random",
4896 "1.00 Bangladeshi taka random",
4897 "1.00 Bangladeshi takas random",
4898 "1.00 Barbadian Dollar random",
4899 "1.00 Barbadian dollar random",
4900 "1.00 Barbadian dollars random",
4901 "1.00 Belarusian New Ruble (1994\\u20131999) random",
4902 "1.00 Belarusian Ruble random",
4903 "1.00 Belarusian new ruble (1994\\u20131999) random",
4904 "1.00 Belarusian new rubles (1994\\u20131999) random",
4905 "1.00 Belarusian ruble random",
4906 "1.00 Belarusian rubles random",
4907 "1.00 Belgian Franc (convertible) random",
4908 "1.00 Belgian Franc (financial) random",
4909 "1.00 Belgian Franc random",
4910 "1.00 Belgian franc (convertible) random",
4911 "1.00 Belgian franc (financial) random",
4912 "1.00 Belgian franc random",
4913 "1.00 Belgian francs (convertible) random",
4914 "1.00 Belgian francs (financial) random",
4915 "1.00 Belgian francs random",
4916 "1.00 Belize Dollar random",
4917 "1.00 Belize dollar random",
4918 "1.00 Belize dollars random",
4919 "1.00 Bermudan Dollar random",
4920 "1.00 Bermudan dollar random",
4921 "1.00 Bermudan dollars random",
4922 "1.00 Bhutanese Ngultrum random",
4923 "1.00 Bhutanese ngultrum random",
4924 "1.00 Bhutanese ngultrums random",
4925 "1.00 Bolivian Mvdol random",
4926 "1.00 Bolivian Peso random",
4927 "1.00 Bolivian mvdol random",
4928 "1.00 Bolivian mvdols random",
4929 "1.00 Bolivian peso random",
4930 "1.00 Bolivian pesos random",
4931 "1.00 Bolivian Boliviano random",
4932 "1.00 Bolivian Boliviano random",
4933 "1.00 Bolivian Bolivianos random",
4934 "1.00 Bosnia-Herzegovina Convertible Mark random",
4935 "1.00 Bosnia-Herzegovina Dinar (1992\\u20131994) random",
4936 "1.00 Bosnia-Herzegovina convertible mark random",
4937 "1.00 Bosnia-Herzegovina convertible marks random",
4938 "1.00 Bosnia-Herzegovina dinar (1992\\u20131994) random",
4939 "1.00 Bosnia-Herzegovina dinars (1992\\u20131994) random",
4940 "1.00 Botswanan Pula random",
4941 "1.00 Botswanan pula random",
4942 "1.00 Botswanan pulas random",
4943 "1.00 Brazilian New Cruzado (1989\\u20131990) random",
4944 "1.00 Brazilian Cruzado (1986\\u20131989) random",
4945 "1.00 Brazilian Cruzeiro (1990\\u20131993) random",
4946 "1.00 Brazilian New Cruzeiro (1967\\u20131986) random",
4947 "1.00 Brazilian Cruzeiro (1993\\u20131994) random",
4948 "1.00 Brazilian Real random",
4949 "1.00 Brazilian new cruzado (1989\\u20131990) random",
4950 "1.00 Brazilian new cruzados (1989\\u20131990) random",
4951 "1.00 Brazilian cruzado (1986\\u20131989) random",
4952 "1.00 Brazilian cruzados (1986\\u20131989) random",
4953 "1.00 Brazilian cruzeiro (1990\\u20131993) random",
4954 "1.00 Brazilian new cruzeiro (1967\\u20131986) random",
4955 "1.00 Brazilian cruzeiro (1993\\u20131994) random",
4956 "1.00 Brazilian cruzeiros (1990\\u20131993) random",
4957 "1.00 Brazilian new cruzeiros (1967\\u20131986) random",
4958 "1.00 Brazilian cruzeiros (1993\\u20131994) random",
4959 "1.00 Brazilian real random",
4960 "1.00 Brazilian reals random",
4961 "1.00 British Pound random",
4962 "1.00 British pound random",
4963 "1.00 British pounds random",
4964 "1.00 Brunei Dollar random",
4965 "1.00 Brunei dollar random",
4966 "1.00 Brunei dollars random",
4967 "1.00 Bulgarian Hard Lev random",
4968 "1.00 Bulgarian Lev random",
4969 "1.00 Bulgarian Leva random",
4970 "1.00 Bulgarian hard lev random",
4971 "1.00 Bulgarian hard leva random",
4972 "1.00 Bulgarian lev random",
4973 "1.00 Burmese Kyat random",
4974 "1.00 Burmese kyat random",
4975 "1.00 Burmese kyats random",
4976 "1.00 Burundian Franc random",
4977 "1.00 Burundian franc random",
4978 "1.00 Burundian francs random",
4979 "1.00 Cambodian Riel random",
4980 "1.00 Cambodian riel random",
4981 "1.00 Cambodian riels random",
4982 "1.00 Canadian Dollar random",
4983 "1.00 Canadian dollar random",
4984 "1.00 Canadian dollars random",
4985 "1.00 Cape Verdean Escudo random",
4986 "1.00 Cape Verdean escudo random",
4987 "1.00 Cape Verdean escudos random",
4988 "1.00 Cayman Islands Dollar random",
4989 "1.00 Cayman Islands dollar random",
4990 "1.00 Cayman Islands dollars random",
4991 "1.00 Chilean Peso random",
4992 "1.00 Chilean Unit of Account (UF) random",
4993 "1.00 Chilean peso random",
4994 "1.00 Chilean pesos random",
4995 "1.00 Chilean unit of account (UF) random",
4996 "1.00 Chilean units of account (UF) random",
4997 "1.00 Chinese Yuan random",
4998 "1.00 Chinese yuan random",
4999 "1.00 Colombian Peso random",
5000 "1.00 Colombian peso random",
5001 "1.00 Colombian pesos random",
5002 "1.00 Comorian Franc random",
5003 "1.00 Comorian franc random",
5004 "1.00 Comorian francs random",
5005 "1.00 Congolese Franc Congolais random",
5006 "1.00 Congolese franc Congolais random",
5007 "1.00 Congolese francs Congolais random",
5008 "1.00 Costa Rican Col\\u00f3n random",
5009 "1.00 Costa Rican col\\u00f3n random",
5010 "1.00 Costa Rican col\\u00f3ns random",
5011 "1.00 Croatian Dinar random",
5012 "1.00 Croatian Kuna random",
5013 "1.00 Croatian dinar random",
5014 "1.00 Croatian dinars random",
5015 "1.00 Croatian kuna random",
5016 "1.00 Croatian kunas random",
5017 "1.00 Cuban Peso random",
5018 "1.00 Cuban peso random",
5019 "1.00 Cuban pesos random",
5020 "1.00 Cypriot Pound random",
5021 "1.00 Cypriot pound random",
5022 "1.00 Cypriot pounds random",
5023 "1.00 Czech Republic Koruna random",
5024 "1.00 Czech Republic koruna random",
5025 "1.00 Czech Republic korunas random",
5026 "1.00 Czechoslovak Hard Koruna random",
5027 "1.00 Czechoslovak hard koruna random",
5028 "1.00 Czechoslovak hard korunas random",
5029 "1.00 Danish Krone random",
5030 "1.00 Danish krone random",
5031 "1.00 Danish kroner random",
5032 "1.00 German Mark random",
5033 "1.00 German mark random",
5034 "1.00 German marks random",
5035 "1.00 Djiboutian Franc random",
5036 "1.00 Djiboutian franc random",
5037 "1.00 Djiboutian francs random",
5038 "1.00 Dominican Peso random",
5039 "1.00 Dominican peso random",
5040 "1.00 Dominican pesos random",
5041 "1.00 East Caribbean Dollar random",
5042 "1.00 East Caribbean dollar random",
5043 "1.00 East Caribbean dollars random",
5044 "1.00 East German Mark random",
5045 "1.00 East German mark random",
5046 "1.00 East German marks random",
5047 "1.00 Ecuadorian Sucre random",
5048 "1.00 Ecuadorian Unit of Constant Value random",
5049 "1.00 Ecuadorian sucre random",
5050 "1.00 Ecuadorian sucres random",
5051 "1.00 Ecuadorian unit of constant value random",
5052 "1.00 Ecuadorian units of constant value random",
5053 "1.00 Egyptian Pound random",
5054 "1.00 Egyptian pound random",
5055 "1.00 Egyptian pounds random",
5056 "1.00 Salvadoran Col\\u00f3n random",
5057 "1.00 Salvadoran col\\u00f3n random",
5058 "1.00 Salvadoran colones random",
5059 "1.00 Equatorial Guinean Ekwele random",
5060 "1.00 Equatorial Guinean ekwele random",
5061 "1.00 Eritrean Nakfa random",
5062 "1.00 Eritrean nakfa random",
5063 "1.00 Eritrean nakfas random",
5064 "1.00 Estonian Kroon random",
5065 "1.00 Estonian kroon random",
5066 "1.00 Estonian kroons random",
5067 "1.00 Ethiopian Birr random",
5068 "1.00 Ethiopian birr random",
5069 "1.00 Ethiopian birrs random",
5070 "1.00 European Composite Unit random",
5071 "1.00 European Currency Unit random",
5072 "1.00 European Monetary Unit random",
5073 "1.00 European Unit of Account (XBC) random",
5074 "1.00 European Unit of Account (XBD) random",
5075 "1.00 European composite unit random",
5076 "1.00 European composite units random",
5077 "1.00 European currency unit random",
5078 "1.00 European currency units random",
5079 "1.00 European monetary unit random",
5080 "1.00 European monetary units random",
5081 "1.00 European unit of account (XBC) random",
5082 "1.00 European unit of account (XBD) random",
5083 "1.00 European units of account (XBC) random",
5084 "1.00 European units of account (XBD) random",
5085 "1.00 Falkland Islands Pound random",
5086 "1.00 Falkland Islands pound random",
5087 "1.00 Falkland Islands pounds random",
5088 "1.00 Fijian Dollar random",
5089 "1.00 Fijian dollar random",
5090 "1.00 Fijian dollars random",
5091 "1.00 Finnish Markka random",
5092 "1.00 Finnish markka random",
5093 "1.00 Finnish markkas random",
5094 "1.00 French Franc random",
5095 "1.00 French Gold Franc random",
5096 "1.00 French UIC-Franc random",
5097 "1.00 French UIC-franc random",
5098 "1.00 French UIC-francs random",
5099 "1.00 French franc random",
5100 "1.00 French francs random",
5101 "1.00 French gold franc random",
5102 "1.00 French gold francs random",
5103 "1.00 Gambian Dalasi random",
5104 "1.00 Gambian dalasi random",
5105 "1.00 Gambian dalasis random",
5106 "1.00 Georgian Kupon Larit random",
5107 "1.00 Georgian Lari random",
5108 "1.00 Georgian kupon larit random",
5109 "1.00 Georgian kupon larits random",
5110 "1.00 Georgian lari random",
5111 "1.00 Georgian laris random",
5112 "1.00 Ghanaian Cedi (1979\\u20132007) random",
5113 "1.00 Ghanaian Cedi random",
5114 "1.00 Ghanaian cedi (1979\\u20132007) random",
5115 "1.00 Ghanaian cedi random",
5116 "1.00 Ghanaian cedis (1979\\u20132007) random",
5117 "1.00 Ghanaian cedis random",
5118 "1.00 Gibraltar Pound random",
5119 "1.00 Gibraltar pound random",
5120 "1.00 Gibraltar pounds random",
5123 "1.00 Greek Drachma random",
5124 "1.00 Greek drachma random",
5125 "1.00 Greek drachmas random",
5126 "1.00 Guatemalan Quetzal random",
5127 "1.00 Guatemalan quetzal random",
5128 "1.00 Guatemalan quetzals random",
5129 "1.00 Guinean Franc random",
5130 "1.00 Guinean Syli random",
5131 "1.00 Guinean franc random",
5132 "1.00 Guinean francs random",
5133 "1.00 Guinean syli random",
5134 "1.00 Guinean sylis random",
5135 "1.00 Guinea-Bissau Peso random",
5136 "1.00 Guinea-Bissau peso random",
5137 "1.00 Guinea-Bissau pesos random",
5138 "1.00 Guyanaese Dollar random",
5139 "1.00 Guyanaese dollar random",
5140 "1.00 Guyanaese dollars random",
5141 "1.00 Haitian Gourde random",
5142 "1.00 Haitian gourde random",
5143 "1.00 Haitian gourdes random",
5144 "1.00 Honduran Lempira random",
5145 "1.00 Honduran lempira random",
5146 "1.00 Honduran lempiras random",
5147 "1.00 Hong Kong Dollar random",
5148 "1.00 Hong Kong dollar random",
5149 "1.00 Hong Kong dollars random",
5150 "1.00 Hungarian Forint random",
5151 "1.00 Hungarian forint random",
5152 "1.00 Hungarian forints random",
5153 "1.00 Icelandic Kr\\u00f3na random",
5154 "1.00 Icelandic kr\\u00f3na random",
5155 "1.00 Icelandic kr\\u00f3nur random",
5156 "1.00 Indian Rupee random",
5157 "1.00 Indian rupee random",
5158 "1.00 Indian rupees random",
5159 "1.00 Indonesian Rupiah random",
5160 "1.00 Indonesian rupiah random",
5161 "1.00 Indonesian rupiahs random",
5162 "1.00 Iranian Rial random",
5163 "1.00 Iranian rial random",
5164 "1.00 Iranian rials random",
5165 "1.00 Iraqi Dinar random",
5166 "1.00 Iraqi dinar random",
5167 "1.00 Iraqi dinars random",
5168 "1.00 Irish Pound random",
5169 "1.00 Irish pound random",
5170 "1.00 Irish pounds random",
5171 "1.00 Israeli Pound random",
5172 "1.00 Israeli new sheqel random",
5173 "1.00 Israeli pound random",
5174 "1.00 Israeli pounds random",
5175 "1.00 Italian Lira random",
5176 "1.00 Italian lira random",
5177 "1.00 Italian liras random",
5178 "1.00 Jamaican Dollar random",
5179 "1.00 Jamaican dollar random",
5180 "1.00 Jamaican dollars random",
5181 "1.00 Japanese Yen random",
5182 "1.00 Japanese yen random",
5183 "1.00 Jordanian Dinar random",
5184 "1.00 Jordanian dinar random",
5185 "1.00 Jordanian dinars random",
5186 "1.00 Kazakhstani Tenge random",
5187 "1.00 Kazakhstani tenge random",
5188 "1.00 Kazakhstani tenges random",
5189 "1.00 Kenyan Shilling random",
5190 "1.00 Kenyan shilling random",
5191 "1.00 Kenyan shillings random",
5192 "1.00 Kuwaiti Dinar random",
5193 "1.00 Kuwaiti dinar random",
5194 "1.00 Kuwaiti dinars random",
5195 "1.00 Kyrgystani Som random",
5196 "1.00 Kyrgystani som random",
5197 "1.00 Kyrgystani soms random",
5198 "1.00 Laotian Kip random",
5199 "1.00 Laotian kip random",
5200 "1.00 Laotian kips random",
5201 "1.00 Latvian Lats random",
5202 "1.00 Latvian Ruble random",
5203 "1.00 Latvian lats random",
5204 "1.00 Latvian lati random",
5205 "1.00 Latvian ruble random",
5206 "1.00 Latvian rubles random",
5207 "1.00 Lebanese Pound random",
5208 "1.00 Lebanese pound random",
5209 "1.00 Lebanese pounds random",
5210 "1.00 Lesotho Loti random",
5211 "1.00 Lesotho loti random",
5212 "1.00 Lesotho lotis random",
5213 "1.00 Liberian Dollar random",
5214 "1.00 Liberian dollar random",
5215 "1.00 Liberian dollars random",
5216 "1.00 Libyan Dinar random",
5217 "1.00 Libyan dinar random",
5218 "1.00 Libyan dinars random",
5219 "1.00 Lithuanian Litas random",
5220 "1.00 Lithuanian Talonas random",
5221 "1.00 Lithuanian litas random",
5222 "1.00 Lithuanian litai random",
5223 "1.00 Lithuanian talonas random",
5224 "1.00 Lithuanian talonases random",
5225 "1.00 Luxembourgian Convertible Franc random",
5226 "1.00 Luxembourg Financial Franc random",
5227 "1.00 Luxembourgian Franc random",
5228 "1.00 Luxembourgian convertible franc random",
5229 "1.00 Luxembourgian convertible francs random",
5230 "1.00 Luxembourg financial franc random",
5231 "1.00 Luxembourg financial francs random",
5232 "1.00 Luxembourgian franc random",
5233 "1.00 Luxembourgian francs random",
5234 "1.00 Macanese Pataca random",
5235 "1.00 Macanese pataca random",
5236 "1.00 Macanese patacas random",
5237 "1.00 Macedonian Denar random",
5238 "1.00 Macedonian denar random",
5239 "1.00 Macedonian denari random",
5240 "1.00 Malagasy Ariaries random",
5241 "1.00 Malagasy Ariary random",
5242 "1.00 Malagasy Ariary random",
5243 "1.00 Malagasy Franc random",
5244 "1.00 Malagasy franc random",
5245 "1.00 Malagasy francs random",
5246 "1.00 Malawian Kwacha random",
5247 "1.00 Malawian Kwacha random",
5248 "1.00 Malawian Kwachas random",
5249 "1.00 Malaysian Ringgit random",
5250 "1.00 Malaysian ringgit random",
5251 "1.00 Malaysian ringgits random",
5252 "1.00 Maldivian Rufiyaa random",
5253 "1.00 Maldivian rufiyaa random",
5254 "1.00 Maldivian rufiyaas random",
5255 "1.00 Malian Franc random",
5256 "1.00 Malian franc random",
5257 "1.00 Malian francs random",
5258 "1.00 Maltese Lira random",
5259 "1.00 Maltese Pound random",
5260 "1.00 Maltese lira random",
5261 "1.00 Maltese liras random",
5262 "1.00 Maltese pound random",
5263 "1.00 Maltese pounds random",
5264 "1.00 Mauritanian Ouguiya random",
5265 "1.00 Mauritanian ouguiya random",
5266 "1.00 Mauritanian ouguiyas random",
5267 "1.00 Mauritian Rupee random",
5268 "1.00 Mauritian rupee random",
5269 "1.00 Mauritian rupees random",
5270 "1.00 Mexican Peso random",
5271 "1.00 Mexican Silver Peso (1861\\u20131992) random",
5272 "1.00 Mexican Investment Unit random",
5273 "1.00 Mexican peso random",
5274 "1.00 Mexican pesos random",
5275 "1.00 Mexican silver peso (1861\\u20131992) random",
5276 "1.00 Mexican silver pesos (1861\\u20131992) random",
5277 "1.00 Mexican investment unit random",
5278 "1.00 Mexican investment units random",
5279 "1.00 Moldovan Leu random",
5280 "1.00 Moldovan leu random",
5281 "1.00 Moldovan lei random",
5282 "1.00 Mongolian Tugrik random",
5283 "1.00 Mongolian tugrik random",
5284 "1.00 Mongolian tugriks random",
5285 "1.00 Moroccan Dirham random",
5286 "1.00 Moroccan Franc random",
5287 "1.00 Moroccan dirham random",
5288 "1.00 Moroccan dirhams random",
5289 "1.00 Moroccan franc random",
5290 "1.00 Moroccan francs random",
5291 "1.00 Mozambican Escudo random",
5292 "1.00 Mozambican Metical random",
5293 "1.00 Mozambican escudo random",
5294 "1.00 Mozambican escudos random",
5295 "1.00 Mozambican metical random",
5296 "1.00 Mozambican meticals random",
5297 "1.00 Myanmar Kyat random",
5298 "1.00 Myanmar kyat random",
5299 "1.00 Myanmar kyats random",
5300 "1.00 Namibian Dollar random",
5301 "1.00 Namibian dollar random",
5302 "1.00 Namibian dollars random",
5303 "1.00 Nepalese Rupee random",
5304 "1.00 Nepalese rupee random",
5305 "1.00 Nepalese rupees random",
5306 "1.00 Netherlands Antillean Guilder random",
5307 "1.00 Netherlands Antillean guilder random",
5308 "1.00 Netherlands Antillean guilders random",
5309 "1.00 Dutch Guilder random",
5310 "1.00 Dutch guilder random",
5311 "1.00 Dutch guilders random",
5312 "1.00 Israeli New Sheqel random",
5313 "1.00 Israeli new sheqels random",
5314 "1.00 New Zealand Dollar random",
5315 "1.00 New Zealand dollar random",
5316 "1.00 New Zealand dollars random",
5317 "1.00 Nicaraguan C\\u00f3rdoba random",
5318 "1.00 Nicaraguan C\\u00f3rdoba (1988\\u20131991) random",
5319 "1.00 Nicaraguan c\\u00f3rdoba random",
5320 "1.00 Nicaraguan c\\u00f3rdoba random",
5321 "1.00 Nicaraguan c\\u00f3rdoba (1988\\u20131991) random",
5322 "1.00 Nicaraguan c\\u00f3rdobas (1988\\u20131991) random",
5323 "1.00 Nigerian Naira random",
5324 "1.00 Nigerian naira random",
5325 "1.00 Nigerian nairas random",
5326 "1.00 North Korean Won random",
5327 "1.00 North Korean won random",
5328 "1.00 North Korean won random",
5329 "1.00 Norwegian Krone random",
5330 "1.00 Norwegian krone random",
5331 "1.00 Norwegian kroner random",
5332 "1.00 Mozambican Metical (1980\\u20132006) random",
5333 "1.00 Mozambican metical (1980\\u20132006) random",
5334 "1.00 Mozambican meticals (1980\\u20132006) random",
5335 "1.00 Romanian Lei (1952\\u20132006) random",
5336 "1.00 Romanian Leu (1952\\u20132006) random",
5337 "1.00 Romanian leu (1952\\u20132006) random",
5338 "1.00 Serbian Dinar (2002\\u20132006) random",
5339 "1.00 Serbian dinar (2002\\u20132006) random",
5340 "1.00 Serbian dinars (2002\\u20132006) random",
5341 "1.00 Sudanese Dinar (1992\\u20132007) random",
5342 "1.00 Sudanese Pound (1957\\u20131998) random",
5343 "1.00 Sudanese dinar (1992\\u20132007) random",
5344 "1.00 Sudanese dinars (1992\\u20132007) random",
5345 "1.00 Sudanese pound (1957\\u20131998) random",
5346 "1.00 Sudanese pounds (1957\\u20131998) random",
5347 "1.00 Turkish Lira (1922\\u20132005) random",
5348 "1.00 Turkish Lira (1922\\u20132005) random",
5349 "1.00 Omani Rial random",
5350 "1.00 Omani rial random",
5351 "1.00 Omani rials random",
5352 "1.00 Pakistani Rupee random",
5353 "1.00 Pakistani rupee random",
5354 "1.00 Pakistani rupees random",
5355 "1.00 Palladium random",
5356 "1.00 Palladium random",
5357 "1.00 Panamanian Balboa random",
5358 "1.00 Panamanian balboa random",
5359 "1.00 Panamanian balboas random",
5360 "1.00 Papua New Guinean Kina random",
5361 "1.00 Papua New Guinean kina random",
5362 "1.00 Papua New Guinean kina random",
5363 "1.00 Paraguayan Guarani random",
5364 "1.00 Paraguayan guarani random",
5365 "1.00 Paraguayan guaranis random",
5366 "1.00 Peruvian Inti random",
5367 "1.00 Peruvian Nuevo Sol random",
5368 "1.00 Peruvian Sol (1863\\u20131965) random",
5369 "1.00 Peruvian inti random",
5370 "1.00 Peruvian intis random",
5371 "1.00 Peruvian nuevo sol random",
5372 "1.00 Peruvian nuevos soles random",
5373 "1.00 Peruvian sol (1863\\u20131965) random",
5374 "1.00 Peruvian soles (1863\\u20131965) random",
5375 "1.00 Philippine Peso random",
5376 "1.00 Philippine peso random",
5377 "1.00 Philippine pesos random",
5378 "1.00 Platinum random",
5379 "1.00 Platinum random",
5380 "1.00 Polish Zloty (1950\\u20131995) random",
5381 "1.00 Polish Zloty random",
5382 "1.00 Polish zlotys random",
5383 "1.00 Polish zloty (PLZ) random",
5384 "1.00 Polish zloty random",
5385 "1.00 Polish zlotys (PLZ) random",
5386 "1.00 Portuguese Escudo random",
5387 "1.00 Portuguese Guinea Escudo random",
5388 "1.00 Portuguese Guinea escudo random",
5389 "1.00 Portuguese Guinea escudos random",
5390 "1.00 Portuguese escudo random",
5391 "1.00 Portuguese escudos random",
5392 "1.00 Qatari Rial random",
5393 "1.00 Qatari rial random",
5394 "1.00 Qatari rials random",
5395 "1.00 RINET Funds random",
5396 "1.00 RINET Funds random",
5397 "1.00 Rhodesian Dollar random",
5398 "1.00 Rhodesian dollar random",
5399 "1.00 Rhodesian dollars random",
5400 "1.00 Romanian Leu random",
5401 "1.00 Romanian lei random",
5402 "1.00 Romanian leu random",
5403 "1.00 Russian Ruble (1991\\u20131998) random",
5404 "1.00 Russian Ruble random",
5405 "1.00 Russian ruble (1991\\u20131998) random",
5406 "1.00 Russian ruble random",
5407 "1.00 Russian rubles (1991\\u20131998) random",
5408 "1.00 Russian rubles random",
5409 "1.00 Rwandan Franc random",
5410 "1.00 Rwandan franc random",
5411 "1.00 Rwandan francs random",
5412 "1.00 St. Helena Pound random",
5413 "1.00 St. Helena pound random",
5414 "1.00 St. Helena pounds random",
5415 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra random",
5416 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra random",
5417 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras random",
5418 "1.00 Saudi Riyal random",
5419 "1.00 Saudi riyal random",
5420 "1.00 Saudi riyals random",
5421 "1.00 Serbian Dinar random",
5422 "1.00 Serbian dinar random",
5423 "1.00 Serbian dinars random",
5424 "1.00 Seychellois Rupee random",
5425 "1.00 Seychellois rupee random",
5426 "1.00 Seychellois rupees random",
5427 "1.00 Sierra Leonean Leone random",
5428 "1.00 Sierra Leonean leone random",
5429 "1.00 Sierra Leonean leones random",
5430 "1.00 Singapore Dollar random",
5431 "1.00 Singapore dollar random",
5432 "1.00 Singapore dollars random",
5433 "1.00 Slovak Koruna random",
5434 "1.00 Slovak koruna random",
5435 "1.00 Slovak korunas random",
5436 "1.00 Slovenian Tolar random",
5437 "1.00 Slovenian tolar random",
5438 "1.00 Slovenian tolars random",
5439 "1.00 Solomon Islands Dollar random",
5440 "1.00 Solomon Islands dollar random",
5441 "1.00 Solomon Islands dollars random",
5442 "1.00 Somali Shilling random",
5443 "1.00 Somali shilling random",
5444 "1.00 Somali shillings random",
5445 "1.00 South African Rand (financial) random",
5446 "1.00 South African Rand random",
5447 "1.00 South African rand (financial) random",
5448 "1.00 South African rand random",
5449 "1.00 South African rands (financial) random",
5450 "1.00 South African rand random",
5451 "1.00 South Korean Won random",
5452 "1.00 South Korean won random",
5453 "1.00 South Korean won random",
5454 "1.00 Soviet Rouble random",
5455 "1.00 Soviet rouble random",
5456 "1.00 Soviet roubles random",
5457 "1.00 Spanish Peseta (A account) random",
5458 "1.00 Spanish Peseta (convertible account) random",
5459 "1.00 Spanish Peseta random",
5460 "1.00 Spanish peseta (A account) random",
5461 "1.00 Spanish peseta (convertible account) random",
5462 "1.00 Spanish peseta random",
5463 "1.00 Spanish pesetas (A account) random",
5464 "1.00 Spanish pesetas (convertible account) random",
5465 "1.00 Spanish pesetas random",
5466 "1.00 Special Drawing Rights random",
5467 "1.00 Sri Lankan Rupee random",
5468 "1.00 Sri Lankan rupee random",
5469 "1.00 Sri Lankan rupees random",
5470 "1.00 Sudanese Pound random",
5471 "1.00 Sudanese pound random",
5472 "1.00 Sudanese pounds random",
5473 "1.00 Surinamese Dollar random",
5474 "1.00 Surinamese dollar random",
5475 "1.00 Surinamese dollars random",
5476 "1.00 Surinamese Guilder random",
5477 "1.00 Surinamese guilder random",
5478 "1.00 Surinamese guilders random",
5479 "1.00 Swazi Lilangeni random",
5480 "1.00 Swazi lilangeni random",
5481 "1.00 Swazi emalangeni random",
5482 "1.00 Swedish Krona random",
5483 "1.00 Swedish krona random",
5484 "1.00 Swedish kronor random",
5485 "1.00 Swiss Franc random",
5486 "1.00 Swiss franc random",
5487 "1.00 Swiss francs random",
5488 "1.00 Syrian Pound random",
5489 "1.00 Syrian pound random",
5490 "1.00 Syrian pounds random",
5491 "1.00 New Taiwan Dollar random",
5492 "1.00 New Taiwan dollar random",
5493 "1.00 New Taiwan dollars random",
5494 "1.00 Tajikistani Ruble random",
5495 "1.00 Tajikistani Somoni random",
5496 "1.00 Tajikistani ruble random",
5497 "1.00 Tajikistani rubles random",
5498 "1.00 Tajikistani somoni random",
5499 "1.00 Tajikistani somonis random",
5500 "1.00 Tanzanian Shilling random",
5501 "1.00 Tanzanian shilling random",
5502 "1.00 Tanzanian shillings random",
5503 "1.00 Testing Currency Code random",
5504 "1.00 Testing Currency Code random",
5505 "1.00 Thai Baht random",
5506 "1.00 Thai baht random",
5507 "1.00 Thai baht random",
5508 "1.00 Timorese Escudo random",
5509 "1.00 Timorese escudo random",
5510 "1.00 Timorese escudos random",
5511 "1.00 Trinidad & Tobago Dollar random",
5512 "1.00 Trinidad & Tobago dollar random",
5513 "1.00 Trinidad & Tobago dollars random",
5514 "1.00 Tunisian Dinar random",
5515 "1.00 Tunisian dinar random",
5516 "1.00 Tunisian dinars random",
5517 "1.00 Turkish Lira random",
5518 "1.00 Turkish Lira random",
5519 "1.00 Turkish lira random",
5520 "1.00 Turkmenistani Manat random",
5521 "1.00 Turkmenistani manat random",
5522 "1.00 Turkmenistani manat random",
5523 "1.00 US Dollar (Next day) random",
5524 "1.00 US Dollar (Same day) random",
5525 "1.00 US Dollar random",
5526 "1.00 US dollar (next day) random",
5527 "1.00 US dollar (same day) random",
5528 "1.00 US dollar random",
5529 "1.00 US dollars (next day) random",
5530 "1.00 US dollars (same day) random",
5531 "1.00 US dollars random",
5532 "1.00 Ugandan Shilling (1966\\u20131987) random",
5533 "1.00 Ugandan Shilling random",
5534 "1.00 Ugandan shilling (1966\\u20131987) random",
5535 "1.00 Ugandan shilling random",
5536 "1.00 Ugandan shillings (1966\\u20131987) random",
5537 "1.00 Ugandan shillings random",
5538 "1.00 Ukrainian Hryvnia random",
5539 "1.00 Ukrainian Karbovanets random",
5540 "1.00 Ukrainian hryvnia random",
5541 "1.00 Ukrainian hryvnias random",
5542 "1.00 Ukrainian karbovanets random",
5543 "1.00 Ukrainian karbovantsiv random",
5544 "1.00 Colombian Real Value Unit random",
5545 "1.00 United Arab Emirates Dirham random",
5546 "1.00 Unknown Currency random",
5547 "1.00 Uruguayan Peso (1975\\u20131993) random",
5548 "1.00 Uruguayan Peso random",
5549 "1.00 Uruguayan Peso (Indexed Units) random",
5550 "1.00 Uruguayan peso (1975\\u20131993) random",
5551 "1.00 Uruguayan peso (indexed units) random",
5552 "1.00 Uruguayan peso random",
5553 "1.00 Uruguayan pesos (1975\\u20131993) random",
5554 "1.00 Uruguayan pesos (indexed units) random",
5555 "1.00 Uzbekistani Som random",
5556 "1.00 Uzbekistani som random",
5557 "1.00 Uzbekistani som random",
5558 "1.00 Vanuatu Vatu random",
5559 "1.00 Vanuatu vatu random",
5560 "1.00 Vanuatu vatus random",
5561 "1.00 Venezuelan Bol\\u00edvar random",
5562 "1.00 Venezuelan Bol\\u00edvar (1871\\u20132008) random",
5563 "1.00 Venezuelan bol\\u00edvar random",
5564 "1.00 Venezuelan bol\\u00edvars random",
5565 "1.00 Venezuelan bol\\u00edvar (1871\\u20132008) random",
5566 "1.00 Venezuelan bol\\u00edvars (1871\\u20132008) random",
5567 "1.00 Vietnamese Dong random",
5568 "1.00 Vietnamese dong random",
5569 "1.00 Vietnamese dong random",
5570 "1.00 WIR Euro random",
5571 "1.00 WIR Franc random",
5572 "1.00 WIR euro random",
5573 "1.00 WIR euros random",
5574 "1.00 WIR franc random",
5575 "1.00 WIR francs random",
5576 "1.00 Samoan Tala random",
5577 "1.00 Samoan tala random",
5578 "1.00 Samoan tala random",
5579 "1.00 Yemeni Dinar random",
5580 "1.00 Yemeni Rial random",
5581 "1.00 Yemeni dinar random",
5582 "1.00 Yemeni dinars random",
5583 "1.00 Yemeni rial random",
5584 "1.00 Yemeni rials random",
5585 "1.00 Yugoslavian Convertible Dinar (1990\\u20131992) random",
5586 "1.00 Yugoslavian Hard Dinar (1966\\u20131990) random",
5587 "1.00 Yugoslavian New Dinar (1994\\u20132002) random",
5588 "1.00 Yugoslavian convertible dinar (1990\\u20131992) random",
5589 "1.00 Yugoslavian convertible dinars (1990\\u20131992) random",
5590 "1.00 Yugoslavian hard dinar (1966\\u20131990) random",
5591 "1.00 Yugoslavian hard dinars (1966\\u20131990) random",
5592 "1.00 Yugoslavian new dinar (1994\\u20132002) random",
5593 "1.00 Yugoslavian new dinars (1994\\u20132002) random",
5594 "1.00 Zairean New Zaire (1993\\u20131998) random",
5595 "1.00 Zairean Zaire (1971\\u20131993) random",
5596 "1.00 Zairean new zaire (1993\\u20131998) random",
5597 "1.00 Zairean new zaires (1993\\u20131998) random",
5598 "1.00 Zairean zaire (1971\\u20131993) random",
5599 "1.00 Zairean zaires (1971\\u20131993) random",
5600 "1.00 Zambian Kwacha random",
5601 "1.00 Zambian kwacha random",
5602 "1.00 Zambian kwachas random",
5603 "1.00 Zimbabwean Dollar (1980\\u20132008) random",
5604 "1.00 Zimbabwean dollar (1980\\u20132008) random",
5605 "1.00 Zimbabwean dollars (1980\\u20132008) random",
5607 "1.00 euros random",
5608 "1.00 Turkish lira (1922\\u20132005) random",
5609 "1.00 special drawing rights random",
5610 "1.00 Colombian real value unit random",
5611 "1.00 Colombian real value units random",
5612 "1.00 unknown currency random",
5615 const char* WRONG_DATA
[] = {
5616 // Following are missing one last char in the currency name
5617 "usd1.00", // case sensitive
5618 "1.00 Nicaraguan Cordob",
5619 "1.00 Namibian Dolla",
5620 "1.00 Namibian dolla",
5621 "1.00 Nepalese Rupe",
5622 "1.00 Nepalese rupe",
5623 "1.00 Netherlands Antillean Guilde",
5624 "1.00 Netherlands Antillean guilde",
5625 "1.00 Dutch Guilde",
5626 "1.00 Dutch guilde",
5627 "1.00 Israeli New Sheqe",
5628 "1.00 New Zealand Dolla",
5629 "1.00 New Zealand dolla",
5630 "1.00 Nicaraguan cordob",
5631 "1.00 Nigerian Nair",
5632 "1.00 Nigerian nair",
5633 "1.00 North Korean Wo",
5634 "1.00 North Korean wo",
5635 "1.00 Norwegian Kron",
5636 "1.00 Norwegian kron",
5652 "Afghan Afghan1.00",
5653 "Afghan Afghani (1927\\u201320021.00",
5656 "Algerian Dina1.00",
5657 "Andorran Peset1.00",
5658 "Angolan Kwanz1.00",
5659 "Angolan Kwanza (1977\\u201319901.00",
5660 "Angolan Readjusted Kwanza (1995\\u201319991.00",
5661 "Angolan New Kwanza (1990\\u201320001.00",
5662 "Argentine Austra1.00",
5663 "Argentine Pes1.00",
5664 "Argentine Peso (1983\\u201319851.00",
5667 "Australian Dolla1.00",
5668 "Austrian Schillin1.00",
5669 "Azerbaijani Mana1.00",
5670 "Azerbaijani Manat (1993\\u201320061.00",
5688 "Bahamian Dolla1.00",
5689 "Bahraini Dina1.00",
5690 "Bangladeshi Tak1.00",
5691 "Barbadian Dolla1.00",
5693 "Belarusian New Ruble (1994\\u201319991.00",
5694 "Belarusian Rubl1.00",
5696 "Belgian Franc (convertible1.00",
5697 "Belgian Franc (financial1.00",
5699 "Bermudan Dolla1.00",
5700 "Bhutanese Ngultru1.00",
5701 "Bolivian Mvdo1.00",
5703 "Bolivian Bolivian1.00",
5704 "Bosnia-Herzegovina Convertible Mar1.00",
5705 "Bosnia-Herzegovina Dina1.00",
5706 "Botswanan Pul1.00",
5707 "Brazilian Cruzad1.00",
5708 "Brazilian Cruzado Nov1.00",
5709 "Brazilian Cruzeir1.00",
5710 "Brazilian Cruzeiro (1990\\u201319931.00",
5711 "Brazilian New Cruzeiro (1967\\u201319861.00",
5712 "Brazilian Rea1.00",
5713 "British Pound Sterlin1.00",
5715 "Bulgarian Hard Le1.00",
5718 "Burundian Fran1.00",
5733 "Cambodian Rie1.00",
5734 "Canadian Dolla1.00",
5735 "Cape Verdean Escud1.00",
5736 "Cayman Islands Dolla1.00",
5738 "Chilean Unit of Accoun1.00",
5740 "Colombian Pes1.00",
5742 "Congolese Fran1.00",
5743 "Costa Rican Col\\u00f31.00",
5744 "Croatian Dina1.00",
5748 "Czech Republic Korun1.00",
5749 "Czechoslovak Hard Korun1.00",
5759 "Djiboutian Fran1.00",
5761 "Dominican Pes1.00",
5770 "East Caribbean Dolla1.00",
5771 "East German Ostmar1.00",
5772 "Ecuadorian Sucr1.00",
5773 "Ecuadorian Unit of Constant Valu1.00",
5774 "Egyptian Poun1.00",
5776 "Salvadoran Col\\u00f31.00",
5777 "Equatorial Guinean Ekwel1.00",
5778 "Eritrean Nakf1.00",
5780 "Estonian Kroo1.00",
5781 "Ethiopian Bir1.00",
5783 "European Composite Uni1.00",
5784 "European Currency Uni1.00",
5785 "European Monetary Uni1.00",
5786 "European Unit of Account (XBC1.00",
5787 "European Unit of Account (XBD1.00",
5794 "Falkland Islands Poun1.00",
5797 "Finnish Markk1.00",
5800 "French Gold Fran1.00",
5801 "French UIC-Fran1.00",
5814 "Gambian Dalas1.00",
5815 "Georgian Kupon Lari1.00",
5818 "Ghanaian Cedi (1979\\u201320071.00",
5819 "Gibraltar Poun1.00",
5822 "Guatemalan Quetza1.00",
5825 "Guinea-Bissau Pes1.00",
5826 "Guyanaese Dolla1.00",
5832 "Haitian Gourd1.00",
5833 "Honduran Lempir1.00",
5834 "Hong Kong Dolla1.00",
5835 "Hungarian Forin1.00",
5844 "Icelandic Kron1.00",
5846 "Indonesian Rupia1.00",
5856 "Jamaican Dolla1.00",
5858 "Jordanian Dina1.00",
5869 "Kazakhstani Teng1.00",
5870 "Kenyan Shillin1.00",
5872 "Kyrgystani So1.00",
5884 "Lebanese Poun1.00",
5886 "Liberian Dolla1.00",
5888 "Lithuanian Lit1.00",
5889 "Lithuanian Talona1.00",
5890 "Luxembourgian Convertible Fran1.00",
5891 "Luxembourg Financial Fran1.00",
5892 "Luxembourgian Fran1.00",
5910 "Macanese Patac1.00",
5911 "Macedonian Dena1.00",
5912 "Malagasy Ariar1.00",
5913 "Malagasy Fran1.00",
5914 "Malawian Kwach1.00",
5915 "Malaysian Ringgi1.00",
5916 "Maldivian Rufiya1.00",
5921 "Mauritanian Ouguiy1.00",
5922 "Mauritian Rupe1.00",
5924 "Mexican Silver Peso (1861\\u201319921.00",
5925 "Mexican Investment Uni1.00",
5927 "Mongolian Tugri1.00",
5928 "Moroccan Dirha1.00",
5929 "Moroccan Fran1.00",
5930 "Mozambican Escud1.00",
5931 "Mozambican Metica1.00",
5943 "Namibian Dolla1.00",
5944 "Nepalese Rupe1.00",
5945 "Netherlands Antillean Guilde1.00",
5947 "Israeli New Sheqe1.00",
5948 "New Zealand Dolla1.00",
5949 "Nicaraguan C\\u00f3rdoba (1988\\u201319911.00",
5950 "Nicaraguan C\\u00f3rdob1.00",
5951 "Nigerian Nair1.00",
5952 "North Korean Wo1.00",
5953 "Norwegian Kron1.00",
5956 "Old Mozambican Metica1.00",
5957 "Romanian Leu (1952\\u201320061.00",
5958 "Serbian Dinar (2002\\u201320061.00",
5959 "Sudanese Dinar (1992\\u201320071.00",
5960 "Sudanese Pound (1957\\u201319981.00",
5961 "Turkish Lira (1922\\u201320051.00",
5971 "Pakistani Rupe1.00",
5973 "Panamanian Balbo1.00",
5974 "Papua New Guinean Kin1.00",
5975 "Paraguayan Guaran1.00",
5977 "Peruvian Sol (1863\\u201319651.00",
5978 "Peruvian Sol Nuev1.00",
5979 "Philippine Pes1.00",
5982 "Polish Zloty (1950\\u201319951.00",
5983 "Portuguese Escud1.00",
5984 "Portuguese Guinea Escud1.00",
5995 "Rhodesian Dolla1.00",
5998 "Russian Ruble (1991\\u201319981.00",
6018 "St. Helena Poun1.00",
6019 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobr1.00",
6022 "Seychellois Rupe1.00",
6024 "Sierra Leonean Leon1.00",
6026 "Singapore Dolla1.00",
6028 "Slovenian Tola1.00",
6029 "Solomon Islands Dolla1.00",
6030 "Somali Shillin1.00",
6031 "South African Ran1.00",
6032 "South African Rand (financial1.00",
6033 "South Korean Wo1.00",
6035 "Spanish Peset1.00",
6036 "Spanish Peseta (A account1.00",
6037 "Spanish Peseta (convertible account1.00",
6038 "Special Drawing Right1.00",
6039 "Sri Lankan Rupe1.00",
6040 "Sudanese Poun1.00",
6041 "Surinamese Dolla1.00",
6042 "Surinamese Guilde1.00",
6043 "Swazi Lilangen1.00",
6058 "New Taiwan Dolla1.00",
6059 "Tajikistani Rubl1.00",
6060 "Tajikistani Somon1.00",
6061 "Tanzanian Shillin1.00",
6062 "Testing Currency Cod1.00",
6064 "Timorese Escud1.00",
6065 "Tongan Pa\\u20bbang1.00",
6066 "Trinidad & Tobago Dolla1.00",
6067 "Tunisian Dina1.00",
6069 "Turkmenistani Mana1.00",
6075 "US Dollar (Next day1.00",
6076 "US Dollar (Same day1.00",
6080 "Ugandan Shillin1.00",
6081 "Ugandan Shilling (1966\\u201319871.00",
6082 "Ukrainian Hryvni1.00",
6083 "Ukrainian Karbovanet1.00",
6084 "Colombian Real Value Uni1.00",
6085 "United Arab Emirates Dirha1.00",
6086 "Unknown Currenc1.00",
6088 "Uruguay Peso (1975\\u201319931.00",
6089 "Uruguay Peso Uruguay1.00",
6090 "Uruguay Peso (Indexed Units1.00",
6091 "Uzbekistani So1.00",
6097 "Venezuelan Bol\\u00edva1.00",
6098 "Venezuelan Bol\\u00edvar Fuert1.00",
6099 "Vietnamese Don1.00",
6100 "West African CFA Fran1.00",
6101 "Central African CFA Fran1.00",
6122 "Yugoslavian Convertible Dina1.00",
6123 "Yugoslavian Hard Dinar (1966\\u201319901.00",
6124 "Yugoslavian New Dina1.00",
6130 "Zairean New Zaire (1993\\u201319981.00",
6132 "Zambian Kwach1.00",
6133 "Zimbabwean Dollar (1980\\u201320081.00",
6141 Locale
locale("en_US");
6142 for (uint32_t i
=0; i
<sizeof(DATA
)/sizeof(DATA
[0]); ++i
) {
6143 UnicodeString formatted
= ctou(DATA
[i
]);
6144 UErrorCode status
= U_ZERO_ERROR
;
6145 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, UNUM_CURRENCY
, status
);
6146 if (numFmt
!= NULL
&& U_SUCCESS(status
)) {
6147 ParsePosition parsePos
;
6148 LocalPointer
<CurrencyAmount
> currAmt(numFmt
->parseCurrency(formatted
, parsePos
));
6149 if (parsePos
.getIndex() > 0) {
6150 double doubleVal
= currAmt
->getNumber().getDouble(status
);
6151 if ( doubleVal
!= 1.0 ) {
6152 errln("Parsed as currency value other than 1.0: " + formatted
+ " -> " + doubleVal
);
6155 errln("Failed to parse as currency: " + formatted
);
6158 dataerrln("Unable to create NumberFormat. - %s", u_errorName(status
));
6165 for (uint32_t i
=0; i
<sizeof(WRONG_DATA
)/sizeof(WRONG_DATA
[0]); ++i
) {
6166 UnicodeString formatted
= ctou(WRONG_DATA
[i
]);
6167 UErrorCode status
= U_ZERO_ERROR
;
6168 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, UNUM_CURRENCY
, status
);
6169 if (numFmt
!= NULL
&& U_SUCCESS(status
)) {
6170 ParsePosition parsePos
;
6171 LocalPointer
<CurrencyAmount
> currAmt(numFmt
->parseCurrency(formatted
, parsePos
));
6172 if (parsePos
.getIndex() > 0) {
6173 double doubleVal
= currAmt
->getNumber().getDouble(status
);
6174 errln("Parsed as currency, should not have: " + formatted
+ " -> " + doubleVal
);
6177 dataerrln("Unable to create NumberFormat. - %s", u_errorName(status
));
6185 const char* attrString(int32_t);
6189 // std::cout << s.toUTF8String(ss)
6190 void NumberFormatTest::expectPositions(FieldPositionIterator
& iter
, int32_t *values
, int32_t tupleCount
,
6191 const UnicodeString
& str
) {
6195 if (tupleCount
> 10) {
6196 assertTrue("internal error, tupleCount too large", FALSE
);
6198 for (int i
= 0; i
< tupleCount
; ++i
) {
6204 while (iter
.next(fp
)) {
6206 int32_t id
= fp
.getField();
6207 int32_t start
= fp
.getBeginIndex();
6208 int32_t limit
= fp
.getEndIndex();
6210 // is there a logln using printf?
6212 sprintf(buf
, "%24s %3d %3d %3d", attrString(id
), id
, start
, limit
);
6215 for (int i
= 0; i
< tupleCount
; ++i
) {
6219 if (values
[i
*3] == id
&&
6220 values
[i
*3+1] == start
&&
6221 values
[i
*3+2] == limit
) {
6222 found
[i
] = ok
= TRUE
;
6227 assertTrue((UnicodeString
)"found [" + id
+ "," + start
+ "," + limit
+ "]", ok
);
6230 // check that all were found
6232 for (int i
= 0; i
< tupleCount
; ++i
) {
6235 assertTrue((UnicodeString
) "missing [" + values
[i
*3] + "," + values
[i
*3+1] + "," + values
[i
*3+2] + "]", found
[i
]);
6238 assertTrue("no expected values were missing", ok
);
6241 void NumberFormatTest::expectPosition(FieldPosition
& pos
, int32_t id
, int32_t start
, int32_t limit
,
6242 const UnicodeString
& str
) {
6244 assertTrue((UnicodeString
)"id " + id
+ " == " + pos
.getField(), id
== pos
.getField());
6245 assertTrue((UnicodeString
)"begin " + start
+ " == " + pos
.getBeginIndex(), start
== pos
.getBeginIndex());
6246 assertTrue((UnicodeString
)"end " + limit
+ " == " + pos
.getEndIndex(), limit
== pos
.getEndIndex());
6249 void NumberFormatTest::TestFieldPositionIterator() {
6251 UErrorCode status
= U_ZERO_ERROR
;
6252 FieldPositionIterator iter1
;
6253 FieldPositionIterator iter2
;
6256 DecimalFormat
*decFmt
= (DecimalFormat
*) NumberFormat::createInstance(status
);
6257 if (failure(status
, "NumberFormat::createInstance", TRUE
)) return;
6259 double num
= 1234.56;
6263 assertTrue((UnicodeString
)"self==", iter1
== iter1
);
6264 assertTrue((UnicodeString
)"iter1==iter2", iter1
== iter2
);
6266 decFmt
->format(num
, str1
, &iter1
, status
);
6267 assertTrue((UnicodeString
)"iter1 != iter2", iter1
!= iter2
);
6268 decFmt
->format(num
, str2
, &iter2
, status
);
6269 assertTrue((UnicodeString
)"iter1 == iter2 (2)", iter1
== iter2
);
6271 assertTrue((UnicodeString
)"iter1 != iter2 (2)", iter1
!= iter2
);
6273 assertTrue((UnicodeString
)"iter1 == iter2 (3)", iter1
== iter2
);
6275 // should format ok with no iterator
6277 decFmt
->format(num
, str2
, NULL
, status
);
6278 assertEquals("null fpiter", str1
, str2
);
6283 void NumberFormatTest::TestFormatAttributes() {
6284 Locale
locale("en_US");
6285 UErrorCode status
= U_ZERO_ERROR
;
6286 DecimalFormat
*decFmt
= (DecimalFormat
*) NumberFormat::createInstance(locale
, UNUM_CURRENCY
, status
);
6287 if (failure(status
, "NumberFormat::createInstance", TRUE
)) return;
6288 double val
= 12345.67;
6291 int32_t expected
[] = {
6292 UNUM_CURRENCY_FIELD
, 0, 1,
6293 UNUM_GROUPING_SEPARATOR_FIELD
, 3, 4,
6294 UNUM_INTEGER_FIELD
, 1, 7,
6295 UNUM_DECIMAL_SEPARATOR_FIELD
, 7, 8,
6296 UNUM_FRACTION_FIELD
, 8, 10,
6298 int32_t tupleCount
= sizeof(expected
)/(3 * sizeof(*expected
));
6300 FieldPositionIterator posIter
;
6301 UnicodeString result
;
6302 decFmt
->format(val
, result
, &posIter
, status
);
6303 expectPositions(posIter
, expected
, tupleCount
, result
);
6306 FieldPosition
fp(UNUM_INTEGER_FIELD
);
6307 UnicodeString result
;
6308 decFmt
->format(val
, result
, fp
);
6309 expectPosition(fp
, UNUM_INTEGER_FIELD
, 1, 7, result
);
6312 FieldPosition
fp(UNUM_FRACTION_FIELD
);
6313 UnicodeString result
;
6314 decFmt
->format(val
, result
, fp
);
6315 expectPosition(fp
, UNUM_FRACTION_FIELD
, 8, 10, result
);
6319 decFmt
= (DecimalFormat
*) NumberFormat::createInstance(locale
, UNUM_SCIENTIFIC
, status
);
6322 int32_t expected
[] = {
6323 UNUM_SIGN_FIELD
, 0, 1,
6324 UNUM_INTEGER_FIELD
, 1, 2,
6325 UNUM_DECIMAL_SEPARATOR_FIELD
, 2, 3,
6326 UNUM_FRACTION_FIELD
, 3, 5,
6327 UNUM_EXPONENT_SYMBOL_FIELD
, 5, 6,
6328 UNUM_EXPONENT_SIGN_FIELD
, 6, 7,
6329 UNUM_EXPONENT_FIELD
, 7, 8
6331 int32_t tupleCount
= sizeof(expected
)/(3 * sizeof(*expected
));
6333 FieldPositionIterator posIter
;
6334 UnicodeString result
;
6335 decFmt
->format(val
, result
, &posIter
, status
);
6336 expectPositions(posIter
, expected
, tupleCount
, result
);
6339 FieldPosition
fp(UNUM_INTEGER_FIELD
);
6340 UnicodeString result
;
6341 decFmt
->format(val
, result
, fp
);
6342 expectPosition(fp
, UNUM_INTEGER_FIELD
, 1, 2, result
);
6345 FieldPosition
fp(UNUM_FRACTION_FIELD
);
6346 UnicodeString result
;
6347 decFmt
->format(val
, result
, fp
);
6348 expectPosition(fp
, UNUM_FRACTION_FIELD
, 3, 5, result
);
6355 const char* attrString(int32_t attrId
) {
6357 case UNUM_INTEGER_FIELD
: return "integer";
6358 case UNUM_FRACTION_FIELD
: return "fraction";
6359 case UNUM_DECIMAL_SEPARATOR_FIELD
: return "decimal separator";
6360 case UNUM_EXPONENT_SYMBOL_FIELD
: return "exponent symbol";
6361 case UNUM_EXPONENT_SIGN_FIELD
: return "exponent sign";
6362 case UNUM_EXPONENT_FIELD
: return "exponent";
6363 case UNUM_GROUPING_SEPARATOR_FIELD
: return "grouping separator";
6364 case UNUM_CURRENCY_FIELD
: return "currency";
6365 case UNUM_PERCENT_FIELD
: return "percent";
6366 case UNUM_PERMILL_FIELD
: return "permille";
6367 case UNUM_SIGN_FIELD
: return "sign";
6373 // Test formatting & parsing of big decimals.
6374 // API test, not a comprehensive test.
6375 // See DecimalFormatTest/DataDrivenTests
6377 #define ASSERT_SUCCESS(status) {if (U_FAILURE(status)) errln("file %s, line %d: status: %s", \
6378 __FILE__, __LINE__, u_errorName(status));}
6379 #define ASSERT_EQUALS(expected, actual) {if ((expected) != (actual)) \
6380 errln("file %s, line %d: %s != %s", __FILE__, __LINE__, #expected, #actual);}
6382 static UBool
operator != (const char *s1
, UnicodeString
&s2
) {
6383 // This function lets ASSERT_EQUALS("literal", UnicodeString) work.
6384 UnicodeString
us1(s1
);
6388 void NumberFormatTest::TestDecimal() {
6390 UErrorCode status
= U_ZERO_ERROR
;
6391 Formattable
f("12.345678999987654321E666", status
);
6392 ASSERT_SUCCESS(status
);
6393 StringPiece s
= f
.getDecimalNumber(status
);
6394 ASSERT_SUCCESS(status
);
6395 ASSERT_EQUALS("1.2345678999987654321E+667", s
);
6396 //printf("%s\n", s.data());
6400 UErrorCode status
= U_ZERO_ERROR
;
6401 Formattable
f1("this is not a number", status
);
6402 ASSERT_EQUALS(U_DECIMAL_NUMBER_SYNTAX_ERROR
, status
);
6406 UErrorCode status
= U_ZERO_ERROR
;
6408 f
.setDecimalNumber("123.45", status
);
6409 ASSERT_SUCCESS(status
);
6410 ASSERT_EQUALS( Formattable::kDouble
, f
.getType());
6411 ASSERT_EQUALS(123.45, f
.getDouble());
6412 ASSERT_EQUALS(123.45, f
.getDouble(status
));
6413 ASSERT_SUCCESS(status
);
6414 ASSERT_EQUALS("123.45", f
.getDecimalNumber(status
));
6415 ASSERT_SUCCESS(status
);
6417 f
.setDecimalNumber("4.5678E7", status
);
6420 ASSERT_EQUALS(45678000, n
);
6422 status
= U_ZERO_ERROR
;
6423 f
.setDecimalNumber("-123", status
);
6424 ASSERT_SUCCESS(status
);
6425 ASSERT_EQUALS( Formattable::kLong
, f
.getType());
6426 ASSERT_EQUALS(-123, f
.getLong());
6427 ASSERT_EQUALS(-123, f
.getLong(status
));
6428 ASSERT_SUCCESS(status
);
6429 ASSERT_EQUALS("-123", f
.getDecimalNumber(status
));
6430 ASSERT_SUCCESS(status
);
6432 status
= U_ZERO_ERROR
;
6433 f
.setDecimalNumber("1234567890123", status
); // Number too big for 32 bits
6434 ASSERT_SUCCESS(status
);
6435 ASSERT_EQUALS( Formattable::kInt64
, f
.getType());
6436 ASSERT_EQUALS(1234567890123LL, f
.getInt64());
6437 ASSERT_EQUALS(1234567890123LL, f
.getInt64(status
));
6438 ASSERT_SUCCESS(status
);
6439 ASSERT_EQUALS("1234567890123", f
.getDecimalNumber(status
));
6440 ASSERT_SUCCESS(status
);
6444 UErrorCode status
= U_ZERO_ERROR
;
6445 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL
, status
);
6446 if (U_FAILURE(status
) || fmtr
== NULL
) {
6447 dataerrln("Unable to create NumberFormat");
6449 UnicodeString formattedResult
;
6450 StringPiece
num("244444444444444444444444444444444444446.4");
6451 fmtr
->format(num
, formattedResult
, NULL
, status
);
6452 ASSERT_SUCCESS(status
);
6453 ASSERT_EQUALS("244,444,444,444,444,444,444,444,444,444,444,444,446.4", formattedResult
);
6454 //std::string ss; std::cout << formattedResult.toUTF8String(ss);
6460 // Check formatting a DigitList. DigitList is internal, but this is
6461 // a critical interface that must work.
6462 UErrorCode status
= U_ZERO_ERROR
;
6463 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL
, status
);
6464 if (U_FAILURE(status
) || fmtr
== NULL
) {
6465 dataerrln("Unable to create NumberFormat");
6467 UnicodeString formattedResult
;
6469 StringPiece
num("123.4566666666666666666666666666666666621E+40");
6470 dl
.set(num
, status
);
6471 ASSERT_SUCCESS(status
);
6472 fmtr
->format(dl
, formattedResult
, NULL
, status
);
6473 ASSERT_SUCCESS(status
);
6474 ASSERT_EQUALS("1,234,566,666,666,666,666,666,666,666,666,666,666,621,000", formattedResult
);
6476 status
= U_ZERO_ERROR
;
6478 dl
.set(num
, status
);
6479 FieldPosition
pos(NumberFormat::FRACTION_FIELD
);
6480 ASSERT_SUCCESS(status
);
6481 formattedResult
.remove();
6482 fmtr
->format(dl
, formattedResult
, pos
, status
);
6483 ASSERT_SUCCESS(status
);
6484 ASSERT_EQUALS("666.666", formattedResult
);
6485 ASSERT_EQUALS(4, pos
.getBeginIndex());
6486 ASSERT_EQUALS(7, pos
.getEndIndex());
6492 // Check a parse with a formatter with a multiplier.
6493 UErrorCode status
= U_ZERO_ERROR
;
6494 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_PERCENT
, status
);
6495 if (U_FAILURE(status
) || fmtr
== NULL
) {
6496 dataerrln("Unable to create NumberFormat");
6498 UnicodeString input
= "1.84%";
6500 fmtr
->parse(input
, result
, status
);
6501 ASSERT_SUCCESS(status
);
6502 ASSERT_EQUALS(0, strcmp("0.0184", result
.getDecimalNumber(status
).data()));
6503 //std::cout << result.getDecimalNumber(status).data();
6508 #if U_PLATFORM != U_PF_CYGWIN || defined(CYGWINMSVC)
6510 * This test fails on Cygwin (1.7.16) using GCC because of a rounding issue with strtod().
6514 // Check that a parse returns a decimal number with full accuracy
6515 UErrorCode status
= U_ZERO_ERROR
;
6516 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL
, status
);
6517 if (U_FAILURE(status
) || fmtr
== NULL
) {
6518 dataerrln("Unable to create NumberFormat");
6520 UnicodeString input
= "1.002200044400088880000070000";
6522 fmtr
->parse(input
, result
, status
);
6523 ASSERT_SUCCESS(status
);
6524 ASSERT_EQUALS(0, strcmp("1.00220004440008888000007", result
.getDecimalNumber(status
).data()));
6525 ASSERT_EQUALS(1.00220004440008888, result
.getDouble());
6526 //std::cout << result.getDecimalNumber(status).data();
6534 void NumberFormatTest::TestCurrencyFractionDigits() {
6535 UErrorCode status
= U_ZERO_ERROR
;
6536 UnicodeString text1
, text2
;
6537 double value
= 99.12345;
6539 // Create currenct instance
6540 NumberFormat
* fmt
= NumberFormat::createCurrencyInstance("ja_JP", status
);
6541 if (U_FAILURE(status
) || fmt
== NULL
) {
6542 dataerrln("Unable to create NumberFormat");
6544 fmt
->format(value
, text1
);
6546 // Reset the same currency and format the test value again
6547 fmt
->setCurrency(fmt
->getCurrency(), status
);
6548 ASSERT_SUCCESS(status
);
6549 fmt
->format(value
, text2
);
6551 if (text1
!= text2
) {
6552 errln((UnicodeString
)"NumberFormat::format() should return the same result - text1="
6553 + text1
+ " text2=" + text2
);
6559 void NumberFormatTest::TestExponentParse() {
6561 UErrorCode status
= U_ZERO_ERROR
;
6563 ParsePosition
parsePos(0);
6565 // set the exponent symbol
6566 status
= U_ZERO_ERROR
;
6567 DecimalFormatSymbols
*symbols
= new DecimalFormatSymbols(Locale::getDefault(), status
);
6568 if(U_FAILURE(status
)) {
6569 dataerrln((UnicodeString
)"ERROR: Could not create DecimalFormatSymbols (Default)");
6573 // create format instance
6574 status
= U_ZERO_ERROR
;
6575 DecimalFormat
fmt("#####", symbols
, status
);
6576 if(U_FAILURE(status
)) {
6577 errln((UnicodeString
)"ERROR: Could not create DecimalFormat (pattern, symbols*)");
6581 fmt
.parse("5.06e-27", result
, parsePos
);
6582 if(result
.getType() != Formattable::kDouble
&&
6583 result
.getDouble() != 5.06E-27 &&
6584 parsePos
.getIndex() != 8
6587 errln("ERROR: parse failed - expected 5.06E-27, 8 - returned %d, %i",
6588 result
.getDouble(), parsePos
.getIndex());
6592 void NumberFormatTest::TestExplicitParents() {
6594 /* Test that number formats are properly inherited from es_419 */
6595 /* These could be subject to change if the CLDR data changes */
6596 static const char* parentLocaleTests
[][2]= {
6597 /* locale ID */ /* expected */
6598 {"es_CO", "1.250,75" },
6599 {"es_CR", "1.250,75" },
6600 {"es_ES", "1.250,75" },
6601 {"es_GQ", "1.250,75" },
6602 {"es_MX", "1,250.75" },
6603 {"es_US", "1,250.75" },
6604 {"es_VE", "1.250,75" },
6609 for(int i
=0; i
< (int)(sizeof(parentLocaleTests
)/sizeof(parentLocaleTests
[i
])); i
++){
6610 UErrorCode status
= U_ZERO_ERROR
;
6611 const char *localeID
= parentLocaleTests
[i
][0];
6612 UnicodeString
expected(parentLocaleTests
[i
][1], -1, US_INV
);
6613 expected
= expected
.unescape();
6615 uloc_canonicalize(localeID
, loc
, 256, &status
);
6616 NumberFormat
*fmt
= NumberFormat::createInstance(Locale(loc
), status
);
6617 if(U_FAILURE(status
)){
6618 dataerrln("Could not create number formatter for locale %s - %s",localeID
, u_errorName(status
));
6622 fmt
->format(1250.75, s
);
6624 errln(UnicodeString("FAIL: Expected: ")+expected
6625 + UnicodeString(" Got: ") + s
6626 + UnicodeString( " for locale: ")+ UnicodeString(localeID
) );
6628 if (U_FAILURE(status
)){
6629 errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
6637 * Test available numbering systems API.
6639 void NumberFormatTest::TestAvailableNumberingSystems() {
6640 UErrorCode status
= U_ZERO_ERROR
;
6641 StringEnumeration
*availableNumberingSystems
= NumberingSystem::getAvailableNames(status
);
6642 CHECK_DATA(status
, "NumberingSystem::getAvailableNames()")
6644 int32_t nsCount
= availableNumberingSystems
->count(status
);
6645 if ( nsCount
< 36 ) {
6646 errln("FAIL: Didn't get as many numbering systems as we had hoped for. Need at least 36, got %d",nsCount
);
6649 /* A relatively simple test of the API. We call getAvailableNames() and cycle through */
6650 /* each name returned, attempting to create a numbering system based on that name and */
6651 /* verifying that the name returned from the resulting numbering system is the same */
6652 /* one that we initially thought. */
6655 for ( int32_t i
= 0 ; i
< nsCount
; i
++ ) {
6656 const char *nsname
= availableNumberingSystems
->next(&len
,status
);
6657 NumberingSystem
* ns
= NumberingSystem::createInstanceByName(nsname
,status
);
6658 if ( uprv_strcmp(nsname
,ns
->getName()) ) {
6659 errln("FAIL: Numbering system name didn't match for name = %s\n",nsname
);
6665 delete availableNumberingSystems
;
6669 NumberFormatTest::Test9087(void)
6671 U_STRING_DECL(pattern
,"#",1);
6672 U_STRING_INIT(pattern
,"#",1);
6674 U_STRING_DECL(infstr
,"INF",3);
6675 U_STRING_INIT(infstr
,"INF",3);
6677 U_STRING_DECL(nanstr
,"NAN",3);
6678 U_STRING_INIT(nanstr
,"NAN",3);
6680 UChar outputbuf
[50] = {0};
6681 UErrorCode status
= U_ZERO_ERROR
;
6682 UNumberFormat
* fmt
= unum_open(UNUM_PATTERN_DECIMAL
,pattern
,1,NULL
,NULL
,&status
);
6683 if ( U_FAILURE(status
) ) {
6684 dataerrln("FAIL: error in unum_open() - %s", u_errorName(status
));
6688 unum_setSymbol(fmt
,UNUM_INFINITY_SYMBOL
,infstr
,3,&status
);
6689 unum_setSymbol(fmt
,UNUM_NAN_SYMBOL
,nanstr
,3,&status
);
6690 if ( U_FAILURE(status
) ) {
6691 errln("FAIL: error setting symbols");
6694 double inf
= uprv_getInfinity();
6696 unum_setAttribute(fmt
,UNUM_ROUNDING_MODE
,UNUM_ROUND_HALFEVEN
);
6697 unum_setDoubleAttribute(fmt
,UNUM_ROUNDING_INCREMENT
,0);
6699 UFieldPosition position
= { 0, 0, 0};
6700 unum_formatDouble(fmt
,inf
,outputbuf
,50,&position
,&status
);
6702 if ( u_strcmp(infstr
, outputbuf
)) {
6703 errln((UnicodeString
)"FAIL: unexpected result for infinity - expected " + infstr
+ " got " + outputbuf
);
6709 #include "dcfmtimp.h"
6711 void NumberFormatTest::TestFormatFastpaths() {
6712 #if UCONFIG_FORMAT_FASTPATHS_49
6713 logln("Sizeof DecimalFormat = %d, Sizeof DecimalFormatInternal=%d, UNUM_DECIMALFORMAT_INTERNAL_SIZE=%d\n",
6714 sizeof(DecimalFormat
), sizeof(DecimalFormatInternal
), UNUM_DECIMALFORMAT_INTERNAL_SIZE
);
6715 if(UNUM_DECIMALFORMAT_INTERNAL_SIZE
< sizeof(DecimalFormatInternal
)) {
6716 errln("Error: sizeof(DecimalFormatInternal)=%d but UNUM_DECIMALFORMAT_INTERNAL_SIZE is only %d. Increase the #define?\n", sizeof(DecimalFormatInternal
), UNUM_DECIMALFORMAT_INTERNAL_SIZE
);
6717 } else if(UNUM_DECIMALFORMAT_INTERNAL_SIZE
> (sizeof(DecimalFormatInternal
)+16)) {
6718 infoln("Note: sizeof(DecimalFormatInternal)=%d but UNUM_DECIMALFORMAT_INTERNAL_SIZE is %d. Decrease the #define? sizeof(DecimalFormat)=%d\n", sizeof(DecimalFormatInternal
), UNUM_DECIMALFORMAT_INTERNAL_SIZE
, sizeof(DecimalFormat
));
6721 infoln("NOTE: UCONFIG_FORMAT_FASTPATHS not set, test skipped.");
6724 // get some additional case
6726 UErrorCode status
=U_ZERO_ERROR
;
6727 DecimalFormat
df(UnicodeString("0000",""),status
);
6728 int64_t long_number
= 1;
6729 UnicodeString expect
= "0001";
6730 UnicodeString result
;
6732 df
.format(long_number
, result
, pos
);
6733 if(U_FAILURE(status
)||expect
!=result
) {
6734 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),""));
6736 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),""));
6740 UErrorCode status
=U_ZERO_ERROR
;
6741 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
6742 int64_t long_number
= U_INT64_MIN
; // -9223372036854775808L;
6744 // memcpy(bits,&long_number,8);
6745 // for(int i=0;i<8;i++) {
6746 // logln("bits: %02X", (unsigned int)bits[i]);
6748 UnicodeString expect
= "-9223372036854775808";
6749 UnicodeString result
;
6751 df
.format(long_number
, result
, pos
);
6752 if(U_FAILURE(status
)||expect
!=result
) {
6753 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775808");
6755 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775808");
6759 UErrorCode status
=U_ZERO_ERROR
;
6760 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
6761 int64_t long_number
= U_INT64_MAX
; // -9223372036854775808L;
6763 // memcpy(bits,&long_number,8);
6764 // for(int i=0;i<8;i++) {
6765 // logln("bits: %02X", (unsigned int)bits[i]);
6767 UnicodeString expect
= "9223372036854775807";
6768 UnicodeString result
;
6770 df
.format(long_number
, result
, pos
);
6771 if(U_FAILURE(status
)||expect
!=result
) {
6772 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on U_INT64_MAX");
6774 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on U_INT64_MAX");
6778 UErrorCode status
=U_ZERO_ERROR
;
6779 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
6780 int64_t long_number
= 0;
6782 // memcpy(bits,&long_number,8);
6783 // for(int i=0;i<8;i++) {
6784 // logln("bits: %02X", (unsigned int)bits[i]);
6786 UnicodeString expect
= "0000000000000000000";
6787 UnicodeString result
;
6789 df
.format(long_number
, result
, pos
);
6790 if(U_FAILURE(status
)||expect
!=result
) {
6791 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on 0");
6793 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on 0");
6797 UErrorCode status
=U_ZERO_ERROR
;
6798 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
6799 int64_t long_number
= U_INT64_MIN
+ 1;
6800 UnicodeString expect
= "-9223372036854775807";
6801 UnicodeString result
;
6803 df
.format(long_number
, result
, pos
);
6804 if(U_FAILURE(status
)||expect
!=result
) {
6805 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775807");
6807 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775807");
6813 void NumberFormatTest::TestFormattableSize(void) {
6814 if(sizeof(FmtStackData
) > UNUM_INTERNAL_STACKARRAY_SIZE
) {
6815 errln("Error: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
6816 sizeof(FmtStackData
), UNUM_INTERNAL_STACKARRAY_SIZE
);
6817 } else if(sizeof(FmtStackData
) < UNUM_INTERNAL_STACKARRAY_SIZE
) {
6818 logln("Warning: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
6819 sizeof(FmtStackData
), UNUM_INTERNAL_STACKARRAY_SIZE
);
6821 logln("sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
6822 sizeof(FmtStackData
), UNUM_INTERNAL_STACKARRAY_SIZE
);
6826 UBool
NumberFormatTest::testFormattableAsUFormattable(const char *file
, int line
, Formattable
&f
) {
6827 UnicodeString fileLine
= UnicodeString(file
)+UnicodeString(":")+line
+UnicodeString(": ");
6829 UFormattable
*u
= f
.toUFormattable();
6832 errln("%s:%d: Error: f.toUFormattable() retuned NULL.");
6835 logln("%s:%d: comparing Formattable with UFormattable", file
, line
);
6836 logln(fileLine
+ toString(f
));
6838 UErrorCode status
= U_ZERO_ERROR
;
6839 UErrorCode valueStatus
= U_ZERO_ERROR
;
6840 UFormattableType expectUType
= UFMT_COUNT
; // invalid
6842 UBool triedExact
= FALSE
; // did we attempt an exact comparison?
6843 UBool exactMatch
= FALSE
; // was the exact comparison true?
6845 switch( f
.getType() ) {
6846 case Formattable::kDate
:
6847 expectUType
= UFMT_DATE
;
6848 exactMatch
= (f
.getDate()==ufmt_getDate(u
, &valueStatus
));
6851 case Formattable::kDouble
:
6852 expectUType
= UFMT_DOUBLE
;
6853 exactMatch
= (f
.getDouble()==ufmt_getDouble(u
, &valueStatus
));
6856 case Formattable::kLong
:
6857 expectUType
= UFMT_LONG
;
6858 exactMatch
= (f
.getLong()==ufmt_getLong(u
, &valueStatus
));
6861 case Formattable::kString
:
6862 expectUType
= UFMT_STRING
;
6867 const UChar
* uch
= ufmt_getUChars(u
, &len
, &valueStatus
);
6868 if(U_SUCCESS(valueStatus
)) {
6869 UnicodeString
str2(uch
, len
);
6870 assertTrue("UChar* NULL-terminated", uch
[len
]==0);
6871 exactMatch
= (str
== str2
);
6876 case Formattable::kArray
:
6877 expectUType
= UFMT_ARRAY
;
6880 int32_t count
= ufmt_getArrayLength(u
, &valueStatus
);
6882 const Formattable
*array2
= f
.getArray(count2
);
6883 exactMatch
= assertEquals(fileLine
+ " array count", count
, count2
);
6886 for(int i
=0;U_SUCCESS(valueStatus
) && i
<count
;i
++) {
6887 UFormattable
*uu
= ufmt_getArrayItemByIndex(u
, i
, &valueStatus
);
6888 if(*Formattable::fromUFormattable(uu
) != (array2
[i
])) {
6889 errln("%s:%d: operator== did not match at index[%d] - %p vs %p", file
, line
, i
,
6890 (const void*)Formattable::fromUFormattable(uu
), (const void*)&(array2
[i
]));
6893 if(!testFormattableAsUFormattable("(sub item)",i
,*Formattable::fromUFormattable(uu
))) {
6901 case Formattable::kInt64
:
6902 expectUType
= UFMT_INT64
;
6903 exactMatch
= (f
.getInt64()==ufmt_getInt64(u
, &valueStatus
));
6906 case Formattable::kObject
:
6907 expectUType
= UFMT_OBJECT
;
6908 exactMatch
= (f
.getObject()==ufmt_getObject(u
, &valueStatus
));
6912 UFormattableType uType
= ufmt_getType(u
, &status
);
6914 if(U_FAILURE(status
)) {
6915 errln("%s:%d: Error calling ufmt_getType - %s", file
, line
, u_errorName(status
));
6919 if(uType
!= expectUType
) {
6920 errln("%s:%d: got type (%d) expected (%d) from ufmt_getType", file
, line
, (int) uType
, (int) expectUType
);
6924 if(U_FAILURE(valueStatus
)) {
6925 errln("%s:%d: got err %s trying to ufmt_get...() for exact match check", file
, line
, u_errorName(valueStatus
));
6926 } else if(!exactMatch
) {
6927 errln("%s:%d: failed exact match for the Formattable type", file
, line
);
6929 logln("%s:%d: exact match OK", file
, line
);
6932 logln("%s:%d: note, did not attempt exact match for this formattable type", file
, line
);
6935 if( assertEquals(fileLine
+ " isNumeric()", f
.isNumeric(), ufmt_isNumeric(u
))
6937 UErrorCode convStatus
= U_ZERO_ERROR
;
6939 if(uType
!= UFMT_INT64
) { // may fail to compare
6940 assertTrue(fileLine
+ " as doubles ==", f
.getDouble(convStatus
)==ufmt_getDouble(u
, &convStatus
));
6943 if( assertSuccess(fileLine
+ " (numeric conversion status)", convStatus
) ) {
6944 StringPiece fDecNum
= f
.getDecimalNumber(convStatus
);
6947 const char *decNumChars
= ufmt_getDecNumChars(u
, &len
, &convStatus
);
6950 char decNumChars
[200];
6951 int32_t len
= ufmt_getDecNumChars(u
, decNumChars
, 200, &convStatus
);
6954 if( assertSuccess(fileLine
+ " (decNumbers conversion)", convStatus
) ) {
6955 logln(fileLine
+ decNumChars
);
6956 assertEquals(fileLine
+ " decNumChars length==", len
, fDecNum
.length());
6957 assertEquals(fileLine
+ " decNumChars digits", decNumChars
, fDecNum
.data());
6960 UErrorCode int64ConversionF
= U_ZERO_ERROR
;
6961 int64_t l
= f
.getInt64(int64ConversionF
);
6962 UErrorCode int64ConversionU
= U_ZERO_ERROR
;
6963 int64_t r
= ufmt_getInt64(u
, &int64ConversionU
);
6966 && ( uType
!= UFMT_INT64
) // int64 better not overflow
6967 && (U_INVALID_FORMAT_ERROR
==int64ConversionU
)
6968 && (U_INVALID_FORMAT_ERROR
==int64ConversionF
) ) {
6969 logln("%s:%d: OK: 64 bit overflow", file
, line
);
6971 assertEquals(fileLine
+ " as int64 ==", l
, r
);
6972 assertSuccess(fileLine
+ " Formattable.getnt64()", int64ConversionF
);
6973 assertSuccess(fileLine
+ " ufmt_getInt64()", int64ConversionU
);
6977 return exactMatch
|| !triedExact
;
6980 void NumberFormatTest::TestUFormattable(void) {
6982 // test that a default formattable is equal to Formattable()
6983 UErrorCode status
= U_ZERO_ERROR
;
6984 LocalUFormattablePointer
defaultUFormattable(ufmt_open(&status
));
6985 assertSuccess("calling umt_open", status
);
6986 Formattable defaultFormattable
;
6987 assertTrue((UnicodeString
)"comparing ufmt_open() with Formattable()",
6989 == *(Formattable::fromUFormattable(defaultUFormattable
.getAlias()))));
6990 assertTrue((UnicodeString
)"comparing ufmt_open() with Formattable()",
6992 == *(Formattable::fromUFormattable(defaultUFormattable
.getAlias()))));
6993 assertTrue((UnicodeString
)"comparing Formattable() round tripped through UFormattable",
6995 == *(Formattable::fromUFormattable(defaultFormattable
.toUFormattable()))));
6996 assertTrue((UnicodeString
)"comparing &Formattable() round tripped through UFormattable",
6997 ((&defaultFormattable
)
6998 == Formattable::fromUFormattable(defaultFormattable
.toUFormattable())));
6999 assertFalse((UnicodeString
)"comparing &Formattable() with ufmt_open()",
7000 ((&defaultFormattable
)
7001 == Formattable::fromUFormattable(defaultUFormattable
.getAlias())));
7002 testFormattableAsUFormattable(__FILE__
, __LINE__
, defaultFormattable
);
7004 // test some random Formattables
7006 Formattable
f(ucal_getNow(), Formattable::kIsDate
);
7007 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7010 Formattable
f((double)1.61803398874989484820); // golden ratio
7011 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7014 Formattable
f((int64_t)80994231587905127LL); // weight of the moon, in kilotons http://solarsystem.nasa.gov/planets/profile.cfm?Display=Facts&Object=Moon
7015 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7018 Formattable
f((int32_t)4); // random number, source: http://www.xkcd.com/221/
7019 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7022 Formattable
f("Hello world."); // should be invariant?
7023 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7026 UErrorCode status2
= U_ZERO_ERROR
;
7027 Formattable
f(StringPiece("73476730924573500000000.0"), status2
); // weight of the moon, kg
7028 assertSuccess("Constructing a StringPiece", status2
);
7029 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7032 UErrorCode status2
= U_ZERO_ERROR
;
7033 UObject
*obj
= new Locale();
7035 assertSuccess("Constructing a Formattable from a default constructed Locale()", status2
);
7036 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7039 const Formattable array
[] = {
7040 Formattable(ucal_getNow(), Formattable::kIsDate
),
7041 Formattable((int32_t)4),
7042 Formattable((double)1.234),
7045 Formattable
fa(array
, 3);
7046 testFormattableAsUFormattable(__FILE__
, __LINE__
, fa
);
7050 void NumberFormatTest::TestSignificantDigits(void) {
7057 123.44501, -123.44501,
7058 0.001234, -0.001234,
7059 0.00000000123, -0.00000000123,
7060 0.0000000000000000000123, -0.0000000000000000000123,
7062 0.0000000012344501, -0.0000000012344501,
7063 123445.01, -123445.01,
7064 12344501000000000000000000000000000.0, -12344501000000000000000000000000000.0,
7066 const char* expected
[] = {
7071 "123.45", "-123.45",
7072 "123.45", "-123.45",
7073 "0.001234", "-0.001234",
7074 "0.00000000123", "-0.00000000123",
7075 "0.0000000000000000000123", "-0.0000000000000000000123",
7077 "0.0000000012345", "-0.0000000012345",
7078 "123450", "-123450",
7079 "12345000000000000000000000000000000", "-12345000000000000000000000000000000",
7082 UErrorCode status
= U_ZERO_ERROR
;
7083 Locale
locale("en_US");
7084 LocalPointer
<DecimalFormat
> numberFormat(static_cast<DecimalFormat
*>(
7085 NumberFormat::createInstance(locale
, status
)));
7086 CHECK_DATA(status
,"NumberFormat::createInstance")
7088 numberFormat
->setSignificantDigitsUsed(TRUE
);
7089 numberFormat
->setMinimumSignificantDigits(3);
7090 numberFormat
->setMaximumSignificantDigits(5);
7091 numberFormat
->setGroupingUsed(false);
7093 UnicodeString result
;
7094 UnicodeString expectedResult
;
7095 for (unsigned int i
= 0; i
< sizeof(input
)/sizeof(double); ++i
) {
7096 numberFormat
->format(input
[i
], result
);
7097 UnicodeString
expectedResult(expected
[i
]);
7098 if (result
!= expectedResult
) {
7099 errln((UnicodeString
)"Expected: '" + expectedResult
+ "' got '" + result
);
7105 void NumberFormatTest::TestShowZero() {
7106 UErrorCode status
= U_ZERO_ERROR
;
7107 Locale
locale("en_US");
7108 LocalPointer
<DecimalFormat
> numberFormat(static_cast<DecimalFormat
*>(
7109 NumberFormat::createInstance(locale
, status
)));
7110 CHECK_DATA(status
, "NumberFormat::createInstance")
7112 numberFormat
->setSignificantDigitsUsed(TRUE
);
7113 numberFormat
->setMaximumSignificantDigits(3);
7115 UnicodeString result
;
7116 numberFormat
->format(0.0, result
);
7117 if (result
!= "0") {
7118 errln((UnicodeString
)"Expected: 0, got " + result
);
7122 void NumberFormatTest::TestBug9936() {
7123 UErrorCode status
= U_ZERO_ERROR
;
7124 Locale
locale("en_US");
7125 LocalPointer
<DecimalFormat
> numberFormat(static_cast<DecimalFormat
*>(
7126 NumberFormat::createInstance(locale
, status
)));
7127 if (U_FAILURE(status
)) {
7128 dataerrln("File %s, Line %d: status = %s.\n", __FILE__
, __LINE__
, u_errorName(status
));
7132 if (numberFormat
->areSignificantDigitsUsed() == TRUE
) {
7133 errln("File %s, Line %d: areSignificantDigitsUsed() was TRUE, expected FALSE.\n", __FILE__
, __LINE__
);
7135 numberFormat
->setSignificantDigitsUsed(TRUE
);
7136 if (numberFormat
->areSignificantDigitsUsed() == FALSE
) {
7137 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__
, __LINE__
);
7140 numberFormat
->setSignificantDigitsUsed(FALSE
);
7141 if (numberFormat
->areSignificantDigitsUsed() == TRUE
) {
7142 errln("File %s, Line %d: areSignificantDigitsUsed() was TRUE, expected FALSE.\n", __FILE__
, __LINE__
);
7145 numberFormat
->setMinimumSignificantDigits(3);
7146 if (numberFormat
->areSignificantDigitsUsed() == FALSE
) {
7147 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__
, __LINE__
);
7150 numberFormat
->setSignificantDigitsUsed(FALSE
);
7151 numberFormat
->setMaximumSignificantDigits(6);
7152 if (numberFormat
->areSignificantDigitsUsed() == FALSE
) {
7153 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__
, __LINE__
);
7158 void NumberFormatTest::TestParseNegativeWithFaLocale() {
7159 UErrorCode status
= U_ZERO_ERROR
;
7160 DecimalFormat
*test
= (DecimalFormat
*) NumberFormat::createInstance("fa", status
);
7161 CHECK_DATA(status
, "NumberFormat::createInstance")
7162 test
->setLenient(TRUE
);
7165 UnicodeString
value("\\u200e-0,5");
7166 value
= value
.unescape();
7167 test
->parse(value
, af
, ppos
);
7168 if (ppos
.getIndex() == 0) {
7169 errln("Expected -0,5 to parse for Farsi.");
7174 void NumberFormatTest::TestParseNegativeWithAlternateMinusSign() {
7175 UErrorCode status
= U_ZERO_ERROR
;
7176 DecimalFormat
*test
= (DecimalFormat
*) NumberFormat::createInstance("en", status
);
7177 CHECK_DATA(status
, "NumberFormat::createInstance")
7178 test
->setLenient(TRUE
);
7181 UnicodeString
value("\\u208B0.5");
7182 value
= value
.unescape();
7183 test
->parse(value
, af
, ppos
);
7184 if (ppos
.getIndex() == 0) {
7185 errln(UnicodeString("Expected ") + value
+ UnicodeString(" to parse."));
7190 void NumberFormatTest::TestCustomCurrencySignAndSeparator() {
7191 UErrorCode status
= U_ZERO_ERROR
;
7192 DecimalFormatSymbols
custom(Locale::getUS(), status
);
7193 CHECK(status
, "DecimalFormatSymbols constructor");
7195 custom
.setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "*");
7196 custom
.setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
, "^");
7197 custom
.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol
, ":");
7199 UnicodeString
pat(" #,##0.00");
7200 pat
.insert(0, (UChar
)0x00A4);
7202 DecimalFormat
fmt(pat
, custom
, status
);
7203 CHECK(status
, "DecimalFormat constructor");
7205 UnicodeString
numstr("* 1^234:56");
7206 expect2(fmt
, (Formattable
)((double)1234.56), numstr
);
7210 const char * locale
;
7212 UnicodeString numString
;
7214 } SignsAndMarksItem
;
7217 void NumberFormatTest::TestParseSignsAndMarks() {
7218 const SignsAndMarksItem items
[] = {
7219 // locale lenient numString value
7220 { "en", FALSE
, CharsToUnicodeString("12"), 12 },
7221 { "en", TRUE
, CharsToUnicodeString("12"), 12 },
7222 { "en", FALSE
, CharsToUnicodeString("-23"), -23 },
7223 { "en", TRUE
, CharsToUnicodeString("-23"), -23 },
7224 { "en", TRUE
, CharsToUnicodeString("- 23"), -23 },
7225 { "en", FALSE
, CharsToUnicodeString("\\u200E-23"), -23 },
7226 { "en", TRUE
, CharsToUnicodeString("\\u200E-23"), -23 },
7227 { "en", TRUE
, CharsToUnicodeString("\\u200E- 23"), -23 },
7229 { "en@numbers=arab", FALSE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7230 { "en@numbers=arab", TRUE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7231 { "en@numbers=arab", FALSE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7232 { "en@numbers=arab", TRUE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7233 { "en@numbers=arab", TRUE
, CharsToUnicodeString("- \\u0664\\u0665"), -45 },
7234 { "en@numbers=arab", FALSE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7235 { "en@numbers=arab", TRUE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7236 { "en@numbers=arab", TRUE
, CharsToUnicodeString("\\u200F- \\u0664\\u0665"), -45 },
7238 { "en@numbers=arabext", FALSE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7239 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7240 { "en@numbers=arabext", FALSE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7241 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7242 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("- \\u06F6\\u06F7"), -67 },
7243 { "en@numbers=arabext", FALSE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7244 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7245 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("\\u200E-\\u200E \\u06F6\\u06F7"), -67 },
7247 { "he", FALSE
, CharsToUnicodeString("12"), 12 },
7248 { "he", TRUE
, CharsToUnicodeString("12"), 12 },
7249 { "he", FALSE
, CharsToUnicodeString("-23"), -23 },
7250 { "he", TRUE
, CharsToUnicodeString("-23"), -23 },
7251 { "he", TRUE
, CharsToUnicodeString("- 23"), -23 },
7252 { "he", FALSE
, CharsToUnicodeString("\\u200E-23"), -23 },
7253 { "he", TRUE
, CharsToUnicodeString("\\u200E-23"), -23 },
7254 { "he", TRUE
, CharsToUnicodeString("\\u200E- 23"), -23 },
7256 { "ar", FALSE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7257 { "ar", TRUE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7258 { "ar", FALSE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7259 { "ar", TRUE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7260 { "ar", TRUE
, CharsToUnicodeString("- \\u0664\\u0665"), -45 },
7261 { "ar", FALSE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7262 { "ar", TRUE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7263 { "ar", TRUE
, CharsToUnicodeString("\\u200F- \\u0664\\u0665"), -45 },
7265 { "ar_MA", FALSE
, CharsToUnicodeString("12"), 12 },
7266 { "ar_MA", TRUE
, CharsToUnicodeString("12"), 12 },
7267 { "ar_MA", FALSE
, CharsToUnicodeString("-23"), -23 },
7268 { "ar_MA", TRUE
, CharsToUnicodeString("-23"), -23 },
7269 { "ar_MA", TRUE
, CharsToUnicodeString("- 23"), -23 },
7270 { "ar_MA", FALSE
, CharsToUnicodeString("\\u200E-23"), -23 },
7271 { "ar_MA", TRUE
, CharsToUnicodeString("\\u200E-23"), -23 },
7272 { "ar_MA", TRUE
, CharsToUnicodeString("\\u200E- 23"), -23 },
7274 { "fa", FALSE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7275 { "fa", TRUE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7276 { "fa", FALSE
, CharsToUnicodeString("\\u2212\\u06F6\\u06F7"), -67 },
7277 { "fa", TRUE
, CharsToUnicodeString("\\u2212\\u06F6\\u06F7"), -67 },
7278 { "fa", TRUE
, CharsToUnicodeString("\\u2212 \\u06F6\\u06F7"), -67 },
7279 { "fa", FALSE
, CharsToUnicodeString("\\u200E\\u2212\\u200E\\u06F6\\u06F7"), -67 },
7280 { "fa", TRUE
, CharsToUnicodeString("\\u200E\\u2212\\u200E\\u06F6\\u06F7"), -67 },
7281 { "fa", TRUE
, CharsToUnicodeString("\\u200E\\u2212\\u200E \\u06F6\\u06F7"), -67 },
7283 { "ps", FALSE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7284 { "ps", TRUE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7285 { "ps", FALSE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7286 { "ps", TRUE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7287 { "ps", TRUE
, CharsToUnicodeString("- \\u06F6\\u06F7"), -67 },
7288 { "ps", FALSE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7289 { "ps", TRUE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7290 { "ps", TRUE
, CharsToUnicodeString("\\u200E-\\u200E \\u06F6\\u06F7"), -67 },
7291 { "ps", FALSE
, CharsToUnicodeString("-\\u200E\\u06F6\\u06F7"), -67 },
7292 { "ps", TRUE
, CharsToUnicodeString("-\\u200E\\u06F6\\u06F7"), -67 },
7293 { "ps", TRUE
, CharsToUnicodeString("-\\u200E \\u06F6\\u06F7"), -67 },
7295 { NULL
, 0, UnicodeString(""), 0 },
7298 const SignsAndMarksItem
* itemPtr
;
7299 for (itemPtr
= items
; itemPtr
->locale
!= NULL
; itemPtr
++ ) {
7300 UErrorCode status
= U_ZERO_ERROR
;
7301 NumberFormat
*numfmt
= NumberFormat::createInstance(Locale(itemPtr
->locale
), status
);
7302 if (U_SUCCESS(status
)) {
7303 numfmt
->setLenient(itemPtr
->lenient
);
7306 numfmt
->parse(itemPtr
->numString
, fmtobj
, ppos
);
7307 if (ppos
.getIndex() == itemPtr
->numString
.length()) {
7308 double parsedValue
= fmtobj
.getDouble(status
);
7309 if (U_FAILURE(status
) || parsedValue
!= itemPtr
->value
) {
7310 errln((UnicodeString
)"FAIL: locale " + itemPtr
->locale
+ ", lenient " + itemPtr
->lenient
+ ", parse of \"" + itemPtr
->numString
+ "\" gives value " + parsedValue
);
7313 errln((UnicodeString
)"FAIL: locale " + itemPtr
->locale
+ ", lenient " + itemPtr
->lenient
+ ", parse of \"" + itemPtr
->numString
+ "\" gives position " + ppos
.getIndex());
7316 dataerrln("FAIL: NumberFormat::createInstance for locale % gives error %s", itemPtr
->locale
, u_errorName(status
));
7323 DecimalFormat::ERoundingMode mode
;
7325 UnicodeString expected
;
7329 // Tests that rounding works right when fractional digits is set to 0.
7330 void NumberFormatTest::Test10419RoundingWith0FractionDigits() {
7331 const Test10419Data items
[] = {
7332 { DecimalFormat::kRoundCeiling
, 1.488, "2"},
7333 { DecimalFormat::kRoundDown
, 1.588, "1"},
7334 { DecimalFormat::kRoundFloor
, 1.888, "1"},
7335 { DecimalFormat::kRoundHalfDown
, 1.5, "1"},
7336 { DecimalFormat::kRoundHalfEven
, 2.5, "2"},
7337 { DecimalFormat::kRoundHalfUp
, 2.5, "3"},
7338 { DecimalFormat::kRoundUp
, 1.5, "2"},
7340 UErrorCode status
= U_ZERO_ERROR
;
7341 LocalPointer
<DecimalFormat
> decfmt((DecimalFormat
*) NumberFormat::createInstance(Locale("en_US"), status
));
7342 if (U_FAILURE(status
)) {
7343 dataerrln("Failure creating DecimalFormat %s", u_errorName(status
));
7346 for (int32_t i
= 0; i
< (int32_t) (sizeof(items
) / sizeof(items
[0])); ++i
) {
7347 decfmt
->setRoundingMode(items
[i
].mode
);
7348 decfmt
->setMaximumFractionDigits(0);
7349 UnicodeString actual
;
7350 if (items
[i
].expected
!= decfmt
->format(items
[i
].value
, actual
)) {
7351 errln("Expected " + items
[i
].expected
+ ", got " + actual
);
7356 void NumberFormatTest::Test10468ApplyPattern() {
7357 // Padding char of fmt is now 'a'
7358 UErrorCode status
= U_ZERO_ERROR
;
7359 DecimalFormat
fmt("'I''ll'*a###.##", status
);
7361 if (U_FAILURE(status
)) {
7362 errcheckln(status
, "DecimalFormat constructor failed - %s", u_errorName(status
));
7366 if (fmt
.getPadCharacterString() != UnicodeString("a")) {
7367 errln("Padding character should be 'a'.");
7371 // Padding char of fmt ought to be '*' since that is the default and no
7372 // explicit padding char is specified in the new pattern.
7373 fmt
.applyPattern("AA#,##0.00ZZ", status
);
7375 // Oops this still prints 'a' even though we changed the pattern.
7376 if (fmt
.getPadCharacterString() != UnicodeString("*")) {
7377 errln("applyPattern did not clear padding character.");
7381 void NumberFormatTest::TestRoundingScientific10542() {
7382 UErrorCode status
= U_ZERO_ERROR
;
7383 DecimalFormat
format("0.00E0", status
);
7384 if (U_FAILURE(status
)) {
7385 errcheckln(status
, "DecimalFormat constructor failed - %s", u_errorName(status
));
7389 DecimalFormat::ERoundingMode roundingModes
[] = {
7390 DecimalFormat::kRoundCeiling
,
7391 DecimalFormat::kRoundDown
,
7392 DecimalFormat::kRoundFloor
,
7393 DecimalFormat::kRoundHalfDown
,
7394 DecimalFormat::kRoundHalfEven
,
7395 DecimalFormat::kRoundHalfUp
,
7396 DecimalFormat::kRoundUp
};
7397 const char *descriptions
[] = {
7407 double values
[] = {-0.003006, -0.003005, -0.003004, 0.003014, 0.003015, 0.003016};
7408 // The order of these expected values correspond to the order of roundingModes and the order of values.
7409 const char *expected
[] = {
7410 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.02E-3", "3.02E-3", "3.02E-3",
7411 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.01E-3",
7412 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.01E-3", "3.01E-3", "3.01E-3",
7413 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.02E-3",
7414 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E-3",
7415 "-3.01E-3", "-3.01E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E-3",
7416 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.02E-3", "3.02E-3", "3.02E-3"};
7423 (int32_t) (sizeof(values
) / sizeof(values
[0])),
7424 (int32_t) (sizeof(roundingModes
) / sizeof(roundingModes
[0])));
7427 double values
[] = {-3006.0, -3005, -3004, 3014, 3015, 3016};
7428 // The order of these expected values correspond to the order of roundingModes and the order of values.
7429 const char *expected
[] = {
7430 "-3.00E3", "-3.00E3", "-3.00E3", "3.02E3", "3.02E3", "3.02E3",
7431 "-3.00E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.01E3",
7432 "-3.01E3", "-3.01E3", "-3.01E3", "3.01E3", "3.01E3", "3.01E3",
7433 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.02E3",
7434 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3",
7435 "-3.01E3", "-3.01E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3",
7436 "-3.01E3", "-3.01E3", "-3.01E3", "3.02E3", "3.02E3", "3.02E3"};
7443 (int32_t) (sizeof(values
) / sizeof(values
[0])),
7444 (int32_t) (sizeof(roundingModes
) / sizeof(roundingModes
[0])));
7446 /* Commented out for now until we decide how rounding to zero should work, +0 vs. -0
7448 double values[] = {0.0, -0.0};
7449 // The order of these expected values correspond to the order of roundingModes and the order of values.
7450 const char *expected[] = {
7451 "0.00E0", "-0.00E0",
7452 "0.00E0", "-0.00E0",
7453 "0.00E0", "-0.00E0",
7454 "0.00E0", "-0.00E0",
7455 "0.00E0", "-0.00E0",
7456 "0.00E0", "-0.00E0",
7457 "0.00E0", "-0.00E0"};
7464 (int32_t) (sizeof(values) / sizeof(values[0])),
7465 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7470 double values
[] = {1e25
, 1e25
+ 1e15
, 1e25
- 1e15
};
7471 // The order of these expected values correspond to the order of roundingModes and the order of values.
7472 const char *expected
[] = {
7473 "1.00E25", "1.01E25", "1.00E25",
7474 "1.00E25", "1.00E25", "9.99E24",
7475 "1.00E25", "1.00E25", "9.99E24",
7476 "1.00E25", "1.00E25", "1.00E25",
7477 "1.00E25", "1.00E25", "1.00E25",
7478 "1.00E25", "1.00E25", "1.00E25",
7479 "1.00E25", "1.01E25", "1.00E25"};
7486 (int32_t) (sizeof(values
) / sizeof(values
[0])),
7487 (int32_t) (sizeof(roundingModes
) / sizeof(roundingModes
[0])));
7490 double values
[] = {-1e25
, -1e25
+ 1e15
, -1e25
- 1e15
};
7491 // The order of these expected values correspond to the order of roundingModes and the order of values.
7492 const char *expected
[] = {
7493 "-1.00E25", "-9.99E24", "-1.00E25",
7494 "-1.00E25", "-9.99E24", "-1.00E25",
7495 "-1.00E25", "-1.00E25", "-1.01E25",
7496 "-1.00E25", "-1.00E25", "-1.00E25",
7497 "-1.00E25", "-1.00E25", "-1.00E25",
7498 "-1.00E25", "-1.00E25", "-1.00E25",
7499 "-1.00E25", "-1.00E25", "-1.01E25"};
7506 (int32_t) (sizeof(values
) / sizeof(values
[0])),
7507 (int32_t) (sizeof(roundingModes
) / sizeof(roundingModes
[0])));
7510 double values
[] = {1e-25, 1e-25 + 1e-35, 1e-25 - 1e-35};
7511 // The order of these expected values correspond to the order of roundingModes and the order of values.
7512 const char *expected
[] = {
7513 "1.00E-25", "1.01E-25", "1.00E-25",
7514 "1.00E-25", "1.00E-25", "9.99E-26",
7515 "1.00E-25", "1.00E-25", "9.99E-26",
7516 "1.00E-25", "1.00E-25", "1.00E-25",
7517 "1.00E-25", "1.00E-25", "1.00E-25",
7518 "1.00E-25", "1.00E-25", "1.00E-25",
7519 "1.00E-25", "1.01E-25", "1.00E-25"};
7526 (int32_t) (sizeof(values
) / sizeof(values
[0])),
7527 (int32_t) (sizeof(roundingModes
) / sizeof(roundingModes
[0])));
7530 double values
[] = {-1e-25, -1e-25 + 1e-35, -1e-25 - 1e-35};
7531 // The order of these expected values correspond to the order of roundingModes and the order of values.
7532 const char *expected
[] = {
7533 "-1.00E-25", "-9.99E-26", "-1.00E-25",
7534 "-1.00E-25", "-9.99E-26", "-1.00E-25",
7535 "-1.00E-25", "-1.00E-25", "-1.01E-25",
7536 "-1.00E-25", "-1.00E-25", "-1.00E-25",
7537 "-1.00E-25", "-1.00E-25", "-1.00E-25",
7538 "-1.00E-25", "-1.00E-25", "-1.00E-25",
7539 "-1.00E-25", "-1.00E-25", "-1.01E-25"};
7546 (int32_t) (sizeof(values
) / sizeof(values
[0])),
7547 (int32_t) (sizeof(roundingModes
) / sizeof(roundingModes
[0])));
7551 void NumberFormatTest::TestZeroScientific10547() {
7552 UErrorCode status
= U_ZERO_ERROR
;
7553 DecimalFormat
fmt("0.00E0", status
);
7554 if (!assertSuccess("Formt creation", status
)) {
7558 fmt
.format(-0.0, out
);
7559 assertEquals("format", "-0.00E0", out
);
7562 void NumberFormatTest::verifyRounding(
7563 DecimalFormat
& format
,
7564 const double *values
,
7565 const char * const *expected
,
7566 const DecimalFormat::ERoundingMode
*roundingModes
,
7567 const char * const *descriptions
,
7569 int32_t roundingModeSize
) {
7570 for (int32_t i
= 0; i
< roundingModeSize
; ++i
) {
7571 format
.setRoundingMode(roundingModes
[i
]);
7572 for (int32_t j
= 0; j
< valueSize
; j
++) {
7573 UnicodeString
currentExpected(expected
[i
* valueSize
+ j
]);
7574 currentExpected
= currentExpected
.unescape();
7575 UnicodeString actual
;
7576 format
.format(values
[j
], actual
);
7577 if (currentExpected
!= actual
) {
7581 "For %s value %f, expected ",
7584 errln(UnicodeString(buffer
) + currentExpected
+ ", got " + actual
);
7590 void NumberFormatTest::TestAccountingCurrency() {
7591 UErrorCode status
= U_ZERO_ERROR
;
7592 UNumberFormatStyle style
= UNUM_CURRENCY_ACCOUNTING
;
7594 expect(NumberFormat::createInstance("en_US", style
, status
),
7595 (Formattable
)1234.5, "$1,234.50", TRUE
, status
);
7596 expect(NumberFormat::createInstance("en_US", style
, status
),
7597 (Formattable
)-1234.5, "($1,234.50)", TRUE
, status
);
7598 expect(NumberFormat::createInstance("en_US", style
, status
),
7599 (Formattable
)0, "$0.00", TRUE
, status
);
7600 expect(NumberFormat::createInstance("en_US", style
, status
),
7601 (Formattable
)-0.2, "($0.20)", TRUE
, status
);
7602 expect(NumberFormat::createInstance("ja_JP", style
, status
),
7603 (Formattable
)10000, UnicodeString("\\u00A510,000").unescape(), TRUE
, status
);
7604 expect(NumberFormat::createInstance("ja_JP", style
, status
),
7605 (Formattable
)-1000.5, UnicodeString("(\\u00A51,000)").unescape(), FALSE
, status
);
7606 expect(NumberFormat::createInstance("de_DE", style
, status
),
7607 (Formattable
)-23456.7, UnicodeString("-23.456,70\\u00A0\\u20AC").unescape(), TRUE
, status
);
7611 void NumberFormatTest::TestEquality() {
7612 UErrorCode status
= U_ZERO_ERROR
;
7613 DecimalFormatSymbols
* symbols
= new DecimalFormatSymbols(Locale("root"), status
);
7614 if (U_FAILURE(status
)) {
7615 dataerrln("Fail: can't create DecimalFormatSymbols for root");
7618 UnicodeString
pattern("#,##0.###");
7619 DecimalFormat
* fmtBase
= new DecimalFormat(pattern
, symbols
, status
);
7620 if (U_FAILURE(status
)) {
7621 dataerrln("Fail: can't create DecimalFormat using root symbols");
7625 DecimalFormat
* fmtClone
= (DecimalFormat
*)fmtBase
->clone();
7626 fmtClone
->setFormatWidth(fmtBase
->getFormatWidth() + 32);
7627 if (*fmtClone
== *fmtBase
) {
7628 errln("Error: DecimalFormat == does not distinguish objects that differ only in FormatWidth");
7635 void NumberFormatTest::TestCurrencyUsage() {
7636 double agent
= 123.567;
7641 // compare the Currency and Currency Cash Digits
7642 // Note that as of CLDR 26:
7643 // * TWD switches from 0 decimals to 2; PKR still has 0, so change test to that
7644 // * CAD and all other currencies that rounded to .05 no longer do
7645 // 1st time for getter/setter, 2nd time for factory method
7646 Locale
enUS_PKR("en_US@currency=PKR");
7648 for(int i
=0; i
<2; i
++){
7649 status
= U_ZERO_ERROR
;
7651 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_PKR
, UNUM_CURRENCY
, status
);
7652 if (assertSuccess("en_US@currency=PKR/CURRENCY", status
, TRUE
) == FALSE
) {
7656 UnicodeString original
;
7657 fmt
->format(agent
,original
);
7658 assertEquals("Test Currency Usage 1", UnicodeString("PKR124"), original
);
7660 // test the getter here
7661 UCurrencyUsage curUsage
= fmt
->getCurrencyUsage();
7662 assertEquals("Test usage getter - standard", curUsage
, UCURR_USAGE_STANDARD
);
7664 fmt
->setCurrencyUsage(UCURR_USAGE_CASH
, &status
);
7666 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_PKR
, UNUM_CASH_CURRENCY
, status
);
7667 if (assertSuccess("en_US@currency=PKR/CASH", status
, TRUE
) == FALSE
) {
7672 // must be usage = cash
7673 UCurrencyUsage curUsage
= fmt
->getCurrencyUsage();
7674 assertEquals("Test usage getter - cash", curUsage
, UCURR_USAGE_CASH
);
7676 UnicodeString cash_currency
;
7677 fmt
->format(agent
,cash_currency
);
7678 assertEquals("Test Currency Usage 2", UnicodeString("PKR124"), cash_currency
);
7682 // compare the Currency and Currency Cash Rounding
7683 // 1st time for getter/setter, 2nd time for factory method
7684 Locale
enUS_CAD("en_US@currency=CAD");
7685 for(int i
=0; i
<2; i
++){
7686 status
= U_ZERO_ERROR
;
7688 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CURRENCY
, status
);
7689 if (assertSuccess("en_US@currency=CAD/CURRENCY", status
, TRUE
) == FALSE
) {
7693 UnicodeString original_rounding
;
7694 fmt
->format(agent
, original_rounding
);
7695 assertEquals("Test Currency Usage 3", UnicodeString("CA$123.57"), original_rounding
);
7696 fmt
->setCurrencyUsage(UCURR_USAGE_CASH
, &status
);
7698 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CASH_CURRENCY
, status
);
7699 if (assertSuccess("en_US@currency=CAD/CASH", status
, TRUE
) == FALSE
) {
7704 UnicodeString cash_rounding_currency
;
7705 fmt
->format(agent
, cash_rounding_currency
);
7706 assertEquals("Test Currency Usage 4", UnicodeString("CA$123.57"), cash_rounding_currency
);
7710 // Test the currency change
7711 // 1st time for getter/setter, 2nd time for factory method
7712 const UChar CUR_PKR
[] = {0x50, 0x4B, 0x52, 0};
7713 for(int i
=0; i
<2; i
++){
7714 status
= U_ZERO_ERROR
;
7716 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CURRENCY
, status
);
7717 if (assertSuccess("en_US@currency=CAD/CURRENCY", status
, TRUE
) == FALSE
) {
7720 fmt
->setCurrencyUsage(UCURR_USAGE_CASH
, &status
);
7722 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CASH_CURRENCY
, status
);
7723 if (assertSuccess("en_US@currency=CAD/CASH", status
, TRUE
) == FALSE
) {
7728 UnicodeString cur_original
;
7729 fmt
->format(agent
, cur_original
);
7730 assertEquals("Test Currency Usage 5", UnicodeString("CA$123.57"), cur_original
);
7732 fmt
->setCurrency(CUR_PKR
, status
);
7733 assertSuccess("Set currency to PKR", status
);
7735 UnicodeString PKR_changed
;
7736 fmt
->format(agent
, PKR_changed
);
7737 assertEquals("Test Currency Usage 6", UnicodeString("PKR124"), PKR_changed
);
7743 // Check the constant MAX_INT64_IN_DOUBLE.
7744 // The value should convert to a double with no loss of precision.
7745 // A failure may indicate a platform with a different double format, requiring
7746 // a revision to the constant.
7748 // Note that this is actually hard to test, because the language standard gives
7749 // compilers considerable flexibility to do unexpected things with rounding and
7750 // with overflow in simple int to/from float conversions. Some compilers will completely optimize
7751 // away a simple round-trip conversion from int64_t -> double -> int64_t.
7753 void NumberFormatTest::TestDoubleLimit11439() {
7755 for (int64_t num
= MAX_INT64_IN_DOUBLE
-10; num
<=MAX_INT64_IN_DOUBLE
; num
++) {
7756 sprintf(buf
, "%lld", (long long)num
);
7758 sscanf(buf
, "%lf", &fNum
);
7759 int64_t rtNum
= fNum
;
7761 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__
, __LINE__
, (long long)num
, (long long)rtNum
);
7765 for (int64_t num
= -MAX_INT64_IN_DOUBLE
+10; num
>=-MAX_INT64_IN_DOUBLE
; num
--) {
7766 sprintf(buf
, "%lld", (long long)num
);
7768 sscanf(buf
, "%lf", &fNum
);
7769 int64_t rtNum
= fNum
;
7771 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__
, __LINE__
, (long long)num
, (long long)rtNum
);
7777 void NumberFormatTest::TestFastPathConsistent11524() {
7778 UErrorCode status
= U_ZERO_ERROR
;
7779 NumberFormat
*fmt
= NumberFormat::createInstance("en", status
);
7780 if (U_FAILURE(status
) || fmt
== NULL
) {
7781 dataerrln("Failed call to NumberFormat::createInstance() - %s", u_errorName(status
));
7784 fmt
->setMaximumIntegerDigits(INT32_MIN
);
7785 UnicodeString appendTo
;
7786 assertEquals("", "0", fmt
->format(123, appendTo
));
7788 assertEquals("", "0", fmt
->format(12345, appendTo
));
7793 #endif /* #if !UCONFIG_NO_FORMATTING */