1 /********************************************************************
3 * Copyright (c) 1997-2016, 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"
34 #include "unicode/numsys.h"
35 #include "fmtableimp.h"
36 #include "numberformattesttuple.h"
37 #include "datadrivennumberformattestsuite.h"
38 #include "unicode/msgfmt.h"
40 class NumberFormatTestDataDriven
: public DataDrivenNumberFormatTestSuite
{
43 const NumberFormatTestTuple
&tuple
,
44 UnicodeString
&appendErrorMessage
,
46 UBool
isToPatternPass(
47 const NumberFormatTestTuple
&tuple
,
48 UnicodeString
&appendErrorMessage
,
51 const NumberFormatTestTuple
&tuple
,
52 UnicodeString
&appendErrorMessage
,
54 UBool
isParseCurrencyPass(
55 const NumberFormatTestTuple
&tuple
,
56 UnicodeString
&appendErrorMessage
,
60 static DigitList
&strToDigitList(
61 const UnicodeString
&str
,
64 if (U_FAILURE(status
)) {
68 digitList
.set(uprv_getNaN());
72 digitList
.set(-1*uprv_getInfinity());
76 digitList
.set(uprv_getInfinity());
79 CharString formatValue
;
80 formatValue
.appendInvariantChars(str
, status
);
81 digitList
.set(StringPiece(formatValue
.data()), status
, 0);
85 static UnicodeString
&format(
86 const DecimalFormat
&fmt
,
87 const DigitList
&digitList
,
88 UnicodeString
&appendTo
,
90 if (U_FAILURE(status
)) {
93 FieldPosition
fpos(FieldPosition::DONT_CARE
);
94 return fmt
.format(digitList
, appendTo
, fpos
, status
);
98 static UnicodeString
&format(
99 const DecimalFormat
&fmt
,
101 UnicodeString
&appendTo
,
102 UErrorCode
&status
) {
103 if (U_FAILURE(status
)) {
106 FieldPosition
fpos(FieldPosition::DONT_CARE
);
107 return fmt
.format(value
, appendTo
, fpos
, status
);
110 static void adjustDecimalFormat(
111 const NumberFormatTestTuple
&tuple
,
113 UnicodeString
&appendErrorMessage
) {
114 if (tuple
.minIntegerDigitsFlag
) {
115 fmt
.setMinimumIntegerDigits(tuple
.minIntegerDigits
);
117 if (tuple
.maxIntegerDigitsFlag
) {
118 fmt
.setMaximumIntegerDigits(tuple
.maxIntegerDigits
);
120 if (tuple
.minFractionDigitsFlag
) {
121 fmt
.setMinimumFractionDigits(tuple
.minFractionDigits
);
123 if (tuple
.maxFractionDigitsFlag
) {
124 fmt
.setMaximumFractionDigits(tuple
.maxFractionDigits
);
126 if (tuple
.currencyFlag
) {
127 UErrorCode status
= U_ZERO_ERROR
;
128 UnicodeString
currency(tuple
.currency
);
129 const UChar
*terminatedCurrency
= currency
.getTerminatedBuffer();
130 fmt
.setCurrency(terminatedCurrency
, status
);
131 if (U_FAILURE(status
)) {
132 appendErrorMessage
.append("Error setting currency.");
135 if (tuple
.minGroupingDigitsFlag
) {
136 fmt
.setMinimumGroupingDigits(tuple
.minGroupingDigits
);
138 if (tuple
.useSigDigitsFlag
) {
139 fmt
.setSignificantDigitsUsed(tuple
.useSigDigits
!= 0);
141 if (tuple
.minSigDigitsFlag
) {
142 fmt
.setMinimumSignificantDigits(tuple
.minSigDigits
);
144 if (tuple
.maxSigDigitsFlag
) {
145 fmt
.setMaximumSignificantDigits(tuple
.maxSigDigits
);
147 if (tuple
.useGroupingFlag
) {
148 fmt
.setGroupingUsed(tuple
.useGrouping
!= 0);
150 if (tuple
.multiplierFlag
) {
151 fmt
.setMultiplier(tuple
.multiplier
);
153 if (tuple
.roundingIncrementFlag
) {
154 fmt
.setRoundingIncrement(tuple
.roundingIncrement
);
156 if (tuple
.formatWidthFlag
) {
157 fmt
.setFormatWidth(tuple
.formatWidth
);
159 if (tuple
.padCharacterFlag
) {
160 fmt
.setPadCharacter(tuple
.padCharacter
);
162 if (tuple
.useScientificFlag
) {
163 fmt
.setScientificNotation(tuple
.useScientific
!= 0);
165 if (tuple
.groupingFlag
) {
166 fmt
.setGroupingSize(tuple
.grouping
);
168 if (tuple
.grouping2Flag
) {
169 fmt
.setSecondaryGroupingSize(tuple
.grouping2
);
171 if (tuple
.roundingModeFlag
) {
172 fmt
.setRoundingMode(tuple
.roundingMode
);
174 if (tuple
.currencyUsageFlag
) {
175 UErrorCode status
= U_ZERO_ERROR
;
176 fmt
.setCurrencyUsage(tuple
.currencyUsage
, &status
);
177 if (U_FAILURE(status
)) {
178 appendErrorMessage
.append("CurrencyUsage: error setting.");
181 if (tuple
.minimumExponentDigitsFlag
) {
182 fmt
.setMinimumExponentDigits(tuple
.minimumExponentDigits
);
184 if (tuple
.exponentSignAlwaysShownFlag
) {
185 fmt
.setExponentSignAlwaysShown(tuple
.exponentSignAlwaysShown
!= 0);
187 if (tuple
.decimalSeparatorAlwaysShownFlag
) {
188 fmt
.setDecimalSeparatorAlwaysShown(
189 tuple
.decimalSeparatorAlwaysShown
!= 0);
191 if (tuple
.padPositionFlag
) {
192 fmt
.setPadPosition(tuple
.padPosition
);
194 if (tuple
.positivePrefixFlag
) {
195 fmt
.setPositivePrefix(tuple
.positivePrefix
);
197 if (tuple
.positiveSuffixFlag
) {
198 fmt
.setPositiveSuffix(tuple
.positiveSuffix
);
200 if (tuple
.negativePrefixFlag
) {
201 fmt
.setNegativePrefix(tuple
.negativePrefix
);
203 if (tuple
.negativeSuffixFlag
) {
204 fmt
.setNegativeSuffix(tuple
.negativeSuffix
);
206 if (tuple
.localizedPatternFlag
) {
207 UErrorCode status
= U_ZERO_ERROR
;
208 fmt
.applyLocalizedPattern(tuple
.localizedPattern
, status
);
209 if (U_FAILURE(status
)) {
210 appendErrorMessage
.append("Error setting localized pattern.");
213 fmt
.setLenient(NFTT_GET_FIELD(tuple
, lenient
, 1) != 0);
214 if (tuple
.parseIntegerOnlyFlag
) {
215 fmt
.setParseIntegerOnly(tuple
.parseIntegerOnly
!= 0);
217 if (tuple
.decimalPatternMatchRequiredFlag
) {
218 fmt
.setDecimalPatternMatchRequired(
219 tuple
.decimalPatternMatchRequired
!= 0);
221 if (tuple
.parseNoExponentFlag
) {
222 UErrorCode status
= U_ZERO_ERROR
;
224 UNUM_PARSE_NO_EXPONENT
,
225 tuple
.parseNoExponent
,
227 if (U_FAILURE(status
)) {
228 appendErrorMessage
.append("Error setting parse no exponent flag.");
233 static DecimalFormat
*newDecimalFormat(
234 const Locale
&locale
,
235 const UnicodeString
&pattern
,
236 UErrorCode
&status
) {
237 if (U_FAILURE(status
)) {
240 LocalPointer
<DecimalFormatSymbols
> symbols(
241 new DecimalFormatSymbols(locale
, status
), status
);
242 if (U_FAILURE(status
)) {
246 LocalPointer
<DecimalFormat
> result(new DecimalFormat(
247 pattern
, symbols
.getAlias(), perror
, status
), status
);
248 if (!result
.isNull()) {
251 if (U_FAILURE(status
)) {
254 return result
.orphan();
257 static DecimalFormat
*newDecimalFormat(
258 const NumberFormatTestTuple
&tuple
,
259 UErrorCode
&status
) {
260 if (U_FAILURE(status
)) {
264 return newDecimalFormat(
265 NFTT_GET_FIELD(tuple
, locale
, en
),
266 NFTT_GET_FIELD(tuple
, pattern
, "0"),
270 UBool
NumberFormatTestDataDriven::isFormatPass(
271 const NumberFormatTestTuple
&tuple
,
272 UnicodeString
&appendErrorMessage
,
273 UErrorCode
&status
) {
274 if (U_FAILURE(status
)) {
277 LocalPointer
<DecimalFormat
> fmtPtr(newDecimalFormat(tuple
, status
));
278 if (U_FAILURE(status
)) {
279 appendErrorMessage
.append("Error creating DecimalFormat.");
282 adjustDecimalFormat(tuple
, *fmtPtr
, appendErrorMessage
);
283 if (appendErrorMessage
.length() > 0) {
287 strToDigitList(tuple
.format
, digitList
, status
);
289 UnicodeString appendTo
;
290 format(*fmtPtr
, digitList
, appendTo
, status
);
291 if (U_FAILURE(status
)) {
292 appendErrorMessage
.append("Error formatting.");
295 if (appendTo
!= tuple
.output
) {
296 appendErrorMessage
.append(
297 UnicodeString("Expected: ") + tuple
.output
+ ", got: " + appendTo
);
301 double doubleVal
= digitList
.getDouble();
303 UnicodeString appendTo
;
304 format(*fmtPtr
, doubleVal
, appendTo
, status
);
305 if (U_FAILURE(status
)) {
306 appendErrorMessage
.append("Error formatting.");
309 if (appendTo
!= tuple
.output
) {
310 appendErrorMessage
.append(
311 UnicodeString("double Expected: ") + tuple
.output
+ ", got: " + appendTo
);
315 if (!uprv_isNaN(doubleVal
) && !uprv_isInfinite(doubleVal
) && doubleVal
== uprv_floor(doubleVal
)) {
316 int64_t intVal
= digitList
.getInt64();
318 UnicodeString appendTo
;
319 format(*fmtPtr
, intVal
, appendTo
, status
);
320 if (U_FAILURE(status
)) {
321 appendErrorMessage
.append("Error formatting.");
324 if (appendTo
!= tuple
.output
) {
325 appendErrorMessage
.append(
326 UnicodeString("int64 Expected: ") + tuple
.output
+ ", got: " + appendTo
);
334 UBool
NumberFormatTestDataDriven::isToPatternPass(
335 const NumberFormatTestTuple
&tuple
,
336 UnicodeString
&appendErrorMessage
,
337 UErrorCode
&status
) {
338 if (U_FAILURE(status
)) {
341 LocalPointer
<DecimalFormat
> fmtPtr(newDecimalFormat(tuple
, status
));
342 if (U_FAILURE(status
)) {
343 appendErrorMessage
.append("Error creating DecimalFormat.");
346 adjustDecimalFormat(tuple
, *fmtPtr
, appendErrorMessage
);
347 if (appendErrorMessage
.length() > 0) {
350 if (tuple
.toPatternFlag
) {
351 UnicodeString actual
;
352 fmtPtr
->toPattern(actual
);
353 if (actual
!= tuple
.toPattern
) {
354 appendErrorMessage
.append(
355 UnicodeString("Expected: ") + tuple
.toPattern
+ ", got: " + actual
+ ". ");
358 if (tuple
.toLocalizedPatternFlag
) {
359 UnicodeString actual
;
360 fmtPtr
->toLocalizedPattern(actual
);
361 if (actual
!= tuple
.toLocalizedPattern
) {
362 appendErrorMessage
.append(
363 UnicodeString("Expected: ") + tuple
.toLocalizedPattern
+ ", got: " + actual
+ ". ");
366 return appendErrorMessage
.length() == 0;
369 UBool
NumberFormatTestDataDriven::isParsePass(
370 const NumberFormatTestTuple
&tuple
,
371 UnicodeString
&appendErrorMessage
,
372 UErrorCode
&status
) {
373 if (U_FAILURE(status
)) {
376 LocalPointer
<DecimalFormat
> fmtPtr(newDecimalFormat(tuple
, status
));
377 if (U_FAILURE(status
)) {
378 appendErrorMessage
.append("Error creating DecimalFormat.");
381 adjustDecimalFormat(tuple
, *fmtPtr
, appendErrorMessage
);
382 if (appendErrorMessage
.length() > 0) {
387 fmtPtr
->parse(tuple
.parse
, result
, ppos
);
388 if (ppos
.getIndex() == 0) {
389 if (tuple
.output
!= "fail") {
390 appendErrorMessage
.append("Parse failed but was expected to succeed.");
395 UnicodeString
resultStr(UnicodeString::fromUTF8(result
.getDecimalNumber(status
)));
396 if (tuple
.output
== "fail") {
397 appendErrorMessage
.append(UnicodeString("Parse succeeded: ") + resultStr
+ ", but was expected to fail.");
401 strToDigitList(tuple
.output
, expected
, status
);
402 if (U_FAILURE(status
)) {
403 appendErrorMessage
.append("Error parsing.");
406 if (expected
!= *result
.getDigitList()) {
407 appendErrorMessage
.append(
408 UnicodeString("Expected: ") + tuple
.output
+ ", got: " + resultStr
+ ". ");
414 UBool
NumberFormatTestDataDriven::isParseCurrencyPass(
415 const NumberFormatTestTuple
&tuple
,
416 UnicodeString
&appendErrorMessage
,
417 UErrorCode
&status
) {
418 if (U_FAILURE(status
)) {
421 LocalPointer
<DecimalFormat
> fmtPtr(newDecimalFormat(tuple
, status
));
422 if (U_FAILURE(status
)) {
423 appendErrorMessage
.append("Error creating DecimalFormat.");
426 adjustDecimalFormat(tuple
, *fmtPtr
, appendErrorMessage
);
427 if (appendErrorMessage
.length() > 0) {
431 LocalPointer
<CurrencyAmount
> currAmt(
432 fmtPtr
->parseCurrency(tuple
.parse
, ppos
));
433 if (ppos
.getIndex() == 0) {
434 if (tuple
.output
!= "fail") {
435 appendErrorMessage
.append("Parse failed but was expected to succeed.");
440 UnicodeString
currStr(currAmt
->getISOCurrency());
441 Formattable
resultFormattable(currAmt
->getNumber());
442 UnicodeString
resultStr(UnicodeString::fromUTF8(resultFormattable
.getDecimalNumber(status
)));
443 if (tuple
.output
== "fail") {
444 appendErrorMessage
.append(UnicodeString("Parse succeeded: ") + resultStr
+ ", but was expected to fail.");
448 strToDigitList(tuple
.output
, expected
, status
);
449 if (U_FAILURE(status
)) {
450 appendErrorMessage
.append("Error parsing.");
453 if (expected
!= *currAmt
->getNumber().getDigitList()) {
454 appendErrorMessage
.append(
455 UnicodeString("Expected: ") + tuple
.output
+ ", got: " + resultStr
+ ". ");
458 if (currStr
!= tuple
.outputCurrency
) {
459 appendErrorMessage
.append(UnicodeString(
460 "Expected currency: ") + tuple
.outputCurrency
+ ", got: " + currStr
+ ". ");
466 //#define NUMFMTST_CACHE_DEBUG 1
467 #include "stdio.h" /* for sprintf */
468 // #include "iostream" // for cout
470 //#define NUMFMTST_DEBUG 1
472 static const UChar EUR
[] = {69,85,82,0}; // "EUR"
473 static const UChar ISO_CURRENCY_USD
[] = {0x55, 0x53, 0x44, 0}; // "USD"
476 // *****************************************************************************
477 // class NumberFormatTest
478 // *****************************************************************************
480 #define CHECK(status,str) if (U_FAILURE(status)) { errcheckln(status, UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
481 #define CHECK_DATA(status,str) if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
483 void NumberFormatTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
486 TESTCASE_AUTO(TestCurrencySign
);
487 TESTCASE_AUTO(TestCurrency
);
488 TESTCASE_AUTO(TestParse
);
489 TESTCASE_AUTO(TestRounding487
);
490 TESTCASE_AUTO(TestQuotes
);
491 TESTCASE_AUTO(TestExponential
);
492 TESTCASE_AUTO(TestPatterns
);
494 // Upgrade to alphaWorks - liu 5/99
495 TESTCASE_AUTO(TestExponent
);
496 TESTCASE_AUTO(TestScientific
);
497 TESTCASE_AUTO(TestPad
);
498 TESTCASE_AUTO(TestPatterns2
);
499 TESTCASE_AUTO(TestSecondaryGrouping
);
500 TESTCASE_AUTO(TestSurrogateSupport
);
501 TESTCASE_AUTO(TestAPI
);
503 TESTCASE_AUTO(TestCurrencyObject
);
504 TESTCASE_AUTO(TestCurrencyPatterns
);
505 //TESTCASE_AUTO(TestDigitList);
506 TESTCASE_AUTO(TestWhiteSpaceParsing
);
507 TESTCASE_AUTO(TestComplexCurrency
); // This test removed because CLDR no longer uses choice formats in currency symbols.
508 TESTCASE_AUTO(TestRegCurrency
);
509 TESTCASE_AUTO(TestSymbolsWithBadLocale
);
510 TESTCASE_AUTO(TestAdoptDecimalFormatSymbols
);
512 TESTCASE_AUTO(TestScientific2
);
513 TESTCASE_AUTO(TestScientificGrouping
);
514 TESTCASE_AUTO(TestInt64
);
516 TESTCASE_AUTO(TestPerMill
);
517 TESTCASE_AUTO(TestIllegalPatterns
);
518 TESTCASE_AUTO(TestCases
);
520 TESTCASE_AUTO(TestCurrencyNames
);
521 TESTCASE_AUTO(TestCurrencyAmount
);
522 TESTCASE_AUTO(TestCurrencyUnit
);
523 TESTCASE_AUTO(TestCoverage
);
524 TESTCASE_AUTO(TestJB3832
);
525 TESTCASE_AUTO(TestHost
);
526 TESTCASE_AUTO(TestHostClone
);
527 TESTCASE_AUTO(TestCurrencyFormat
);
528 TESTCASE_AUTO(TestRounding
);
529 TESTCASE_AUTO(TestNonpositiveMultiplier
);
530 TESTCASE_AUTO(TestNumberingSystems
);
531 TESTCASE_AUTO(TestSpaceParsing
);
532 TESTCASE_AUTO(TestMultiCurrencySign
);
533 TESTCASE_AUTO(TestCurrencyFormatForMixParsing
);
534 TESTCASE_AUTO(TestDecimalFormatCurrencyParse
);
535 TESTCASE_AUTO(TestCurrencyIsoPluralFormat
);
536 TESTCASE_AUTO(TestCurrencyParsing
);
537 TESTCASE_AUTO(TestParseCurrencyInUCurr
);
538 TESTCASE_AUTO(TestFormatAttributes
);
539 TESTCASE_AUTO(TestFieldPositionIterator
);
540 TESTCASE_AUTO(TestDecimal
);
541 TESTCASE_AUTO(TestCurrencyFractionDigits
);
542 TESTCASE_AUTO(TestExponentParse
);
543 TESTCASE_AUTO(TestExplicitParents
);
544 TESTCASE_AUTO(TestLenientParse
);
545 TESTCASE_AUTO(TestAvailableNumberingSystems
);
546 TESTCASE_AUTO(TestRoundingPattern
);
547 TESTCASE_AUTO(Test9087
);
548 TESTCASE_AUTO(TestFormatFastpaths
);
549 TESTCASE_AUTO(TestFormattableSize
);
550 TESTCASE_AUTO(TestUFormattable
);
551 TESTCASE_AUTO(TestSignificantDigits
);
552 TESTCASE_AUTO(TestShowZero
);
553 TESTCASE_AUTO(TestCompatibleCurrencies
);
554 TESTCASE_AUTO(TestBug9936
);
555 TESTCASE_AUTO(TestParseNegativeWithFaLocale
);
556 TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign
);
557 TESTCASE_AUTO(TestCustomCurrencySignAndSeparator
);
558 TESTCASE_AUTO(TestParseSignsAndMarks
);
559 TESTCASE_AUTO(Test10419RoundingWith0FractionDigits
);
560 TESTCASE_AUTO(Test10468ApplyPattern
);
561 TESTCASE_AUTO(TestRoundingScientific10542
);
562 TESTCASE_AUTO(TestZeroScientific10547
);
563 TESTCASE_AUTO(TestAccountingCurrency
);
564 TESTCASE_AUTO(TestEquality
);
565 TESTCASE_AUTO(TestCurrencyUsage
);
566 TESTCASE_AUTO(TestNumberFormatTestTuple
);
567 TESTCASE_AUTO(TestDataDriven
);
568 TESTCASE_AUTO(TestDoubleLimit11439
);
569 TESTCASE_AUTO(TestFastPathConsistent11524
);
570 TESTCASE_AUTO(TestGetAffixes
);
571 TESTCASE_AUTO(TestToPatternScientific11648
);
572 TESTCASE_AUTO(TestBenchmark
);
573 TESTCASE_AUTO(TestCtorApplyPatternDifference
);
574 TESTCASE_AUTO(TestFractionalDigitsForCurrency
);
575 TESTCASE_AUTO(TestFormatCurrencyPlural
);
576 TESTCASE_AUTO(Test11868
);
577 TESTCASE_AUTO(Test10727_RoundingZero
);
578 TESTCASE_AUTO(Test11376_getAndSetPositivePrefix
);
579 TESTCASE_AUTO(Test11475_signRecognition
);
580 TESTCASE_AUTO(Test11640_getAffixes
);
581 TESTCASE_AUTO(Test11649_toPatternWithMultiCurrency
);
585 // -------------------------------------
587 // Test API (increase code coverage)
589 NumberFormatTest::TestAPI(void)
592 UErrorCode status
= U_ZERO_ERROR
;
593 NumberFormat
*test
= NumberFormat::createInstance("root", status
);
594 if(U_FAILURE(status
)) {
595 dataerrln("unable to create format object - %s", u_errorName(status
));
598 test
->setMinimumIntegerDigits(10);
599 test
->setMaximumIntegerDigits(2);
601 test
->setMinimumFractionDigits(10);
602 test
->setMaximumFractionDigits(2);
604 UnicodeString result
;
606 Formattable
bla("Paja Patak"); // Donald Duck for non Serbian speakers
607 test
->format(bla
, result
, pos
, status
);
608 if(U_SUCCESS(status
)) {
609 errln("Yuck... Formatted a duck... As a number!");
611 status
= U_ZERO_ERROR
;
616 test
->format(ll
, result
);
617 if (result
!= "12.00"){
618 errln("format int64_t error");
622 LocalPointer
<CurrencyAmount
> currAmt(test
->parseCurrency("",ppos
));
623 // old test for (U_FAILURE(status)) was bogus here, method does not set status!
624 if (ppos
.getIndex()) {
625 errln("Parsed empty string as currency");
632 class StubNumberFormat
:public NumberFormat
{
634 StubNumberFormat(){};
635 virtual UnicodeString
& format(double ,UnicodeString
& appendTo
,FieldPosition
& ) const {
638 virtual UnicodeString
& format(int32_t ,UnicodeString
& appendTo
,FieldPosition
& ) const {
639 return appendTo
.append((UChar
)0x0033);
641 virtual UnicodeString
& format(int64_t number
,UnicodeString
& appendTo
,FieldPosition
& pos
) const {
642 return NumberFormat::format(number
, appendTo
, pos
);
644 virtual UnicodeString
& format(const Formattable
& , UnicodeString
& appendTo
, FieldPosition
& , UErrorCode
& ) const {
647 virtual void parse(const UnicodeString
& ,
649 ParsePosition
& ) const {}
650 virtual void parse( const UnicodeString
& ,
652 UErrorCode
& ) const {}
653 virtual UClassID
getDynamicClassID(void) const {
654 static char classID
= 0;
655 return (UClassID
)&classID
;
657 virtual Format
* clone() const {return NULL
;}
661 NumberFormatTest::TestCoverage(void){
662 StubNumberFormat stub
;
663 UnicodeString
agent("agent");
666 if (stub
.format(num
, agent
, pos
) != UnicodeString("agent3")){
667 errln("NumberFormat::format(int64, UnicodString&, FieldPosition&) should delegate to (int32, ,)");
671 // Test various patterns
673 NumberFormatTest::TestPatterns(void)
675 UErrorCode status
= U_ZERO_ERROR
;
676 DecimalFormatSymbols
sym(Locale::getUS(), status
);
677 if (U_FAILURE(status
)) { errcheckln(status
, "FAIL: Could not construct DecimalFormatSymbols - %s", u_errorName(status
)); return; }
679 const char* pat
[] = { "#.#", "#.", ".#", "#" };
680 int32_t pat_length
= UPRV_LENGTHOF(pat
);
681 const char* newpat
[] = { "#0.#", "#0.", "#.0", "#" };
682 const char* num
[] = { "0", "0.", ".0", "0" };
683 for (int32_t i
=0; i
<pat_length
; ++i
)
685 status
= U_ZERO_ERROR
;
686 DecimalFormat
fmt(pat
[i
], sym
, status
);
687 if (U_FAILURE(status
)) { errln((UnicodeString
)"FAIL: DecimalFormat constructor failed for " + pat
[i
]); continue; }
688 UnicodeString newp
; fmt
.toPattern(newp
);
689 if (!(newp
== newpat
[i
]))
690 errln((UnicodeString
)"FAIL: Pattern " + pat
[i
] + " should transmute to " + newpat
[i
] +
691 "; " + newp
+ " seen instead");
693 UnicodeString s
; (*(NumberFormat
*)&fmt
).format((int32_t)0, s
);
696 errln((UnicodeString
)"FAIL: Pattern " + pat
[i
] + " should format zero as " + num
[i
] +
697 "; " + s
+ " seen instead");
698 logln((UnicodeString
)"Min integer digits = " + fmt
.getMinimumIntegerDigits());
704 icu_2_4::DigitList::operator== 0 0 2 icuuc24d.dll digitlst.cpp Doug
705 icu_2_4::DigitList::append 0 0 4 icuin24d.dll digitlst.h Doug
706 icu_2_4::DigitList::operator!= 0 0 1 icuuc24d.dll digitlst.h Doug
710 NumberFormatTest::TestDigitList(void)
712 // API coverage for DigitList
715 list1.fDecimalAt = 1;
717 list2.set((int32_t)1);
718 if (list1 != list2) {
719 errln("digitlist append, operator!= or set failed ");
721 if (!(list1 == list2)) {
722 errln("digitlist append, operator== or set failed ");
727 // -------------------------------------
729 // Test exponential pattern
731 NumberFormatTest::TestExponential(void)
733 UErrorCode status
= U_ZERO_ERROR
;
734 DecimalFormatSymbols
sym(Locale::getUS(), status
);
735 if (U_FAILURE(status
)) { errcheckln(status
, "FAIL: Bad status returned by DecimalFormatSymbols ct - %s", u_errorName(status
)); return; }
736 const char* pat
[] = { "0.####E0", "00.000E00", "##0.######E000", "0.###E0;[0.###E0]" };
737 int32_t pat_length
= UPRV_LENGTHOF(pat
);
739 // The following #if statements allow this test to be built and run on
740 // platforms that do not have standard IEEE numerics. For example,
741 // S/390 doubles have an exponent range of -78 to +75. For the
742 // following #if statements to work, float.h must define
743 // DBL_MAX_10_EXP to be a compile-time constant.
745 // This section may be expanded as needed.
747 #if DBL_MAX_10_EXP > 300
748 double val
[] = { 0.01234, 123456789, 1.23e300
, -3.141592653e-271 };
749 int32_t val_length
= UPRV_LENGTHOF(val
);
750 const char* valFormat
[] =
753 "1.234E-2", "1.2346E8", "1.23E300", "-3.1416E-271",
755 "12.340E-03", "12.346E07", "12.300E299", "-31.416E-272",
757 "12.34E-003", "123.4568E006", "1.23E300", "-314.1593E-273",
759 "1.234E-2", "1.235E8", "1.23E300", "[3.142E-271]"
763 0.01234, 123460000, 1.23E300
, -3.1416E-271,
764 0.01234, 123460000, 1.23E300
, -3.1416E-271,
765 0.01234, 123456800, 1.23E300
, -3.141593E-271,
766 0.01234, 123500000, 1.23E300
, -3.142E-271,
768 #elif DBL_MAX_10_EXP > 70
769 double val
[] = { 0.01234, 123456789, 1.23e70
, -3.141592653e-71 };
770 int32_t val_length
= UPRV_LENGTHOF(val
);
774 "1.234E-2", "1.2346E8", "1.23E70", "-3.1416E-71",
776 "12.340E-03", "12.346E07", "12.300E69", "-31.416E-72",
778 "12.34E-003", "123.4568E006", "12.3E069", "-31.41593E-072",
780 "1.234E-2", "1.235E8", "1.23E70", "[3.142E-71]"
784 0.01234, 123460000, 1.23E70
, -3.1416E-71,
785 0.01234, 123460000, 1.23E70
, -3.1416E-71,
786 0.01234, 123456800, 1.23E70
, -3.141593E-71,
787 0.01234, 123500000, 1.23E70
, -3.142E-71,
790 // Don't test double conversion
792 int32_t val_length
= 0;
793 char** valFormat
= 0;
794 double* valParse
= 0;
795 logln("Warning: Skipping double conversion tests");
798 int32_t lval
[] = { 0, -1, 1, 123456789 };
799 int32_t lval_length
= UPRV_LENGTHOF(lval
);
800 const char* lvalFormat
[] =
803 "0E0", "-1E0", "1E0", "1.2346E8",
805 "00.000E00", "-10.000E-01", "10.000E-01", "12.346E07",
807 "0E000", "-1E000", "1E000", "123.4568E006",
809 "0E0", "[1E0]", "1E0", "1.235E8"
811 int32_t lvalParse
[] =
818 int32_t ival
= 0, ilval
= 0;
819 for (int32_t p
=0; p
<pat_length
; ++p
)
821 DecimalFormat
fmt(pat
[p
], sym
, status
);
822 if (U_FAILURE(status
)) { errln("FAIL: Bad status returned by DecimalFormat ct"); continue; }
823 UnicodeString pattern
;
824 logln((UnicodeString
)"Pattern \"" + pat
[p
] + "\" -toPattern-> \"" +
825 fmt
.toPattern(pattern
) + "\"");
827 for (v
=0; v
<val_length
; ++v
)
829 UnicodeString s
; (*(NumberFormat
*)&fmt
).format(val
[v
], s
);
830 logln((UnicodeString
)" " + val
[v
] + " -format-> " + s
);
831 if (s
!= valFormat
[v
+ival
])
832 errln((UnicodeString
)"FAIL: Expected " + valFormat
[v
+ival
]);
834 ParsePosition
pos(0);
836 fmt
.parse(s
, af
, pos
);
838 UBool useEpsilon
= FALSE
;
839 if (af
.getType() == Formattable::kLong
)
841 else if (af
.getType() == Formattable::kDouble
) {
843 #if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
844 // S/390 will show a failure like this:
845 //| -3.141592652999999e-271 -format-> -3.1416E-271
846 //| -parse-> -3.1416e-271
847 //| FAIL: Expected -3.141599999999999e-271
848 // To compensate, we use an epsilon-based equality
849 // test on S/390 only. We don't want to do this in
850 // general because it's less exacting.
855 errln((UnicodeString
)"FAIL: Non-numeric Formattable returned");
858 if (pos
.getIndex() == s
.length())
860 logln((UnicodeString
)" -parse-> " + a
);
861 // Use epsilon comparison as necessary
863 (uprv_fabs(a
- valParse
[v
+ival
]) / a
> (2*DBL_EPSILON
))) ||
864 (!useEpsilon
&& a
!= valParse
[v
+ival
]))
866 errln((UnicodeString
)"FAIL: Expected " + valParse
[v
+ival
]);
870 errln((UnicodeString
)"FAIL: Partial parse (" + pos
.getIndex() + " chars) -> " + a
);
871 errln((UnicodeString
)" should be (" + s
.length() + " chars) -> " + valParse
[v
+ival
]);
874 for (v
=0; v
<lval_length
; ++v
)
877 (*(NumberFormat
*)&fmt
).format(lval
[v
], s
);
878 logln((UnicodeString
)" " + lval
[v
] + "L -format-> " + s
);
879 if (s
!= lvalFormat
[v
+ilval
])
880 errln((UnicodeString
)"ERROR: Expected " + lvalFormat
[v
+ilval
] + " Got: " + s
);
882 ParsePosition
pos(0);
884 fmt
.parse(s
, af
, pos
);
885 if (af
.getType() == Formattable::kLong
||
886 af
.getType() == Formattable::kInt64
) {
887 UErrorCode status
= U_ZERO_ERROR
;
888 int32_t a
= af
.getLong(status
);
889 if (pos
.getIndex() == s
.length())
891 logln((UnicodeString
)" -parse-> " + a
);
892 if (a
!= lvalParse
[v
+ilval
])
893 errln((UnicodeString
)"FAIL: Expected " + lvalParse
[v
+ilval
]);
896 errln((UnicodeString
)"FAIL: Partial parse (" + pos
.getIndex() + " chars) -> " + a
);
899 errln((UnicodeString
)"FAIL: Non-long Formattable returned for " + s
900 + " Double: " + af
.getDouble()
901 + ", Long: " + af
.getLong());
904 ilval
+= lval_length
;
909 NumberFormatTest::TestScientific2() {
911 UErrorCode status
= U_ZERO_ERROR
;
912 DecimalFormat
* fmt
= (DecimalFormat
*)NumberFormat::createCurrencyInstance("en_US", status
);
913 if (U_SUCCESS(status
)) {
915 expect(*fmt
, num
, "$12.34");
916 fmt
->setScientificNotation(TRUE
);
917 expect(*fmt
, num
, "$1.23E1");
918 fmt
->setScientificNotation(FALSE
);
919 expect(*fmt
, num
, "$12.34");
925 NumberFormatTest::TestScientificGrouping() {
927 UErrorCode status
= U_ZERO_ERROR
;
928 DecimalFormat
fmt("##0.00E0",status
);
929 if (U_SUCCESS(status
)) {
930 expect(fmt
, .01234, "12.3E-3");
931 expect(fmt
, .1234, "123E-3");
932 expect(fmt
, 1.234, "1.23E0");
933 expect(fmt
, 12.34, "12.3E0");
934 expect(fmt
, 123.4, "123E0");
935 expect(fmt
, 1234., "1.23E3");
939 /*static void setFromString(DigitList& dl, const char* str) {
941 UBool decimalSet = FALSE;
943 while ((c = *str++)) {
945 dl.fIsPositive = FALSE;
946 } else if (c == '+') {
947 dl.fIsPositive = TRUE;
948 } else if (c == '.') {
949 dl.fDecimalAt = dl.fCount;
956 dl.fDecimalAt = dl.fCount;
961 NumberFormatTest::TestInt64() {
962 UErrorCode status
= U_ZERO_ERROR
;
963 DecimalFormat
fmt("#.#E0",status
);
964 if (U_FAILURE(status
)) {
965 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
968 fmt
.setMaximumFractionDigits(20);
969 if (U_SUCCESS(status
)) {
970 expect(fmt
, (Formattable
)(int64_t)0, "0E0");
971 expect(fmt
, (Formattable
)(int64_t)-1, "-1E0");
972 expect(fmt
, (Formattable
)(int64_t)1, "1E0");
973 expect(fmt
, (Formattable
)(int64_t)2147483647, "2.147483647E9");
974 expect(fmt
, (Formattable
)((int64_t)-2147483647-1), "-2.147483648E9");
975 expect(fmt
, (Formattable
)(int64_t)U_INT64_MAX
, "9.223372036854775807E18");
976 expect(fmt
, (Formattable
)(int64_t)U_INT64_MIN
, "-9.223372036854775808E18");
979 // also test digitlist
980 /* int64_t int64max = U_INT64_MAX;
981 int64_t int64min = U_INT64_MIN;
982 const char* int64maxstr = "9223372036854775807";
983 const char* int64minstr = "-9223372036854775808";
984 UnicodeString fail("fail: ");
986 // test max int64 value
988 setFromString(dl, int64maxstr);
990 if (!dl.fitsIntoInt64(FALSE)) {
991 errln(fail + int64maxstr + " didn't fit");
993 int64_t int64Value = dl.getInt64();
994 if (int64Value != int64max) {
995 errln(fail + int64maxstr);
998 int64Value = dl.getInt64();
999 if (int64Value != int64max) {
1000 errln(fail + int64maxstr);
1003 // test negative of max int64 value (1 shy of min int64 value)
1004 dl.fIsPositive = FALSE;
1006 if (!dl.fitsIntoInt64(FALSE)) {
1007 errln(fail + "-" + int64maxstr + " didn't fit");
1009 int64_t int64Value = dl.getInt64();
1010 if (int64Value != -int64max) {
1011 errln(fail + "-" + int64maxstr);
1014 int64Value = dl.getInt64();
1015 if (int64Value != -int64max) {
1016 errln(fail + "-" + int64maxstr);
1019 // test min int64 value
1020 setFromString(dl, int64minstr);
1022 if (!dl.fitsIntoInt64(FALSE)) {
1023 errln(fail + "-" + int64minstr + " didn't fit");
1025 int64_t int64Value = dl.getInt64();
1026 if (int64Value != int64min) {
1027 errln(fail + int64minstr);
1030 int64Value = dl.getInt64();
1031 if (int64Value != int64min) {
1032 errln(fail + int64minstr);
1035 // test negative of min int 64 value (1 more than max int64 value)
1036 dl.fIsPositive = TRUE; // won't fit
1038 if (dl.fitsIntoInt64(FALSE)) {
1039 errln(fail + "-(" + int64minstr + ") didn't fit");
1044 // -------------------------------------
1046 // Test the handling of quotes
1048 NumberFormatTest::TestQuotes(void)
1050 UErrorCode status
= U_ZERO_ERROR
;
1052 DecimalFormatSymbols
*sym
= new DecimalFormatSymbols(Locale::getUS(), status
);
1053 if (U_FAILURE(status
)) {
1054 errcheckln(status
, "Fail to create DecimalFormatSymbols - %s", u_errorName(status
));
1058 pat
= new UnicodeString("a'fo''o'b#");
1059 DecimalFormat
*fmt
= new DecimalFormat(*pat
, *sym
, status
);
1061 ((NumberFormat
*)fmt
)->format((int32_t)123, s
);
1062 logln((UnicodeString
)"Pattern \"" + *pat
+ "\"");
1063 logln((UnicodeString
)" Format 123 -> " + escape(s
));
1064 if (!(s
=="afo'ob123"))
1065 errln((UnicodeString
)"FAIL: Expected afo'ob123");
1071 pat
= new UnicodeString("a''b#");
1072 fmt
= new DecimalFormat(*pat
, *sym
, status
);
1073 ((NumberFormat
*)fmt
)->format((int32_t)123, s
);
1074 logln((UnicodeString
)"Pattern \"" + *pat
+ "\"");
1075 logln((UnicodeString
)" Format 123 -> " + escape(s
));
1077 errln((UnicodeString
)"FAIL: Expected a'b123");
1084 * Test the handling of the currency symbol in patterns.
1087 NumberFormatTest::TestCurrencySign(void)
1089 UErrorCode status
= U_ZERO_ERROR
;
1090 DecimalFormatSymbols
* sym
= new DecimalFormatSymbols(Locale::getUS(), status
);
1092 UChar currency
= 0x00A4;
1093 if (U_FAILURE(status
)) {
1094 errcheckln(status
, "Fail to create DecimalFormatSymbols - %s", u_errorName(status
));
1098 // "\xA4#,##0.00;-\xA4#,##0.00"
1099 pat
.append(currency
).append("#,##0.00;-").
1100 append(currency
).append("#,##0.00");
1101 DecimalFormat
*fmt
= new DecimalFormat(pat
, *sym
, status
);
1102 UnicodeString s
; ((NumberFormat
*)fmt
)->format(1234.56, s
);
1104 logln((UnicodeString
)"Pattern \"" + fmt
->toPattern(pat
) + "\"");
1105 logln((UnicodeString
)" Format " + 1234.56 + " -> " + escape(s
));
1106 if (s
!= "$1,234.56") dataerrln((UnicodeString
)"FAIL: Expected $1,234.56");
1108 ((NumberFormat
*)fmt
)->format(- 1234.56, s
);
1109 logln((UnicodeString
)" Format " + (-1234.56) + " -> " + escape(s
));
1110 if (s
!= "-$1,234.56") dataerrln((UnicodeString
)"FAIL: Expected -$1,234.56");
1113 // "\xA4\xA4 #,##0.00;\xA4\xA4 -#,##0.00"
1114 pat
.append(currency
).append(currency
).
1115 append(" #,##0.00;").
1116 append(currency
).append(currency
).
1117 append(" -#,##0.00");
1118 fmt
= new DecimalFormat(pat
, *sym
, status
);
1120 ((NumberFormat
*)fmt
)->format(1234.56, s
);
1121 logln((UnicodeString
)"Pattern \"" + fmt
->toPattern(pat
) + "\"");
1122 logln((UnicodeString
)" Format " + 1234.56 + " -> " + escape(s
));
1123 if (s
!= "USD 1,234.56") dataerrln((UnicodeString
)"FAIL: Expected USD 1,234.56");
1125 ((NumberFormat
*)fmt
)->format(-1234.56, s
);
1126 logln((UnicodeString
)" Format " + (-1234.56) + " -> " + escape(s
));
1127 if (s
!= "USD -1,234.56") dataerrln((UnicodeString
)"FAIL: Expected USD -1,234.56");
1130 if (U_FAILURE(status
)) errln((UnicodeString
)"FAIL: Status " + u_errorName(status
));
1133 // -------------------------------------
1135 static UChar
toHexString(int32_t i
) { return (UChar
)(i
+ (i
< 10 ? 0x30 : (0x41 - 10))); }
1138 NumberFormatTest::escape(UnicodeString
& s
)
1141 for (int32_t i
=0; i
<s
.length(); ++i
)
1143 UChar c
= s
[(int32_t)i
];
1144 if (c
<= (UChar
)0x7F) buf
+= c
;
1146 buf
+= (UChar
)0x5c; buf
+= (UChar
)0x55;
1147 buf
+= toHexString((c
& 0xF000) >> 12);
1148 buf
+= toHexString((c
& 0x0F00) >> 8);
1149 buf
+= toHexString((c
& 0x00F0) >> 4);
1150 buf
+= toHexString(c
& 0x000F);
1157 // -------------------------------------
1158 static const char* testCases
[][2]= {
1159 /* locale ID */ /* expected */
1160 {"ca_ES_PREEURO", "\\u20A7\\u00A01.150" },
1161 {"de_LU_PREEURO", "1,150\\u00A0F" },
1162 {"el_GR_PREEURO", "1.150,50\\u00A0\\u0394\\u03C1\\u03C7" },
1163 {"en_BE_PREEURO", "1.150,50\\u00A0BEF" },
1164 {"es_ES_PREEURO", "1.150\\u00A0\\u20A7" },
1165 {"eu_ES_PREEURO", "\\u20A7\\u00A01.150" },
1166 {"gl_ES_PREEURO", "1.150\\u00A0\\u20A7" },
1167 {"it_IT_PREEURO", "ITL\\u00A01.150" },
1168 {"pt_PT_PREEURO", "1,150$50\\u00A0\\u200B"}, // per cldrbug 7670
1169 {"en_US@currency=JPY", "\\u00A51,150"},
1170 {"en_US@currency=jpy", "\\u00A51,150"},
1171 {"en-US-u-cu-jpy", "\\u00A51,150"}
1174 * Test localized currency patterns.
1177 NumberFormatTest::TestCurrency(void)
1179 UErrorCode status
= U_ZERO_ERROR
;
1180 NumberFormat
* currencyFmt
= NumberFormat::createCurrencyInstance(Locale::getCanadaFrench(), status
);
1181 if (U_FAILURE(status
)) {
1182 dataerrln("Error calling NumberFormat::createCurrencyInstance()");
1186 UnicodeString s
; currencyFmt
->format(1.50, s
);
1187 logln((UnicodeString
)"Un pauvre ici a..........." + s
);
1188 if (!(s
==CharsToUnicodeString("1,50\\u00A0$")))
1189 errln((UnicodeString
)"FAIL: Expected 1,50<nbsp>$");
1193 int len
= uloc_canonicalize("de_DE_PREEURO", loc
, 256, &status
);
1194 (void)len
; // Suppress unused variable warning.
1195 currencyFmt
= NumberFormat::createCurrencyInstance(Locale(loc
),status
);
1196 currencyFmt
->format(1.50, s
);
1197 logln((UnicodeString
)"Un pauvre en Allemagne a.." + s
);
1198 if (!(s
==CharsToUnicodeString("1,50\\u00A0DM")))
1199 errln((UnicodeString
)"FAIL: Expected 1,50<nbsp>DM");
1202 len
= uloc_canonicalize("fr_FR_PREEURO", loc
, 256, &status
);
1203 currencyFmt
= NumberFormat::createCurrencyInstance(Locale(loc
), status
);
1204 currencyFmt
->format(1.50, s
);
1205 logln((UnicodeString
)"Un pauvre en France a....." + s
);
1206 if (!(s
==CharsToUnicodeString("1,50\\u00A0F")))
1207 errln((UnicodeString
)"FAIL: Expected 1,50<nbsp>F");
1209 if (U_FAILURE(status
))
1210 errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
1212 for(int i
=0; i
< UPRV_LENGTHOF(testCases
); i
++){
1213 status
= U_ZERO_ERROR
;
1214 const char *localeID
= testCases
[i
][0];
1215 UnicodeString
expected(testCases
[i
][1], -1, US_INV
);
1216 expected
= expected
.unescape();
1219 uloc_canonicalize(localeID
, loc
, 256, &status
);
1220 currencyFmt
= NumberFormat::createCurrencyInstance(Locale(loc
), status
);
1221 if(U_FAILURE(status
)){
1222 errln("Could not create currency formatter for locale %s",localeID
);
1225 currencyFmt
->format(1150.50, s
);
1227 errln(UnicodeString("FAIL: Expected: ")+expected
1228 + UnicodeString(" Got: ") + s
1229 + UnicodeString( " for locale: ")+ UnicodeString(localeID
) );
1231 if (U_FAILURE(status
)){
1232 errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
1238 // -------------------------------------
1241 * Test the Currency object handling, new as of ICU 2.2.
1243 void NumberFormatTest::TestCurrencyObject() {
1244 UErrorCode ec
= U_ZERO_ERROR
;
1246 NumberFormat::createCurrencyInstance(Locale::getUS(), ec
);
1248 if (U_FAILURE(ec
)) {
1249 dataerrln("FAIL: getCurrencyInstance(US) - %s", u_errorName(ec
));
1254 Locale
null("", "", "");
1256 expectCurrency(*fmt
, null
, 1234.56, "$1,234.56");
1258 expectCurrency(*fmt
, Locale::getFrance(),
1259 1234.56, CharsToUnicodeString("\\u20AC1,234.56")); // Euro
1261 expectCurrency(*fmt
, Locale::getJapan(),
1262 1234.56, CharsToUnicodeString("\\u00A51,235")); // Yen
1264 expectCurrency(*fmt
, Locale("fr", "CH", ""),
1265 1234.56, "CHF1,234.56"); // no more 0.05 rounding here, see cldrbug 5548
1267 expectCurrency(*fmt
, Locale::getUS(),
1268 1234.56, "$1,234.56");
1271 fmt
= NumberFormat::createCurrencyInstance(Locale::getFrance(), ec
);
1273 if (U_FAILURE(ec
)) {
1274 errln("FAIL: getCurrencyInstance(FRANCE)");
1279 expectCurrency(*fmt
, null
, 1234.56, CharsToUnicodeString("1 234,56 \\u20AC"));
1281 expectCurrency(*fmt
, Locale::getJapan(),
1282 1234.56, CharsToUnicodeString("1 235 JPY")); // Yen
1284 expectCurrency(*fmt
, Locale("fr", "CH", ""),
1285 1234.56, "1 234,56 CHF"); // no more 0.05 rounding here, see cldrbug 5548
1287 expectCurrency(*fmt
, Locale::getUS(),
1288 1234.56, "1 234,56 $US");
1290 expectCurrency(*fmt
, Locale::getFrance(),
1291 1234.56, CharsToUnicodeString("1 234,56 \\u20AC")); // Euro
1296 // -------------------------------------
1299 * Do rudimentary testing of parsing.
1302 NumberFormatTest::TestParse(void)
1304 UErrorCode status
= U_ZERO_ERROR
;
1305 UnicodeString
arg("0");
1306 DecimalFormat
* format
= new DecimalFormat("00", status
);
1308 Formattable n
; format
->parse(arg
, n
, status
);
1309 logln((UnicodeString
)"parse(" + arg
+ ") = " + n
.getLong());
1310 if (n
.getType() != Formattable::kLong
||
1311 n
.getLong() != 0) errln((UnicodeString
)"FAIL: Expected 0");
1313 if (U_FAILURE(status
)) errcheckln(status
, (UnicodeString
)"FAIL: Status " + u_errorName(status
));
1315 //catch(Exception e) {
1316 // errln((UnicodeString)"Exception caught: " + e);
1320 // -------------------------------------
1322 static const char *lenientAffixTestCases
[] = {
1329 static const char *lenientMinusTestCases
[] = {
1335 static const char *lenientCurrencyTestCases
[] = {
1346 // changed from () to - per cldrbug 5674
1347 static const char *lenientNegativeCurrencyTestCases
[] = {
1355 "-$ 1\\u00A0000.00",
1359 static const char *lenientPercentTestCases
[] = {
1368 static const char *lenientNegativePercentTestCases
[] = {
1380 static const char *strictFailureTestCases
[] = {
1387 * Test lenient parsing.
1390 NumberFormatTest::TestLenientParse(void)
1392 UErrorCode status
= U_ZERO_ERROR
;
1393 DecimalFormat
*format
= new DecimalFormat("(#,##0)", status
);
1396 if (format
== NULL
|| U_FAILURE(status
)) {
1397 dataerrln("Unable to create DecimalFormat (#,##0) - %s", u_errorName(status
));
1399 format
->setLenient(TRUE
);
1400 for (int32_t t
= 0; t
< UPRV_LENGTHOF (lenientAffixTestCases
); t
+= 1) {
1401 UnicodeString testCase
= ctou(lenientAffixTestCases
[t
]);
1403 format
->parse(testCase
, n
, status
);
1404 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1406 if (U_FAILURE(status
) || n
.getType() != Formattable::kLong
||
1408 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientAffixTestCases
[t
] + (UnicodeString
) "\"");
1409 status
= U_ZERO_ERROR
;
1415 Locale
en_US("en_US");
1416 Locale
sv_SE("sv_SE");
1418 NumberFormat
*mFormat
= NumberFormat::createInstance(sv_SE
, UNUM_DECIMAL
, status
);
1420 if (mFormat
== NULL
|| U_FAILURE(status
)) {
1421 dataerrln("Unable to create NumberFormat (sv_SE, UNUM_DECIMAL) - %s", u_errorName(status
));
1423 mFormat
->setLenient(TRUE
);
1424 for (int32_t t
= 0; t
< UPRV_LENGTHOF(lenientMinusTestCases
); t
+= 1) {
1425 UnicodeString testCase
= ctou(lenientMinusTestCases
[t
]);
1427 mFormat
->parse(testCase
, n
, status
);
1428 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1430 if (U_FAILURE(status
) || n
.getType() != Formattable::kLong
|| n
.getLong() != -5) {
1431 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientMinusTestCases
[t
] + (UnicodeString
) "\"");
1432 status
= U_ZERO_ERROR
;
1438 mFormat
= NumberFormat::createInstance(en_US
, UNUM_DECIMAL
, status
);
1440 if (mFormat
== NULL
|| U_FAILURE(status
)) {
1441 dataerrln("Unable to create NumberFormat (en_US, UNUM_DECIMAL) - %s", u_errorName(status
));
1443 mFormat
->setLenient(TRUE
);
1444 for (int32_t t
= 0; t
< UPRV_LENGTHOF(lenientMinusTestCases
); t
+= 1) {
1445 UnicodeString testCase
= ctou(lenientMinusTestCases
[t
]);
1447 mFormat
->parse(testCase
, n
, status
);
1448 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1450 if (U_FAILURE(status
) || n
.getType() != Formattable::kLong
|| n
.getLong() != -5) {
1451 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientMinusTestCases
[t
] + (UnicodeString
) "\"");
1452 status
= U_ZERO_ERROR
;
1458 NumberFormat
*cFormat
= NumberFormat::createInstance(en_US
, UNUM_CURRENCY
, status
);
1460 if (cFormat
== NULL
|| U_FAILURE(status
)) {
1461 dataerrln("Unable to create NumberFormat (en_US, UNUM_CURRENCY) - %s", u_errorName(status
));
1463 cFormat
->setLenient(TRUE
);
1464 for (int32_t t
= 0; t
< UPRV_LENGTHOF (lenientCurrencyTestCases
); t
+= 1) {
1465 UnicodeString testCase
= ctou(lenientCurrencyTestCases
[t
]);
1467 cFormat
->parse(testCase
, n
, status
);
1468 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1470 if (U_FAILURE(status
) ||n
.getType() != Formattable::kLong
||
1471 n
.getLong() != 1000) {
1472 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientCurrencyTestCases
[t
] + (UnicodeString
) "\"");
1473 status
= U_ZERO_ERROR
;
1477 for (int32_t t
= 0; t
< UPRV_LENGTHOF (lenientNegativeCurrencyTestCases
); t
+= 1) {
1478 UnicodeString testCase
= ctou(lenientNegativeCurrencyTestCases
[t
]);
1480 cFormat
->parse(testCase
, n
, status
);
1481 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1483 if (U_FAILURE(status
) ||n
.getType() != Formattable::kLong
||
1484 n
.getLong() != -1000) {
1485 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientNegativeCurrencyTestCases
[t
] + (UnicodeString
) "\"");
1486 status
= U_ZERO_ERROR
;
1493 NumberFormat
*pFormat
= NumberFormat::createPercentInstance(en_US
, status
);
1495 if (pFormat
== NULL
|| U_FAILURE(status
)) {
1496 dataerrln("Unable to create NumberFormat::createPercentInstance (en_US) - %s", u_errorName(status
));
1498 pFormat
->setLenient(TRUE
);
1499 for (int32_t t
= 0; t
< UPRV_LENGTHOF (lenientPercentTestCases
); t
+= 1) {
1500 UnicodeString testCase
= ctou(lenientPercentTestCases
[t
]);
1502 pFormat
->parse(testCase
, n
, status
);
1503 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getDouble());
1505 if (U_FAILURE(status
) ||n
.getType() != Formattable::kDouble
||
1506 n
.getDouble() != 0.25) {
1507 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientPercentTestCases
[t
] + (UnicodeString
) "\"");
1508 status
= U_ZERO_ERROR
;
1512 for (int32_t t
= 0; t
< UPRV_LENGTHOF (lenientNegativePercentTestCases
); t
+= 1) {
1513 UnicodeString testCase
= ctou(lenientNegativePercentTestCases
[t
]);
1515 pFormat
->parse(testCase
, n
, status
);
1516 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getDouble());
1518 if (U_FAILURE(status
) ||n
.getType() != Formattable::kDouble
||
1519 n
.getDouble() != -0.25) {
1520 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) lenientNegativePercentTestCases
[t
] + (UnicodeString
) "\"");
1521 status
= U_ZERO_ERROR
;
1528 // Test cases that should fail with a strict parse and pass with a
1530 NumberFormat
*nFormat
= NumberFormat::createInstance(en_US
, status
);
1532 if (nFormat
== NULL
|| U_FAILURE(status
)) {
1533 dataerrln("Unable to create NumberFormat (en_US) - %s", u_errorName(status
));
1535 // first, make sure that they fail with a strict parse
1536 for (int32_t t
= 0; t
< UPRV_LENGTHOF(strictFailureTestCases
); t
+= 1) {
1537 UnicodeString testCase
= ctou(strictFailureTestCases
[t
]);
1539 nFormat
->parse(testCase
, n
, status
);
1540 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1542 if (! U_FAILURE(status
)) {
1543 errln((UnicodeString
)"Strict Parse succeeded for \"" + (UnicodeString
) strictFailureTestCases
[t
] + (UnicodeString
) "\"");
1546 status
= U_ZERO_ERROR
;
1549 // then, make sure that they pass with a lenient parse
1550 nFormat
->setLenient(TRUE
);
1551 for (int32_t t
= 0; t
< UPRV_LENGTHOF(strictFailureTestCases
); t
+= 1) {
1552 UnicodeString testCase
= ctou(strictFailureTestCases
[t
]);
1554 nFormat
->parse(testCase
, n
, status
);
1555 logln((UnicodeString
)"parse(" + testCase
+ ") = " + n
.getLong());
1557 if (U_FAILURE(status
) ||n
.getType() != Formattable::kLong
||
1558 n
.getLong() != 1000) {
1559 errln((UnicodeString
)"Lenient parse failed for \"" + (UnicodeString
) strictFailureTestCases
[t
] + (UnicodeString
) "\"");
1560 status
= U_ZERO_ERROR
;
1568 // -------------------------------------
1571 * Test proper rounding by the format method.
1574 NumberFormatTest::TestRounding487(void)
1576 UErrorCode status
= U_ZERO_ERROR
;
1577 NumberFormat
*nf
= NumberFormat::createInstance(status
);
1578 if (U_FAILURE(status
)) {
1579 dataerrln("Error calling NumberFormat::createInstance()");
1583 roundingTest(*nf
, 0.00159999, 4, "0.0016");
1584 roundingTest(*nf
, 0.00995, 4, "0.01");
1586 roundingTest(*nf
, 12.3995, 3, "12.4");
1588 roundingTest(*nf
, 12.4999, 0, "12");
1589 roundingTest(*nf
, - 19.5, 0, "-20");
1591 if (U_FAILURE(status
)) errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
1595 * Test the functioning of the secondary grouping value.
1597 void NumberFormatTest::TestSecondaryGrouping(void) {
1598 UErrorCode status
= U_ZERO_ERROR
;
1599 DecimalFormatSymbols
US(Locale::getUS(), status
);
1600 CHECK(status
, "DecimalFormatSymbols ct");
1602 DecimalFormat
f("#,##,###", US
, status
);
1603 CHECK(status
, "DecimalFormat ct");
1605 expect2(f
, (int32_t)123456789L, "12,34,56,789");
1606 expectPat(f
, "#,##,###");
1607 f
.applyPattern("#,###", status
);
1608 CHECK(status
, "applyPattern");
1610 f
.setSecondaryGroupingSize(4);
1611 expect2(f
, (int32_t)123456789L, "12,3456,789");
1612 expectPat(f
, "#,####,###");
1613 NumberFormat
*g
= NumberFormat::createInstance(Locale("hi", "IN"), status
);
1614 CHECK_DATA(status
, "createInstance(hi_IN)");
1617 int32_t l
= (int32_t)1876543210L;
1620 // expect "1,87,65,43,210", but with Hindi digits
1623 if (out
.length() != 14) {
1626 for (int32_t i
=0; i
<out
.length(); ++i
) {
1627 UBool expectGroup
= FALSE
;
1636 // Later -- fix this to get the actual grouping
1637 // character from the resource bundle.
1638 UBool isGroup
= (out
.charAt(i
) == 0x002C);
1639 if (isGroup
!= expectGroup
) {
1646 errln((UnicodeString
)"FAIL Expected " + l
+
1647 " x hi_IN -> \"1,87,65,43,210\" (with Hindi digits), got \"" +
1648 escape(out
) + "\"");
1650 logln((UnicodeString
)"Ok " + l
+
1652 escape(out
) + "\"");
1656 void NumberFormatTest::TestWhiteSpaceParsing(void) {
1657 UErrorCode ec
= U_ZERO_ERROR
;
1658 DecimalFormatSymbols
US(Locale::getUS(), ec
);
1659 DecimalFormat
fmt("a b#0c ", US
, ec
);
1660 if (U_FAILURE(ec
)) {
1661 errcheckln(ec
, "FAIL: Constructor - %s", u_errorName(ec
));
1665 expect(fmt
, "a b1234c ", n
);
1666 expect(fmt
, "a b1234c ", n
);
1670 * Test currencies whose display name is a ChoiceFormat.
1672 void NumberFormatTest::TestComplexCurrency() {
1674 // UErrorCode ec = U_ZERO_ERROR;
1675 // Locale loc("kn", "IN", "");
1676 // NumberFormat* fmt = NumberFormat::createCurrencyInstance(loc, ec);
1677 // if (U_SUCCESS(ec)) {
1678 // expect2(*fmt, 1.0, CharsToUnicodeString("Re.\\u00A01.00"));
1679 // Use .00392625 because that's 2^-8. Any value less than 0.005 is fine.
1680 // expect(*fmt, 1.00390625, CharsToUnicodeString("Re.\\u00A01.00")); // tricky
1681 // expect2(*fmt, 12345678.0, CharsToUnicodeString("Rs.\\u00A01,23,45,678.00"));
1682 // expect2(*fmt, 0.5, CharsToUnicodeString("Rs.\\u00A00.50"));
1683 // expect2(*fmt, -1.0, CharsToUnicodeString("-Re.\\u00A01.00"));
1684 // expect2(*fmt, -10.0, CharsToUnicodeString("-Rs.\\u00A010.00"));
1686 // errln("FAIL: getCurrencyInstance(kn_IN)");
1692 // -------------------------------------
1695 NumberFormatTest::roundingTest(NumberFormat
& nf
, double x
, int32_t maxFractionDigits
, const char* expected
)
1697 nf
.setMaximumFractionDigits(maxFractionDigits
);
1698 UnicodeString out
; nf
.format(x
, out
);
1699 logln((UnicodeString
)"" + x
+ " formats with " + maxFractionDigits
+ " fractional digits to " + out
);
1700 if (!(out
==expected
)) errln((UnicodeString
)"FAIL: Expected " + expected
);
1704 * Upgrade to alphaWorks
1706 void NumberFormatTest::TestExponent(void) {
1707 UErrorCode status
= U_ZERO_ERROR
;
1708 DecimalFormatSymbols
US(Locale::getUS(), status
);
1709 CHECK(status
, "DecimalFormatSymbols constructor");
1710 DecimalFormat
fmt1(UnicodeString("0.###E0"), US
, status
);
1711 CHECK(status
, "DecimalFormat(0.###E0)");
1712 DecimalFormat
fmt2(UnicodeString("0.###E+0"), US
, status
);
1713 CHECK(status
, "DecimalFormat(0.###E+0)");
1715 expect2(fmt1
, n
, "1.234E3");
1716 expect2(fmt2
, n
, "1.234E+3");
1717 expect(fmt1
, "1.234E+3", n
); // Either format should parse "E+3"
1721 * Upgrade to alphaWorks
1723 void NumberFormatTest::TestScientific(void) {
1724 UErrorCode status
= U_ZERO_ERROR
;
1725 DecimalFormatSymbols
US(Locale::getUS(), status
);
1726 CHECK(status
, "DecimalFormatSymbols constructor");
1728 // Test pattern round-trip
1729 const char* PAT
[] = { "#E0", "0.####E0", "00.000E00", "##0.####E000",
1730 "0.###E0;[0.###E0]" };
1731 int32_t PAT_length
= UPRV_LENGTHOF(PAT
);
1732 int32_t DIGITS
[] = {
1733 // min int, max int, min frac, max frac
1734 0, 1, 0, 0, // "#E0"
1735 1, 1, 0, 4, // "0.####E0"
1736 2, 2, 3, 3, // "00.000E00"
1737 1, 3, 0, 4, // "##0.####E000"
1738 1, 1, 0, 3, // "0.###E0;[0.###E0]"
1740 for (int32_t i
=0; i
<PAT_length
; ++i
) {
1741 UnicodeString
pat(PAT
[i
]);
1742 DecimalFormat
df(pat
, US
, status
);
1743 CHECK(status
, "DecimalFormat constructor");
1747 logln(UnicodeString("Ok Pattern rt \"") +
1751 errln(UnicodeString("FAIL Pattern rt \"") +
1755 // Make sure digit counts match what we expect
1756 if (df
.getMinimumIntegerDigits() != DIGITS
[4*i
] ||
1757 df
.getMaximumIntegerDigits() != DIGITS
[4*i
+1] ||
1758 df
.getMinimumFractionDigits() != DIGITS
[4*i
+2] ||
1759 df
.getMaximumFractionDigits() != DIGITS
[4*i
+3]) {
1760 errln(UnicodeString("FAIL \"" + pat
+
1761 "\" min/max int; min/max frac = ") +
1762 df
.getMinimumIntegerDigits() + "/" +
1763 df
.getMaximumIntegerDigits() + ";" +
1764 df
.getMinimumFractionDigits() + "/" +
1765 df
.getMaximumFractionDigits() + ", expect " +
1767 DIGITS
[4*i
+1] + ";" +
1768 DIGITS
[4*i
+2] + "/" +
1774 // Test the constructor for default locale. We have to
1775 // manually set the default locale, as there is no
1776 // guarantee that the default locale has the same
1777 // scientific format.
1778 Locale def
= Locale::getDefault();
1779 Locale::setDefault(Locale::getUS(), status
);
1780 expect2(NumberFormat::createScientificInstance(status
),
1782 "1.2345678901E4", status
);
1783 Locale::setDefault(def
, status
);
1785 expect2(new DecimalFormat("#E0", US
, status
),
1787 "1.2345E4", status
);
1788 expect(new DecimalFormat("0E0", US
, status
),
1791 expect2(NumberFormat::createScientificInstance(Locale::getUS(), status
),
1793 "1.2345678901E4", status
);
1794 expect(new DecimalFormat("##0.###E0", US
, status
),
1797 expect(new DecimalFormat("##0.###E0", US
, status
),
1800 expect2(new DecimalFormat("##0.####E0", US
, status
),
1802 "12.345E3", status
);
1803 expect2(NumberFormat::createScientificInstance(Locale::getFrance(), status
),
1805 "1,2345678901E4", status
);
1806 expect(new DecimalFormat("##0.####E0", US
, status
),
1808 "789.12E-9", status
);
1809 expect2(new DecimalFormat("##0.####E0", US
, status
),
1812 expect(new DecimalFormat(".###E0", US
, status
),
1815 expect2(new DecimalFormat(".###E0", US
, status
),
1819 expect(new DecimalFormat[] { new DecimalFormat("#E0", US),
1820 new DecimalFormat("##E0", US),
1821 new DecimalFormat("####E0", US),
1822 new DecimalFormat("0E0", US),
1823 new DecimalFormat("00E0", US),
1824 new DecimalFormat("000E0", US),
1827 new String[] { "4.5678E7",
1836 ! Unroll this test into individual tests below...
1839 expect2(new DecimalFormat("#E0", US
, status
),
1840 (int32_t) 45678000, "4.5678E7", status
);
1841 expect2(new DecimalFormat("##E0", US
, status
),
1842 (int32_t) 45678000, "45.678E6", status
);
1843 expect2(new DecimalFormat("####E0", US
, status
),
1844 (int32_t) 45678000, "4567.8E4", status
);
1845 expect(new DecimalFormat("0E0", US
, status
),
1846 (int32_t) 45678000, "5E7", status
);
1847 expect(new DecimalFormat("00E0", US
, status
),
1848 (int32_t) 45678000, "46E6", status
);
1849 expect(new DecimalFormat("000E0", US
, status
),
1850 (int32_t) 45678000, "457E5", status
);
1852 expect(new DecimalFormat("###E0", US, status),
1853 new Object[] { new Double(0.0000123), "12.3E-6",
1854 new Double(0.000123), "123E-6",
1855 new Double(0.00123), "1.23E-3",
1856 new Double(0.0123), "12.3E-3",
1857 new Double(0.123), "123E-3",
1858 new Double(1.23), "1.23E0",
1859 new Double(12.3), "12.3E0",
1860 new Double(123), "123E0",
1861 new Double(1230), "1.23E3",
1864 ! Unroll this test into individual tests below...
1867 expect2(new DecimalFormat("###E0", US
, status
),
1868 0.0000123, "12.3E-6", status
);
1869 expect2(new DecimalFormat("###E0", US
, status
),
1870 0.000123, "123E-6", status
);
1871 expect2(new DecimalFormat("###E0", US
, status
),
1872 0.00123, "1.23E-3", status
);
1873 expect2(new DecimalFormat("###E0", US
, status
),
1874 0.0123, "12.3E-3", status
);
1875 expect2(new DecimalFormat("###E0", US
, status
),
1876 0.123, "123E-3", status
);
1877 expect2(new DecimalFormat("###E0", US
, status
),
1878 1.23, "1.23E0", status
);
1879 expect2(new DecimalFormat("###E0", US
, status
),
1880 12.3, "12.3E0", status
);
1881 expect2(new DecimalFormat("###E0", US
, status
),
1882 123.0, "123E0", status
);
1883 expect2(new DecimalFormat("###E0", US
, status
),
1884 1230.0, "1.23E3", status
);
1886 expect(new DecimalFormat("0.#E+00", US, status),
1887 new Object[] { new Double(0.00012), "1.2E-04",
1888 new Long(12000), "1.2E+04",
1891 ! Unroll this test into individual tests below...
1894 expect2(new DecimalFormat("0.#E+00", US
, status
),
1895 0.00012, "1.2E-04", status
);
1896 expect2(new DecimalFormat("0.#E+00", US
, status
),
1897 (int32_t) 12000, "1.2E+04", status
);
1901 * Upgrade to alphaWorks
1903 void NumberFormatTest::TestPad(void) {
1904 UErrorCode status
= U_ZERO_ERROR
;
1905 DecimalFormatSymbols
US(Locale::getUS(), status
);
1906 CHECK(status
, "DecimalFormatSymbols constructor");
1908 expect2(new DecimalFormat("*^##.##", US
, status
),
1909 int32_t(0), "^^^^0", status
);
1910 expect2(new DecimalFormat("*^##.##", US
, status
),
1911 -1.3, "^-1.3", status
);
1912 expect2(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US
, status
),
1913 int32_t(0), "0.0E0______ g-m/s^2", status
);
1914 expect(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US
, status
),
1915 1.0/3, "333.333E-3_ g-m/s^2", status
);
1916 expect2(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US
, status
),
1917 int32_t(0), "0.0______ g-m/s^2", status
);
1918 expect(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US
, status
),
1919 1.0/3, "0.33333__ g-m/s^2", status
);
1921 // Test padding before a sign
1922 const char *formatStr
= "*x#,###,###,##0.0#;*x(###,###,##0.0#)";
1923 expect2(new DecimalFormat(formatStr
, US
, status
),
1924 int32_t(-10), "xxxxxxxxxx(10.0)", status
);
1925 expect2(new DecimalFormat(formatStr
, US
, status
),
1926 int32_t(-1000),"xxxxxxx(1,000.0)", status
);
1927 expect2(new DecimalFormat(formatStr
, US
, status
),
1928 int32_t(-1000000),"xxx(1,000,000.0)", status
);
1929 expect2(new DecimalFormat(formatStr
, US
, status
),
1930 -100.37, "xxxxxxxx(100.37)", status
);
1931 expect2(new DecimalFormat(formatStr
, US
, status
),
1932 -10456.37, "xxxxx(10,456.37)", status
);
1933 expect2(new DecimalFormat(formatStr
, US
, status
),
1934 -1120456.37, "xx(1,120,456.37)", status
);
1935 expect2(new DecimalFormat(formatStr
, US
, status
),
1936 -112045600.37, "(112,045,600.37)", status
);
1937 expect2(new DecimalFormat(formatStr
, US
, status
),
1938 -1252045600.37,"(1,252,045,600.37)", status
);
1940 expect2(new DecimalFormat(formatStr
, US
, status
),
1941 int32_t(10), "xxxxxxxxxxxx10.0", status
);
1942 expect2(new DecimalFormat(formatStr
, US
, status
),
1943 int32_t(1000),"xxxxxxxxx1,000.0", status
);
1944 expect2(new DecimalFormat(formatStr
, US
, status
),
1945 int32_t(1000000),"xxxxx1,000,000.0", status
);
1946 expect2(new DecimalFormat(formatStr
, US
, status
),
1947 100.37, "xxxxxxxxxx100.37", status
);
1948 expect2(new DecimalFormat(formatStr
, US
, status
),
1949 10456.37, "xxxxxxx10,456.37", status
);
1950 expect2(new DecimalFormat(formatStr
, US
, status
),
1951 1120456.37, "xxxx1,120,456.37", status
);
1952 expect2(new DecimalFormat(formatStr
, US
, status
),
1953 112045600.37, "xx112,045,600.37", status
);
1954 expect2(new DecimalFormat(formatStr
, US
, status
),
1955 10252045600.37,"10,252,045,600.37", status
);
1958 // Test padding between a sign and a number
1959 const char *formatStr2
= "#,###,###,##0.0#*x;(###,###,##0.0#*x)";
1960 expect2(new DecimalFormat(formatStr2
, US
, status
),
1961 int32_t(-10), "(10.0xxxxxxxxxx)", status
);
1962 expect2(new DecimalFormat(formatStr2
, US
, status
),
1963 int32_t(-1000),"(1,000.0xxxxxxx)", status
);
1964 expect2(new DecimalFormat(formatStr2
, US
, status
),
1965 int32_t(-1000000),"(1,000,000.0xxx)", status
);
1966 expect2(new DecimalFormat(formatStr2
, US
, status
),
1967 -100.37, "(100.37xxxxxxxx)", status
);
1968 expect2(new DecimalFormat(formatStr2
, US
, status
),
1969 -10456.37, "(10,456.37xxxxx)", status
);
1970 expect2(new DecimalFormat(formatStr2
, US
, status
),
1971 -1120456.37, "(1,120,456.37xx)", status
);
1972 expect2(new DecimalFormat(formatStr2
, US
, status
),
1973 -112045600.37, "(112,045,600.37)", status
);
1974 expect2(new DecimalFormat(formatStr2
, US
, status
),
1975 -1252045600.37,"(1,252,045,600.37)", status
);
1977 expect2(new DecimalFormat(formatStr2
, US
, status
),
1978 int32_t(10), "10.0xxxxxxxxxxxx", status
);
1979 expect2(new DecimalFormat(formatStr2
, US
, status
),
1980 int32_t(1000),"1,000.0xxxxxxxxx", status
);
1981 expect2(new DecimalFormat(formatStr2
, US
, status
),
1982 int32_t(1000000),"1,000,000.0xxxxx", status
);
1983 expect2(new DecimalFormat(formatStr2
, US
, status
),
1984 100.37, "100.37xxxxxxxxxx", status
);
1985 expect2(new DecimalFormat(formatStr2
, US
, status
),
1986 10456.37, "10,456.37xxxxxxx", status
);
1987 expect2(new DecimalFormat(formatStr2
, US
, status
),
1988 1120456.37, "1,120,456.37xxxx", status
);
1989 expect2(new DecimalFormat(formatStr2
, US
, status
),
1990 112045600.37, "112,045,600.37xx", status
);
1991 expect2(new DecimalFormat(formatStr2
, US
, status
),
1992 10252045600.37,"10,252,045,600.37", status
);
1994 //testing the setPadCharacter(UnicodeString) and getPadCharacterString()
1995 DecimalFormat
fmt("#", US
, status
);
1996 CHECK(status
, "DecimalFormat constructor");
1997 UnicodeString
padString("P");
1998 fmt
.setPadCharacter(padString
);
1999 expectPad(fmt
, "*P##.##", DecimalFormat::kPadBeforePrefix
, 5, padString
);
2000 fmt
.setPadCharacter((UnicodeString
)"^");
2001 expectPad(fmt
, "*^#", DecimalFormat::kPadBeforePrefix
, 1, (UnicodeString
)"^");
2002 //commented untill implementation is complete
2003 /* fmt.setPadCharacter((UnicodeString)"^^^");
2004 expectPad(fmt, "*^^^#", DecimalFormat::kPadBeforePrefix, 3, (UnicodeString)"^^^");
2006 padString.append((UChar)0x0061);
2007 padString.append((UChar)0x0302);
2008 fmt.setPadCharacter(padString);
2009 UChar patternChars[]={0x002a, 0x0061, 0x0302, 0x0061, 0x0302, 0x0023, 0x0000};
2010 UnicodeString pattern(patternChars);
2011 expectPad(fmt, pattern , DecimalFormat::kPadBeforePrefix, 4, padString);
2017 * Upgrade to alphaWorks
2019 void NumberFormatTest::TestPatterns2(void) {
2020 UErrorCode status
= U_ZERO_ERROR
;
2021 DecimalFormatSymbols
US(Locale::getUS(), status
);
2022 CHECK(status
, "DecimalFormatSymbols constructor");
2024 DecimalFormat
fmt("#", US
, status
);
2025 CHECK(status
, "DecimalFormat constructor");
2027 UChar hat
= 0x005E; /*^*/
2029 expectPad(fmt
, "*^#", DecimalFormat::kPadBeforePrefix
, 1, hat
);
2030 expectPad(fmt
, "$*^#", DecimalFormat::kPadAfterPrefix
, 2, hat
);
2031 expectPad(fmt
, "#*^", DecimalFormat::kPadBeforeSuffix
, 1, hat
);
2032 expectPad(fmt
, "#$*^", DecimalFormat::kPadAfterSuffix
, 2, hat
);
2033 expectPad(fmt
, "$*^$#", ILLEGAL
);
2034 expectPad(fmt
, "#$*^$", ILLEGAL
);
2035 expectPad(fmt
, "'pre'#,##0*x'post'", DecimalFormat::kPadBeforeSuffix
,
2036 12, (UChar
)0x0078 /*x*/);
2037 expectPad(fmt
, "''#0*x", DecimalFormat::kPadBeforeSuffix
,
2038 3, (UChar
)0x0078 /*x*/);
2039 expectPad(fmt
, "'I''ll'*a###.##", DecimalFormat::kPadAfterPrefix
,
2040 10, (UChar
)0x0061 /*a*/);
2042 fmt
.applyPattern("AA#,##0.00ZZ", status
);
2043 CHECK(status
, "applyPattern");
2044 fmt
.setPadCharacter(hat
);
2046 fmt
.setFormatWidth(10);
2048 fmt
.setPadPosition(DecimalFormat::kPadBeforePrefix
);
2049 expectPat(fmt
, "*^AA#,##0.00ZZ");
2051 fmt
.setPadPosition(DecimalFormat::kPadBeforeSuffix
);
2052 expectPat(fmt
, "AA#,##0.00*^ZZ");
2054 fmt
.setPadPosition(DecimalFormat::kPadAfterSuffix
);
2055 expectPat(fmt
, "AA#,##0.00ZZ*^");
2058 UnicodeString
exp("AA*^#,##0.00ZZ", "");
2059 fmt
.setFormatWidth(12);
2060 fmt
.setPadPosition(DecimalFormat::kPadAfterPrefix
);
2061 expectPat(fmt
, exp
);
2063 fmt
.setFormatWidth(13);
2065 expectPat(fmt
, "AA*^##,##0.00ZZ");
2067 fmt
.setFormatWidth(14);
2069 expectPat(fmt
, "AA*^###,##0.00ZZ");
2071 fmt
.setFormatWidth(15);
2073 expectPat(fmt
, "AA*^####,##0.00ZZ"); // This is the interesting case
2075 fmt
.setFormatWidth(16);
2076 // 12 34567890123456
2077 expectPat(fmt
, "AA*^#,###,##0.00ZZ");
2080 void NumberFormatTest::TestSurrogateSupport(void) {
2081 UErrorCode status
= U_ZERO_ERROR
;
2082 DecimalFormatSymbols
custom(Locale::getUS(), status
);
2083 CHECK(status
, "DecimalFormatSymbols constructor");
2085 custom
.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol
, "decimal");
2086 custom
.setSymbol(DecimalFormatSymbols::kPlusSignSymbol
, "plus");
2087 custom
.setSymbol(DecimalFormatSymbols::kMinusSignSymbol
, " minus ");
2088 custom
.setSymbol(DecimalFormatSymbols::kExponentialSymbol
, "exponent");
2090 UnicodeString
patternStr("*\\U00010000##.##", "");
2091 patternStr
= patternStr
.unescape();
2092 UnicodeString
expStr("\\U00010000\\U00010000\\U00010000\\U000100000", "");
2093 expStr
= expStr
.unescape();
2094 expect2(new DecimalFormat(patternStr
, custom
, status
),
2095 int32_t(0), expStr
, status
);
2097 status
= U_ZERO_ERROR
;
2098 expect2(new DecimalFormat("*^##.##", custom
, status
),
2099 int32_t(0), "^^^^0", status
);
2100 status
= U_ZERO_ERROR
;
2101 expect2(new DecimalFormat("##.##", custom
, status
),
2102 -1.3, " minus 1decimal3", status
);
2103 status
= U_ZERO_ERROR
;
2104 expect2(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom
, status
),
2105 int32_t(0), "0decimal0exponent0 g-m/s^2", status
);
2106 status
= U_ZERO_ERROR
;
2107 expect(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom
, status
),
2108 1.0/3, "333decimal333exponent minus 3 g-m/s^2", status
);
2109 status
= U_ZERO_ERROR
;
2110 expect2(new DecimalFormat("##0.0#### 'g-m/s^2'", custom
, status
),
2111 int32_t(0), "0decimal0 g-m/s^2", status
);
2112 status
= U_ZERO_ERROR
;
2113 expect(new DecimalFormat("##0.0#### 'g-m/s^2'", custom
, status
),
2114 1.0/3, "0decimal33333 g-m/s^2", status
);
2116 UnicodeString
zero((UChar32
)0x10000);
2117 UnicodeString
one((UChar32
)0x10001);
2118 UnicodeString
two((UChar32
)0x10002);
2119 UnicodeString
five((UChar32
)0x10005);
2120 custom
.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol
, zero
);
2121 custom
.setSymbol(DecimalFormatSymbols::kOneDigitSymbol
, one
);
2122 custom
.setSymbol(DecimalFormatSymbols::kTwoDigitSymbol
, two
);
2123 custom
.setSymbol(DecimalFormatSymbols::kFiveDigitSymbol
, five
);
2124 expStr
= UnicodeString("\\U00010001decimal\\U00010002\\U00010005\\U00010000", "");
2125 expStr
= expStr
.unescape();
2126 status
= U_ZERO_ERROR
;
2127 expect2(new DecimalFormat("##0.000", custom
, status
),
2128 1.25, expStr
, status
);
2130 custom
.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol
, (UChar
)0x30);
2131 custom
.setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "units of money");
2132 custom
.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol
, "money separator");
2133 patternStr
= UNICODE_STRING_SIMPLE("0.00 \\u00A4' in your bank account'");
2134 patternStr
= patternStr
.unescape();
2135 expStr
= UnicodeString(" minus 20money separator00 units of money in your bank account", "");
2136 status
= U_ZERO_ERROR
;
2137 expect2(new DecimalFormat(patternStr
, custom
, status
),
2138 int32_t(-20), expStr
, status
);
2140 custom
.setSymbol(DecimalFormatSymbols::kPercentSymbol
, "percent");
2141 patternStr
= "'You''ve lost ' -0.00 %' of your money today'";
2142 patternStr
= patternStr
.unescape();
2143 expStr
= UnicodeString(" minus You've lost minus 2000decimal00 percent of your money today", "");
2144 status
= U_ZERO_ERROR
;
2145 expect2(new DecimalFormat(patternStr
, custom
, status
),
2146 int32_t(-20), expStr
, status
);
2149 void NumberFormatTest::TestCurrencyPatterns(void) {
2150 int32_t i
, locCount
;
2151 const Locale
* locs
= NumberFormat::getAvailableLocales(locCount
);
2152 for (i
=0; i
<locCount
; ++i
) {
2153 UErrorCode ec
= U_ZERO_ERROR
;
2154 NumberFormat
* nf
= NumberFormat::createCurrencyInstance(locs
[i
], ec
);
2155 if (U_FAILURE(ec
)) {
2156 errln("FAIL: Can't create NumberFormat(%s) - %s", locs
[i
].getName(), u_errorName(ec
));
2158 // Make sure currency formats do not have a variable number
2159 // of fraction digits
2160 int32_t min
= nf
->getMinimumFractionDigits();
2161 int32_t max
= nf
->getMaximumFractionDigits();
2165 nf
->format(1.125, b
);
2166 errln((UnicodeString
)"FAIL: " + locs
[i
].getName() +
2167 " min fraction digits != max fraction digits; "
2168 "x 1.0 => " + escape(a
) +
2169 "; x 1.125 => " + escape(b
));
2172 // Make sure EURO currency formats have exactly 2 fraction digits
2173 DecimalFormat
* df
= dynamic_cast<DecimalFormat
*>(nf
);
2175 if (u_strcmp(EUR
, df
->getCurrency()) == 0) {
2176 if (min
!= 2 || max
!= 2) {
2179 errln((UnicodeString
)"FAIL: " + locs
[i
].getName() +
2180 " is a EURO format but it does not have 2 fraction digits; "
2191 void NumberFormatTest::TestRegCurrency(void) {
2192 #if !UCONFIG_NO_SERVICE
2193 UErrorCode status
= U_ZERO_ERROR
;
2195 ucurr_forLocale("en_US", USD
, 4, &status
);
2197 ucurr_forLocale("ja_JP", YEN
, 4, &status
);
2199 static const UChar QQQ
[] = {0x51, 0x51, 0x51, 0};
2200 if(U_FAILURE(status
)) {
2201 errcheckln(status
, "Unable to get currency for locale, error %s", u_errorName(status
));
2205 UCurrRegistryKey enkey
= ucurr_register(YEN
, "en_US", &status
);
2206 UCurrRegistryKey enUSEUROkey
= ucurr_register(QQQ
, "en_US_EURO", &status
);
2208 ucurr_forLocale("en_US", TMP
, 4, &status
);
2209 if (u_strcmp(YEN
, TMP
) != 0) {
2210 errln("FAIL: didn't return YEN registered for en_US");
2213 ucurr_forLocale("en_US_EURO", TMP
, 4, &status
);
2214 if (u_strcmp(QQQ
, TMP
) != 0) {
2215 errln("FAIL: didn't return QQQ for en_US_EURO");
2218 int32_t fallbackLen
= ucurr_forLocale("en_XX_BAR", TMP
, 4, &status
);
2220 errln("FAIL: tried to fallback en_XX_BAR");
2222 status
= U_ZERO_ERROR
; // reset
2224 if (!ucurr_unregister(enkey
, &status
)) {
2225 errln("FAIL: couldn't unregister enkey");
2228 ucurr_forLocale("en_US", TMP
, 4, &status
);
2229 if (u_strcmp(USD
, TMP
) != 0) {
2230 errln("FAIL: didn't return USD for en_US after unregister of en_US");
2232 status
= U_ZERO_ERROR
; // reset
2234 ucurr_forLocale("en_US_EURO", TMP
, 4, &status
);
2235 if (u_strcmp(QQQ
, TMP
) != 0) {
2236 errln("FAIL: didn't return QQQ for en_US_EURO after unregister of en_US");
2239 ucurr_forLocale("en_US_BLAH", TMP
, 4, &status
);
2240 if (u_strcmp(USD
, TMP
) != 0) {
2241 errln("FAIL: could not find USD for en_US_BLAH after unregister of en");
2243 status
= U_ZERO_ERROR
; // reset
2245 if (!ucurr_unregister(enUSEUROkey
, &status
)) {
2246 errln("FAIL: couldn't unregister enUSEUROkey");
2249 ucurr_forLocale("en_US_EURO", TMP
, 4, &status
);
2250 if (u_strcmp(EUR
, TMP
) != 0) {
2251 errln("FAIL: didn't return EUR for en_US_EURO after unregister of en_US_EURO");
2253 status
= U_ZERO_ERROR
; // reset
2257 void NumberFormatTest::TestCurrencyNames(void) {
2258 // Do a basic check of getName()
2259 // USD { "US$", "US Dollar" } // 04/04/1792-
2260 UErrorCode ec
= U_ZERO_ERROR
;
2261 static const UChar USD
[] = {0x55, 0x53, 0x44, 0}; /*USD*/
2262 static const UChar USX
[] = {0x55, 0x53, 0x58, 0}; /*USX*/
2263 static const UChar CAD
[] = {0x43, 0x41, 0x44, 0}; /*CAD*/
2264 static const UChar ITL
[] = {0x49, 0x54, 0x4C, 0}; /*ITL*/
2265 UBool isChoiceFormat
;
2267 const UBool possibleDataError
= TRUE
;
2268 // Warning: HARD-CODED LOCALE DATA in this test. If it fails, CHECK
2269 // THE LOCALE DATA before diving into the code.
2270 assertEquals("USD.getName(SYMBOL_NAME)",
2272 UnicodeString(ucurr_getName(USD
, "en",
2274 &isChoiceFormat
, &len
, &ec
)),
2276 assertEquals("USD.getName(LONG_NAME)",
2277 UnicodeString("US Dollar"),
2278 UnicodeString(ucurr_getName(USD
, "en",
2280 &isChoiceFormat
, &len
, &ec
)),
2282 assertEquals("CAD.getName(SYMBOL_NAME)",
2283 UnicodeString("CA$"),
2284 UnicodeString(ucurr_getName(CAD
, "en",
2286 &isChoiceFormat
, &len
, &ec
)),
2288 assertEquals("CAD.getName(SYMBOL_NAME)",
2290 UnicodeString(ucurr_getName(CAD
, "en_CA",
2292 &isChoiceFormat
, &len
, &ec
)),
2294 assertEquals("USD.getName(SYMBOL_NAME) in en_NZ",
2295 UnicodeString("US$"),
2296 UnicodeString(ucurr_getName(USD
, "en_NZ",
2298 &isChoiceFormat
, &len
, &ec
)),
2300 assertEquals("CAD.getName(SYMBOL_NAME)",
2301 UnicodeString("CA$"),
2302 UnicodeString(ucurr_getName(CAD
, "en_NZ",
2304 &isChoiceFormat
, &len
, &ec
)),
2306 assertEquals("USX.getName(LONG_NAME)",
2307 UnicodeString("USX"),
2308 UnicodeString(ucurr_getName(USX
, "en_US",
2310 &isChoiceFormat
, &len
, &ec
)),
2312 assertSuccess("ucurr_getName", ec
);
2316 // Test that a default or fallback warning is being returned. JB 4239.
2317 ucurr_getName(CAD
, "es_ES", UCURR_LONG_NAME
, &isChoiceFormat
,
2319 assertTrue("ucurr_getName (es_ES fallback)",
2320 U_USING_FALLBACK_WARNING
== ec
, TRUE
, possibleDataError
);
2322 ucurr_getName(CAD
, "zh_TW", UCURR_LONG_NAME
, &isChoiceFormat
,
2324 assertTrue("ucurr_getName (zh_TW fallback)",
2325 U_USING_FALLBACK_WARNING
== ec
, TRUE
, possibleDataError
);
2327 ucurr_getName(CAD
, "en_US", UCURR_LONG_NAME
, &isChoiceFormat
,
2329 assertTrue("ucurr_getName (en_US default)",
2330 U_USING_DEFAULT_WARNING
== ec
|| U_USING_FALLBACK_WARNING
== ec
, TRUE
);
2332 ucurr_getName(CAD
, "ti", UCURR_LONG_NAME
, &isChoiceFormat
,
2334 assertTrue("ucurr_getName (ti default)",
2335 U_USING_DEFAULT_WARNING
== ec
, TRUE
);
2337 // Test that a default warning is being returned when falling back to root. JB 4536.
2338 ucurr_getName(ITL
, "cy", UCURR_LONG_NAME
, &isChoiceFormat
,
2340 assertTrue("ucurr_getName (cy default to root)",
2341 U_USING_DEFAULT_WARNING
== ec
, TRUE
);
2343 // TODO add more tests later
2346 void NumberFormatTest::TestCurrencyUnit(void){
2347 UErrorCode ec
= U_ZERO_ERROR
;
2348 static const UChar USD
[] = {85, 83, 68, 0}; /*USD*/
2349 static const UChar BAD
[] = {63, 63, 63, 0}; /*???*/
2350 static const UChar BAD2
[] = {63, 63, 65, 0}; /*???*/
2351 CurrencyUnit
cu(USD
, ec
);
2352 assertSuccess("CurrencyUnit", ec
);
2354 const UChar
* r
= cu
.getISOCurrency(); // who is the buffer owner ?
2355 assertEquals("getISOCurrency()", USD
, r
);
2357 CurrencyUnit
cu2(cu
);
2359 errln("CurrencyUnit copy constructed object should be same");
2362 CurrencyUnit
* cu3
= (CurrencyUnit
*)cu
.clone();
2364 errln("CurrencyUnit cloned object should be same");
2366 CurrencyUnit
bad(BAD
, ec
);
2367 assertSuccess("CurrencyUnit", ec
);
2368 if (cu
.getIndex() == bad
.getIndex()) {
2369 errln("Indexes of different currencies should differ.");
2371 CurrencyUnit
bad2(BAD2
, ec
);
2372 assertSuccess("CurrencyUnit", ec
);
2373 if (bad2
.getIndex() != bad
.getIndex()) {
2374 errln("Indexes of unrecognized currencies should be the same.");
2377 errln("Different unrecognized currencies should not be equal.");
2381 errln("Currency unit assignment should be the same.");
2386 void NumberFormatTest::TestCurrencyAmount(void){
2387 UErrorCode ec
= U_ZERO_ERROR
;
2388 static const UChar USD
[] = {85, 83, 68, 0}; /*USD*/
2389 CurrencyAmount
ca(9, USD
, ec
);
2390 assertSuccess("CurrencyAmount", ec
);
2392 CurrencyAmount
ca2(ca
);
2394 errln("CurrencyAmount copy constructed object should be same");
2399 errln("CurrencyAmount assigned object should be same");
2402 CurrencyAmount
*ca3
= (CurrencyAmount
*)ca
.clone();
2404 errln("CurrencyAmount cloned object should be same");
2409 void NumberFormatTest::TestSymbolsWithBadLocale(void) {
2411 static const char *badLocales
[] = {
2412 // length < ULOC_FULLNAME_CAPACITY
2413 "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME",
2415 // length > ULOC_FULLNAME_CAPACITY
2416 "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"
2417 }; // expect U_USING_DEFAULT_WARNING for both
2420 for (i
= 0; i
< UPRV_LENGTHOF(badLocales
); i
++) {
2421 const char *localeName
= badLocales
[i
];
2422 Locale
locBad(localeName
);
2423 UErrorCode status
= U_ZERO_ERROR
;
2424 UnicodeString
intlCurrencySymbol((UChar
)0xa4);
2426 intlCurrencySymbol
.append((UChar
)0xa4);
2428 logln("Current locale is %s", Locale::getDefault().getName());
2429 Locale::setDefault(locBad
, status
);
2430 logln("Current locale is %s", Locale::getDefault().getName());
2431 DecimalFormatSymbols
mySymbols(status
);
2432 if (status
!= U_USING_DEFAULT_WARNING
) {
2433 errln("DecimalFormatSymbols should return U_USING_DEFAULT_WARNING.");
2435 if (strcmp(mySymbols
.getLocale().getName(), locBad
.getName()) != 0) {
2436 errln("DecimalFormatSymbols does not have the right locale.", locBad
.getName());
2438 int symbolEnum
= (int)DecimalFormatSymbols::kDecimalSeparatorSymbol
;
2439 for (; symbolEnum
< (int)DecimalFormatSymbols::kFormatSymbolCount
; symbolEnum
++) {
2440 UnicodeString symbolString
= mySymbols
.getSymbol((DecimalFormatSymbols::ENumberFormatSymbol
)symbolEnum
);
2441 logln(UnicodeString("DecimalFormatSymbols[") + symbolEnum
+ UnicodeString("] = ") + prettify(symbolString
));
2442 if (symbolString
.length() == 0
2443 && symbolEnum
!= (int)DecimalFormatSymbols::kGroupingSeparatorSymbol
2444 && symbolEnum
!= (int)DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
)
2446 errln("DecimalFormatSymbols has an empty string at index %d.", symbolEnum
);
2450 status
= U_ZERO_ERROR
;
2451 Locale::setDefault(locDefault
, status
);
2452 logln("Current locale is %s", Locale::getDefault().getName());
2457 * Check that adoptDecimalFormatSymbols and setDecimalFormatSymbols
2458 * behave the same, except for memory ownership semantics. (No
2459 * version of this test on Java, since Java has only one method.)
2461 void NumberFormatTest::TestAdoptDecimalFormatSymbols(void) {
2462 UErrorCode ec
= U_ZERO_ERROR
;
2463 DecimalFormatSymbols
*sym
= new DecimalFormatSymbols(Locale::getUS(), ec
);
2464 if (U_FAILURE(ec
)) {
2465 errcheckln(ec
, "Fail: DecimalFormatSymbols constructor - %s", u_errorName(ec
));
2469 UnicodeString
pat(" #,##0.00");
2470 pat
.insert(0, (UChar
)0x00A4);
2471 DecimalFormat
fmt(pat
, sym
, ec
);
2472 if (U_FAILURE(ec
)) {
2473 errln("Fail: DecimalFormat constructor");
2478 fmt
.format(2350.75, str
);
2479 if (str
== "$ 2,350.75") {
2482 dataerrln("Fail: " + str
+ ", expected $ 2,350.75");
2485 sym
= new DecimalFormatSymbols(Locale::getUS(), ec
);
2486 if (U_FAILURE(ec
)) {
2487 errln("Fail: DecimalFormatSymbols constructor");
2491 sym
->setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "Q");
2492 fmt
.adoptDecimalFormatSymbols(sym
);
2495 fmt
.format(2350.75, str
);
2496 if (str
== "Q 2,350.75") {
2499 dataerrln("Fail: adoptDecimalFormatSymbols -> " + str
+ ", expected Q 2,350.75");
2502 sym
= new DecimalFormatSymbols(Locale::getUS(), ec
);
2503 if (U_FAILURE(ec
)) {
2504 errln("Fail: DecimalFormatSymbols constructor");
2508 DecimalFormat
fmt2(pat
, sym
, ec
);
2509 if (U_FAILURE(ec
)) {
2510 errln("Fail: DecimalFormat constructor");
2514 DecimalFormatSymbols
sym2(Locale::getUS(), ec
);
2515 if (U_FAILURE(ec
)) {
2516 errln("Fail: DecimalFormatSymbols constructor");
2519 sym2
.setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "Q");
2520 fmt2
.setDecimalFormatSymbols(sym2
);
2523 fmt2
.format(2350.75, str
);
2524 if (str
== "Q 2,350.75") {
2527 dataerrln("Fail: setDecimalFormatSymbols -> " + str
+ ", expected Q 2,350.75");
2531 void NumberFormatTest::TestPerMill() {
2532 UErrorCode ec
= U_ZERO_ERROR
;
2534 DecimalFormat
fmt(ctou("###.###\\u2030"), ec
);
2535 if (!assertSuccess("DecimalFormat ct", ec
)) return;
2536 assertEquals("0.4857 x ###.###\\u2030",
2537 ctou("485.7\\u2030"), fmt
.format(0.4857, str
));
2539 DecimalFormatSymbols
sym(Locale::getUS(), ec
);
2540 sym
.setSymbol(DecimalFormatSymbols::kPerMillSymbol
, ctou("m"));
2541 DecimalFormat
fmt2("", sym
, ec
);
2542 fmt2
.applyLocalizedPattern("###.###m", ec
);
2543 if (!assertSuccess("setup", ec
)) return;
2545 assertEquals("0.4857 x ###.###m",
2546 "485.7m", fmt2
.format(0.4857, str
));
2550 * Generic test for patterns that should be legal/illegal.
2552 void NumberFormatTest::TestIllegalPatterns() {
2554 // Prefix with "-:" for illegal patterns
2555 // Prefix with "+:" for legal patterns
2556 const char* DATA
[] = {
2557 // Unquoted special characters in the suffix are illegal
2562 for (int32_t i
=0; DATA
[i
]; ++i
) {
2563 const char* pat
=DATA
[i
];
2564 UBool valid
= (*pat
) == '+';
2566 UErrorCode ec
= U_ZERO_ERROR
;
2567 DecimalFormat
fmt(pat
, ec
); // locale doesn't matter here
2568 if (U_SUCCESS(ec
) == valid
) {
2569 logln("Ok: pattern \"%s\": %s",
2570 pat
, u_errorName(ec
));
2572 errcheckln(ec
, "FAIL: pattern \"%s\" should have %s; got %s",
2573 pat
, (valid
?"succeeded":"failed"),
2579 //----------------------------------------------------------------------
2581 static const char* KEYWORDS
[] = {
2582 /*0*/ "ref=", // <reference pattern to parse numbers>
2583 /*1*/ "loc=", // <locale for formats>
2584 /*2*/ "f:", // <pattern or '-'> <number> <exp. string>
2585 /*3*/ "fp:", // <pattern or '-'> <number> <exp. string> <exp. number>
2586 /*4*/ "rt:", // <pattern or '-'> <(exp.) number> <(exp.) string>
2587 /*5*/ "p:", // <pattern or '-'> <string> <exp. number>
2588 /*6*/ "perr:", // <pattern or '-'> <invalid string>
2589 /*7*/ "pat:", // <pattern or '-'> <exp. toPattern or '-' or 'err'>
2590 /*8*/ "fpc:", // <pattern or '-'> <curr.amt> <exp. string> <exp. curr.amt>
2595 * Return an integer representing the next token from this
2596 * iterator. The integer will be an index into the given list, or
2597 * -1 if there are no more tokens, or -2 if the token is not on
2600 static int32_t keywordIndex(const UnicodeString
& tok
) {
2601 for (int32_t i
=0; KEYWORDS
[i
]!=0; ++i
) {
2602 if (tok
==KEYWORDS
[i
]) {
2610 * Parse a CurrencyAmount using the given NumberFormat, with
2611 * the 'delim' character separating the number and the currency.
2613 static void parseCurrencyAmount(const UnicodeString
& str
,
2614 const NumberFormat
& fmt
,
2616 Formattable
& result
,
2618 UnicodeString num
, cur
;
2619 int32_t i
= str
.indexOf(delim
);
2620 str
.extractBetween(0, i
, num
);
2621 str
.extractBetween(i
+1, INT32_MAX
, cur
);
2623 fmt
.parse(num
, n
, ec
);
2624 result
.adoptObject(new CurrencyAmount(n
, cur
.getTerminatedBuffer(), ec
));
2627 void NumberFormatTest::TestCases() {
2628 UErrorCode ec
= U_ZERO_ERROR
;
2629 TextFile
reader("NumberFormatTestCases.txt", "UTF8", ec
);
2630 if (U_FAILURE(ec
)) {
2631 dataerrln("Couldn't open NumberFormatTestCases.txt");
2634 TokenIterator
tokens(&reader
);
2636 Locale
loc("en", "US", "");
2637 DecimalFormat
*ref
= 0, *fmt
= 0;
2638 MeasureFormat
*mfmt
= 0;
2639 UnicodeString pat
, tok
, mloc
, str
, out
, where
, currAmt
;
2644 if (!tokens
.next(tok
, ec
)) {
2647 where
= UnicodeString("(") + tokens
.getLineNumber() + ") ";
2648 int32_t cmd
= keywordIndex(tok
);
2651 // ref= <reference pattern>
2652 if (!tokens
.next(tok
, ec
)) goto error
;
2654 ref
= new DecimalFormat(tok
,
2655 new DecimalFormatSymbols(Locale::getUS(), ec
), ec
);
2656 if (U_FAILURE(ec
)) {
2657 dataerrln("Error constructing DecimalFormat");
2663 if (!tokens
.next(tok
, ec
)) goto error
;
2664 loc
= Locale::createFromName(CharString().appendInvariantChars(tok
, ec
).data());
2670 if (!tokens
.next(tok
, ec
)) goto error
;
2674 fmt
= new DecimalFormat(pat
, new DecimalFormatSymbols(loc
, ec
), ec
);
2675 if (U_FAILURE(ec
)) {
2676 errln("FAIL: " + where
+ "Pattern \"" + pat
+ "\": " + u_errorName(ec
));
2678 if (!tokens
.next(tok
, ec
)) goto error
;
2679 if (!tokens
.next(tok
, ec
)) goto error
;
2681 if (!tokens
.next(tok
, ec
)) goto error
;
2686 if (cmd
== 2 || cmd
== 3 || cmd
== 4) {
2687 // f: <pattern or '-'> <number> <exp. string>
2688 // fp: <pattern or '-'> <number> <exp. string> <exp. number>
2689 // rt: <pattern or '-'> <number> <string>
2691 if (!tokens
.next(num
, ec
)) goto error
;
2692 if (!tokens
.next(str
, ec
)) goto error
;
2693 ref
->parse(num
, n
, ec
);
2694 assertSuccess("parse", ec
);
2695 assertEquals(where
+ "\"" + pat
+ "\".format(" + num
+ ")",
2696 str
, fmt
->format(n
, out
.remove(), ec
));
2697 assertSuccess("format", ec
);
2698 if (cmd
== 3) { // fp:
2699 if (!tokens
.next(num
, ec
)) goto error
;
2700 ref
->parse(num
, n
, ec
);
2701 assertSuccess("parse", ec
);
2703 if (cmd
!= 2) { // != f:
2705 fmt
->parse(str
, m
, ec
);
2706 assertSuccess("parse", ec
);
2707 assertEquals(where
+ "\"" + pat
+ "\".parse(\"" + str
+ "\")",
2711 // p: <pattern or '-'> <string to parse> <exp. number>
2713 UnicodeString expstr
;
2714 if (!tokens
.next(str
, ec
)) goto error
;
2715 if (!tokens
.next(expstr
, ec
)) goto error
;
2717 ref
->parse(expstr
, exp
, ec
);
2718 assertSuccess("parse", ec
);
2719 fmt
->parse(str
, n
, ec
);
2720 assertSuccess("parse", ec
);
2721 assertEquals(where
+ "\"" + pat
+ "\".parse(\"" + str
+ "\")",
2726 if (!tokens
.next(tok
, ec
)) goto error
;
2730 mfmt
= MeasureFormat::createCurrencyFormat(
2731 Locale::createFromName(
2732 CharString().appendInvariantChars(mloc
, ec
).data()), ec
);
2733 if (U_FAILURE(ec
)) {
2734 errln("FAIL: " + where
+ "Loc \"" + mloc
+ "\": " + u_errorName(ec
));
2736 if (!tokens
.next(tok
, ec
)) goto error
;
2737 if (!tokens
.next(tok
, ec
)) goto error
;
2738 if (!tokens
.next(tok
, ec
)) goto error
;
2741 } else if (mfmt
== NULL
) {
2742 errln("FAIL: " + where
+ "Loc \"" + mloc
+ "\": skip case using previous locale, no valid MeasureFormat");
2743 if (!tokens
.next(tok
, ec
)) goto error
;
2744 if (!tokens
.next(tok
, ec
)) goto error
;
2745 if (!tokens
.next(tok
, ec
)) goto error
;
2748 // fpc: <loc or '-'> <curr.amt> <exp. string> <exp. curr.amt>
2749 if (!tokens
.next(currAmt
, ec
)) goto error
;
2750 if (!tokens
.next(str
, ec
)) goto error
;
2751 parseCurrencyAmount(currAmt
, *ref
, (UChar
)0x2F/*'/'*/, n
, ec
);
2752 if (assertSuccess("parseCurrencyAmount", ec
)) {
2753 assertEquals(where
+ "getCurrencyFormat(" + mloc
+ ").format(" + currAmt
+ ")",
2754 str
, mfmt
->format(n
, out
.remove(), ec
));
2755 assertSuccess("format", ec
);
2757 if (!tokens
.next(currAmt
, ec
)) goto error
;
2758 parseCurrencyAmount(currAmt
, *ref
, (UChar
)0x2F/*'/'*/, n
, ec
);
2759 if (assertSuccess("parseCurrencyAmount", ec
)) {
2762 mfmt
->parseObject(str
, m
, ec
);
2763 if (assertSuccess("parseCurrency", ec
)) {
2764 assertEquals(where
+ "getCurrencyFormat(" + mloc
+ ").parse(\"" + str
+ "\")",
2767 errln("FAIL: source " + str
);
2772 // perr: <pattern or '-'> <invalid string>
2773 errln("FAIL: Under construction");
2776 // pat: <pattern> <exp. toPattern, or '-' or 'err'>
2777 UnicodeString testpat
;
2778 UnicodeString exppat
;
2779 if (!tokens
.next(testpat
, ec
)) goto error
;
2780 if (!tokens
.next(exppat
, ec
)) goto error
;
2781 UBool err
= exppat
== "err";
2782 UBool existingPat
= FALSE
;
2783 if (testpat
== "-") {
2785 errln("FAIL: " + where
+ "Invalid command \"pat: - err\"");
2791 if (exppat
== "-") exppat
= testpat
;
2792 DecimalFormat
* f
= 0;
2793 UErrorCode ec2
= U_ZERO_ERROR
;
2797 f
= new DecimalFormat(testpat
, ec2
);
2799 if (U_SUCCESS(ec2
)) {
2801 errln("FAIL: " + where
+ "Invalid pattern \"" + testpat
+
2805 assertEquals(where
+ "\"" + testpat
+ "\".toPattern()",
2806 exppat
, f
->toPattern(pat2
));
2810 logln("Ok: " + where
+ "Invalid pattern \"" + testpat
+
2811 "\" failed: " + u_errorName(ec2
));
2813 errln("FAIL: " + where
+ "Valid pattern \"" + testpat
+
2814 "\" failed: " + u_errorName(ec2
));
2817 if (!existingPat
) delete f
;
2820 errln("FAIL: " + where
+ "Unknown command \"" + tok
+ "\"");
2827 if (U_SUCCESS(ec
)) {
2828 errln("FAIL: Unexpected EOF");
2830 errcheckln(ec
, "FAIL: " + where
+ "Unexpected " + u_errorName(ec
));
2840 //----------------------------------------------------------------------
2842 //----------------------------------------------------------------------
2844 UBool
NumberFormatTest::equalValue(const Formattable
& a
, const Formattable
& b
) {
2845 if (a
.getType() == b
.getType()) {
2849 if (a
.getType() == Formattable::kLong
) {
2850 if (b
.getType() == Formattable::kInt64
) {
2851 return a
.getLong() == b
.getLong();
2852 } else if (b
.getType() == Formattable::kDouble
) {
2853 return (double) a
.getLong() == b
.getDouble(); // TODO check use of double instead of long
2855 } else if (a
.getType() == Formattable::kDouble
) {
2856 if (b
.getType() == Formattable::kLong
) {
2857 return a
.getDouble() == (double) b
.getLong();
2858 } else if (b
.getType() == Formattable::kInt64
) {
2859 return a
.getDouble() == (double)b
.getInt64();
2861 } else if (a
.getType() == Formattable::kInt64
) {
2862 if (b
.getType() == Formattable::kLong
) {
2863 return a
.getInt64() == (int64_t)b
.getLong();
2864 } else if (b
.getType() == Formattable::kDouble
) {
2865 return a
.getInt64() == (int64_t)b
.getDouble();
2871 void NumberFormatTest::expect3(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
) {
2872 // Don't round-trip format test, since we explicitly do it
2873 expect_rbnf(fmt
, n
, str
, FALSE
);
2874 expect_rbnf(fmt
, str
, n
);
2877 void NumberFormatTest::expect2(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
) {
2878 // Don't round-trip format test, since we explicitly do it
2879 expect(fmt
, n
, str
, FALSE
);
2880 expect(fmt
, str
, n
);
2883 void NumberFormatTest::expect2(NumberFormat
* fmt
, const Formattable
& n
,
2884 const UnicodeString
& exp
,
2885 UErrorCode status
) {
2886 if (fmt
== NULL
|| U_FAILURE(status
)) {
2887 dataerrln("FAIL: NumberFormat constructor");
2889 expect2(*fmt
, n
, exp
);
2894 void NumberFormatTest::expect(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
) {
2895 UErrorCode status
= U_ZERO_ERROR
;
2897 fmt
.parse(str
, num
, status
);
2898 if (U_FAILURE(status
)) {
2899 dataerrln(UnicodeString("FAIL: Parse failed for \"") + str
+ "\" - " + u_errorName(status
));
2903 ((DecimalFormat
*) &fmt
)->toPattern(pat
);
2904 if (equalValue(num
, n
)) {
2905 logln(UnicodeString("Ok \"") + str
+ "\" x " +
2909 dataerrln(UnicodeString("FAIL \"") + str
+ "\" x " +
2911 toString(num
) + ", expected " + toString(n
));
2915 void NumberFormatTest::expect_rbnf(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
) {
2916 UErrorCode status
= U_ZERO_ERROR
;
2918 fmt
.parse(str
, num
, status
);
2919 if (U_FAILURE(status
)) {
2920 errln(UnicodeString("FAIL: Parse failed for \"") + str
+ "\"");
2923 if (equalValue(num
, n
)) {
2924 logln(UnicodeString("Ok \"") + str
+ " = " +
2927 errln(UnicodeString("FAIL \"") + str
+ " = " +
2928 toString(num
) + ", expected " + toString(n
));
2932 void NumberFormatTest::expect_rbnf(NumberFormat
& fmt
, const Formattable
& n
,
2933 const UnicodeString
& exp
, UBool rt
) {
2936 UErrorCode status
= U_ZERO_ERROR
;
2937 fmt
.format(n
, saw
, pos
, status
);
2938 CHECK(status
, "NumberFormat::format");
2940 logln(UnicodeString("Ok ") + toString(n
) +
2942 escape(saw
) + "\"");
2943 // We should be able to round-trip the formatted string =>
2944 // number => string (but not the other way around: number
2945 // => string => number2, might have number2 != number):
2948 fmt
.parse(exp
, n2
, status
);
2949 if (U_FAILURE(status
)) {
2950 errln(UnicodeString("FAIL: Parse failed for \"") + exp
+ "\"");
2954 fmt
.format(n2
, saw2
, pos
, status
);
2955 CHECK(status
, "NumberFormat::format");
2957 errln((UnicodeString
)"FAIL \"" + exp
+ "\" => " + toString(n2
) +
2958 " => \"" + saw2
+ "\"");
2962 errln(UnicodeString("FAIL ") + toString(n
) +
2964 escape(saw
) + "\", expected \"" + exp
+ "\"");
2968 void NumberFormatTest::expect(NumberFormat
& fmt
, const Formattable
& n
,
2969 const UnicodeString
& exp
, UBool rt
) {
2972 UErrorCode status
= U_ZERO_ERROR
;
2973 fmt
.format(n
, saw
, pos
, status
);
2974 CHECK(status
, "NumberFormat::format");
2976 ((DecimalFormat
*) &fmt
)->toPattern(pat
);
2978 logln(UnicodeString("Ok ") + toString(n
) + " x " +
2979 escape(pat
) + " = \"" +
2980 escape(saw
) + "\"");
2981 // We should be able to round-trip the formatted string =>
2982 // number => string (but not the other way around: number
2983 // => string => number2, might have number2 != number):
2986 fmt
.parse(exp
, n2
, status
);
2987 if (U_FAILURE(status
)) {
2988 errln(UnicodeString("FAIL: Parse failed for \"") + exp
+ "\" - " + u_errorName(status
));
2992 fmt
.format(n2
, saw2
, pos
, status
);
2993 CHECK(status
, "NumberFormat::format");
2995 errln((UnicodeString
)"FAIL \"" + exp
+ "\" => " + toString(n2
) +
2996 " => \"" + saw2
+ "\"");
3000 dataerrln(UnicodeString("FAIL ") + toString(n
) + " x " +
3001 escape(pat
) + " = \"" +
3002 escape(saw
) + "\", expected \"" + exp
+ "\"");
3006 void NumberFormatTest::expect(NumberFormat
* fmt
, const Formattable
& n
,
3007 const UnicodeString
& exp
, UBool rt
,
3008 UErrorCode status
) {
3009 if (fmt
== NULL
|| U_FAILURE(status
)) {
3010 dataerrln("FAIL: NumberFormat constructor");
3012 expect(*fmt
, n
, exp
, rt
);
3017 void NumberFormatTest::expectCurrency(NumberFormat
& nf
, const Locale
& locale
,
3018 double value
, const UnicodeString
& string
) {
3019 UErrorCode ec
= U_ZERO_ERROR
;
3020 DecimalFormat
& fmt
= * (DecimalFormat
*) &nf
;
3021 const UChar DEFAULT_CURR
[] = {45/*-*/,0};
3023 u_strcpy(curr
, DEFAULT_CURR
);
3024 if (*locale
.getLanguage() != 0) {
3025 ucurr_forLocale(locale
.getName(), curr
, 4, &ec
);
3026 assertSuccess("ucurr_forLocale", ec
);
3027 fmt
.setCurrency(curr
, ec
);
3028 assertSuccess("DecimalFormat::setCurrency", ec
);
3029 fmt
.setCurrency(curr
); //Deprecated variant, for coverage only
3032 fmt
.format(value
, s
);
3033 s
.findAndReplace((UChar32
)0x00A0, (UChar32
)0x0020);
3035 // Default display of the number yields "1234.5599999999999"
3036 // instead of "1234.56". Use a formatter to fix this.
3038 NumberFormat::createInstance(Locale::getUS(), ec
);
3040 if (U_FAILURE(ec
)) {
3041 // Oops; bad formatter. Use default op+= display.
3042 v
= (UnicodeString
)"" + value
;
3044 f
->setMaximumFractionDigits(4);
3045 f
->setGroupingUsed(FALSE
);
3046 f
->format(value
, v
);
3051 logln((UnicodeString
)"Ok: " + v
+ " x " + curr
+ " => " + prettify(s
));
3053 errln((UnicodeString
)"FAIL: " + v
+ " x " + curr
+ " => " + prettify(s
) +
3054 ", expected " + prettify(string
));
3058 void NumberFormatTest::expectPat(DecimalFormat
& fmt
, const UnicodeString
& exp
) {
3062 logln(UnicodeString("Ok \"") + pat
+ "\"");
3064 errln(UnicodeString("FAIL \"") + pat
+ "\", expected \"" + exp
+ "\"");
3068 void NumberFormatTest::expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
3070 expectPad(fmt
, pat
, pos
, 0, (UnicodeString
)"");
3072 void NumberFormatTest::expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
3073 int32_t pos
, int32_t width
, UChar pad
) {
3074 expectPad(fmt
, pat
, pos
, width
, UnicodeString(pad
));
3076 void NumberFormatTest::expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
3077 int32_t pos
, int32_t width
, const UnicodeString
& pad
) {
3078 int32_t apos
= 0, awidth
= 0;
3079 UnicodeString apadStr
;
3080 UErrorCode status
= U_ZERO_ERROR
;
3081 fmt
.applyPattern(pat
, status
);
3082 if (U_SUCCESS(status
)) {
3083 apos
= fmt
.getPadPosition();
3084 awidth
= fmt
.getFormatWidth();
3085 apadStr
=fmt
.getPadCharacterString();
3091 if (apos
== pos
&& awidth
== width
&& apadStr
== pad
) {
3092 UnicodeString infoStr
;
3093 if (pos
== ILLEGAL
) {
3094 infoStr
= UnicodeString(" width=", "") + awidth
+ UnicodeString(" pad=", "") + apadStr
;
3096 logln(UnicodeString("Ok \"") + pat
+ "\" pos=" + apos
+ infoStr
);
3098 errln(UnicodeString("FAIL \"") + pat
+ "\" pos=" + apos
+
3099 " width=" + awidth
+ " pad=" + apadStr
+
3100 ", expected " + pos
+ " " + width
+ " " + pad
);
3104 // This test is flaky b/c the symbols for CNY and JPY are equivalent in this locale - FIXME
3105 void NumberFormatTest::TestCompatibleCurrencies() {
3107 static const UChar JPY[] = {0x4A, 0x50, 0x59, 0};
3108 static const UChar CNY[] = {0x43, 0x4E, 0x59, 0};
3109 UErrorCode status = U_ZERO_ERROR;
3110 LocalPointer<NumberFormat> fmt(
3111 NumberFormat::createCurrencyInstance(Locale::getUS(), status));
3112 if (U_FAILURE(status)) {
3113 errln("Could not create number format instance.");
3116 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__);
3117 expectParseCurrency(*fmt, JPY, 1235, "\\u00A51,235");
3118 logln("%s:%d - testing parse of fullwidth yen sign\n", __FILE__, __LINE__);
3119 expectParseCurrency(*fmt, JPY, 1235, "\\uFFE51,235");
3120 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__);
3121 expectParseCurrency(*fmt, CNY, 1235, "CN\\u00A51,235");
3123 LocalPointer<NumberFormat> fmtTW(
3124 NumberFormat::createCurrencyInstance(Locale::getTaiwan(), status));
3126 logln("%s:%d - testing parse of halfwidth yen sign in TW\n", __FILE__, __LINE__);
3127 expectParseCurrency(*fmtTW, CNY, 1235, "\\u00A51,235");
3128 logln("%s:%d - testing parse of fullwidth yen sign in TW\n", __FILE__, __LINE__);
3129 expectParseCurrency(*fmtTW, CNY, 1235, "\\uFFE51,235");
3131 LocalPointer<NumberFormat> fmtJP(
3132 NumberFormat::createCurrencyInstance(Locale::getJapan(), status));
3134 logln("%s:%d - testing parse of halfwidth yen sign in JP\n", __FILE__, __LINE__);
3135 expectParseCurrency(*fmtJP, JPY, 1235, "\\u00A51,235");
3136 logln("%s:%d - testing parse of fullwidth yen sign in JP\n", __FILE__, __LINE__);
3137 expectParseCurrency(*fmtJP, JPY, 1235, "\\uFFE51,235");
3143 void NumberFormatTest::expectParseCurrency(const NumberFormat
&fmt
, const UChar
* currency
, double amount
, const char *text
) {
3145 UnicodeString utext
= ctou(text
);
3146 LocalPointer
<CurrencyAmount
> currencyAmount(fmt
.parseCurrency(utext
, ppos
));
3147 if (!ppos
.getIndex()) {
3148 errln(UnicodeString("Parse of ") + utext
+ " should have succeeded.");
3151 UErrorCode status
= U_ZERO_ERROR
;
3154 sprintf(theInfo
, "For locale %s, string \"%s\", currency ",
3155 fmt
.getLocale(ULOC_ACTUAL_LOCALE
, status
).getBaseName(),
3157 u_austrcpy(theInfo
+uprv_strlen(theInfo
), currency
);
3159 char theOperation
[100];
3161 uprv_strcpy(theOperation
, theInfo
);
3162 uprv_strcat(theOperation
, ", check amount:");
3163 assertTrue(theOperation
, amount
== currencyAmount
->getNumber().getDouble(status
));
3165 uprv_strcpy(theOperation
, theInfo
);
3166 uprv_strcat(theOperation
, ", check currency:");
3167 assertEquals(theOperation
, currency
, currencyAmount
->getISOCurrency());
3171 void NumberFormatTest::TestJB3832(){
3172 const char* localeID
= "pt_PT@currency=PTE";
3173 Locale
loc(localeID
);
3174 UErrorCode status
= U_ZERO_ERROR
;
3175 UnicodeString
expected(CharsToUnicodeString("1,150$50\\u00A0\\u200B")); // per cldrbug 7670
3177 NumberFormat
* currencyFmt
= NumberFormat::createCurrencyInstance(loc
, status
);
3178 if(U_FAILURE(status
)){
3179 dataerrln("Could not create currency formatter for locale %s - %s", localeID
, u_errorName(status
));
3182 currencyFmt
->format(1150.50, s
);
3184 errln(UnicodeString("FAIL: Expected: ")+expected
3185 + UnicodeString(" Got: ") + s
3186 + UnicodeString( " for locale: ")+ UnicodeString(localeID
) );
3188 if (U_FAILURE(status
)){
3189 errln("FAIL: Status %s", u_errorName(status
));
3194 void NumberFormatTest::TestHost()
3196 #if U_PLATFORM_USES_ONLY_WIN32_API
3197 Win32NumberTest::testLocales(this);
3199 Locale
loc("en_US@compat=host");
3200 for (UNumberFormatStyle k
= UNUM_DECIMAL
;
3201 k
< UNUM_FORMAT_STYLE_COUNT
; k
= (UNumberFormatStyle
)(k
+1)) {
3202 UErrorCode status
= U_ZERO_ERROR
;
3203 LocalPointer
<NumberFormat
> full(NumberFormat::createInstance(loc
, k
, status
));
3204 if (!NumberFormat::isStyleSupported(k
)) {
3205 if (status
!= U_UNSUPPORTED_ERROR
) {
3206 errln("FAIL: expected style %d to be unsupported - %s",
3207 k
, u_errorName(status
));
3211 if (full
.isNull() || U_FAILURE(status
)) {
3212 dataerrln("FAIL: Can't create number instance of style %d for host - %s",
3213 k
, u_errorName(status
));
3216 UnicodeString result1
;
3217 Formattable
number(10.00);
3218 full
->format(number
, result1
, status
);
3219 if (U_FAILURE(status
)) {
3220 errln("FAIL: Can't format for host");
3223 Formattable formattable
;
3224 full
->parse(result1
, formattable
, status
);
3225 if (U_FAILURE(status
)) {
3226 errln("FAIL: Can't parse for host");
3232 void NumberFormatTest::TestHostClone()
3235 Verify that a cloned formatter gives the same results
3236 and is useable after the original has been deleted.
3238 // This is mainly important on Windows.
3239 UErrorCode status
= U_ZERO_ERROR
;
3240 Locale
loc("en_US@compat=host");
3241 UDate now
= Calendar::getNow();
3242 NumberFormat
*full
= NumberFormat::createInstance(loc
, status
);
3243 if (full
== NULL
|| U_FAILURE(status
)) {
3244 dataerrln("FAIL: Can't create Relative date instance - %s", u_errorName(status
));
3247 UnicodeString result1
;
3248 full
->format(now
, result1
, status
);
3249 Format
*fullClone
= full
->clone();
3253 UnicodeString result2
;
3254 fullClone
->format(now
, result2
, status
);
3255 if (U_FAILURE(status
)) {
3256 errln("FAIL: format failure.");
3258 if (result1
!= result2
) {
3259 errln("FAIL: Clone returned different result from non-clone.");
3264 void NumberFormatTest::TestCurrencyFormat()
3266 // This test is here to increase code coverage.
3267 UErrorCode status
= U_ZERO_ERROR
;
3268 MeasureFormat
*cloneObj
;
3270 Formattable toFormat
, result
;
3271 static const UChar ISO_CODE
[4] = {0x0047, 0x0042, 0x0050, 0};
3273 Locale saveDefaultLocale
= Locale::getDefault();
3274 Locale::setDefault( Locale::getUK(), status
);
3275 if (U_FAILURE(status
)) {
3276 errln("couldn't set default Locale!");
3280 MeasureFormat
*measureObj
= MeasureFormat::createCurrencyFormat(status
);
3281 Locale::setDefault( saveDefaultLocale
, status
);
3282 if (U_FAILURE(status
)){
3283 dataerrln("FAIL: Status %s", u_errorName(status
));
3286 cloneObj
= (MeasureFormat
*)measureObj
->clone();
3287 if (cloneObj
== NULL
) {
3288 errln("Clone doesn't work");
3291 toFormat
.adoptObject(new CurrencyAmount(1234.56, ISO_CODE
, status
));
3292 measureObj
->format(toFormat
, str
, status
);
3293 measureObj
->parseObject(str
, result
, status
);
3294 if (U_FAILURE(status
)){
3295 errln("FAIL: Status %s", u_errorName(status
));
3297 if (result
!= toFormat
) {
3298 errln("measureObj does not round trip. Formatted string was \"" + str
+ "\" Got: " + toString(result
) + " Expected: " + toString(toFormat
));
3300 status
= U_ZERO_ERROR
;
3302 cloneObj
->format(toFormat
, str
, status
);
3303 cloneObj
->parseObject(str
, result
, status
);
3304 if (U_FAILURE(status
)){
3305 errln("FAIL: Status %s", u_errorName(status
));
3307 if (result
!= toFormat
) {
3308 errln("Clone does not round trip. Formatted string was \"" + str
+ "\" Got: " + toString(result
) + " Expected: " + toString(toFormat
));
3310 if (*measureObj
!= *cloneObj
) {
3311 errln("Cloned object is not equal to the original object");
3316 status
= U_USELESS_COLLATOR_ERROR
;
3317 if (MeasureFormat::createCurrencyFormat(status
) != NULL
) {
3318 errln("createCurrencyFormat should have returned NULL.");
3322 /* Port of ICU4J rounding test. */
3323 void NumberFormatTest::TestRounding() {
3324 UErrorCode status
= U_ZERO_ERROR
;
3325 DecimalFormat
*df
= (DecimalFormat
*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status
);
3327 if (U_FAILURE(status
)) {
3328 dataerrln("Unable to create decimal formatter. - %s", u_errorName(status
));
3332 int roundingIncrements
[]={1, 2, 5, 20, 50, 100};
3333 int testValues
[]={0, 300};
3335 for (int j
=0; j
<2; j
++) {
3336 for (int mode
=DecimalFormat::kRoundUp
;mode
<DecimalFormat::kRoundHalfEven
;mode
++) {
3337 df
->setRoundingMode((DecimalFormat::ERoundingMode
)mode
);
3338 for (int increment
=0; increment
<6; increment
++) {
3339 double base
=testValues
[j
];
3340 double rInc
=roundingIncrements
[increment
];
3341 checkRounding(df
, base
, 20, rInc
);
3342 rInc
=1.000000000/rInc
;
3343 checkRounding(df
, base
, 20, rInc
);
3350 void NumberFormatTest::TestRoundingPattern() {
3351 UErrorCode status
= U_ZERO_ERROR
;
3353 UnicodeString pattern
;
3355 UnicodeString expected
;
3357 { (UnicodeString
)"##0.65", 1.234, (UnicodeString
)"1.30" },
3358 { (UnicodeString
)"#50", 1230, (UnicodeString
)"1250" }
3360 int32_t numOfTests
= UPRV_LENGTHOF(tests
);
3361 UnicodeString result
;
3363 DecimalFormat
*df
= (DecimalFormat
*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status
);
3364 if (U_FAILURE(status
)) {
3365 dataerrln("Unable to create decimal formatter. - %s", u_errorName(status
));
3369 for (int32_t i
= 0; i
< numOfTests
; i
++) {
3372 df
->applyPattern(tests
[i
].pattern
, status
);
3373 if (U_FAILURE(status
)) {
3374 errln("Unable to apply pattern to decimal formatter. - %s", u_errorName(status
));
3377 df
->format(tests
[i
].testCase
, result
);
3379 if (result
!= tests
[i
].expected
) {
3380 errln("String Pattern Rounding Test Failed: Pattern: \"" + tests
[i
].pattern
+ "\" Number: " + tests
[i
].testCase
+ " - Got: " + result
+ " Expected: " + tests
[i
].expected
);
3387 void NumberFormatTest::checkRounding(DecimalFormat
* df
, double base
, int iterations
, double increment
) {
3388 df
->setRoundingIncrement(increment
);
3389 double lastParsed
=INT32_MIN
; //Intger.MIN_VALUE
3390 for (int i
=-iterations
; i
<=iterations
;i
++) {
3391 double iValue
=base
+(increment
*(i
*0.1));
3392 double smallIncrement
=0.00000001;
3394 smallIncrement
*=iValue
;
3396 //we not only test the value, but some values in a small range around it
3397 lastParsed
=checkRound(df
, iValue
-smallIncrement
, lastParsed
);
3398 lastParsed
=checkRound(df
, iValue
, lastParsed
);
3399 lastParsed
=checkRound(df
, iValue
+smallIncrement
, lastParsed
);
3403 double NumberFormatTest::checkRound(DecimalFormat
* df
, double iValue
, double lastParsed
) {
3404 UErrorCode status
=U_ZERO_ERROR
;
3405 UnicodeString formattedDecimal
;
3408 df
->format(iValue
, formattedDecimal
, status
);
3410 if (U_FAILURE(status
)) {
3411 errln("Error formatting number.");
3414 df
->parse(formattedDecimal
, result
, status
);
3416 if (U_FAILURE(status
)) {
3417 errln("Error parsing number.");
3420 parsed
=result
.getDouble();
3422 if (lastParsed
>parsed
) {
3423 errln("Rounding wrong direction! %d > %d", lastParsed
, parsed
);
3429 void NumberFormatTest::TestNonpositiveMultiplier() {
3430 UErrorCode status
= U_ZERO_ERROR
;
3431 DecimalFormatSymbols
US(Locale::getUS(), status
);
3432 CHECK(status
, "DecimalFormatSymbols constructor");
3433 DecimalFormat
df(UnicodeString("0"), US
, status
);
3434 CHECK(status
, "DecimalFormat(0)");
3436 // test zero multiplier
3438 int32_t mult
= df
.getMultiplier();
3439 df
.setMultiplier(0);
3440 if (df
.getMultiplier() != mult
) {
3441 errln("DecimalFormat.setMultiplier(0) did not ignore its zero input");
3444 // test negative multiplier
3446 df
.setMultiplier(-1);
3447 if (df
.getMultiplier() != -1) {
3448 errln("DecimalFormat.setMultiplier(-1) ignored its negative input");
3452 expect(df
, "1122.123", -1122.123);
3453 expect(df
, "-1122.123", 1122.123);
3454 expect(df
, "1.2", -1.2);
3455 expect(df
, "-1.2", 1.2);
3457 // Note: the tests with the final parameter of FALSE will not round trip.
3458 // The initial numeric value will format correctly, after the multiplier.
3459 // Parsing the formatted text will be out-of-range for an int64, however.
3460 // The expect() function could be modified to detect this and fall back
3461 // to looking at the decimal parsed value, but it doesn't.
3462 expect(df
, U_INT64_MIN
, "9223372036854775808", FALSE
);
3463 expect(df
, U_INT64_MIN
+1, "9223372036854775807");
3464 expect(df
, (int64_t)-123, "123");
3465 expect(df
, (int64_t)123, "-123");
3466 expect(df
, U_INT64_MAX
-1, "-9223372036854775806");
3467 expect(df
, U_INT64_MAX
, "-9223372036854775807");
3469 df
.setMultiplier(-2);
3470 expect(df
, -(U_INT64_MIN
/2)-1, "-9223372036854775806");
3471 expect(df
, -(U_INT64_MIN
/2), "-9223372036854775808");
3472 expect(df
, -(U_INT64_MIN
/2)+1, "-9223372036854775810", FALSE
);
3474 df
.setMultiplier(-7);
3475 expect(df
, -(U_INT64_MAX
/7)-1, "9223372036854775814", FALSE
);
3476 expect(df
, -(U_INT64_MAX
/7), "9223372036854775807");
3477 expect(df
, -(U_INT64_MAX
/7)+1, "9223372036854775800");
3479 // TODO: uncomment (and fix up) all the following int64_t tests once BigInteger is ported
3480 // (right now the big numbers get turned into doubles and lose tons of accuracy)
3481 //expect2(df, U_INT64_MAX, Int64ToUnicodeString(-U_INT64_MAX));
3482 //expect2(df, U_INT64_MIN, UnicodeString(Int64ToUnicodeString(U_INT64_MIN), 1));
3483 //expect2(df, U_INT64_MAX / 2, Int64ToUnicodeString(-(U_INT64_MAX / 2)));
3484 //expect2(df, U_INT64_MIN / 2, Int64ToUnicodeString(-(U_INT64_MIN / 2)));
3486 // TODO: uncomment (and fix up) once BigDecimal is ported and DecimalFormat can handle it
3487 //expect2(df, BigDecimal.valueOf(Long.MAX_VALUE), BigDecimal.valueOf(Long.MAX_VALUE).negate().toString());
3488 //expect2(df, BigDecimal.valueOf(Long.MIN_VALUE), BigDecimal.valueOf(Long.MIN_VALUE).negate().toString());
3489 //expect2(df, java.math.BigDecimal.valueOf(Long.MAX_VALUE), java.math.BigDecimal.valueOf(Long.MAX_VALUE).negate().toString());
3490 //expect2(df, java.math.BigDecimal.valueOf(Long.MIN_VALUE), java.math.BigDecimal.valueOf(Long.MIN_VALUE).negate().toString());
3494 const char * stringToParse
;
3498 } TestSpaceParsingItem
;
3501 NumberFormatTest::TestSpaceParsing() {
3503 // the string to be parsed, parsed position, parsed error index
3504 const TestSpaceParsingItem DATA
[] = {
3505 // TOTO: Update the following TODOs, some may be handled now
3506 {"$124", 4, -1, FALSE
},
3507 {"$124 $124", 4, -1, FALSE
},
3508 {"$124 ", 4, -1, FALSE
},
3509 //{"$ 124 ", 5, -1, FALSE}, // TODO: need to handle space correctly
3510 //{"$\\u00A0124 ", 5, -1, FALSE}, // TODO: need to handle space correctly
3511 {"$ 124 ", 0, 1, FALSE
}, // errorIndex used to be 0, now 1 (better)
3512 {"$\\u00A0124 ", 5, -1, FALSE
}, // errorIndex used to be 0, now 1 (better) *Apple change from open source*
3513 {" $ 124 ", 0, 0, FALSE
}, // TODO: need to handle space correctly
3514 {"124$", 0, 3, FALSE
}, // TODO: need to handle space correctly
3515 // {"124 $", 5, -1, FALSE}, // TODO: OK or not, need currency spacing rule
3516 {"124 $", 0, 3, FALSE
},
3517 {"$124", 4, -1, TRUE
},
3518 {"$124 $124", 4, -1, TRUE
},
3519 {"$124 ", 4, -1, TRUE
},
3520 {"$ 124 ", 5, -1, TRUE
},
3521 {"$\\u00A0124 ", 5, -1, TRUE
},
3522 {" $ 124 ", 6, -1, TRUE
},
3523 //{"124$", 4, -1, TRUE}, // TODO: need to handle trailing currency correctly
3524 {"124$", 3, -1, TRUE
},
3525 //{"124 $", 5, -1, TRUE}, // TODO: OK or not, need currency spacing rule
3526 {"124 $", 4, -1, TRUE
},
3528 UErrorCode status
= U_ZERO_ERROR
;
3529 Locale
locale("en_US");
3530 NumberFormat
* foo
= NumberFormat::createCurrencyInstance(locale
, status
);
3532 if (U_FAILURE(status
)) {
3536 for (uint32_t i
= 0; i
< UPRV_LENGTHOF(DATA
); ++i
) {
3537 ParsePosition
parsePosition(0);
3538 UnicodeString stringToBeParsed
= ctou(DATA
[i
].stringToParse
);
3539 int parsedPosition
= DATA
[i
].parsedPos
;
3540 int errorIndex
= DATA
[i
].errorIndex
;
3541 foo
->setLenient(DATA
[i
].lenient
);
3543 foo
->parse(stringToBeParsed
, result
, parsePosition
);
3544 if (parsePosition
.getIndex() != parsedPosition
||
3545 parsePosition
.getErrorIndex() != errorIndex
) {
3546 errln("FAILED parse " + stringToBeParsed
+ "; lenient: " + DATA
[i
].lenient
+ "; wrong position, expected: (" + parsedPosition
+ ", " + errorIndex
+ "); got (" + parsePosition
.getIndex() + ", " + parsePosition
.getErrorIndex() + ")");
3548 if (parsePosition
.getErrorIndex() == -1 &&
3549 result
.getType() == Formattable::kLong
&&
3550 result
.getLong() != 124) {
3551 errln("FAILED parse " + stringToBeParsed
+ "; wrong number, expect: 124, got " + result
.getLong());
3558 * Test using various numbering systems and numbering system keyword.
3561 const char *localeName
;
3564 const char *expectedResult
;
3565 } TestNumberingSystemItem
;
3567 void NumberFormatTest::TestNumberingSystems() {
3569 const TestNumberingSystemItem DATA
[] = {
3570 { "en_US@numbers=thai", 1234.567, FALSE
, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" },
3571 { "en_US@numbers=hebr", 5678.0, TRUE
, "\\u05D4\\u05F3\\u05EA\\u05E8\\u05E2\\u05F4\\u05D7" },
3572 { "en_US@numbers=arabext", 1234.567, FALSE
, "\\u06F1\\u066c\\u06F2\\u06F3\\u06F4\\u066b\\u06F5\\u06F6\\u06F7" },
3573 { "ar_EG", 1234.567, FALSE
, "\\u0661\\u066C\\u0662\\u0663\\u0664\\u066b\\u0665\\u0666\\u0667" },
3574 { "th_TH@numbers=traditional", 1234.567, FALSE
, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" }, // fall back to native per TR35
3575 { "ar_MA", 1234.567, FALSE
, "1.234,567" },
3576 { "en_US@numbers=hanidec", 1234.567, FALSE
, "\\u4e00,\\u4e8c\\u4e09\\u56db.\\u4e94\\u516d\\u4e03" },
3577 { "ta_IN@numbers=native", 1234.567, FALSE
, "\\u0BE7,\\u0BE8\\u0BE9\\u0BEA.\\u0BEB\\u0BEC\\u0BED" },
3578 { "ta_IN@numbers=traditional", 1235.0, TRUE
, "\\u0BF2\\u0BE8\\u0BF1\\u0BE9\\u0BF0\\u0BEB" },
3579 { "ta_IN@numbers=finance", 1234.567, FALSE
, "1,234.567" }, // fall back to default per TR35
3580 { "zh_TW@numbers=native", 1234.567, FALSE
, "\\u4e00,\\u4e8c\\u4e09\\u56db.\\u4e94\\u516d\\u4e03" },
3581 { "zh_TW@numbers=traditional", 1234.567, TRUE
, "\\u4E00\\u5343\\u4E8C\\u767E\\u4E09\\u5341\\u56DB\\u9EDE\\u4E94\\u516D\\u4E03" },
3582 { "zh_TW@numbers=finance", 1234.567, TRUE
, "\\u58F9\\u4EDF\\u8CB3\\u4F70\\u53C3\\u62FE\\u8086\\u9EDE\\u4F0D\\u9678\\u67D2" },
3583 { NULL
, 0, FALSE
, NULL
}
3588 const TestNumberingSystemItem
*item
;
3589 for (item
= DATA
; item
->localeName
!= NULL
; item
++) {
3591 Locale loc
= Locale::createFromName(item
->localeName
);
3593 NumberFormat
*origFmt
= NumberFormat::createInstance(loc
,ec
);
3594 if (U_FAILURE(ec
)) {
3595 dataerrln("FAIL: getInstance(%s) - %s", item
->localeName
, u_errorName(ec
));
3598 // Clone to test ticket #10682
3599 NumberFormat
*fmt
= (NumberFormat
*) origFmt
->clone();
3604 expect3(*fmt
,item
->value
,CharsToUnicodeString(item
->expectedResult
));
3606 expect2(*fmt
,item
->value
,CharsToUnicodeString(item
->expectedResult
));
3612 // Test bogus keyword value
3614 Locale loc4
= Locale::createFromName("en_US@numbers=foobar");
3615 NumberFormat
* fmt4
= NumberFormat::createInstance(loc4
, ec
);
3616 if ( ec
!= U_UNSUPPORTED_ERROR
) {
3617 errln("FAIL: getInstance(en_US@numbers=foobar) should have returned U_UNSUPPORTED_ERROR");
3622 NumberingSystem
*ns
= NumberingSystem::createInstance(ec
);
3623 if (U_FAILURE(ec
)) {
3624 dataerrln("FAIL: NumberingSystem::createInstance(ec); - %s", u_errorName(ec
));
3628 ns
->getDynamicClassID();
3629 ns
->getStaticClassID();
3631 errln("FAIL: getInstance() returned NULL.");
3634 NumberingSystem
*ns1
= new NumberingSystem(*ns
);
3636 errln("FAIL: NumberSystem copy constructor returned NULL.");
3646 NumberFormatTest::TestMultiCurrencySign() {
3647 const char* DATA
[][6] = {
3648 // the fields in the following test are:
3650 // currency pattern (with negative pattern),
3651 // currency number to be formatted,
3652 // currency format using currency symbol name, such as "$" for USD,
3653 // currency format using currency ISO name, such as "USD",
3654 // currency format using plural name, such as "US dollars".
3656 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "1234.56", "$1,234.56", "USD1,234.56", "US dollars1,234.56"},
3657 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "-1234.56", "-$1,234.56", "-USD1,234.56", "-US dollars1,234.56"},
3658 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "1", "$1.00", "USD1.00", "US dollars1.00"},
3660 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "1234.56", "\\uFFE51,234.56", "CNY1,234.56", "\\u4EBA\\u6C11\\u5E011,234.56"},
3661 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "-1234.56", "(\\uFFE51,234.56)", "(CNY1,234.56)", "(\\u4EBA\\u6C11\\u5E011,234.56)"},
3662 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "1", "\\uFFE51.00", "CNY1.00", "\\u4EBA\\u6C11\\u5E011.00"}
3665 const UChar doubleCurrencySign
[] = {0xA4, 0xA4, 0};
3666 UnicodeString
doubleCurrencyStr(doubleCurrencySign
);
3667 const UChar tripleCurrencySign
[] = {0xA4, 0xA4, 0xA4, 0};
3668 UnicodeString
tripleCurrencyStr(tripleCurrencySign
);
3670 for (uint32_t i
=0; i
<UPRV_LENGTHOF(DATA
); ++i
) {
3671 const char* locale
= DATA
[i
][0];
3672 UnicodeString pat
= ctou(DATA
[i
][1]);
3673 double numberToBeFormat
= atof(DATA
[i
][2]);
3674 UErrorCode status
= U_ZERO_ERROR
;
3675 DecimalFormatSymbols
* sym
= new DecimalFormatSymbols(Locale(locale
), status
);
3676 if (U_FAILURE(status
)) {
3680 for (int j
=1; j
<=3; ++j
) {
3681 // j represents the number of currency sign in the pattern.
3683 pat
= pat
.findAndReplace(ctou("\\u00A4"), doubleCurrencyStr
);
3684 } else if (j
== 3) {
3685 pat
= pat
.findAndReplace(ctou("\\u00A4\\u00A4"), tripleCurrencyStr
);
3688 DecimalFormat
* fmt
= new DecimalFormat(pat
, new DecimalFormatSymbols(*sym
), status
);
3689 if (U_FAILURE(status
)) {
3690 errln("FAILED init DecimalFormat ");
3695 ((NumberFormat
*) fmt
)->format(numberToBeFormat
, s
);
3696 // DATA[i][3] is the currency format result using a
3697 // single currency sign.
3698 // DATA[i][4] is the currency format result using
3699 // double currency sign.
3700 // DATA[i][5] is the currency format result using
3701 // triple currency sign.
3702 // DATA[i][j+2] is the currency format result using
3703 // 'j' number of currency sign.
3704 UnicodeString currencyFormatResult
= ctou(DATA
[i
][2+j
]);
3705 if (s
.compare(currencyFormatResult
)) {
3706 errln("FAIL format: Expected " + currencyFormatResult
+ "; Got " + s
);
3708 // mix style parsing
3709 for (int k
=3; k
<=5; ++k
) {
3710 // DATA[i][3] is the currency format result using a
3711 // single currency sign.
3712 // DATA[i][4] is the currency format result using
3713 // double currency sign.
3714 // DATA[i][5] is the currency format result using
3715 // triple currency sign.
3716 UnicodeString oneCurrencyFormat
= ctou(DATA
[i
][k
]);
3717 UErrorCode status
= U_ZERO_ERROR
;
3718 Formattable parseRes
;
3719 fmt
->parse(oneCurrencyFormat
, parseRes
, status
);
3720 if (U_FAILURE(status
) ||
3721 (parseRes
.getType() == Formattable::kDouble
&&
3722 parseRes
.getDouble() != numberToBeFormat
) ||
3723 (parseRes
.getType() == Formattable::kLong
&&
3724 parseRes
.getLong() != numberToBeFormat
)) {
3725 errln("FAILED parse " + oneCurrencyFormat
+ "; (i, j, k): " +
3726 i
+ ", " + j
+ ", " + k
);
3737 NumberFormatTest::TestCurrencyFormatForMixParsing() {
3738 UErrorCode status
= U_ZERO_ERROR
;
3739 MeasureFormat
* curFmt
= MeasureFormat::createCurrencyFormat(Locale("en_US"), status
);
3740 if (U_FAILURE(status
)) {
3744 const char* formats
[] = {
3745 "$1,234.56", // string to be parsed
3747 "US dollars1,234.56",
3748 "1,234.56 US dollars"
3750 const CurrencyAmount
* curramt
= NULL
;
3751 for (uint32_t i
= 0; i
< UPRV_LENGTHOF(formats
); ++i
) {
3752 UnicodeString stringToBeParsed
= ctou(formats
[i
]);
3753 logln(UnicodeString("stringToBeParsed: ") + stringToBeParsed
);
3755 UErrorCode status
= U_ZERO_ERROR
;
3756 curFmt
->parseObject(stringToBeParsed
, result
, status
);
3757 if (U_FAILURE(status
)) {
3758 errln("FAIL: measure format parsing: '%s' ec: %s", formats
[i
], u_errorName(status
));
3759 } else if (result
.getType() != Formattable::kObject
||
3760 (curramt
= dynamic_cast<const CurrencyAmount
*>(result
.getObject())) == NULL
||
3761 curramt
->getNumber().getDouble() != 1234.56 ||
3762 UnicodeString(curramt
->getISOCurrency()).compare(ISO_CURRENCY_USD
)
3764 errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the number ");
3765 if (curramt
->getNumber().getDouble() != 1234.56) {
3766 errln((UnicodeString
)"wong number, expect: 1234.56" + ", got: " + curramt
->getNumber().getDouble());
3768 if (curramt
->getISOCurrency() != ISO_CURRENCY_USD
) {
3769 errln((UnicodeString
)"wong currency, expect: USD" + ", got: " + curramt
->getISOCurrency());
3778 NumberFormatTest::TestDecimalFormatCurrencyParse() {
3780 UErrorCode status
= U_ZERO_ERROR
;
3781 DecimalFormatSymbols
* sym
= new DecimalFormatSymbols(Locale("en_US"), status
);
3782 if (U_FAILURE(status
)) {
3787 UChar currency
= 0x00A4;
3788 // "\xA4#,##0.00;-\xA4#,##0.00"
3789 pat
.append(currency
).append(currency
).append(currency
).append("#,##0.00;-").append(currency
).append(currency
).append(currency
).append("#,##0.00");
3790 DecimalFormat
* fmt
= new DecimalFormat(pat
, sym
, status
);
3791 if (U_FAILURE(status
)) {
3793 errln("failed to new DecimalFormat in TestDecimalFormatCurrencyParse");
3796 const char* DATA
[][2] = {
3798 // string to be parsed, the parsed result (number)
3801 {"1.00 US dollar", "1"},
3802 {"$1,234.56", "1234.56"},
3803 {"USD1,234.56", "1234.56"},
3804 {"1,234.56 US dollar", "1234.56"},
3806 for (uint32_t i
= 0; i
< UPRV_LENGTHOF(DATA
); ++i
) {
3807 UnicodeString stringToBeParsed
= ctou(DATA
[i
][0]);
3808 double parsedResult
= atof(DATA
[i
][1]);
3809 UErrorCode status
= U_ZERO_ERROR
;
3811 fmt
->parse(stringToBeParsed
, result
, status
);
3812 if (U_FAILURE(status
) ||
3813 (result
.getType() == Formattable::kDouble
&&
3814 result
.getDouble() != parsedResult
) ||
3815 (result
.getType() == Formattable::kLong
&&
3816 result
.getLong() != parsedResult
)) {
3817 errln((UnicodeString
)"FAIL parse: Expected " + parsedResult
);
3825 NumberFormatTest::TestCurrencyIsoPluralFormat() {
3826 static const char* DATA
[][6] = {
3829 // currency amount to be formatted,
3830 // currency ISO code to be formatted,
3831 // format result using CURRENCYSTYLE,
3832 // format result using ISOCURRENCYSTYLE,
3833 // format result using PLURALCURRENCYSTYLE,
3835 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollars"},
3836 {"en_US", "1234.56", "USD", "$1,234.56", "USD1,234.56", "1,234.56 US dollars"},
3837 {"en_US", "-1234.56", "USD", "-$1,234.56", "-USD1,234.56", "-1,234.56 US dollars"},
3838 {"zh_CN", "1", "USD", "US$1.00", "USD1.00", "1.00\\u7F8E\\u5143"},
3839 {"zh_CN", "1234.56", "USD", "US$1,234.56", "USD1,234.56", "1,234.56\\u7F8E\\u5143"},
3840 {"zh_CN", "1", "CNY", "\\uFFE51.00", "CNY1.00", "1.00\\u4EBA\\u6C11\\u5E01"},
3841 {"zh_CN", "1234.56", "CNY", "\\uFFE51,234.56", "CNY1,234.56", "1,234.56\\u4EBA\\u6C11\\u5E01"},
3842 {"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"},
3843 {"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"},
3844 {"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"},
3845 // test locale without currency information
3846 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 USD"},
3847 // test choice format
3848 {"es_AR", "1", "INR", "INR\\u00A01,00", "INR\\u00A01,00", "1,00 rupia india"},
3850 static const UNumberFormatStyle currencyStyles
[] = {
3853 UNUM_CURRENCY_PLURAL
3856 for (int32_t i
=0; i
<UPRV_LENGTHOF(DATA
); ++i
) {
3857 for (int32_t kIndex
= 0; kIndex
< UPRV_LENGTHOF(currencyStyles
); ++kIndex
) {
3858 UNumberFormatStyle k
= currencyStyles
[kIndex
];
3859 const char* localeString
= DATA
[i
][0];
3860 double numberToBeFormat
= atof(DATA
[i
][1]);
3861 const char* currencyISOCode
= DATA
[i
][2];
3862 Locale
locale(localeString
);
3863 UErrorCode status
= U_ZERO_ERROR
;
3864 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, k
, status
);
3865 if (U_FAILURE(status
)) {
3867 dataerrln((UnicodeString
)"can not create instance, locale:" + localeString
+ ", style: " + k
+ " - " + u_errorName(status
));
3870 UChar currencyCode
[4];
3871 u_charsToUChars(currencyISOCode
, currencyCode
, 4);
3872 numFmt
->setCurrency(currencyCode
, status
);
3873 if (U_FAILURE(status
)) {
3875 errln((UnicodeString
)"can not set currency:" + currencyISOCode
);
3879 UnicodeString strBuf
;
3880 numFmt
->format(numberToBeFormat
, strBuf
);
3881 int resultDataIndex
= 3 + kIndex
;
3882 // DATA[i][resultDataIndex] is the currency format result
3883 // using 'k' currency style.
3884 UnicodeString formatResult
= ctou(DATA
[i
][resultDataIndex
]);
3885 if (strBuf
.compare(formatResult
)) {
3886 errln("FAIL: Expected " + formatResult
+ " actual: " + strBuf
);
3888 // test parsing, and test parsing for all currency formats.
3889 for (int j
= 3; j
< 6; ++j
) {
3890 // DATA[i][3] is the currency format result using
3891 // CURRENCYSTYLE formatter.
3892 // DATA[i][4] is the currency format result using
3893 // ISOCURRENCYSTYLE formatter.
3894 // DATA[i][5] is the currency format result using
3895 // PLURALCURRENCYSTYLE formatter.
3896 UnicodeString oneCurrencyFormatResult
= ctou(DATA
[i
][j
]);
3897 UErrorCode status
= U_ZERO_ERROR
;
3898 Formattable parseResult
;
3899 numFmt
->parse(oneCurrencyFormatResult
, parseResult
, status
);
3900 if (U_FAILURE(status
) ||
3901 (parseResult
.getType() == Formattable::kDouble
&&
3902 parseResult
.getDouble() != numberToBeFormat
) ||
3903 (parseResult
.getType() == Formattable::kLong
&&
3904 parseResult
.getLong() != numberToBeFormat
)) {
3905 errln((UnicodeString
)"FAIL: getCurrencyFormat of locale " +
3906 localeString
+ " failed roundtripping the number");
3907 if (parseResult
.getType() == Formattable::kDouble
) {
3908 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual: " +parseResult
.getDouble());
3910 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual: " +parseResult
.getLong());
3920 NumberFormatTest::TestCurrencyParsing() {
3921 static const char* DATA
[][6] = {
3924 // currency amount to be formatted,
3925 // currency ISO code to be formatted,
3926 // format result using CURRENCYSTYLE,
3927 // format result using ISOCURRENCYSTYLE,
3928 // format result using PLURALCURRENCYSTYLE,
3929 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollar"},
3930 {"pa_IN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00 \\u0a2f\\u0a42.\\u0a10\\u0a38. \\u0a21\\u0a3e\\u0a32\\u0a30"},
3931 {"es_AR", "1", "USD", "US$\\u00A01,00", "USD\\u00A01,00", "1,00 d\\u00f3lar estadounidense"},
3932 {"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"},
3933 {"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"},
3934 {"he_IL", "1", "USD", "1.00\\u00a0$", "1.00\\u00a0USD", "1.00 \\u05d3\\u05d5\\u05dc\\u05e8 \\u05d0\\u05de\\u05e8\\u05d9\\u05e7\\u05d0\\u05d9"},
3935 {"hr_HR", "1", "USD", "1,00\\u00a0USD", "1,00\\u00a0USD", "1,00 Ameri\\u010dki dolar"},
3936 {"id_ID", "1", "USD", "US$1,00", "USD1,00", "1,00 Dolar Amerika Serikat"},
3937 {"it_IT", "1", "USD", "1,00\\u00a0US$", "1,00\\u00a0USD", "1,00 Dollaro Statunitense"},
3938 {"ko_KR", "1", "USD", "US$1.00", "USD1.00", "1.00 \\ubbf8\\uad6d \\ub2ec\\ub7ec"},
3939 {"ja_JP", "1", "USD", "$1.00", "USD1.00", "1.00\\u7c73\\u30c9\\u30eb"},
3940 {"zh_CN", "1", "CNY", "\\uFFE51.00", "CNY01.00", "1.00\\u4EBA\\u6C11\\u5E01"},
3941 {"zh_TW", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\u5e63"},
3942 {"zh_Hant", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\u5e63"},
3943 {"zh_Hant", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u5713"},
3944 {"ja_JP", "1", "JPY", "\\uFFE51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u5186"},
3945 {"ja_JP", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u5186"},
3946 {"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"}
3948 static const UNumberFormatStyle currencyStyles
[] = {
3951 UNUM_CURRENCY_PLURAL
3953 static const char* currencyStyleNames
[] = {
3955 "UNUM_CURRENCY_ISO",
3956 "UNUM_CURRENCY_PLURAL"
3959 #ifdef NUMFMTST_CACHE_DEBUG
3962 printf("loop: %d\n", deadloop
++);
3964 for (uint32_t i
=0; i
< UPRV_LENGTHOF(DATA
); ++i
) { /* i = test case # - should be i=0*/
3965 for (int32_t kIndex
= 2; kIndex
< UPRV_LENGTHOF(currencyStyles
); ++kIndex
) {
3966 UNumberFormatStyle k
= currencyStyles
[kIndex
]; /* k = style */
3967 const char* localeString
= DATA
[i
][0];
3968 double numberToBeFormat
= atof(DATA
[i
][1]);
3969 const char* currencyISOCode
= DATA
[i
][2];
3970 Locale
locale(localeString
);
3971 UErrorCode status
= U_ZERO_ERROR
;
3972 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, k
, status
);
3973 logln("#%d NumberFormat(%s, %s) Currency=%s\n",
3974 i
, localeString
, currencyStyleNames
[kIndex
],
3977 if (U_FAILURE(status
)) {
3979 dataerrln((UnicodeString
)"can not create instance, locale:" + localeString
+ ", style: " + k
+ " - " + u_errorName(status
));
3982 UChar currencyCode
[4];
3983 u_charsToUChars(currencyISOCode
, currencyCode
, 4);
3984 numFmt
->setCurrency(currencyCode
, status
);
3985 if (U_FAILURE(status
)) {
3987 errln((UnicodeString
)"can not set currency:" + currencyISOCode
);
3991 UnicodeString strBuf
;
3992 numFmt
->format(numberToBeFormat
, strBuf
);
3994 int resultDataIndex = 3 + kIndex;
3995 // DATA[i][resultDataIndex] is the currency format result
3996 // using 'k' currency style.
3997 UnicodeString formatResult = ctou(DATA[i][resultDataIndex]);
3998 if (strBuf.compare(formatResult)) {
3999 errln("FAIL: Expected " + formatResult + " actual: " + strBuf);
4002 // test parsing, and test parsing for all currency formats.
4003 for (int j
= 3; j
< 6; ++j
) {
4004 // DATA[i][3] is the currency format result using
4005 // CURRENCYSTYLE formatter.
4006 // DATA[i][4] is the currency format result using
4007 // ISOCURRENCYSTYLE formatter.
4008 // DATA[i][5] is the currency format result using
4009 // PLURALCURRENCYSTYLE formatter.
4010 UnicodeString oneCurrencyFormatResult
= ctou(DATA
[i
][j
]);
4011 UErrorCode status
= U_ZERO_ERROR
;
4012 Formattable parseResult
;
4013 logln("parse(%s)", DATA
[i
][j
]);
4014 numFmt
->parse(oneCurrencyFormatResult
, parseResult
, status
);
4015 if (U_FAILURE(status
) ||
4016 (parseResult
.getType() == Formattable::kDouble
&&
4017 parseResult
.getDouble() != numberToBeFormat
) ||
4018 (parseResult
.getType() == Formattable::kLong
&&
4019 parseResult
.getLong() != numberToBeFormat
)) {
4020 errln((UnicodeString
)"FAIL: NumberFormat(" + localeString
+", " + currencyStyleNames
[kIndex
] +
4021 "), Currency="+currencyISOCode
+", parse("+DATA
[i
][j
]+") returned error " + (UnicodeString
)u_errorName(status
)+". Testcase: data[" + i
+ "][" + currencyStyleNames
[j
-3] +"="+j
+"]");
4022 if (parseResult
.getType() == Formattable::kDouble
) {
4023 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual (double): " +parseResult
.getDouble());
4025 errln((UnicodeString
)"expected: " + numberToBeFormat
+ "; actual (long): " +parseResult
.getLong());
4027 errln((UnicodeString
)" round-trip would be: " + strBuf
);
4033 #ifdef NUMFMTST_CACHE_DEBUG
4040 NumberFormatTest::TestParseCurrencyInUCurr() {
4041 const char* DATA
[] = {
4042 "1.00 US DOLLAR", // case in-sensitive
4079 "Afghan Afghani (1927\\u20132002)1.00",
4080 "Afghan afghani (1927\\u20132002)1.00",
4081 "Afghan Afghani1.00",
4082 "Afghan Afghanis1.00",
4085 "Albanian lek\\u00eb1.00",
4086 "Algerian Dinar1.00",
4087 "Algerian dinar1.00",
4088 "Algerian dinars1.00",
4089 "Andorran Peseta1.00",
4090 "Andorran peseta1.00",
4091 "Andorran pesetas1.00",
4092 "Angolan Kwanza (1977\\u20131991)1.00",
4093 "Angolan Readjusted Kwanza (1995\\u20131999)1.00",
4094 "Angolan Kwanza1.00",
4095 "Angolan New Kwanza (1990\\u20132000)1.00",
4096 "Angolan kwanza (1977\\u20131991)1.00",
4097 "Angolan readjusted kwanza (1995\\u20131999)1.00",
4098 "Angolan kwanza1.00",
4099 "Angolan kwanzas (1977\\u20131991)1.00",
4100 "Angolan readjusted kwanzas (1995\\u20131999)1.00",
4101 "Angolan kwanzas1.00",
4102 "Angolan new kwanza (1990\\u20132000)1.00",
4103 "Angolan new kwanzas (1990\\u20132000)1.00",
4104 "Argentine Austral1.00",
4105 "Argentine Peso (1983\\u20131985)1.00",
4106 "Argentine Peso1.00",
4107 "Argentine austral1.00",
4108 "Argentine australs1.00",
4109 "Argentine peso (1983\\u20131985)1.00",
4110 "Argentine peso1.00",
4111 "Argentine pesos (1983\\u20131985)1.00",
4112 "Argentine pesos1.00",
4113 "Armenian Dram1.00",
4114 "Armenian dram1.00",
4115 "Armenian drams1.00",
4116 "Aruban Florin1.00",
4117 "Aruban florin1.00",
4118 "Australian Dollar1.00",
4119 "Australian dollar1.00",
4120 "Australian dollars1.00",
4121 "Austrian Schilling1.00",
4122 "Austrian schilling1.00",
4123 "Austrian schillings1.00",
4124 "Azerbaijani Manat (1993\\u20132006)1.00",
4125 "Azerbaijani Manat1.00",
4126 "Azerbaijani manat (1993\\u20132006)1.00",
4127 "Azerbaijani manat1.00",
4128 "Azerbaijani manats (1993\\u20132006)1.00",
4129 "Azerbaijani manats1.00",
4173 "Bahamian Dollar1.00",
4174 "Bahamian dollar1.00",
4175 "Bahamian dollars1.00",
4176 "Bahraini Dinar1.00",
4177 "Bahraini dinar1.00",
4178 "Bahraini dinars1.00",
4179 "Bangladeshi Taka1.00",
4180 "Bangladeshi taka1.00",
4181 "Bangladeshi takas1.00",
4182 "Barbadian Dollar1.00",
4183 "Barbadian dollar1.00",
4184 "Barbadian dollars1.00",
4185 "Belarusian New Ruble (1994\\u20131999)1.00",
4186 "Belarusian Ruble1.00",
4187 "Belarusian new ruble (1994\\u20131999)1.00",
4188 "Belarusian new rubles (1994\\u20131999)1.00",
4189 "Belarusian ruble1.00",
4190 "Belarusian rubles1.00",
4191 "Belgian Franc (convertible)1.00",
4192 "Belgian Franc (financial)1.00",
4193 "Belgian Franc1.00",
4194 "Belgian franc (convertible)1.00",
4195 "Belgian franc (financial)1.00",
4196 "Belgian franc1.00",
4197 "Belgian francs (convertible)1.00",
4198 "Belgian francs (financial)1.00",
4199 "Belgian francs1.00",
4200 "Belize Dollar1.00",
4201 "Belize dollar1.00",
4202 "Belize dollars1.00",
4203 "Bermudan Dollar1.00",
4204 "Bermudan dollar1.00",
4205 "Bermudan dollars1.00",
4206 "Bhutanese Ngultrum1.00",
4207 "Bhutanese ngultrum1.00",
4208 "Bhutanese ngultrums1.00",
4209 "Bolivian Mvdol1.00",
4210 "Bolivian Peso1.00",
4211 "Bolivian mvdol1.00",
4212 "Bolivian mvdols1.00",
4213 "Bolivian peso1.00",
4214 "Bolivian pesos1.00",
4215 "Bolivian Boliviano1.00",
4216 "Bolivian Boliviano1.00",
4217 "Bolivian Bolivianos1.00",
4218 "Bosnia-Herzegovina Convertible Mark1.00",
4219 "Bosnia-Herzegovina Dinar (1992\\u20131994)1.00",
4220 "Bosnia-Herzegovina convertible mark1.00",
4221 "Bosnia-Herzegovina convertible marks1.00",
4222 "Bosnia-Herzegovina dinar (1992\\u20131994)1.00",
4223 "Bosnia-Herzegovina dinars (1992\\u20131994)1.00",
4224 "Botswanan Pula1.00",
4225 "Botswanan pula1.00",
4226 "Botswanan pulas1.00",
4227 "Brazilian New Cruzado (1989\\u20131990)1.00",
4228 "Brazilian Cruzado (1986\\u20131989)1.00",
4229 "Brazilian Cruzeiro (1990\\u20131993)1.00",
4230 "Brazilian New Cruzeiro (1967\\u20131986)1.00",
4231 "Brazilian Cruzeiro (1993\\u20131994)1.00",
4232 "Brazilian Real1.00",
4233 "Brazilian new cruzado (1989\\u20131990)1.00",
4234 "Brazilian new cruzados (1989\\u20131990)1.00",
4235 "Brazilian cruzado (1986\\u20131989)1.00",
4236 "Brazilian cruzados (1986\\u20131989)1.00",
4237 "Brazilian cruzeiro (1990\\u20131993)1.00",
4238 "Brazilian new cruzeiro (1967\\u20131986)1.00",
4239 "Brazilian cruzeiro (1993\\u20131994)1.00",
4240 "Brazilian cruzeiros (1990\\u20131993)1.00",
4241 "Brazilian new cruzeiros (1967\\u20131986)1.00",
4242 "Brazilian cruzeiros (1993\\u20131994)1.00",
4243 "Brazilian real1.00",
4244 "Brazilian reals1.00",
4245 "British Pound1.00",
4246 "British pound1.00",
4247 "British pounds1.00",
4248 "Brunei Dollar1.00",
4249 "Brunei dollar1.00",
4250 "Brunei dollars1.00",
4251 "Bulgarian Hard Lev1.00",
4252 "Bulgarian Lev1.00",
4253 "Bulgarian Leva1.00",
4254 "Bulgarian hard lev1.00",
4255 "Bulgarian hard leva1.00",
4256 "Bulgarian lev1.00",
4259 "Burmese kyats1.00",
4260 "Burundian Franc1.00",
4261 "Burundian franc1.00",
4262 "Burundian francs1.00",
4267 "West African CFA Franc1.00",
4268 "Central African CFA Franc1.00",
4269 "West African CFA franc1.00",
4270 "Central African CFA franc1.00",
4271 "West African CFA francs1.00",
4272 "Central African CFA francs1.00",
4299 "Cambodian Riel1.00",
4300 "Cambodian riel1.00",
4301 "Cambodian riels1.00",
4302 "Canadian Dollar1.00",
4303 "Canadian dollar1.00",
4304 "Canadian dollars1.00",
4305 "Cape Verdean Escudo1.00",
4306 "Cape Verdean escudo1.00",
4307 "Cape Verdean escudos1.00",
4308 "Cayman Islands Dollar1.00",
4309 "Cayman Islands dollar1.00",
4310 "Cayman Islands dollars1.00",
4312 "Chilean Unit of Account (UF)1.00",
4314 "Chilean pesos1.00",
4315 "Chilean unit of account (UF)1.00",
4316 "Chilean units of account (UF)1.00",
4319 "Colombian Peso1.00",
4320 "Colombian peso1.00",
4321 "Colombian pesos1.00",
4322 "Comorian Franc1.00",
4323 "Comorian franc1.00",
4324 "Comorian francs1.00",
4325 "Congolese Franc1.00",
4326 "Congolese franc1.00",
4327 "Congolese francs1.00",
4328 "Costa Rican Col\\u00f3n1.00",
4329 "Costa Rican col\\u00f3n1.00",
4330 "Costa Rican col\\u00f3ns1.00",
4331 "Croatian Dinar1.00",
4332 "Croatian Kuna1.00",
4333 "Croatian dinar1.00",
4334 "Croatian dinars1.00",
4335 "Croatian kuna1.00",
4336 "Croatian kunas1.00",
4340 "Cypriot Pound1.00",
4341 "Cypriot pound1.00",
4342 "Cypriot pounds1.00",
4343 "Czech Republic Koruna1.00",
4344 "Czech Republic koruna1.00",
4345 "Czech Republic korunas1.00",
4346 "Czechoslovak Hard Koruna1.00",
4347 "Czechoslovak hard koruna1.00",
4348 "Czechoslovak hard korunas1.00",
4359 "Danish kroner1.00",
4363 "Djiboutian Franc1.00",
4364 "Djiboutian franc1.00",
4365 "Djiboutian francs1.00",
4366 "Dominican Peso1.00",
4367 "Dominican peso1.00",
4368 "Dominican pesos1.00",
4387 "East Caribbean Dollar1.00",
4388 "East Caribbean dollar1.00",
4389 "East Caribbean dollars1.00",
4390 "East German Mark1.00",
4391 "East German mark1.00",
4392 "East German marks1.00",
4393 "Ecuadorian Sucre1.00",
4394 "Ecuadorian Unit of Constant Value1.00",
4395 "Ecuadorian sucre1.00",
4396 "Ecuadorian sucres1.00",
4397 "Ecuadorian unit of constant value1.00",
4398 "Ecuadorian units of constant value1.00",
4399 "Egyptian Pound1.00",
4400 "Egyptian pound1.00",
4401 "Egyptian pounds1.00",
4402 "Salvadoran Col\\u00f3n1.00",
4403 "Salvadoran col\\u00f3n1.00",
4404 "Salvadoran colones1.00",
4405 "Equatorial Guinean Ekwele1.00",
4406 "Equatorial Guinean ekwele1.00",
4407 "Eritrean Nakfa1.00",
4408 "Eritrean nakfa1.00",
4409 "Eritrean nakfas1.00",
4410 "Estonian Kroon1.00",
4411 "Estonian kroon1.00",
4412 "Estonian kroons1.00",
4413 "Ethiopian Birr1.00",
4414 "Ethiopian birr1.00",
4415 "Ethiopian birrs1.00",
4417 "European Composite Unit1.00",
4418 "European Currency Unit1.00",
4419 "European Monetary Unit1.00",
4420 "European Unit of Account (XBC)1.00",
4421 "European Unit of Account (XBD)1.00",
4422 "European composite unit1.00",
4423 "European composite units1.00",
4424 "European currency unit1.00",
4425 "European currency units1.00",
4426 "European monetary unit1.00",
4427 "European monetary units1.00",
4428 "European unit of account (XBC)1.00",
4429 "European unit of account (XBD)1.00",
4430 "European units of account (XBC)1.00",
4431 "European units of account (XBD)1.00",
4439 "Falkland Islands Pound1.00",
4440 "Falkland Islands pound1.00",
4441 "Falkland Islands pounds1.00",
4442 "Fijian Dollar1.00",
4443 "Fijian dollar1.00",
4444 "Fijian dollars1.00",
4445 "Finnish Markka1.00",
4446 "Finnish markka1.00",
4447 "Finnish markkas1.00",
4450 "French Gold Franc1.00",
4451 "French UIC-Franc1.00",
4452 "French UIC-franc1.00",
4453 "French UIC-francs1.00",
4455 "French francs1.00",
4456 "French gold franc1.00",
4457 "French gold francs1.00",
4482 "Gambian Dalasi1.00",
4483 "Gambian dalasi1.00",
4484 "Gambian dalasis1.00",
4485 "Georgian Kupon Larit1.00",
4486 "Georgian Lari1.00",
4487 "Georgian kupon larit1.00",
4488 "Georgian kupon larits1.00",
4489 "Georgian lari1.00",
4490 "Georgian laris1.00",
4491 "Ghanaian Cedi (1979\\u20132007)1.00",
4492 "Ghanaian Cedi1.00",
4493 "Ghanaian cedi (1979\\u20132007)1.00",
4494 "Ghanaian cedi1.00",
4495 "Ghanaian cedis (1979\\u20132007)1.00",
4496 "Ghanaian cedis1.00",
4497 "Gibraltar Pound1.00",
4498 "Gibraltar pound1.00",
4499 "Gibraltar pounds1.00",
4502 "Greek Drachma1.00",
4503 "Greek drachma1.00",
4504 "Greek drachmas1.00",
4505 "Guatemalan Quetzal1.00",
4506 "Guatemalan quetzal1.00",
4507 "Guatemalan quetzals1.00",
4508 "Guinean Franc1.00",
4510 "Guinean franc1.00",
4511 "Guinean francs1.00",
4513 "Guinean sylis1.00",
4514 "Guinea-Bissau Peso1.00",
4515 "Guinea-Bissau peso1.00",
4516 "Guinea-Bissau pesos1.00",
4517 "Guyanaese Dollar1.00",
4518 "Guyanaese dollar1.00",
4519 "Guyanaese dollars1.00",
4530 "Haitian Gourde1.00",
4531 "Haitian gourde1.00",
4532 "Haitian gourdes1.00",
4533 "Honduran Lempira1.00",
4534 "Honduran lempira1.00",
4535 "Honduran lempiras1.00",
4536 "Hong Kong Dollar1.00",
4537 "Hong Kong dollar1.00",
4538 "Hong Kong dollars1.00",
4539 "Hungarian Forint1.00",
4540 "Hungarian forint1.00",
4541 "Hungarian forints1.00",
4553 "Icelandic Kr\\u00f3na1.00",
4554 "Icelandic kr\\u00f3na1.00",
4555 "Icelandic kr\\u00f3nur1.00",
4558 "Indian rupees1.00",
4559 "Indonesian Rupiah1.00",
4560 "Indonesian rupiah1.00",
4561 "Indonesian rupiahs1.00",
4564 "Iranian rials1.00",
4571 "Israeli Pound1.00",
4572 "Israeli new sheqel1.00",
4573 "Israeli pound1.00",
4574 "Israeli pounds1.00",
4577 "Italian liras1.00",
4581 "Jamaican Dollar1.00",
4582 "Jamaican dollar1.00",
4583 "Jamaican dollars1.00",
4586 "Jordanian Dinar1.00",
4587 "Jordanian dinar1.00",
4588 "Jordanian dinars1.00",
4600 "Kazakhstani Tenge1.00",
4601 "Kazakhstani tenge1.00",
4602 "Kazakhstani tenges1.00",
4603 "Kenyan Shilling1.00",
4604 "Kenyan shilling1.00",
4605 "Kenyan shillings1.00",
4606 "Kuwaiti Dinar1.00",
4607 "Kuwaiti dinar1.00",
4608 "Kuwaiti dinars1.00",
4609 "Kyrgystani Som1.00",
4610 "Kyrgystani som1.00",
4611 "Kyrgystani soms1.00",
4639 "Latvian Ruble1.00",
4642 "Latvian ruble1.00",
4643 "Latvian rubles1.00",
4644 "Lebanese Pound1.00",
4645 "Lebanese pound1.00",
4646 "Lebanese pounds1.00",
4649 "Lesotho lotis1.00",
4650 "Liberian Dollar1.00",
4651 "Liberian dollar1.00",
4652 "Liberian dollars1.00",
4655 "Libyan dinars1.00",
4656 "Lithuanian Litas1.00",
4657 "Lithuanian Talonas1.00",
4658 "Lithuanian litas1.00",
4659 "Lithuanian litai1.00",
4660 "Lithuanian talonas1.00",
4661 "Lithuanian talonases1.00",
4662 "Luxembourgian Convertible Franc1.00",
4663 "Luxembourg Financial Franc1.00",
4664 "Luxembourgian Franc1.00",
4665 "Luxembourgian convertible franc1.00",
4666 "Luxembourgian convertible francs1.00",
4667 "Luxembourg financial franc1.00",
4668 "Luxembourg financial francs1.00",
4669 "Luxembourgian franc1.00",
4670 "Luxembourgian francs1.00",
4709 "Macanese Pataca1.00",
4710 "Macanese pataca1.00",
4711 "Macanese patacas1.00",
4712 "Macedonian Denar1.00",
4713 "Macedonian denar1.00",
4714 "Macedonian denari1.00",
4715 "Malagasy Ariaries1.00",
4716 "Malagasy Ariary1.00",
4717 "Malagasy Ariary1.00",
4718 "Malagasy Franc1.00",
4719 "Malagasy franc1.00",
4720 "Malagasy francs1.00",
4721 "Malawian Kwacha1.00",
4722 "Malawian Kwacha1.00",
4723 "Malawian Kwachas1.00",
4724 "Malaysian Ringgit1.00",
4725 "Malaysian ringgit1.00",
4726 "Malaysian ringgits1.00",
4727 "Maldivian Rufiyaa1.00",
4728 "Maldivian rufiyaa1.00",
4729 "Maldivian rufiyaas1.00",
4732 "Malian francs1.00",
4734 "Maltese Pound1.00",
4737 "Maltese pound1.00",
4738 "Maltese pounds1.00",
4739 "Mauritanian Ouguiya1.00",
4740 "Mauritanian ouguiya1.00",
4741 "Mauritanian ouguiyas1.00",
4742 "Mauritian Rupee1.00",
4743 "Mauritian rupee1.00",
4744 "Mauritian rupees1.00",
4746 "Mexican Silver Peso (1861\\u20131992)1.00",
4747 "Mexican Investment Unit1.00",
4749 "Mexican pesos1.00",
4750 "Mexican silver peso (1861\\u20131992)1.00",
4751 "Mexican silver pesos (1861\\u20131992)1.00",
4752 "Mexican investment unit1.00",
4753 "Mexican investment units1.00",
4757 "Mongolian Tugrik1.00",
4758 "Mongolian tugrik1.00",
4759 "Mongolian tugriks1.00",
4760 "Moroccan Dirham1.00",
4761 "Moroccan Franc1.00",
4762 "Moroccan dirham1.00",
4763 "Moroccan dirhams1.00",
4764 "Moroccan franc1.00",
4765 "Moroccan francs1.00",
4766 "Mozambican Escudo1.00",
4767 "Mozambican Metical1.00",
4768 "Mozambican escudo1.00",
4769 "Mozambican escudos1.00",
4770 "Mozambican metical1.00",
4771 "Mozambican meticals1.00",
4774 "Myanmar kyats1.00",
4787 "Namibian Dollar1.00",
4788 "Namibian dollar1.00",
4789 "Namibian dollars1.00",
4790 "Nepalese Rupee1.00",
4791 "Nepalese rupee1.00",
4792 "Nepalese rupees1.00",
4793 "Netherlands Antillean Guilder1.00",
4794 "Netherlands Antillean guilder1.00",
4795 "Netherlands Antillean guilders1.00",
4796 "Dutch Guilder1.00",
4797 "Dutch guilder1.00",
4798 "Dutch guilders1.00",
4799 "Israeli New Sheqel1.00",
4800 "Israeli New Sheqels1.00",
4801 "New Zealand Dollar1.00",
4802 "New Zealand dollar1.00",
4803 "New Zealand dollars1.00",
4804 "Nicaraguan C\\u00f3rdoba1.00",
4805 "Nicaraguan C\\u00f3rdoba (1988\\u20131991)1.00",
4806 "Nicaraguan c\\u00f3rdoba1.00",
4807 "Nicaraguan c\\u00f3rdobas1.00",
4808 "Nicaraguan c\\u00f3rdoba (1988\\u20131991)1.00",
4809 "Nicaraguan c\\u00f3rdobas (1988\\u20131991)1.00",
4810 "Nigerian Naira1.00",
4811 "Nigerian naira1.00",
4812 "Nigerian nairas1.00",
4813 "North Korean Won1.00",
4814 "North Korean won1.00",
4815 "North Korean won1.00",
4816 "Norwegian Krone1.00",
4817 "Norwegian krone1.00",
4818 "Norwegian kroner1.00",
4820 "Mozambican Metical (1980\\u20132006)1.00",
4821 "Mozambican metical (1980\\u20132006)1.00",
4822 "Mozambican meticals (1980\\u20132006)1.00",
4823 "Romanian Lei (1952\\u20132006)1.00",
4824 "Romanian Leu (1952\\u20132006)1.00",
4825 "Romanian leu (1952\\u20132006)1.00",
4826 "Serbian Dinar (2002\\u20132006)1.00",
4827 "Serbian dinar (2002\\u20132006)1.00",
4828 "Serbian dinars (2002\\u20132006)1.00",
4829 "Sudanese Dinar (1992\\u20132007)1.00",
4830 "Sudanese Pound (1957\\u20131998)1.00",
4831 "Sudanese dinar (1992\\u20132007)1.00",
4832 "Sudanese dinars (1992\\u20132007)1.00",
4833 "Sudanese pound (1957\\u20131998)1.00",
4834 "Sudanese pounds (1957\\u20131998)1.00",
4835 "Turkish Lira (1922\\u20132005)1.00",
4836 "Turkish Lira (1922\\u20132005)1.00",
4858 "Pakistani Rupee1.00",
4859 "Pakistani rupee1.00",
4860 "Pakistani rupees1.00",
4863 "Panamanian Balboa1.00",
4864 "Panamanian balboa1.00",
4865 "Panamanian balboas1.00",
4866 "Papua New Guinean Kina1.00",
4867 "Papua New Guinean kina1.00",
4868 "Papua New Guinean kina1.00",
4869 "Paraguayan Guarani1.00",
4870 "Paraguayan guarani1.00",
4871 "Paraguayan guaranis1.00",
4872 "Peruvian Inti1.00",
4873 "Peruvian Nuevo Sol1.00",
4874 "Peruvian Sol (1863\\u20131965)1.00",
4875 "Peruvian inti1.00",
4876 "Peruvian intis1.00",
4877 "Peruvian nuevo sol1.00",
4878 "Peruvian nuevos soles1.00",
4879 "Peruvian sol (1863\\u20131965)1.00",
4880 "Peruvian soles (1863\\u20131965)1.00",
4881 "Philippine Peso1.00",
4882 "Philippine peso1.00",
4883 "Philippine pesos1.00",
4886 "Polish Zloty (1950\\u20131995)1.00",
4888 "Polish zlotys1.00",
4889 "Polish zloty (PLZ)1.00",
4891 "Polish zlotys (PLZ)1.00",
4892 "Portuguese Escudo1.00",
4893 "Portuguese Guinea Escudo1.00",
4894 "Portuguese Guinea escudo1.00",
4895 "Portuguese Guinea escudos1.00",
4896 "Portuguese escudo1.00",
4897 "Portuguese escudos1.00",
4919 "Rhodesian Dollar1.00",
4920 "Rhodesian dollar1.00",
4921 "Rhodesian dollars1.00",
4925 "Russian Ruble (1991\\u20131998)1.00",
4926 "Russian Ruble1.00",
4927 "Russian ruble (1991\\u20131998)1.00",
4928 "Russian ruble1.00",
4929 "Russian rubles (1991\\u20131998)1.00",
4930 "Russian rubles1.00",
4931 "Rwandan Franc1.00",
4932 "Rwandan franc1.00",
4933 "Rwandan francs1.00",
4963 "St. Helena Pound1.00",
4964 "St. Helena pound1.00",
4965 "St. Helena pounds1.00",
4966 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra1.00",
4967 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra1.00",
4968 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras1.00",
4972 "Serbian Dinar1.00",
4973 "Serbian dinar1.00",
4974 "Serbian dinars1.00",
4975 "Seychellois Rupee1.00",
4976 "Seychellois rupee1.00",
4977 "Seychellois rupees1.00",
4978 "Sierra Leonean Leone1.00",
4979 "Sierra Leonean leone1.00",
4980 "Sierra Leonean leones1.00",
4983 "Singapore Dollar1.00",
4984 "Singapore dollar1.00",
4985 "Singapore dollars1.00",
4986 "Slovak Koruna1.00",
4987 "Slovak koruna1.00",
4988 "Slovak korunas1.00",
4989 "Slovenian Tolar1.00",
4990 "Slovenian tolar1.00",
4991 "Slovenian tolars1.00",
4992 "Solomon Islands Dollar1.00",
4993 "Solomon Islands dollar1.00",
4994 "Solomon Islands dollars1.00",
4995 "Somali Shilling1.00",
4996 "Somali shilling1.00",
4997 "Somali shillings1.00",
4998 "South African Rand (financial)1.00",
4999 "South African Rand1.00",
5000 "South African rand (financial)1.00",
5001 "South African rand1.00",
5002 "South African rands (financial)1.00",
5003 "South African rand1.00",
5004 "South Korean Won1.00",
5005 "South Korean won1.00",
5006 "South Korean won1.00",
5007 "Soviet Rouble1.00",
5008 "Soviet rouble1.00",
5009 "Soviet roubles1.00",
5010 "Spanish Peseta (A account)1.00",
5011 "Spanish Peseta (convertible account)1.00",
5012 "Spanish Peseta1.00",
5013 "Spanish peseta (A account)1.00",
5014 "Spanish peseta (convertible account)1.00",
5015 "Spanish peseta1.00",
5016 "Spanish pesetas (A account)1.00",
5017 "Spanish pesetas (convertible account)1.00",
5018 "Spanish pesetas1.00",
5019 "Special Drawing Rights1.00",
5020 "Sri Lankan Rupee1.00",
5021 "Sri Lankan rupee1.00",
5022 "Sri Lankan rupees1.00",
5023 "Sudanese Pound1.00",
5024 "Sudanese pound1.00",
5025 "Sudanese pounds1.00",
5026 "Surinamese Dollar1.00",
5027 "Surinamese dollar1.00",
5028 "Surinamese dollars1.00",
5029 "Surinamese Guilder1.00",
5030 "Surinamese guilder1.00",
5031 "Surinamese guilders1.00",
5032 "Swazi Lilangeni1.00",
5033 "Swazi lilangeni1.00",
5034 "Swazi emalangeni1.00",
5035 "Swedish Krona1.00",
5036 "Swedish krona1.00",
5037 "Swedish kronor1.00",
5043 "Syrian pounds1.00",
5062 "New Taiwan Dollar1.00",
5063 "New Taiwan dollar1.00",
5064 "New Taiwan dollars1.00",
5065 "Tajikistani Ruble1.00",
5066 "Tajikistani Somoni1.00",
5067 "Tajikistani ruble1.00",
5068 "Tajikistani rubles1.00",
5069 "Tajikistani somoni1.00",
5070 "Tajikistani somonis1.00",
5071 "Tanzanian Shilling1.00",
5072 "Tanzanian shilling1.00",
5073 "Tanzanian shillings1.00",
5074 "Testing Currency Code1.00",
5075 "Testing Currency Code1.00",
5079 "Timorese Escudo1.00",
5080 "Timorese escudo1.00",
5081 "Timorese escudos1.00",
5082 "Tongan Pa\\u02bbanga1.00",
5083 "Tongan pa\\u02bbanga1.00",
5084 "Tongan pa\\u02bbanga1.00",
5085 "Trinidad & Tobago Dollar1.00",
5086 "Trinidad & Tobago dollar1.00",
5087 "Trinidad & Tobago dollars1.00",
5088 "Tunisian Dinar1.00",
5089 "Tunisian dinar1.00",
5090 "Tunisian dinars1.00",
5094 "Turkmenistani Manat1.00",
5095 "Turkmenistani manat1.00",
5096 "Turkmenistani manat1.00",
5105 "US Dollar (Next day)1.00",
5106 "US Dollar (Same day)1.00",
5108 "US dollar (next day)1.00",
5109 "US dollar (same day)1.00",
5111 "US dollars (next day)1.00",
5112 "US dollars (same day)1.00",
5126 "Ugandan Shilling (1966\\u20131987)1.00",
5127 "Ugandan Shilling1.00",
5128 "Ugandan shilling (1966\\u20131987)1.00",
5129 "Ugandan shilling1.00",
5130 "Ugandan shillings (1966\\u20131987)1.00",
5131 "Ugandan shillings1.00",
5132 "Ukrainian Hryvnia1.00",
5133 "Ukrainian Karbovanets1.00",
5134 "Ukrainian hryvnia1.00",
5135 "Ukrainian hryvnias1.00",
5136 "Ukrainian karbovanets1.00",
5137 "Ukrainian karbovantsiv1.00",
5138 "Colombian Real Value Unit1.00",
5139 "United Arab Emirates Dirham1.00",
5140 "Unknown Currency1.00",
5141 "Uruguayan Peso (1975\\u20131993)1.00",
5142 "Uruguayan Peso1.00",
5143 "Uruguayan Peso (Indexed Units)1.00",
5144 "Uruguayan peso (1975\\u20131993)1.00",
5145 "Uruguayan peso (indexed units)1.00",
5146 "Uruguayan peso1.00",
5147 "Uruguayan pesos (1975\\u20131993)1.00",
5148 "Uruguayan pesos (indexed units)1.00",
5149 "Uruguayan pesos1.00",
5150 "Uzbekistani Som1.00",
5151 "Uzbekistani som1.00",
5152 "Uzbekistani som1.00",
5159 "Vanuatu vatus1.00",
5160 "Venezuelan Bol\\u00edvar1.00",
5161 "Venezuelan Bol\\u00edvar (1871\\u20132008)1.00",
5162 "Venezuelan bol\\u00edvar1.00",
5163 "Venezuelan bol\\u00edvars1.00",
5164 "Venezuelan bol\\u00edvar (1871\\u20132008)1.00",
5165 "Venezuelan bol\\u00edvars (1871\\u20132008)1.00",
5166 "Vietnamese Dong1.00",
5167 "Vietnamese dong1.00",
5168 "Vietnamese dong1.00",
5228 "Yemeni dinars1.00",
5231 "Yugoslavian Convertible Dinar (1990\\u20131992)1.00",
5232 "Yugoslavian Hard Dinar (1966\\u20131990)1.00",
5233 "Yugoslavian New Dinar (1994\\u20132002)1.00",
5234 "Yugoslavian convertible dinar (1990\\u20131992)1.00",
5235 "Yugoslavian convertible dinars (1990\\u20131992)1.00",
5236 "Yugoslavian hard dinar (1966\\u20131990)1.00",
5237 "Yugoslavian hard dinars (1966\\u20131990)1.00",
5238 "Yugoslavian new dinar (1994\\u20132002)1.00",
5239 "Yugoslavian new dinars (1994\\u20132002)1.00",
5250 "Zairean New Zaire (1993\\u20131998)1.00",
5251 "Zairean Zaire (1971\\u20131993)1.00",
5252 "Zairean new zaire (1993\\u20131998)1.00",
5253 "Zairean new zaires (1993\\u20131998)1.00",
5254 "Zairean zaire (1971\\u20131993)1.00",
5255 "Zairean zaires (1971\\u20131993)1.00",
5256 "Zambian Kwacha1.00",
5257 "Zambian kwacha1.00",
5258 "Zambian kwachas1.00",
5259 "Zimbabwean Dollar (1980\\u20132008)1.00",
5260 "Zimbabwean dollar (1980\\u20132008)1.00",
5261 "Zimbabwean dollars (1980\\u20132008)1.00",
5264 "Turkish lira (1922\\u20132005)1.00",
5265 "special drawing rights1.00",
5266 "Colombian real value unit1.00",
5267 "Colombian real value units1.00",
5268 "unknown currency1.00",
5276 // Following has extra text, should be parsed correctly too
5279 "1.00 US dollar random",
5280 "1.00 US dollars random",
5281 "1.00 Afghan Afghani random",
5282 "1.00 Afghan Afghani random",
5283 "1.00 Afghan Afghanis (1927\\u20131992) random",
5284 "1.00 Afghan Afghanis random",
5285 "1.00 Albanian Lek random",
5286 "1.00 Albanian lek random",
5287 "1.00 Albanian lek\\u00eb random",
5288 "1.00 Algerian Dinar random",
5289 "1.00 Algerian dinar random",
5290 "1.00 Algerian dinars random",
5291 "1.00 Andorran Peseta random",
5292 "1.00 Andorran peseta random",
5293 "1.00 Andorran pesetas random",
5294 "1.00 Angolan Kwanza (1977\\u20131990) random",
5295 "1.00 Angolan Readjusted Kwanza (1995\\u20131999) random",
5296 "1.00 Angolan Kwanza random",
5297 "1.00 Angolan New Kwanza (1990\\u20132000) random",
5298 "1.00 Angolan kwanza (1977\\u20131991) random",
5299 "1.00 Angolan readjusted kwanza (1995\\u20131999) random",
5300 "1.00 Angolan kwanza random",
5301 "1.00 Angolan kwanzas (1977\\u20131991) random",
5302 "1.00 Angolan readjusted kwanzas (1995\\u20131999) random",
5303 "1.00 Angolan kwanzas random",
5304 "1.00 Angolan new kwanza (1990\\u20132000) random",
5305 "1.00 Angolan new kwanzas (1990\\u20132000) random",
5306 "1.00 Argentine Austral random",
5307 "1.00 Argentine Peso (1983\\u20131985) random",
5308 "1.00 Argentine Peso random",
5309 "1.00 Argentine austral random",
5310 "1.00 Argentine australs random",
5311 "1.00 Argentine peso (1983\\u20131985) random",
5312 "1.00 Argentine peso random",
5313 "1.00 Argentine pesos (1983\\u20131985) random",
5314 "1.00 Argentine pesos random",
5315 "1.00 Armenian Dram random",
5316 "1.00 Armenian dram random",
5317 "1.00 Armenian drams random",
5318 "1.00 Aruban Florin random",
5319 "1.00 Aruban florin random",
5320 "1.00 Australian Dollar random",
5321 "1.00 Australian dollar random",
5322 "1.00 Australian dollars random",
5323 "1.00 Austrian Schilling random",
5324 "1.00 Austrian schilling random",
5325 "1.00 Austrian schillings random",
5326 "1.00 Azerbaijani Manat (1993\\u20132006) random",
5327 "1.00 Azerbaijani Manat random",
5328 "1.00 Azerbaijani manat (1993\\u20132006) random",
5329 "1.00 Azerbaijani manat random",
5330 "1.00 Azerbaijani manats (1993\\u20132006) random",
5331 "1.00 Azerbaijani manats random",
5332 "1.00 Bahamian Dollar random",
5333 "1.00 Bahamian dollar random",
5334 "1.00 Bahamian dollars random",
5335 "1.00 Bahraini Dinar random",
5336 "1.00 Bahraini dinar random",
5337 "1.00 Bahraini dinars random",
5338 "1.00 Bangladeshi Taka random",
5339 "1.00 Bangladeshi taka random",
5340 "1.00 Bangladeshi takas random",
5341 "1.00 Barbadian Dollar random",
5342 "1.00 Barbadian dollar random",
5343 "1.00 Barbadian dollars random",
5344 "1.00 Belarusian New Ruble (1994\\u20131999) random",
5345 "1.00 Belarusian Ruble random",
5346 "1.00 Belarusian new ruble (1994\\u20131999) random",
5347 "1.00 Belarusian new rubles (1994\\u20131999) random",
5348 "1.00 Belarusian ruble random",
5349 "1.00 Belarusian rubles random",
5350 "1.00 Belgian Franc (convertible) random",
5351 "1.00 Belgian Franc (financial) random",
5352 "1.00 Belgian Franc random",
5353 "1.00 Belgian franc (convertible) random",
5354 "1.00 Belgian franc (financial) random",
5355 "1.00 Belgian franc random",
5356 "1.00 Belgian francs (convertible) random",
5357 "1.00 Belgian francs (financial) random",
5358 "1.00 Belgian francs random",
5359 "1.00 Belize Dollar random",
5360 "1.00 Belize dollar random",
5361 "1.00 Belize dollars random",
5362 "1.00 Bermudan Dollar random",
5363 "1.00 Bermudan dollar random",
5364 "1.00 Bermudan dollars random",
5365 "1.00 Bhutanese Ngultrum random",
5366 "1.00 Bhutanese ngultrum random",
5367 "1.00 Bhutanese ngultrums random",
5368 "1.00 Bolivian Mvdol random",
5369 "1.00 Bolivian Peso random",
5370 "1.00 Bolivian mvdol random",
5371 "1.00 Bolivian mvdols random",
5372 "1.00 Bolivian peso random",
5373 "1.00 Bolivian pesos random",
5374 "1.00 Bolivian Boliviano random",
5375 "1.00 Bolivian Boliviano random",
5376 "1.00 Bolivian Bolivianos random",
5377 "1.00 Bosnia-Herzegovina Convertible Mark random",
5378 "1.00 Bosnia-Herzegovina Dinar (1992\\u20131994) random",
5379 "1.00 Bosnia-Herzegovina convertible mark random",
5380 "1.00 Bosnia-Herzegovina convertible marks random",
5381 "1.00 Bosnia-Herzegovina dinar (1992\\u20131994) random",
5382 "1.00 Bosnia-Herzegovina dinars (1992\\u20131994) random",
5383 "1.00 Botswanan Pula random",
5384 "1.00 Botswanan pula random",
5385 "1.00 Botswanan pulas random",
5386 "1.00 Brazilian New Cruzado (1989\\u20131990) random",
5387 "1.00 Brazilian Cruzado (1986\\u20131989) random",
5388 "1.00 Brazilian Cruzeiro (1990\\u20131993) random",
5389 "1.00 Brazilian New Cruzeiro (1967\\u20131986) random",
5390 "1.00 Brazilian Cruzeiro (1993\\u20131994) random",
5391 "1.00 Brazilian Real random",
5392 "1.00 Brazilian new cruzado (1989\\u20131990) random",
5393 "1.00 Brazilian new cruzados (1989\\u20131990) random",
5394 "1.00 Brazilian cruzado (1986\\u20131989) random",
5395 "1.00 Brazilian cruzados (1986\\u20131989) random",
5396 "1.00 Brazilian cruzeiro (1990\\u20131993) random",
5397 "1.00 Brazilian new cruzeiro (1967\\u20131986) random",
5398 "1.00 Brazilian cruzeiro (1993\\u20131994) random",
5399 "1.00 Brazilian cruzeiros (1990\\u20131993) random",
5400 "1.00 Brazilian new cruzeiros (1967\\u20131986) random",
5401 "1.00 Brazilian cruzeiros (1993\\u20131994) random",
5402 "1.00 Brazilian real random",
5403 "1.00 Brazilian reals random",
5404 "1.00 British Pound random",
5405 "1.00 British pound random",
5406 "1.00 British pounds random",
5407 "1.00 Brunei Dollar random",
5408 "1.00 Brunei dollar random",
5409 "1.00 Brunei dollars random",
5410 "1.00 Bulgarian Hard Lev random",
5411 "1.00 Bulgarian Lev random",
5412 "1.00 Bulgarian Leva random",
5413 "1.00 Bulgarian hard lev random",
5414 "1.00 Bulgarian hard leva random",
5415 "1.00 Bulgarian lev random",
5416 "1.00 Burmese Kyat random",
5417 "1.00 Burmese kyat random",
5418 "1.00 Burmese kyats random",
5419 "1.00 Burundian Franc random",
5420 "1.00 Burundian franc random",
5421 "1.00 Burundian francs random",
5422 "1.00 Cambodian Riel random",
5423 "1.00 Cambodian riel random",
5424 "1.00 Cambodian riels random",
5425 "1.00 Canadian Dollar random",
5426 "1.00 Canadian dollar random",
5427 "1.00 Canadian dollars random",
5428 "1.00 Cape Verdean Escudo random",
5429 "1.00 Cape Verdean escudo random",
5430 "1.00 Cape Verdean escudos random",
5431 "1.00 Cayman Islands Dollar random",
5432 "1.00 Cayman Islands dollar random",
5433 "1.00 Cayman Islands dollars random",
5434 "1.00 Chilean Peso random",
5435 "1.00 Chilean Unit of Account (UF) random",
5436 "1.00 Chilean peso random",
5437 "1.00 Chilean pesos random",
5438 "1.00 Chilean unit of account (UF) random",
5439 "1.00 Chilean units of account (UF) random",
5440 "1.00 Chinese Yuan random",
5441 "1.00 Chinese yuan random",
5442 "1.00 Colombian Peso random",
5443 "1.00 Colombian peso random",
5444 "1.00 Colombian pesos random",
5445 "1.00 Comorian Franc random",
5446 "1.00 Comorian franc random",
5447 "1.00 Comorian francs random",
5448 "1.00 Congolese Franc Congolais random",
5449 "1.00 Congolese franc Congolais random",
5450 "1.00 Congolese francs Congolais random",
5451 "1.00 Costa Rican Col\\u00f3n random",
5452 "1.00 Costa Rican col\\u00f3n random",
5453 "1.00 Costa Rican col\\u00f3ns random",
5454 "1.00 Croatian Dinar random",
5455 "1.00 Croatian Kuna random",
5456 "1.00 Croatian dinar random",
5457 "1.00 Croatian dinars random",
5458 "1.00 Croatian kuna random",
5459 "1.00 Croatian kunas random",
5460 "1.00 Cuban Peso random",
5461 "1.00 Cuban peso random",
5462 "1.00 Cuban pesos random",
5463 "1.00 Cypriot Pound random",
5464 "1.00 Cypriot pound random",
5465 "1.00 Cypriot pounds random",
5466 "1.00 Czech Republic Koruna random",
5467 "1.00 Czech Republic koruna random",
5468 "1.00 Czech Republic korunas random",
5469 "1.00 Czechoslovak Hard Koruna random",
5470 "1.00 Czechoslovak hard koruna random",
5471 "1.00 Czechoslovak hard korunas random",
5472 "1.00 Danish Krone random",
5473 "1.00 Danish krone random",
5474 "1.00 Danish kroner random",
5475 "1.00 German Mark random",
5476 "1.00 German mark random",
5477 "1.00 German marks random",
5478 "1.00 Djiboutian Franc random",
5479 "1.00 Djiboutian franc random",
5480 "1.00 Djiboutian francs random",
5481 "1.00 Dominican Peso random",
5482 "1.00 Dominican peso random",
5483 "1.00 Dominican pesos random",
5484 "1.00 East Caribbean Dollar random",
5485 "1.00 East Caribbean dollar random",
5486 "1.00 East Caribbean dollars random",
5487 "1.00 East German Mark random",
5488 "1.00 East German mark random",
5489 "1.00 East German marks random",
5490 "1.00 Ecuadorian Sucre random",
5491 "1.00 Ecuadorian Unit of Constant Value random",
5492 "1.00 Ecuadorian sucre random",
5493 "1.00 Ecuadorian sucres random",
5494 "1.00 Ecuadorian unit of constant value random",
5495 "1.00 Ecuadorian units of constant value random",
5496 "1.00 Egyptian Pound random",
5497 "1.00 Egyptian pound random",
5498 "1.00 Egyptian pounds random",
5499 "1.00 Salvadoran Col\\u00f3n random",
5500 "1.00 Salvadoran col\\u00f3n random",
5501 "1.00 Salvadoran colones random",
5502 "1.00 Equatorial Guinean Ekwele random",
5503 "1.00 Equatorial Guinean ekwele random",
5504 "1.00 Eritrean Nakfa random",
5505 "1.00 Eritrean nakfa random",
5506 "1.00 Eritrean nakfas random",
5507 "1.00 Estonian Kroon random",
5508 "1.00 Estonian kroon random",
5509 "1.00 Estonian kroons random",
5510 "1.00 Ethiopian Birr random",
5511 "1.00 Ethiopian birr random",
5512 "1.00 Ethiopian birrs random",
5513 "1.00 European Composite Unit random",
5514 "1.00 European Currency Unit random",
5515 "1.00 European Monetary Unit random",
5516 "1.00 European Unit of Account (XBC) random",
5517 "1.00 European Unit of Account (XBD) random",
5518 "1.00 European composite unit random",
5519 "1.00 European composite units random",
5520 "1.00 European currency unit random",
5521 "1.00 European currency units random",
5522 "1.00 European monetary unit random",
5523 "1.00 European monetary units random",
5524 "1.00 European unit of account (XBC) random",
5525 "1.00 European unit of account (XBD) random",
5526 "1.00 European units of account (XBC) random",
5527 "1.00 European units of account (XBD) random",
5528 "1.00 Falkland Islands Pound random",
5529 "1.00 Falkland Islands pound random",
5530 "1.00 Falkland Islands pounds random",
5531 "1.00 Fijian Dollar random",
5532 "1.00 Fijian dollar random",
5533 "1.00 Fijian dollars random",
5534 "1.00 Finnish Markka random",
5535 "1.00 Finnish markka random",
5536 "1.00 Finnish markkas random",
5537 "1.00 French Franc random",
5538 "1.00 French Gold Franc random",
5539 "1.00 French UIC-Franc random",
5540 "1.00 French UIC-franc random",
5541 "1.00 French UIC-francs random",
5542 "1.00 French franc random",
5543 "1.00 French francs random",
5544 "1.00 French gold franc random",
5545 "1.00 French gold francs random",
5546 "1.00 Gambian Dalasi random",
5547 "1.00 Gambian dalasi random",
5548 "1.00 Gambian dalasis random",
5549 "1.00 Georgian Kupon Larit random",
5550 "1.00 Georgian Lari random",
5551 "1.00 Georgian kupon larit random",
5552 "1.00 Georgian kupon larits random",
5553 "1.00 Georgian lari random",
5554 "1.00 Georgian laris random",
5555 "1.00 Ghanaian Cedi (1979\\u20132007) random",
5556 "1.00 Ghanaian Cedi random",
5557 "1.00 Ghanaian cedi (1979\\u20132007) random",
5558 "1.00 Ghanaian cedi random",
5559 "1.00 Ghanaian cedis (1979\\u20132007) random",
5560 "1.00 Ghanaian cedis random",
5561 "1.00 Gibraltar Pound random",
5562 "1.00 Gibraltar pound random",
5563 "1.00 Gibraltar pounds random",
5566 "1.00 Greek Drachma random",
5567 "1.00 Greek drachma random",
5568 "1.00 Greek drachmas random",
5569 "1.00 Guatemalan Quetzal random",
5570 "1.00 Guatemalan quetzal random",
5571 "1.00 Guatemalan quetzals random",
5572 "1.00 Guinean Franc random",
5573 "1.00 Guinean Syli random",
5574 "1.00 Guinean franc random",
5575 "1.00 Guinean francs random",
5576 "1.00 Guinean syli random",
5577 "1.00 Guinean sylis random",
5578 "1.00 Guinea-Bissau Peso random",
5579 "1.00 Guinea-Bissau peso random",
5580 "1.00 Guinea-Bissau pesos random",
5581 "1.00 Guyanaese Dollar random",
5582 "1.00 Guyanaese dollar random",
5583 "1.00 Guyanaese dollars random",
5584 "1.00 Haitian Gourde random",
5585 "1.00 Haitian gourde random",
5586 "1.00 Haitian gourdes random",
5587 "1.00 Honduran Lempira random",
5588 "1.00 Honduran lempira random",
5589 "1.00 Honduran lempiras random",
5590 "1.00 Hong Kong Dollar random",
5591 "1.00 Hong Kong dollar random",
5592 "1.00 Hong Kong dollars random",
5593 "1.00 Hungarian Forint random",
5594 "1.00 Hungarian forint random",
5595 "1.00 Hungarian forints random",
5596 "1.00 Icelandic Kr\\u00f3na random",
5597 "1.00 Icelandic kr\\u00f3na random",
5598 "1.00 Icelandic kr\\u00f3nur random",
5599 "1.00 Indian Rupee random",
5600 "1.00 Indian rupee random",
5601 "1.00 Indian rupees random",
5602 "1.00 Indonesian Rupiah random",
5603 "1.00 Indonesian rupiah random",
5604 "1.00 Indonesian rupiahs random",
5605 "1.00 Iranian Rial random",
5606 "1.00 Iranian rial random",
5607 "1.00 Iranian rials random",
5608 "1.00 Iraqi Dinar random",
5609 "1.00 Iraqi dinar random",
5610 "1.00 Iraqi dinars random",
5611 "1.00 Irish Pound random",
5612 "1.00 Irish pound random",
5613 "1.00 Irish pounds random",
5614 "1.00 Israeli Pound random",
5615 "1.00 Israeli new sheqel random",
5616 "1.00 Israeli pound random",
5617 "1.00 Israeli pounds random",
5618 "1.00 Italian Lira random",
5619 "1.00 Italian lira random",
5620 "1.00 Italian liras random",
5621 "1.00 Jamaican Dollar random",
5622 "1.00 Jamaican dollar random",
5623 "1.00 Jamaican dollars random",
5624 "1.00 Japanese Yen random",
5625 "1.00 Japanese yen random",
5626 "1.00 Jordanian Dinar random",
5627 "1.00 Jordanian dinar random",
5628 "1.00 Jordanian dinars random",
5629 "1.00 Kazakhstani Tenge random",
5630 "1.00 Kazakhstani tenge random",
5631 "1.00 Kazakhstani tenges random",
5632 "1.00 Kenyan Shilling random",
5633 "1.00 Kenyan shilling random",
5634 "1.00 Kenyan shillings random",
5635 "1.00 Kuwaiti Dinar random",
5636 "1.00 Kuwaiti dinar random",
5637 "1.00 Kuwaiti dinars random",
5638 "1.00 Kyrgystani Som random",
5639 "1.00 Kyrgystani som random",
5640 "1.00 Kyrgystani soms random",
5641 "1.00 Laotian Kip random",
5642 "1.00 Laotian kip random",
5643 "1.00 Laotian kips random",
5644 "1.00 Latvian Lats random",
5645 "1.00 Latvian Ruble random",
5646 "1.00 Latvian lats random",
5647 "1.00 Latvian lati random",
5648 "1.00 Latvian ruble random",
5649 "1.00 Latvian rubles random",
5650 "1.00 Lebanese Pound random",
5651 "1.00 Lebanese pound random",
5652 "1.00 Lebanese pounds random",
5653 "1.00 Lesotho Loti random",
5654 "1.00 Lesotho loti random",
5655 "1.00 Lesotho lotis random",
5656 "1.00 Liberian Dollar random",
5657 "1.00 Liberian dollar random",
5658 "1.00 Liberian dollars random",
5659 "1.00 Libyan Dinar random",
5660 "1.00 Libyan dinar random",
5661 "1.00 Libyan dinars random",
5662 "1.00 Lithuanian Litas random",
5663 "1.00 Lithuanian Talonas random",
5664 "1.00 Lithuanian litas random",
5665 "1.00 Lithuanian litai random",
5666 "1.00 Lithuanian talonas random",
5667 "1.00 Lithuanian talonases random",
5668 "1.00 Luxembourgian Convertible Franc random",
5669 "1.00 Luxembourg Financial Franc random",
5670 "1.00 Luxembourgian Franc random",
5671 "1.00 Luxembourgian convertible franc random",
5672 "1.00 Luxembourgian convertible francs random",
5673 "1.00 Luxembourg financial franc random",
5674 "1.00 Luxembourg financial francs random",
5675 "1.00 Luxembourgian franc random",
5676 "1.00 Luxembourgian francs random",
5677 "1.00 Macanese Pataca random",
5678 "1.00 Macanese pataca random",
5679 "1.00 Macanese patacas random",
5680 "1.00 Macedonian Denar random",
5681 "1.00 Macedonian denar random",
5682 "1.00 Macedonian denari random",
5683 "1.00 Malagasy Ariaries random",
5684 "1.00 Malagasy Ariary random",
5685 "1.00 Malagasy Ariary random",
5686 "1.00 Malagasy Franc random",
5687 "1.00 Malagasy franc random",
5688 "1.00 Malagasy francs random",
5689 "1.00 Malawian Kwacha random",
5690 "1.00 Malawian Kwacha random",
5691 "1.00 Malawian Kwachas random",
5692 "1.00 Malaysian Ringgit random",
5693 "1.00 Malaysian ringgit random",
5694 "1.00 Malaysian ringgits random",
5695 "1.00 Maldivian Rufiyaa random",
5696 "1.00 Maldivian rufiyaa random",
5697 "1.00 Maldivian rufiyaas random",
5698 "1.00 Malian Franc random",
5699 "1.00 Malian franc random",
5700 "1.00 Malian francs random",
5701 "1.00 Maltese Lira random",
5702 "1.00 Maltese Pound random",
5703 "1.00 Maltese lira random",
5704 "1.00 Maltese liras random",
5705 "1.00 Maltese pound random",
5706 "1.00 Maltese pounds random",
5707 "1.00 Mauritanian Ouguiya random",
5708 "1.00 Mauritanian ouguiya random",
5709 "1.00 Mauritanian ouguiyas random",
5710 "1.00 Mauritian Rupee random",
5711 "1.00 Mauritian rupee random",
5712 "1.00 Mauritian rupees random",
5713 "1.00 Mexican Peso random",
5714 "1.00 Mexican Silver Peso (1861\\u20131992) random",
5715 "1.00 Mexican Investment Unit random",
5716 "1.00 Mexican peso random",
5717 "1.00 Mexican pesos random",
5718 "1.00 Mexican silver peso (1861\\u20131992) random",
5719 "1.00 Mexican silver pesos (1861\\u20131992) random",
5720 "1.00 Mexican investment unit random",
5721 "1.00 Mexican investment units random",
5722 "1.00 Moldovan Leu random",
5723 "1.00 Moldovan leu random",
5724 "1.00 Moldovan lei random",
5725 "1.00 Mongolian Tugrik random",
5726 "1.00 Mongolian tugrik random",
5727 "1.00 Mongolian tugriks random",
5728 "1.00 Moroccan Dirham random",
5729 "1.00 Moroccan Franc random",
5730 "1.00 Moroccan dirham random",
5731 "1.00 Moroccan dirhams random",
5732 "1.00 Moroccan franc random",
5733 "1.00 Moroccan francs random",
5734 "1.00 Mozambican Escudo random",
5735 "1.00 Mozambican Metical random",
5736 "1.00 Mozambican escudo random",
5737 "1.00 Mozambican escudos random",
5738 "1.00 Mozambican metical random",
5739 "1.00 Mozambican meticals random",
5740 "1.00 Myanmar Kyat random",
5741 "1.00 Myanmar kyat random",
5742 "1.00 Myanmar kyats random",
5743 "1.00 Namibian Dollar random",
5744 "1.00 Namibian dollar random",
5745 "1.00 Namibian dollars random",
5746 "1.00 Nepalese Rupee random",
5747 "1.00 Nepalese rupee random",
5748 "1.00 Nepalese rupees random",
5749 "1.00 Netherlands Antillean Guilder random",
5750 "1.00 Netherlands Antillean guilder random",
5751 "1.00 Netherlands Antillean guilders random",
5752 "1.00 Dutch Guilder random",
5753 "1.00 Dutch guilder random",
5754 "1.00 Dutch guilders random",
5755 "1.00 Israeli New Sheqel random",
5756 "1.00 Israeli new sheqels random",
5757 "1.00 New Zealand Dollar random",
5758 "1.00 New Zealand dollar random",
5759 "1.00 New Zealand dollars random",
5760 "1.00 Nicaraguan C\\u00f3rdoba random",
5761 "1.00 Nicaraguan C\\u00f3rdoba (1988\\u20131991) random",
5762 "1.00 Nicaraguan c\\u00f3rdoba random",
5763 "1.00 Nicaraguan c\\u00f3rdoba random",
5764 "1.00 Nicaraguan c\\u00f3rdoba (1988\\u20131991) random",
5765 "1.00 Nicaraguan c\\u00f3rdobas (1988\\u20131991) random",
5766 "1.00 Nigerian Naira random",
5767 "1.00 Nigerian naira random",
5768 "1.00 Nigerian nairas random",
5769 "1.00 North Korean Won random",
5770 "1.00 North Korean won random",
5771 "1.00 North Korean won random",
5772 "1.00 Norwegian Krone random",
5773 "1.00 Norwegian krone random",
5774 "1.00 Norwegian kroner random",
5775 "1.00 Mozambican Metical (1980\\u20132006) random",
5776 "1.00 Mozambican metical (1980\\u20132006) random",
5777 "1.00 Mozambican meticals (1980\\u20132006) random",
5778 "1.00 Romanian Lei (1952\\u20132006) random",
5779 "1.00 Romanian Leu (1952\\u20132006) random",
5780 "1.00 Romanian leu (1952\\u20132006) random",
5781 "1.00 Serbian Dinar (2002\\u20132006) random",
5782 "1.00 Serbian dinar (2002\\u20132006) random",
5783 "1.00 Serbian dinars (2002\\u20132006) random",
5784 "1.00 Sudanese Dinar (1992\\u20132007) random",
5785 "1.00 Sudanese Pound (1957\\u20131998) random",
5786 "1.00 Sudanese dinar (1992\\u20132007) random",
5787 "1.00 Sudanese dinars (1992\\u20132007) random",
5788 "1.00 Sudanese pound (1957\\u20131998) random",
5789 "1.00 Sudanese pounds (1957\\u20131998) random",
5790 "1.00 Turkish Lira (1922\\u20132005) random",
5791 "1.00 Turkish Lira (1922\\u20132005) random",
5792 "1.00 Omani Rial random",
5793 "1.00 Omani rial random",
5794 "1.00 Omani rials random",
5795 "1.00 Pakistani Rupee random",
5796 "1.00 Pakistani rupee random",
5797 "1.00 Pakistani rupees random",
5798 "1.00 Palladium random",
5799 "1.00 Palladium random",
5800 "1.00 Panamanian Balboa random",
5801 "1.00 Panamanian balboa random",
5802 "1.00 Panamanian balboas random",
5803 "1.00 Papua New Guinean Kina random",
5804 "1.00 Papua New Guinean kina random",
5805 "1.00 Papua New Guinean kina random",
5806 "1.00 Paraguayan Guarani random",
5807 "1.00 Paraguayan guarani random",
5808 "1.00 Paraguayan guaranis random",
5809 "1.00 Peruvian Inti random",
5810 "1.00 Peruvian Nuevo Sol random",
5811 "1.00 Peruvian Sol (1863\\u20131965) random",
5812 "1.00 Peruvian inti random",
5813 "1.00 Peruvian intis random",
5814 "1.00 Peruvian nuevo sol random",
5815 "1.00 Peruvian nuevos soles random",
5816 "1.00 Peruvian sol (1863\\u20131965) random",
5817 "1.00 Peruvian soles (1863\\u20131965) random",
5818 "1.00 Philippine Peso random",
5819 "1.00 Philippine peso random",
5820 "1.00 Philippine pesos random",
5821 "1.00 Platinum random",
5822 "1.00 Platinum random",
5823 "1.00 Polish Zloty (1950\\u20131995) random",
5824 "1.00 Polish Zloty random",
5825 "1.00 Polish zlotys random",
5826 "1.00 Polish zloty (PLZ) random",
5827 "1.00 Polish zloty random",
5828 "1.00 Polish zlotys (PLZ) random",
5829 "1.00 Portuguese Escudo random",
5830 "1.00 Portuguese Guinea Escudo random",
5831 "1.00 Portuguese Guinea escudo random",
5832 "1.00 Portuguese Guinea escudos random",
5833 "1.00 Portuguese escudo random",
5834 "1.00 Portuguese escudos random",
5835 "1.00 Qatari Rial random",
5836 "1.00 Qatari rial random",
5837 "1.00 Qatari rials random",
5838 "1.00 RINET Funds random",
5839 "1.00 RINET Funds random",
5840 "1.00 Rhodesian Dollar random",
5841 "1.00 Rhodesian dollar random",
5842 "1.00 Rhodesian dollars random",
5843 "1.00 Romanian Leu random",
5844 "1.00 Romanian lei random",
5845 "1.00 Romanian leu random",
5846 "1.00 Russian Ruble (1991\\u20131998) random",
5847 "1.00 Russian Ruble random",
5848 "1.00 Russian ruble (1991\\u20131998) random",
5849 "1.00 Russian ruble random",
5850 "1.00 Russian rubles (1991\\u20131998) random",
5851 "1.00 Russian rubles random",
5852 "1.00 Rwandan Franc random",
5853 "1.00 Rwandan franc random",
5854 "1.00 Rwandan francs random",
5855 "1.00 St. Helena Pound random",
5856 "1.00 St. Helena pound random",
5857 "1.00 St. Helena pounds random",
5858 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra random",
5859 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra random",
5860 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras random",
5861 "1.00 Saudi Riyal random",
5862 "1.00 Saudi riyal random",
5863 "1.00 Saudi riyals random",
5864 "1.00 Serbian Dinar random",
5865 "1.00 Serbian dinar random",
5866 "1.00 Serbian dinars random",
5867 "1.00 Seychellois Rupee random",
5868 "1.00 Seychellois rupee random",
5869 "1.00 Seychellois rupees random",
5870 "1.00 Sierra Leonean Leone random",
5871 "1.00 Sierra Leonean leone random",
5872 "1.00 Sierra Leonean leones random",
5873 "1.00 Singapore Dollar random",
5874 "1.00 Singapore dollar random",
5875 "1.00 Singapore dollars random",
5876 "1.00 Slovak Koruna random",
5877 "1.00 Slovak koruna random",
5878 "1.00 Slovak korunas random",
5879 "1.00 Slovenian Tolar random",
5880 "1.00 Slovenian tolar random",
5881 "1.00 Slovenian tolars random",
5882 "1.00 Solomon Islands Dollar random",
5883 "1.00 Solomon Islands dollar random",
5884 "1.00 Solomon Islands dollars random",
5885 "1.00 Somali Shilling random",
5886 "1.00 Somali shilling random",
5887 "1.00 Somali shillings random",
5888 "1.00 South African Rand (financial) random",
5889 "1.00 South African Rand random",
5890 "1.00 South African rand (financial) random",
5891 "1.00 South African rand random",
5892 "1.00 South African rands (financial) random",
5893 "1.00 South African rand random",
5894 "1.00 South Korean Won random",
5895 "1.00 South Korean won random",
5896 "1.00 South Korean won random",
5897 "1.00 Soviet Rouble random",
5898 "1.00 Soviet rouble random",
5899 "1.00 Soviet roubles random",
5900 "1.00 Spanish Peseta (A account) random",
5901 "1.00 Spanish Peseta (convertible account) random",
5902 "1.00 Spanish Peseta random",
5903 "1.00 Spanish peseta (A account) random",
5904 "1.00 Spanish peseta (convertible account) random",
5905 "1.00 Spanish peseta random",
5906 "1.00 Spanish pesetas (A account) random",
5907 "1.00 Spanish pesetas (convertible account) random",
5908 "1.00 Spanish pesetas random",
5909 "1.00 Special Drawing Rights random",
5910 "1.00 Sri Lankan Rupee random",
5911 "1.00 Sri Lankan rupee random",
5912 "1.00 Sri Lankan rupees random",
5913 "1.00 Sudanese Pound random",
5914 "1.00 Sudanese pound random",
5915 "1.00 Sudanese pounds random",
5916 "1.00 Surinamese Dollar random",
5917 "1.00 Surinamese dollar random",
5918 "1.00 Surinamese dollars random",
5919 "1.00 Surinamese Guilder random",
5920 "1.00 Surinamese guilder random",
5921 "1.00 Surinamese guilders random",
5922 "1.00 Swazi Lilangeni random",
5923 "1.00 Swazi lilangeni random",
5924 "1.00 Swazi emalangeni random",
5925 "1.00 Swedish Krona random",
5926 "1.00 Swedish krona random",
5927 "1.00 Swedish kronor random",
5928 "1.00 Swiss Franc random",
5929 "1.00 Swiss franc random",
5930 "1.00 Swiss francs random",
5931 "1.00 Syrian Pound random",
5932 "1.00 Syrian pound random",
5933 "1.00 Syrian pounds random",
5934 "1.00 New Taiwan Dollar random",
5935 "1.00 New Taiwan dollar random",
5936 "1.00 New Taiwan dollars random",
5937 "1.00 Tajikistani Ruble random",
5938 "1.00 Tajikistani Somoni random",
5939 "1.00 Tajikistani ruble random",
5940 "1.00 Tajikistani rubles random",
5941 "1.00 Tajikistani somoni random",
5942 "1.00 Tajikistani somonis random",
5943 "1.00 Tanzanian Shilling random",
5944 "1.00 Tanzanian shilling random",
5945 "1.00 Tanzanian shillings random",
5946 "1.00 Testing Currency Code random",
5947 "1.00 Testing Currency Code random",
5948 "1.00 Thai Baht random",
5949 "1.00 Thai baht random",
5950 "1.00 Thai baht random",
5951 "1.00 Timorese Escudo random",
5952 "1.00 Timorese escudo random",
5953 "1.00 Timorese escudos random",
5954 "1.00 Trinidad & Tobago Dollar random",
5955 "1.00 Trinidad & Tobago dollar random",
5956 "1.00 Trinidad & Tobago dollars random",
5957 "1.00 Tunisian Dinar random",
5958 "1.00 Tunisian dinar random",
5959 "1.00 Tunisian dinars random",
5960 "1.00 Turkish Lira random",
5961 "1.00 Turkish Lira random",
5962 "1.00 Turkish lira random",
5963 "1.00 Turkmenistani Manat random",
5964 "1.00 Turkmenistani manat random",
5965 "1.00 Turkmenistani manat random",
5966 "1.00 US Dollar (Next day) random",
5967 "1.00 US Dollar (Same day) random",
5968 "1.00 US Dollar random",
5969 "1.00 US dollar (next day) random",
5970 "1.00 US dollar (same day) random",
5971 "1.00 US dollar random",
5972 "1.00 US dollars (next day) random",
5973 "1.00 US dollars (same day) random",
5974 "1.00 US dollars random",
5975 "1.00 Ugandan Shilling (1966\\u20131987) random",
5976 "1.00 Ugandan Shilling random",
5977 "1.00 Ugandan shilling (1966\\u20131987) random",
5978 "1.00 Ugandan shilling random",
5979 "1.00 Ugandan shillings (1966\\u20131987) random",
5980 "1.00 Ugandan shillings random",
5981 "1.00 Ukrainian Hryvnia random",
5982 "1.00 Ukrainian Karbovanets random",
5983 "1.00 Ukrainian hryvnia random",
5984 "1.00 Ukrainian hryvnias random",
5985 "1.00 Ukrainian karbovanets random",
5986 "1.00 Ukrainian karbovantsiv random",
5987 "1.00 Colombian Real Value Unit random",
5988 "1.00 United Arab Emirates Dirham random",
5989 "1.00 Unknown Currency random",
5990 "1.00 Uruguayan Peso (1975\\u20131993) random",
5991 "1.00 Uruguayan Peso random",
5992 "1.00 Uruguayan Peso (Indexed Units) random",
5993 "1.00 Uruguayan peso (1975\\u20131993) random",
5994 "1.00 Uruguayan peso (indexed units) random",
5995 "1.00 Uruguayan peso random",
5996 "1.00 Uruguayan pesos (1975\\u20131993) random",
5997 "1.00 Uruguayan pesos (indexed units) random",
5998 "1.00 Uzbekistani Som random",
5999 "1.00 Uzbekistani som random",
6000 "1.00 Uzbekistani som random",
6001 "1.00 Vanuatu Vatu random",
6002 "1.00 Vanuatu vatu random",
6003 "1.00 Vanuatu vatus random",
6004 "1.00 Venezuelan Bol\\u00edvar random",
6005 "1.00 Venezuelan Bol\\u00edvar (1871\\u20132008) random",
6006 "1.00 Venezuelan bol\\u00edvar random",
6007 "1.00 Venezuelan bol\\u00edvars random",
6008 "1.00 Venezuelan bol\\u00edvar (1871\\u20132008) random",
6009 "1.00 Venezuelan bol\\u00edvars (1871\\u20132008) random",
6010 "1.00 Vietnamese Dong random",
6011 "1.00 Vietnamese dong random",
6012 "1.00 Vietnamese dong random",
6013 "1.00 WIR Euro random",
6014 "1.00 WIR Franc random",
6015 "1.00 WIR euro random",
6016 "1.00 WIR euros random",
6017 "1.00 WIR franc random",
6018 "1.00 WIR francs random",
6019 "1.00 Samoan Tala random",
6020 "1.00 Samoan tala random",
6021 "1.00 Samoan tala random",
6022 "1.00 Yemeni Dinar random",
6023 "1.00 Yemeni Rial random",
6024 "1.00 Yemeni dinar random",
6025 "1.00 Yemeni dinars random",
6026 "1.00 Yemeni rial random",
6027 "1.00 Yemeni rials random",
6028 "1.00 Yugoslavian Convertible Dinar (1990\\u20131992) random",
6029 "1.00 Yugoslavian Hard Dinar (1966\\u20131990) random",
6030 "1.00 Yugoslavian New Dinar (1994\\u20132002) random",
6031 "1.00 Yugoslavian convertible dinar (1990\\u20131992) random",
6032 "1.00 Yugoslavian convertible dinars (1990\\u20131992) random",
6033 "1.00 Yugoslavian hard dinar (1966\\u20131990) random",
6034 "1.00 Yugoslavian hard dinars (1966\\u20131990) random",
6035 "1.00 Yugoslavian new dinar (1994\\u20132002) random",
6036 "1.00 Yugoslavian new dinars (1994\\u20132002) random",
6037 "1.00 Zairean New Zaire (1993\\u20131998) random",
6038 "1.00 Zairean Zaire (1971\\u20131993) random",
6039 "1.00 Zairean new zaire (1993\\u20131998) random",
6040 "1.00 Zairean new zaires (1993\\u20131998) random",
6041 "1.00 Zairean zaire (1971\\u20131993) random",
6042 "1.00 Zairean zaires (1971\\u20131993) random",
6043 "1.00 Zambian Kwacha random",
6044 "1.00 Zambian kwacha random",
6045 "1.00 Zambian kwachas random",
6046 "1.00 Zimbabwean Dollar (1980\\u20132008) random",
6047 "1.00 Zimbabwean dollar (1980\\u20132008) random",
6048 "1.00 Zimbabwean dollars (1980\\u20132008) random",
6050 "1.00 euros random",
6051 "1.00 Turkish lira (1922\\u20132005) random",
6052 "1.00 special drawing rights random",
6053 "1.00 Colombian real value unit random",
6054 "1.00 Colombian real value units random",
6055 "1.00 unknown currency random",
6058 const char* WRONG_DATA
[] = {
6059 // Following are missing one last char in the currency name
6060 "usd1.00", // case sensitive
6061 "1.00 Nicaraguan Cordob",
6062 "1.00 Namibian Dolla",
6063 "1.00 Namibian dolla",
6064 "1.00 Nepalese Rupe",
6065 "1.00 Nepalese rupe",
6066 "1.00 Netherlands Antillean Guilde",
6067 "1.00 Netherlands Antillean guilde",
6068 "1.00 Dutch Guilde",
6069 "1.00 Dutch guilde",
6070 "1.00 Israeli New Sheqe",
6071 "1.00 New Zealand Dolla",
6072 "1.00 New Zealand dolla",
6073 "1.00 Nicaraguan cordob",
6074 "1.00 Nigerian Nair",
6075 "1.00 Nigerian nair",
6076 "1.00 North Korean Wo",
6077 "1.00 North Korean wo",
6078 "1.00 Norwegian Kron",
6079 "1.00 Norwegian kron",
6095 "Afghan Afghan1.00",
6096 "Afghan Afghani (1927\\u201320021.00",
6099 "Algerian Dina1.00",
6100 "Andorran Peset1.00",
6101 "Angolan Kwanz1.00",
6102 "Angolan Kwanza (1977\\u201319901.00",
6103 "Angolan Readjusted Kwanza (1995\\u201319991.00",
6104 "Angolan New Kwanza (1990\\u201320001.00",
6105 "Argentine Austra1.00",
6106 "Argentine Pes1.00",
6107 "Argentine Peso (1983\\u201319851.00",
6110 "Australian Dolla1.00",
6111 "Austrian Schillin1.00",
6112 "Azerbaijani Mana1.00",
6113 "Azerbaijani Manat (1993\\u201320061.00",
6131 "Bahamian Dolla1.00",
6132 "Bahraini Dina1.00",
6133 "Bangladeshi Tak1.00",
6134 "Barbadian Dolla1.00",
6136 "Belarusian New Ruble (1994\\u201319991.00",
6137 "Belarusian Rubl1.00",
6139 "Belgian Franc (convertible1.00",
6140 "Belgian Franc (financial1.00",
6142 "Bermudan Dolla1.00",
6143 "Bhutanese Ngultru1.00",
6144 "Bolivian Mvdo1.00",
6146 "Bolivian Bolivian1.00",
6147 "Bosnia-Herzegovina Convertible Mar1.00",
6148 "Bosnia-Herzegovina Dina1.00",
6149 "Botswanan Pul1.00",
6150 "Brazilian Cruzad1.00",
6151 "Brazilian Cruzado Nov1.00",
6152 "Brazilian Cruzeir1.00",
6153 "Brazilian Cruzeiro (1990\\u201319931.00",
6154 "Brazilian New Cruzeiro (1967\\u201319861.00",
6155 "Brazilian Rea1.00",
6156 "British Pound Sterlin1.00",
6158 "Bulgarian Hard Le1.00",
6161 "Burundian Fran1.00",
6176 "Cambodian Rie1.00",
6177 "Canadian Dolla1.00",
6178 "Cape Verdean Escud1.00",
6179 "Cayman Islands Dolla1.00",
6181 "Chilean Unit of Accoun1.00",
6183 "Colombian Pes1.00",
6185 "Congolese Fran1.00",
6186 "Costa Rican Col\\u00f31.00",
6187 "Croatian Dina1.00",
6191 "Czech Republic Korun1.00",
6192 "Czechoslovak Hard Korun1.00",
6202 "Djiboutian Fran1.00",
6204 "Dominican Pes1.00",
6213 "East Caribbean Dolla1.00",
6214 "East German Ostmar1.00",
6215 "Ecuadorian Sucr1.00",
6216 "Ecuadorian Unit of Constant Valu1.00",
6217 "Egyptian Poun1.00",
6219 "Salvadoran Col\\u00f31.00",
6220 "Equatorial Guinean Ekwel1.00",
6221 "Eritrean Nakf1.00",
6223 "Estonian Kroo1.00",
6224 "Ethiopian Bir1.00",
6226 "European Composite Uni1.00",
6227 "European Currency Uni1.00",
6228 "European Monetary Uni1.00",
6229 "European Unit of Account (XBC1.00",
6230 "European Unit of Account (XBD1.00",
6237 "Falkland Islands Poun1.00",
6240 "Finnish Markk1.00",
6243 "French Gold Fran1.00",
6244 "French UIC-Fran1.00",
6257 "Gambian Dalas1.00",
6258 "Georgian Kupon Lari1.00",
6261 "Ghanaian Cedi (1979\\u201320071.00",
6262 "Gibraltar Poun1.00",
6265 "Guatemalan Quetza1.00",
6268 "Guinea-Bissau Pes1.00",
6269 "Guyanaese Dolla1.00",
6275 "Haitian Gourd1.00",
6276 "Honduran Lempir1.00",
6277 "Hong Kong Dolla1.00",
6278 "Hungarian Forin1.00",
6287 "Icelandic Kron1.00",
6289 "Indonesian Rupia1.00",
6299 "Jamaican Dolla1.00",
6301 "Jordanian Dina1.00",
6312 "Kazakhstani Teng1.00",
6313 "Kenyan Shillin1.00",
6315 "Kyrgystani So1.00",
6327 "Lebanese Poun1.00",
6329 "Liberian Dolla1.00",
6331 "Lithuanian Lit1.00",
6332 "Lithuanian Talona1.00",
6333 "Luxembourgian Convertible Fran1.00",
6334 "Luxembourg Financial Fran1.00",
6335 "Luxembourgian Fran1.00",
6353 "Macanese Patac1.00",
6354 "Macedonian Dena1.00",
6355 "Malagasy Ariar1.00",
6356 "Malagasy Fran1.00",
6357 "Malawian Kwach1.00",
6358 "Malaysian Ringgi1.00",
6359 "Maldivian Rufiya1.00",
6364 "Mauritanian Ouguiy1.00",
6365 "Mauritian Rupe1.00",
6367 "Mexican Silver Peso (1861\\u201319921.00",
6368 "Mexican Investment Uni1.00",
6370 "Mongolian Tugri1.00",
6371 "Moroccan Dirha1.00",
6372 "Moroccan Fran1.00",
6373 "Mozambican Escud1.00",
6374 "Mozambican Metica1.00",
6386 "Namibian Dolla1.00",
6387 "Nepalese Rupe1.00",
6388 "Netherlands Antillean Guilde1.00",
6390 "Israeli New Sheqe1.00",
6391 "New Zealand Dolla1.00",
6392 "Nicaraguan C\\u00f3rdoba (1988\\u201319911.00",
6393 "Nicaraguan C\\u00f3rdob1.00",
6394 "Nigerian Nair1.00",
6395 "North Korean Wo1.00",
6396 "Norwegian Kron1.00",
6399 "Old Mozambican Metica1.00",
6400 "Romanian Leu (1952\\u201320061.00",
6401 "Serbian Dinar (2002\\u201320061.00",
6402 "Sudanese Dinar (1992\\u201320071.00",
6403 "Sudanese Pound (1957\\u201319981.00",
6404 "Turkish Lira (1922\\u201320051.00",
6414 "Pakistani Rupe1.00",
6416 "Panamanian Balbo1.00",
6417 "Papua New Guinean Kin1.00",
6418 "Paraguayan Guaran1.00",
6420 "Peruvian Sol (1863\\u201319651.00",
6421 "Peruvian Sol Nuev1.00",
6422 "Philippine Pes1.00",
6425 "Polish Zloty (1950\\u201319951.00",
6426 "Portuguese Escud1.00",
6427 "Portuguese Guinea Escud1.00",
6438 "Rhodesian Dolla1.00",
6441 "Russian Ruble (1991\\u201319981.00",
6461 "St. Helena Poun1.00",
6462 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobr1.00",
6465 "Seychellois Rupe1.00",
6467 "Sierra Leonean Leon1.00",
6469 "Singapore Dolla1.00",
6471 "Slovenian Tola1.00",
6472 "Solomon Islands Dolla1.00",
6473 "Somali Shillin1.00",
6474 "South African Ran1.00",
6475 "South African Rand (financial1.00",
6476 "South Korean Wo1.00",
6478 "Spanish Peset1.00",
6479 "Spanish Peseta (A account1.00",
6480 "Spanish Peseta (convertible account1.00",
6481 "Special Drawing Right1.00",
6482 "Sri Lankan Rupe1.00",
6483 "Sudanese Poun1.00",
6484 "Surinamese Dolla1.00",
6485 "Surinamese Guilde1.00",
6486 "Swazi Lilangen1.00",
6501 "New Taiwan Dolla1.00",
6502 "Tajikistani Rubl1.00",
6503 "Tajikistani Somon1.00",
6504 "Tanzanian Shillin1.00",
6505 "Testing Currency Cod1.00",
6507 "Timorese Escud1.00",
6508 "Tongan Pa\\u20bbang1.00",
6509 "Trinidad & Tobago Dolla1.00",
6510 "Tunisian Dina1.00",
6512 "Turkmenistani Mana1.00",
6518 "US Dollar (Next day1.00",
6519 "US Dollar (Same day1.00",
6523 "Ugandan Shillin1.00",
6524 "Ugandan Shilling (1966\\u201319871.00",
6525 "Ukrainian Hryvni1.00",
6526 "Ukrainian Karbovanet1.00",
6527 "Colombian Real Value Uni1.00",
6528 "United Arab Emirates Dirha1.00",
6529 "Unknown Currenc1.00",
6531 "Uruguay Peso (1975\\u201319931.00",
6532 "Uruguay Peso Uruguay1.00",
6533 "Uruguay Peso (Indexed Units1.00",
6534 "Uzbekistani So1.00",
6540 "Venezuelan Bol\\u00edva1.00",
6541 "Venezuelan Bol\\u00edvar Fuert1.00",
6542 "Vietnamese Don1.00",
6543 "West African CFA Fran1.00",
6544 "Central African CFA Fran1.00",
6565 "Yugoslavian Convertible Dina1.00",
6566 "Yugoslavian Hard Dinar (1966\\u201319901.00",
6567 "Yugoslavian New Dina1.00",
6573 "Zairean New Zaire (1993\\u201319981.00",
6575 "Zambian Kwach1.00",
6576 "Zimbabwean Dollar (1980\\u201320081.00",
6584 Locale
locale("en_US");
6585 for (uint32_t i
=0; i
<UPRV_LENGTHOF(DATA
); ++i
) {
6586 UnicodeString formatted
= ctou(DATA
[i
]);
6587 UErrorCode status
= U_ZERO_ERROR
;
6588 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, UNUM_CURRENCY
, status
);
6589 if (numFmt
!= NULL
&& U_SUCCESS(status
)) {
6590 ParsePosition parsePos
;
6591 LocalPointer
<CurrencyAmount
> currAmt(numFmt
->parseCurrency(formatted
, parsePos
));
6592 if (parsePos
.getIndex() > 0) {
6593 double doubleVal
= currAmt
->getNumber().getDouble(status
);
6594 if ( doubleVal
!= 1.0 ) {
6595 errln("Parsed as currency value other than 1.0: " + formatted
+ " -> " + doubleVal
);
6598 errln("Failed to parse as currency: " + formatted
);
6601 dataerrln("Unable to create NumberFormat. - %s", u_errorName(status
));
6608 for (uint32_t i
=0; i
<UPRV_LENGTHOF(WRONG_DATA
); ++i
) {
6609 UnicodeString formatted
= ctou(WRONG_DATA
[i
]);
6610 UErrorCode status
= U_ZERO_ERROR
;
6611 NumberFormat
* numFmt
= NumberFormat::createInstance(locale
, UNUM_CURRENCY
, status
);
6612 if (numFmt
!= NULL
&& U_SUCCESS(status
)) {
6613 ParsePosition parsePos
;
6614 LocalPointer
<CurrencyAmount
> currAmt(numFmt
->parseCurrency(formatted
, parsePos
));
6615 if (parsePos
.getIndex() > 0) {
6616 double doubleVal
= currAmt
->getNumber().getDouble(status
);
6617 errln("Parsed as currency, should not have: " + formatted
+ " -> " + doubleVal
);
6620 dataerrln("Unable to create NumberFormat. - %s", u_errorName(status
));
6628 const char* attrString(int32_t);
6632 // std::cout << s.toUTF8String(ss)
6633 void NumberFormatTest::expectPositions(FieldPositionIterator
& iter
, int32_t *values
, int32_t tupleCount
,
6634 const UnicodeString
& str
) {
6638 if (tupleCount
> 10) {
6639 assertTrue("internal error, tupleCount too large", FALSE
);
6641 for (int i
= 0; i
< tupleCount
; ++i
) {
6647 while (iter
.next(fp
)) {
6649 int32_t id
= fp
.getField();
6650 int32_t start
= fp
.getBeginIndex();
6651 int32_t limit
= fp
.getEndIndex();
6653 // is there a logln using printf?
6655 sprintf(buf
, "%24s %3d %3d %3d", attrString(id
), id
, start
, limit
);
6658 for (int i
= 0; i
< tupleCount
; ++i
) {
6662 if (values
[i
*3] == id
&&
6663 values
[i
*3+1] == start
&&
6664 values
[i
*3+2] == limit
) {
6665 found
[i
] = ok
= TRUE
;
6670 assertTrue((UnicodeString
)"found [" + id
+ "," + start
+ "," + limit
+ "]", ok
);
6673 // check that all were found
6675 for (int i
= 0; i
< tupleCount
; ++i
) {
6678 assertTrue((UnicodeString
) "missing [" + values
[i
*3] + "," + values
[i
*3+1] + "," + values
[i
*3+2] + "]", found
[i
]);
6681 assertTrue("no expected values were missing", ok
);
6684 void NumberFormatTest::expectPosition(FieldPosition
& pos
, int32_t id
, int32_t start
, int32_t limit
,
6685 const UnicodeString
& str
) {
6687 assertTrue((UnicodeString
)"id " + id
+ " == " + pos
.getField(), id
== pos
.getField());
6688 assertTrue((UnicodeString
)"begin " + start
+ " == " + pos
.getBeginIndex(), start
== pos
.getBeginIndex());
6689 assertTrue((UnicodeString
)"end " + limit
+ " == " + pos
.getEndIndex(), limit
== pos
.getEndIndex());
6692 void NumberFormatTest::TestFieldPositionIterator() {
6694 UErrorCode status
= U_ZERO_ERROR
;
6695 FieldPositionIterator iter1
;
6696 FieldPositionIterator iter2
;
6699 DecimalFormat
*decFmt
= (DecimalFormat
*) NumberFormat::createInstance(status
);
6700 if (failure(status
, "NumberFormat::createInstance", TRUE
)) return;
6702 double num
= 1234.56;
6706 assertTrue((UnicodeString
)"self==", iter1
== iter1
);
6707 assertTrue((UnicodeString
)"iter1==iter2", iter1
== iter2
);
6709 decFmt
->format(num
, str1
, &iter1
, status
);
6710 assertTrue((UnicodeString
)"iter1 != iter2", iter1
!= iter2
);
6711 decFmt
->format(num
, str2
, &iter2
, status
);
6712 assertTrue((UnicodeString
)"iter1 == iter2 (2)", iter1
== iter2
);
6714 assertTrue((UnicodeString
)"iter1 != iter2 (2)", iter1
!= iter2
);
6716 assertTrue((UnicodeString
)"iter1 == iter2 (3)", iter1
== iter2
);
6718 // should format ok with no iterator
6720 decFmt
->format(num
, str2
, NULL
, status
);
6721 assertEquals("null fpiter", str1
, str2
);
6726 void NumberFormatTest::TestFormatAttributes() {
6727 Locale
locale("en_US");
6728 UErrorCode status
= U_ZERO_ERROR
;
6729 DecimalFormat
*decFmt
= (DecimalFormat
*) NumberFormat::createInstance(locale
, UNUM_CURRENCY
, status
);
6730 if (failure(status
, "NumberFormat::createInstance", TRUE
)) return;
6731 double val
= 12345.67;
6734 int32_t expected
[] = {
6735 UNUM_CURRENCY_FIELD
, 0, 1,
6736 UNUM_GROUPING_SEPARATOR_FIELD
, 3, 4,
6737 UNUM_INTEGER_FIELD
, 1, 7,
6738 UNUM_DECIMAL_SEPARATOR_FIELD
, 7, 8,
6739 UNUM_FRACTION_FIELD
, 8, 10,
6741 int32_t tupleCount
= UPRV_LENGTHOF(expected
)/3;
6743 FieldPositionIterator posIter
;
6744 UnicodeString result
;
6745 decFmt
->format(val
, result
, &posIter
, status
);
6746 expectPositions(posIter
, expected
, tupleCount
, result
);
6749 FieldPosition
fp(UNUM_INTEGER_FIELD
);
6750 UnicodeString result
;
6751 decFmt
->format(val
, result
, fp
);
6752 expectPosition(fp
, UNUM_INTEGER_FIELD
, 1, 7, result
);
6755 FieldPosition
fp(UNUM_FRACTION_FIELD
);
6756 UnicodeString result
;
6757 decFmt
->format(val
, result
, fp
);
6758 expectPosition(fp
, UNUM_FRACTION_FIELD
, 8, 10, result
);
6762 decFmt
= (DecimalFormat
*) NumberFormat::createInstance(locale
, UNUM_SCIENTIFIC
, status
);
6765 int32_t expected
[] = {
6766 UNUM_SIGN_FIELD
, 0, 1,
6767 UNUM_INTEGER_FIELD
, 1, 2,
6768 UNUM_DECIMAL_SEPARATOR_FIELD
, 2, 3,
6769 UNUM_FRACTION_FIELD
, 3, 5,
6770 UNUM_EXPONENT_SYMBOL_FIELD
, 5, 6,
6771 UNUM_EXPONENT_SIGN_FIELD
, 6, 7,
6772 UNUM_EXPONENT_FIELD
, 7, 8
6774 int32_t tupleCount
= UPRV_LENGTHOF(expected
)/3;
6776 FieldPositionIterator posIter
;
6777 UnicodeString result
;
6778 decFmt
->format(val
, result
, &posIter
, status
);
6779 expectPositions(posIter
, expected
, tupleCount
, result
);
6782 FieldPosition
fp(UNUM_INTEGER_FIELD
);
6783 UnicodeString result
;
6784 decFmt
->format(val
, result
, fp
);
6785 expectPosition(fp
, UNUM_INTEGER_FIELD
, 1, 2, result
);
6788 FieldPosition
fp(UNUM_FRACTION_FIELD
);
6789 UnicodeString result
;
6790 decFmt
->format(val
, result
, fp
);
6791 expectPosition(fp
, UNUM_FRACTION_FIELD
, 3, 5, result
);
6798 const char* attrString(int32_t attrId
) {
6800 case UNUM_INTEGER_FIELD
: return "integer";
6801 case UNUM_FRACTION_FIELD
: return "fraction";
6802 case UNUM_DECIMAL_SEPARATOR_FIELD
: return "decimal separator";
6803 case UNUM_EXPONENT_SYMBOL_FIELD
: return "exponent symbol";
6804 case UNUM_EXPONENT_SIGN_FIELD
: return "exponent sign";
6805 case UNUM_EXPONENT_FIELD
: return "exponent";
6806 case UNUM_GROUPING_SEPARATOR_FIELD
: return "grouping separator";
6807 case UNUM_CURRENCY_FIELD
: return "currency";
6808 case UNUM_PERCENT_FIELD
: return "percent";
6809 case UNUM_PERMILL_FIELD
: return "permille";
6810 case UNUM_SIGN_FIELD
: return "sign";
6816 // Test formatting & parsing of big decimals.
6817 // API test, not a comprehensive test.
6818 // See DecimalFormatTest/DataDrivenTests
6820 #define ASSERT_SUCCESS(status) {if (U_FAILURE(status)) errln("file %s, line %d: status: %s", \
6821 __FILE__, __LINE__, u_errorName(status));}
6822 #define ASSERT_EQUALS(expected, actual) {if ((expected) != (actual)) \
6823 errln("file %s, line %d: %s != %s", __FILE__, __LINE__, #expected, #actual);}
6825 static UBool
operator != (const char *s1
, UnicodeString
&s2
) {
6826 // This function lets ASSERT_EQUALS("literal", UnicodeString) work.
6827 UnicodeString
us1(s1
);
6831 void NumberFormatTest::TestDecimal() {
6833 UErrorCode status
= U_ZERO_ERROR
;
6834 Formattable
f("12.345678999987654321E666", status
);
6835 ASSERT_SUCCESS(status
);
6836 StringPiece s
= f
.getDecimalNumber(status
);
6837 ASSERT_SUCCESS(status
);
6838 ASSERT_EQUALS("1.2345678999987654321E+667", s
);
6839 //printf("%s\n", s.data());
6843 UErrorCode status
= U_ZERO_ERROR
;
6844 Formattable
f1("this is not a number", status
);
6845 ASSERT_EQUALS(U_DECIMAL_NUMBER_SYNTAX_ERROR
, status
);
6849 UErrorCode status
= U_ZERO_ERROR
;
6851 f
.setDecimalNumber("123.45", status
);
6852 ASSERT_SUCCESS(status
);
6853 ASSERT_EQUALS( Formattable::kDouble
, f
.getType());
6854 ASSERT_EQUALS(123.45, f
.getDouble());
6855 ASSERT_EQUALS(123.45, f
.getDouble(status
));
6856 ASSERT_SUCCESS(status
);
6857 ASSERT_EQUALS("123.45", f
.getDecimalNumber(status
));
6858 ASSERT_SUCCESS(status
);
6860 f
.setDecimalNumber("4.5678E7", status
);
6863 ASSERT_EQUALS(45678000, n
);
6865 status
= U_ZERO_ERROR
;
6866 f
.setDecimalNumber("-123", status
);
6867 ASSERT_SUCCESS(status
);
6868 ASSERT_EQUALS( Formattable::kLong
, f
.getType());
6869 ASSERT_EQUALS(-123, f
.getLong());
6870 ASSERT_EQUALS(-123, f
.getLong(status
));
6871 ASSERT_SUCCESS(status
);
6872 ASSERT_EQUALS("-123", f
.getDecimalNumber(status
));
6873 ASSERT_SUCCESS(status
);
6875 status
= U_ZERO_ERROR
;
6876 f
.setDecimalNumber("1234567890123", status
); // Number too big for 32 bits
6877 ASSERT_SUCCESS(status
);
6878 ASSERT_EQUALS( Formattable::kInt64
, f
.getType());
6879 ASSERT_EQUALS(1234567890123LL, f
.getInt64());
6880 ASSERT_EQUALS(1234567890123LL, f
.getInt64(status
));
6881 ASSERT_SUCCESS(status
);
6882 ASSERT_EQUALS("1234567890123", f
.getDecimalNumber(status
));
6883 ASSERT_SUCCESS(status
);
6887 UErrorCode status
= U_ZERO_ERROR
;
6888 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL
, status
);
6889 if (U_FAILURE(status
) || fmtr
== NULL
) {
6890 dataerrln("Unable to create NumberFormat");
6892 UnicodeString formattedResult
;
6893 StringPiece
num("244444444444444444444444444444444444446.4");
6894 fmtr
->format(num
, formattedResult
, NULL
, status
);
6895 ASSERT_SUCCESS(status
);
6896 ASSERT_EQUALS("244,444,444,444,444,444,444,444,444,444,444,444,446.4", formattedResult
);
6897 //std::string ss; std::cout << formattedResult.toUTF8String(ss);
6903 // Check formatting a DigitList. DigitList is internal, but this is
6904 // a critical interface that must work.
6905 UErrorCode status
= U_ZERO_ERROR
;
6906 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL
, status
);
6907 if (U_FAILURE(status
) || fmtr
== NULL
) {
6908 dataerrln("Unable to create NumberFormat");
6910 UnicodeString formattedResult
;
6912 StringPiece
num("123.4566666666666666666666666666666666621E+40");
6913 dl
.set(num
, status
);
6914 ASSERT_SUCCESS(status
);
6915 fmtr
->format(dl
, formattedResult
, NULL
, status
);
6916 ASSERT_SUCCESS(status
);
6917 ASSERT_EQUALS("1,234,566,666,666,666,666,666,666,666,666,666,666,621,000", formattedResult
);
6919 status
= U_ZERO_ERROR
;
6921 dl
.set(num
, status
);
6922 FieldPosition
pos(NumberFormat::FRACTION_FIELD
);
6923 ASSERT_SUCCESS(status
);
6924 formattedResult
.remove();
6925 fmtr
->format(dl
, formattedResult
, pos
, status
);
6926 ASSERT_SUCCESS(status
);
6927 ASSERT_EQUALS("666.666", formattedResult
);
6928 ASSERT_EQUALS(4, pos
.getBeginIndex());
6929 ASSERT_EQUALS(7, pos
.getEndIndex());
6935 // Check a parse with a formatter with a multiplier.
6936 UErrorCode status
= U_ZERO_ERROR
;
6937 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_PERCENT
, status
);
6938 if (U_FAILURE(status
) || fmtr
== NULL
) {
6939 dataerrln("Unable to create NumberFormat");
6941 UnicodeString input
= "1.84%";
6943 fmtr
->parse(input
, result
, status
);
6944 ASSERT_SUCCESS(status
);
6945 ASSERT_EQUALS(0, strcmp("0.0184", result
.getDecimalNumber(status
).data()));
6946 //std::cout << result.getDecimalNumber(status).data();
6951 #if U_PLATFORM != U_PF_CYGWIN || defined(CYGWINMSVC)
6953 * This test fails on Cygwin (1.7.16) using GCC because of a rounding issue with strtod().
6957 // Check that a parse returns a decimal number with full accuracy
6958 UErrorCode status
= U_ZERO_ERROR
;
6959 NumberFormat
*fmtr
= NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL
, status
);
6960 if (U_FAILURE(status
) || fmtr
== NULL
) {
6961 dataerrln("Unable to create NumberFormat");
6963 UnicodeString input
= "1.002200044400088880000070000";
6965 fmtr
->parse(input
, result
, status
);
6966 ASSERT_SUCCESS(status
);
6967 ASSERT_EQUALS(0, strcmp("1.00220004440008888000007", result
.getDecimalNumber(status
).data()));
6968 ASSERT_EQUALS(1.00220004440008888, result
.getDouble());
6969 //std::cout << result.getDecimalNumber(status).data();
6977 void NumberFormatTest::TestCurrencyFractionDigits() {
6978 UErrorCode status
= U_ZERO_ERROR
;
6979 UnicodeString text1
, text2
;
6980 double value
= 99.12345;
6982 // Create currenct instance
6983 NumberFormat
* fmt
= NumberFormat::createCurrencyInstance("ja_JP", status
);
6984 if (U_FAILURE(status
) || fmt
== NULL
) {
6985 dataerrln("Unable to create NumberFormat");
6987 fmt
->format(value
, text1
);
6989 // Reset the same currency and format the test value again
6990 fmt
->setCurrency(fmt
->getCurrency(), status
);
6991 ASSERT_SUCCESS(status
);
6992 fmt
->format(value
, text2
);
6994 if (text1
!= text2
) {
6995 errln((UnicodeString
)"NumberFormat::format() should return the same result - text1="
6996 + text1
+ " text2=" + text2
);
7002 void NumberFormatTest::TestExponentParse() {
7004 UErrorCode status
= U_ZERO_ERROR
;
7006 ParsePosition
parsePos(0);
7008 // set the exponent symbol
7009 status
= U_ZERO_ERROR
;
7010 DecimalFormatSymbols
*symbols
= new DecimalFormatSymbols(Locale::getDefault(), status
);
7011 if(U_FAILURE(status
)) {
7012 dataerrln((UnicodeString
)"ERROR: Could not create DecimalFormatSymbols (Default)");
7016 // create format instance
7017 status
= U_ZERO_ERROR
;
7018 DecimalFormat
fmt("#####", symbols
, status
);
7019 if(U_FAILURE(status
)) {
7020 errln((UnicodeString
)"ERROR: Could not create DecimalFormat (pattern, symbols*)");
7024 fmt
.parse("5.06e-27", result
, parsePos
);
7025 if(result
.getType() != Formattable::kDouble
&&
7026 result
.getDouble() != 5.06E-27 &&
7027 parsePos
.getIndex() != 8
7030 errln("ERROR: parse failed - expected 5.06E-27, 8 - returned %d, %i",
7031 result
.getDouble(), parsePos
.getIndex());
7035 void NumberFormatTest::TestExplicitParents() {
7037 /* Test that number formats are properly inherited from es_419 */
7038 /* These could be subject to change if the CLDR data changes */
7039 static const char* parentLocaleTests
[][2]= {
7040 /* locale ID */ /* expected */
7041 {"es_CO", "1.250,75" },
7042 {"es_ES", "1.250,75" },
7043 {"es_GQ", "1.250,75" },
7044 {"es_MX", "1,250.75" },
7045 {"es_US", "1,250.75" },
7046 {"es_VE", "1.250,75" },
7051 for(int i
=0; i
< UPRV_LENGTHOF(parentLocaleTests
); i
++){
7052 UErrorCode status
= U_ZERO_ERROR
;
7053 const char *localeID
= parentLocaleTests
[i
][0];
7054 UnicodeString
expected(parentLocaleTests
[i
][1], -1, US_INV
);
7055 expected
= expected
.unescape();
7057 uloc_canonicalize(localeID
, loc
, 256, &status
);
7058 NumberFormat
*fmt
= NumberFormat::createInstance(Locale(loc
), status
);
7059 if(U_FAILURE(status
)){
7060 dataerrln("Could not create number formatter for locale %s - %s",localeID
, u_errorName(status
));
7064 fmt
->format(1250.75, s
);
7066 errln(UnicodeString("FAIL: Expected: ")+expected
7067 + UnicodeString(" Got: ") + s
7068 + UnicodeString( " for locale: ")+ UnicodeString(localeID
) );
7070 if (U_FAILURE(status
)){
7071 errln((UnicodeString
)"FAIL: Status " + (int32_t)status
);
7079 * Test available numbering systems API.
7081 void NumberFormatTest::TestAvailableNumberingSystems() {
7082 UErrorCode status
= U_ZERO_ERROR
;
7083 StringEnumeration
*availableNumberingSystems
= NumberingSystem::getAvailableNames(status
);
7084 CHECK_DATA(status
, "NumberingSystem::getAvailableNames()")
7086 int32_t nsCount
= availableNumberingSystems
->count(status
);
7087 if ( nsCount
< 74 ) {
7088 errln("FAIL: Didn't get as many numbering systems as we had hoped for. Need at least 74, got %d",nsCount
);
7091 /* A relatively simple test of the API. We call getAvailableNames() and cycle through */
7092 /* each name returned, attempting to create a numbering system based on that name and */
7093 /* verifying that the name returned from the resulting numbering system is the same */
7094 /* one that we initially thought. */
7097 for ( int32_t i
= 0 ; i
< nsCount
; i
++ ) {
7098 const char *nsname
= availableNumberingSystems
->next(&len
,status
);
7099 NumberingSystem
* ns
= NumberingSystem::createInstanceByName(nsname
,status
);
7100 logln("OK for ns = %s",nsname
);
7101 if ( uprv_strcmp(nsname
,ns
->getName()) ) {
7102 errln("FAIL: Numbering system name didn't match for name = %s\n",nsname
);
7108 delete availableNumberingSystems
;
7112 NumberFormatTest::Test9087(void)
7114 U_STRING_DECL(pattern
,"#",1);
7115 U_STRING_INIT(pattern
,"#",1);
7117 U_STRING_DECL(infstr
,"INF",3);
7118 U_STRING_INIT(infstr
,"INF",3);
7120 U_STRING_DECL(nanstr
,"NAN",3);
7121 U_STRING_INIT(nanstr
,"NAN",3);
7123 UChar outputbuf
[50] = {0};
7124 UErrorCode status
= U_ZERO_ERROR
;
7125 UNumberFormat
* fmt
= unum_open(UNUM_PATTERN_DECIMAL
,pattern
,1,NULL
,NULL
,&status
);
7126 if ( U_FAILURE(status
) ) {
7127 dataerrln("FAIL: error in unum_open() - %s", u_errorName(status
));
7131 unum_setSymbol(fmt
,UNUM_INFINITY_SYMBOL
,infstr
,3,&status
);
7132 unum_setSymbol(fmt
,UNUM_NAN_SYMBOL
,nanstr
,3,&status
);
7133 if ( U_FAILURE(status
) ) {
7134 errln("FAIL: error setting symbols");
7137 double inf
= uprv_getInfinity();
7139 unum_setAttribute(fmt
,UNUM_ROUNDING_MODE
,UNUM_ROUND_HALFEVEN
);
7140 unum_setDoubleAttribute(fmt
,UNUM_ROUNDING_INCREMENT
,0);
7142 UFieldPosition position
= { 0, 0, 0};
7143 unum_formatDouble(fmt
,inf
,outputbuf
,50,&position
,&status
);
7145 if ( u_strcmp(infstr
, outputbuf
)) {
7146 errln((UnicodeString
)"FAIL: unexpected result for infinity - expected " + infstr
+ " got " + outputbuf
);
7152 #include "dcfmtimp.h"
7154 void NumberFormatTest::TestFormatFastpaths() {
7155 #if UCONFIG_FORMAT_FASTPATHS_49
7156 logln("Sizeof DecimalFormat = %d, Sizeof DecimalFormatInternal=%d, UNUM_DECIMALFORMAT_INTERNAL_SIZE=%d\n",
7157 sizeof(DecimalFormat
), sizeof(DecimalFormatInternal
), UNUM_DECIMALFORMAT_INTERNAL_SIZE
);
7158 if(UNUM_DECIMALFORMAT_INTERNAL_SIZE
< sizeof(DecimalFormatInternal
)) {
7159 errln("Error: sizeof(DecimalFormatInternal)=%d but UNUM_DECIMALFORMAT_INTERNAL_SIZE is only %d. Increase the #define?\n", sizeof(DecimalFormatInternal
), UNUM_DECIMALFORMAT_INTERNAL_SIZE
);
7160 } else if(UNUM_DECIMALFORMAT_INTERNAL_SIZE
> (sizeof(DecimalFormatInternal
)+16)) {
7161 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
));
7164 infoln("NOTE: UCONFIG_FORMAT_FASTPATHS not set, test skipped.");
7167 // get some additional case
7169 UErrorCode status
=U_ZERO_ERROR
;
7170 DecimalFormat
df(UnicodeString("0000",""),status
);
7171 if (U_FAILURE(status
)) {
7172 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
7174 int64_t long_number
= 1;
7175 UnicodeString expect
= "0001";
7176 UnicodeString result
;
7178 df
.format(long_number
, result
, pos
);
7179 if(U_FAILURE(status
)||expect
!=result
) {
7180 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),""));
7182 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),""));
7187 UErrorCode status
=U_ZERO_ERROR
;
7188 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
7189 if (U_FAILURE(status
)) {
7190 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
7192 int64_t long_number
= U_INT64_MIN
; // -9223372036854775808L;
7194 // memcpy(bits,&long_number,8);
7195 // for(int i=0;i<8;i++) {
7196 // logln("bits: %02X", (unsigned int)bits[i]);
7198 UnicodeString expect
= "-9223372036854775808";
7199 UnicodeString result
;
7201 df
.format(long_number
, result
, pos
);
7202 if(U_FAILURE(status
)||expect
!=result
) {
7203 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775808");
7205 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775808");
7210 UErrorCode status
=U_ZERO_ERROR
;
7211 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
7212 if (U_FAILURE(status
)) {
7213 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
7215 int64_t long_number
= U_INT64_MAX
; // -9223372036854775808L;
7217 // memcpy(bits,&long_number,8);
7218 // for(int i=0;i<8;i++) {
7219 // logln("bits: %02X", (unsigned int)bits[i]);
7221 UnicodeString expect
= "9223372036854775807";
7222 UnicodeString result
;
7224 df
.format(long_number
, result
, pos
);
7225 if(U_FAILURE(status
)||expect
!=result
) {
7226 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on U_INT64_MAX");
7228 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on U_INT64_MAX");
7233 UErrorCode status
=U_ZERO_ERROR
;
7234 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
7235 if (U_FAILURE(status
)) {
7236 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
7238 int64_t long_number
= 0;
7240 // memcpy(bits,&long_number,8);
7241 // for(int i=0;i<8;i++) {
7242 // logln("bits: %02X", (unsigned int)bits[i]);
7244 UnicodeString expect
= "0000000000000000000";
7245 UnicodeString result
;
7247 df
.format(long_number
, result
, pos
);
7248 if(U_FAILURE(status
)||expect
!=result
) {
7249 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on 0");
7251 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on 0");
7256 UErrorCode status
=U_ZERO_ERROR
;
7257 DecimalFormat
df(UnicodeString("0000000000000000000",""),status
);
7258 if (U_FAILURE(status
)) {
7259 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
7261 int64_t long_number
= U_INT64_MIN
+ 1;
7262 UnicodeString expect
= "-9223372036854775807";
7263 UnicodeString result
;
7265 df
.format(long_number
, result
, pos
);
7266 if(U_FAILURE(status
)||expect
!=result
) {
7267 errcheckln(status
, "FAIL: expected '"+expect
+"' got '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775807");
7269 logln("OK: got expected '"+result
+"' status "+UnicodeString(u_errorName(status
),"")+" on -9223372036854775807");
7276 void NumberFormatTest::TestFormattableSize(void) {
7277 if(sizeof(FmtStackData
) > UNUM_INTERNAL_STACKARRAY_SIZE
) {
7278 errln("Error: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
7279 sizeof(FmtStackData
), UNUM_INTERNAL_STACKARRAY_SIZE
);
7280 } else if(sizeof(FmtStackData
) < UNUM_INTERNAL_STACKARRAY_SIZE
) {
7281 logln("Warning: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
7282 sizeof(FmtStackData
), UNUM_INTERNAL_STACKARRAY_SIZE
);
7284 logln("sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
7285 sizeof(FmtStackData
), UNUM_INTERNAL_STACKARRAY_SIZE
);
7289 UBool
NumberFormatTest::testFormattableAsUFormattable(const char *file
, int line
, Formattable
&f
) {
7290 UnicodeString fileLine
= UnicodeString(file
)+UnicodeString(":")+line
+UnicodeString(": ");
7292 UFormattable
*u
= f
.toUFormattable();
7295 errln("%s:%d: Error: f.toUFormattable() retuned NULL.");
7298 logln("%s:%d: comparing Formattable with UFormattable", file
, line
);
7299 logln(fileLine
+ toString(f
));
7301 UErrorCode status
= U_ZERO_ERROR
;
7302 UErrorCode valueStatus
= U_ZERO_ERROR
;
7303 UFormattableType expectUType
= UFMT_COUNT
; // invalid
7305 UBool triedExact
= FALSE
; // did we attempt an exact comparison?
7306 UBool exactMatch
= FALSE
; // was the exact comparison true?
7308 switch( f
.getType() ) {
7309 case Formattable::kDate
:
7310 expectUType
= UFMT_DATE
;
7311 exactMatch
= (f
.getDate()==ufmt_getDate(u
, &valueStatus
));
7314 case Formattable::kDouble
:
7315 expectUType
= UFMT_DOUBLE
;
7316 exactMatch
= (f
.getDouble()==ufmt_getDouble(u
, &valueStatus
));
7319 case Formattable::kLong
:
7320 expectUType
= UFMT_LONG
;
7321 exactMatch
= (f
.getLong()==ufmt_getLong(u
, &valueStatus
));
7324 case Formattable::kString
:
7325 expectUType
= UFMT_STRING
;
7330 const UChar
* uch
= ufmt_getUChars(u
, &len
, &valueStatus
);
7331 if(U_SUCCESS(valueStatus
)) {
7332 UnicodeString
str2(uch
, len
);
7333 assertTrue("UChar* NULL-terminated", uch
[len
]==0);
7334 exactMatch
= (str
== str2
);
7339 case Formattable::kArray
:
7340 expectUType
= UFMT_ARRAY
;
7343 int32_t count
= ufmt_getArrayLength(u
, &valueStatus
);
7345 const Formattable
*array2
= f
.getArray(count2
);
7346 exactMatch
= assertEquals(fileLine
+ " array count", count
, count2
);
7349 for(int i
=0;U_SUCCESS(valueStatus
) && i
<count
;i
++) {
7350 UFormattable
*uu
= ufmt_getArrayItemByIndex(u
, i
, &valueStatus
);
7351 if(*Formattable::fromUFormattable(uu
) != (array2
[i
])) {
7352 errln("%s:%d: operator== did not match at index[%d] - %p vs %p", file
, line
, i
,
7353 (const void*)Formattable::fromUFormattable(uu
), (const void*)&(array2
[i
]));
7356 if(!testFormattableAsUFormattable("(sub item)",i
,*Formattable::fromUFormattable(uu
))) {
7364 case Formattable::kInt64
:
7365 expectUType
= UFMT_INT64
;
7366 exactMatch
= (f
.getInt64()==ufmt_getInt64(u
, &valueStatus
));
7369 case Formattable::kObject
:
7370 expectUType
= UFMT_OBJECT
;
7371 exactMatch
= (f
.getObject()==ufmt_getObject(u
, &valueStatus
));
7375 UFormattableType uType
= ufmt_getType(u
, &status
);
7377 if(U_FAILURE(status
)) {
7378 errln("%s:%d: Error calling ufmt_getType - %s", file
, line
, u_errorName(status
));
7382 if(uType
!= expectUType
) {
7383 errln("%s:%d: got type (%d) expected (%d) from ufmt_getType", file
, line
, (int) uType
, (int) expectUType
);
7387 if(U_FAILURE(valueStatus
)) {
7388 errln("%s:%d: got err %s trying to ufmt_get...() for exact match check", file
, line
, u_errorName(valueStatus
));
7389 } else if(!exactMatch
) {
7390 errln("%s:%d: failed exact match for the Formattable type", file
, line
);
7392 logln("%s:%d: exact match OK", file
, line
);
7395 logln("%s:%d: note, did not attempt exact match for this formattable type", file
, line
);
7398 if( assertEquals(fileLine
+ " isNumeric()", f
.isNumeric(), ufmt_isNumeric(u
))
7400 UErrorCode convStatus
= U_ZERO_ERROR
;
7402 if(uType
!= UFMT_INT64
) { // may fail to compare
7403 assertTrue(fileLine
+ " as doubles ==", f
.getDouble(convStatus
)==ufmt_getDouble(u
, &convStatus
));
7406 if( assertSuccess(fileLine
+ " (numeric conversion status)", convStatus
) ) {
7407 StringPiece fDecNum
= f
.getDecimalNumber(convStatus
);
7410 const char *decNumChars
= ufmt_getDecNumChars(u
, &len
, &convStatus
);
7413 char decNumChars
[200];
7414 int32_t len
= ufmt_getDecNumChars(u
, decNumChars
, 200, &convStatus
);
7417 if( assertSuccess(fileLine
+ " (decNumbers conversion)", convStatus
) ) {
7418 logln(fileLine
+ decNumChars
);
7419 assertEquals(fileLine
+ " decNumChars length==", len
, fDecNum
.length());
7420 assertEquals(fileLine
+ " decNumChars digits", decNumChars
, fDecNum
.data());
7423 UErrorCode int64ConversionF
= U_ZERO_ERROR
;
7424 int64_t l
= f
.getInt64(int64ConversionF
);
7425 UErrorCode int64ConversionU
= U_ZERO_ERROR
;
7426 int64_t r
= ufmt_getInt64(u
, &int64ConversionU
);
7429 && ( uType
!= UFMT_INT64
) // int64 better not overflow
7430 && (U_INVALID_FORMAT_ERROR
==int64ConversionU
)
7431 && (U_INVALID_FORMAT_ERROR
==int64ConversionF
) ) {
7432 logln("%s:%d: OK: 64 bit overflow", file
, line
);
7434 assertEquals(fileLine
+ " as int64 ==", l
, r
);
7435 assertSuccess(fileLine
+ " Formattable.getnt64()", int64ConversionF
);
7436 assertSuccess(fileLine
+ " ufmt_getInt64()", int64ConversionU
);
7440 return exactMatch
|| !triedExact
;
7443 void NumberFormatTest::TestUFormattable(void) {
7445 // test that a default formattable is equal to Formattable()
7446 UErrorCode status
= U_ZERO_ERROR
;
7447 LocalUFormattablePointer
defaultUFormattable(ufmt_open(&status
));
7448 assertSuccess("calling umt_open", status
);
7449 Formattable defaultFormattable
;
7450 assertTrue((UnicodeString
)"comparing ufmt_open() with Formattable()",
7452 == *(Formattable::fromUFormattable(defaultUFormattable
.getAlias()))));
7453 assertTrue((UnicodeString
)"comparing ufmt_open() with Formattable()",
7455 == *(Formattable::fromUFormattable(defaultUFormattable
.getAlias()))));
7456 assertTrue((UnicodeString
)"comparing Formattable() round tripped through UFormattable",
7458 == *(Formattable::fromUFormattable(defaultFormattable
.toUFormattable()))));
7459 assertTrue((UnicodeString
)"comparing &Formattable() round tripped through UFormattable",
7460 ((&defaultFormattable
)
7461 == Formattable::fromUFormattable(defaultFormattable
.toUFormattable())));
7462 assertFalse((UnicodeString
)"comparing &Formattable() with ufmt_open()",
7463 ((&defaultFormattable
)
7464 == Formattable::fromUFormattable(defaultUFormattable
.getAlias())));
7465 testFormattableAsUFormattable(__FILE__
, __LINE__
, defaultFormattable
);
7467 // test some random Formattables
7469 Formattable
f(ucal_getNow(), Formattable::kIsDate
);
7470 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7473 Formattable
f((double)1.61803398874989484820); // golden ratio
7474 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7477 Formattable
f((int64_t)80994231587905127LL); // weight of the moon, in kilotons http://solarsystem.nasa.gov/planets/profile.cfm?Display=Facts&Object=Moon
7478 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7481 Formattable
f((int32_t)4); // random number, source: http://www.xkcd.com/221/
7482 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7485 Formattable
f("Hello world."); // should be invariant?
7486 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7489 UErrorCode status2
= U_ZERO_ERROR
;
7490 Formattable
f(StringPiece("73476730924573500000000.0"), status2
); // weight of the moon, kg
7491 assertSuccess("Constructing a StringPiece", status2
);
7492 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7495 UErrorCode status2
= U_ZERO_ERROR
;
7496 UObject
*obj
= new Locale();
7498 assertSuccess("Constructing a Formattable from a default constructed Locale()", status2
);
7499 testFormattableAsUFormattable(__FILE__
, __LINE__
, f
);
7502 const Formattable array
[] = {
7503 Formattable(ucal_getNow(), Formattable::kIsDate
),
7504 Formattable((int32_t)4),
7505 Formattable((double)1.234),
7508 Formattable
fa(array
, 3);
7509 testFormattableAsUFormattable(__FILE__
, __LINE__
, fa
);
7513 void NumberFormatTest::TestSignificantDigits(void) {
7520 123.44501, -123.44501,
7521 0.001234, -0.001234,
7522 0.00000000123, -0.00000000123,
7523 0.0000000000000000000123, -0.0000000000000000000123,
7525 0.0000000012344501, -0.0000000012344501,
7526 123445.01, -123445.01,
7527 12344501000000000000000000000000000.0, -12344501000000000000000000000000000.0,
7529 const char* expected
[] = {
7534 "123.45", "-123.45",
7535 "123.45", "-123.45",
7536 "0.001234", "-0.001234",
7537 "0.00000000123", "-0.00000000123",
7538 "0.0000000000000000000123", "-0.0000000000000000000123",
7540 "0.0000000012345", "-0.0000000012345",
7541 "123450", "-123450",
7542 "12345000000000000000000000000000000", "-12345000000000000000000000000000000",
7545 UErrorCode status
= U_ZERO_ERROR
;
7546 Locale
locale("en_US");
7547 LocalPointer
<DecimalFormat
> numberFormat(static_cast<DecimalFormat
*>(
7548 NumberFormat::createInstance(locale
, status
)));
7549 CHECK_DATA(status
,"NumberFormat::createInstance")
7551 numberFormat
->setSignificantDigitsUsed(TRUE
);
7552 numberFormat
->setMinimumSignificantDigits(3);
7553 numberFormat
->setMaximumSignificantDigits(5);
7554 numberFormat
->setGroupingUsed(false);
7556 UnicodeString result
;
7557 UnicodeString expectedResult
;
7558 for (unsigned int i
= 0; i
< UPRV_LENGTHOF(input
); ++i
) {
7559 numberFormat
->format(input
[i
], result
);
7560 UnicodeString
expectedResult(expected
[i
]);
7561 if (result
!= expectedResult
) {
7562 errln((UnicodeString
)"Expected: '" + expectedResult
+ "' got '" + result
);
7568 void NumberFormatTest::TestShowZero() {
7569 UErrorCode status
= U_ZERO_ERROR
;
7570 Locale
locale("en_US");
7571 LocalPointer
<DecimalFormat
> numberFormat(static_cast<DecimalFormat
*>(
7572 NumberFormat::createInstance(locale
, status
)));
7573 CHECK_DATA(status
, "NumberFormat::createInstance")
7575 numberFormat
->setSignificantDigitsUsed(TRUE
);
7576 numberFormat
->setMaximumSignificantDigits(3);
7578 UnicodeString result
;
7579 numberFormat
->format(0.0, result
);
7580 if (result
!= "0") {
7581 errln((UnicodeString
)"Expected: 0, got " + result
);
7585 void NumberFormatTest::TestBug9936() {
7586 UErrorCode status
= U_ZERO_ERROR
;
7587 Locale
locale("en_US");
7588 LocalPointer
<DecimalFormat
> numberFormat(static_cast<DecimalFormat
*>(
7589 NumberFormat::createInstance(locale
, status
)));
7590 if (U_FAILURE(status
)) {
7591 dataerrln("File %s, Line %d: status = %s.\n", __FILE__
, __LINE__
, u_errorName(status
));
7595 if (numberFormat
->areSignificantDigitsUsed() == TRUE
) {
7596 errln("File %s, Line %d: areSignificantDigitsUsed() was TRUE, expected FALSE.\n", __FILE__
, __LINE__
);
7598 numberFormat
->setSignificantDigitsUsed(TRUE
);
7599 if (numberFormat
->areSignificantDigitsUsed() == FALSE
) {
7600 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__
, __LINE__
);
7603 numberFormat
->setSignificantDigitsUsed(FALSE
);
7604 if (numberFormat
->areSignificantDigitsUsed() == TRUE
) {
7605 errln("File %s, Line %d: areSignificantDigitsUsed() was TRUE, expected FALSE.\n", __FILE__
, __LINE__
);
7608 numberFormat
->setMinimumSignificantDigits(3);
7609 if (numberFormat
->areSignificantDigitsUsed() == FALSE
) {
7610 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__
, __LINE__
);
7613 numberFormat
->setSignificantDigitsUsed(FALSE
);
7614 numberFormat
->setMaximumSignificantDigits(6);
7615 if (numberFormat
->areSignificantDigitsUsed() == FALSE
) {
7616 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__
, __LINE__
);
7621 void NumberFormatTest::TestParseNegativeWithFaLocale() {
7622 UErrorCode status
= U_ZERO_ERROR
;
7623 DecimalFormat
*test
= (DecimalFormat
*) NumberFormat::createInstance("fa", status
);
7624 CHECK_DATA(status
, "NumberFormat::createInstance")
7625 test
->setLenient(TRUE
);
7628 UnicodeString
value("\\u200e-0,5");
7629 value
= value
.unescape();
7630 test
->parse(value
, af
, ppos
);
7631 if (ppos
.getIndex() == 0) {
7632 errln("Expected -0,5 to parse for Farsi.");
7637 void NumberFormatTest::TestParseNegativeWithAlternateMinusSign() {
7638 UErrorCode status
= U_ZERO_ERROR
;
7639 DecimalFormat
*test
= (DecimalFormat
*) NumberFormat::createInstance("en", status
);
7640 CHECK_DATA(status
, "NumberFormat::createInstance")
7641 test
->setLenient(TRUE
);
7644 UnicodeString
value("\\u208B0.5");
7645 value
= value
.unescape();
7646 test
->parse(value
, af
, ppos
);
7647 if (ppos
.getIndex() == 0) {
7648 errln(UnicodeString("Expected ") + value
+ UnicodeString(" to parse."));
7653 void NumberFormatTest::TestCustomCurrencySignAndSeparator() {
7654 UErrorCode status
= U_ZERO_ERROR
;
7655 DecimalFormatSymbols
custom(Locale::getUS(), status
);
7656 CHECK(status
, "DecimalFormatSymbols constructor");
7658 custom
.setSymbol(DecimalFormatSymbols::kCurrencySymbol
, "*");
7659 custom
.setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol
, "^");
7660 custom
.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol
, ":");
7662 UnicodeString
pat(" #,##0.00");
7663 pat
.insert(0, (UChar
)0x00A4);
7665 DecimalFormat
fmt(pat
, custom
, status
);
7666 CHECK(status
, "DecimalFormat constructor");
7668 UnicodeString
numstr("* 1^234:56");
7669 expect2(fmt
, (Formattable
)((double)1234.56), numstr
);
7673 const char * locale
;
7675 UnicodeString numString
;
7677 } SignsAndMarksItem
;
7680 void NumberFormatTest::TestParseSignsAndMarks() {
7681 const SignsAndMarksItem items
[] = {
7682 // locale lenient numString value
7683 { "en", FALSE
, CharsToUnicodeString("12"), 12 },
7684 { "en", TRUE
, CharsToUnicodeString("12"), 12 },
7685 { "en", FALSE
, CharsToUnicodeString("-23"), -23 },
7686 { "en", TRUE
, CharsToUnicodeString("-23"), -23 },
7687 { "en", TRUE
, CharsToUnicodeString("- 23"), -23 },
7688 { "en", FALSE
, CharsToUnicodeString("\\u200E-23"), -23 },
7689 { "en", TRUE
, CharsToUnicodeString("\\u200E-23"), -23 },
7690 { "en", TRUE
, CharsToUnicodeString("\\u200E- 23"), -23 },
7692 { "en@numbers=arab", FALSE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7693 { "en@numbers=arab", TRUE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7694 { "en@numbers=arab", FALSE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7695 { "en@numbers=arab", TRUE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7696 { "en@numbers=arab", TRUE
, CharsToUnicodeString("- \\u0664\\u0665"), -45 },
7697 { "en@numbers=arab", FALSE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7698 { "en@numbers=arab", TRUE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7699 { "en@numbers=arab", TRUE
, CharsToUnicodeString("\\u200F- \\u0664\\u0665"), -45 },
7701 { "en@numbers=arabext", FALSE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7702 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7703 { "en@numbers=arabext", FALSE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7704 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7705 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("- \\u06F6\\u06F7"), -67 },
7706 { "en@numbers=arabext", FALSE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7707 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7708 { "en@numbers=arabext", TRUE
, CharsToUnicodeString("\\u200E-\\u200E \\u06F6\\u06F7"), -67 },
7710 { "he", FALSE
, CharsToUnicodeString("12"), 12 },
7711 { "he", TRUE
, CharsToUnicodeString("12"), 12 },
7712 { "he", FALSE
, CharsToUnicodeString("-23"), -23 },
7713 { "he", TRUE
, CharsToUnicodeString("-23"), -23 },
7714 { "he", TRUE
, CharsToUnicodeString("- 23"), -23 },
7715 { "he", FALSE
, CharsToUnicodeString("\\u200E-23"), -23 },
7716 { "he", TRUE
, CharsToUnicodeString("\\u200E-23"), -23 },
7717 { "he", TRUE
, CharsToUnicodeString("\\u200E- 23"), -23 },
7719 { "ar", FALSE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7720 { "ar", TRUE
, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7721 { "ar", FALSE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7722 { "ar", TRUE
, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7723 { "ar", TRUE
, CharsToUnicodeString("- \\u0664\\u0665"), -45 },
7724 { "ar", FALSE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7725 { "ar", TRUE
, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7726 { "ar", TRUE
, CharsToUnicodeString("\\u200F- \\u0664\\u0665"), -45 },
7728 { "ar_MA", FALSE
, CharsToUnicodeString("12"), 12 },
7729 { "ar_MA", TRUE
, CharsToUnicodeString("12"), 12 },
7730 { "ar_MA", FALSE
, CharsToUnicodeString("-23"), -23 },
7731 { "ar_MA", TRUE
, CharsToUnicodeString("-23"), -23 },
7732 { "ar_MA", TRUE
, CharsToUnicodeString("- 23"), -23 },
7733 { "ar_MA", FALSE
, CharsToUnicodeString("\\u200E-23"), -23 },
7734 { "ar_MA", TRUE
, CharsToUnicodeString("\\u200E-23"), -23 },
7735 { "ar_MA", TRUE
, CharsToUnicodeString("\\u200E- 23"), -23 },
7737 { "fa", FALSE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7738 { "fa", TRUE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7739 { "fa", FALSE
, CharsToUnicodeString("\\u2212\\u06F6\\u06F7"), -67 },
7740 { "fa", TRUE
, CharsToUnicodeString("\\u2212\\u06F6\\u06F7"), -67 },
7741 { "fa", TRUE
, CharsToUnicodeString("\\u2212 \\u06F6\\u06F7"), -67 },
7742 { "fa", FALSE
, CharsToUnicodeString("\\u200E\\u2212\\u200E\\u06F6\\u06F7"), -67 },
7743 { "fa", TRUE
, CharsToUnicodeString("\\u200E\\u2212\\u200E\\u06F6\\u06F7"), -67 },
7744 { "fa", TRUE
, CharsToUnicodeString("\\u200E\\u2212\\u200E \\u06F6\\u06F7"), -67 },
7746 { "ps", FALSE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7747 { "ps", TRUE
, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7748 { "ps", FALSE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7749 { "ps", TRUE
, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7750 { "ps", TRUE
, CharsToUnicodeString("- \\u06F6\\u06F7"), -67 },
7751 { "ps", FALSE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7752 { "ps", TRUE
, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7753 { "ps", TRUE
, CharsToUnicodeString("\\u200E-\\u200E \\u06F6\\u06F7"), -67 },
7754 { "ps", FALSE
, CharsToUnicodeString("-\\u200E\\u06F6\\u06F7"), -67 },
7755 { "ps", TRUE
, CharsToUnicodeString("-\\u200E\\u06F6\\u06F7"), -67 },
7756 { "ps", TRUE
, CharsToUnicodeString("-\\u200E \\u06F6\\u06F7"), -67 },
7758 { NULL
, 0, UnicodeString(""), 0 },
7761 const SignsAndMarksItem
* itemPtr
;
7762 for (itemPtr
= items
; itemPtr
->locale
!= NULL
; itemPtr
++ ) {
7763 UErrorCode status
= U_ZERO_ERROR
;
7764 NumberFormat
*numfmt
= NumberFormat::createInstance(Locale(itemPtr
->locale
), status
);
7765 if (U_SUCCESS(status
)) {
7766 numfmt
->setLenient(itemPtr
->lenient
);
7769 numfmt
->parse(itemPtr
->numString
, fmtobj
, ppos
);
7770 if (ppos
.getIndex() == itemPtr
->numString
.length()) {
7771 double parsedValue
= fmtobj
.getDouble(status
);
7772 if (U_FAILURE(status
) || parsedValue
!= itemPtr
->value
) {
7773 errln((UnicodeString
)"FAIL: locale " + itemPtr
->locale
+ ", lenient " + itemPtr
->lenient
+ ", parse of \"" + itemPtr
->numString
+ "\" gives value " + parsedValue
);
7776 errln((UnicodeString
)"FAIL: locale " + itemPtr
->locale
+ ", lenient " + itemPtr
->lenient
+ ", parse of \"" + itemPtr
->numString
+ "\" gives position " + ppos
.getIndex());
7779 dataerrln("FAIL: NumberFormat::createInstance for locale % gives error %s", itemPtr
->locale
, u_errorName(status
));
7786 DecimalFormat::ERoundingMode mode
;
7788 UnicodeString expected
;
7792 // Tests that rounding works right when fractional digits is set to 0.
7793 void NumberFormatTest::Test10419RoundingWith0FractionDigits() {
7794 const Test10419Data items
[] = {
7795 { DecimalFormat::kRoundCeiling
, 1.488, "2"},
7796 { DecimalFormat::kRoundDown
, 1.588, "1"},
7797 { DecimalFormat::kRoundFloor
, 1.888, "1"},
7798 { DecimalFormat::kRoundHalfDown
, 1.5, "1"},
7799 { DecimalFormat::kRoundHalfEven
, 2.5, "2"},
7800 { DecimalFormat::kRoundHalfUp
, 2.5, "3"},
7801 { DecimalFormat::kRoundUp
, 1.5, "2"},
7803 UErrorCode status
= U_ZERO_ERROR
;
7804 LocalPointer
<DecimalFormat
> decfmt((DecimalFormat
*) NumberFormat::createInstance(Locale("en_US"), status
));
7805 if (U_FAILURE(status
)) {
7806 dataerrln("Failure creating DecimalFormat %s", u_errorName(status
));
7809 for (int32_t i
= 0; i
< UPRV_LENGTHOF(items
); ++i
) {
7810 decfmt
->setRoundingMode(items
[i
].mode
);
7811 decfmt
->setMaximumFractionDigits(0);
7812 UnicodeString actual
;
7813 if (items
[i
].expected
!= decfmt
->format(items
[i
].value
, actual
)) {
7814 errln("Expected " + items
[i
].expected
+ ", got " + actual
);
7819 void NumberFormatTest::Test10468ApplyPattern() {
7820 // Padding char of fmt is now 'a'
7821 UErrorCode status
= U_ZERO_ERROR
;
7822 DecimalFormat
fmt("'I''ll'*a###.##", status
);
7824 if (U_FAILURE(status
)) {
7825 errcheckln(status
, "DecimalFormat constructor failed - %s", u_errorName(status
));
7829 if (fmt
.getPadCharacterString() != UnicodeString("a")) {
7830 errln("Padding character should be 'a'.");
7834 // Padding char of fmt ought to be '*' since that is the default and no
7835 // explicit padding char is specified in the new pattern.
7836 fmt
.applyPattern("AA#,##0.00ZZ", status
);
7838 // Oops this still prints 'a' even though we changed the pattern.
7839 if (fmt
.getPadCharacterString() != UnicodeString(" ")) {
7840 errln("applyPattern did not clear padding character.");
7844 void NumberFormatTest::TestRoundingScientific10542() {
7845 UErrorCode status
= U_ZERO_ERROR
;
7846 DecimalFormat
format("0.00E0", status
);
7847 if (U_FAILURE(status
)) {
7848 errcheckln(status
, "DecimalFormat constructor failed - %s", u_errorName(status
));
7852 DecimalFormat::ERoundingMode roundingModes
[] = {
7853 DecimalFormat::kRoundCeiling
,
7854 DecimalFormat::kRoundDown
,
7855 DecimalFormat::kRoundFloor
,
7856 DecimalFormat::kRoundHalfDown
,
7857 DecimalFormat::kRoundHalfEven
,
7858 DecimalFormat::kRoundHalfUp
,
7859 DecimalFormat::kRoundUp
};
7860 const char *descriptions
[] = {
7870 double values
[] = {-0.003006, -0.003005, -0.003004, 0.003014, 0.003015, 0.003016};
7871 // The order of these expected values correspond to the order of roundingModes and the order of values.
7872 const char *expected
[] = {
7873 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.02E-3", "3.02E-3", "3.02E-3",
7874 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.01E-3",
7875 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.01E-3", "3.01E-3", "3.01E-3",
7876 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.02E-3",
7877 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E-3",
7878 "-3.01E-3", "-3.01E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E-3",
7879 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.02E-3", "3.02E-3", "3.02E-3"};
7886 UPRV_LENGTHOF(values
),
7887 UPRV_LENGTHOF(roundingModes
));
7890 double values
[] = {-3006.0, -3005, -3004, 3014, 3015, 3016};
7891 // The order of these expected values correspond to the order of roundingModes and the order of values.
7892 const char *expected
[] = {
7893 "-3.00E3", "-3.00E3", "-3.00E3", "3.02E3", "3.02E3", "3.02E3",
7894 "-3.00E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.01E3",
7895 "-3.01E3", "-3.01E3", "-3.01E3", "3.01E3", "3.01E3", "3.01E3",
7896 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.02E3",
7897 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3",
7898 "-3.01E3", "-3.01E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3",
7899 "-3.01E3", "-3.01E3", "-3.01E3", "3.02E3", "3.02E3", "3.02E3"};
7906 UPRV_LENGTHOF(values
),
7907 UPRV_LENGTHOF(roundingModes
));
7909 /* Commented out for now until we decide how rounding to zero should work, +0 vs. -0
7911 double values[] = {0.0, -0.0};
7912 // The order of these expected values correspond to the order of roundingModes and the order of values.
7913 const char *expected[] = {
7914 "0.00E0", "-0.00E0",
7915 "0.00E0", "-0.00E0",
7916 "0.00E0", "-0.00E0",
7917 "0.00E0", "-0.00E0",
7918 "0.00E0", "-0.00E0",
7919 "0.00E0", "-0.00E0",
7920 "0.00E0", "-0.00E0"};
7927 UPRV_LENGTHOF(values),
7928 UPRV_LENGTHOF(roundingModes));
7933 double values
[] = {1e25
, 1e25
+ 1e15
, 1e25
- 1e15
};
7934 // The order of these expected values correspond to the order of roundingModes and the order of values.
7935 const char *expected
[] = {
7936 "1.00E25", "1.01E25", "1.00E25",
7937 "1.00E25", "1.00E25", "9.99E24",
7938 "1.00E25", "1.00E25", "9.99E24",
7939 "1.00E25", "1.00E25", "1.00E25",
7940 "1.00E25", "1.00E25", "1.00E25",
7941 "1.00E25", "1.00E25", "1.00E25",
7942 "1.00E25", "1.01E25", "1.00E25"};
7949 UPRV_LENGTHOF(values
),
7950 UPRV_LENGTHOF(roundingModes
));
7953 double values
[] = {-1e25
, -1e25
+ 1e15
, -1e25
- 1e15
};
7954 // The order of these expected values correspond to the order of roundingModes and the order of values.
7955 const char *expected
[] = {
7956 "-1.00E25", "-9.99E24", "-1.00E25",
7957 "-1.00E25", "-9.99E24", "-1.00E25",
7958 "-1.00E25", "-1.00E25", "-1.01E25",
7959 "-1.00E25", "-1.00E25", "-1.00E25",
7960 "-1.00E25", "-1.00E25", "-1.00E25",
7961 "-1.00E25", "-1.00E25", "-1.00E25",
7962 "-1.00E25", "-1.00E25", "-1.01E25"};
7969 UPRV_LENGTHOF(values
),
7970 UPRV_LENGTHOF(roundingModes
));
7973 double values
[] = {1e-25, 1e-25 + 1e-35, 1e-25 - 1e-35};
7974 // The order of these expected values correspond to the order of roundingModes and the order of values.
7975 const char *expected
[] = {
7976 "1.00E-25", "1.01E-25", "1.00E-25",
7977 "1.00E-25", "1.00E-25", "9.99E-26",
7978 "1.00E-25", "1.00E-25", "9.99E-26",
7979 "1.00E-25", "1.00E-25", "1.00E-25",
7980 "1.00E-25", "1.00E-25", "1.00E-25",
7981 "1.00E-25", "1.00E-25", "1.00E-25",
7982 "1.00E-25", "1.01E-25", "1.00E-25"};
7989 UPRV_LENGTHOF(values
),
7990 UPRV_LENGTHOF(roundingModes
));
7993 double values
[] = {-1e-25, -1e-25 + 1e-35, -1e-25 - 1e-35};
7994 // The order of these expected values correspond to the order of roundingModes and the order of values.
7995 const char *expected
[] = {
7996 "-1.00E-25", "-9.99E-26", "-1.00E-25",
7997 "-1.00E-25", "-9.99E-26", "-1.00E-25",
7998 "-1.00E-25", "-1.00E-25", "-1.01E-25",
7999 "-1.00E-25", "-1.00E-25", "-1.00E-25",
8000 "-1.00E-25", "-1.00E-25", "-1.00E-25",
8001 "-1.00E-25", "-1.00E-25", "-1.00E-25",
8002 "-1.00E-25", "-1.00E-25", "-1.01E-25"};
8009 UPRV_LENGTHOF(values
),
8010 UPRV_LENGTHOF(roundingModes
));
8014 void NumberFormatTest::TestZeroScientific10547() {
8015 UErrorCode status
= U_ZERO_ERROR
;
8016 DecimalFormat
fmt("0.00E0", status
);
8017 if (!assertSuccess("Formt creation", status
)) {
8021 fmt
.format(-0.0, out
);
8022 assertEquals("format", "-0.00E0", out
);
8025 void NumberFormatTest::verifyRounding(
8026 DecimalFormat
& format
,
8027 const double *values
,
8028 const char * const *expected
,
8029 const DecimalFormat::ERoundingMode
*roundingModes
,
8030 const char * const *descriptions
,
8032 int32_t roundingModeSize
) {
8033 for (int32_t i
= 0; i
< roundingModeSize
; ++i
) {
8034 format
.setRoundingMode(roundingModes
[i
]);
8035 for (int32_t j
= 0; j
< valueSize
; j
++) {
8036 UnicodeString
currentExpected(expected
[i
* valueSize
+ j
]);
8037 currentExpected
= currentExpected
.unescape();
8038 UnicodeString actual
;
8039 format
.format(values
[j
], actual
);
8040 if (currentExpected
!= actual
) {
8044 "For %s value %f, expected ",
8047 errln(UnicodeString(buffer
) + currentExpected
+ ", got " + actual
);
8053 void NumberFormatTest::TestAccountingCurrency() {
8054 UErrorCode status
= U_ZERO_ERROR
;
8055 UNumberFormatStyle style
= UNUM_CURRENCY_ACCOUNTING
;
8057 expect(NumberFormat::createInstance("en_US", style
, status
),
8058 (Formattable
)1234.5, "$1,234.50", TRUE
, status
);
8059 expect(NumberFormat::createInstance("en_US", style
, status
),
8060 (Formattable
)-1234.5, "($1,234.50)", TRUE
, status
);
8061 expect(NumberFormat::createInstance("en_US", style
, status
),
8062 (Formattable
)0, "$0.00", TRUE
, status
);
8063 expect(NumberFormat::createInstance("en_US", style
, status
),
8064 (Formattable
)-0.2, "($0.20)", TRUE
, status
);
8065 expect(NumberFormat::createInstance("ja_JP", style
, status
),
8066 (Formattable
)10000, UnicodeString("\\u00A510,000").unescape(), TRUE
, status
);
8067 expect(NumberFormat::createInstance("ja_JP", style
, status
),
8068 (Formattable
)-1000.5, UnicodeString("(\\u00A51,000)").unescape(), FALSE
, status
);
8069 expect(NumberFormat::createInstance("de_DE", style
, status
),
8070 (Formattable
)-23456.7, UnicodeString("-23.456,70\\u00A0\\u20AC").unescape(), TRUE
, status
);
8074 void NumberFormatTest::TestEquality() {
8075 UErrorCode status
= U_ZERO_ERROR
;
8076 DecimalFormatSymbols
* symbols
= new DecimalFormatSymbols(Locale("root"), status
);
8077 if (U_FAILURE(status
)) {
8078 dataerrln("Fail: can't create DecimalFormatSymbols for root");
8081 UnicodeString
pattern("#,##0.###");
8082 DecimalFormat
* fmtBase
= new DecimalFormat(pattern
, symbols
, status
);
8083 if (U_FAILURE(status
)) {
8084 dataerrln("Fail: can't create DecimalFormat using root symbols");
8088 DecimalFormat
* fmtClone
= (DecimalFormat
*)fmtBase
->clone();
8089 fmtClone
->setFormatWidth(fmtBase
->getFormatWidth() + 32);
8090 if (*fmtClone
== *fmtBase
) {
8091 errln("Error: DecimalFormat == does not distinguish objects that differ only in FormatWidth");
8098 void NumberFormatTest::TestCurrencyUsage() {
8099 double agent
= 123.567;
8104 // compare the Currency and Currency Cash Digits
8105 // Note that as of CLDR 26:
8106 // * TWD switches from 0 decimals to 2; PKR still has 0, so change test to that
8107 // * CAD rounds to .05 in cash mode only
8108 // 1st time for getter/setter, 2nd time for factory method
8109 Locale
enUS_PKR("en_US@currency=PKR");
8111 for(int i
=0; i
<2; i
++){
8112 status
= U_ZERO_ERROR
;
8114 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_PKR
, UNUM_CURRENCY
, status
);
8115 if (assertSuccess("en_US@currency=PKR/CURRENCY", status
, TRUE
) == FALSE
) {
8119 UnicodeString original
;
8120 fmt
->format(agent
,original
);
8121 assertEquals("Test Currency Usage 1", UnicodeString("PKR124"), original
);
8123 // test the getter here
8124 UCurrencyUsage curUsage
= fmt
->getCurrencyUsage();
8125 assertEquals("Test usage getter - standard", curUsage
, UCURR_USAGE_STANDARD
);
8127 fmt
->setCurrencyUsage(UCURR_USAGE_CASH
, &status
);
8129 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_PKR
, UNUM_CASH_CURRENCY
, status
);
8130 if (assertSuccess("en_US@currency=PKR/CASH", status
, TRUE
) == FALSE
) {
8135 // must be usage = cash
8136 UCurrencyUsage curUsage
= fmt
->getCurrencyUsage();
8137 assertEquals("Test usage getter - cash", curUsage
, UCURR_USAGE_CASH
);
8139 UnicodeString cash_currency
;
8140 fmt
->format(agent
,cash_currency
);
8141 assertEquals("Test Currency Usage 2", UnicodeString("PKR124"), cash_currency
);
8145 // compare the Currency and Currency Cash Rounding
8146 // 1st time for getter/setter, 2nd time for factory method
8147 Locale
enUS_CAD("en_US@currency=CAD");
8148 for(int i
=0; i
<2; i
++){
8149 status
= U_ZERO_ERROR
;
8151 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CURRENCY
, status
);
8152 if (assertSuccess("en_US@currency=CAD/CURRENCY", status
, TRUE
) == FALSE
) {
8156 UnicodeString original_rounding
;
8157 fmt
->format(agent
, original_rounding
);
8158 assertEquals("Test Currency Usage 3", UnicodeString("CA$123.57"), original_rounding
);
8159 fmt
->setCurrencyUsage(UCURR_USAGE_CASH
, &status
);
8161 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CASH_CURRENCY
, status
);
8162 if (assertSuccess("en_US@currency=CAD/CASH", status
, TRUE
) == FALSE
) {
8167 UnicodeString cash_rounding_currency
;
8168 fmt
->format(agent
, cash_rounding_currency
);
8169 assertEquals("Test Currency Usage 4", UnicodeString("CA$123.55"), cash_rounding_currency
);
8173 // Test the currency change
8174 // 1st time for getter/setter, 2nd time for factory method
8175 const UChar CUR_PKR
[] = {0x50, 0x4B, 0x52, 0};
8176 for(int i
=0; i
<2; i
++){
8177 status
= U_ZERO_ERROR
;
8179 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CURRENCY
, status
);
8180 if (assertSuccess("en_US@currency=CAD/CURRENCY", status
, TRUE
) == FALSE
) {
8183 fmt
->setCurrencyUsage(UCURR_USAGE_CASH
, &status
);
8185 fmt
= (DecimalFormat
*) NumberFormat::createInstance(enUS_CAD
, UNUM_CASH_CURRENCY
, status
);
8186 if (assertSuccess("en_US@currency=CAD/CASH", status
, TRUE
) == FALSE
) {
8191 UnicodeString cur_original
;
8192 fmt
->setCurrencyUsage(UCURR_USAGE_STANDARD
, &status
);
8193 fmt
->format(agent
, cur_original
);
8194 assertEquals("Test Currency Usage 5", UnicodeString("CA$123.57"), cur_original
);
8196 fmt
->setCurrency(CUR_PKR
, status
);
8197 assertSuccess("Set currency to PKR", status
);
8199 UnicodeString PKR_changed
;
8200 fmt
->format(agent
, PKR_changed
);
8201 assertEquals("Test Currency Usage 6", UnicodeString("PKR124"), PKR_changed
);
8206 void NumberFormatTest::TestNumberFormatTestTuple() {
8207 NumberFormatTestTuple tuple
;
8208 UErrorCode status
= U_ZERO_ERROR
;
8211 NumberFormatTestTuple::getFieldByName("locale"),
8215 NumberFormatTestTuple::getFieldByName("pattern"),
8219 NumberFormatTestTuple::getFieldByName("minIntegerDigits"),
8222 if (!assertSuccess("", status
)) {
8226 // only what we set should be set.
8227 assertEquals("", "en", tuple
.locale
.getName());
8228 assertEquals("", "#,##0.00", tuple
.pattern
);
8229 assertEquals("", -10, tuple
.minIntegerDigits
);
8230 assertTrue("", tuple
.localeFlag
);
8231 assertTrue("", tuple
.patternFlag
);
8232 assertTrue("", tuple
.minIntegerDigitsFlag
);
8233 assertFalse("", tuple
.formatFlag
);
8235 UnicodeString appendTo
;
8238 "{locale: en, pattern: #,##0.00, minIntegerDigits: -10}",
8239 tuple
.toString(appendTo
));
8246 tuple
.toString(appendTo
));
8248 NumberFormatTestTuple::getFieldByName("aBadFieldName"),
8251 if (status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
8252 errln("Expected U_ILLEGAL_ARGUMENT_ERROR");
8254 status
= U_ZERO_ERROR
;
8256 NumberFormatTestTuple::getFieldByName("minIntegerDigits"),
8259 if (status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
8260 errln("Expected U_ILLEGAL_ARGUMENT_ERROR");
8265 NumberFormatTest::TestDataDriven() {
8266 NumberFormatTestDataDriven dd
;
8268 dd
.run("numberformattestspecification.txt", FALSE
);
8272 // Check the constant MAX_INT64_IN_DOUBLE.
8273 // The value should convert to a double with no loss of precision.
8274 // A failure may indicate a platform with a different double format, requiring
8275 // a revision to the constant.
8277 // Note that this is actually hard to test, because the language standard gives
8278 // compilers considerable flexibility to do unexpected things with rounding and
8279 // with overflow in simple int to/from float conversions. Some compilers will completely optimize
8280 // away a simple round-trip conversion from int64_t -> double -> int64_t.
8282 void NumberFormatTest::TestDoubleLimit11439() {
8284 for (int64_t num
= MAX_INT64_IN_DOUBLE
-10; num
<=MAX_INT64_IN_DOUBLE
; num
++) {
8285 sprintf(buf
, "%lld", (long long)num
);
8287 sscanf(buf
, "%lf", &fNum
);
8288 int64_t rtNum
= fNum
;
8290 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__
, __LINE__
, (long long)num
, (long long)rtNum
);
8294 for (int64_t num
= -MAX_INT64_IN_DOUBLE
+10; num
>=-MAX_INT64_IN_DOUBLE
; num
--) {
8295 sprintf(buf
, "%lld", (long long)num
);
8297 sscanf(buf
, "%lf", &fNum
);
8298 int64_t rtNum
= fNum
;
8300 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__
, __LINE__
, (long long)num
, (long long)rtNum
);
8306 void NumberFormatTest::TestFastPathConsistent11524() {
8307 UErrorCode status
= U_ZERO_ERROR
;
8308 NumberFormat
*fmt
= NumberFormat::createInstance("en", status
);
8309 if (U_FAILURE(status
) || fmt
== NULL
) {
8310 dataerrln("Failed call to NumberFormat::createInstance() - %s", u_errorName(status
));
8313 fmt
->setMaximumIntegerDigits(INT32_MIN
);
8314 UnicodeString appendTo
;
8315 assertEquals("", "0", fmt
->format(123, appendTo
));
8317 assertEquals("", "0", fmt
->format(12345, appendTo
));
8321 void NumberFormatTest::TestGetAffixes() {
8322 UErrorCode status
= U_ZERO_ERROR
;
8323 DecimalFormatSymbols
sym("en_US", status
);
8324 UnicodeString
pattern("\\u00a4\\u00a4\\u00a4 0.00 %\\u00a4\\u00a4");
8325 pattern
= pattern
.unescape();
8326 DecimalFormat
fmt(pattern
, sym
, status
);
8327 if (U_FAILURE(status
)) {
8328 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
8331 UnicodeString affixStr
;
8332 assertEquals("", "US dollars ", fmt
.getPositivePrefix(affixStr
));
8333 assertEquals("", " %USD", fmt
.getPositiveSuffix(affixStr
));
8334 assertEquals("", "-US dollars ", fmt
.getNegativePrefix(affixStr
));
8335 assertEquals("", " %USD", fmt
.getNegativeSuffix(affixStr
));
8337 // Test equality with affixes. set affix methods can't capture special
8338 // characters which is why equality should fail.
8340 DecimalFormat
fmtCopy(fmt
);
8341 assertTrue("", fmt
== fmtCopy
);
8342 UnicodeString someAffix
;
8343 fmtCopy
.setPositivePrefix(fmtCopy
.getPositivePrefix(someAffix
));
8344 assertTrue("", fmt
!= fmtCopy
);
8347 DecimalFormat
fmtCopy(fmt
);
8348 assertTrue("", fmt
== fmtCopy
);
8349 UnicodeString someAffix
;
8350 fmtCopy
.setPositiveSuffix(fmtCopy
.getPositiveSuffix(someAffix
));
8351 assertTrue("", fmt
!= fmtCopy
);
8354 DecimalFormat
fmtCopy(fmt
);
8355 assertTrue("", fmt
== fmtCopy
);
8356 UnicodeString someAffix
;
8357 fmtCopy
.setNegativePrefix(fmtCopy
.getNegativePrefix(someAffix
));
8358 assertTrue("", fmt
!= fmtCopy
);
8361 DecimalFormat
fmtCopy(fmt
);
8362 assertTrue("", fmt
== fmtCopy
);
8363 UnicodeString someAffix
;
8364 fmtCopy
.setNegativeSuffix(fmtCopy
.getNegativeSuffix(someAffix
));
8365 assertTrue("", fmt
!= fmtCopy
);
8367 fmt
.setPositivePrefix("Don't");
8368 fmt
.setPositiveSuffix("do");
8369 UnicodeString
someAffix("be''eet\\u00a4\\u00a4\\u00a4 it.");
8370 someAffix
= someAffix
.unescape();
8371 fmt
.setNegativePrefix(someAffix
);
8372 fmt
.setNegativeSuffix("%");
8373 assertEquals("", "Don't", fmt
.getPositivePrefix(affixStr
));
8374 assertEquals("", "do", fmt
.getPositiveSuffix(affixStr
));
8375 assertEquals("", someAffix
, fmt
.getNegativePrefix(affixStr
));
8376 assertEquals("", "%", fmt
.getNegativeSuffix(affixStr
));
8379 void NumberFormatTest::TestToPatternScientific11648() {
8380 UErrorCode status
= U_ZERO_ERROR
;
8382 DecimalFormatSymbols
sym(en
, status
);
8383 DecimalFormat
fmt("0.00", sym
, status
);
8384 if (U_FAILURE(status
)) {
8385 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
8388 fmt
.setScientificNotation(TRUE
);
8389 UnicodeString pattern
;
8390 assertEquals("", "0.00E0", fmt
.toPattern(pattern
));
8391 DecimalFormat
fmt2(pattern
, sym
, status
);
8392 assertSuccess("", status
);
8395 void NumberFormatTest::TestBenchmark() {
8397 UErrorCode status = U_ZERO_ERROR;
8399 DecimalFormatSymbols sym(en, status);
8400 DecimalFormat fmt("0.0000000", new DecimalFormatSymbols(sym), status);
8401 // DecimalFormat fmt("0.00000E0", new DecimalFormatSymbols(sym), status);
8402 // DecimalFormat fmt("0", new DecimalFormatSymbols(sym), status);
8403 FieldPosition fpos(0);
8404 clock_t start = clock();
8405 for (int32_t i = 0; i < 1000000; ++i) {
8406 UnicodeString append;
8407 fmt.format(3.0, append, fpos, status);
8408 // fmt.format(4.6692016, append, fpos, status);
8409 // fmt.format(1234567.8901, append, fpos, status);
8410 // fmt.format(2.99792458E8, append, fpos, status);
8411 // fmt.format(31, append);
8413 errln("Took %f", (double) (clock() - start) / CLOCKS_PER_SEC);
8414 assertSuccess("", status);
8416 UErrorCode status = U_ZERO_ERROR;
8417 MessageFormat fmt("{0, plural, one {I have # friend.} other {I have # friends.}}", status);
8418 FieldPosition fpos(0);
8419 Formattable one(1.0);
8420 Formattable three(3.0);
8421 clock_t start = clock();
8422 for (int32_t i = 0; i < 500000; ++i) {
8423 UnicodeString append;
8424 fmt.format(&one, 1, append, fpos, status);
8425 UnicodeString append2;
8426 fmt.format(&three, 1, append2, fpos, status);
8428 errln("Took %f", (double) (clock() - start) / CLOCKS_PER_SEC);
8429 assertSuccess("", status);
8431 UErrorCode status = U_ZERO_ERROR;
8433 Measure measureC(23, MeasureUnit::createCelsius(status), status);
8434 MeasureFormat fmt(en, UMEASFMT_WIDTH_WIDE, status);
8435 FieldPosition fpos(0);
8436 clock_t start = clock();
8437 for (int32_t i = 0; i < 1000000; ++i) {
8438 UnicodeString appendTo;
8440 &measureC, 1, appendTo, fpos, status);
8442 errln("Took %f", (double) (clock() - start) / CLOCKS_PER_SEC);
8443 assertSuccess("", status);
8447 void NumberFormatTest::TestFractionalDigitsForCurrency() {
8448 UErrorCode status
= U_ZERO_ERROR
;
8449 LocalPointer
<NumberFormat
> fmt(NumberFormat::createCurrencyInstance("en", status
));
8450 if (U_FAILURE(status
)) {
8451 dataerrln("Error creating NumberFormat - %s", u_errorName(status
));
8454 UChar JPY
[] = {0x4A, 0x50, 0x59, 0x0};
8455 fmt
->setCurrency(JPY
, status
);
8456 if (!assertSuccess("", status
)) {
8459 assertEquals("", 0, fmt
->getMaximumFractionDigits());
8463 void NumberFormatTest::TestFormatCurrencyPlural() {
8464 UErrorCode status
= U_ZERO_ERROR
;
8465 Locale locale
= Locale::createCanonical("en_US");
8466 NumberFormat
*fmt
= NumberFormat::createInstance(locale
, UNUM_CURRENCY_PLURAL
, status
);
8467 if (U_FAILURE(status
)) {
8468 dataerrln("Error creating NumberFormat - %s", u_errorName(status
));
8471 UnicodeString formattedNum
;
8472 fmt
->format(11234.567, formattedNum
, NULL
, status
);
8473 assertEquals("", "11,234.57 US dollars", formattedNum
);
8477 void NumberFormatTest::TestCtorApplyPatternDifference() {
8478 UErrorCode status
= U_ZERO_ERROR
;
8479 DecimalFormatSymbols
sym("en_US", status
);
8480 UnicodeString
pattern("\\u00a40");
8481 DecimalFormat
fmt(pattern
.unescape(), sym
, status
);
8482 if (U_FAILURE(status
)) {
8483 dataerrln("Error creating DecimalFormat - %s", u_errorName(status
));
8486 UnicodeString result
;
8488 "ctor favors precision of currency",
8490 fmt
.format(5, result
));
8492 fmt
.applyPattern(pattern
.unescape(), status
);
8494 "applyPattern favors precision of pattern",
8496 fmt
.format(5, result
));
8499 void NumberFormatTest::Test11868() {
8500 double posAmt
= 34.567;
8501 double negAmt
= -9876.543;
8503 Locale
selectedLocale("en_US");
8504 UErrorCode status
= U_ZERO_ERROR
;
8506 UnicodeString result
;
8507 FieldPosition
fpCurr(UNUM_CURRENCY_FIELD
);
8508 LocalPointer
<NumberFormat
> fmt(
8509 NumberFormat::createInstance(
8510 selectedLocale
, UNUM_CURRENCY_PLURAL
, status
));
8511 if (!assertSuccess("Format creation", status
)) {
8514 fmt
->format(posAmt
, result
, fpCurr
, status
);
8515 assertEquals("", "34.57 US dollars", result
);
8516 assertEquals("begin index", 6, fpCurr
.getBeginIndex());
8517 assertEquals("end index", 16, fpCurr
.getEndIndex());
8519 // Test field position iterator
8521 NumberFormatTest_Attributes attributes
[] = {
8522 {UNUM_INTEGER_FIELD
, 0, 2},
8523 {UNUM_DECIMAL_SEPARATOR_FIELD
, 2, 3},
8524 {UNUM_FRACTION_FIELD
, 3, 5},
8525 {UNUM_CURRENCY_FIELD
, 6, 16},
8527 UnicodeString result
;
8528 FieldPositionIterator iter
;
8529 fmt
->format(posAmt
, result
, &iter
, status
);
8530 assertEquals("", "34.57 US dollars", result
);
8531 verifyFieldPositionIterator(attributes
, iter
);
8535 fmt
->format(negAmt
, result
, fpCurr
, status
);
8536 assertEquals("", "-9,876.54 US dollars", result
);
8537 assertEquals("begin index", 10, fpCurr
.getBeginIndex());
8538 assertEquals("end index", 20, fpCurr
.getEndIndex());
8540 // Test field position iterator
8542 NumberFormatTest_Attributes attributes
[] = {
8543 {UNUM_SIGN_FIELD
, 0, 1},
8544 {UNUM_GROUPING_SEPARATOR_FIELD
, 2, 3},
8545 {UNUM_INTEGER_FIELD
, 1, 6},
8546 {UNUM_DECIMAL_SEPARATOR_FIELD
, 6, 7},
8547 {UNUM_FRACTION_FIELD
, 7, 9},
8548 {UNUM_CURRENCY_FIELD
, 10, 20},
8550 UnicodeString result
;
8551 FieldPositionIterator iter
;
8552 fmt
->format(negAmt
, result
, &iter
, status
);
8553 assertEquals("", "-9,876.54 US dollars", result
);
8554 verifyFieldPositionIterator(attributes
, iter
);
8558 void NumberFormatTest::Test10727_RoundingZero() {
8561 assertFalse("", d
.isPositive());
8563 assertFalse("", d
.isPositive());
8566 void NumberFormatTest::Test11376_getAndSetPositivePrefix() {
8568 const UChar USD
[] = {0x55, 0x53, 0x44, 0x0};
8569 UErrorCode status
= U_ZERO_ERROR
;
8570 LocalPointer
<NumberFormat
> fmt(
8571 NumberFormat::createCurrencyInstance("en", status
));
8572 if (!assertSuccess("", status
)) {
8575 DecimalFormat
*dfmt
= (DecimalFormat
*) fmt
.getAlias();
8576 dfmt
->setCurrency(USD
);
8577 UnicodeString result
;
8579 // This line should be a no-op. I am setting the positive prefix
8580 // to be the same thing it was before.
8581 dfmt
->setPositivePrefix(dfmt
->getPositivePrefix(result
));
8583 UnicodeString appendTo
;
8584 assertEquals("", "$3.78", dfmt
->format(3.78, appendTo
, status
));
8585 assertSuccess("", status
);
8588 const UChar USD
[] = {0x55, 0x53, 0x44, 0x0};
8589 UErrorCode status
= U_ZERO_ERROR
;
8590 LocalPointer
<NumberFormat
> fmt(
8591 NumberFormat::createInstance("en", UNUM_CURRENCY_PLURAL
, status
));
8592 if (!assertSuccess("", status
)) {
8595 DecimalFormat
*dfmt
= (DecimalFormat
*) fmt
.getAlias();
8596 UnicodeString result
;
8597 UnicodeString
tripleIntlCurrency(" \\u00a4\\u00a4\\u00a4");
8598 tripleIntlCurrency
= tripleIntlCurrency
.unescape();
8599 assertEquals("", tripleIntlCurrency
, dfmt
->getPositiveSuffix(result
));
8600 dfmt
->setCurrency(USD
);
8602 // getPositiveSuffix() always returns the suffix for the
8603 // "other" plural category
8604 assertEquals("", " US dollars", dfmt
->getPositiveSuffix(result
));
8605 UnicodeString appendTo
;
8606 assertEquals("", "3.78 US dollars", dfmt
->format(3.78, appendTo
, status
));
8607 assertEquals("", " US dollars", dfmt
->getPositiveSuffix(result
));
8608 dfmt
->setPositiveSuffix("booya");
8610 assertEquals("", "3.78booya", dfmt
->format(3.78, appendTo
, status
));
8611 assertEquals("", "booya", dfmt
->getPositiveSuffix(result
));
8615 void NumberFormatTest::Test11475_signRecognition() {
8616 UErrorCode status
= U_ZERO_ERROR
;
8617 DecimalFormatSymbols
sym("en", status
);
8618 UnicodeString result
;
8620 DecimalFormat
fmt("+0.00", sym
, status
);
8621 if (!assertSuccess("", status
)) {
8624 NumberFormatTest_Attributes attributes
[] = {
8625 {UNUM_SIGN_FIELD
, 0, 1},
8626 {UNUM_INTEGER_FIELD
, 1, 2},
8627 {UNUM_DECIMAL_SEPARATOR_FIELD
, 2, 3},
8628 {UNUM_FRACTION_FIELD
, 3, 5},
8630 UnicodeString result
;
8631 FieldPositionIterator iter
;
8632 fmt
.format(2.3, result
, &iter
, status
);
8633 assertEquals("", "+2.30", result
);
8634 verifyFieldPositionIterator(attributes
, iter
);
8637 DecimalFormat
fmt("++0.00+;-(#)--", sym
, status
);
8638 if (!assertSuccess("", status
)) {
8642 NumberFormatTest_Attributes attributes
[] = {
8643 {UNUM_SIGN_FIELD
, 0, 2},
8644 {UNUM_INTEGER_FIELD
, 2, 3},
8645 {UNUM_DECIMAL_SEPARATOR_FIELD
, 3, 4},
8646 {UNUM_FRACTION_FIELD
, 4, 6},
8647 {UNUM_SIGN_FIELD
, 6, 7},
8649 UnicodeString result
;
8650 FieldPositionIterator iter
;
8651 fmt
.format(2.3, result
, &iter
, status
);
8652 assertEquals("", "++2.30+", result
);
8653 verifyFieldPositionIterator(attributes
, iter
);
8656 NumberFormatTest_Attributes attributes
[] = {
8657 {UNUM_SIGN_FIELD
, 0, 1},
8658 {UNUM_INTEGER_FIELD
, 2, 3},
8659 {UNUM_DECIMAL_SEPARATOR_FIELD
, 3, 4},
8660 {UNUM_FRACTION_FIELD
, 4, 6},
8661 {UNUM_SIGN_FIELD
, 7, 9},
8663 UnicodeString result
;
8664 FieldPositionIterator iter
;
8665 fmt
.format(-2.3, result
, &iter
, status
);
8666 assertEquals("", "-(2.30)--", result
);
8667 verifyFieldPositionIterator(attributes
, iter
);
8672 void NumberFormatTest::Test11640_getAffixes() {
8673 UErrorCode status
= U_ZERO_ERROR
;
8674 DecimalFormatSymbols
symbols("en_US", status
);
8675 if (!assertSuccess("", status
)) {
8678 UnicodeString
pattern("\\u00a4\\u00a4\\u00a4 0.00 %\\u00a4\\u00a4");
8679 pattern
= pattern
.unescape();
8680 DecimalFormat
fmt(pattern
, symbols
, status
);
8681 if (!assertSuccess("", status
)) {
8684 UnicodeString affixStr
;
8685 assertEquals("", "US dollars ", fmt
.getPositivePrefix(affixStr
));
8686 assertEquals("", " %USD", fmt
.getPositiveSuffix(affixStr
));
8687 assertEquals("", "-US dollars ", fmt
.getNegativePrefix(affixStr
));
8688 assertEquals("", " %USD", fmt
.getNegativeSuffix(affixStr
));
8691 void NumberFormatTest::Test11649_toPatternWithMultiCurrency() {
8692 UnicodeString
pattern("\\u00a4\\u00a4\\u00a4 0.00");
8693 pattern
= pattern
.unescape();
8694 UErrorCode status
= U_ZERO_ERROR
;
8695 DecimalFormat
fmt(pattern
, status
);
8696 if (!assertSuccess("", status
)) {
8699 static UChar USD
[] = {0x55, 0x53, 0x44, 0x0};
8700 fmt
.setCurrency(USD
);
8701 UnicodeString appendTo
;
8703 assertEquals("", "US dollars 12.34", fmt
.format(12.34, appendTo
));
8705 UnicodeString topattern
;
8706 fmt
.toPattern(topattern
);
8707 DecimalFormat
fmt2(topattern
, status
);
8708 if (!assertSuccess("", status
)) {
8711 fmt2
.setCurrency(USD
);
8714 assertEquals("", "US dollars 12.34", fmt2
.format(12.34, appendTo
));
8718 void NumberFormatTest::verifyFieldPositionIterator(
8719 NumberFormatTest_Attributes
*expected
, FieldPositionIterator
&iter
) {
8722 while (iter
.next(fp
)) {
8723 if (expected
[idx
].spos
== -1) {
8724 errln("Iterator should have ended. got %d", fp
.getField());
8727 assertEquals("id", expected
[idx
].id
, fp
.getField());
8728 assertEquals("start", expected
[idx
].spos
, fp
.getBeginIndex());
8729 assertEquals("end", expected
[idx
].epos
, fp
.getEndIndex());
8732 if (expected
[idx
].spos
!= -1) {
8733 errln("Premature end of iterator. expected %d", expected
[idx
].id
);
8737 void NumberFormatTest::checkExceptionIssue11735() {
8739 Locale
enLocale("en");
8740 DecimalFormatSymbols
symbols(enLocale
, status
);
8742 if (U_FAILURE(status
)) {
8743 errln((UnicodeString
)
8744 "Fail: Construct DecimalFormatSymbols");
8747 DecimalFormat
fmt("0", symbols
, status
);
8748 if (U_FAILURE(status
)) {
8749 errln((UnicodeString
)
8750 "Fail: Construct DecimalFormat formatter");
8753 ParsePosition
ppos(0);
8754 fmt
.parseCurrency("53.45", ppos
); // NPE thrown here in ICU4J.
8755 assertEquals("Issue11735 ppos", 0, ppos
.getIndex());
8758 #endif /* #if !UCONFIG_NO_FORMATTING */