]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/numfmtst.cpp
ICU-551.41.tar.gz
[apple/icu.git] / icuSources / test / intltest / numfmtst.cpp
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2015, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /* Modification History:
7 * Date Name Description
8 * 07/15/99 helena Ported to HPUX 10/11 CC.
9 */
10
11 #include "unicode/utypes.h"
12
13 #if !UCONFIG_NO_FORMATTING
14
15 #include "numfmtst.h"
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"
23 #include "digitlst.h"
24 #include "textfile.h"
25 #include "tokiter.h"
26 #include "charstr.h"
27 #include "putilimp.h"
28 #include "winnmtst.h"
29 #include <float.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include "cstring.h"
33 #include "unicode/numsys.h"
34 #include "fmtableimp.h"
35
36 //#define NUMFMTST_CACHE_DEBUG 1
37 #include "stdio.h" /* for sprintf */
38 // #include "iostream" // for cout
39
40 //#define NUMFMTST_DEBUG 1
41
42 static const UChar EUR[] = {69,85,82,0}; // "EUR"
43 static const UChar ISO_CURRENCY_USD[] = {0x55, 0x53, 0x44, 0}; // "USD"
44
45
46 // *****************************************************************************
47 // class NumberFormatTest
48 // *****************************************************************************
49
50 #define CHECK(status,str) if (U_FAILURE(status)) { errcheckln(status, UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
51 #define CHECK_DATA(status,str) if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: ") + str + " - " + u_errorName(status)); return; }
52
53 void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
54 {
55 TESTCASE_AUTO_BEGIN;
56 TESTCASE_AUTO(TestCurrencySign);
57 TESTCASE_AUTO(TestCurrency);
58 TESTCASE_AUTO(TestParse);
59 TESTCASE_AUTO(TestRounding487);
60 TESTCASE_AUTO(TestQuotes);
61 TESTCASE_AUTO(TestExponential);
62 TESTCASE_AUTO(TestPatterns);
63
64 // Upgrade to alphaWorks - liu 5/99
65 TESTCASE_AUTO(TestExponent);
66 TESTCASE_AUTO(TestScientific);
67 TESTCASE_AUTO(TestPad);
68 TESTCASE_AUTO(TestPatterns2);
69 TESTCASE_AUTO(TestSecondaryGrouping);
70 TESTCASE_AUTO(TestSurrogateSupport);
71 TESTCASE_AUTO(TestAPI);
72
73 TESTCASE_AUTO(TestCurrencyObject);
74 TESTCASE_AUTO(TestCurrencyPatterns);
75 //TESTCASE_AUTO(TestDigitList);
76 TESTCASE_AUTO(TestWhiteSpaceParsing);
77 TESTCASE_AUTO(TestComplexCurrency); // This test removed because CLDR no longer uses choice formats in currency symbols.
78 TESTCASE_AUTO(TestRegCurrency);
79 TESTCASE_AUTO(TestSymbolsWithBadLocale);
80 TESTCASE_AUTO(TestAdoptDecimalFormatSymbols);
81
82 TESTCASE_AUTO(TestScientific2);
83 TESTCASE_AUTO(TestScientificGrouping);
84 TESTCASE_AUTO(TestInt64);
85
86 TESTCASE_AUTO(TestPerMill);
87 TESTCASE_AUTO(TestIllegalPatterns);
88 TESTCASE_AUTO(TestCases);
89
90 TESTCASE_AUTO(TestCurrencyNames);
91 TESTCASE_AUTO(TestCurrencyAmount);
92 TESTCASE_AUTO(TestCurrencyUnit);
93 TESTCASE_AUTO(TestCoverage);
94 TESTCASE_AUTO(TestJB3832);
95 TESTCASE_AUTO(TestHost);
96 TESTCASE_AUTO(TestHostClone);
97 TESTCASE_AUTO(TestCurrencyFormat);
98 TESTCASE_AUTO(TestRounding);
99 TESTCASE_AUTO(TestNonpositiveMultiplier);
100 TESTCASE_AUTO(TestNumberingSystems);
101 TESTCASE_AUTO(TestSpaceParsing);
102 TESTCASE_AUTO(TestMultiCurrencySign);
103 TESTCASE_AUTO(TestCurrencyFormatForMixParsing);
104 TESTCASE_AUTO(TestDecimalFormatCurrencyParse);
105 TESTCASE_AUTO(TestCurrencyIsoPluralFormat);
106 TESTCASE_AUTO(TestCurrencyParsing);
107 TESTCASE_AUTO(TestParseCurrencyInUCurr);
108 TESTCASE_AUTO(TestFormatAttributes);
109 TESTCASE_AUTO(TestFieldPositionIterator);
110 TESTCASE_AUTO(TestDecimal);
111 TESTCASE_AUTO(TestCurrencyFractionDigits);
112 TESTCASE_AUTO(TestExponentParse);
113 TESTCASE_AUTO(TestExplicitParents);
114 TESTCASE_AUTO(TestLenientParse);
115 TESTCASE_AUTO(TestAvailableNumberingSystems);
116 TESTCASE_AUTO(TestRoundingPattern);
117 TESTCASE_AUTO(Test9087);
118 TESTCASE_AUTO(TestFormatFastpaths);
119 TESTCASE_AUTO(TestFormattableSize);
120 TESTCASE_AUTO(TestUFormattable);
121 TESTCASE_AUTO(TestSignificantDigits);
122 TESTCASE_AUTO(TestShowZero);
123 TESTCASE_AUTO(TestCompatibleCurrencies);
124 TESTCASE_AUTO(TestBug9936);
125 TESTCASE_AUTO(TestParseNegativeWithFaLocale);
126 TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign);
127 TESTCASE_AUTO(TestCustomCurrencySignAndSeparator);
128 TESTCASE_AUTO(TestParseSignsAndMarks);
129 TESTCASE_AUTO(Test10419RoundingWith0FractionDigits);
130 TESTCASE_AUTO(Test10468ApplyPattern);
131 TESTCASE_AUTO(TestRoundingScientific10542);
132 TESTCASE_AUTO(TestZeroScientific10547);
133 TESTCASE_AUTO(TestAccountingCurrency);
134 TESTCASE_AUTO(TestEquality);
135 TESTCASE_AUTO(TestCurrencyUsage);
136 TESTCASE_AUTO(TestDoubleLimit11439);
137 TESTCASE_AUTO(TestFastPathConsistent11524);
138 TESTCASE_AUTO_END;
139 }
140
141 // -------------------------------------
142
143 // Test API (increase code coverage)
144 void
145 NumberFormatTest::TestAPI(void)
146 {
147 logln("Test API");
148 UErrorCode status = U_ZERO_ERROR;
149 NumberFormat *test = NumberFormat::createInstance("root", status);
150 if(U_FAILURE(status)) {
151 dataerrln("unable to create format object - %s", u_errorName(status));
152 }
153 if(test != NULL) {
154 test->setMinimumIntegerDigits(10);
155 test->setMaximumIntegerDigits(2);
156
157 test->setMinimumFractionDigits(10);
158 test->setMaximumFractionDigits(2);
159
160 UnicodeString result;
161 FieldPosition pos;
162 Formattable bla("Paja Patak"); // Donald Duck for non Serbian speakers
163 test->format(bla, result, pos, status);
164 if(U_SUCCESS(status)) {
165 errln("Yuck... Formatted a duck... As a number!");
166 } else {
167 status = U_ZERO_ERROR;
168 }
169
170 result.remove();
171 int64_t ll = 12;
172 test->format(ll, result);
173 if (result != "12.00"){
174 errln("format int64_t error");
175 }
176
177 ParsePosition ppos;
178 LocalPointer<CurrencyAmount> currAmt(test->parseCurrency("",ppos));
179 // old test for (U_FAILURE(status)) was bogus here, method does not set status!
180 if (ppos.getIndex()) {
181 errln("Parsed empty string as currency");
182 }
183
184 delete test;
185 }
186 }
187
188 class StubNumberFormat :public NumberFormat{
189 public:
190 StubNumberFormat(){};
191 virtual UnicodeString& format(double ,UnicodeString& appendTo,FieldPosition& ) const {
192 return appendTo;
193 }
194 virtual UnicodeString& format(int32_t ,UnicodeString& appendTo,FieldPosition& ) const {
195 return appendTo.append((UChar)0x0033);
196 }
197 virtual UnicodeString& format(int64_t number,UnicodeString& appendTo,FieldPosition& pos) const {
198 return NumberFormat::format(number, appendTo, pos);
199 }
200 virtual UnicodeString& format(const Formattable& , UnicodeString& appendTo, FieldPosition& , UErrorCode& ) const {
201 return appendTo;
202 }
203 virtual void parse(const UnicodeString& ,
204 Formattable& ,
205 ParsePosition& ) const {}
206 virtual void parse( const UnicodeString& ,
207 Formattable& ,
208 UErrorCode& ) const {}
209 virtual UClassID getDynamicClassID(void) const {
210 static char classID = 0;
211 return (UClassID)&classID;
212 }
213 virtual Format* clone() const {return NULL;}
214 };
215
216 void
217 NumberFormatTest::TestCoverage(void){
218 StubNumberFormat stub;
219 UnicodeString agent("agent");
220 FieldPosition pos;
221 int64_t num = 4;
222 if (stub.format(num, agent, pos) != UnicodeString("agent3")){
223 errln("NumberFormat::format(int64, UnicodString&, FieldPosition&) should delegate to (int32, ,)");
224 };
225 }
226
227 // Test various patterns
228 void
229 NumberFormatTest::TestPatterns(void)
230 {
231 UErrorCode status = U_ZERO_ERROR;
232 DecimalFormatSymbols sym(Locale::getUS(), status);
233 if (U_FAILURE(status)) { errcheckln(status, "FAIL: Could not construct DecimalFormatSymbols - %s", u_errorName(status)); return; }
234
235 const char* pat[] = { "#.#", "#.", ".#", "#" };
236 int32_t pat_length = (int32_t)(sizeof(pat) / sizeof(pat[0]));
237 const char* newpat[] = { "#0.#", "#0.", "#.0", "#" };
238 const char* num[] = { "0", "0.", ".0", "0" };
239 for (int32_t i=0; i<pat_length; ++i)
240 {
241 status = U_ZERO_ERROR;
242 DecimalFormat fmt(pat[i], sym, status);
243 if (U_FAILURE(status)) { errln((UnicodeString)"FAIL: DecimalFormat constructor failed for " + pat[i]); continue; }
244 UnicodeString newp; fmt.toPattern(newp);
245 if (!(newp == newpat[i]))
246 errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should transmute to " + newpat[i] +
247 "; " + newp + " seen instead");
248
249 UnicodeString s; (*(NumberFormat*)&fmt).format((int32_t)0, s);
250 if (!(s == num[i]))
251 {
252 errln((UnicodeString)"FAIL: Pattern " + pat[i] + " should format zero as " + num[i] +
253 "; " + s + " seen instead");
254 logln((UnicodeString)"Min integer digits = " + fmt.getMinimumIntegerDigits());
255 }
256 }
257 }
258
259 /*
260 icu_2_4::DigitList::operator== 0 0 2 icuuc24d.dll digitlst.cpp Doug
261 icu_2_4::DigitList::append 0 0 4 icuin24d.dll digitlst.h Doug
262 icu_2_4::DigitList::operator!= 0 0 1 icuuc24d.dll digitlst.h Doug
263 */
264 /*
265 void
266 NumberFormatTest::TestDigitList(void)
267 {
268 // API coverage for DigitList
269 DigitList list1;
270 list1.append('1');
271 list1.fDecimalAt = 1;
272 DigitList list2;
273 list2.set((int32_t)1);
274 if (list1 != list2) {
275 errln("digitlist append, operator!= or set failed ");
276 }
277 if (!(list1 == list2)) {
278 errln("digitlist append, operator== or set failed ");
279 }
280 }
281 */
282
283 // -------------------------------------
284
285 // Test exponential pattern
286 void
287 NumberFormatTest::TestExponential(void)
288 {
289 UErrorCode status = U_ZERO_ERROR;
290 DecimalFormatSymbols sym(Locale::getUS(), status);
291 if (U_FAILURE(status)) { errcheckln(status, "FAIL: Bad status returned by DecimalFormatSymbols ct - %s", u_errorName(status)); return; }
292 const char* pat[] = { "0.####E0", "00.000E00", "##0.######E000", "0.###E0;[0.###E0]" };
293 int32_t pat_length = (int32_t)(sizeof(pat) / sizeof(pat[0]));
294
295 // The following #if statements allow this test to be built and run on
296 // platforms that do not have standard IEEE numerics. For example,
297 // S/390 doubles have an exponent range of -78 to +75. For the
298 // following #if statements to work, float.h must define
299 // DBL_MAX_10_EXP to be a compile-time constant.
300
301 // This section may be expanded as needed.
302
303 #if DBL_MAX_10_EXP > 300
304 double val[] = { 0.01234, 123456789, 1.23e300, -3.141592653e-271 };
305 int32_t val_length = (int32_t)(sizeof(val) / sizeof(val[0]));
306 const char* valFormat[] =
307 {
308 // 0.####E0
309 "1.234E-2", "1.2346E8", "1.23E300", "-3.1416E-271",
310 // 00.000E00
311 "12.340E-03", "12.346E07", "12.300E299", "-31.416E-272",
312 // ##0.######E000
313 "12.34E-003", "123.4568E006", "1.23E300", "-314.1593E-273",
314 // 0.###E0;[0.###E0]
315 "1.234E-2", "1.235E8", "1.23E300", "[3.142E-271]"
316 };
317 double valParse[] =
318 {
319 0.01234, 123460000, 1.23E300, -3.1416E-271,
320 0.01234, 123460000, 1.23E300, -3.1416E-271,
321 0.01234, 123456800, 1.23E300, -3.141593E-271,
322 0.01234, 123500000, 1.23E300, -3.142E-271,
323 };
324 #elif DBL_MAX_10_EXP > 70
325 double val[] = { 0.01234, 123456789, 1.23e70, -3.141592653e-71 };
326 int32_t val_length = sizeof(val) / sizeof(val[0]);
327 char* valFormat[] =
328 {
329 // 0.####E0
330 "1.234E-2", "1.2346E8", "1.23E70", "-3.1416E-71",
331 // 00.000E00
332 "12.340E-03", "12.346E07", "12.300E69", "-31.416E-72",
333 // ##0.######E000
334 "12.34E-003", "123.4568E006", "12.3E069", "-31.41593E-072",
335 // 0.###E0;[0.###E0]
336 "1.234E-2", "1.235E8", "1.23E70", "[3.142E-71]"
337 };
338 double valParse[] =
339 {
340 0.01234, 123460000, 1.23E70, -3.1416E-71,
341 0.01234, 123460000, 1.23E70, -3.1416E-71,
342 0.01234, 123456800, 1.23E70, -3.141593E-71,
343 0.01234, 123500000, 1.23E70, -3.142E-71,
344 };
345 #else
346 // Don't test double conversion
347 double* val = 0;
348 int32_t val_length = 0;
349 char** valFormat = 0;
350 double* valParse = 0;
351 logln("Warning: Skipping double conversion tests");
352 #endif
353
354 int32_t lval[] = { 0, -1, 1, 123456789 };
355 int32_t lval_length = (int32_t)(sizeof(lval) / sizeof(lval[0]));
356 const char* lvalFormat[] =
357 {
358 // 0.####E0
359 "0E0", "-1E0", "1E0", "1.2346E8",
360 // 00.000E00
361 "00.000E00", "-10.000E-01", "10.000E-01", "12.346E07",
362 // ##0.######E000
363 "0E000", "-1E000", "1E000", "123.4568E006",
364 // 0.###E0;[0.###E0]
365 "0E0", "[1E0]", "1E0", "1.235E8"
366 };
367 int32_t lvalParse[] =
368 {
369 0, -1, 1, 123460000,
370 0, -1, 1, 123460000,
371 0, -1, 1, 123456800,
372 0, -1, 1, 123500000,
373 };
374 int32_t ival = 0, ilval = 0;
375 for (int32_t p=0; p<pat_length; ++p)
376 {
377 DecimalFormat fmt(pat[p], sym, status);
378 if (U_FAILURE(status)) { errln("FAIL: Bad status returned by DecimalFormat ct"); continue; }
379 UnicodeString pattern;
380 logln((UnicodeString)"Pattern \"" + pat[p] + "\" -toPattern-> \"" +
381 fmt.toPattern(pattern) + "\"");
382 int32_t v;
383 for (v=0; v<val_length; ++v)
384 {
385 UnicodeString s; (*(NumberFormat*)&fmt).format(val[v], s);
386 logln((UnicodeString)" " + val[v] + " -format-> " + s);
387 if (s != valFormat[v+ival])
388 errln((UnicodeString)"FAIL: Expected " + valFormat[v+ival]);
389
390 ParsePosition pos(0);
391 Formattable af;
392 fmt.parse(s, af, pos);
393 double a;
394 UBool useEpsilon = FALSE;
395 if (af.getType() == Formattable::kLong)
396 a = af.getLong();
397 else if (af.getType() == Formattable::kDouble) {
398 a = af.getDouble();
399 #if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
400 // S/390 will show a failure like this:
401 //| -3.141592652999999e-271 -format-> -3.1416E-271
402 //| -parse-> -3.1416e-271
403 //| FAIL: Expected -3.141599999999999e-271
404 // To compensate, we use an epsilon-based equality
405 // test on S/390 only. We don't want to do this in
406 // general because it's less exacting.
407 useEpsilon = TRUE;
408 #endif
409 }
410 else {
411 errln((UnicodeString)"FAIL: Non-numeric Formattable returned");
412 continue;
413 }
414 if (pos.getIndex() == s.length())
415 {
416 logln((UnicodeString)" -parse-> " + a);
417 // Use epsilon comparison as necessary
418 if ((useEpsilon &&
419 (uprv_fabs(a - valParse[v+ival]) / a > (2*DBL_EPSILON))) ||
420 (!useEpsilon && a != valParse[v+ival]))
421 {
422 errln((UnicodeString)"FAIL: Expected " + valParse[v+ival]);
423 }
424 }
425 else {
426 errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);
427 errln((UnicodeString)" should be (" + s.length() + " chars) -> " + valParse[v+ival]);
428 }
429 }
430 for (v=0; v<lval_length; ++v)
431 {
432 UnicodeString s;
433 (*(NumberFormat*)&fmt).format(lval[v], s);
434 logln((UnicodeString)" " + lval[v] + "L -format-> " + s);
435 if (s != lvalFormat[v+ilval])
436 errln((UnicodeString)"ERROR: Expected " + lvalFormat[v+ilval] + " Got: " + s);
437
438 ParsePosition pos(0);
439 Formattable af;
440 fmt.parse(s, af, pos);
441 if (af.getType() == Formattable::kLong ||
442 af.getType() == Formattable::kInt64) {
443 UErrorCode status = U_ZERO_ERROR;
444 int32_t a = af.getLong(status);
445 if (pos.getIndex() == s.length())
446 {
447 logln((UnicodeString)" -parse-> " + a);
448 if (a != lvalParse[v+ilval])
449 errln((UnicodeString)"FAIL: Expected " + lvalParse[v+ilval]);
450 }
451 else
452 errln((UnicodeString)"FAIL: Partial parse (" + pos.getIndex() + " chars) -> " + a);
453 }
454 else
455 errln((UnicodeString)"FAIL: Non-long Formattable returned for " + s
456 + " Double: " + af.getDouble()
457 + ", Long: " + af.getLong());
458 }
459 ival += val_length;
460 ilval += lval_length;
461 }
462 }
463
464 void
465 NumberFormatTest::TestScientific2() {
466 // jb 2552
467 UErrorCode status = U_ZERO_ERROR;
468 DecimalFormat* fmt = (DecimalFormat*)NumberFormat::createCurrencyInstance("en_US", status);
469 if (U_SUCCESS(status)) {
470 double num = 12.34;
471 expect(*fmt, num, "$12.34");
472 fmt->setScientificNotation(TRUE);
473 expect(*fmt, num, "$1.23E1");
474 fmt->setScientificNotation(FALSE);
475 expect(*fmt, num, "$12.34");
476 }
477 delete fmt;
478 }
479
480 void
481 NumberFormatTest::TestScientificGrouping() {
482 // jb 2552
483 UErrorCode status = U_ZERO_ERROR;
484 DecimalFormat fmt("##0.00E0",status);
485 if (U_SUCCESS(status)) {
486 expect(fmt, .01234, "12.3E-3");
487 expect(fmt, .1234, "123E-3");
488 expect(fmt, 1.234, "1.23E0");
489 expect(fmt, 12.34, "12.3E0");
490 expect(fmt, 123.4, "123E0");
491 expect(fmt, 1234., "1.23E3");
492 }
493 }
494
495 /*static void setFromString(DigitList& dl, const char* str) {
496 char c;
497 UBool decimalSet = FALSE;
498 dl.clear();
499 while ((c = *str++)) {
500 if (c == '-') {
501 dl.fIsPositive = FALSE;
502 } else if (c == '+') {
503 dl.fIsPositive = TRUE;
504 } else if (c == '.') {
505 dl.fDecimalAt = dl.fCount;
506 decimalSet = TRUE;
507 } else {
508 dl.append(c);
509 }
510 }
511 if (!decimalSet) {
512 dl.fDecimalAt = dl.fCount;
513 }
514 }*/
515
516 void
517 NumberFormatTest::TestInt64() {
518 UErrorCode status = U_ZERO_ERROR;
519 DecimalFormat fmt("#.#E0",status);
520 fmt.setMaximumFractionDigits(20);
521 if (U_SUCCESS(status)) {
522 expect(fmt, (Formattable)(int64_t)0, "0E0");
523 expect(fmt, (Formattable)(int64_t)-1, "-1E0");
524 expect(fmt, (Formattable)(int64_t)1, "1E0");
525 expect(fmt, (Formattable)(int64_t)2147483647, "2.147483647E9");
526 expect(fmt, (Formattable)((int64_t)-2147483647-1), "-2.147483648E9");
527 expect(fmt, (Formattable)(int64_t)U_INT64_MAX, "9.223372036854775807E18");
528 expect(fmt, (Formattable)(int64_t)U_INT64_MIN, "-9.223372036854775808E18");
529 }
530
531 // also test digitlist
532 /* int64_t int64max = U_INT64_MAX;
533 int64_t int64min = U_INT64_MIN;
534 const char* int64maxstr = "9223372036854775807";
535 const char* int64minstr = "-9223372036854775808";
536 UnicodeString fail("fail: ");
537
538 // test max int64 value
539 DigitList dl;
540 setFromString(dl, int64maxstr);
541 {
542 if (!dl.fitsIntoInt64(FALSE)) {
543 errln(fail + int64maxstr + " didn't fit");
544 }
545 int64_t int64Value = dl.getInt64();
546 if (int64Value != int64max) {
547 errln(fail + int64maxstr);
548 }
549 dl.set(int64Value);
550 int64Value = dl.getInt64();
551 if (int64Value != int64max) {
552 errln(fail + int64maxstr);
553 }
554 }
555 // test negative of max int64 value (1 shy of min int64 value)
556 dl.fIsPositive = FALSE;
557 {
558 if (!dl.fitsIntoInt64(FALSE)) {
559 errln(fail + "-" + int64maxstr + " didn't fit");
560 }
561 int64_t int64Value = dl.getInt64();
562 if (int64Value != -int64max) {
563 errln(fail + "-" + int64maxstr);
564 }
565 dl.set(int64Value);
566 int64Value = dl.getInt64();
567 if (int64Value != -int64max) {
568 errln(fail + "-" + int64maxstr);
569 }
570 }
571 // test min int64 value
572 setFromString(dl, int64minstr);
573 {
574 if (!dl.fitsIntoInt64(FALSE)) {
575 errln(fail + "-" + int64minstr + " didn't fit");
576 }
577 int64_t int64Value = dl.getInt64();
578 if (int64Value != int64min) {
579 errln(fail + int64minstr);
580 }
581 dl.set(int64Value);
582 int64Value = dl.getInt64();
583 if (int64Value != int64min) {
584 errln(fail + int64minstr);
585 }
586 }
587 // test negative of min int 64 value (1 more than max int64 value)
588 dl.fIsPositive = TRUE; // won't fit
589 {
590 if (dl.fitsIntoInt64(FALSE)) {
591 errln(fail + "-(" + int64minstr + ") didn't fit");
592 }
593 }*/
594 }
595
596 // -------------------------------------
597
598 // Test the handling of quotes
599 void
600 NumberFormatTest::TestQuotes(void)
601 {
602 UErrorCode status = U_ZERO_ERROR;
603 UnicodeString *pat;
604 DecimalFormatSymbols *sym = new DecimalFormatSymbols(Locale::getUS(), status);
605 if (U_FAILURE(status)) {
606 errcheckln(status, "Fail to create DecimalFormatSymbols - %s", u_errorName(status));
607 delete sym;
608 return;
609 }
610 pat = new UnicodeString("a'fo''o'b#");
611 DecimalFormat *fmt = new DecimalFormat(*pat, *sym, status);
612 UnicodeString s;
613 ((NumberFormat*)fmt)->format((int32_t)123, s);
614 logln((UnicodeString)"Pattern \"" + *pat + "\"");
615 logln((UnicodeString)" Format 123 -> " + escape(s));
616 if (!(s=="afo'ob123"))
617 errln((UnicodeString)"FAIL: Expected afo'ob123");
618
619 s.truncate(0);
620 delete fmt;
621 delete pat;
622
623 pat = new UnicodeString("a''b#");
624 fmt = new DecimalFormat(*pat, *sym, status);
625 ((NumberFormat*)fmt)->format((int32_t)123, s);
626 logln((UnicodeString)"Pattern \"" + *pat + "\"");
627 logln((UnicodeString)" Format 123 -> " + escape(s));
628 if (!(s=="a'b123"))
629 errln((UnicodeString)"FAIL: Expected a'b123");
630 delete fmt;
631 delete pat;
632 delete sym;
633 }
634
635 /**
636 * Test the handling of the currency symbol in patterns.
637 */
638 void
639 NumberFormatTest::TestCurrencySign(void)
640 {
641 UErrorCode status = U_ZERO_ERROR;
642 DecimalFormatSymbols* sym = new DecimalFormatSymbols(Locale::getUS(), status);
643 UnicodeString pat;
644 UChar currency = 0x00A4;
645 if (U_FAILURE(status)) {
646 errcheckln(status, "Fail to create DecimalFormatSymbols - %s", u_errorName(status));
647 delete sym;
648 return;
649 }
650 // "\xA4#,##0.00;-\xA4#,##0.00"
651 pat.append(currency).append("#,##0.00;-").
652 append(currency).append("#,##0.00");
653 DecimalFormat *fmt = new DecimalFormat(pat, *sym, status);
654 UnicodeString s; ((NumberFormat*)fmt)->format(1234.56, s);
655 pat.truncate(0);
656 logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
657 logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
658 if (s != "$1,234.56") dataerrln((UnicodeString)"FAIL: Expected $1,234.56");
659 s.truncate(0);
660 ((NumberFormat*)fmt)->format(- 1234.56, s);
661 logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
662 if (s != "-$1,234.56") dataerrln((UnicodeString)"FAIL: Expected -$1,234.56");
663 delete fmt;
664 pat.truncate(0);
665 // "\xA4\xA4 #,##0.00;\xA4\xA4 -#,##0.00"
666 pat.append(currency).append(currency).
667 append(" #,##0.00;").
668 append(currency).append(currency).
669 append(" -#,##0.00");
670 fmt = new DecimalFormat(pat, *sym, status);
671 s.truncate(0);
672 ((NumberFormat*)fmt)->format(1234.56, s);
673 logln((UnicodeString)"Pattern \"" + fmt->toPattern(pat) + "\"");
674 logln((UnicodeString)" Format " + 1234.56 + " -> " + escape(s));
675 if (s != "USD 1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD 1,234.56");
676 s.truncate(0);
677 ((NumberFormat*)fmt)->format(-1234.56, s);
678 logln((UnicodeString)" Format " + (-1234.56) + " -> " + escape(s));
679 if (s != "USD -1,234.56") dataerrln((UnicodeString)"FAIL: Expected USD -1,234.56");
680 delete fmt;
681 delete sym;
682 if (U_FAILURE(status)) errln((UnicodeString)"FAIL: Status " + u_errorName(status));
683 }
684
685 // -------------------------------------
686
687 static UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10))); }
688
689 UnicodeString&
690 NumberFormatTest::escape(UnicodeString& s)
691 {
692 UnicodeString buf;
693 for (int32_t i=0; i<s.length(); ++i)
694 {
695 UChar c = s[(int32_t)i];
696 if (c <= (UChar)0x7F) buf += c;
697 else {
698 buf += (UChar)0x5c; buf += (UChar)0x55;
699 buf += toHexString((c & 0xF000) >> 12);
700 buf += toHexString((c & 0x0F00) >> 8);
701 buf += toHexString((c & 0x00F0) >> 4);
702 buf += toHexString(c & 0x000F);
703 }
704 }
705 return (s = buf);
706 }
707
708
709 // -------------------------------------
710 static const char* testCases[][2]= {
711 /* locale ID */ /* expected */
712 {"ca_ES_PREEURO", "\\u20A7\\u00A01.150" },
713 {"de_LU_PREEURO", "1,150\\u00A0F" },
714 {"el_GR_PREEURO", "1.150,50\\u00A0\\u0394\\u03C1\\u03C7" },
715 {"en_BE_PREEURO", "1.150,50\\u00A0BEF" },
716 {"es_ES_PREEURO", "1.150\\u00A0\\u20A7" },
717 {"eu_ES_PREEURO", "\\u20A7\\u00A01.150" },
718 {"gl_ES_PREEURO", "1.150\\u00A0\\u20A7" },
719 {"it_IT_PREEURO", "ITL\\u00A01.150" },
720 {"pt_PT_PREEURO", "1,150$50\\u00A0\\u200B"}, // per cldrbug 7670
721 {"en_US@currency=JPY", "\\u00A51,150"},
722 {"en_US@currency=jpy", "\\u00A51,150"},
723 {"en-US-u-cu-jpy", "\\u00A51,150"}
724 };
725 /**
726 * Test localized currency patterns.
727 */
728 void
729 NumberFormatTest::TestCurrency(void)
730 {
731 UErrorCode status = U_ZERO_ERROR;
732 NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(Locale::getCanadaFrench(), status);
733 if (U_FAILURE(status)) {
734 dataerrln("Error calling NumberFormat::createCurrencyInstance()");
735 return;
736 }
737
738 UnicodeString s; currencyFmt->format(1.50, s);
739 logln((UnicodeString)"Un pauvre ici a..........." + s);
740 if (!(s==CharsToUnicodeString("1,50\\u00A0$")))
741 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>$");
742 delete currencyFmt;
743 s.truncate(0);
744 char loc[256]={0};
745 int len = uloc_canonicalize("de_DE_PREEURO", loc, 256, &status);
746 (void)len; // Suppress unused variable warning.
747 currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc),status);
748 currencyFmt->format(1.50, s);
749 logln((UnicodeString)"Un pauvre en Allemagne a.." + s);
750 if (!(s==CharsToUnicodeString("1,50\\u00A0DM")))
751 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>DM");
752 delete currencyFmt;
753 s.truncate(0);
754 len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status);
755 currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status);
756 currencyFmt->format(1.50, s);
757 logln((UnicodeString)"Un pauvre en France a....." + s);
758 if (!(s==CharsToUnicodeString("1,50\\u00A0F")))
759 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>F");
760 delete currencyFmt;
761 if (U_FAILURE(status))
762 errln((UnicodeString)"FAIL: Status " + (int32_t)status);
763
764 for(int i=0; i < (int)(sizeof(testCases)/sizeof(testCases[i])); i++){
765 status = U_ZERO_ERROR;
766 const char *localeID = testCases[i][0];
767 UnicodeString expected(testCases[i][1], -1, US_INV);
768 expected = expected.unescape();
769 s.truncate(0);
770 char loc[256]={0};
771 uloc_canonicalize(localeID, loc, 256, &status);
772 currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status);
773 if(U_FAILURE(status)){
774 errln("Could not create currency formatter for locale %s",localeID);
775 continue;
776 }
777 currencyFmt->format(1150.50, s);
778 if(s!=expected){
779 errln(UnicodeString("FAIL: Expected: ")+expected
780 + UnicodeString(" Got: ") + s
781 + UnicodeString( " for locale: ")+ UnicodeString(localeID) );
782 }
783 if (U_FAILURE(status)){
784 errln((UnicodeString)"FAIL: Status " + (int32_t)status);
785 }
786 delete currencyFmt;
787 }
788 }
789
790 // -------------------------------------
791
792 /**
793 * Test the Currency object handling, new as of ICU 2.2.
794 */
795 void NumberFormatTest::TestCurrencyObject() {
796 UErrorCode ec = U_ZERO_ERROR;
797 NumberFormat* fmt =
798 NumberFormat::createCurrencyInstance(Locale::getUS(), ec);
799
800 if (U_FAILURE(ec)) {
801 dataerrln("FAIL: getCurrencyInstance(US) - %s", u_errorName(ec));
802 delete fmt;
803 return;
804 }
805
806 Locale null("", "", "");
807
808 expectCurrency(*fmt, null, 1234.56, "$1,234.56");
809
810 expectCurrency(*fmt, Locale::getFrance(),
811 1234.56, CharsToUnicodeString("\\u20AC1,234.56")); // Euro
812
813 expectCurrency(*fmt, Locale::getJapan(),
814 1234.56, CharsToUnicodeString("\\u00A51,235")); // Yen
815
816 expectCurrency(*fmt, Locale("fr", "CH", ""),
817 1234.56, "CHF1,234.56"); // no more 0.05 rounding here, see cldrbug 5548
818
819 expectCurrency(*fmt, Locale::getUS(),
820 1234.56, "$1,234.56");
821
822 delete fmt;
823 fmt = NumberFormat::createCurrencyInstance(Locale::getFrance(), ec);
824
825 if (U_FAILURE(ec)) {
826 errln("FAIL: getCurrencyInstance(FRANCE)");
827 delete fmt;
828 return;
829 }
830
831 expectCurrency(*fmt, null, 1234.56, CharsToUnicodeString("1 234,56 \\u20AC"));
832
833 expectCurrency(*fmt, Locale::getJapan(),
834 1234.56, CharsToUnicodeString("1 235 JPY")); // Yen
835
836 expectCurrency(*fmt, Locale("fr", "CH", ""),
837 1234.56, "1 234,56 CHF"); // no more 0.05 rounding here, see cldrbug 5548
838
839 expectCurrency(*fmt, Locale::getUS(),
840 1234.56, "1 234,56 $US");
841
842 expectCurrency(*fmt, Locale::getFrance(),
843 1234.56, CharsToUnicodeString("1 234,56 \\u20AC")); // Euro
844
845 delete fmt;
846 }
847
848 // -------------------------------------
849
850 /**
851 * Do rudimentary testing of parsing.
852 */
853 void
854 NumberFormatTest::TestParse(void)
855 {
856 UErrorCode status = U_ZERO_ERROR;
857 UnicodeString arg("0");
858 DecimalFormat* format = new DecimalFormat("00", status);
859 //try {
860 Formattable n; format->parse(arg, n, status);
861 logln((UnicodeString)"parse(" + arg + ") = " + n.getLong());
862 if (n.getType() != Formattable::kLong ||
863 n.getLong() != 0) errln((UnicodeString)"FAIL: Expected 0");
864 delete format;
865 if (U_FAILURE(status)) errcheckln(status, (UnicodeString)"FAIL: Status " + u_errorName(status));
866 //}
867 //catch(Exception e) {
868 // errln((UnicodeString)"Exception caught: " + e);
869 //}
870 }
871
872 // -------------------------------------
873
874 static const char *lenientAffixTestCases[] = {
875 "(1)",
876 "( 1)",
877 "(1 )",
878 "( 1 )"
879 };
880
881 static const char *lenientMinusTestCases[] = {
882 "-5",
883 "\\u22125",
884 "\\u20105"
885 };
886
887 static const char *lenientCurrencyTestCases[] = {
888 "$1,000",
889 "$ 1,000",
890 "$1000",
891 "$ 1000",
892 "$1 000.00",
893 "$ 1 000.00",
894 "$ 1\\u00A0000.00",
895 "1000.00"
896 };
897
898 // changed from () to - per cldrbug 5674
899 static const char *lenientNegativeCurrencyTestCases[] = {
900 "-$1,000",
901 "-$ 1,000",
902 "-$1000",
903 "-$ 1000",
904 "-$1 000.00",
905 "-$ 1 000.00",
906 "- $ 1,000.00 ",
907 "-$ 1\\u00A0000.00",
908 "-1000.00"
909 };
910
911 static const char *lenientPercentTestCases[] = {
912 "25%",
913 " 25%",
914 " 25 %",
915 "25 %",
916 "25\\u00A0%",
917 "25"
918 };
919
920 static const char *lenientNegativePercentTestCases[] = {
921 "-25%",
922 " -25%",
923 " - 25%",
924 "- 25 %",
925 " - 25 %",
926 "-25 %",
927 "-25\\u00A0%",
928 "-25",
929 "- 25"
930 };
931
932 static const char *strictFailureTestCases[] = {
933 " 1000",
934 "10,00",
935 "1,000,.0"
936 };
937
938 #define ARRAY_SIZE(array) ((int32_t) (sizeof (array) / sizeof(array[0])))
939
940 /**
941 * Test lenient parsing.
942 */
943 void
944 NumberFormatTest::TestLenientParse(void)
945 {
946 UErrorCode status = U_ZERO_ERROR;
947 DecimalFormat *format = new DecimalFormat("(#,##0)", status);
948 Formattable n;
949
950 if (format == NULL || U_FAILURE(status)) {
951 dataerrln("Unable to create DecimalFormat (#,##0) - %s", u_errorName(status));
952 } else {
953 format->setLenient(TRUE);
954 for (int32_t t = 0; t < ARRAY_SIZE (lenientAffixTestCases); t += 1) {
955 UnicodeString testCase = ctou(lenientAffixTestCases[t]);
956
957 format->parse(testCase, n, status);
958 logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
959
960 if (U_FAILURE(status) || n.getType() != Formattable::kLong ||
961 n.getLong() != 1) {
962 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientAffixTestCases[t] + (UnicodeString) "\"");
963 status = U_ZERO_ERROR;
964 }
965 }
966 delete format;
967 }
968
969 Locale en_US("en_US");
970 Locale sv_SE("sv_SE");
971
972 NumberFormat *mFormat = NumberFormat::createInstance(sv_SE, UNUM_DECIMAL, status);
973
974 if (mFormat == NULL || U_FAILURE(status)) {
975 dataerrln("Unable to create NumberFormat (sv_SE, UNUM_DECIMAL) - %s", u_errorName(status));
976 } else {
977 mFormat->setLenient(TRUE);
978 for (int32_t t = 0; t < ARRAY_SIZE(lenientMinusTestCases); t += 1) {
979 UnicodeString testCase = ctou(lenientMinusTestCases[t]);
980
981 mFormat->parse(testCase, n, status);
982 logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
983
984 if (U_FAILURE(status) || n.getType() != Formattable::kLong || n.getLong() != -5) {
985 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientMinusTestCases[t] + (UnicodeString) "\"");
986 status = U_ZERO_ERROR;
987 }
988 }
989 delete mFormat;
990 }
991
992 mFormat = NumberFormat::createInstance(en_US, UNUM_DECIMAL, status);
993
994 if (mFormat == NULL || U_FAILURE(status)) {
995 dataerrln("Unable to create NumberFormat (en_US, UNUM_DECIMAL) - %s", u_errorName(status));
996 } else {
997 mFormat->setLenient(TRUE);
998 for (int32_t t = 0; t < ARRAY_SIZE(lenientMinusTestCases); t += 1) {
999 UnicodeString testCase = ctou(lenientMinusTestCases[t]);
1000
1001 mFormat->parse(testCase, n, status);
1002 logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1003
1004 if (U_FAILURE(status) || n.getType() != Formattable::kLong || n.getLong() != -5) {
1005 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientMinusTestCases[t] + (UnicodeString) "\"");
1006 status = U_ZERO_ERROR;
1007 }
1008 }
1009 delete mFormat;
1010 }
1011
1012 NumberFormat *cFormat = NumberFormat::createInstance(en_US, UNUM_CURRENCY, status);
1013
1014 if (cFormat == NULL || U_FAILURE(status)) {
1015 dataerrln("Unable to create NumberFormat (en_US, UNUM_CURRENCY) - %s", u_errorName(status));
1016 } else {
1017 cFormat->setLenient(TRUE);
1018 for (int32_t t = 0; t < ARRAY_SIZE (lenientCurrencyTestCases); t += 1) {
1019 UnicodeString testCase = ctou(lenientCurrencyTestCases[t]);
1020
1021 cFormat->parse(testCase, n, status);
1022 logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1023
1024 if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
1025 n.getLong() != 1000) {
1026 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientCurrencyTestCases[t] + (UnicodeString) "\"");
1027 status = U_ZERO_ERROR;
1028 }
1029 }
1030
1031 for (int32_t t = 0; t < ARRAY_SIZE (lenientNegativeCurrencyTestCases); t += 1) {
1032 UnicodeString testCase = ctou(lenientNegativeCurrencyTestCases[t]);
1033
1034 cFormat->parse(testCase, n, status);
1035 logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1036
1037 if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
1038 n.getLong() != -1000) {
1039 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientNegativeCurrencyTestCases[t] + (UnicodeString) "\"");
1040 status = U_ZERO_ERROR;
1041 }
1042 }
1043
1044 delete cFormat;
1045 }
1046
1047 NumberFormat *pFormat = NumberFormat::createPercentInstance(en_US, status);
1048
1049 if (pFormat == NULL || U_FAILURE(status)) {
1050 dataerrln("Unable to create NumberFormat::createPercentInstance (en_US) - %s", u_errorName(status));
1051 } else {
1052 pFormat->setLenient(TRUE);
1053 for (int32_t t = 0; t < ARRAY_SIZE (lenientPercentTestCases); t += 1) {
1054 UnicodeString testCase = ctou(lenientPercentTestCases[t]);
1055
1056 pFormat->parse(testCase, n, status);
1057 logln((UnicodeString)"parse(" + testCase + ") = " + n.getDouble());
1058
1059 if (U_FAILURE(status) ||n.getType() != Formattable::kDouble ||
1060 n.getDouble() != 0.25) {
1061 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientPercentTestCases[t] + (UnicodeString) "\"");
1062 status = U_ZERO_ERROR;
1063 }
1064 }
1065
1066 for (int32_t t = 0; t < ARRAY_SIZE (lenientNegativePercentTestCases); t += 1) {
1067 UnicodeString testCase = ctou(lenientNegativePercentTestCases[t]);
1068
1069 pFormat->parse(testCase, n, status);
1070 logln((UnicodeString)"parse(" + testCase + ") = " + n.getDouble());
1071
1072 if (U_FAILURE(status) ||n.getType() != Formattable::kDouble ||
1073 n.getDouble() != -0.25) {
1074 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) lenientNegativePercentTestCases[t] + (UnicodeString) "\"");
1075 status = U_ZERO_ERROR;
1076 }
1077 }
1078
1079 delete pFormat;
1080 }
1081
1082 // Test cases that should fail with a strict parse and pass with a
1083 // lenient parse.
1084 NumberFormat *nFormat = NumberFormat::createInstance(en_US, status);
1085
1086 if (nFormat == NULL || U_FAILURE(status)) {
1087 dataerrln("Unable to create NumberFormat (en_US) - %s", u_errorName(status));
1088 } else {
1089 // first, make sure that they fail with a strict parse
1090 for (int32_t t = 0; t < ARRAY_SIZE(strictFailureTestCases); t += 1) {
1091 UnicodeString testCase = ctou(strictFailureTestCases[t]);
1092
1093 nFormat->parse(testCase, n, status);
1094 logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1095
1096 if (! U_FAILURE(status)) {
1097 errln((UnicodeString)"Strict Parse succeeded for \"" + (UnicodeString) strictFailureTestCases[t] + (UnicodeString) "\"");
1098 }
1099
1100 status = U_ZERO_ERROR;
1101 }
1102
1103 // then, make sure that they pass with a lenient parse
1104 nFormat->setLenient(TRUE);
1105 for (int32_t t = 0; t < ARRAY_SIZE(strictFailureTestCases); t += 1) {
1106 UnicodeString testCase = ctou(strictFailureTestCases[t]);
1107
1108 nFormat->parse(testCase, n, status);
1109 logln((UnicodeString)"parse(" + testCase + ") = " + n.getLong());
1110
1111 if (U_FAILURE(status) ||n.getType() != Formattable::kLong ||
1112 n.getLong() != 1000) {
1113 errln((UnicodeString)"Lenient parse failed for \"" + (UnicodeString) strictFailureTestCases[t] + (UnicodeString) "\"");
1114 status = U_ZERO_ERROR;
1115 }
1116 }
1117
1118 delete nFormat;
1119 }
1120 }
1121
1122 // -------------------------------------
1123
1124 /**
1125 * Test proper rounding by the format method.
1126 */
1127 void
1128 NumberFormatTest::TestRounding487(void)
1129 {
1130 UErrorCode status = U_ZERO_ERROR;
1131 NumberFormat *nf = NumberFormat::createInstance(status);
1132 if (U_FAILURE(status)) {
1133 dataerrln("Error calling NumberFormat::createInstance()");
1134 return;
1135 }
1136
1137 roundingTest(*nf, 0.00159999, 4, "0.0016");
1138 roundingTest(*nf, 0.00995, 4, "0.01");
1139
1140 roundingTest(*nf, 12.3995, 3, "12.4");
1141
1142 roundingTest(*nf, 12.4999, 0, "12");
1143 roundingTest(*nf, - 19.5, 0, "-20");
1144 delete nf;
1145 if (U_FAILURE(status)) errln((UnicodeString)"FAIL: Status " + (int32_t)status);
1146 }
1147
1148 /**
1149 * Test the functioning of the secondary grouping value.
1150 */
1151 void NumberFormatTest::TestSecondaryGrouping(void) {
1152 UErrorCode status = U_ZERO_ERROR;
1153 DecimalFormatSymbols US(Locale::getUS(), status);
1154 CHECK(status, "DecimalFormatSymbols ct");
1155
1156 DecimalFormat f("#,##,###", US, status);
1157 CHECK(status, "DecimalFormat ct");
1158
1159 expect2(f, (int32_t)123456789L, "12,34,56,789");
1160 expectPat(f, "#,##,###");
1161 f.applyPattern("#,###", status);
1162 CHECK(status, "applyPattern");
1163
1164 f.setSecondaryGroupingSize(4);
1165 expect2(f, (int32_t)123456789L, "12,3456,789");
1166 expectPat(f, "#,####,###");
1167 NumberFormat *g = NumberFormat::createInstance(Locale("hi", "IN"), status);
1168 CHECK_DATA(status, "createInstance(hi_IN)");
1169
1170 UnicodeString out;
1171 int32_t l = (int32_t)1876543210L;
1172 g->format(l, out);
1173 delete g;
1174 // expect "1,87,65,43,210", but with Hindi digits
1175 // 01234567890123
1176 UBool ok = TRUE;
1177 if (out.length() != 14) {
1178 ok = FALSE;
1179 } else {
1180 for (int32_t i=0; i<out.length(); ++i) {
1181 UBool expectGroup = FALSE;
1182 switch (i) {
1183 case 1:
1184 case 4:
1185 case 7:
1186 case 10:
1187 expectGroup = TRUE;
1188 break;
1189 }
1190 // Later -- fix this to get the actual grouping
1191 // character from the resource bundle.
1192 UBool isGroup = (out.charAt(i) == 0x002C);
1193 if (isGroup != expectGroup) {
1194 ok = FALSE;
1195 break;
1196 }
1197 }
1198 }
1199 if (!ok) {
1200 errln((UnicodeString)"FAIL Expected " + l +
1201 " x hi_IN -> \"1,87,65,43,210\" (with Hindi digits), got \"" +
1202 escape(out) + "\"");
1203 } else {
1204 logln((UnicodeString)"Ok " + l +
1205 " x hi_IN -> \"" +
1206 escape(out) + "\"");
1207 }
1208 }
1209
1210 void NumberFormatTest::TestWhiteSpaceParsing(void) {
1211 UErrorCode ec = U_ZERO_ERROR;
1212 DecimalFormatSymbols US(Locale::getUS(), ec);
1213 DecimalFormat fmt("a b#0c ", US, ec);
1214 if (U_FAILURE(ec)) {
1215 errcheckln(ec, "FAIL: Constructor - %s", u_errorName(ec));
1216 return;
1217 }
1218 int32_t n = 1234;
1219 expect(fmt, "a b1234c ", n);
1220 expect(fmt, "a b1234c ", n);
1221 }
1222
1223 /**
1224 * Test currencies whose display name is a ChoiceFormat.
1225 */
1226 void NumberFormatTest::TestComplexCurrency() {
1227
1228 // UErrorCode ec = U_ZERO_ERROR;
1229 // Locale loc("kn", "IN", "");
1230 // NumberFormat* fmt = NumberFormat::createCurrencyInstance(loc, ec);
1231 // if (U_SUCCESS(ec)) {
1232 // expect2(*fmt, 1.0, CharsToUnicodeString("Re.\\u00A01.00"));
1233 // Use .00392625 because that's 2^-8. Any value less than 0.005 is fine.
1234 // expect(*fmt, 1.00390625, CharsToUnicodeString("Re.\\u00A01.00")); // tricky
1235 // expect2(*fmt, 12345678.0, CharsToUnicodeString("Rs.\\u00A01,23,45,678.00"));
1236 // expect2(*fmt, 0.5, CharsToUnicodeString("Rs.\\u00A00.50"));
1237 // expect2(*fmt, -1.0, CharsToUnicodeString("-Re.\\u00A01.00"));
1238 // expect2(*fmt, -10.0, CharsToUnicodeString("-Rs.\\u00A010.00"));
1239 // } else {
1240 // errln("FAIL: getCurrencyInstance(kn_IN)");
1241 // }
1242 // delete fmt;
1243
1244 }
1245
1246 // -------------------------------------
1247
1248 void
1249 NumberFormatTest::roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected)
1250 {
1251 nf.setMaximumFractionDigits(maxFractionDigits);
1252 UnicodeString out; nf.format(x, out);
1253 logln((UnicodeString)"" + x + " formats with " + maxFractionDigits + " fractional digits to " + out);
1254 if (!(out==expected)) errln((UnicodeString)"FAIL: Expected " + expected);
1255 }
1256
1257 /**
1258 * Upgrade to alphaWorks
1259 */
1260 void NumberFormatTest::TestExponent(void) {
1261 UErrorCode status = U_ZERO_ERROR;
1262 DecimalFormatSymbols US(Locale::getUS(), status);
1263 CHECK(status, "DecimalFormatSymbols constructor");
1264 DecimalFormat fmt1(UnicodeString("0.###E0"), US, status);
1265 CHECK(status, "DecimalFormat(0.###E0)");
1266 DecimalFormat fmt2(UnicodeString("0.###E+0"), US, status);
1267 CHECK(status, "DecimalFormat(0.###E+0)");
1268 int32_t n = 1234;
1269 expect2(fmt1, n, "1.234E3");
1270 expect2(fmt2, n, "1.234E+3");
1271 expect(fmt1, "1.234E+3", n); // Either format should parse "E+3"
1272 }
1273
1274 /**
1275 * Upgrade to alphaWorks
1276 */
1277 void NumberFormatTest::TestScientific(void) {
1278 UErrorCode status = U_ZERO_ERROR;
1279 DecimalFormatSymbols US(Locale::getUS(), status);
1280 CHECK(status, "DecimalFormatSymbols constructor");
1281
1282 // Test pattern round-trip
1283 const char* PAT[] = { "#E0", "0.####E0", "00.000E00", "##0.####E000",
1284 "0.###E0;[0.###E0]" };
1285 int32_t PAT_length = (int32_t)(sizeof(PAT) / sizeof(PAT[0]));
1286 int32_t DIGITS[] = {
1287 // min int, max int, min frac, max frac
1288 0, 1, 0, 0, // "#E0"
1289 1, 1, 0, 4, // "0.####E0"
1290 2, 2, 3, 3, // "00.000E00"
1291 1, 3, 0, 4, // "##0.####E000"
1292 1, 1, 0, 3, // "0.###E0;[0.###E0]"
1293 };
1294 for (int32_t i=0; i<PAT_length; ++i) {
1295 UnicodeString pat(PAT[i]);
1296 DecimalFormat df(pat, US, status);
1297 CHECK(status, "DecimalFormat constructor");
1298 UnicodeString pat2;
1299 df.toPattern(pat2);
1300 if (pat == pat2) {
1301 logln(UnicodeString("Ok Pattern rt \"") +
1302 pat + "\" -> \"" +
1303 pat2 + "\"");
1304 } else {
1305 errln(UnicodeString("FAIL Pattern rt \"") +
1306 pat + "\" -> \"" +
1307 pat2 + "\"");
1308 }
1309 // Make sure digit counts match what we expect
1310 if (df.getMinimumIntegerDigits() != DIGITS[4*i] ||
1311 df.getMaximumIntegerDigits() != DIGITS[4*i+1] ||
1312 df.getMinimumFractionDigits() != DIGITS[4*i+2] ||
1313 df.getMaximumFractionDigits() != DIGITS[4*i+3]) {
1314 errln(UnicodeString("FAIL \"" + pat +
1315 "\" min/max int; min/max frac = ") +
1316 df.getMinimumIntegerDigits() + "/" +
1317 df.getMaximumIntegerDigits() + ";" +
1318 df.getMinimumFractionDigits() + "/" +
1319 df.getMaximumFractionDigits() + ", expect " +
1320 DIGITS[4*i] + "/" +
1321 DIGITS[4*i+1] + ";" +
1322 DIGITS[4*i+2] + "/" +
1323 DIGITS[4*i+3]);
1324 }
1325 }
1326
1327
1328 // Test the constructor for default locale. We have to
1329 // manually set the default locale, as there is no
1330 // guarantee that the default locale has the same
1331 // scientific format.
1332 Locale def = Locale::getDefault();
1333 Locale::setDefault(Locale::getUS(), status);
1334 expect2(NumberFormat::createScientificInstance(status),
1335 12345.678901,
1336 "1.2345678901E4", status);
1337 Locale::setDefault(def, status);
1338
1339 expect2(new DecimalFormat("#E0", US, status),
1340 12345.0,
1341 "1.2345E4", status);
1342 expect(new DecimalFormat("0E0", US, status),
1343 12345.0,
1344 "1E4", status);
1345 expect2(NumberFormat::createScientificInstance(Locale::getUS(), status),
1346 12345.678901,
1347 "1.2345678901E4", status);
1348 expect(new DecimalFormat("##0.###E0", US, status),
1349 12345.0,
1350 "12.34E3", status);
1351 expect(new DecimalFormat("##0.###E0", US, status),
1352 12345.00001,
1353 "12.35E3", status);
1354 expect2(new DecimalFormat("##0.####E0", US, status),
1355 (int32_t) 12345,
1356 "12.345E3", status);
1357 expect2(NumberFormat::createScientificInstance(Locale::getFrance(), status),
1358 12345.678901,
1359 "1,2345678901E4", status);
1360 expect(new DecimalFormat("##0.####E0", US, status),
1361 789.12345e-9,
1362 "789.12E-9", status);
1363 expect2(new DecimalFormat("##0.####E0", US, status),
1364 780.e-9,
1365 "780E-9", status);
1366 expect(new DecimalFormat(".###E0", US, status),
1367 45678.0,
1368 ".457E5", status);
1369 expect2(new DecimalFormat(".###E0", US, status),
1370 (int32_t) 0,
1371 ".0E0", status);
1372 /*
1373 expect(new DecimalFormat[] { new DecimalFormat("#E0", US),
1374 new DecimalFormat("##E0", US),
1375 new DecimalFormat("####E0", US),
1376 new DecimalFormat("0E0", US),
1377 new DecimalFormat("00E0", US),
1378 new DecimalFormat("000E0", US),
1379 },
1380 new Long(45678000),
1381 new String[] { "4.5678E7",
1382 "45.678E6",
1383 "4567.8E4",
1384 "5E7",
1385 "46E6",
1386 "457E5",
1387 }
1388 );
1389 !
1390 ! Unroll this test into individual tests below...
1391 !
1392 */
1393 expect2(new DecimalFormat("#E0", US, status),
1394 (int32_t) 45678000, "4.5678E7", status);
1395 expect2(new DecimalFormat("##E0", US, status),
1396 (int32_t) 45678000, "45.678E6", status);
1397 expect2(new DecimalFormat("####E0", US, status),
1398 (int32_t) 45678000, "4567.8E4", status);
1399 expect(new DecimalFormat("0E0", US, status),
1400 (int32_t) 45678000, "5E7", status);
1401 expect(new DecimalFormat("00E0", US, status),
1402 (int32_t) 45678000, "46E6", status);
1403 expect(new DecimalFormat("000E0", US, status),
1404 (int32_t) 45678000, "457E5", status);
1405 /*
1406 expect(new DecimalFormat("###E0", US, status),
1407 new Object[] { new Double(0.0000123), "12.3E-6",
1408 new Double(0.000123), "123E-6",
1409 new Double(0.00123), "1.23E-3",
1410 new Double(0.0123), "12.3E-3",
1411 new Double(0.123), "123E-3",
1412 new Double(1.23), "1.23E0",
1413 new Double(12.3), "12.3E0",
1414 new Double(123), "123E0",
1415 new Double(1230), "1.23E3",
1416 });
1417 !
1418 ! Unroll this test into individual tests below...
1419 !
1420 */
1421 expect2(new DecimalFormat("###E0", US, status),
1422 0.0000123, "12.3E-6", status);
1423 expect2(new DecimalFormat("###E0", US, status),
1424 0.000123, "123E-6", status);
1425 expect2(new DecimalFormat("###E0", US, status),
1426 0.00123, "1.23E-3", status);
1427 expect2(new DecimalFormat("###E0", US, status),
1428 0.0123, "12.3E-3", status);
1429 expect2(new DecimalFormat("###E0", US, status),
1430 0.123, "123E-3", status);
1431 expect2(new DecimalFormat("###E0", US, status),
1432 1.23, "1.23E0", status);
1433 expect2(new DecimalFormat("###E0", US, status),
1434 12.3, "12.3E0", status);
1435 expect2(new DecimalFormat("###E0", US, status),
1436 123.0, "123E0", status);
1437 expect2(new DecimalFormat("###E0", US, status),
1438 1230.0, "1.23E3", status);
1439 /*
1440 expect(new DecimalFormat("0.#E+00", US, status),
1441 new Object[] { new Double(0.00012), "1.2E-04",
1442 new Long(12000), "1.2E+04",
1443 });
1444 !
1445 ! Unroll this test into individual tests below...
1446 !
1447 */
1448 expect2(new DecimalFormat("0.#E+00", US, status),
1449 0.00012, "1.2E-04", status);
1450 expect2(new DecimalFormat("0.#E+00", US, status),
1451 (int32_t) 12000, "1.2E+04", status);
1452 }
1453
1454 /**
1455 * Upgrade to alphaWorks
1456 */
1457 void NumberFormatTest::TestPad(void) {
1458 UErrorCode status = U_ZERO_ERROR;
1459 DecimalFormatSymbols US(Locale::getUS(), status);
1460 CHECK(status, "DecimalFormatSymbols constructor");
1461
1462 expect2(new DecimalFormat("*^##.##", US, status),
1463 int32_t(0), "^^^^0", status);
1464 expect2(new DecimalFormat("*^##.##", US, status),
1465 -1.3, "^-1.3", status);
1466 expect2(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US, status),
1467 int32_t(0), "0.0E0______ g-m/s^2", status);
1468 expect(new DecimalFormat("##0.0####E0*_ 'g-m/s^2'", US, status),
1469 1.0/3, "333.333E-3_ g-m/s^2", status);
1470 expect2(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US, status),
1471 int32_t(0), "0.0______ g-m/s^2", status);
1472 expect(new DecimalFormat("##0.0####*_ 'g-m/s^2'", US, status),
1473 1.0/3, "0.33333__ g-m/s^2", status);
1474
1475 // Test padding before a sign
1476 const char *formatStr = "*x#,###,###,##0.0#;*x(###,###,##0.0#)";
1477 expect2(new DecimalFormat(formatStr, US, status),
1478 int32_t(-10), "xxxxxxxxxx(10.0)", status);
1479 expect2(new DecimalFormat(formatStr, US, status),
1480 int32_t(-1000),"xxxxxxx(1,000.0)", status);
1481 expect2(new DecimalFormat(formatStr, US, status),
1482 int32_t(-1000000),"xxx(1,000,000.0)", status);
1483 expect2(new DecimalFormat(formatStr, US, status),
1484 -100.37, "xxxxxxxx(100.37)", status);
1485 expect2(new DecimalFormat(formatStr, US, status),
1486 -10456.37, "xxxxx(10,456.37)", status);
1487 expect2(new DecimalFormat(formatStr, US, status),
1488 -1120456.37, "xx(1,120,456.37)", status);
1489 expect2(new DecimalFormat(formatStr, US, status),
1490 -112045600.37, "(112,045,600.37)", status);
1491 expect2(new DecimalFormat(formatStr, US, status),
1492 -1252045600.37,"(1,252,045,600.37)", status);
1493
1494 expect2(new DecimalFormat(formatStr, US, status),
1495 int32_t(10), "xxxxxxxxxxxx10.0", status);
1496 expect2(new DecimalFormat(formatStr, US, status),
1497 int32_t(1000),"xxxxxxxxx1,000.0", status);
1498 expect2(new DecimalFormat(formatStr, US, status),
1499 int32_t(1000000),"xxxxx1,000,000.0", status);
1500 expect2(new DecimalFormat(formatStr, US, status),
1501 100.37, "xxxxxxxxxx100.37", status);
1502 expect2(new DecimalFormat(formatStr, US, status),
1503 10456.37, "xxxxxxx10,456.37", status);
1504 expect2(new DecimalFormat(formatStr, US, status),
1505 1120456.37, "xxxx1,120,456.37", status);
1506 expect2(new DecimalFormat(formatStr, US, status),
1507 112045600.37, "xx112,045,600.37", status);
1508 expect2(new DecimalFormat(formatStr, US, status),
1509 10252045600.37,"10,252,045,600.37", status);
1510
1511
1512 // Test padding between a sign and a number
1513 const char *formatStr2 = "#,###,###,##0.0#*x;(###,###,##0.0#*x)";
1514 expect2(new DecimalFormat(formatStr2, US, status),
1515 int32_t(-10), "(10.0xxxxxxxxxx)", status);
1516 expect2(new DecimalFormat(formatStr2, US, status),
1517 int32_t(-1000),"(1,000.0xxxxxxx)", status);
1518 expect2(new DecimalFormat(formatStr2, US, status),
1519 int32_t(-1000000),"(1,000,000.0xxx)", status);
1520 expect2(new DecimalFormat(formatStr2, US, status),
1521 -100.37, "(100.37xxxxxxxx)", status);
1522 expect2(new DecimalFormat(formatStr2, US, status),
1523 -10456.37, "(10,456.37xxxxx)", status);
1524 expect2(new DecimalFormat(formatStr2, US, status),
1525 -1120456.37, "(1,120,456.37xx)", status);
1526 expect2(new DecimalFormat(formatStr2, US, status),
1527 -112045600.37, "(112,045,600.37)", status);
1528 expect2(new DecimalFormat(formatStr2, US, status),
1529 -1252045600.37,"(1,252,045,600.37)", status);
1530
1531 expect2(new DecimalFormat(formatStr2, US, status),
1532 int32_t(10), "10.0xxxxxxxxxxxx", status);
1533 expect2(new DecimalFormat(formatStr2, US, status),
1534 int32_t(1000),"1,000.0xxxxxxxxx", status);
1535 expect2(new DecimalFormat(formatStr2, US, status),
1536 int32_t(1000000),"1,000,000.0xxxxx", status);
1537 expect2(new DecimalFormat(formatStr2, US, status),
1538 100.37, "100.37xxxxxxxxxx", status);
1539 expect2(new DecimalFormat(formatStr2, US, status),
1540 10456.37, "10,456.37xxxxxxx", status);
1541 expect2(new DecimalFormat(formatStr2, US, status),
1542 1120456.37, "1,120,456.37xxxx", status);
1543 expect2(new DecimalFormat(formatStr2, US, status),
1544 112045600.37, "112,045,600.37xx", status);
1545 expect2(new DecimalFormat(formatStr2, US, status),
1546 10252045600.37,"10,252,045,600.37", status);
1547
1548 //testing the setPadCharacter(UnicodeString) and getPadCharacterString()
1549 DecimalFormat fmt("#", US, status);
1550 CHECK(status, "DecimalFormat constructor");
1551 UnicodeString padString("P");
1552 fmt.setPadCharacter(padString);
1553 expectPad(fmt, "*P##.##", DecimalFormat::kPadBeforePrefix, 5, padString);
1554 fmt.setPadCharacter((UnicodeString)"^");
1555 expectPad(fmt, "*^#", DecimalFormat::kPadBeforePrefix, 1, (UnicodeString)"^");
1556 //commented untill implementation is complete
1557 /* fmt.setPadCharacter((UnicodeString)"^^^");
1558 expectPad(fmt, "*^^^#", DecimalFormat::kPadBeforePrefix, 3, (UnicodeString)"^^^");
1559 padString.remove();
1560 padString.append((UChar)0x0061);
1561 padString.append((UChar)0x0302);
1562 fmt.setPadCharacter(padString);
1563 UChar patternChars[]={0x002a, 0x0061, 0x0302, 0x0061, 0x0302, 0x0023, 0x0000};
1564 UnicodeString pattern(patternChars);
1565 expectPad(fmt, pattern , DecimalFormat::kPadBeforePrefix, 4, padString);
1566 */
1567
1568 }
1569
1570 /**
1571 * Upgrade to alphaWorks
1572 */
1573 void NumberFormatTest::TestPatterns2(void) {
1574 UErrorCode status = U_ZERO_ERROR;
1575 DecimalFormatSymbols US(Locale::getUS(), status);
1576 CHECK(status, "DecimalFormatSymbols constructor");
1577
1578 DecimalFormat fmt("#", US, status);
1579 CHECK(status, "DecimalFormat constructor");
1580
1581 UChar hat = 0x005E; /*^*/
1582
1583 expectPad(fmt, "*^#", DecimalFormat::kPadBeforePrefix, 1, hat);
1584 expectPad(fmt, "$*^#", DecimalFormat::kPadAfterPrefix, 2, hat);
1585 expectPad(fmt, "#*^", DecimalFormat::kPadBeforeSuffix, 1, hat);
1586 expectPad(fmt, "#$*^", DecimalFormat::kPadAfterSuffix, 2, hat);
1587 expectPad(fmt, "$*^$#", ILLEGAL);
1588 expectPad(fmt, "#$*^$", ILLEGAL);
1589 expectPad(fmt, "'pre'#,##0*x'post'", DecimalFormat::kPadBeforeSuffix,
1590 12, (UChar)0x0078 /*x*/);
1591 expectPad(fmt, "''#0*x", DecimalFormat::kPadBeforeSuffix,
1592 3, (UChar)0x0078 /*x*/);
1593 expectPad(fmt, "'I''ll'*a###.##", DecimalFormat::kPadAfterPrefix,
1594 10, (UChar)0x0061 /*a*/);
1595
1596 fmt.applyPattern("AA#,##0.00ZZ", status);
1597 CHECK(status, "applyPattern");
1598 fmt.setPadCharacter(hat);
1599
1600 fmt.setFormatWidth(10);
1601
1602 fmt.setPadPosition(DecimalFormat::kPadBeforePrefix);
1603 expectPat(fmt, "*^AA#,##0.00ZZ");
1604
1605 fmt.setPadPosition(DecimalFormat::kPadBeforeSuffix);
1606 expectPat(fmt, "AA#,##0.00*^ZZ");
1607
1608 fmt.setPadPosition(DecimalFormat::kPadAfterSuffix);
1609 expectPat(fmt, "AA#,##0.00ZZ*^");
1610
1611 // 12 3456789012
1612 UnicodeString exp("AA*^#,##0.00ZZ", "");
1613 fmt.setFormatWidth(12);
1614 fmt.setPadPosition(DecimalFormat::kPadAfterPrefix);
1615 expectPat(fmt, exp);
1616
1617 fmt.setFormatWidth(13);
1618 // 12 34567890123
1619 expectPat(fmt, "AA*^##,##0.00ZZ");
1620
1621 fmt.setFormatWidth(14);
1622 // 12 345678901234
1623 expectPat(fmt, "AA*^###,##0.00ZZ");
1624
1625 fmt.setFormatWidth(15);
1626 // 12 3456789012345
1627 expectPat(fmt, "AA*^####,##0.00ZZ"); // This is the interesting case
1628
1629 fmt.setFormatWidth(16);
1630 // 12 34567890123456
1631 expectPat(fmt, "AA*^#,###,##0.00ZZ");
1632 }
1633
1634 void NumberFormatTest::TestSurrogateSupport(void) {
1635 UErrorCode status = U_ZERO_ERROR;
1636 DecimalFormatSymbols custom(Locale::getUS(), status);
1637 CHECK(status, "DecimalFormatSymbols constructor");
1638
1639 custom.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, "decimal");
1640 custom.setSymbol(DecimalFormatSymbols::kPlusSignSymbol, "plus");
1641 custom.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, " minus ");
1642 custom.setSymbol(DecimalFormatSymbols::kExponentialSymbol, "exponent");
1643
1644 UnicodeString patternStr("*\\U00010000##.##", "");
1645 patternStr = patternStr.unescape();
1646 UnicodeString expStr("\\U00010000\\U00010000\\U00010000\\U000100000", "");
1647 expStr = expStr.unescape();
1648 expect2(new DecimalFormat(patternStr, custom, status),
1649 int32_t(0), expStr, status);
1650
1651 status = U_ZERO_ERROR;
1652 expect2(new DecimalFormat("*^##.##", custom, status),
1653 int32_t(0), "^^^^0", status);
1654 status = U_ZERO_ERROR;
1655 expect2(new DecimalFormat("##.##", custom, status),
1656 -1.3, " minus 1decimal3", status);
1657 status = U_ZERO_ERROR;
1658 expect2(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom, status),
1659 int32_t(0), "0decimal0exponent0 g-m/s^2", status);
1660 status = U_ZERO_ERROR;
1661 expect(new DecimalFormat("##0.0####E0 'g-m/s^2'", custom, status),
1662 1.0/3, "333decimal333exponent minus 3 g-m/s^2", status);
1663 status = U_ZERO_ERROR;
1664 expect2(new DecimalFormat("##0.0#### 'g-m/s^2'", custom, status),
1665 int32_t(0), "0decimal0 g-m/s^2", status);
1666 status = U_ZERO_ERROR;
1667 expect(new DecimalFormat("##0.0#### 'g-m/s^2'", custom, status),
1668 1.0/3, "0decimal33333 g-m/s^2", status);
1669
1670 UnicodeString zero((UChar32)0x10000);
1671 UnicodeString one((UChar32)0x10001);
1672 UnicodeString two((UChar32)0x10002);
1673 UnicodeString five((UChar32)0x10005);
1674 custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, zero);
1675 custom.setSymbol(DecimalFormatSymbols::kOneDigitSymbol, one);
1676 custom.setSymbol(DecimalFormatSymbols::kTwoDigitSymbol, two);
1677 custom.setSymbol(DecimalFormatSymbols::kFiveDigitSymbol, five);
1678 expStr = UnicodeString("\\U00010001decimal\\U00010002\\U00010005\\U00010000", "");
1679 expStr = expStr.unescape();
1680 status = U_ZERO_ERROR;
1681 expect2(new DecimalFormat("##0.000", custom, status),
1682 1.25, expStr, status);
1683
1684 custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, (UChar)0x30);
1685 custom.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "units of money");
1686 custom.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, "money separator");
1687 patternStr = UNICODE_STRING_SIMPLE("0.00 \\u00A4' in your bank account'");
1688 patternStr = patternStr.unescape();
1689 expStr = UnicodeString(" minus 20money separator00 units of money in your bank account", "");
1690 status = U_ZERO_ERROR;
1691 expect2(new DecimalFormat(patternStr, custom, status),
1692 int32_t(-20), expStr, status);
1693
1694 custom.setSymbol(DecimalFormatSymbols::kPercentSymbol, "percent");
1695 patternStr = "'You''ve lost ' -0.00 %' of your money today'";
1696 patternStr = patternStr.unescape();
1697 expStr = UnicodeString(" minus You've lost minus 2000decimal00 percent of your money today", "");
1698 status = U_ZERO_ERROR;
1699 expect2(new DecimalFormat(patternStr, custom, status),
1700 int32_t(-20), expStr, status);
1701 }
1702
1703 void NumberFormatTest::TestCurrencyPatterns(void) {
1704 int32_t i, locCount;
1705 const Locale* locs = NumberFormat::getAvailableLocales(locCount);
1706 for (i=0; i<locCount; ++i) {
1707 UErrorCode ec = U_ZERO_ERROR;
1708 NumberFormat* nf = NumberFormat::createCurrencyInstance(locs[i], ec);
1709 if (U_FAILURE(ec)) {
1710 errln("FAIL: Can't create NumberFormat(%s) - %s", locs[i].getName(), u_errorName(ec));
1711 } else {
1712 // Make sure currency formats do not have a variable number
1713 // of fraction digits
1714 int32_t min = nf->getMinimumFractionDigits();
1715 int32_t max = nf->getMaximumFractionDigits();
1716 if (min != max) {
1717 UnicodeString a, b;
1718 nf->format(1.0, a);
1719 nf->format(1.125, b);
1720 errln((UnicodeString)"FAIL: " + locs[i].getName() +
1721 " min fraction digits != max fraction digits; "
1722 "x 1.0 => " + escape(a) +
1723 "; x 1.125 => " + escape(b));
1724 }
1725
1726 // Make sure EURO currency formats have exactly 2 fraction digits
1727 DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
1728 if (df != NULL) {
1729 if (u_strcmp(EUR, df->getCurrency()) == 0) {
1730 if (min != 2 || max != 2) {
1731 UnicodeString a;
1732 nf->format(1.0, a);
1733 errln((UnicodeString)"FAIL: " + locs[i].getName() +
1734 " is a EURO format but it does not have 2 fraction digits; "
1735 "x 1.0 => " +
1736 escape(a));
1737 }
1738 }
1739 }
1740 }
1741 delete nf;
1742 }
1743 }
1744
1745 void NumberFormatTest::TestRegCurrency(void) {
1746 #if !UCONFIG_NO_SERVICE
1747 UErrorCode status = U_ZERO_ERROR;
1748 UChar USD[4];
1749 ucurr_forLocale("en_US", USD, 4, &status);
1750 UChar YEN[4];
1751 ucurr_forLocale("ja_JP", YEN, 4, &status);
1752 UChar TMP[4];
1753 static const UChar QQQ[] = {0x51, 0x51, 0x51, 0};
1754 if(U_FAILURE(status)) {
1755 errcheckln(status, "Unable to get currency for locale, error %s", u_errorName(status));
1756 return;
1757 }
1758
1759 UCurrRegistryKey enkey = ucurr_register(YEN, "en_US", &status);
1760 UCurrRegistryKey enUSEUROkey = ucurr_register(QQQ, "en_US_EURO", &status);
1761
1762 ucurr_forLocale("en_US", TMP, 4, &status);
1763 if (u_strcmp(YEN, TMP) != 0) {
1764 errln("FAIL: didn't return YEN registered for en_US");
1765 }
1766
1767 ucurr_forLocale("en_US_EURO", TMP, 4, &status);
1768 if (u_strcmp(QQQ, TMP) != 0) {
1769 errln("FAIL: didn't return QQQ for en_US_EURO");
1770 }
1771
1772 int32_t fallbackLen = ucurr_forLocale("en_XX_BAR", TMP, 4, &status);
1773 if (fallbackLen) {
1774 errln("FAIL: tried to fallback en_XX_BAR");
1775 }
1776 status = U_ZERO_ERROR; // reset
1777
1778 if (!ucurr_unregister(enkey, &status)) {
1779 errln("FAIL: couldn't unregister enkey");
1780 }
1781
1782 ucurr_forLocale("en_US", TMP, 4, &status);
1783 if (u_strcmp(USD, TMP) != 0) {
1784 errln("FAIL: didn't return USD for en_US after unregister of en_US");
1785 }
1786 status = U_ZERO_ERROR; // reset
1787
1788 ucurr_forLocale("en_US_EURO", TMP, 4, &status);
1789 if (u_strcmp(QQQ, TMP) != 0) {
1790 errln("FAIL: didn't return QQQ for en_US_EURO after unregister of en_US");
1791 }
1792
1793 ucurr_forLocale("en_US_BLAH", TMP, 4, &status);
1794 if (u_strcmp(USD, TMP) != 0) {
1795 errln("FAIL: could not find USD for en_US_BLAH after unregister of en");
1796 }
1797 status = U_ZERO_ERROR; // reset
1798
1799 if (!ucurr_unregister(enUSEUROkey, &status)) {
1800 errln("FAIL: couldn't unregister enUSEUROkey");
1801 }
1802
1803 ucurr_forLocale("en_US_EURO", TMP, 4, &status);
1804 if (u_strcmp(EUR, TMP) != 0) {
1805 errln("FAIL: didn't return EUR for en_US_EURO after unregister of en_US_EURO");
1806 }
1807 status = U_ZERO_ERROR; // reset
1808 #endif
1809 }
1810
1811 void NumberFormatTest::TestCurrencyNames(void) {
1812 // Do a basic check of getName()
1813 // USD { "US$", "US Dollar" } // 04/04/1792-
1814 UErrorCode ec = U_ZERO_ERROR;
1815 static const UChar USD[] = {0x55, 0x53, 0x44, 0}; /*USD*/
1816 static const UChar USX[] = {0x55, 0x53, 0x58, 0}; /*USX*/
1817 static const UChar CAD[] = {0x43, 0x41, 0x44, 0}; /*CAD*/
1818 static const UChar ITL[] = {0x49, 0x54, 0x4C, 0}; /*ITL*/
1819 UBool isChoiceFormat;
1820 int32_t len;
1821 const UBool possibleDataError = TRUE;
1822 // Warning: HARD-CODED LOCALE DATA in this test. If it fails, CHECK
1823 // THE LOCALE DATA before diving into the code.
1824 assertEquals("USD.getName(SYMBOL_NAME)",
1825 UnicodeString("$"),
1826 UnicodeString(ucurr_getName(USD, "en",
1827 UCURR_SYMBOL_NAME,
1828 &isChoiceFormat, &len, &ec)),
1829 possibleDataError);
1830 assertEquals("USD.getName(LONG_NAME)",
1831 UnicodeString("US Dollar"),
1832 UnicodeString(ucurr_getName(USD, "en",
1833 UCURR_LONG_NAME,
1834 &isChoiceFormat, &len, &ec)),
1835 possibleDataError);
1836 assertEquals("CAD.getName(SYMBOL_NAME)",
1837 UnicodeString("CA$"),
1838 UnicodeString(ucurr_getName(CAD, "en",
1839 UCURR_SYMBOL_NAME,
1840 &isChoiceFormat, &len, &ec)),
1841 possibleDataError);
1842 assertEquals("CAD.getName(SYMBOL_NAME)",
1843 UnicodeString("$"),
1844 UnicodeString(ucurr_getName(CAD, "en_CA",
1845 UCURR_SYMBOL_NAME,
1846 &isChoiceFormat, &len, &ec)),
1847 possibleDataError);
1848 assertEquals("USD.getName(SYMBOL_NAME) in en_AU",
1849 UnicodeString("US$"),
1850 UnicodeString(ucurr_getName(USD, "en_AU",
1851 UCURR_SYMBOL_NAME,
1852 &isChoiceFormat, &len, &ec)),
1853 possibleDataError);
1854 assertEquals("CAD.getName(SYMBOL_NAME)",
1855 UnicodeString("CA$"),
1856 UnicodeString(ucurr_getName(CAD, "en_AU",
1857 UCURR_SYMBOL_NAME,
1858 &isChoiceFormat, &len, &ec)),
1859 possibleDataError);
1860 assertEquals("USX.getName(LONG_NAME)",
1861 UnicodeString("USX"),
1862 UnicodeString(ucurr_getName(USX, "en_US",
1863 UCURR_LONG_NAME,
1864 &isChoiceFormat, &len, &ec)),
1865 possibleDataError);
1866 assertSuccess("ucurr_getName", ec);
1867
1868 ec = U_ZERO_ERROR;
1869
1870 // Test that a default or fallback warning is being returned. JB 4239.
1871 ucurr_getName(CAD, "es_ES", UCURR_LONG_NAME, &isChoiceFormat,
1872 &len, &ec);
1873 assertTrue("ucurr_getName (es_ES fallback)",
1874 U_USING_FALLBACK_WARNING == ec, TRUE, possibleDataError);
1875
1876 ucurr_getName(CAD, "zh_TW", UCURR_LONG_NAME, &isChoiceFormat,
1877 &len, &ec);
1878 assertTrue("ucurr_getName (zh_TW fallback)",
1879 U_USING_FALLBACK_WARNING == ec, TRUE, possibleDataError);
1880
1881 ucurr_getName(CAD, "en_US", UCURR_LONG_NAME, &isChoiceFormat,
1882 &len, &ec);
1883 assertTrue("ucurr_getName (en_US default)",
1884 U_USING_DEFAULT_WARNING == ec || U_USING_FALLBACK_WARNING == ec, TRUE);
1885
1886 ucurr_getName(CAD, "ti", UCURR_LONG_NAME, &isChoiceFormat,
1887 &len, &ec);
1888 assertTrue("ucurr_getName (ti default)",
1889 U_USING_DEFAULT_WARNING == ec, TRUE);
1890
1891 // Test that a default warning is being returned when falling back to root. JB 4536.
1892 ucurr_getName(ITL, "cy", UCURR_LONG_NAME, &isChoiceFormat,
1893 &len, &ec);
1894 assertTrue("ucurr_getName (cy default to root)",
1895 U_USING_DEFAULT_WARNING == ec, TRUE);
1896
1897 // TODO add more tests later
1898 }
1899
1900 void NumberFormatTest::TestCurrencyUnit(void){
1901 UErrorCode ec = U_ZERO_ERROR;
1902 static const UChar USD[] = {85, 83, 68, 0}; /*USD*/
1903 static const UChar BAD[] = {63, 63, 63, 0}; /*???*/
1904 static const UChar BAD2[] = {63, 63, 65, 0}; /*???*/
1905 CurrencyUnit cu(USD, ec);
1906 assertSuccess("CurrencyUnit", ec);
1907
1908 const UChar * r = cu.getISOCurrency(); // who is the buffer owner ?
1909 assertEquals("getISOCurrency()", USD, r);
1910
1911 CurrencyUnit cu2(cu);
1912 if (!(cu2 == cu)){
1913 errln("CurrencyUnit copy constructed object should be same");
1914 }
1915
1916 CurrencyUnit * cu3 = (CurrencyUnit *)cu.clone();
1917 if (!(*cu3 == cu)){
1918 errln("CurrencyUnit cloned object should be same");
1919 }
1920 CurrencyUnit bad(BAD, ec);
1921 assertSuccess("CurrencyUnit", ec);
1922 if (cu.getIndex() == bad.getIndex()) {
1923 errln("Indexes of different currencies should differ.");
1924 }
1925 CurrencyUnit bad2(BAD2, ec);
1926 assertSuccess("CurrencyUnit", ec);
1927 if (bad2.getIndex() != bad.getIndex()) {
1928 errln("Indexes of unrecognized currencies should be the same.");
1929 }
1930 if (bad == bad2) {
1931 errln("Different unrecognized currencies should not be equal.");
1932 }
1933 bad = bad2;
1934 if (bad != bad2) {
1935 errln("Currency unit assignment should be the same.");
1936 }
1937 delete cu3;
1938 }
1939
1940 void NumberFormatTest::TestCurrencyAmount(void){
1941 UErrorCode ec = U_ZERO_ERROR;
1942 static const UChar USD[] = {85, 83, 68, 0}; /*USD*/
1943 CurrencyAmount ca(9, USD, ec);
1944 assertSuccess("CurrencyAmount", ec);
1945
1946 CurrencyAmount ca2(ca);
1947 if (!(ca2 == ca)){
1948 errln("CurrencyAmount copy constructed object should be same");
1949 }
1950
1951 ca2=ca;
1952 if (!(ca2 == ca)){
1953 errln("CurrencyAmount assigned object should be same");
1954 }
1955
1956 CurrencyAmount *ca3 = (CurrencyAmount *)ca.clone();
1957 if (!(*ca3 == ca)){
1958 errln("CurrencyAmount cloned object should be same");
1959 }
1960 delete ca3;
1961 }
1962
1963 void NumberFormatTest::TestSymbolsWithBadLocale(void) {
1964 Locale locDefault;
1965 static const char *badLocales[] = {
1966 // length < ULOC_FULLNAME_CAPACITY
1967 "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME",
1968
1969 // length > ULOC_FULLNAME_CAPACITY
1970 "x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME"
1971 }; // expect U_USING_DEFAULT_WARNING for both
1972
1973 unsigned int i;
1974 for (i = 0; i < sizeof(badLocales) / sizeof(char*); i++) {
1975 const char *localeName = badLocales[i];
1976 Locale locBad(localeName);
1977 UErrorCode status = U_ZERO_ERROR;
1978 UnicodeString intlCurrencySymbol((UChar)0xa4);
1979
1980 intlCurrencySymbol.append((UChar)0xa4);
1981
1982 logln("Current locale is %s", Locale::getDefault().getName());
1983 Locale::setDefault(locBad, status);
1984 logln("Current locale is %s", Locale::getDefault().getName());
1985 DecimalFormatSymbols mySymbols(status);
1986 if (status != U_USING_DEFAULT_WARNING) {
1987 errln("DecimalFormatSymbols should return U_USING_DEFAULT_WARNING.");
1988 }
1989 if (strcmp(mySymbols.getLocale().getName(), locBad.getName()) != 0) {
1990 errln("DecimalFormatSymbols does not have the right locale.", locBad.getName());
1991 }
1992 int symbolEnum = (int)DecimalFormatSymbols::kDecimalSeparatorSymbol;
1993 for (; symbolEnum < (int)DecimalFormatSymbols::kFormatSymbolCount; symbolEnum++) {
1994 UnicodeString symbolString = mySymbols.getSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbolEnum);
1995 logln(UnicodeString("DecimalFormatSymbols[") + symbolEnum + UnicodeString("] = ") + prettify(symbolString));
1996 if (symbolString.length() == 0
1997 && symbolEnum != (int)DecimalFormatSymbols::kGroupingSeparatorSymbol
1998 && symbolEnum != (int)DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol)
1999 {
2000 errln("DecimalFormatSymbols has an empty string at index %d.", symbolEnum);
2001 }
2002 }
2003
2004 status = U_ZERO_ERROR;
2005 Locale::setDefault(locDefault, status);
2006 logln("Current locale is %s", Locale::getDefault().getName());
2007 }
2008 }
2009
2010 /**
2011 * Check that adoptDecimalFormatSymbols and setDecimalFormatSymbols
2012 * behave the same, except for memory ownership semantics. (No
2013 * version of this test on Java, since Java has only one method.)
2014 */
2015 void NumberFormatTest::TestAdoptDecimalFormatSymbols(void) {
2016 UErrorCode ec = U_ZERO_ERROR;
2017 DecimalFormatSymbols *sym = new DecimalFormatSymbols(Locale::getUS(), ec);
2018 if (U_FAILURE(ec)) {
2019 errcheckln(ec, "Fail: DecimalFormatSymbols constructor - %s", u_errorName(ec));
2020 delete sym;
2021 return;
2022 }
2023 UnicodeString pat(" #,##0.00");
2024 pat.insert(0, (UChar)0x00A4);
2025 DecimalFormat fmt(pat, sym, ec);
2026 if (U_FAILURE(ec)) {
2027 errln("Fail: DecimalFormat constructor");
2028 return;
2029 }
2030
2031 UnicodeString str;
2032 fmt.format(2350.75, str);
2033 if (str == "$ 2,350.75") {
2034 logln(str);
2035 } else {
2036 dataerrln("Fail: " + str + ", expected $ 2,350.75");
2037 }
2038
2039 sym = new DecimalFormatSymbols(Locale::getUS(), ec);
2040 if (U_FAILURE(ec)) {
2041 errln("Fail: DecimalFormatSymbols constructor");
2042 delete sym;
2043 return;
2044 }
2045 sym->setSymbol(DecimalFormatSymbols::kCurrencySymbol, "Q");
2046 fmt.adoptDecimalFormatSymbols(sym);
2047
2048 str.truncate(0);
2049 fmt.format(2350.75, str);
2050 if (str == "Q 2,350.75") {
2051 logln(str);
2052 } else {
2053 dataerrln("Fail: adoptDecimalFormatSymbols -> " + str + ", expected Q 2,350.75");
2054 }
2055
2056 sym = new DecimalFormatSymbols(Locale::getUS(), ec);
2057 if (U_FAILURE(ec)) {
2058 errln("Fail: DecimalFormatSymbols constructor");
2059 delete sym;
2060 return;
2061 }
2062 DecimalFormat fmt2(pat, sym, ec);
2063 if (U_FAILURE(ec)) {
2064 errln("Fail: DecimalFormat constructor");
2065 return;
2066 }
2067
2068 DecimalFormatSymbols sym2(Locale::getUS(), ec);
2069 if (U_FAILURE(ec)) {
2070 errln("Fail: DecimalFormatSymbols constructor");
2071 return;
2072 }
2073 sym2.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "Q");
2074 fmt2.setDecimalFormatSymbols(sym2);
2075
2076 str.truncate(0);
2077 fmt2.format(2350.75, str);
2078 if (str == "Q 2,350.75") {
2079 logln(str);
2080 } else {
2081 dataerrln("Fail: setDecimalFormatSymbols -> " + str + ", expected Q 2,350.75");
2082 }
2083 }
2084
2085 void NumberFormatTest::TestPerMill() {
2086 UErrorCode ec = U_ZERO_ERROR;
2087 UnicodeString str;
2088 DecimalFormat fmt(ctou("###.###\\u2030"), ec);
2089 if (!assertSuccess("DecimalFormat ct", ec)) return;
2090 assertEquals("0.4857 x ###.###\\u2030",
2091 ctou("485.7\\u2030"), fmt.format(0.4857, str));
2092
2093 DecimalFormatSymbols sym(Locale::getUS(), ec);
2094 sym.setSymbol(DecimalFormatSymbols::kPerMillSymbol, ctou("m"));
2095 DecimalFormat fmt2("", sym, ec);
2096 fmt2.applyLocalizedPattern("###.###m", ec);
2097 if (!assertSuccess("setup", ec)) return;
2098 str.truncate(0);
2099 assertEquals("0.4857 x ###.###m",
2100 "485.7m", fmt2.format(0.4857, str));
2101 }
2102
2103 /**
2104 * Generic test for patterns that should be legal/illegal.
2105 */
2106 void NumberFormatTest::TestIllegalPatterns() {
2107 // Test cases:
2108 // Prefix with "-:" for illegal patterns
2109 // Prefix with "+:" for legal patterns
2110 const char* DATA[] = {
2111 // Unquoted special characters in the suffix are illegal
2112 "-:000.000|###",
2113 "+:000.000'|###'",
2114 0
2115 };
2116 for (int32_t i=0; DATA[i]; ++i) {
2117 const char* pat=DATA[i];
2118 UBool valid = (*pat) == '+';
2119 pat += 2;
2120 UErrorCode ec = U_ZERO_ERROR;
2121 DecimalFormat fmt(pat, ec); // locale doesn't matter here
2122 if (U_SUCCESS(ec) == valid) {
2123 logln("Ok: pattern \"%s\": %s",
2124 pat, u_errorName(ec));
2125 } else {
2126 errcheckln(ec, "FAIL: pattern \"%s\" should have %s; got %s",
2127 pat, (valid?"succeeded":"failed"),
2128 u_errorName(ec));
2129 }
2130 }
2131 }
2132
2133 //----------------------------------------------------------------------
2134
2135 static const char* KEYWORDS[] = {
2136 /*0*/ "ref=", // <reference pattern to parse numbers>
2137 /*1*/ "loc=", // <locale for formats>
2138 /*2*/ "f:", // <pattern or '-'> <number> <exp. string>
2139 /*3*/ "fp:", // <pattern or '-'> <number> <exp. string> <exp. number>
2140 /*4*/ "rt:", // <pattern or '-'> <(exp.) number> <(exp.) string>
2141 /*5*/ "p:", // <pattern or '-'> <string> <exp. number>
2142 /*6*/ "perr:", // <pattern or '-'> <invalid string>
2143 /*7*/ "pat:", // <pattern or '-'> <exp. toPattern or '-' or 'err'>
2144 /*8*/ "fpc:", // <pattern or '-'> <curr.amt> <exp. string> <exp. curr.amt>
2145 0
2146 };
2147
2148 /**
2149 * Return an integer representing the next token from this
2150 * iterator. The integer will be an index into the given list, or
2151 * -1 if there are no more tokens, or -2 if the token is not on
2152 * the list.
2153 */
2154 static int32_t keywordIndex(const UnicodeString& tok) {
2155 for (int32_t i=0; KEYWORDS[i]!=0; ++i) {
2156 if (tok==KEYWORDS[i]) {
2157 return i;
2158 }
2159 }
2160 return -1;
2161 }
2162
2163 /**
2164 * Parse a CurrencyAmount using the given NumberFormat, with
2165 * the 'delim' character separating the number and the currency.
2166 */
2167 static void parseCurrencyAmount(const UnicodeString& str,
2168 const NumberFormat& fmt,
2169 UChar delim,
2170 Formattable& result,
2171 UErrorCode& ec) {
2172 UnicodeString num, cur;
2173 int32_t i = str.indexOf(delim);
2174 str.extractBetween(0, i, num);
2175 str.extractBetween(i+1, INT32_MAX, cur);
2176 Formattable n;
2177 fmt.parse(num, n, ec);
2178 result.adoptObject(new CurrencyAmount(n, cur.getTerminatedBuffer(), ec));
2179 }
2180
2181 void NumberFormatTest::TestCases() {
2182 UErrorCode ec = U_ZERO_ERROR;
2183 TextFile reader("NumberFormatTestCases.txt", "UTF8", ec);
2184 if (U_FAILURE(ec)) {
2185 dataerrln("Couldn't open NumberFormatTestCases.txt");
2186 return;
2187 }
2188 TokenIterator tokens(&reader);
2189
2190 Locale loc("en", "US", "");
2191 DecimalFormat *ref = 0, *fmt = 0;
2192 MeasureFormat *mfmt = 0;
2193 UnicodeString pat, tok, mloc, str, out, where, currAmt;
2194 Formattable n;
2195
2196 for (;;) {
2197 ec = U_ZERO_ERROR;
2198 if (!tokens.next(tok, ec)) {
2199 break;
2200 }
2201 where = UnicodeString("(") + tokens.getLineNumber() + ") ";
2202 int32_t cmd = keywordIndex(tok);
2203 switch (cmd) {
2204 case 0:
2205 // ref= <reference pattern>
2206 if (!tokens.next(tok, ec)) goto error;
2207 delete ref;
2208 ref = new DecimalFormat(tok,
2209 new DecimalFormatSymbols(Locale::getUS(), ec), ec);
2210 if (U_FAILURE(ec)) {
2211 dataerrln("Error constructing DecimalFormat");
2212 goto error;
2213 }
2214 break;
2215 case 1:
2216 // loc= <locale>
2217 if (!tokens.next(tok, ec)) goto error;
2218 loc = Locale::createFromName(CharString().appendInvariantChars(tok, ec).data());
2219 break;
2220 case 2: // f:
2221 case 3: // fp:
2222 case 4: // rt:
2223 case 5: // p:
2224 if (!tokens.next(tok, ec)) goto error;
2225 if (tok != "-") {
2226 pat = tok;
2227 delete fmt;
2228 fmt = new DecimalFormat(pat, new DecimalFormatSymbols(loc, ec), ec);
2229 if (U_FAILURE(ec)) {
2230 errln("FAIL: " + where + "Pattern \"" + pat + "\": " + u_errorName(ec));
2231 ec = U_ZERO_ERROR;
2232 if (!tokens.next(tok, ec)) goto error;
2233 if (!tokens.next(tok, ec)) goto error;
2234 if (cmd == 3) {
2235 if (!tokens.next(tok, ec)) goto error;
2236 }
2237 continue;
2238 }
2239 }
2240 if (cmd == 2 || cmd == 3 || cmd == 4) {
2241 // f: <pattern or '-'> <number> <exp. string>
2242 // fp: <pattern or '-'> <number> <exp. string> <exp. number>
2243 // rt: <pattern or '-'> <number> <string>
2244 UnicodeString num;
2245 if (!tokens.next(num, ec)) goto error;
2246 if (!tokens.next(str, ec)) goto error;
2247 ref->parse(num, n, ec);
2248 assertSuccess("parse", ec);
2249 assertEquals(where + "\"" + pat + "\".format(" + num + ")",
2250 str, fmt->format(n, out.remove(), ec));
2251 assertSuccess("format", ec);
2252 if (cmd == 3) { // fp:
2253 if (!tokens.next(num, ec)) goto error;
2254 ref->parse(num, n, ec);
2255 assertSuccess("parse", ec);
2256 }
2257 if (cmd != 2) { // != f:
2258 Formattable m;
2259 fmt->parse(str, m, ec);
2260 assertSuccess("parse", ec);
2261 assertEquals(where + "\"" + pat + "\".parse(\"" + str + "\")",
2262 n, m);
2263 }
2264 }
2265 // p: <pattern or '-'> <string to parse> <exp. number>
2266 else {
2267 UnicodeString expstr;
2268 if (!tokens.next(str, ec)) goto error;
2269 if (!tokens.next(expstr, ec)) goto error;
2270 Formattable exp, n;
2271 ref->parse(expstr, exp, ec);
2272 assertSuccess("parse", ec);
2273 fmt->parse(str, n, ec);
2274 assertSuccess("parse", ec);
2275 assertEquals(where + "\"" + pat + "\".parse(\"" + str + "\")",
2276 exp, n);
2277 }
2278 break;
2279 case 8: // fpc:
2280 if (!tokens.next(tok, ec)) goto error;
2281 if (tok != "-") {
2282 mloc = tok;
2283 delete mfmt;
2284 mfmt = MeasureFormat::createCurrencyFormat(
2285 Locale::createFromName(
2286 CharString().appendInvariantChars(mloc, ec).data()), ec);
2287 if (U_FAILURE(ec)) {
2288 errln("FAIL: " + where + "Loc \"" + mloc + "\": " + u_errorName(ec));
2289 ec = U_ZERO_ERROR;
2290 if (!tokens.next(tok, ec)) goto error;
2291 if (!tokens.next(tok, ec)) goto error;
2292 if (!tokens.next(tok, ec)) goto error;
2293 continue;
2294 }
2295 } else if (mfmt == NULL) {
2296 errln("FAIL: " + where + "Loc \"" + mloc + "\": skip case using previous locale, no valid MeasureFormat");
2297 if (!tokens.next(tok, ec)) goto error;
2298 if (!tokens.next(tok, ec)) goto error;
2299 if (!tokens.next(tok, ec)) goto error;
2300 continue;
2301 }
2302 // fpc: <loc or '-'> <curr.amt> <exp. string> <exp. curr.amt>
2303 if (!tokens.next(currAmt, ec)) goto error;
2304 if (!tokens.next(str, ec)) goto error;
2305 parseCurrencyAmount(currAmt, *ref, (UChar)0x2F/*'/'*/, n, ec);
2306 if (assertSuccess("parseCurrencyAmount", ec)) {
2307 assertEquals(where + "getCurrencyFormat(" + mloc + ").format(" + currAmt + ")",
2308 str, mfmt->format(n, out.remove(), ec));
2309 assertSuccess("format", ec);
2310 }
2311 if (!tokens.next(currAmt, ec)) goto error;
2312 parseCurrencyAmount(currAmt, *ref, (UChar)0x2F/*'/'*/, n, ec);
2313 if (assertSuccess("parseCurrencyAmount", ec)) {
2314 Formattable m;
2315
2316 mfmt->parseObject(str, m, ec);
2317 if (assertSuccess("parseCurrency", ec)) {
2318 assertEquals(where + "getCurrencyFormat(" + mloc + ").parse(\"" + str + "\")",
2319 n, m);
2320 } else {
2321 errln("FAIL: source " + str);
2322 }
2323 }
2324 break;
2325 case 6:
2326 // perr: <pattern or '-'> <invalid string>
2327 errln("FAIL: Under construction");
2328 goto done;
2329 case 7: {
2330 // pat: <pattern> <exp. toPattern, or '-' or 'err'>
2331 UnicodeString testpat;
2332 UnicodeString exppat;
2333 if (!tokens.next(testpat, ec)) goto error;
2334 if (!tokens.next(exppat, ec)) goto error;
2335 UBool err = exppat == "err";
2336 UBool existingPat = FALSE;
2337 if (testpat == "-") {
2338 if (err) {
2339 errln("FAIL: " + where + "Invalid command \"pat: - err\"");
2340 continue;
2341 }
2342 existingPat = TRUE;
2343 testpat = pat;
2344 }
2345 if (exppat == "-") exppat = testpat;
2346 DecimalFormat* f = 0;
2347 UErrorCode ec2 = U_ZERO_ERROR;
2348 if (existingPat) {
2349 f = fmt;
2350 } else {
2351 f = new DecimalFormat(testpat, ec2);
2352 }
2353 if (U_SUCCESS(ec2)) {
2354 if (err) {
2355 errln("FAIL: " + where + "Invalid pattern \"" + testpat +
2356 "\" was accepted");
2357 } else {
2358 UnicodeString pat2;
2359 assertEquals(where + "\"" + testpat + "\".toPattern()",
2360 exppat, f->toPattern(pat2));
2361 }
2362 } else {
2363 if (err) {
2364 logln("Ok: " + where + "Invalid pattern \"" + testpat +
2365 "\" failed: " + u_errorName(ec2));
2366 } else {
2367 errln("FAIL: " + where + "Valid pattern \"" + testpat +
2368 "\" failed: " + u_errorName(ec2));
2369 }
2370 }
2371 if (!existingPat) delete f;
2372 } break;
2373 case -1:
2374 errln("FAIL: " + where + "Unknown command \"" + tok + "\"");
2375 goto done;
2376 }
2377 }
2378 goto done;
2379
2380 error:
2381 if (U_SUCCESS(ec)) {
2382 errln("FAIL: Unexpected EOF");
2383 } else {
2384 errcheckln(ec, "FAIL: " + where + "Unexpected " + u_errorName(ec));
2385 }
2386
2387 done:
2388 delete mfmt;
2389 delete fmt;
2390 delete ref;
2391 }
2392
2393
2394 //----------------------------------------------------------------------
2395 // Support methods
2396 //----------------------------------------------------------------------
2397
2398 UBool NumberFormatTest::equalValue(const Formattable& a, const Formattable& b) {
2399 if (a.getType() == b.getType()) {
2400 return a == b;
2401 }
2402
2403 if (a.getType() == Formattable::kLong) {
2404 if (b.getType() == Formattable::kInt64) {
2405 return a.getLong() == b.getLong();
2406 } else if (b.getType() == Formattable::kDouble) {
2407 return (double) a.getLong() == b.getDouble(); // TODO check use of double instead of long
2408 }
2409 } else if (a.getType() == Formattable::kDouble) {
2410 if (b.getType() == Formattable::kLong) {
2411 return a.getDouble() == (double) b.getLong();
2412 } else if (b.getType() == Formattable::kInt64) {
2413 return a.getDouble() == (double)b.getInt64();
2414 }
2415 } else if (a.getType() == Formattable::kInt64) {
2416 if (b.getType() == Formattable::kLong) {
2417 return a.getInt64() == (int64_t)b.getLong();
2418 } else if (b.getType() == Formattable::kDouble) {
2419 return a.getInt64() == (int64_t)b.getDouble();
2420 }
2421 }
2422 return FALSE;
2423 }
2424
2425 void NumberFormatTest::expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str) {
2426 // Don't round-trip format test, since we explicitly do it
2427 expect_rbnf(fmt, n, str, FALSE);
2428 expect_rbnf(fmt, str, n);
2429 }
2430
2431 void NumberFormatTest::expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str) {
2432 // Don't round-trip format test, since we explicitly do it
2433 expect(fmt, n, str, FALSE);
2434 expect(fmt, str, n);
2435 }
2436
2437 void NumberFormatTest::expect2(NumberFormat* fmt, const Formattable& n,
2438 const UnicodeString& exp,
2439 UErrorCode status) {
2440 if (fmt == NULL || U_FAILURE(status)) {
2441 dataerrln("FAIL: NumberFormat constructor");
2442 } else {
2443 expect2(*fmt, n, exp);
2444 }
2445 delete fmt;
2446 }
2447
2448 void NumberFormatTest::expect(NumberFormat& fmt, const UnicodeString& str, const Formattable& n) {
2449 UErrorCode status = U_ZERO_ERROR;
2450 Formattable num;
2451 fmt.parse(str, num, status);
2452 if (U_FAILURE(status)) {
2453 dataerrln(UnicodeString("FAIL: Parse failed for \"") + str + "\" - " + u_errorName(status));
2454 return;
2455 }
2456 UnicodeString pat;
2457 ((DecimalFormat*) &fmt)->toPattern(pat);
2458 if (equalValue(num, n)) {
2459 logln(UnicodeString("Ok \"") + str + "\" x " +
2460 pat + " = " +
2461 toString(num));
2462 } else {
2463 dataerrln(UnicodeString("FAIL \"") + str + "\" x " +
2464 pat + " = " +
2465 toString(num) + ", expected " + toString(n));
2466 }
2467 }
2468
2469 void NumberFormatTest::expect_rbnf(NumberFormat& fmt, const UnicodeString& str, const Formattable& n) {
2470 UErrorCode status = U_ZERO_ERROR;
2471 Formattable num;
2472 fmt.parse(str, num, status);
2473 if (U_FAILURE(status)) {
2474 errln(UnicodeString("FAIL: Parse failed for \"") + str + "\"");
2475 return;
2476 }
2477 if (equalValue(num, n)) {
2478 logln(UnicodeString("Ok \"") + str + " = " +
2479 toString(num));
2480 } else {
2481 errln(UnicodeString("FAIL \"") + str + " = " +
2482 toString(num) + ", expected " + toString(n));
2483 }
2484 }
2485
2486 void NumberFormatTest::expect_rbnf(NumberFormat& fmt, const Formattable& n,
2487 const UnicodeString& exp, UBool rt) {
2488 UnicodeString saw;
2489 FieldPosition pos;
2490 UErrorCode status = U_ZERO_ERROR;
2491 fmt.format(n, saw, pos, status);
2492 CHECK(status, "NumberFormat::format");
2493 if (saw == exp) {
2494 logln(UnicodeString("Ok ") + toString(n) +
2495 " = \"" +
2496 escape(saw) + "\"");
2497 // We should be able to round-trip the formatted string =>
2498 // number => string (but not the other way around: number
2499 // => string => number2, might have number2 != number):
2500 if (rt) {
2501 Formattable n2;
2502 fmt.parse(exp, n2, status);
2503 if (U_FAILURE(status)) {
2504 errln(UnicodeString("FAIL: Parse failed for \"") + exp + "\"");
2505 return;
2506 }
2507 UnicodeString saw2;
2508 fmt.format(n2, saw2, pos, status);
2509 CHECK(status, "NumberFormat::format");
2510 if (saw2 != exp) {
2511 errln((UnicodeString)"FAIL \"" + exp + "\" => " + toString(n2) +
2512 " => \"" + saw2 + "\"");
2513 }
2514 }
2515 } else {
2516 errln(UnicodeString("FAIL ") + toString(n) +
2517 " = \"" +
2518 escape(saw) + "\", expected \"" + exp + "\"");
2519 }
2520 }
2521
2522 void NumberFormatTest::expect(NumberFormat& fmt, const Formattable& n,
2523 const UnicodeString& exp, UBool rt) {
2524 UnicodeString saw;
2525 FieldPosition pos;
2526 UErrorCode status = U_ZERO_ERROR;
2527 fmt.format(n, saw, pos, status);
2528 CHECK(status, "NumberFormat::format");
2529 UnicodeString pat;
2530 ((DecimalFormat*) &fmt)->toPattern(pat);
2531 if (saw == exp) {
2532 logln(UnicodeString("Ok ") + toString(n) + " x " +
2533 escape(pat) + " = \"" +
2534 escape(saw) + "\"");
2535 // We should be able to round-trip the formatted string =>
2536 // number => string (but not the other way around: number
2537 // => string => number2, might have number2 != number):
2538 if (rt) {
2539 Formattable n2;
2540 fmt.parse(exp, n2, status);
2541 if (U_FAILURE(status)) {
2542 errln(UnicodeString("FAIL: Parse failed for \"") + exp + "\" - " + u_errorName(status));
2543 return;
2544 }
2545 UnicodeString saw2;
2546 fmt.format(n2, saw2, pos, status);
2547 CHECK(status, "NumberFormat::format");
2548 if (saw2 != exp) {
2549 errln((UnicodeString)"FAIL \"" + exp + "\" => " + toString(n2) +
2550 " => \"" + saw2 + "\"");
2551 }
2552 }
2553 } else {
2554 dataerrln(UnicodeString("FAIL ") + toString(n) + " x " +
2555 escape(pat) + " = \"" +
2556 escape(saw) + "\", expected \"" + exp + "\"");
2557 }
2558 }
2559
2560 void NumberFormatTest::expect(NumberFormat* fmt, const Formattable& n,
2561 const UnicodeString& exp, UBool rt,
2562 UErrorCode status) {
2563 if (fmt == NULL || U_FAILURE(status)) {
2564 dataerrln("FAIL: NumberFormat constructor");
2565 } else {
2566 expect(*fmt, n, exp, rt);
2567 }
2568 delete fmt;
2569 }
2570
2571 void NumberFormatTest::expectCurrency(NumberFormat& nf, const Locale& locale,
2572 double value, const UnicodeString& string) {
2573 UErrorCode ec = U_ZERO_ERROR;
2574 DecimalFormat& fmt = * (DecimalFormat*) &nf;
2575 const UChar DEFAULT_CURR[] = {45/*-*/,0};
2576 UChar curr[4];
2577 u_strcpy(curr, DEFAULT_CURR);
2578 if (*locale.getLanguage() != 0) {
2579 ucurr_forLocale(locale.getName(), curr, 4, &ec);
2580 assertSuccess("ucurr_forLocale", ec);
2581 fmt.setCurrency(curr, ec);
2582 assertSuccess("DecimalFormat::setCurrency", ec);
2583 fmt.setCurrency(curr); //Deprecated variant, for coverage only
2584 }
2585 UnicodeString s;
2586 fmt.format(value, s);
2587 s.findAndReplace((UChar32)0x00A0, (UChar32)0x0020);
2588
2589 // Default display of the number yields "1234.5599999999999"
2590 // instead of "1234.56". Use a formatter to fix this.
2591 NumberFormat* f =
2592 NumberFormat::createInstance(Locale::getUS(), ec);
2593 UnicodeString v;
2594 if (U_FAILURE(ec)) {
2595 // Oops; bad formatter. Use default op+= display.
2596 v = (UnicodeString)"" + value;
2597 } else {
2598 f->setMaximumFractionDigits(4);
2599 f->setGroupingUsed(FALSE);
2600 f->format(value, v);
2601 }
2602 delete f;
2603
2604 if (s == string) {
2605 logln((UnicodeString)"Ok: " + v + " x " + curr + " => " + prettify(s));
2606 } else {
2607 errln((UnicodeString)"FAIL: " + v + " x " + curr + " => " + prettify(s) +
2608 ", expected " + prettify(string));
2609 }
2610 }
2611
2612 void NumberFormatTest::expectPat(DecimalFormat& fmt, const UnicodeString& exp) {
2613 UnicodeString pat;
2614 fmt.toPattern(pat);
2615 if (pat == exp) {
2616 logln(UnicodeString("Ok \"") + pat + "\"");
2617 } else {
2618 errln(UnicodeString("FAIL \"") + pat + "\", expected \"" + exp + "\"");
2619 }
2620 }
2621
2622 void NumberFormatTest::expectPad(DecimalFormat& fmt, const UnicodeString& pat,
2623 int32_t pos) {
2624 expectPad(fmt, pat, pos, 0, (UnicodeString)"");
2625 }
2626 void NumberFormatTest::expectPad(DecimalFormat& fmt, const UnicodeString& pat,
2627 int32_t pos, int32_t width, UChar pad) {
2628 expectPad(fmt, pat, pos, width, UnicodeString(pad));
2629 }
2630 void NumberFormatTest::expectPad(DecimalFormat& fmt, const UnicodeString& pat,
2631 int32_t pos, int32_t width, const UnicodeString& pad) {
2632 int32_t apos = 0, awidth = 0;
2633 UnicodeString apadStr;
2634 UErrorCode status = U_ZERO_ERROR;
2635 fmt.applyPattern(pat, status);
2636 if (U_SUCCESS(status)) {
2637 apos = fmt.getPadPosition();
2638 awidth = fmt.getFormatWidth();
2639 apadStr=fmt.getPadCharacterString();
2640 } else {
2641 apos = -1;
2642 awidth = width;
2643 apadStr = pad;
2644 }
2645 if (apos == pos && awidth == width && apadStr == pad) {
2646 UnicodeString infoStr;
2647 if (pos == ILLEGAL) {
2648 infoStr = UnicodeString(" width=", "") + awidth + UnicodeString(" pad=", "") + apadStr;
2649 }
2650 logln(UnicodeString("Ok \"") + pat + "\" pos=" + apos + infoStr);
2651 } else {
2652 errln(UnicodeString("FAIL \"") + pat + "\" pos=" + apos +
2653 " width=" + awidth + " pad=" + apadStr +
2654 ", expected " + pos + " " + width + " " + pad);
2655 }
2656 }
2657
2658 // This test is flaky b/c the symbols for CNY and JPY are equivalent in this locale - FIXME
2659 void NumberFormatTest::TestCompatibleCurrencies() {
2660 /*
2661 static const UChar JPY[] = {0x4A, 0x50, 0x59, 0};
2662 static const UChar CNY[] = {0x43, 0x4E, 0x59, 0};
2663 UErrorCode status = U_ZERO_ERROR;
2664 LocalPointer<NumberFormat> fmt(
2665 NumberFormat::createCurrencyInstance(Locale::getUS(), status));
2666 if (U_FAILURE(status)) {
2667 errln("Could not create number format instance.");
2668 return;
2669 }
2670 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__);
2671 expectParseCurrency(*fmt, JPY, 1235, "\\u00A51,235");
2672 logln("%s:%d - testing parse of fullwidth yen sign\n", __FILE__, __LINE__);
2673 expectParseCurrency(*fmt, JPY, 1235, "\\uFFE51,235");
2674 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__);
2675 expectParseCurrency(*fmt, CNY, 1235, "CN\\u00A51,235");
2676
2677 LocalPointer<NumberFormat> fmtTW(
2678 NumberFormat::createCurrencyInstance(Locale::getTaiwan(), status));
2679
2680 logln("%s:%d - testing parse of halfwidth yen sign in TW\n", __FILE__, __LINE__);
2681 expectParseCurrency(*fmtTW, CNY, 1235, "\\u00A51,235");
2682 logln("%s:%d - testing parse of fullwidth yen sign in TW\n", __FILE__, __LINE__);
2683 expectParseCurrency(*fmtTW, CNY, 1235, "\\uFFE51,235");
2684
2685 LocalPointer<NumberFormat> fmtJP(
2686 NumberFormat::createCurrencyInstance(Locale::getJapan(), status));
2687
2688 logln("%s:%d - testing parse of halfwidth yen sign in JP\n", __FILE__, __LINE__);
2689 expectParseCurrency(*fmtJP, JPY, 1235, "\\u00A51,235");
2690 logln("%s:%d - testing parse of fullwidth yen sign in JP\n", __FILE__, __LINE__);
2691 expectParseCurrency(*fmtJP, JPY, 1235, "\\uFFE51,235");
2692
2693 // more..
2694 */
2695 }
2696
2697 void NumberFormatTest::expectParseCurrency(const NumberFormat &fmt, const UChar* currency, double amount, const char *text) {
2698 ParsePosition ppos;
2699 UnicodeString utext = ctou(text);
2700 LocalPointer<CurrencyAmount> currencyAmount(fmt.parseCurrency(utext, ppos));
2701 if (!ppos.getIndex()) {
2702 errln(UnicodeString("Parse of ") + utext + " should have succeeded.");
2703 return;
2704 }
2705 UErrorCode status = U_ZERO_ERROR;
2706
2707 char theInfo[100];
2708 sprintf(theInfo, "For locale %s, string \"%s\", currency ",
2709 fmt.getLocale(ULOC_ACTUAL_LOCALE, status).getBaseName(),
2710 text);
2711 u_austrcpy(theInfo+uprv_strlen(theInfo), currency);
2712
2713 char theOperation[100];
2714
2715 uprv_strcpy(theOperation, theInfo);
2716 uprv_strcat(theOperation, ", check amount:");
2717 assertTrue(theOperation, amount == currencyAmount->getNumber().getDouble(status));
2718
2719 uprv_strcpy(theOperation, theInfo);
2720 uprv_strcat(theOperation, ", check currency:");
2721 assertEquals(theOperation, currency, currencyAmount->getISOCurrency());
2722 }
2723
2724
2725 void NumberFormatTest::TestJB3832(){
2726 const char* localeID = "pt_PT@currency=PTE";
2727 Locale loc(localeID);
2728 UErrorCode status = U_ZERO_ERROR;
2729 UnicodeString expected(CharsToUnicodeString("1,150$50\\u00A0\\u200B")); // per cldrbug 7670
2730 UnicodeString s;
2731 NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(loc, status);
2732 if(U_FAILURE(status)){
2733 dataerrln("Could not create currency formatter for locale %s - %s", localeID, u_errorName(status));
2734 return;
2735 }
2736 currencyFmt->format(1150.50, s);
2737 if(s!=expected){
2738 errln(UnicodeString("FAIL: Expected: ")+expected
2739 + UnicodeString(" Got: ") + s
2740 + UnicodeString( " for locale: ")+ UnicodeString(localeID) );
2741 }
2742 if (U_FAILURE(status)){
2743 errln("FAIL: Status %s", u_errorName(status));
2744 }
2745 delete currencyFmt;
2746 }
2747
2748 void NumberFormatTest::TestHost()
2749 {
2750 #if U_PLATFORM_USES_ONLY_WIN32_API
2751 Win32NumberTest::testLocales(this);
2752 #endif
2753 Locale loc("en_US@compat=host");
2754 for (UNumberFormatStyle k = UNUM_DECIMAL;
2755 k < UNUM_FORMAT_STYLE_COUNT; k = (UNumberFormatStyle)(k+1)) {
2756 UErrorCode status = U_ZERO_ERROR;
2757 LocalPointer<NumberFormat> full(NumberFormat::createInstance(loc, k, status));
2758 if (!NumberFormat::isStyleSupported(k)) {
2759 if (status != U_UNSUPPORTED_ERROR) {
2760 errln("FAIL: expected style %d to be unsupported - %s",
2761 k, u_errorName(status));
2762 }
2763 continue;
2764 }
2765 if (full.isNull() || U_FAILURE(status)) {
2766 dataerrln("FAIL: Can't create number instance of style %d for host - %s",
2767 k, u_errorName(status));
2768 return;
2769 }
2770 UnicodeString result1;
2771 Formattable number(10.00);
2772 full->format(number, result1, status);
2773 if (U_FAILURE(status)) {
2774 errln("FAIL: Can't format for host");
2775 return;
2776 }
2777 Formattable formattable;
2778 full->parse(result1, formattable, status);
2779 if (U_FAILURE(status)) {
2780 errln("FAIL: Can't parse for host");
2781 return;
2782 }
2783 }
2784 }
2785
2786 void NumberFormatTest::TestHostClone()
2787 {
2788 /*
2789 Verify that a cloned formatter gives the same results
2790 and is useable after the original has been deleted.
2791 */
2792 // This is mainly important on Windows.
2793 UErrorCode status = U_ZERO_ERROR;
2794 Locale loc("en_US@compat=host");
2795 UDate now = Calendar::getNow();
2796 NumberFormat *full = NumberFormat::createInstance(loc, status);
2797 if (full == NULL || U_FAILURE(status)) {
2798 dataerrln("FAIL: Can't create Relative date instance - %s", u_errorName(status));
2799 return;
2800 }
2801 UnicodeString result1;
2802 full->format(now, result1, status);
2803 Format *fullClone = full->clone();
2804 delete full;
2805 full = NULL;
2806
2807 UnicodeString result2;
2808 fullClone->format(now, result2, status);
2809 if (U_FAILURE(status)) {
2810 errln("FAIL: format failure.");
2811 }
2812 if (result1 != result2) {
2813 errln("FAIL: Clone returned different result from non-clone.");
2814 }
2815 delete fullClone;
2816 }
2817
2818 void NumberFormatTest::TestCurrencyFormat()
2819 {
2820 // This test is here to increase code coverage.
2821 UErrorCode status = U_ZERO_ERROR;
2822 MeasureFormat *cloneObj;
2823 UnicodeString str;
2824 Formattable toFormat, result;
2825 static const UChar ISO_CODE[4] = {0x0047, 0x0042, 0x0050, 0};
2826
2827 Locale saveDefaultLocale = Locale::getDefault();
2828 Locale::setDefault( Locale::getUK(), status );
2829 if (U_FAILURE(status)) {
2830 errln("couldn't set default Locale!");
2831 return;
2832 }
2833
2834 MeasureFormat *measureObj = MeasureFormat::createCurrencyFormat(status);
2835 Locale::setDefault( saveDefaultLocale, status );
2836 if (U_FAILURE(status)){
2837 dataerrln("FAIL: Status %s", u_errorName(status));
2838 return;
2839 }
2840 cloneObj = (MeasureFormat *)measureObj->clone();
2841 if (cloneObj == NULL) {
2842 errln("Clone doesn't work");
2843 return;
2844 }
2845 toFormat.adoptObject(new CurrencyAmount(1234.56, ISO_CODE, status));
2846 measureObj->format(toFormat, str, status);
2847 measureObj->parseObject(str, result, status);
2848 if (U_FAILURE(status)){
2849 errln("FAIL: Status %s", u_errorName(status));
2850 }
2851 if (result != toFormat) {
2852 errln("measureObj does not round trip. Formatted string was \"" + str + "\" Got: " + toString(result) + " Expected: " + toString(toFormat));
2853 }
2854 status = U_ZERO_ERROR;
2855 str.truncate(0);
2856 cloneObj->format(toFormat, str, status);
2857 cloneObj->parseObject(str, result, status);
2858 if (U_FAILURE(status)){
2859 errln("FAIL: Status %s", u_errorName(status));
2860 }
2861 if (result != toFormat) {
2862 errln("Clone does not round trip. Formatted string was \"" + str + "\" Got: " + toString(result) + " Expected: " + toString(toFormat));
2863 }
2864 if (*measureObj != *cloneObj) {
2865 errln("Cloned object is not equal to the original object");
2866 }
2867 delete measureObj;
2868 delete cloneObj;
2869
2870 status = U_USELESS_COLLATOR_ERROR;
2871 if (MeasureFormat::createCurrencyFormat(status) != NULL) {
2872 errln("createCurrencyFormat should have returned NULL.");
2873 }
2874 }
2875
2876 /* Port of ICU4J rounding test. */
2877 void NumberFormatTest::TestRounding() {
2878 UErrorCode status = U_ZERO_ERROR;
2879 DecimalFormat *df = (DecimalFormat*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status);
2880
2881 if (U_FAILURE(status)) {
2882 dataerrln("Unable to create decimal formatter. - %s", u_errorName(status));
2883 return;
2884 }
2885
2886 int roundingIncrements[]={1, 2, 5, 20, 50, 100};
2887 int testValues[]={0, 300};
2888
2889 for (int j=0; j<2; j++) {
2890 for (int mode=DecimalFormat::kRoundUp;mode<DecimalFormat::kRoundHalfEven;mode++) {
2891 df->setRoundingMode((DecimalFormat::ERoundingMode)mode);
2892 for (int increment=0; increment<6; increment++) {
2893 double base=testValues[j];
2894 double rInc=roundingIncrements[increment];
2895 checkRounding(df, base, 20, rInc);
2896 rInc=1.000000000/rInc;
2897 checkRounding(df, base, 20, rInc);
2898 }
2899 }
2900 }
2901 delete df;
2902 }
2903
2904 void NumberFormatTest::TestRoundingPattern() {
2905 UErrorCode status = U_ZERO_ERROR;
2906 struct {
2907 UnicodeString pattern;
2908 double testCase;
2909 UnicodeString expected;
2910 } tests[] = {
2911 { (UnicodeString)"##0.65", 1.234, (UnicodeString)"1.30" },
2912 { (UnicodeString)"#50", 1230, (UnicodeString)"1250" }
2913 };
2914 int32_t numOfTests = (sizeof(tests)/sizeof(tests[0]));
2915 UnicodeString result;
2916
2917 DecimalFormat *df = (DecimalFormat*)NumberFormat::createCurrencyInstance(Locale::getEnglish(), status);
2918 if (U_FAILURE(status)) {
2919 dataerrln("Unable to create decimal formatter. - %s", u_errorName(status));
2920 return;
2921 }
2922
2923 for (int32_t i = 0; i < numOfTests; i++) {
2924 result.remove();
2925
2926 df->applyPattern(tests[i].pattern, status);
2927 if (U_FAILURE(status)) {
2928 errln("Unable to apply pattern to decimal formatter. - %s", u_errorName(status));
2929 }
2930
2931 df->format(tests[i].testCase, result);
2932
2933 if (result != tests[i].expected) {
2934 errln("String Pattern Rounding Test Failed: Pattern: \"" + tests[i].pattern + "\" Number: " + tests[i].testCase + " - Got: " + result + " Expected: " + tests[i].expected);
2935 }
2936 }
2937
2938 delete df;
2939 }
2940
2941 void NumberFormatTest::checkRounding(DecimalFormat* df, double base, int iterations, double increment) {
2942 df->setRoundingIncrement(increment);
2943 double lastParsed=INT32_MIN; //Intger.MIN_VALUE
2944 for (int i=-iterations; i<=iterations;i++) {
2945 double iValue=base+(increment*(i*0.1));
2946 double smallIncrement=0.00000001;
2947 if (iValue!=0) {
2948 smallIncrement*=iValue;
2949 }
2950 //we not only test the value, but some values in a small range around it
2951 lastParsed=checkRound(df, iValue-smallIncrement, lastParsed);
2952 lastParsed=checkRound(df, iValue, lastParsed);
2953 lastParsed=checkRound(df, iValue+smallIncrement, lastParsed);
2954 }
2955 }
2956
2957 double NumberFormatTest::checkRound(DecimalFormat* df, double iValue, double lastParsed) {
2958 UErrorCode status=U_ZERO_ERROR;
2959 UnicodeString formattedDecimal;
2960 double parsed;
2961 Formattable result;
2962 df->format(iValue, formattedDecimal, status);
2963
2964 if (U_FAILURE(status)) {
2965 errln("Error formatting number.");
2966 }
2967
2968 df->parse(formattedDecimal, result, status);
2969
2970 if (U_FAILURE(status)) {
2971 errln("Error parsing number.");
2972 }
2973
2974 parsed=result.getDouble();
2975
2976 if (lastParsed>parsed) {
2977 errln("Rounding wrong direction! %d > %d", lastParsed, parsed);
2978 }
2979
2980 return lastParsed;
2981 }
2982
2983 void NumberFormatTest::TestNonpositiveMultiplier() {
2984 UErrorCode status = U_ZERO_ERROR;
2985 DecimalFormatSymbols US(Locale::getUS(), status);
2986 CHECK(status, "DecimalFormatSymbols constructor");
2987 DecimalFormat df(UnicodeString("0"), US, status);
2988 CHECK(status, "DecimalFormat(0)");
2989
2990 // test zero multiplier
2991
2992 int32_t mult = df.getMultiplier();
2993 df.setMultiplier(0);
2994 if (df.getMultiplier() != mult) {
2995 errln("DecimalFormat.setMultiplier(0) did not ignore its zero input");
2996 }
2997
2998 // test negative multiplier
2999
3000 df.setMultiplier(-1);
3001 if (df.getMultiplier() != -1) {
3002 errln("DecimalFormat.setMultiplier(-1) ignored its negative input");
3003 return;
3004 }
3005
3006 expect(df, "1122.123", -1122.123);
3007 expect(df, "-1122.123", 1122.123);
3008 expect(df, "1.2", -1.2);
3009 expect(df, "-1.2", 1.2);
3010
3011 // Note: the tests with the final parameter of FALSE will not round trip.
3012 // The initial numeric value will format correctly, after the multiplier.
3013 // Parsing the formatted text will be out-of-range for an int64, however.
3014 // The expect() function could be modified to detect this and fall back
3015 // to looking at the decimal parsed value, but it doesn't.
3016 expect(df, U_INT64_MIN, "9223372036854775808", FALSE);
3017 expect(df, U_INT64_MIN+1, "9223372036854775807");
3018 expect(df, (int64_t)-123, "123");
3019 expect(df, (int64_t)123, "-123");
3020 expect(df, U_INT64_MAX-1, "-9223372036854775806");
3021 expect(df, U_INT64_MAX, "-9223372036854775807");
3022
3023 df.setMultiplier(-2);
3024 expect(df, -(U_INT64_MIN/2)-1, "-9223372036854775806");
3025 expect(df, -(U_INT64_MIN/2), "-9223372036854775808");
3026 expect(df, -(U_INT64_MIN/2)+1, "-9223372036854775810", FALSE);
3027
3028 df.setMultiplier(-7);
3029 expect(df, -(U_INT64_MAX/7)-1, "9223372036854775814", FALSE);
3030 expect(df, -(U_INT64_MAX/7), "9223372036854775807");
3031 expect(df, -(U_INT64_MAX/7)+1, "9223372036854775800");
3032
3033 // TODO: uncomment (and fix up) all the following int64_t tests once BigInteger is ported
3034 // (right now the big numbers get turned into doubles and lose tons of accuracy)
3035 //expect2(df, U_INT64_MAX, Int64ToUnicodeString(-U_INT64_MAX));
3036 //expect2(df, U_INT64_MIN, UnicodeString(Int64ToUnicodeString(U_INT64_MIN), 1));
3037 //expect2(df, U_INT64_MAX / 2, Int64ToUnicodeString(-(U_INT64_MAX / 2)));
3038 //expect2(df, U_INT64_MIN / 2, Int64ToUnicodeString(-(U_INT64_MIN / 2)));
3039
3040 // TODO: uncomment (and fix up) once BigDecimal is ported and DecimalFormat can handle it
3041 //expect2(df, BigDecimal.valueOf(Long.MAX_VALUE), BigDecimal.valueOf(Long.MAX_VALUE).negate().toString());
3042 //expect2(df, BigDecimal.valueOf(Long.MIN_VALUE), BigDecimal.valueOf(Long.MIN_VALUE).negate().toString());
3043 //expect2(df, java.math.BigDecimal.valueOf(Long.MAX_VALUE), java.math.BigDecimal.valueOf(Long.MAX_VALUE).negate().toString());
3044 //expect2(df, java.math.BigDecimal.valueOf(Long.MIN_VALUE), java.math.BigDecimal.valueOf(Long.MIN_VALUE).negate().toString());
3045 }
3046
3047 typedef struct {
3048 const char * stringToParse;
3049 int parsedPos;
3050 int errorIndex;
3051 UBool lenient;
3052 } TestSpaceParsingItem;
3053
3054 void
3055 NumberFormatTest::TestSpaceParsing() {
3056 // the data are:
3057 // the string to be parsed, parsed position, parsed error index
3058 const TestSpaceParsingItem DATA[] = {
3059 // TOTO: Update the following TODOs, some may be handled now
3060 {"$124", 4, -1, FALSE},
3061 {"$124 $124", 4, -1, FALSE},
3062 {"$124 ", 4, -1, FALSE},
3063 //{"$ 124 ", 5, -1, FALSE}, // TODO: need to handle space correctly
3064 //{"$\\u00A0124 ", 5, -1, FALSE}, // TODO: need to handle space correctly
3065 {"$ 124 ", 0, 1, FALSE}, // errorIndex used to be 0, now 1 (better)
3066 {"$\\u00A0124 ", 5, -1, FALSE}, // errorIndex used to be 0, now 1 (better) *Apple change from open source*
3067 {" $ 124 ", 0, 0, FALSE}, // TODO: need to handle space correctly
3068 {"124$", 0, 3, FALSE}, // TODO: need to handle space correctly
3069 // {"124 $", 5, -1, FALSE}, // TODO: OK or not, need currency spacing rule
3070 {"124 $", 0, 3, FALSE},
3071 {"$124", 4, -1, TRUE},
3072 {"$124 $124", 4, -1, TRUE},
3073 {"$124 ", 4, -1, TRUE},
3074 {"$ 124 ", 5, -1, TRUE},
3075 {"$\\u00A0124 ", 5, -1, TRUE},
3076 {" $ 124 ", 6, -1, TRUE},
3077 //{"124$", 4, -1, TRUE}, // TODO: need to handle trailing currency correctly
3078 {"124$", 3, -1, TRUE},
3079 //{"124 $", 5, -1, TRUE}, // TODO: OK or not, need currency spacing rule
3080 {"124 $", 4, -1, TRUE},
3081 };
3082 UErrorCode status = U_ZERO_ERROR;
3083 Locale locale("en_US");
3084 NumberFormat* foo = NumberFormat::createCurrencyInstance(locale, status);
3085
3086 if (U_FAILURE(status)) {
3087 delete foo;
3088 return;
3089 }
3090 for (uint32_t i = 0; i < sizeof(DATA)/sizeof(DATA[0]); ++i) {
3091 ParsePosition parsePosition(0);
3092 UnicodeString stringToBeParsed = ctou(DATA[i].stringToParse);
3093 int parsedPosition = DATA[i].parsedPos;
3094 int errorIndex = DATA[i].errorIndex;
3095 foo->setLenient(DATA[i].lenient);
3096 Formattable result;
3097 foo->parse(stringToBeParsed, result, parsePosition);
3098 if (parsePosition.getIndex() != parsedPosition ||
3099 parsePosition.getErrorIndex() != errorIndex) {
3100 errln("FAILED parse " + stringToBeParsed + "; lenient: " + DATA[i].lenient + "; wrong position, expected: (" + parsedPosition + ", " + errorIndex + "); got (" + parsePosition.getIndex() + ", " + parsePosition.getErrorIndex() + ")");
3101 }
3102 if (parsePosition.getErrorIndex() == -1 &&
3103 result.getType() == Formattable::kLong &&
3104 result.getLong() != 124) {
3105 errln("FAILED parse " + stringToBeParsed + "; wrong number, expect: 124, got " + result.getLong());
3106 }
3107 }
3108 delete foo;
3109 }
3110
3111 /**
3112 * Test using various numbering systems and numbering system keyword.
3113 */
3114 typedef struct {
3115 const char *localeName;
3116 double value;
3117 UBool isRBNF;
3118 const char *expectedResult;
3119 } TestNumberingSystemItem;
3120
3121 void NumberFormatTest::TestNumberingSystems() {
3122
3123 const TestNumberingSystemItem DATA[] = {
3124 { "en_US@numbers=thai", 1234.567, FALSE, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" },
3125 { "en_US@numbers=hebr", 5678.0, TRUE, "\\u05D4\\u05F3\\u05EA\\u05E8\\u05E2\\u05F4\\u05D7" },
3126 { "en_US@numbers=arabext", 1234.567, FALSE, "\\u06F1\\u066c\\u06F2\\u06F3\\u06F4\\u066b\\u06F5\\u06F6\\u06F7" },
3127 { "ar_EG", 1234.567, FALSE, "\\u0661\\u066C\\u0662\\u0663\\u0664\\u066b\\u0665\\u0666\\u0667" },
3128 { "th_TH@numbers=traditional", 1234.567, FALSE, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" }, // fall back to native per TR35
3129 { "ar_MA", 1234.567, FALSE, "1.234,567" },
3130 { "en_US@numbers=hanidec", 1234.567, FALSE, "\\u4e00,\\u4e8c\\u4e09\\u56db.\\u4e94\\u516d\\u4e03" },
3131 { "ta_IN@numbers=native", 1234.567, FALSE, "\\u0BE7,\\u0BE8\\u0BE9\\u0BEA.\\u0BEB\\u0BEC\\u0BED" },
3132 { "ta_IN@numbers=traditional", 1235.0, TRUE, "\\u0BF2\\u0BE8\\u0BF1\\u0BE9\\u0BF0\\u0BEB" },
3133 { "ta_IN@numbers=finance", 1234.567, FALSE, "1,234.567" }, // fall back to default per TR35
3134 { "zh_TW@numbers=native", 1234.567, FALSE, "\\u4e00,\\u4e8c\\u4e09\\u56db.\\u4e94\\u516d\\u4e03" },
3135 { "zh_TW@numbers=traditional", 1234.567, TRUE, "\\u4E00\\u5343\\u4E8C\\u767E\\u4E09\\u5341\\u56DB\\u9EDE\\u4E94\\u516D\\u4E03" },
3136 { "zh_TW@numbers=finance", 1234.567, TRUE, "\\u58F9\\u4EDF\\u8CB3\\u4F70\\u53C3\\u62FE\\u8086\\u9EDE\\u4F0D\\u9678\\u67D2" },
3137 { NULL, 0, FALSE, NULL }
3138 };
3139
3140 UErrorCode ec;
3141
3142 const TestNumberingSystemItem *item;
3143 for (item = DATA; item->localeName != NULL; item++) {
3144 ec = U_ZERO_ERROR;
3145 Locale loc = Locale::createFromName(item->localeName);
3146
3147 NumberFormat *origFmt = NumberFormat::createInstance(loc,ec);
3148 if (U_FAILURE(ec)) {
3149 dataerrln("FAIL: getInstance(%s) - %s", item->localeName, u_errorName(ec));
3150 continue;
3151 }
3152 // Clone to test ticket #10682
3153 NumberFormat *fmt = (NumberFormat *) origFmt->clone();
3154 delete origFmt;
3155
3156
3157 if (item->isRBNF) {
3158 expect3(*fmt,item->value,CharsToUnicodeString(item->expectedResult));
3159 } else {
3160 expect2(*fmt,item->value,CharsToUnicodeString(item->expectedResult));
3161 }
3162 delete fmt;
3163 }
3164
3165
3166 // Test bogus keyword value
3167 ec = U_ZERO_ERROR;
3168 Locale loc4 = Locale::createFromName("en_US@numbers=foobar");
3169 NumberFormat* fmt4= NumberFormat::createInstance(loc4, ec);
3170 if ( ec != U_UNSUPPORTED_ERROR ) {
3171 errln("FAIL: getInstance(en_US@numbers=foobar) should have returned U_UNSUPPORTED_ERROR");
3172 delete fmt4;
3173 }
3174
3175 ec = U_ZERO_ERROR;
3176 NumberingSystem *ns = NumberingSystem::createInstance(ec);
3177 if (U_FAILURE(ec)) {
3178 dataerrln("FAIL: NumberingSystem::createInstance(ec); - %s", u_errorName(ec));
3179 }
3180
3181 if ( ns != NULL ) {
3182 ns->getDynamicClassID();
3183 ns->getStaticClassID();
3184 } else {
3185 errln("FAIL: getInstance() returned NULL.");
3186 }
3187
3188 NumberingSystem *ns1 = new NumberingSystem(*ns);
3189 if (ns1 == NULL) {
3190 errln("FAIL: NumberSystem copy constructor returned NULL.");
3191 }
3192
3193 delete ns1;
3194 delete ns;
3195
3196 }
3197
3198
3199 void
3200 NumberFormatTest::TestMultiCurrencySign() {
3201 const char* DATA[][6] = {
3202 // the fields in the following test are:
3203 // locale,
3204 // currency pattern (with negative pattern),
3205 // currency number to be formatted,
3206 // currency format using currency symbol name, such as "$" for USD,
3207 // currency format using currency ISO name, such as "USD",
3208 // currency format using plural name, such as "US dollars".
3209 // for US locale
3210 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "1234.56", "$1,234.56", "USD1,234.56", "US dollars1,234.56"},
3211 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "-1234.56", "-$1,234.56", "-USD1,234.56", "-US dollars1,234.56"},
3212 {"en_US", "\\u00A4#,##0.00;-\\u00A4#,##0.00", "1", "$1.00", "USD1.00", "US dollars1.00"},
3213 // for CHINA locale
3214 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "1234.56", "\\uFFE51,234.56", "CNY1,234.56", "\\u4EBA\\u6C11\\u5E011,234.56"},
3215 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "-1234.56", "(\\uFFE51,234.56)", "(CNY1,234.56)", "(\\u4EBA\\u6C11\\u5E011,234.56)"},
3216 {"zh_CN", "\\u00A4#,##0.00;(\\u00A4#,##0.00)", "1", "\\uFFE51.00", "CNY1.00", "\\u4EBA\\u6C11\\u5E011.00"}
3217 };
3218
3219 const UChar doubleCurrencySign[] = {0xA4, 0xA4, 0};
3220 UnicodeString doubleCurrencyStr(doubleCurrencySign);
3221 const UChar tripleCurrencySign[] = {0xA4, 0xA4, 0xA4, 0};
3222 UnicodeString tripleCurrencyStr(tripleCurrencySign);
3223
3224 for (uint32_t i=0; i<sizeof(DATA)/sizeof(DATA[0]); ++i) {
3225 const char* locale = DATA[i][0];
3226 UnicodeString pat = ctou(DATA[i][1]);
3227 double numberToBeFormat = atof(DATA[i][2]);
3228 UErrorCode status = U_ZERO_ERROR;
3229 DecimalFormatSymbols* sym = new DecimalFormatSymbols(Locale(locale), status);
3230 if (U_FAILURE(status)) {
3231 delete sym;
3232 continue;
3233 }
3234 for (int j=1; j<=3; ++j) {
3235 // j represents the number of currency sign in the pattern.
3236 if (j == 2) {
3237 pat = pat.findAndReplace(ctou("\\u00A4"), doubleCurrencyStr);
3238 } else if (j == 3) {
3239 pat = pat.findAndReplace(ctou("\\u00A4\\u00A4"), tripleCurrencyStr);
3240 }
3241
3242 DecimalFormat* fmt = new DecimalFormat(pat, new DecimalFormatSymbols(*sym), status);
3243 if (U_FAILURE(status)) {
3244 errln("FAILED init DecimalFormat ");
3245 delete fmt;
3246 continue;
3247 }
3248 UnicodeString s;
3249 ((NumberFormat*) fmt)->format(numberToBeFormat, s);
3250 // DATA[i][3] is the currency format result using a
3251 // single currency sign.
3252 // DATA[i][4] is the currency format result using
3253 // double currency sign.
3254 // DATA[i][5] is the currency format result using
3255 // triple currency sign.
3256 // DATA[i][j+2] is the currency format result using
3257 // 'j' number of currency sign.
3258 UnicodeString currencyFormatResult = ctou(DATA[i][2+j]);
3259 if (s.compare(currencyFormatResult)) {
3260 errln("FAIL format: Expected " + currencyFormatResult + "; Got " + s);
3261 }
3262 // mix style parsing
3263 for (int k=3; k<=5; ++k) {
3264 // DATA[i][3] is the currency format result using a
3265 // single currency sign.
3266 // DATA[i][4] is the currency format result using
3267 // double currency sign.
3268 // DATA[i][5] is the currency format result using
3269 // triple currency sign.
3270 UnicodeString oneCurrencyFormat = ctou(DATA[i][k]);
3271 UErrorCode status = U_ZERO_ERROR;
3272 Formattable parseRes;
3273 fmt->parse(oneCurrencyFormat, parseRes, status);
3274 if (U_FAILURE(status) ||
3275 (parseRes.getType() == Formattable::kDouble &&
3276 parseRes.getDouble() != numberToBeFormat) ||
3277 (parseRes.getType() == Formattable::kLong &&
3278 parseRes.getLong() != numberToBeFormat)) {
3279 errln("FAILED parse " + oneCurrencyFormat + "; (i, j, k): " +
3280 i + ", " + j + ", " + k);
3281 }
3282 }
3283 delete fmt;
3284 }
3285 delete sym;
3286 }
3287 }
3288
3289
3290 void
3291 NumberFormatTest::TestCurrencyFormatForMixParsing() {
3292 UErrorCode status = U_ZERO_ERROR;
3293 MeasureFormat* curFmt = MeasureFormat::createCurrencyFormat(Locale("en_US"), status);
3294 if (U_FAILURE(status)) {
3295 delete curFmt;
3296 return;
3297 }
3298 const char* formats[] = {
3299 "$1,234.56", // string to be parsed
3300 "USD1,234.56",
3301 "US dollars1,234.56",
3302 "1,234.56 US dollars"
3303 };
3304 const CurrencyAmount* curramt = NULL;
3305 for (uint32_t i = 0; i < sizeof(formats)/sizeof(formats[0]); ++i) {
3306 UnicodeString stringToBeParsed = ctou(formats[i]);
3307 logln(UnicodeString("stringToBeParsed: ") + stringToBeParsed);
3308 Formattable result;
3309 UErrorCode status = U_ZERO_ERROR;
3310 curFmt->parseObject(stringToBeParsed, result, status);
3311 if (U_FAILURE(status)) {
3312 errln("FAIL: measure format parsing: '%s' ec: %s", formats[i], u_errorName(status));
3313 } else if (result.getType() != Formattable::kObject ||
3314 (curramt = dynamic_cast<const CurrencyAmount*>(result.getObject())) == NULL ||
3315 curramt->getNumber().getDouble() != 1234.56 ||
3316 UnicodeString(curramt->getISOCurrency()).compare(ISO_CURRENCY_USD)
3317 ) {
3318 errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the number ");
3319 if (curramt->getNumber().getDouble() != 1234.56) {
3320 errln((UnicodeString)"wong number, expect: 1234.56" + ", got: " + curramt->getNumber().getDouble());
3321 }
3322 if (curramt->getISOCurrency() != ISO_CURRENCY_USD) {
3323 errln((UnicodeString)"wong currency, expect: USD" + ", got: " + curramt->getISOCurrency());
3324 }
3325 }
3326 }
3327 delete curFmt;
3328 }
3329
3330
3331 void
3332 NumberFormatTest::TestDecimalFormatCurrencyParse() {
3333 // Locale.US
3334 UErrorCode status = U_ZERO_ERROR;
3335 DecimalFormatSymbols* sym = new DecimalFormatSymbols(Locale("en_US"), status);
3336 if (U_FAILURE(status)) {
3337 delete sym;
3338 return;
3339 }
3340 UnicodeString pat;
3341 UChar currency = 0x00A4;
3342 // "\xA4#,##0.00;-\xA4#,##0.00"
3343 pat.append(currency).append(currency).append(currency).append("#,##0.00;-").append(currency).append(currency).append(currency).append("#,##0.00");
3344 DecimalFormat* fmt = new DecimalFormat(pat, sym, status);
3345 if (U_FAILURE(status)) {
3346 delete fmt;
3347 errln("failed to new DecimalFormat in TestDecimalFormatCurrencyParse");
3348 return;
3349 }
3350 const char* DATA[][2] = {
3351 // the data are:
3352 // string to be parsed, the parsed result (number)
3353 {"$1.00", "1"},
3354 {"USD1.00", "1"},
3355 {"1.00 US dollar", "1"},
3356 {"$1,234.56", "1234.56"},
3357 {"USD1,234.56", "1234.56"},
3358 {"1,234.56 US dollar", "1234.56"},
3359 };
3360 for (uint32_t i = 0; i < sizeof(DATA)/sizeof(DATA[0]); ++i) {
3361 UnicodeString stringToBeParsed = ctou(DATA[i][0]);
3362 double parsedResult = atof(DATA[i][1]);
3363 UErrorCode status = U_ZERO_ERROR;
3364 Formattable result;
3365 fmt->parse(stringToBeParsed, result, status);
3366 if (U_FAILURE(status) ||
3367 (result.getType() == Formattable::kDouble &&
3368 result.getDouble() != parsedResult) ||
3369 (result.getType() == Formattable::kLong &&
3370 result.getLong() != parsedResult)) {
3371 errln((UnicodeString)"FAIL parse: Expected " + parsedResult);
3372 }
3373 }
3374 delete fmt;
3375 }
3376
3377
3378 void
3379 NumberFormatTest::TestCurrencyIsoPluralFormat() {
3380 static const char* DATA[][6] = {
3381 // the data are:
3382 // locale,
3383 // currency amount to be formatted,
3384 // currency ISO code to be formatted,
3385 // format result using CURRENCYSTYLE,
3386 // format result using ISOCURRENCYSTYLE,
3387 // format result using PLURALCURRENCYSTYLE,
3388
3389 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollars"},
3390 {"en_US", "1234.56", "USD", "$1,234.56", "USD1,234.56", "1,234.56 US dollars"},
3391 {"en_US", "-1234.56", "USD", "-$1,234.56", "-USD1,234.56", "-1,234.56 US dollars"},
3392 {"zh_CN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00\\u7F8E\\u5143"},
3393 {"zh_CN", "1234.56", "USD", "US$\\u00A01,234.56", "USD\\u00A01,234.56", "1,234.56\\u7F8E\\u5143"},
3394 // wrong ISO code {"zh_CN", "1", "CHY", "CHY1.00", "CHY1.00", "1.00 CHY"},
3395 // wrong ISO code {"zh_CN", "1234.56", "CHY", "CHY1,234.56", "CHY1,234.56", "1,234.56 CHY"},
3396 {"zh_CN", "1", "CNY", "\\uFFE5\\u00A01.00", "CNY\\u00A01.00", "1.00\\u4EBA\\u6C11\\u5E01"},
3397 {"zh_CN", "1234.56", "CNY", "\\uFFE5\\u00A01,234.56", "CNY\\u00A01,234.56", "1,234.56\\u4EBA\\u6C11\\u5E01"},
3398 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u20BD", "1,00\\u00A0RUB", "1,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3399 {"ru_RU", "2", "RUB", "2,00\\u00A0\\u20BD", "2,00\\u00A0RUB", "2,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3400 {"ru_RU", "5", "RUB", "5,00\\u00A0\\u20BD", "5,00\\u00A0RUB", "5,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"},
3401 // test locale without currency information
3402 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 USD"},
3403 // test choice format
3404 {"es_AR", "1", "INR", "INR1,00", "INR1,00", "1,00 rupia india"},
3405 };
3406 static const UNumberFormatStyle currencyStyles[] = {
3407 UNUM_CURRENCY,
3408 UNUM_CURRENCY_ISO,
3409 UNUM_CURRENCY_PLURAL
3410 };
3411
3412 for (int32_t i=0; i<UPRV_LENGTHOF(DATA); ++i) {
3413 for (int32_t kIndex = 0; kIndex < UPRV_LENGTHOF(currencyStyles); ++kIndex) {
3414 UNumberFormatStyle k = currencyStyles[kIndex];
3415 const char* localeString = DATA[i][0];
3416 double numberToBeFormat = atof(DATA[i][1]);
3417 const char* currencyISOCode = DATA[i][2];
3418 Locale locale(localeString);
3419 UErrorCode status = U_ZERO_ERROR;
3420 NumberFormat* numFmt = NumberFormat::createInstance(locale, k, status);
3421 if (U_FAILURE(status)) {
3422 delete numFmt;
3423 dataerrln((UnicodeString)"can not create instance, locale:" + localeString + ", style: " + k + " - " + u_errorName(status));
3424 continue;
3425 }
3426 UChar currencyCode[4];
3427 u_charsToUChars(currencyISOCode, currencyCode, 4);
3428 numFmt->setCurrency(currencyCode, status);
3429 if (U_FAILURE(status)) {
3430 delete numFmt;
3431 errln((UnicodeString)"can not set currency:" + currencyISOCode);
3432 continue;
3433 }
3434
3435 UnicodeString strBuf;
3436 numFmt->format(numberToBeFormat, strBuf);
3437 int resultDataIndex = 3 + kIndex;
3438 // DATA[i][resultDataIndex] is the currency format result
3439 // using 'k' currency style.
3440 UnicodeString formatResult = ctou(DATA[i][resultDataIndex]);
3441 if (strBuf.compare(formatResult)) {
3442 errln("FAIL: Expected " + formatResult + " actual: " + strBuf);
3443 }
3444 // test parsing, and test parsing for all currency formats.
3445 for (int j = 3; j < 6; ++j) {
3446 // DATA[i][3] is the currency format result using
3447 // CURRENCYSTYLE formatter.
3448 // DATA[i][4] is the currency format result using
3449 // ISOCURRENCYSTYLE formatter.
3450 // DATA[i][5] is the currency format result using
3451 // PLURALCURRENCYSTYLE formatter.
3452 UnicodeString oneCurrencyFormatResult = ctou(DATA[i][j]);
3453 UErrorCode status = U_ZERO_ERROR;
3454 Formattable parseResult;
3455 numFmt->parse(oneCurrencyFormatResult, parseResult, status);
3456 if (U_FAILURE(status) ||
3457 (parseResult.getType() == Formattable::kDouble &&
3458 parseResult.getDouble() != numberToBeFormat) ||
3459 (parseResult.getType() == Formattable::kLong &&
3460 parseResult.getLong() != numberToBeFormat)) {
3461 errln((UnicodeString)"FAIL: getCurrencyFormat of locale " +
3462 localeString + " failed roundtripping the number");
3463 if (parseResult.getType() == Formattable::kDouble) {
3464 errln((UnicodeString)"expected: " + numberToBeFormat + "; actual: " +parseResult.getDouble());
3465 } else {
3466 errln((UnicodeString)"expected: " + numberToBeFormat + "; actual: " +parseResult.getLong());
3467 }
3468 }
3469 }
3470 delete numFmt;
3471 }
3472 }
3473 }
3474
3475 void
3476 NumberFormatTest::TestCurrencyParsing() {
3477 static const char* DATA[][6] = {
3478 // the data are:
3479 // locale,
3480 // currency amount to be formatted,
3481 // currency ISO code to be formatted,
3482 // format result using CURRENCYSTYLE,
3483 // format result using ISOCURRENCYSTYLE,
3484 // format result using PLURALCURRENCYSTYLE,
3485 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollar"},
3486 {"pa_IN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00 \\u0a2f\\u0a42.\\u0a10\\u0a38. \\u0a21\\u0a3e\\u0a32\\u0a30"},
3487 {"es_AR", "1", "USD", "US$1,00", "USD1,00", "1,00 d\\u00f3lar estadounidense"},
3488 {"ar_EG", "1", "USD", "\\u0661\\u066b\\u0660\\u0660\\u00a0US$", "\\u0661\\u066b\\u0660\\u0660\\u00a0USD", "\\u0661\\u066b\\u0660\\u0660 \\u062f\\u0648\\u0644\\u0627\\u0631 \\u0623\\u0645\\u0631\\u064a\\u0643\\u064a"},
3489 {"fa_CA", "1", "USD", "\\u200e$\\u06f1\\u066b\\u06f0\\u06f0", "\\u200eUSD\\u06f1\\u066b\\u06f0\\u06f0", "\\u200e\\u062f\\u0644\\u0627\\u0631 \\u0627\\u0645\\u0631\\u06cc\\u06a9\\u0627\\u06f1\\u066b\\u06f0\\u06f0"},
3490 {"he_IL", "1", "USD", "1.00\\u00a0$", "1.00\\u00a0USD", "1.00 \\u05d3\\u05d5\\u05dc\\u05e8 \\u05d0\\u05de\\u05e8\\u05d9\\u05e7\\u05d0\\u05d9"},
3491 {"hr_HR", "1", "USD", "1,00\\u00a0USD", "1,00\\u00a0USD", "1,00 Ameri\\u010dki dolar"},
3492 {"id_ID", "1", "USD", "US$1,00", "USD1,00", "1,00 Dolar Amerika Serikat"},
3493 {"it_IT", "1", "USD", "1,00\\u00a0US$", "1,00\\u00a0USD", "1,00 Dollaro Statunitense"},
3494 {"ko_KR", "1", "USD", "US$1.00", "USD1.00", "1.00\\ubbf8\\uad6d \\ub2ec\\ub7ec"},
3495 {"ja_JP", "1", "USD", "$1.00", "USD1.00", "1.00\\u7c73\\u30c9\\u30eb"},
3496 {"zh_CN", "1", "CNY", "\\uFFE5\\u00a01.00", "CNY\\u00a01.00", "1.00\\u4EBA\\u6C11\\u5E01"},
3497 {"zh_TW", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\u5e63"},
3498 {"zh_Hant", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\u5e63"},
3499 {"zh_Hant", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u5713"},
3500 {"ja_JP", "1", "JPY", "\\uFFE51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u5186"},
3501 {"ja_JP", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00\\u65e5\\u672c\\u5186"},
3502 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u20BD", "1,00\\u00A0RUB", "1,00 \\u0420\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u0438\\u0439 \\u0440\\u0443\\u0431\\u043B\\u044C"}
3503 };
3504 static const UNumberFormatStyle currencyStyles[] = {
3505 UNUM_CURRENCY,
3506 UNUM_CURRENCY_ISO,
3507 UNUM_CURRENCY_PLURAL
3508 };
3509 static const char* currencyStyleNames[] = {
3510 "UNUM_CURRENCY",
3511 "UNUM_CURRENCY_ISO",
3512 "UNUM_CURRENCY_PLURAL"
3513 };
3514
3515 #ifdef NUMFMTST_CACHE_DEBUG
3516 int deadloop = 0;
3517 for (;;) {
3518 printf("loop: %d\n", deadloop++);
3519 #endif
3520 for (uint32_t i=0; i< sizeof(DATA)/sizeof(DATA[0]); ++i) { /* i = test case # - should be i=0*/
3521 for (int32_t kIndex = 2; kIndex < UPRV_LENGTHOF(currencyStyles); ++kIndex) {
3522 UNumberFormatStyle k = currencyStyles[kIndex]; /* k = style */
3523 const char* localeString = DATA[i][0];
3524 double numberToBeFormat = atof(DATA[i][1]);
3525 const char* currencyISOCode = DATA[i][2];
3526 Locale locale(localeString);
3527 UErrorCode status = U_ZERO_ERROR;
3528 NumberFormat* numFmt = NumberFormat::createInstance(locale, k, status);
3529 logln("#%d NumberFormat(%s, %s) Currency=%s\n",
3530 i, localeString, currencyStyleNames[kIndex],
3531 currencyISOCode);
3532
3533 if (U_FAILURE(status)) {
3534 delete numFmt;
3535 dataerrln((UnicodeString)"can not create instance, locale:" + localeString + ", style: " + k + " - " + u_errorName(status));
3536 continue;
3537 }
3538 UChar currencyCode[4];
3539 u_charsToUChars(currencyISOCode, currencyCode, 4);
3540 numFmt->setCurrency(currencyCode, status);
3541 if (U_FAILURE(status)) {
3542 delete numFmt;
3543 errln((UnicodeString)"can not set currency:" + currencyISOCode);
3544 continue;
3545 }
3546
3547 UnicodeString strBuf;
3548 numFmt->format(numberToBeFormat, strBuf);
3549 /*
3550 int resultDataIndex = 3 + kIndex;
3551 // DATA[i][resultDataIndex] is the currency format result
3552 // using 'k' currency style.
3553 UnicodeString formatResult = ctou(DATA[i][resultDataIndex]);
3554 if (strBuf.compare(formatResult)) {
3555 errln("FAIL: Expected " + formatResult + " actual: " + strBuf);
3556 }
3557 */
3558 // test parsing, and test parsing for all currency formats.
3559 for (int j = 3; j < 6; ++j) {
3560 // DATA[i][3] is the currency format result using
3561 // CURRENCYSTYLE formatter.
3562 // DATA[i][4] is the currency format result using
3563 // ISOCURRENCYSTYLE formatter.
3564 // DATA[i][5] is the currency format result using
3565 // PLURALCURRENCYSTYLE formatter.
3566 UnicodeString oneCurrencyFormatResult = ctou(DATA[i][j]);
3567 UErrorCode status = U_ZERO_ERROR;
3568 Formattable parseResult;
3569 logln("parse(%s)", DATA[i][j]);
3570 numFmt->parse(oneCurrencyFormatResult, parseResult, status);
3571 if (U_FAILURE(status) ||
3572 (parseResult.getType() == Formattable::kDouble &&
3573 parseResult.getDouble() != numberToBeFormat) ||
3574 (parseResult.getType() == Formattable::kLong &&
3575 parseResult.getLong() != numberToBeFormat)) {
3576 errln((UnicodeString)"FAIL: NumberFormat(" + localeString +", " + currencyStyleNames[kIndex] +
3577 "), Currency="+currencyISOCode+", parse("+DATA[i][j]+") returned error " + (UnicodeString)u_errorName(status)+". Testcase: data[" + i + "][" + currencyStyleNames[j-3] +"="+j+"]");
3578 if (parseResult.getType() == Formattable::kDouble) {
3579 errln((UnicodeString)"expected: " + numberToBeFormat + "; actual (double): " +parseResult.getDouble());
3580 } else {
3581 errln((UnicodeString)"expected: " + numberToBeFormat + "; actual (long): " +parseResult.getLong());
3582 }
3583 errln((UnicodeString)" round-trip would be: " + strBuf);
3584 }
3585 }
3586 delete numFmt;
3587 }
3588 }
3589 #ifdef NUMFMTST_CACHE_DEBUG
3590 }
3591 #endif
3592 }
3593
3594
3595 void
3596 NumberFormatTest::TestParseCurrencyInUCurr() {
3597 const char* DATA[] = {
3598 "1.00 US DOLLAR", // case in-sensitive
3599 "$1.00",
3600 "USD1.00",
3601 "US dollar1.00",
3602 "US dollars1.00",
3603 "$1.00",
3604 "A$1.00",
3605 "ADP1.00",
3606 "ADP1.00",
3607 "AED1.00",
3608 "AED1.00",
3609 "AFA1.00",
3610 "AFA1.00",
3611 "AFN1.00",
3612 "ALL1.00",
3613 "AMD1.00",
3614 "ANG1.00",
3615 "AOA1.00",
3616 "AOK1.00",
3617 "AOK1.00",
3618 "AON1.00",
3619 "AON1.00",
3620 "AOR1.00",
3621 "AOR1.00",
3622 "ARS1.00",
3623 "ARA1.00",
3624 "ARA1.00",
3625 "ARP1.00",
3626 "ARP1.00",
3627 "ARS1.00",
3628 "ATS1.00",
3629 "ATS1.00",
3630 "AUD1.00",
3631 "AWG1.00",
3632 "AZM1.00",
3633 "AZM1.00",
3634 "AZN1.00",
3635 "Afghan Afghani (1927\\u20132002)1.00",
3636 "Afghan afghani (1927\\u20132002)1.00",
3637 "Afghan Afghani1.00",
3638 "Afghan Afghanis1.00",
3639 "Albanian Lek1.00",
3640 "Albanian lek1.00",
3641 "Albanian lek\\u00eb1.00",
3642 "Algerian Dinar1.00",
3643 "Algerian dinar1.00",
3644 "Algerian dinars1.00",
3645 "Andorran Peseta1.00",
3646 "Andorran peseta1.00",
3647 "Andorran pesetas1.00",
3648 "Angolan Kwanza (1977\\u20131991)1.00",
3649 "Angolan Readjusted Kwanza (1995\\u20131999)1.00",
3650 "Angolan Kwanza1.00",
3651 "Angolan New Kwanza (1990\\u20132000)1.00",
3652 "Angolan kwanza (1977\\u20131991)1.00",
3653 "Angolan readjusted kwanza (1995\\u20131999)1.00",
3654 "Angolan kwanza1.00",
3655 "Angolan kwanzas (1977\\u20131991)1.00",
3656 "Angolan readjusted kwanzas (1995\\u20131999)1.00",
3657 "Angolan kwanzas1.00",
3658 "Angolan new kwanza (1990\\u20132000)1.00",
3659 "Angolan new kwanzas (1990\\u20132000)1.00",
3660 "Argentine Austral1.00",
3661 "Argentine Peso (1983\\u20131985)1.00",
3662 "Argentine Peso1.00",
3663 "Argentine austral1.00",
3664 "Argentine australs1.00",
3665 "Argentine peso (1983\\u20131985)1.00",
3666 "Argentine peso1.00",
3667 "Argentine pesos (1983\\u20131985)1.00",
3668 "Argentine pesos1.00",
3669 "Armenian Dram1.00",
3670 "Armenian dram1.00",
3671 "Armenian drams1.00",
3672 "Aruban Florin1.00",
3673 "Aruban florin1.00",
3674 "Australian Dollar1.00",
3675 "Australian dollar1.00",
3676 "Australian dollars1.00",
3677 "Austrian Schilling1.00",
3678 "Austrian schilling1.00",
3679 "Austrian schillings1.00",
3680 "Azerbaijani Manat (1993\\u20132006)1.00",
3681 "Azerbaijani Manat1.00",
3682 "Azerbaijani manat (1993\\u20132006)1.00",
3683 "Azerbaijani manat1.00",
3684 "Azerbaijani manats (1993\\u20132006)1.00",
3685 "Azerbaijani manats1.00",
3686 "BAD1.00",
3687 "BAD1.00",
3688 "BAM1.00",
3689 "BBD1.00",
3690 "BDT1.00",
3691 "BEC1.00",
3692 "BEC1.00",
3693 "BEF1.00",
3694 "BEL1.00",
3695 "BEL1.00",
3696 "BGL1.00",
3697 "BGN1.00",
3698 "BGN1.00",
3699 "BHD1.00",
3700 "BIF1.00",
3701 "BMD1.00",
3702 "BND1.00",
3703 "BOB1.00",
3704 "BOP1.00",
3705 "BOP1.00",
3706 "BOV1.00",
3707 "BOV1.00",
3708 "BRB1.00",
3709 "BRB1.00",
3710 "BRC1.00",
3711 "BRC1.00",
3712 "BRE1.00",
3713 "BRE1.00",
3714 "BRL1.00",
3715 "BRN1.00",
3716 "BRN1.00",
3717 "BRR1.00",
3718 "BRR1.00",
3719 "BSD1.00",
3720 "BSD1.00",
3721 "BTN1.00",
3722 "BUK1.00",
3723 "BUK1.00",
3724 "BWP1.00",
3725 "BYB1.00",
3726 "BYB1.00",
3727 "BYR1.00",
3728 "BZD1.00",
3729 "Bahamian Dollar1.00",
3730 "Bahamian dollar1.00",
3731 "Bahamian dollars1.00",
3732 "Bahraini Dinar1.00",
3733 "Bahraini dinar1.00",
3734 "Bahraini dinars1.00",
3735 "Bangladeshi Taka1.00",
3736 "Bangladeshi taka1.00",
3737 "Bangladeshi takas1.00",
3738 "Barbadian Dollar1.00",
3739 "Barbadian dollar1.00",
3740 "Barbadian dollars1.00",
3741 "Belarusian New Ruble (1994\\u20131999)1.00",
3742 "Belarusian Ruble1.00",
3743 "Belarusian new ruble (1994\\u20131999)1.00",
3744 "Belarusian new rubles (1994\\u20131999)1.00",
3745 "Belarusian ruble1.00",
3746 "Belarusian rubles1.00",
3747 "Belgian Franc (convertible)1.00",
3748 "Belgian Franc (financial)1.00",
3749 "Belgian Franc1.00",
3750 "Belgian franc (convertible)1.00",
3751 "Belgian franc (financial)1.00",
3752 "Belgian franc1.00",
3753 "Belgian francs (convertible)1.00",
3754 "Belgian francs (financial)1.00",
3755 "Belgian francs1.00",
3756 "Belize Dollar1.00",
3757 "Belize dollar1.00",
3758 "Belize dollars1.00",
3759 "Bermudan Dollar1.00",
3760 "Bermudan dollar1.00",
3761 "Bermudan dollars1.00",
3762 "Bhutanese Ngultrum1.00",
3763 "Bhutanese ngultrum1.00",
3764 "Bhutanese ngultrums1.00",
3765 "Bolivian Mvdol1.00",
3766 "Bolivian Peso1.00",
3767 "Bolivian mvdol1.00",
3768 "Bolivian mvdols1.00",
3769 "Bolivian peso1.00",
3770 "Bolivian pesos1.00",
3771 "Bolivian Boliviano1.00",
3772 "Bolivian Boliviano1.00",
3773 "Bolivian Bolivianos1.00",
3774 "Bosnia-Herzegovina Convertible Mark1.00",
3775 "Bosnia-Herzegovina Dinar (1992\\u20131994)1.00",
3776 "Bosnia-Herzegovina convertible mark1.00",
3777 "Bosnia-Herzegovina convertible marks1.00",
3778 "Bosnia-Herzegovina dinar (1992\\u20131994)1.00",
3779 "Bosnia-Herzegovina dinars (1992\\u20131994)1.00",
3780 "Botswanan Pula1.00",
3781 "Botswanan pula1.00",
3782 "Botswanan pulas1.00",
3783 "Brazilian New Cruzado (1989\\u20131990)1.00",
3784 "Brazilian Cruzado (1986\\u20131989)1.00",
3785 "Brazilian Cruzeiro (1990\\u20131993)1.00",
3786 "Brazilian New Cruzeiro (1967\\u20131986)1.00",
3787 "Brazilian Cruzeiro (1993\\u20131994)1.00",
3788 "Brazilian Real1.00",
3789 "Brazilian new cruzado (1989\\u20131990)1.00",
3790 "Brazilian new cruzados (1989\\u20131990)1.00",
3791 "Brazilian cruzado (1986\\u20131989)1.00",
3792 "Brazilian cruzados (1986\\u20131989)1.00",
3793 "Brazilian cruzeiro (1990\\u20131993)1.00",
3794 "Brazilian new cruzeiro (1967\\u20131986)1.00",
3795 "Brazilian cruzeiro (1993\\u20131994)1.00",
3796 "Brazilian cruzeiros (1990\\u20131993)1.00",
3797 "Brazilian new cruzeiros (1967\\u20131986)1.00",
3798 "Brazilian cruzeiros (1993\\u20131994)1.00",
3799 "Brazilian real1.00",
3800 "Brazilian reals1.00",
3801 "British Pound1.00",
3802 "British pound1.00",
3803 "British pounds1.00",
3804 "Brunei Dollar1.00",
3805 "Brunei dollar1.00",
3806 "Brunei dollars1.00",
3807 "Bulgarian Hard Lev1.00",
3808 "Bulgarian Lev1.00",
3809 "Bulgarian Leva1.00",
3810 "Bulgarian hard lev1.00",
3811 "Bulgarian hard leva1.00",
3812 "Bulgarian lev1.00",
3813 "Burmese Kyat1.00",
3814 "Burmese kyat1.00",
3815 "Burmese kyats1.00",
3816 "Burundian Franc1.00",
3817 "Burundian franc1.00",
3818 "Burundian francs1.00",
3819 "CA$1.00",
3820 "CAD1.00",
3821 "CDF1.00",
3822 "CDF1.00",
3823 "West African CFA Franc1.00",
3824 "Central African CFA Franc1.00",
3825 "West African CFA franc1.00",
3826 "Central African CFA franc1.00",
3827 "West African CFA francs1.00",
3828 "Central African CFA francs1.00",
3829 "CFP Franc1.00",
3830 "CFP franc1.00",
3831 "CFP francs1.00",
3832 "CFPF1.00",
3833 "CHE1.00",
3834 "CHE1.00",
3835 "CHF1.00",
3836 "CHW1.00",
3837 "CHW1.00",
3838 "CLF1.00",
3839 "CLF1.00",
3840 "CLP1.00",
3841 "CNY1.00",
3842 "COP1.00",
3843 "COU1.00",
3844 "COU1.00",
3845 "CRC1.00",
3846 "CSD1.00",
3847 "CSD1.00",
3848 "CSK1.00",
3849 "CSK1.00",
3850 "CUP1.00",
3851 "CUP1.00",
3852 "CVE1.00",
3853 "CYP1.00",
3854 "CZK1.00",
3855 "Cambodian Riel1.00",
3856 "Cambodian riel1.00",
3857 "Cambodian riels1.00",
3858 "Canadian Dollar1.00",
3859 "Canadian dollar1.00",
3860 "Canadian dollars1.00",
3861 "Cape Verdean Escudo1.00",
3862 "Cape Verdean escudo1.00",
3863 "Cape Verdean escudos1.00",
3864 "Cayman Islands Dollar1.00",
3865 "Cayman Islands dollar1.00",
3866 "Cayman Islands dollars1.00",
3867 "Chilean Peso1.00",
3868 "Chilean Unit of Account (UF)1.00",
3869 "Chilean peso1.00",
3870 "Chilean pesos1.00",
3871 "Chilean unit of account (UF)1.00",
3872 "Chilean units of account (UF)1.00",
3873 "Chinese Yuan1.00",
3874 "Chinese yuan1.00",
3875 "Colombian Peso1.00",
3876 "Colombian peso1.00",
3877 "Colombian pesos1.00",
3878 "Comorian Franc1.00",
3879 "Comorian franc1.00",
3880 "Comorian francs1.00",
3881 "Congolese Franc1.00",
3882 "Congolese franc1.00",
3883 "Congolese francs1.00",
3884 "Costa Rican Col\\u00f3n1.00",
3885 "Costa Rican col\\u00f3n1.00",
3886 "Costa Rican col\\u00f3ns1.00",
3887 "Croatian Dinar1.00",
3888 "Croatian Kuna1.00",
3889 "Croatian dinar1.00",
3890 "Croatian dinars1.00",
3891 "Croatian kuna1.00",
3892 "Croatian kunas1.00",
3893 "Cuban Peso1.00",
3894 "Cuban peso1.00",
3895 "Cuban pesos1.00",
3896 "Cypriot Pound1.00",
3897 "Cypriot pound1.00",
3898 "Cypriot pounds1.00",
3899 "Czech Republic Koruna1.00",
3900 "Czech Republic koruna1.00",
3901 "Czech Republic korunas1.00",
3902 "Czechoslovak Hard Koruna1.00",
3903 "Czechoslovak hard koruna1.00",
3904 "Czechoslovak hard korunas1.00",
3905 "DDM1.00",
3906 "DDM1.00",
3907 "DEM1.00",
3908 "DEM1.00",
3909 "DJF1.00",
3910 "DKK1.00",
3911 "DOP1.00",
3912 "DZD1.00",
3913 "Danish Krone1.00",
3914 "Danish krone1.00",
3915 "Danish kroner1.00",
3916 "German Mark1.00",
3917 "German mark1.00",
3918 "German marks1.00",
3919 "Djiboutian Franc1.00",
3920 "Djiboutian franc1.00",
3921 "Djiboutian francs1.00",
3922 "Dominican Peso1.00",
3923 "Dominican peso1.00",
3924 "Dominican pesos1.00",
3925 "EC$1.00",
3926 "ECS1.00",
3927 "ECS1.00",
3928 "ECV1.00",
3929 "ECV1.00",
3930 "EEK1.00",
3931 "EEK1.00",
3932 "EGP1.00",
3933 "EGP1.00",
3934 "ERN1.00",
3935 "ERN1.00",
3936 "ESA1.00",
3937 "ESA1.00",
3938 "ESB1.00",
3939 "ESB1.00",
3940 "ESP1.00",
3941 "ETB1.00",
3942 "EUR1.00",
3943 "East Caribbean Dollar1.00",
3944 "East Caribbean dollar1.00",
3945 "East Caribbean dollars1.00",
3946 "East German Mark1.00",
3947 "East German mark1.00",
3948 "East German marks1.00",
3949 "Ecuadorian Sucre1.00",
3950 "Ecuadorian Unit of Constant Value1.00",
3951 "Ecuadorian sucre1.00",
3952 "Ecuadorian sucres1.00",
3953 "Ecuadorian unit of constant value1.00",
3954 "Ecuadorian units of constant value1.00",
3955 "Egyptian Pound1.00",
3956 "Egyptian pound1.00",
3957 "Egyptian pounds1.00",
3958 "Salvadoran Col\\u00f3n1.00",
3959 "Salvadoran col\\u00f3n1.00",
3960 "Salvadoran colones1.00",
3961 "Equatorial Guinean Ekwele1.00",
3962 "Equatorial Guinean ekwele1.00",
3963 "Eritrean Nakfa1.00",
3964 "Eritrean nakfa1.00",
3965 "Eritrean nakfas1.00",
3966 "Estonian Kroon1.00",
3967 "Estonian kroon1.00",
3968 "Estonian kroons1.00",
3969 "Ethiopian Birr1.00",
3970 "Ethiopian birr1.00",
3971 "Ethiopian birrs1.00",
3972 "Euro1.00",
3973 "European Composite Unit1.00",
3974 "European Currency Unit1.00",
3975 "European Monetary Unit1.00",
3976 "European Unit of Account (XBC)1.00",
3977 "European Unit of Account (XBD)1.00",
3978 "European composite unit1.00",
3979 "European composite units1.00",
3980 "European currency unit1.00",
3981 "European currency units1.00",
3982 "European monetary unit1.00",
3983 "European monetary units1.00",
3984 "European unit of account (XBC)1.00",
3985 "European unit of account (XBD)1.00",
3986 "European units of account (XBC)1.00",
3987 "European units of account (XBD)1.00",
3988 "FIM1.00",
3989 "FIM1.00",
3990 "FJD1.00",
3991 "FKP1.00",
3992 "FKP1.00",
3993 "FRF1.00",
3994 "FRF1.00",
3995 "Falkland Islands Pound1.00",
3996 "Falkland Islands pound1.00",
3997 "Falkland Islands pounds1.00",
3998 "Fijian Dollar1.00",
3999 "Fijian dollar1.00",
4000 "Fijian dollars1.00",
4001 "Finnish Markka1.00",
4002 "Finnish markka1.00",
4003 "Finnish markkas1.00",
4004 "CHF1.00",
4005 "French Franc1.00",
4006 "French Gold Franc1.00",
4007 "French UIC-Franc1.00",
4008 "French UIC-franc1.00",
4009 "French UIC-francs1.00",
4010 "French franc1.00",
4011 "French francs1.00",
4012 "French gold franc1.00",
4013 "French gold francs1.00",
4014 "GBP1.00",
4015 "GEK1.00",
4016 "GEK1.00",
4017 "GEL1.00",
4018 "GHC1.00",
4019 "GHC1.00",
4020 "GHS1.00",
4021 "GIP1.00",
4022 "GIP1.00",
4023 "GMD1.00",
4024 "GMD1.00",
4025 "GNF1.00",
4026 "GNS1.00",
4027 "GNS1.00",
4028 "GQE1.00",
4029 "GQE1.00",
4030 "GRD1.00",
4031 "GRD1.00",
4032 "GTQ1.00",
4033 "GWE1.00",
4034 "GWE1.00",
4035 "GWP1.00",
4036 "GWP1.00",
4037 "GYD1.00",
4038 "Gambian Dalasi1.00",
4039 "Gambian dalasi1.00",
4040 "Gambian dalasis1.00",
4041 "Georgian Kupon Larit1.00",
4042 "Georgian Lari1.00",
4043 "Georgian kupon larit1.00",
4044 "Georgian kupon larits1.00",
4045 "Georgian lari1.00",
4046 "Georgian laris1.00",
4047 "Ghanaian Cedi (1979\\u20132007)1.00",
4048 "Ghanaian Cedi1.00",
4049 "Ghanaian cedi (1979\\u20132007)1.00",
4050 "Ghanaian cedi1.00",
4051 "Ghanaian cedis (1979\\u20132007)1.00",
4052 "Ghanaian cedis1.00",
4053 "Gibraltar Pound1.00",
4054 "Gibraltar pound1.00",
4055 "Gibraltar pounds1.00",
4056 "Gold1.00",
4057 "Gold1.00",
4058 "Greek Drachma1.00",
4059 "Greek drachma1.00",
4060 "Greek drachmas1.00",
4061 "Guatemalan Quetzal1.00",
4062 "Guatemalan quetzal1.00",
4063 "Guatemalan quetzals1.00",
4064 "Guinean Franc1.00",
4065 "Guinean Syli1.00",
4066 "Guinean franc1.00",
4067 "Guinean francs1.00",
4068 "Guinean syli1.00",
4069 "Guinean sylis1.00",
4070 "Guinea-Bissau Peso1.00",
4071 "Guinea-Bissau peso1.00",
4072 "Guinea-Bissau pesos1.00",
4073 "Guyanaese Dollar1.00",
4074 "Guyanaese dollar1.00",
4075 "Guyanaese dollars1.00",
4076 "HK$1.00",
4077 "HKD1.00",
4078 "HNL1.00",
4079 "HRD1.00",
4080 "HRD1.00",
4081 "HRK1.00",
4082 "HRK1.00",
4083 "HTG1.00",
4084 "HTG1.00",
4085 "HUF1.00",
4086 "Haitian Gourde1.00",
4087 "Haitian gourde1.00",
4088 "Haitian gourdes1.00",
4089 "Honduran Lempira1.00",
4090 "Honduran lempira1.00",
4091 "Honduran lempiras1.00",
4092 "Hong Kong Dollar1.00",
4093 "Hong Kong dollar1.00",
4094 "Hong Kong dollars1.00",
4095 "Hungarian Forint1.00",
4096 "Hungarian forint1.00",
4097 "Hungarian forints1.00",
4098 "IDR1.00",
4099 "IEP1.00",
4100 "ILP1.00",
4101 "ILP1.00",
4102 "ILS1.00",
4103 "INR1.00",
4104 "IQD1.00",
4105 "IRR1.00",
4106 "ISK1.00",
4107 "ISK1.00",
4108 "ITL1.00",
4109 "Icelandic Kr\\u00f3na1.00",
4110 "Icelandic kr\\u00f3na1.00",
4111 "Icelandic kr\\u00f3nur1.00",
4112 "Indian Rupee1.00",
4113 "Indian rupee1.00",
4114 "Indian rupees1.00",
4115 "Indonesian Rupiah1.00",
4116 "Indonesian rupiah1.00",
4117 "Indonesian rupiahs1.00",
4118 "Iranian Rial1.00",
4119 "Iranian rial1.00",
4120 "Iranian rials1.00",
4121 "Iraqi Dinar1.00",
4122 "Iraqi dinar1.00",
4123 "Iraqi dinars1.00",
4124 "Irish Pound1.00",
4125 "Irish pound1.00",
4126 "Irish pounds1.00",
4127 "Israeli Pound1.00",
4128 "Israeli new sheqel1.00",
4129 "Israeli pound1.00",
4130 "Israeli pounds1.00",
4131 "Italian Lira1.00",
4132 "Italian lira1.00",
4133 "Italian liras1.00",
4134 "JMD1.00",
4135 "JOD1.00",
4136 "JPY1.00",
4137 "Jamaican Dollar1.00",
4138 "Jamaican dollar1.00",
4139 "Jamaican dollars1.00",
4140 "Japanese Yen1.00",
4141 "Japanese yen1.00",
4142 "Jordanian Dinar1.00",
4143 "Jordanian dinar1.00",
4144 "Jordanian dinars1.00",
4145 "KES1.00",
4146 "KGS1.00",
4147 "KHR1.00",
4148 "KMF1.00",
4149 "KPW1.00",
4150 "KPW1.00",
4151 "KRW1.00",
4152 "KWD1.00",
4153 "KYD1.00",
4154 "KYD1.00",
4155 "KZT1.00",
4156 "Kazakhstani Tenge1.00",
4157 "Kazakhstani tenge1.00",
4158 "Kazakhstani tenges1.00",
4159 "Kenyan Shilling1.00",
4160 "Kenyan shilling1.00",
4161 "Kenyan shillings1.00",
4162 "Kuwaiti Dinar1.00",
4163 "Kuwaiti dinar1.00",
4164 "Kuwaiti dinars1.00",
4165 "Kyrgystani Som1.00",
4166 "Kyrgystani som1.00",
4167 "Kyrgystani soms1.00",
4168 "HNL1.00",
4169 "LAK1.00",
4170 "LAK1.00",
4171 "LBP1.00",
4172 "LKR1.00",
4173 "LRD1.00",
4174 "LRD1.00",
4175 "LSL1.00",
4176 "LTL1.00",
4177 "LTL1.00",
4178 "LTT1.00",
4179 "LTT1.00",
4180 "LUC1.00",
4181 "LUC1.00",
4182 "LUF1.00",
4183 "LUF1.00",
4184 "LUL1.00",
4185 "LUL1.00",
4186 "LVL1.00",
4187 "LVL1.00",
4188 "LVR1.00",
4189 "LVR1.00",
4190 "LYD1.00",
4191 "Laotian Kip1.00",
4192 "Laotian kip1.00",
4193 "Laotian kips1.00",
4194 "Latvian Lats1.00",
4195 "Latvian Ruble1.00",
4196 "Latvian lats1.00",
4197 "Latvian lati1.00",
4198 "Latvian ruble1.00",
4199 "Latvian rubles1.00",
4200 "Lebanese Pound1.00",
4201 "Lebanese pound1.00",
4202 "Lebanese pounds1.00",
4203 "Lesotho Loti1.00",
4204 "Lesotho loti1.00",
4205 "Lesotho lotis1.00",
4206 "Liberian Dollar1.00",
4207 "Liberian dollar1.00",
4208 "Liberian dollars1.00",
4209 "Libyan Dinar1.00",
4210 "Libyan dinar1.00",
4211 "Libyan dinars1.00",
4212 "Lithuanian Litas1.00",
4213 "Lithuanian Talonas1.00",
4214 "Lithuanian litas1.00",
4215 "Lithuanian litai1.00",
4216 "Lithuanian talonas1.00",
4217 "Lithuanian talonases1.00",
4218 "Luxembourgian Convertible Franc1.00",
4219 "Luxembourg Financial Franc1.00",
4220 "Luxembourgian Franc1.00",
4221 "Luxembourgian convertible franc1.00",
4222 "Luxembourgian convertible francs1.00",
4223 "Luxembourg financial franc1.00",
4224 "Luxembourg financial francs1.00",
4225 "Luxembourgian franc1.00",
4226 "Luxembourgian francs1.00",
4227 "MAD1.00",
4228 "MAD1.00",
4229 "MAF1.00",
4230 "MAF1.00",
4231 "MDL1.00",
4232 "MDL1.00",
4233 "MX$1.00",
4234 "MGA1.00",
4235 "MGA1.00",
4236 "MGF1.00",
4237 "MGF1.00",
4238 "MKD1.00",
4239 "MLF1.00",
4240 "MLF1.00",
4241 "MMK1.00",
4242 "MMK1.00",
4243 "MNT1.00",
4244 "MOP1.00",
4245 "MOP1.00",
4246 "MRO1.00",
4247 "MTL1.00",
4248 "MTP1.00",
4249 "MTP1.00",
4250 "MUR1.00",
4251 "MUR1.00",
4252 "MVR1.00",
4253 "MVR1.00",
4254 "MWK1.00",
4255 "MXN1.00",
4256 "MXP1.00",
4257 "MXP1.00",
4258 "MXV1.00",
4259 "MXV1.00",
4260 "MYR1.00",
4261 "MZE1.00",
4262 "MZE1.00",
4263 "MZM1.00",
4264 "MZN1.00",
4265 "Macanese Pataca1.00",
4266 "Macanese pataca1.00",
4267 "Macanese patacas1.00",
4268 "Macedonian Denar1.00",
4269 "Macedonian denar1.00",
4270 "Macedonian denari1.00",
4271 "Malagasy Ariaries1.00",
4272 "Malagasy Ariary1.00",
4273 "Malagasy Ariary1.00",
4274 "Malagasy Franc1.00",
4275 "Malagasy franc1.00",
4276 "Malagasy francs1.00",
4277 "Malawian Kwacha1.00",
4278 "Malawian Kwacha1.00",
4279 "Malawian Kwachas1.00",
4280 "Malaysian Ringgit1.00",
4281 "Malaysian ringgit1.00",
4282 "Malaysian ringgits1.00",
4283 "Maldivian Rufiyaa1.00",
4284 "Maldivian rufiyaa1.00",
4285 "Maldivian rufiyaas1.00",
4286 "Malian Franc1.00",
4287 "Malian franc1.00",
4288 "Malian francs1.00",
4289 "Maltese Lira1.00",
4290 "Maltese Pound1.00",
4291 "Maltese lira1.00",
4292 "Maltese lira1.00",
4293 "Maltese pound1.00",
4294 "Maltese pounds1.00",
4295 "Mauritanian Ouguiya1.00",
4296 "Mauritanian ouguiya1.00",
4297 "Mauritanian ouguiyas1.00",
4298 "Mauritian Rupee1.00",
4299 "Mauritian rupee1.00",
4300 "Mauritian rupees1.00",
4301 "Mexican Peso1.00",
4302 "Mexican Silver Peso (1861\\u20131992)1.00",
4303 "Mexican Investment Unit1.00",
4304 "Mexican peso1.00",
4305 "Mexican pesos1.00",
4306 "Mexican silver peso (1861\\u20131992)1.00",
4307 "Mexican silver pesos (1861\\u20131992)1.00",
4308 "Mexican investment unit1.00",
4309 "Mexican investment units1.00",
4310 "Moldovan Leu1.00",
4311 "Moldovan leu1.00",
4312 "Moldovan lei1.00",
4313 "Mongolian Tugrik1.00",
4314 "Mongolian tugrik1.00",
4315 "Mongolian tugriks1.00",
4316 "Moroccan Dirham1.00",
4317 "Moroccan Franc1.00",
4318 "Moroccan dirham1.00",
4319 "Moroccan dirhams1.00",
4320 "Moroccan franc1.00",
4321 "Moroccan francs1.00",
4322 "Mozambican Escudo1.00",
4323 "Mozambican Metical1.00",
4324 "Mozambican escudo1.00",
4325 "Mozambican escudos1.00",
4326 "Mozambican metical1.00",
4327 "Mozambican meticals1.00",
4328 "Myanmar Kyat1.00",
4329 "Myanmar kyat1.00",
4330 "Myanmar kyats1.00",
4331 "NAD1.00",
4332 "NGN1.00",
4333 "NIC1.00",
4334 "NIO1.00",
4335 "NIO1.00",
4336 "NLG1.00",
4337 "NLG1.00",
4338 "NOK1.00",
4339 "NPR1.00",
4340 "NT$1.00",
4341 "NZ$1.00",
4342 "NZD1.00",
4343 "Namibian Dollar1.00",
4344 "Namibian dollar1.00",
4345 "Namibian dollars1.00",
4346 "Nepalese Rupee1.00",
4347 "Nepalese rupee1.00",
4348 "Nepalese rupees1.00",
4349 "Netherlands Antillean Guilder1.00",
4350 "Netherlands Antillean guilder1.00",
4351 "Netherlands Antillean guilders1.00",
4352 "Dutch Guilder1.00",
4353 "Dutch guilder1.00",
4354 "Dutch guilders1.00",
4355 "Israeli New Sheqel1.00",
4356 "Israeli New Sheqels1.00",
4357 "New Zealand Dollar1.00",
4358 "New Zealand dollar1.00",
4359 "New Zealand dollars1.00",
4360 "Nicaraguan C\\u00f3rdoba1.00",
4361 "Nicaraguan C\\u00f3rdoba (1988\\u20131991)1.00",
4362 "Nicaraguan c\\u00f3rdoba1.00",
4363 "Nicaraguan c\\u00f3rdobas1.00",
4364 "Nicaraguan c\\u00f3rdoba (1988\\u20131991)1.00",
4365 "Nicaraguan c\\u00f3rdobas (1988\\u20131991)1.00",
4366 "Nigerian Naira1.00",
4367 "Nigerian naira1.00",
4368 "Nigerian nairas1.00",
4369 "North Korean Won1.00",
4370 "North Korean won1.00",
4371 "North Korean won1.00",
4372 "Norwegian Krone1.00",
4373 "Norwegian krone1.00",
4374 "Norwegian kroner1.00",
4375 "OMR1.00",
4376 "Mozambican Metical (1980\\u20132006)1.00",
4377 "Mozambican metical (1980\\u20132006)1.00",
4378 "Mozambican meticals (1980\\u20132006)1.00",
4379 "Romanian Lei (1952\\u20132006)1.00",
4380 "Romanian Leu (1952\\u20132006)1.00",
4381 "Romanian leu (1952\\u20132006)1.00",
4382 "Serbian Dinar (2002\\u20132006)1.00",
4383 "Serbian dinar (2002\\u20132006)1.00",
4384 "Serbian dinars (2002\\u20132006)1.00",
4385 "Sudanese Dinar (1992\\u20132007)1.00",
4386 "Sudanese Pound (1957\\u20131998)1.00",
4387 "Sudanese dinar (1992\\u20132007)1.00",
4388 "Sudanese dinars (1992\\u20132007)1.00",
4389 "Sudanese pound (1957\\u20131998)1.00",
4390 "Sudanese pounds (1957\\u20131998)1.00",
4391 "Turkish Lira (1922\\u20132005)1.00",
4392 "Turkish Lira (1922\\u20132005)1.00",
4393 "Omani Rial1.00",
4394 "Omani rial1.00",
4395 "Omani rials1.00",
4396 "PAB1.00",
4397 "PAB1.00",
4398 "PEI1.00",
4399 "PEI1.00",
4400 "PEN1.00",
4401 "PEN1.00",
4402 "PES1.00",
4403 "PES1.00",
4404 "PGK1.00",
4405 "PGK1.00",
4406 "PHP1.00",
4407 "PKR1.00",
4408 "PLN1.00",
4409 "PLZ1.00",
4410 "PLZ1.00",
4411 "PTE1.00",
4412 "PTE1.00",
4413 "PYG1.00",
4414 "Pakistani Rupee1.00",
4415 "Pakistani rupee1.00",
4416 "Pakistani rupees1.00",
4417 "Palladium1.00",
4418 "Palladium1.00",
4419 "Panamanian Balboa1.00",
4420 "Panamanian balboa1.00",
4421 "Panamanian balboas1.00",
4422 "Papua New Guinean Kina1.00",
4423 "Papua New Guinean kina1.00",
4424 "Papua New Guinean kina1.00",
4425 "Paraguayan Guarani1.00",
4426 "Paraguayan guarani1.00",
4427 "Paraguayan guaranis1.00",
4428 "Peruvian Inti1.00",
4429 "Peruvian Nuevo Sol1.00",
4430 "Peruvian Sol (1863\\u20131965)1.00",
4431 "Peruvian inti1.00",
4432 "Peruvian intis1.00",
4433 "Peruvian nuevo sol1.00",
4434 "Peruvian nuevos soles1.00",
4435 "Peruvian sol (1863\\u20131965)1.00",
4436 "Peruvian soles (1863\\u20131965)1.00",
4437 "Philippine Peso1.00",
4438 "Philippine peso1.00",
4439 "Philippine pesos1.00",
4440 "Platinum1.00",
4441 "Platinum1.00",
4442 "Polish Zloty (1950\\u20131995)1.00",
4443 "Polish Zloty1.00",
4444 "Polish zlotys1.00",
4445 "Polish zloty (PLZ)1.00",
4446 "Polish zloty1.00",
4447 "Polish zlotys (PLZ)1.00",
4448 "Portuguese Escudo1.00",
4449 "Portuguese Guinea Escudo1.00",
4450 "Portuguese Guinea escudo1.00",
4451 "Portuguese Guinea escudos1.00",
4452 "Portuguese escudo1.00",
4453 "Portuguese escudos1.00",
4454 "GTQ1.00",
4455 "QAR1.00",
4456 "Qatari Rial1.00",
4457 "Qatari rial1.00",
4458 "Qatari rials1.00",
4459 "RHD1.00",
4460 "RHD1.00",
4461 "RINET Funds1.00",
4462 "RINET Funds1.00",
4463 "CN\\u00a51.00",
4464 "ROL1.00",
4465 "ROL1.00",
4466 "RON1.00",
4467 "RON1.00",
4468 "RSD1.00",
4469 "RSD1.00",
4470 "RUB1.00",
4471 "RUB1.00",
4472 "RUR1.00",
4473 "RUR1.00",
4474 "RWF1.00",
4475 "RWF1.00",
4476 "Rhodesian Dollar1.00",
4477 "Rhodesian dollar1.00",
4478 "Rhodesian dollars1.00",
4479 "Romanian Leu1.00",
4480 "Romanian lei1.00",
4481 "Romanian leu1.00",
4482 "Russian Ruble (1991\\u20131998)1.00",
4483 "Russian Ruble1.00",
4484 "Russian ruble (1991\\u20131998)1.00",
4485 "Russian ruble1.00",
4486 "Russian rubles (1991\\u20131998)1.00",
4487 "Russian rubles1.00",
4488 "Rwandan Franc1.00",
4489 "Rwandan franc1.00",
4490 "Rwandan francs1.00",
4491 "SAR1.00",
4492 "SBD1.00",
4493 "SCR1.00",
4494 "SDD1.00",
4495 "SDD1.00",
4496 "SDG1.00",
4497 "SDG1.00",
4498 "SDP1.00",
4499 "SDP1.00",
4500 "SEK1.00",
4501 "SGD1.00",
4502 "SHP1.00",
4503 "SHP1.00",
4504 "SIT1.00",
4505 "SIT1.00",
4506 "SKK1.00",
4507 "SLL1.00",
4508 "SLL1.00",
4509 "SOS1.00",
4510 "SRD1.00",
4511 "SRD1.00",
4512 "SRG1.00",
4513 "STD1.00",
4514 "SUR1.00",
4515 "SUR1.00",
4516 "SVC1.00",
4517 "SVC1.00",
4518 "SYP1.00",
4519 "SZL1.00",
4520 "St. Helena Pound1.00",
4521 "St. Helena pound1.00",
4522 "St. Helena pounds1.00",
4523 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra1.00",
4524 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra1.00",
4525 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras1.00",
4526 "Saudi Riyal1.00",
4527 "Saudi riyal1.00",
4528 "Saudi riyals1.00",
4529 "Serbian Dinar1.00",
4530 "Serbian dinar1.00",
4531 "Serbian dinars1.00",
4532 "Seychellois Rupee1.00",
4533 "Seychellois rupee1.00",
4534 "Seychellois rupees1.00",
4535 "Sierra Leonean Leone1.00",
4536 "Sierra Leonean leone1.00",
4537 "Sierra Leonean leones1.00",
4538 "Silver1.00",
4539 "Silver1.00",
4540 "Singapore Dollar1.00",
4541 "Singapore dollar1.00",
4542 "Singapore dollars1.00",
4543 "Slovak Koruna1.00",
4544 "Slovak koruna1.00",
4545 "Slovak korunas1.00",
4546 "Slovenian Tolar1.00",
4547 "Slovenian tolar1.00",
4548 "Slovenian tolars1.00",
4549 "Solomon Islands Dollar1.00",
4550 "Solomon Islands dollar1.00",
4551 "Solomon Islands dollars1.00",
4552 "Somali Shilling1.00",
4553 "Somali shilling1.00",
4554 "Somali shillings1.00",
4555 "South African Rand (financial)1.00",
4556 "South African Rand1.00",
4557 "South African rand (financial)1.00",
4558 "South African rand1.00",
4559 "South African rands (financial)1.00",
4560 "South African rand1.00",
4561 "South Korean Won1.00",
4562 "South Korean won1.00",
4563 "South Korean won1.00",
4564 "Soviet Rouble1.00",
4565 "Soviet rouble1.00",
4566 "Soviet roubles1.00",
4567 "Spanish Peseta (A account)1.00",
4568 "Spanish Peseta (convertible account)1.00",
4569 "Spanish Peseta1.00",
4570 "Spanish peseta (A account)1.00",
4571 "Spanish peseta (convertible account)1.00",
4572 "Spanish peseta1.00",
4573 "Spanish pesetas (A account)1.00",
4574 "Spanish pesetas (convertible account)1.00",
4575 "Spanish pesetas1.00",
4576 "Special Drawing Rights1.00",
4577 "Sri Lankan Rupee1.00",
4578 "Sri Lankan rupee1.00",
4579 "Sri Lankan rupees1.00",
4580 "Sudanese Pound1.00",
4581 "Sudanese pound1.00",
4582 "Sudanese pounds1.00",
4583 "Surinamese Dollar1.00",
4584 "Surinamese dollar1.00",
4585 "Surinamese dollars1.00",
4586 "Surinamese Guilder1.00",
4587 "Surinamese guilder1.00",
4588 "Surinamese guilders1.00",
4589 "Swazi Lilangeni1.00",
4590 "Swazi lilangeni1.00",
4591 "Swazi emalangeni1.00",
4592 "Swedish Krona1.00",
4593 "Swedish krona1.00",
4594 "Swedish kronor1.00",
4595 "Swiss Franc1.00",
4596 "Swiss franc1.00",
4597 "Swiss francs1.00",
4598 "Syrian Pound1.00",
4599 "Syrian pound1.00",
4600 "Syrian pounds1.00",
4601 "THB1.00",
4602 "TJR1.00",
4603 "TJR1.00",
4604 "TJS1.00",
4605 "TJS1.00",
4606 "TMM1.00",
4607 "TMM1.00",
4608 "TND1.00",
4609 "TND1.00",
4610 "TOP1.00",
4611 "TPE1.00",
4612 "TPE1.00",
4613 "TRL1.00",
4614 "TRY1.00",
4615 "TRY1.00",
4616 "TTD1.00",
4617 "TWD1.00",
4618 "TZS1.00",
4619 "New Taiwan Dollar1.00",
4620 "New Taiwan dollar1.00",
4621 "New Taiwan dollars1.00",
4622 "Tajikistani Ruble1.00",
4623 "Tajikistani Somoni1.00",
4624 "Tajikistani ruble1.00",
4625 "Tajikistani rubles1.00",
4626 "Tajikistani somoni1.00",
4627 "Tajikistani somonis1.00",
4628 "Tanzanian Shilling1.00",
4629 "Tanzanian shilling1.00",
4630 "Tanzanian shillings1.00",
4631 "Testing Currency Code1.00",
4632 "Testing Currency Code1.00",
4633 "Thai Baht1.00",
4634 "Thai baht1.00",
4635 "Thai baht1.00",
4636 "Timorese Escudo1.00",
4637 "Timorese escudo1.00",
4638 "Timorese escudos1.00",
4639 "Tongan Pa\\u02bbanga1.00",
4640 "Tongan pa\\u02bbanga1.00",
4641 "Tongan pa\\u02bbanga1.00",
4642 "Trinidad & Tobago Dollar1.00",
4643 "Trinidad & Tobago dollar1.00",
4644 "Trinidad & Tobago dollars1.00",
4645 "Tunisian Dinar1.00",
4646 "Tunisian dinar1.00",
4647 "Tunisian dinars1.00",
4648 "Turkish Lira1.00",
4649 "Turkish Lira1.00",
4650 "Turkish lira1.00",
4651 "Turkmenistani Manat1.00",
4652 "Turkmenistani manat1.00",
4653 "Turkmenistani manat1.00",
4654 "UAE dirham1.00",
4655 "UAE dirhams1.00",
4656 "UAH1.00",
4657 "UAK1.00",
4658 "UAK1.00",
4659 "UGS1.00",
4660 "UGS1.00",
4661 "UGX1.00",
4662 "US Dollar (Next day)1.00",
4663 "US Dollar (Same day)1.00",
4664 "US Dollar1.00",
4665 "US dollar (next day)1.00",
4666 "US dollar (same day)1.00",
4667 "US dollar1.00",
4668 "US dollars (next day)1.00",
4669 "US dollars (same day)1.00",
4670 "US dollars1.00",
4671 "USD1.00",
4672 "USN1.00",
4673 "USN1.00",
4674 "USS1.00",
4675 "USS1.00",
4676 "UYI1.00",
4677 "UYI1.00",
4678 "UYP1.00",
4679 "UYP1.00",
4680 "UYU1.00",
4681 "UZS1.00",
4682 "UZS1.00",
4683 "Ugandan Shilling (1966\\u20131987)1.00",
4684 "Ugandan Shilling1.00",
4685 "Ugandan shilling (1966\\u20131987)1.00",
4686 "Ugandan shilling1.00",
4687 "Ugandan shillings (1966\\u20131987)1.00",
4688 "Ugandan shillings1.00",
4689 "Ukrainian Hryvnia1.00",
4690 "Ukrainian Karbovanets1.00",
4691 "Ukrainian hryvnia1.00",
4692 "Ukrainian hryvnias1.00",
4693 "Ukrainian karbovanets1.00",
4694 "Ukrainian karbovantsiv1.00",
4695 "Colombian Real Value Unit1.00",
4696 "United Arab Emirates Dirham1.00",
4697 "Unknown Currency1.00",
4698 "Uruguayan Peso (1975\\u20131993)1.00",
4699 "Uruguayan Peso1.00",
4700 "Uruguayan Peso (Indexed Units)1.00",
4701 "Uruguayan peso (1975\\u20131993)1.00",
4702 "Uruguayan peso (indexed units)1.00",
4703 "Uruguayan peso1.00",
4704 "Uruguayan pesos (1975\\u20131993)1.00",
4705 "Uruguayan pesos (indexed units)1.00",
4706 "Uruguayan pesos1.00",
4707 "Uzbekistani Som1.00",
4708 "Uzbekistani som1.00",
4709 "Uzbekistani som1.00",
4710 "VEB1.00",
4711 "VEF1.00",
4712 "VND1.00",
4713 "VUV1.00",
4714 "Vanuatu Vatu1.00",
4715 "Vanuatu vatu1.00",
4716 "Vanuatu vatus1.00",
4717 "Venezuelan Bol\\u00edvar1.00",
4718 "Venezuelan Bol\\u00edvar (1871\\u20132008)1.00",
4719 "Venezuelan bol\\u00edvar1.00",
4720 "Venezuelan bol\\u00edvars1.00",
4721 "Venezuelan bol\\u00edvar (1871\\u20132008)1.00",
4722 "Venezuelan bol\\u00edvars (1871\\u20132008)1.00",
4723 "Vietnamese Dong1.00",
4724 "Vietnamese dong1.00",
4725 "Vietnamese dong1.00",
4726 "WIR Euro1.00",
4727 "WIR Franc1.00",
4728 "WIR euro1.00",
4729 "WIR euros1.00",
4730 "WIR franc1.00",
4731 "WIR francs1.00",
4732 "WST1.00",
4733 "WST1.00",
4734 "Samoan Tala1.00",
4735 "Samoan tala1.00",
4736 "Samoan tala1.00",
4737 "XAF1.00",
4738 "XAF1.00",
4739 "XAG1.00",
4740 "XAG1.00",
4741 "XAU1.00",
4742 "XAU1.00",
4743 "XBA1.00",
4744 "XBA1.00",
4745 "XBB1.00",
4746 "XBB1.00",
4747 "XBC1.00",
4748 "XBC1.00",
4749 "XBD1.00",
4750 "XBD1.00",
4751 "XCD1.00",
4752 "XDR1.00",
4753 "XDR1.00",
4754 "XEU1.00",
4755 "XEU1.00",
4756 "XFO1.00",
4757 "XFO1.00",
4758 "XFU1.00",
4759 "XFU1.00",
4760 "XOF1.00",
4761 "XOF1.00",
4762 "XPD1.00",
4763 "XPD1.00",
4764 "XPF1.00",
4765 "XPT1.00",
4766 "XPT1.00",
4767 "XRE1.00",
4768 "XRE1.00",
4769 "XTS1.00",
4770 "XTS1.00",
4771 "XXX1.00",
4772 "XXX1.00",
4773 "YDD1.00",
4774 "YDD1.00",
4775 "YER1.00",
4776 "YUD1.00",
4777 "YUD1.00",
4778 "YUM1.00",
4779 "YUM1.00",
4780 "YUN1.00",
4781 "YUN1.00",
4782 "Yemeni Dinar1.00",
4783 "Yemeni Rial1.00",
4784 "Yemeni dinar1.00",
4785 "Yemeni dinars1.00",
4786 "Yemeni rial1.00",
4787 "Yemeni rials1.00",
4788 "Yugoslavian Convertible Dinar (1990\\u20131992)1.00",
4789 "Yugoslavian Hard Dinar (1966\\u20131990)1.00",
4790 "Yugoslavian New Dinar (1994\\u20132002)1.00",
4791 "Yugoslavian convertible dinar (1990\\u20131992)1.00",
4792 "Yugoslavian convertible dinars (1990\\u20131992)1.00",
4793 "Yugoslavian hard dinar (1966\\u20131990)1.00",
4794 "Yugoslavian hard dinars (1966\\u20131990)1.00",
4795 "Yugoslavian new dinar (1994\\u20132002)1.00",
4796 "Yugoslavian new dinars (1994\\u20132002)1.00",
4797 "ZAL1.00",
4798 "ZAL1.00",
4799 "ZAR1.00",
4800 "ZMK1.00",
4801 "ZMK1.00",
4802 "ZRN1.00",
4803 "ZRN1.00",
4804 "ZRZ1.00",
4805 "ZRZ1.00",
4806 "ZWD1.00",
4807 "Zairean New Zaire (1993\\u20131998)1.00",
4808 "Zairean Zaire (1971\\u20131993)1.00",
4809 "Zairean new zaire (1993\\u20131998)1.00",
4810 "Zairean new zaires (1993\\u20131998)1.00",
4811 "Zairean zaire (1971\\u20131993)1.00",
4812 "Zairean zaires (1971\\u20131993)1.00",
4813 "Zambian Kwacha1.00",
4814 "Zambian kwacha1.00",
4815 "Zambian kwachas1.00",
4816 "Zimbabwean Dollar (1980\\u20132008)1.00",
4817 "Zimbabwean dollar (1980\\u20132008)1.00",
4818 "Zimbabwean dollars (1980\\u20132008)1.00",
4819 "euro1.00",
4820 "euros1.00",
4821 "Turkish lira (1922\\u20132005)1.00",
4822 "special drawing rights1.00",
4823 "Colombian real value unit1.00",
4824 "Colombian real value units1.00",
4825 "unknown currency1.00",
4826 "\\u00a31.00",
4827 "\\u00a51.00",
4828 "\\u20ab1.00",
4829 "\\u20aa1.00",
4830 "\\u20ac1.00",
4831 "\\u20b91.00",
4832 //
4833 // Following has extra text, should be parsed correctly too
4834 "$1.00 random",
4835 "USD1.00 random",
4836 "1.00 US dollar random",
4837 "1.00 US dollars random",
4838 "1.00 Afghan Afghani random",
4839 "1.00 Afghan Afghani random",
4840 "1.00 Afghan Afghanis (1927\\u20131992) random",
4841 "1.00 Afghan Afghanis random",
4842 "1.00 Albanian Lek random",
4843 "1.00 Albanian lek random",
4844 "1.00 Albanian lek\\u00eb random",
4845 "1.00 Algerian Dinar random",
4846 "1.00 Algerian dinar random",
4847 "1.00 Algerian dinars random",
4848 "1.00 Andorran Peseta random",
4849 "1.00 Andorran peseta random",
4850 "1.00 Andorran pesetas random",
4851 "1.00 Angolan Kwanza (1977\\u20131990) random",
4852 "1.00 Angolan Readjusted Kwanza (1995\\u20131999) random",
4853 "1.00 Angolan Kwanza random",
4854 "1.00 Angolan New Kwanza (1990\\u20132000) random",
4855 "1.00 Angolan kwanza (1977\\u20131991) random",
4856 "1.00 Angolan readjusted kwanza (1995\\u20131999) random",
4857 "1.00 Angolan kwanza random",
4858 "1.00 Angolan kwanzas (1977\\u20131991) random",
4859 "1.00 Angolan readjusted kwanzas (1995\\u20131999) random",
4860 "1.00 Angolan kwanzas random",
4861 "1.00 Angolan new kwanza (1990\\u20132000) random",
4862 "1.00 Angolan new kwanzas (1990\\u20132000) random",
4863 "1.00 Argentine Austral random",
4864 "1.00 Argentine Peso (1983\\u20131985) random",
4865 "1.00 Argentine Peso random",
4866 "1.00 Argentine austral random",
4867 "1.00 Argentine australs random",
4868 "1.00 Argentine peso (1983\\u20131985) random",
4869 "1.00 Argentine peso random",
4870 "1.00 Argentine pesos (1983\\u20131985) random",
4871 "1.00 Argentine pesos random",
4872 "1.00 Armenian Dram random",
4873 "1.00 Armenian dram random",
4874 "1.00 Armenian drams random",
4875 "1.00 Aruban Florin random",
4876 "1.00 Aruban florin random",
4877 "1.00 Australian Dollar random",
4878 "1.00 Australian dollar random",
4879 "1.00 Australian dollars random",
4880 "1.00 Austrian Schilling random",
4881 "1.00 Austrian schilling random",
4882 "1.00 Austrian schillings random",
4883 "1.00 Azerbaijani Manat (1993\\u20132006) random",
4884 "1.00 Azerbaijani Manat random",
4885 "1.00 Azerbaijani manat (1993\\u20132006) random",
4886 "1.00 Azerbaijani manat random",
4887 "1.00 Azerbaijani manats (1993\\u20132006) random",
4888 "1.00 Azerbaijani manats random",
4889 "1.00 Bahamian Dollar random",
4890 "1.00 Bahamian dollar random",
4891 "1.00 Bahamian dollars random",
4892 "1.00 Bahraini Dinar random",
4893 "1.00 Bahraini dinar random",
4894 "1.00 Bahraini dinars random",
4895 "1.00 Bangladeshi Taka random",
4896 "1.00 Bangladeshi taka random",
4897 "1.00 Bangladeshi takas random",
4898 "1.00 Barbadian Dollar random",
4899 "1.00 Barbadian dollar random",
4900 "1.00 Barbadian dollars random",
4901 "1.00 Belarusian New Ruble (1994\\u20131999) random",
4902 "1.00 Belarusian Ruble random",
4903 "1.00 Belarusian new ruble (1994\\u20131999) random",
4904 "1.00 Belarusian new rubles (1994\\u20131999) random",
4905 "1.00 Belarusian ruble random",
4906 "1.00 Belarusian rubles random",
4907 "1.00 Belgian Franc (convertible) random",
4908 "1.00 Belgian Franc (financial) random",
4909 "1.00 Belgian Franc random",
4910 "1.00 Belgian franc (convertible) random",
4911 "1.00 Belgian franc (financial) random",
4912 "1.00 Belgian franc random",
4913 "1.00 Belgian francs (convertible) random",
4914 "1.00 Belgian francs (financial) random",
4915 "1.00 Belgian francs random",
4916 "1.00 Belize Dollar random",
4917 "1.00 Belize dollar random",
4918 "1.00 Belize dollars random",
4919 "1.00 Bermudan Dollar random",
4920 "1.00 Bermudan dollar random",
4921 "1.00 Bermudan dollars random",
4922 "1.00 Bhutanese Ngultrum random",
4923 "1.00 Bhutanese ngultrum random",
4924 "1.00 Bhutanese ngultrums random",
4925 "1.00 Bolivian Mvdol random",
4926 "1.00 Bolivian Peso random",
4927 "1.00 Bolivian mvdol random",
4928 "1.00 Bolivian mvdols random",
4929 "1.00 Bolivian peso random",
4930 "1.00 Bolivian pesos random",
4931 "1.00 Bolivian Boliviano random",
4932 "1.00 Bolivian Boliviano random",
4933 "1.00 Bolivian Bolivianos random",
4934 "1.00 Bosnia-Herzegovina Convertible Mark random",
4935 "1.00 Bosnia-Herzegovina Dinar (1992\\u20131994) random",
4936 "1.00 Bosnia-Herzegovina convertible mark random",
4937 "1.00 Bosnia-Herzegovina convertible marks random",
4938 "1.00 Bosnia-Herzegovina dinar (1992\\u20131994) random",
4939 "1.00 Bosnia-Herzegovina dinars (1992\\u20131994) random",
4940 "1.00 Botswanan Pula random",
4941 "1.00 Botswanan pula random",
4942 "1.00 Botswanan pulas random",
4943 "1.00 Brazilian New Cruzado (1989\\u20131990) random",
4944 "1.00 Brazilian Cruzado (1986\\u20131989) random",
4945 "1.00 Brazilian Cruzeiro (1990\\u20131993) random",
4946 "1.00 Brazilian New Cruzeiro (1967\\u20131986) random",
4947 "1.00 Brazilian Cruzeiro (1993\\u20131994) random",
4948 "1.00 Brazilian Real random",
4949 "1.00 Brazilian new cruzado (1989\\u20131990) random",
4950 "1.00 Brazilian new cruzados (1989\\u20131990) random",
4951 "1.00 Brazilian cruzado (1986\\u20131989) random",
4952 "1.00 Brazilian cruzados (1986\\u20131989) random",
4953 "1.00 Brazilian cruzeiro (1990\\u20131993) random",
4954 "1.00 Brazilian new cruzeiro (1967\\u20131986) random",
4955 "1.00 Brazilian cruzeiro (1993\\u20131994) random",
4956 "1.00 Brazilian cruzeiros (1990\\u20131993) random",
4957 "1.00 Brazilian new cruzeiros (1967\\u20131986) random",
4958 "1.00 Brazilian cruzeiros (1993\\u20131994) random",
4959 "1.00 Brazilian real random",
4960 "1.00 Brazilian reals random",
4961 "1.00 British Pound random",
4962 "1.00 British pound random",
4963 "1.00 British pounds random",
4964 "1.00 Brunei Dollar random",
4965 "1.00 Brunei dollar random",
4966 "1.00 Brunei dollars random",
4967 "1.00 Bulgarian Hard Lev random",
4968 "1.00 Bulgarian Lev random",
4969 "1.00 Bulgarian Leva random",
4970 "1.00 Bulgarian hard lev random",
4971 "1.00 Bulgarian hard leva random",
4972 "1.00 Bulgarian lev random",
4973 "1.00 Burmese Kyat random",
4974 "1.00 Burmese kyat random",
4975 "1.00 Burmese kyats random",
4976 "1.00 Burundian Franc random",
4977 "1.00 Burundian franc random",
4978 "1.00 Burundian francs random",
4979 "1.00 Cambodian Riel random",
4980 "1.00 Cambodian riel random",
4981 "1.00 Cambodian riels random",
4982 "1.00 Canadian Dollar random",
4983 "1.00 Canadian dollar random",
4984 "1.00 Canadian dollars random",
4985 "1.00 Cape Verdean Escudo random",
4986 "1.00 Cape Verdean escudo random",
4987 "1.00 Cape Verdean escudos random",
4988 "1.00 Cayman Islands Dollar random",
4989 "1.00 Cayman Islands dollar random",
4990 "1.00 Cayman Islands dollars random",
4991 "1.00 Chilean Peso random",
4992 "1.00 Chilean Unit of Account (UF) random",
4993 "1.00 Chilean peso random",
4994 "1.00 Chilean pesos random",
4995 "1.00 Chilean unit of account (UF) random",
4996 "1.00 Chilean units of account (UF) random",
4997 "1.00 Chinese Yuan random",
4998 "1.00 Chinese yuan random",
4999 "1.00 Colombian Peso random",
5000 "1.00 Colombian peso random",
5001 "1.00 Colombian pesos random",
5002 "1.00 Comorian Franc random",
5003 "1.00 Comorian franc random",
5004 "1.00 Comorian francs random",
5005 "1.00 Congolese Franc Congolais random",
5006 "1.00 Congolese franc Congolais random",
5007 "1.00 Congolese francs Congolais random",
5008 "1.00 Costa Rican Col\\u00f3n random",
5009 "1.00 Costa Rican col\\u00f3n random",
5010 "1.00 Costa Rican col\\u00f3ns random",
5011 "1.00 Croatian Dinar random",
5012 "1.00 Croatian Kuna random",
5013 "1.00 Croatian dinar random",
5014 "1.00 Croatian dinars random",
5015 "1.00 Croatian kuna random",
5016 "1.00 Croatian kunas random",
5017 "1.00 Cuban Peso random",
5018 "1.00 Cuban peso random",
5019 "1.00 Cuban pesos random",
5020 "1.00 Cypriot Pound random",
5021 "1.00 Cypriot pound random",
5022 "1.00 Cypriot pounds random",
5023 "1.00 Czech Republic Koruna random",
5024 "1.00 Czech Republic koruna random",
5025 "1.00 Czech Republic korunas random",
5026 "1.00 Czechoslovak Hard Koruna random",
5027 "1.00 Czechoslovak hard koruna random",
5028 "1.00 Czechoslovak hard korunas random",
5029 "1.00 Danish Krone random",
5030 "1.00 Danish krone random",
5031 "1.00 Danish kroner random",
5032 "1.00 German Mark random",
5033 "1.00 German mark random",
5034 "1.00 German marks random",
5035 "1.00 Djiboutian Franc random",
5036 "1.00 Djiboutian franc random",
5037 "1.00 Djiboutian francs random",
5038 "1.00 Dominican Peso random",
5039 "1.00 Dominican peso random",
5040 "1.00 Dominican pesos random",
5041 "1.00 East Caribbean Dollar random",
5042 "1.00 East Caribbean dollar random",
5043 "1.00 East Caribbean dollars random",
5044 "1.00 East German Mark random",
5045 "1.00 East German mark random",
5046 "1.00 East German marks random",
5047 "1.00 Ecuadorian Sucre random",
5048 "1.00 Ecuadorian Unit of Constant Value random",
5049 "1.00 Ecuadorian sucre random",
5050 "1.00 Ecuadorian sucres random",
5051 "1.00 Ecuadorian unit of constant value random",
5052 "1.00 Ecuadorian units of constant value random",
5053 "1.00 Egyptian Pound random",
5054 "1.00 Egyptian pound random",
5055 "1.00 Egyptian pounds random",
5056 "1.00 Salvadoran Col\\u00f3n random",
5057 "1.00 Salvadoran col\\u00f3n random",
5058 "1.00 Salvadoran colones random",
5059 "1.00 Equatorial Guinean Ekwele random",
5060 "1.00 Equatorial Guinean ekwele random",
5061 "1.00 Eritrean Nakfa random",
5062 "1.00 Eritrean nakfa random",
5063 "1.00 Eritrean nakfas random",
5064 "1.00 Estonian Kroon random",
5065 "1.00 Estonian kroon random",
5066 "1.00 Estonian kroons random",
5067 "1.00 Ethiopian Birr random",
5068 "1.00 Ethiopian birr random",
5069 "1.00 Ethiopian birrs random",
5070 "1.00 European Composite Unit random",
5071 "1.00 European Currency Unit random",
5072 "1.00 European Monetary Unit random",
5073 "1.00 European Unit of Account (XBC) random",
5074 "1.00 European Unit of Account (XBD) random",
5075 "1.00 European composite unit random",
5076 "1.00 European composite units random",
5077 "1.00 European currency unit random",
5078 "1.00 European currency units random",
5079 "1.00 European monetary unit random",
5080 "1.00 European monetary units random",
5081 "1.00 European unit of account (XBC) random",
5082 "1.00 European unit of account (XBD) random",
5083 "1.00 European units of account (XBC) random",
5084 "1.00 European units of account (XBD) random",
5085 "1.00 Falkland Islands Pound random",
5086 "1.00 Falkland Islands pound random",
5087 "1.00 Falkland Islands pounds random",
5088 "1.00 Fijian Dollar random",
5089 "1.00 Fijian dollar random",
5090 "1.00 Fijian dollars random",
5091 "1.00 Finnish Markka random",
5092 "1.00 Finnish markka random",
5093 "1.00 Finnish markkas random",
5094 "1.00 French Franc random",
5095 "1.00 French Gold Franc random",
5096 "1.00 French UIC-Franc random",
5097 "1.00 French UIC-franc random",
5098 "1.00 French UIC-francs random",
5099 "1.00 French franc random",
5100 "1.00 French francs random",
5101 "1.00 French gold franc random",
5102 "1.00 French gold francs random",
5103 "1.00 Gambian Dalasi random",
5104 "1.00 Gambian dalasi random",
5105 "1.00 Gambian dalasis random",
5106 "1.00 Georgian Kupon Larit random",
5107 "1.00 Georgian Lari random",
5108 "1.00 Georgian kupon larit random",
5109 "1.00 Georgian kupon larits random",
5110 "1.00 Georgian lari random",
5111 "1.00 Georgian laris random",
5112 "1.00 Ghanaian Cedi (1979\\u20132007) random",
5113 "1.00 Ghanaian Cedi random",
5114 "1.00 Ghanaian cedi (1979\\u20132007) random",
5115 "1.00 Ghanaian cedi random",
5116 "1.00 Ghanaian cedis (1979\\u20132007) random",
5117 "1.00 Ghanaian cedis random",
5118 "1.00 Gibraltar Pound random",
5119 "1.00 Gibraltar pound random",
5120 "1.00 Gibraltar pounds random",
5121 "1.00 Gold random",
5122 "1.00 Gold random",
5123 "1.00 Greek Drachma random",
5124 "1.00 Greek drachma random",
5125 "1.00 Greek drachmas random",
5126 "1.00 Guatemalan Quetzal random",
5127 "1.00 Guatemalan quetzal random",
5128 "1.00 Guatemalan quetzals random",
5129 "1.00 Guinean Franc random",
5130 "1.00 Guinean Syli random",
5131 "1.00 Guinean franc random",
5132 "1.00 Guinean francs random",
5133 "1.00 Guinean syli random",
5134 "1.00 Guinean sylis random",
5135 "1.00 Guinea-Bissau Peso random",
5136 "1.00 Guinea-Bissau peso random",
5137 "1.00 Guinea-Bissau pesos random",
5138 "1.00 Guyanaese Dollar random",
5139 "1.00 Guyanaese dollar random",
5140 "1.00 Guyanaese dollars random",
5141 "1.00 Haitian Gourde random",
5142 "1.00 Haitian gourde random",
5143 "1.00 Haitian gourdes random",
5144 "1.00 Honduran Lempira random",
5145 "1.00 Honduran lempira random",
5146 "1.00 Honduran lempiras random",
5147 "1.00 Hong Kong Dollar random",
5148 "1.00 Hong Kong dollar random",
5149 "1.00 Hong Kong dollars random",
5150 "1.00 Hungarian Forint random",
5151 "1.00 Hungarian forint random",
5152 "1.00 Hungarian forints random",
5153 "1.00 Icelandic Kr\\u00f3na random",
5154 "1.00 Icelandic kr\\u00f3na random",
5155 "1.00 Icelandic kr\\u00f3nur random",
5156 "1.00 Indian Rupee random",
5157 "1.00 Indian rupee random",
5158 "1.00 Indian rupees random",
5159 "1.00 Indonesian Rupiah random",
5160 "1.00 Indonesian rupiah random",
5161 "1.00 Indonesian rupiahs random",
5162 "1.00 Iranian Rial random",
5163 "1.00 Iranian rial random",
5164 "1.00 Iranian rials random",
5165 "1.00 Iraqi Dinar random",
5166 "1.00 Iraqi dinar random",
5167 "1.00 Iraqi dinars random",
5168 "1.00 Irish Pound random",
5169 "1.00 Irish pound random",
5170 "1.00 Irish pounds random",
5171 "1.00 Israeli Pound random",
5172 "1.00 Israeli new sheqel random",
5173 "1.00 Israeli pound random",
5174 "1.00 Israeli pounds random",
5175 "1.00 Italian Lira random",
5176 "1.00 Italian lira random",
5177 "1.00 Italian liras random",
5178 "1.00 Jamaican Dollar random",
5179 "1.00 Jamaican dollar random",
5180 "1.00 Jamaican dollars random",
5181 "1.00 Japanese Yen random",
5182 "1.00 Japanese yen random",
5183 "1.00 Jordanian Dinar random",
5184 "1.00 Jordanian dinar random",
5185 "1.00 Jordanian dinars random",
5186 "1.00 Kazakhstani Tenge random",
5187 "1.00 Kazakhstani tenge random",
5188 "1.00 Kazakhstani tenges random",
5189 "1.00 Kenyan Shilling random",
5190 "1.00 Kenyan shilling random",
5191 "1.00 Kenyan shillings random",
5192 "1.00 Kuwaiti Dinar random",
5193 "1.00 Kuwaiti dinar random",
5194 "1.00 Kuwaiti dinars random",
5195 "1.00 Kyrgystani Som random",
5196 "1.00 Kyrgystani som random",
5197 "1.00 Kyrgystani soms random",
5198 "1.00 Laotian Kip random",
5199 "1.00 Laotian kip random",
5200 "1.00 Laotian kips random",
5201 "1.00 Latvian Lats random",
5202 "1.00 Latvian Ruble random",
5203 "1.00 Latvian lats random",
5204 "1.00 Latvian lati random",
5205 "1.00 Latvian ruble random",
5206 "1.00 Latvian rubles random",
5207 "1.00 Lebanese Pound random",
5208 "1.00 Lebanese pound random",
5209 "1.00 Lebanese pounds random",
5210 "1.00 Lesotho Loti random",
5211 "1.00 Lesotho loti random",
5212 "1.00 Lesotho lotis random",
5213 "1.00 Liberian Dollar random",
5214 "1.00 Liberian dollar random",
5215 "1.00 Liberian dollars random",
5216 "1.00 Libyan Dinar random",
5217 "1.00 Libyan dinar random",
5218 "1.00 Libyan dinars random",
5219 "1.00 Lithuanian Litas random",
5220 "1.00 Lithuanian Talonas random",
5221 "1.00 Lithuanian litas random",
5222 "1.00 Lithuanian litai random",
5223 "1.00 Lithuanian talonas random",
5224 "1.00 Lithuanian talonases random",
5225 "1.00 Luxembourgian Convertible Franc random",
5226 "1.00 Luxembourg Financial Franc random",
5227 "1.00 Luxembourgian Franc random",
5228 "1.00 Luxembourgian convertible franc random",
5229 "1.00 Luxembourgian convertible francs random",
5230 "1.00 Luxembourg financial franc random",
5231 "1.00 Luxembourg financial francs random",
5232 "1.00 Luxembourgian franc random",
5233 "1.00 Luxembourgian francs random",
5234 "1.00 Macanese Pataca random",
5235 "1.00 Macanese pataca random",
5236 "1.00 Macanese patacas random",
5237 "1.00 Macedonian Denar random",
5238 "1.00 Macedonian denar random",
5239 "1.00 Macedonian denari random",
5240 "1.00 Malagasy Ariaries random",
5241 "1.00 Malagasy Ariary random",
5242 "1.00 Malagasy Ariary random",
5243 "1.00 Malagasy Franc random",
5244 "1.00 Malagasy franc random",
5245 "1.00 Malagasy francs random",
5246 "1.00 Malawian Kwacha random",
5247 "1.00 Malawian Kwacha random",
5248 "1.00 Malawian Kwachas random",
5249 "1.00 Malaysian Ringgit random",
5250 "1.00 Malaysian ringgit random",
5251 "1.00 Malaysian ringgits random",
5252 "1.00 Maldivian Rufiyaa random",
5253 "1.00 Maldivian rufiyaa random",
5254 "1.00 Maldivian rufiyaas random",
5255 "1.00 Malian Franc random",
5256 "1.00 Malian franc random",
5257 "1.00 Malian francs random",
5258 "1.00 Maltese Lira random",
5259 "1.00 Maltese Pound random",
5260 "1.00 Maltese lira random",
5261 "1.00 Maltese liras random",
5262 "1.00 Maltese pound random",
5263 "1.00 Maltese pounds random",
5264 "1.00 Mauritanian Ouguiya random",
5265 "1.00 Mauritanian ouguiya random",
5266 "1.00 Mauritanian ouguiyas random",
5267 "1.00 Mauritian Rupee random",
5268 "1.00 Mauritian rupee random",
5269 "1.00 Mauritian rupees random",
5270 "1.00 Mexican Peso random",
5271 "1.00 Mexican Silver Peso (1861\\u20131992) random",
5272 "1.00 Mexican Investment Unit random",
5273 "1.00 Mexican peso random",
5274 "1.00 Mexican pesos random",
5275 "1.00 Mexican silver peso (1861\\u20131992) random",
5276 "1.00 Mexican silver pesos (1861\\u20131992) random",
5277 "1.00 Mexican investment unit random",
5278 "1.00 Mexican investment units random",
5279 "1.00 Moldovan Leu random",
5280 "1.00 Moldovan leu random",
5281 "1.00 Moldovan lei random",
5282 "1.00 Mongolian Tugrik random",
5283 "1.00 Mongolian tugrik random",
5284 "1.00 Mongolian tugriks random",
5285 "1.00 Moroccan Dirham random",
5286 "1.00 Moroccan Franc random",
5287 "1.00 Moroccan dirham random",
5288 "1.00 Moroccan dirhams random",
5289 "1.00 Moroccan franc random",
5290 "1.00 Moroccan francs random",
5291 "1.00 Mozambican Escudo random",
5292 "1.00 Mozambican Metical random",
5293 "1.00 Mozambican escudo random",
5294 "1.00 Mozambican escudos random",
5295 "1.00 Mozambican metical random",
5296 "1.00 Mozambican meticals random",
5297 "1.00 Myanmar Kyat random",
5298 "1.00 Myanmar kyat random",
5299 "1.00 Myanmar kyats random",
5300 "1.00 Namibian Dollar random",
5301 "1.00 Namibian dollar random",
5302 "1.00 Namibian dollars random",
5303 "1.00 Nepalese Rupee random",
5304 "1.00 Nepalese rupee random",
5305 "1.00 Nepalese rupees random",
5306 "1.00 Netherlands Antillean Guilder random",
5307 "1.00 Netherlands Antillean guilder random",
5308 "1.00 Netherlands Antillean guilders random",
5309 "1.00 Dutch Guilder random",
5310 "1.00 Dutch guilder random",
5311 "1.00 Dutch guilders random",
5312 "1.00 Israeli New Sheqel random",
5313 "1.00 Israeli new sheqels random",
5314 "1.00 New Zealand Dollar random",
5315 "1.00 New Zealand dollar random",
5316 "1.00 New Zealand dollars random",
5317 "1.00 Nicaraguan C\\u00f3rdoba random",
5318 "1.00 Nicaraguan C\\u00f3rdoba (1988\\u20131991) random",
5319 "1.00 Nicaraguan c\\u00f3rdoba random",
5320 "1.00 Nicaraguan c\\u00f3rdoba random",
5321 "1.00 Nicaraguan c\\u00f3rdoba (1988\\u20131991) random",
5322 "1.00 Nicaraguan c\\u00f3rdobas (1988\\u20131991) random",
5323 "1.00 Nigerian Naira random",
5324 "1.00 Nigerian naira random",
5325 "1.00 Nigerian nairas random",
5326 "1.00 North Korean Won random",
5327 "1.00 North Korean won random",
5328 "1.00 North Korean won random",
5329 "1.00 Norwegian Krone random",
5330 "1.00 Norwegian krone random",
5331 "1.00 Norwegian kroner random",
5332 "1.00 Mozambican Metical (1980\\u20132006) random",
5333 "1.00 Mozambican metical (1980\\u20132006) random",
5334 "1.00 Mozambican meticals (1980\\u20132006) random",
5335 "1.00 Romanian Lei (1952\\u20132006) random",
5336 "1.00 Romanian Leu (1952\\u20132006) random",
5337 "1.00 Romanian leu (1952\\u20132006) random",
5338 "1.00 Serbian Dinar (2002\\u20132006) random",
5339 "1.00 Serbian dinar (2002\\u20132006) random",
5340 "1.00 Serbian dinars (2002\\u20132006) random",
5341 "1.00 Sudanese Dinar (1992\\u20132007) random",
5342 "1.00 Sudanese Pound (1957\\u20131998) random",
5343 "1.00 Sudanese dinar (1992\\u20132007) random",
5344 "1.00 Sudanese dinars (1992\\u20132007) random",
5345 "1.00 Sudanese pound (1957\\u20131998) random",
5346 "1.00 Sudanese pounds (1957\\u20131998) random",
5347 "1.00 Turkish Lira (1922\\u20132005) random",
5348 "1.00 Turkish Lira (1922\\u20132005) random",
5349 "1.00 Omani Rial random",
5350 "1.00 Omani rial random",
5351 "1.00 Omani rials random",
5352 "1.00 Pakistani Rupee random",
5353 "1.00 Pakistani rupee random",
5354 "1.00 Pakistani rupees random",
5355 "1.00 Palladium random",
5356 "1.00 Palladium random",
5357 "1.00 Panamanian Balboa random",
5358 "1.00 Panamanian balboa random",
5359 "1.00 Panamanian balboas random",
5360 "1.00 Papua New Guinean Kina random",
5361 "1.00 Papua New Guinean kina random",
5362 "1.00 Papua New Guinean kina random",
5363 "1.00 Paraguayan Guarani random",
5364 "1.00 Paraguayan guarani random",
5365 "1.00 Paraguayan guaranis random",
5366 "1.00 Peruvian Inti random",
5367 "1.00 Peruvian Nuevo Sol random",
5368 "1.00 Peruvian Sol (1863\\u20131965) random",
5369 "1.00 Peruvian inti random",
5370 "1.00 Peruvian intis random",
5371 "1.00 Peruvian nuevo sol random",
5372 "1.00 Peruvian nuevos soles random",
5373 "1.00 Peruvian sol (1863\\u20131965) random",
5374 "1.00 Peruvian soles (1863\\u20131965) random",
5375 "1.00 Philippine Peso random",
5376 "1.00 Philippine peso random",
5377 "1.00 Philippine pesos random",
5378 "1.00 Platinum random",
5379 "1.00 Platinum random",
5380 "1.00 Polish Zloty (1950\\u20131995) random",
5381 "1.00 Polish Zloty random",
5382 "1.00 Polish zlotys random",
5383 "1.00 Polish zloty (PLZ) random",
5384 "1.00 Polish zloty random",
5385 "1.00 Polish zlotys (PLZ) random",
5386 "1.00 Portuguese Escudo random",
5387 "1.00 Portuguese Guinea Escudo random",
5388 "1.00 Portuguese Guinea escudo random",
5389 "1.00 Portuguese Guinea escudos random",
5390 "1.00 Portuguese escudo random",
5391 "1.00 Portuguese escudos random",
5392 "1.00 Qatari Rial random",
5393 "1.00 Qatari rial random",
5394 "1.00 Qatari rials random",
5395 "1.00 RINET Funds random",
5396 "1.00 RINET Funds random",
5397 "1.00 Rhodesian Dollar random",
5398 "1.00 Rhodesian dollar random",
5399 "1.00 Rhodesian dollars random",
5400 "1.00 Romanian Leu random",
5401 "1.00 Romanian lei random",
5402 "1.00 Romanian leu random",
5403 "1.00 Russian Ruble (1991\\u20131998) random",
5404 "1.00 Russian Ruble random",
5405 "1.00 Russian ruble (1991\\u20131998) random",
5406 "1.00 Russian ruble random",
5407 "1.00 Russian rubles (1991\\u20131998) random",
5408 "1.00 Russian rubles random",
5409 "1.00 Rwandan Franc random",
5410 "1.00 Rwandan franc random",
5411 "1.00 Rwandan francs random",
5412 "1.00 St. Helena Pound random",
5413 "1.00 St. Helena pound random",
5414 "1.00 St. Helena pounds random",
5415 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra random",
5416 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra random",
5417 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras random",
5418 "1.00 Saudi Riyal random",
5419 "1.00 Saudi riyal random",
5420 "1.00 Saudi riyals random",
5421 "1.00 Serbian Dinar random",
5422 "1.00 Serbian dinar random",
5423 "1.00 Serbian dinars random",
5424 "1.00 Seychellois Rupee random",
5425 "1.00 Seychellois rupee random",
5426 "1.00 Seychellois rupees random",
5427 "1.00 Sierra Leonean Leone random",
5428 "1.00 Sierra Leonean leone random",
5429 "1.00 Sierra Leonean leones random",
5430 "1.00 Singapore Dollar random",
5431 "1.00 Singapore dollar random",
5432 "1.00 Singapore dollars random",
5433 "1.00 Slovak Koruna random",
5434 "1.00 Slovak koruna random",
5435 "1.00 Slovak korunas random",
5436 "1.00 Slovenian Tolar random",
5437 "1.00 Slovenian tolar random",
5438 "1.00 Slovenian tolars random",
5439 "1.00 Solomon Islands Dollar random",
5440 "1.00 Solomon Islands dollar random",
5441 "1.00 Solomon Islands dollars random",
5442 "1.00 Somali Shilling random",
5443 "1.00 Somali shilling random",
5444 "1.00 Somali shillings random",
5445 "1.00 South African Rand (financial) random",
5446 "1.00 South African Rand random",
5447 "1.00 South African rand (financial) random",
5448 "1.00 South African rand random",
5449 "1.00 South African rands (financial) random",
5450 "1.00 South African rand random",
5451 "1.00 South Korean Won random",
5452 "1.00 South Korean won random",
5453 "1.00 South Korean won random",
5454 "1.00 Soviet Rouble random",
5455 "1.00 Soviet rouble random",
5456 "1.00 Soviet roubles random",
5457 "1.00 Spanish Peseta (A account) random",
5458 "1.00 Spanish Peseta (convertible account) random",
5459 "1.00 Spanish Peseta random",
5460 "1.00 Spanish peseta (A account) random",
5461 "1.00 Spanish peseta (convertible account) random",
5462 "1.00 Spanish peseta random",
5463 "1.00 Spanish pesetas (A account) random",
5464 "1.00 Spanish pesetas (convertible account) random",
5465 "1.00 Spanish pesetas random",
5466 "1.00 Special Drawing Rights random",
5467 "1.00 Sri Lankan Rupee random",
5468 "1.00 Sri Lankan rupee random",
5469 "1.00 Sri Lankan rupees random",
5470 "1.00 Sudanese Pound random",
5471 "1.00 Sudanese pound random",
5472 "1.00 Sudanese pounds random",
5473 "1.00 Surinamese Dollar random",
5474 "1.00 Surinamese dollar random",
5475 "1.00 Surinamese dollars random",
5476 "1.00 Surinamese Guilder random",
5477 "1.00 Surinamese guilder random",
5478 "1.00 Surinamese guilders random",
5479 "1.00 Swazi Lilangeni random",
5480 "1.00 Swazi lilangeni random",
5481 "1.00 Swazi emalangeni random",
5482 "1.00 Swedish Krona random",
5483 "1.00 Swedish krona random",
5484 "1.00 Swedish kronor random",
5485 "1.00 Swiss Franc random",
5486 "1.00 Swiss franc random",
5487 "1.00 Swiss francs random",
5488 "1.00 Syrian Pound random",
5489 "1.00 Syrian pound random",
5490 "1.00 Syrian pounds random",
5491 "1.00 New Taiwan Dollar random",
5492 "1.00 New Taiwan dollar random",
5493 "1.00 New Taiwan dollars random",
5494 "1.00 Tajikistani Ruble random",
5495 "1.00 Tajikistani Somoni random",
5496 "1.00 Tajikistani ruble random",
5497 "1.00 Tajikistani rubles random",
5498 "1.00 Tajikistani somoni random",
5499 "1.00 Tajikistani somonis random",
5500 "1.00 Tanzanian Shilling random",
5501 "1.00 Tanzanian shilling random",
5502 "1.00 Tanzanian shillings random",
5503 "1.00 Testing Currency Code random",
5504 "1.00 Testing Currency Code random",
5505 "1.00 Thai Baht random",
5506 "1.00 Thai baht random",
5507 "1.00 Thai baht random",
5508 "1.00 Timorese Escudo random",
5509 "1.00 Timorese escudo random",
5510 "1.00 Timorese escudos random",
5511 "1.00 Trinidad & Tobago Dollar random",
5512 "1.00 Trinidad & Tobago dollar random",
5513 "1.00 Trinidad & Tobago dollars random",
5514 "1.00 Tunisian Dinar random",
5515 "1.00 Tunisian dinar random",
5516 "1.00 Tunisian dinars random",
5517 "1.00 Turkish Lira random",
5518 "1.00 Turkish Lira random",
5519 "1.00 Turkish lira random",
5520 "1.00 Turkmenistani Manat random",
5521 "1.00 Turkmenistani manat random",
5522 "1.00 Turkmenistani manat random",
5523 "1.00 US Dollar (Next day) random",
5524 "1.00 US Dollar (Same day) random",
5525 "1.00 US Dollar random",
5526 "1.00 US dollar (next day) random",
5527 "1.00 US dollar (same day) random",
5528 "1.00 US dollar random",
5529 "1.00 US dollars (next day) random",
5530 "1.00 US dollars (same day) random",
5531 "1.00 US dollars random",
5532 "1.00 Ugandan Shilling (1966\\u20131987) random",
5533 "1.00 Ugandan Shilling random",
5534 "1.00 Ugandan shilling (1966\\u20131987) random",
5535 "1.00 Ugandan shilling random",
5536 "1.00 Ugandan shillings (1966\\u20131987) random",
5537 "1.00 Ugandan shillings random",
5538 "1.00 Ukrainian Hryvnia random",
5539 "1.00 Ukrainian Karbovanets random",
5540 "1.00 Ukrainian hryvnia random",
5541 "1.00 Ukrainian hryvnias random",
5542 "1.00 Ukrainian karbovanets random",
5543 "1.00 Ukrainian karbovantsiv random",
5544 "1.00 Colombian Real Value Unit random",
5545 "1.00 United Arab Emirates Dirham random",
5546 "1.00 Unknown Currency random",
5547 "1.00 Uruguayan Peso (1975\\u20131993) random",
5548 "1.00 Uruguayan Peso random",
5549 "1.00 Uruguayan Peso (Indexed Units) random",
5550 "1.00 Uruguayan peso (1975\\u20131993) random",
5551 "1.00 Uruguayan peso (indexed units) random",
5552 "1.00 Uruguayan peso random",
5553 "1.00 Uruguayan pesos (1975\\u20131993) random",
5554 "1.00 Uruguayan pesos (indexed units) random",
5555 "1.00 Uzbekistani Som random",
5556 "1.00 Uzbekistani som random",
5557 "1.00 Uzbekistani som random",
5558 "1.00 Vanuatu Vatu random",
5559 "1.00 Vanuatu vatu random",
5560 "1.00 Vanuatu vatus random",
5561 "1.00 Venezuelan Bol\\u00edvar random",
5562 "1.00 Venezuelan Bol\\u00edvar (1871\\u20132008) random",
5563 "1.00 Venezuelan bol\\u00edvar random",
5564 "1.00 Venezuelan bol\\u00edvars random",
5565 "1.00 Venezuelan bol\\u00edvar (1871\\u20132008) random",
5566 "1.00 Venezuelan bol\\u00edvars (1871\\u20132008) random",
5567 "1.00 Vietnamese Dong random",
5568 "1.00 Vietnamese dong random",
5569 "1.00 Vietnamese dong random",
5570 "1.00 WIR Euro random",
5571 "1.00 WIR Franc random",
5572 "1.00 WIR euro random",
5573 "1.00 WIR euros random",
5574 "1.00 WIR franc random",
5575 "1.00 WIR francs random",
5576 "1.00 Samoan Tala random",
5577 "1.00 Samoan tala random",
5578 "1.00 Samoan tala random",
5579 "1.00 Yemeni Dinar random",
5580 "1.00 Yemeni Rial random",
5581 "1.00 Yemeni dinar random",
5582 "1.00 Yemeni dinars random",
5583 "1.00 Yemeni rial random",
5584 "1.00 Yemeni rials random",
5585 "1.00 Yugoslavian Convertible Dinar (1990\\u20131992) random",
5586 "1.00 Yugoslavian Hard Dinar (1966\\u20131990) random",
5587 "1.00 Yugoslavian New Dinar (1994\\u20132002) random",
5588 "1.00 Yugoslavian convertible dinar (1990\\u20131992) random",
5589 "1.00 Yugoslavian convertible dinars (1990\\u20131992) random",
5590 "1.00 Yugoslavian hard dinar (1966\\u20131990) random",
5591 "1.00 Yugoslavian hard dinars (1966\\u20131990) random",
5592 "1.00 Yugoslavian new dinar (1994\\u20132002) random",
5593 "1.00 Yugoslavian new dinars (1994\\u20132002) random",
5594 "1.00 Zairean New Zaire (1993\\u20131998) random",
5595 "1.00 Zairean Zaire (1971\\u20131993) random",
5596 "1.00 Zairean new zaire (1993\\u20131998) random",
5597 "1.00 Zairean new zaires (1993\\u20131998) random",
5598 "1.00 Zairean zaire (1971\\u20131993) random",
5599 "1.00 Zairean zaires (1971\\u20131993) random",
5600 "1.00 Zambian Kwacha random",
5601 "1.00 Zambian kwacha random",
5602 "1.00 Zambian kwachas random",
5603 "1.00 Zimbabwean Dollar (1980\\u20132008) random",
5604 "1.00 Zimbabwean dollar (1980\\u20132008) random",
5605 "1.00 Zimbabwean dollars (1980\\u20132008) random",
5606 "1.00 euro random",
5607 "1.00 euros random",
5608 "1.00 Turkish lira (1922\\u20132005) random",
5609 "1.00 special drawing rights random",
5610 "1.00 Colombian real value unit random",
5611 "1.00 Colombian real value units random",
5612 "1.00 unknown currency random",
5613 };
5614
5615 const char* WRONG_DATA[] = {
5616 // Following are missing one last char in the currency name
5617 "usd1.00", // case sensitive
5618 "1.00 Nicaraguan Cordob",
5619 "1.00 Namibian Dolla",
5620 "1.00 Namibian dolla",
5621 "1.00 Nepalese Rupe",
5622 "1.00 Nepalese rupe",
5623 "1.00 Netherlands Antillean Guilde",
5624 "1.00 Netherlands Antillean guilde",
5625 "1.00 Dutch Guilde",
5626 "1.00 Dutch guilde",
5627 "1.00 Israeli New Sheqe",
5628 "1.00 New Zealand Dolla",
5629 "1.00 New Zealand dolla",
5630 "1.00 Nicaraguan cordob",
5631 "1.00 Nigerian Nair",
5632 "1.00 Nigerian nair",
5633 "1.00 North Korean Wo",
5634 "1.00 North Korean wo",
5635 "1.00 Norwegian Kron",
5636 "1.00 Norwegian kron",
5637 "1.00 US dolla",
5638 "1.00",
5639 "A1.00",
5640 "AD1.00",
5641 "AE1.00",
5642 "AF1.00",
5643 "AL1.00",
5644 "AM1.00",
5645 "AN1.00",
5646 "AO1.00",
5647 "AR1.00",
5648 "AT1.00",
5649 "AU1.00",
5650 "AW1.00",
5651 "AZ1.00",
5652 "Afghan Afghan1.00",
5653 "Afghan Afghani (1927\\u201320021.00",
5654 "Afl1.00",
5655 "Albanian Le1.00",
5656 "Algerian Dina1.00",
5657 "Andorran Peset1.00",
5658 "Angolan Kwanz1.00",
5659 "Angolan Kwanza (1977\\u201319901.00",
5660 "Angolan Readjusted Kwanza (1995\\u201319991.00",
5661 "Angolan New Kwanza (1990\\u201320001.00",
5662 "Argentine Austra1.00",
5663 "Argentine Pes1.00",
5664 "Argentine Peso (1983\\u201319851.00",
5665 "Armenian Dra1.00",
5666 "Aruban Flori1.00",
5667 "Australian Dolla1.00",
5668 "Austrian Schillin1.00",
5669 "Azerbaijani Mana1.00",
5670 "Azerbaijani Manat (1993\\u201320061.00",
5671 "B1.00",
5672 "BA1.00",
5673 "BB1.00",
5674 "BE1.00",
5675 "BG1.00",
5676 "BH1.00",
5677 "BI1.00",
5678 "BM1.00",
5679 "BN1.00",
5680 "BO1.00",
5681 "BR1.00",
5682 "BS1.00",
5683 "BT1.00",
5684 "BU1.00",
5685 "BW1.00",
5686 "BY1.00",
5687 "BZ1.00",
5688 "Bahamian Dolla1.00",
5689 "Bahraini Dina1.00",
5690 "Bangladeshi Tak1.00",
5691 "Barbadian Dolla1.00",
5692 "Bds1.00",
5693 "Belarusian New Ruble (1994\\u201319991.00",
5694 "Belarusian Rubl1.00",
5695 "Belgian Fran1.00",
5696 "Belgian Franc (convertible1.00",
5697 "Belgian Franc (financial1.00",
5698 "Belize Dolla1.00",
5699 "Bermudan Dolla1.00",
5700 "Bhutanese Ngultru1.00",
5701 "Bolivian Mvdo1.00",
5702 "Bolivian Pes1.00",
5703 "Bolivian Bolivian1.00",
5704 "Bosnia-Herzegovina Convertible Mar1.00",
5705 "Bosnia-Herzegovina Dina1.00",
5706 "Botswanan Pul1.00",
5707 "Brazilian Cruzad1.00",
5708 "Brazilian Cruzado Nov1.00",
5709 "Brazilian Cruzeir1.00",
5710 "Brazilian Cruzeiro (1990\\u201319931.00",
5711 "Brazilian New Cruzeiro (1967\\u201319861.00",
5712 "Brazilian Rea1.00",
5713 "British Pound Sterlin1.00",
5714 "Brunei Dolla1.00",
5715 "Bulgarian Hard Le1.00",
5716 "Bulgarian Le1.00",
5717 "Burmese Kya1.00",
5718 "Burundian Fran1.00",
5719 "C1.00",
5720 "CA1.00",
5721 "CD1.00",
5722 "CFP Fran1.00",
5723 "CFP1.00",
5724 "CH1.00",
5725 "CL1.00",
5726 "CN1.00",
5727 "CO1.00",
5728 "CS1.00",
5729 "CU1.00",
5730 "CV1.00",
5731 "CY1.00",
5732 "CZ1.00",
5733 "Cambodian Rie1.00",
5734 "Canadian Dolla1.00",
5735 "Cape Verdean Escud1.00",
5736 "Cayman Islands Dolla1.00",
5737 "Chilean Pes1.00",
5738 "Chilean Unit of Accoun1.00",
5739 "Chinese Yua1.00",
5740 "Colombian Pes1.00",
5741 "Comoro Fran1.00",
5742 "Congolese Fran1.00",
5743 "Costa Rican Col\\u00f31.00",
5744 "Croatian Dina1.00",
5745 "Croatian Kun1.00",
5746 "Cuban Pes1.00",
5747 "Cypriot Poun1.00",
5748 "Czech Republic Korun1.00",
5749 "Czechoslovak Hard Korun1.00",
5750 "D1.00",
5751 "DD1.00",
5752 "DE1.00",
5753 "DJ1.00",
5754 "DK1.00",
5755 "DO1.00",
5756 "DZ1.00",
5757 "Danish Kron1.00",
5758 "German Mar1.00",
5759 "Djiboutian Fran1.00",
5760 "Dk1.00",
5761 "Dominican Pes1.00",
5762 "EC1.00",
5763 "EE1.00",
5764 "EG1.00",
5765 "EQ1.00",
5766 "ER1.00",
5767 "ES1.00",
5768 "ET1.00",
5769 "EU1.00",
5770 "East Caribbean Dolla1.00",
5771 "East German Ostmar1.00",
5772 "Ecuadorian Sucr1.00",
5773 "Ecuadorian Unit of Constant Valu1.00",
5774 "Egyptian Poun1.00",
5775 "Ekwel1.00",
5776 "Salvadoran Col\\u00f31.00",
5777 "Equatorial Guinean Ekwel1.00",
5778 "Eritrean Nakf1.00",
5779 "Es1.00",
5780 "Estonian Kroo1.00",
5781 "Ethiopian Bir1.00",
5782 "Eur1.00",
5783 "European Composite Uni1.00",
5784 "European Currency Uni1.00",
5785 "European Monetary Uni1.00",
5786 "European Unit of Account (XBC1.00",
5787 "European Unit of Account (XBD1.00",
5788 "F1.00",
5789 "FB1.00",
5790 "FI1.00",
5791 "FJ1.00",
5792 "FK1.00",
5793 "FR1.00",
5794 "Falkland Islands Poun1.00",
5795 "Fd1.00",
5796 "Fijian Dolla1.00",
5797 "Finnish Markk1.00",
5798 "Fr1.00",
5799 "French Fran1.00",
5800 "French Gold Fran1.00",
5801 "French UIC-Fran1.00",
5802 "G1.00",
5803 "GB1.00",
5804 "GE1.00",
5805 "GH1.00",
5806 "GI1.00",
5807 "GM1.00",
5808 "GN1.00",
5809 "GQ1.00",
5810 "GR1.00",
5811 "GT1.00",
5812 "GW1.00",
5813 "GY1.00",
5814 "Gambian Dalas1.00",
5815 "Georgian Kupon Lari1.00",
5816 "Georgian Lar1.00",
5817 "Ghanaian Ced1.00",
5818 "Ghanaian Cedi (1979\\u201320071.00",
5819 "Gibraltar Poun1.00",
5820 "Gol1.00",
5821 "Greek Drachm1.00",
5822 "Guatemalan Quetza1.00",
5823 "Guinean Fran1.00",
5824 "Guinean Syl1.00",
5825 "Guinea-Bissau Pes1.00",
5826 "Guyanaese Dolla1.00",
5827 "HK1.00",
5828 "HN1.00",
5829 "HR1.00",
5830 "HT1.00",
5831 "HU1.00",
5832 "Haitian Gourd1.00",
5833 "Honduran Lempir1.00",
5834 "Hong Kong Dolla1.00",
5835 "Hungarian Forin1.00",
5836 "I1.00",
5837 "IE1.00",
5838 "IL1.00",
5839 "IN1.00",
5840 "IQ1.00",
5841 "IR1.00",
5842 "IS1.00",
5843 "IT1.00",
5844 "Icelandic Kron1.00",
5845 "Indian Rupe1.00",
5846 "Indonesian Rupia1.00",
5847 "Iranian Ria1.00",
5848 "Iraqi Dina1.00",
5849 "Irish Poun1.00",
5850 "Israeli Poun1.00",
5851 "Italian Lir1.00",
5852 "J1.00",
5853 "JM1.00",
5854 "JO1.00",
5855 "JP1.00",
5856 "Jamaican Dolla1.00",
5857 "Japanese Ye1.00",
5858 "Jordanian Dina1.00",
5859 "K S1.00",
5860 "K1.00",
5861 "KE1.00",
5862 "KG1.00",
5863 "KH1.00",
5864 "KP1.00",
5865 "KR1.00",
5866 "KW1.00",
5867 "KY1.00",
5868 "KZ1.00",
5869 "Kazakhstani Teng1.00",
5870 "Kenyan Shillin1.00",
5871 "Kuwaiti Dina1.00",
5872 "Kyrgystani So1.00",
5873 "LA1.00",
5874 "LB1.00",
5875 "LK1.00",
5876 "LR1.00",
5877 "LT1.00",
5878 "LU1.00",
5879 "LV1.00",
5880 "LY1.00",
5881 "Laotian Ki1.00",
5882 "Latvian Lat1.00",
5883 "Latvian Rubl1.00",
5884 "Lebanese Poun1.00",
5885 "Lesotho Lot1.00",
5886 "Liberian Dolla1.00",
5887 "Libyan Dina1.00",
5888 "Lithuanian Lit1.00",
5889 "Lithuanian Talona1.00",
5890 "Luxembourgian Convertible Fran1.00",
5891 "Luxembourg Financial Fran1.00",
5892 "Luxembourgian Fran1.00",
5893 "MA1.00",
5894 "MD1.00",
5895 "MDe1.00",
5896 "MEX1.00",
5897 "MG1.00",
5898 "ML1.00",
5899 "MM1.00",
5900 "MN1.00",
5901 "MO1.00",
5902 "MR1.00",
5903 "MT1.00",
5904 "MU1.00",
5905 "MV1.00",
5906 "MW1.00",
5907 "MX1.00",
5908 "MY1.00",
5909 "MZ1.00",
5910 "Macanese Patac1.00",
5911 "Macedonian Dena1.00",
5912 "Malagasy Ariar1.00",
5913 "Malagasy Fran1.00",
5914 "Malawian Kwach1.00",
5915 "Malaysian Ringgi1.00",
5916 "Maldivian Rufiya1.00",
5917 "Malian Fran1.00",
5918 "Malot1.00",
5919 "Maltese Lir1.00",
5920 "Maltese Poun1.00",
5921 "Mauritanian Ouguiy1.00",
5922 "Mauritian Rupe1.00",
5923 "Mexican Pes1.00",
5924 "Mexican Silver Peso (1861\\u201319921.00",
5925 "Mexican Investment Uni1.00",
5926 "Moldovan Le1.00",
5927 "Mongolian Tugri1.00",
5928 "Moroccan Dirha1.00",
5929 "Moroccan Fran1.00",
5930 "Mozambican Escud1.00",
5931 "Mozambican Metica1.00",
5932 "Myanmar Kya1.00",
5933 "N1.00",
5934 "NA1.00",
5935 "NAf1.00",
5936 "NG1.00",
5937 "NI1.00",
5938 "NK1.00",
5939 "NL1.00",
5940 "NO1.00",
5941 "NP1.00",
5942 "NT1.00",
5943 "Namibian Dolla1.00",
5944 "Nepalese Rupe1.00",
5945 "Netherlands Antillean Guilde1.00",
5946 "Dutch Guilde1.00",
5947 "Israeli New Sheqe1.00",
5948 "New Zealand Dolla1.00",
5949 "Nicaraguan C\\u00f3rdoba (1988\\u201319911.00",
5950 "Nicaraguan C\\u00f3rdob1.00",
5951 "Nigerian Nair1.00",
5952 "North Korean Wo1.00",
5953 "Norwegian Kron1.00",
5954 "Nr1.00",
5955 "OM1.00",
5956 "Old Mozambican Metica1.00",
5957 "Romanian Leu (1952\\u201320061.00",
5958 "Serbian Dinar (2002\\u201320061.00",
5959 "Sudanese Dinar (1992\\u201320071.00",
5960 "Sudanese Pound (1957\\u201319981.00",
5961 "Turkish Lira (1922\\u201320051.00",
5962 "Omani Ria1.00",
5963 "PA1.00",
5964 "PE1.00",
5965 "PG1.00",
5966 "PH1.00",
5967 "PK1.00",
5968 "PL1.00",
5969 "PT1.00",
5970 "PY1.00",
5971 "Pakistani Rupe1.00",
5972 "Palladiu1.00",
5973 "Panamanian Balbo1.00",
5974 "Papua New Guinean Kin1.00",
5975 "Paraguayan Guaran1.00",
5976 "Peruvian Int1.00",
5977 "Peruvian Sol (1863\\u201319651.00",
5978 "Peruvian Sol Nuev1.00",
5979 "Philippine Pes1.00",
5980 "Platinu1.00",
5981 "Polish Zlot1.00",
5982 "Polish Zloty (1950\\u201319951.00",
5983 "Portuguese Escud1.00",
5984 "Portuguese Guinea Escud1.00",
5985 "Pr1.00",
5986 "QA1.00",
5987 "Qatari Ria1.00",
5988 "RD1.00",
5989 "RH1.00",
5990 "RINET Fund1.00",
5991 "RS1.00",
5992 "RU1.00",
5993 "RW1.00",
5994 "Rb1.00",
5995 "Rhodesian Dolla1.00",
5996 "Romanian Le1.00",
5997 "Russian Rubl1.00",
5998 "Russian Ruble (1991\\u201319981.00",
5999 "Rwandan Fran1.00",
6000 "S1.00",
6001 "SA1.00",
6002 "SB1.00",
6003 "SC1.00",
6004 "SD1.00",
6005 "SE1.00",
6006 "SG1.00",
6007 "SH1.00",
6008 "SI1.00",
6009 "SK1.00",
6010 "SL R1.00",
6011 "SL1.00",
6012 "SO1.00",
6013 "ST1.00",
6014 "SU1.00",
6015 "SV1.00",
6016 "SY1.00",
6017 "SZ1.00",
6018 "St. Helena Poun1.00",
6019 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobr1.00",
6020 "Saudi Riya1.00",
6021 "Serbian Dina1.00",
6022 "Seychellois Rupe1.00",
6023 "Sh1.00",
6024 "Sierra Leonean Leon1.00",
6025 "Silve1.00",
6026 "Singapore Dolla1.00",
6027 "Slovak Korun1.00",
6028 "Slovenian Tola1.00",
6029 "Solomon Islands Dolla1.00",
6030 "Somali Shillin1.00",
6031 "South African Ran1.00",
6032 "South African Rand (financial1.00",
6033 "South Korean Wo1.00",
6034 "Soviet Roubl1.00",
6035 "Spanish Peset1.00",
6036 "Spanish Peseta (A account1.00",
6037 "Spanish Peseta (convertible account1.00",
6038 "Special Drawing Right1.00",
6039 "Sri Lankan Rupe1.00",
6040 "Sudanese Poun1.00",
6041 "Surinamese Dolla1.00",
6042 "Surinamese Guilde1.00",
6043 "Swazi Lilangen1.00",
6044 "Swedish Kron1.00",
6045 "Swiss Fran1.00",
6046 "Syrian Poun1.00",
6047 "T S1.00",
6048 "TH1.00",
6049 "TJ1.00",
6050 "TM1.00",
6051 "TN1.00",
6052 "TO1.00",
6053 "TP1.00",
6054 "TR1.00",
6055 "TT1.00",
6056 "TW1.00",
6057 "TZ1.00",
6058 "New Taiwan Dolla1.00",
6059 "Tajikistani Rubl1.00",
6060 "Tajikistani Somon1.00",
6061 "Tanzanian Shillin1.00",
6062 "Testing Currency Cod1.00",
6063 "Thai Bah1.00",
6064 "Timorese Escud1.00",
6065 "Tongan Pa\\u20bbang1.00",
6066 "Trinidad & Tobago Dolla1.00",
6067 "Tunisian Dina1.00",
6068 "Turkish Lir1.00",
6069 "Turkmenistani Mana1.00",
6070 "U S1.00",
6071 "U1.00",
6072 "UA1.00",
6073 "UG1.00",
6074 "US Dolla1.00",
6075 "US Dollar (Next day1.00",
6076 "US Dollar (Same day1.00",
6077 "US1.00",
6078 "UY1.00",
6079 "UZ1.00",
6080 "Ugandan Shillin1.00",
6081 "Ugandan Shilling (1966\\u201319871.00",
6082 "Ukrainian Hryvni1.00",
6083 "Ukrainian Karbovanet1.00",
6084 "Colombian Real Value Uni1.00",
6085 "United Arab Emirates Dirha1.00",
6086 "Unknown Currenc1.00",
6087 "Ur1.00",
6088 "Uruguay Peso (1975\\u201319931.00",
6089 "Uruguay Peso Uruguay1.00",
6090 "Uruguay Peso (Indexed Units1.00",
6091 "Uzbekistani So1.00",
6092 "V1.00",
6093 "VE1.00",
6094 "VN1.00",
6095 "VU1.00",
6096 "Vanuatu Vat1.00",
6097 "Venezuelan Bol\\u00edva1.00",
6098 "Venezuelan Bol\\u00edvar Fuert1.00",
6099 "Vietnamese Don1.00",
6100 "West African CFA Fran1.00",
6101 "Central African CFA Fran1.00",
6102 "WIR Eur1.00",
6103 "WIR Fran1.00",
6104 "WS1.00",
6105 "Samoa Tal1.00",
6106 "XA1.00",
6107 "XB1.00",
6108 "XC1.00",
6109 "XD1.00",
6110 "XE1.00",
6111 "XF1.00",
6112 "XO1.00",
6113 "XP1.00",
6114 "XR1.00",
6115 "XT1.00",
6116 "XX1.00",
6117 "YD1.00",
6118 "YE1.00",
6119 "YU1.00",
6120 "Yemeni Dina1.00",
6121 "Yemeni Ria1.00",
6122 "Yugoslavian Convertible Dina1.00",
6123 "Yugoslavian Hard Dinar (1966\\u201319901.00",
6124 "Yugoslavian New Dina1.00",
6125 "Z1.00",
6126 "ZA1.00",
6127 "ZM1.00",
6128 "ZR1.00",
6129 "ZW1.00",
6130 "Zairean New Zaire (1993\\u201319981.00",
6131 "Zairean Zair1.00",
6132 "Zambian Kwach1.00",
6133 "Zimbabwean Dollar (1980\\u201320081.00",
6134 "dra1.00",
6135 "lar1.00",
6136 "le1.00",
6137 "man1.00",
6138 "so1.00",
6139 };
6140
6141 Locale locale("en_US");
6142 for (uint32_t i=0; i<sizeof(DATA)/sizeof(DATA[0]); ++i) {
6143 UnicodeString formatted = ctou(DATA[i]);
6144 UErrorCode status = U_ZERO_ERROR;
6145 NumberFormat* numFmt = NumberFormat::createInstance(locale, UNUM_CURRENCY, status);
6146 if (numFmt != NULL && U_SUCCESS(status)) {
6147 ParsePosition parsePos;
6148 LocalPointer<CurrencyAmount> currAmt(numFmt->parseCurrency(formatted, parsePos));
6149 if (parsePos.getIndex() > 0) {
6150 double doubleVal = currAmt->getNumber().getDouble(status);
6151 if ( doubleVal != 1.0 ) {
6152 errln("Parsed as currency value other than 1.0: " + formatted + " -> " + doubleVal);
6153 }
6154 } else {
6155 errln("Failed to parse as currency: " + formatted);
6156 }
6157 } else {
6158 dataerrln("Unable to create NumberFormat. - %s", u_errorName(status));
6159 delete numFmt;
6160 break;
6161 }
6162 delete numFmt;
6163 }
6164
6165 for (uint32_t i=0; i<sizeof(WRONG_DATA)/sizeof(WRONG_DATA[0]); ++i) {
6166 UnicodeString formatted = ctou(WRONG_DATA[i]);
6167 UErrorCode status = U_ZERO_ERROR;
6168 NumberFormat* numFmt = NumberFormat::createInstance(locale, UNUM_CURRENCY, status);
6169 if (numFmt != NULL && U_SUCCESS(status)) {
6170 ParsePosition parsePos;
6171 LocalPointer<CurrencyAmount> currAmt(numFmt->parseCurrency(formatted, parsePos));
6172 if (parsePos.getIndex() > 0) {
6173 double doubleVal = currAmt->getNumber().getDouble(status);
6174 errln("Parsed as currency, should not have: " + formatted + " -> " + doubleVal);
6175 }
6176 } else {
6177 dataerrln("Unable to create NumberFormat. - %s", u_errorName(status));
6178 delete numFmt;
6179 break;
6180 }
6181 delete numFmt;
6182 }
6183 }
6184
6185 const char* attrString(int32_t);
6186
6187 // UnicodeString s;
6188 // std::string ss;
6189 // std::cout << s.toUTF8String(ss)
6190 void NumberFormatTest::expectPositions(FieldPositionIterator& iter, int32_t *values, int32_t tupleCount,
6191 const UnicodeString& str) {
6192 UBool found[10];
6193 FieldPosition fp;
6194
6195 if (tupleCount > 10) {
6196 assertTrue("internal error, tupleCount too large", FALSE);
6197 } else {
6198 for (int i = 0; i < tupleCount; ++i) {
6199 found[i] = FALSE;
6200 }
6201 }
6202
6203 logln(str);
6204 while (iter.next(fp)) {
6205 UBool ok = FALSE;
6206 int32_t id = fp.getField();
6207 int32_t start = fp.getBeginIndex();
6208 int32_t limit = fp.getEndIndex();
6209
6210 // is there a logln using printf?
6211 char buf[128];
6212 sprintf(buf, "%24s %3d %3d %3d", attrString(id), id, start, limit);
6213 logln(buf);
6214
6215 for (int i = 0; i < tupleCount; ++i) {
6216 if (found[i]) {
6217 continue;
6218 }
6219 if (values[i*3] == id &&
6220 values[i*3+1] == start &&
6221 values[i*3+2] == limit) {
6222 found[i] = ok = TRUE;
6223 break;
6224 }
6225 }
6226
6227 assertTrue((UnicodeString)"found [" + id + "," + start + "," + limit + "]", ok);
6228 }
6229
6230 // check that all were found
6231 UBool ok = TRUE;
6232 for (int i = 0; i < tupleCount; ++i) {
6233 if (!found[i]) {
6234 ok = FALSE;
6235 assertTrue((UnicodeString) "missing [" + values[i*3] + "," + values[i*3+1] + "," + values[i*3+2] + "]", found[i]);
6236 }
6237 }
6238 assertTrue("no expected values were missing", ok);
6239 }
6240
6241 void NumberFormatTest::expectPosition(FieldPosition& pos, int32_t id, int32_t start, int32_t limit,
6242 const UnicodeString& str) {
6243 logln(str);
6244 assertTrue((UnicodeString)"id " + id + " == " + pos.getField(), id == pos.getField());
6245 assertTrue((UnicodeString)"begin " + start + " == " + pos.getBeginIndex(), start == pos.getBeginIndex());
6246 assertTrue((UnicodeString)"end " + limit + " == " + pos.getEndIndex(), limit == pos.getEndIndex());
6247 }
6248
6249 void NumberFormatTest::TestFieldPositionIterator() {
6250 // bug 7372
6251 UErrorCode status = U_ZERO_ERROR;
6252 FieldPositionIterator iter1;
6253 FieldPositionIterator iter2;
6254 FieldPosition pos;
6255
6256 DecimalFormat *decFmt = (DecimalFormat *) NumberFormat::createInstance(status);
6257 if (failure(status, "NumberFormat::createInstance", TRUE)) return;
6258
6259 double num = 1234.56;
6260 UnicodeString str1;
6261 UnicodeString str2;
6262
6263 assertTrue((UnicodeString)"self==", iter1 == iter1);
6264 assertTrue((UnicodeString)"iter1==iter2", iter1 == iter2);
6265
6266 decFmt->format(num, str1, &iter1, status);
6267 assertTrue((UnicodeString)"iter1 != iter2", iter1 != iter2);
6268 decFmt->format(num, str2, &iter2, status);
6269 assertTrue((UnicodeString)"iter1 == iter2 (2)", iter1 == iter2);
6270 iter1.next(pos);
6271 assertTrue((UnicodeString)"iter1 != iter2 (2)", iter1 != iter2);
6272 iter2.next(pos);
6273 assertTrue((UnicodeString)"iter1 == iter2 (3)", iter1 == iter2);
6274
6275 // should format ok with no iterator
6276 str2.remove();
6277 decFmt->format(num, str2, NULL, status);
6278 assertEquals("null fpiter", str1, str2);
6279
6280 delete decFmt;
6281 }
6282
6283 void NumberFormatTest::TestFormatAttributes() {
6284 Locale locale("en_US");
6285 UErrorCode status = U_ZERO_ERROR;
6286 DecimalFormat *decFmt = (DecimalFormat *) NumberFormat::createInstance(locale, UNUM_CURRENCY, status);
6287 if (failure(status, "NumberFormat::createInstance", TRUE)) return;
6288 double val = 12345.67;
6289
6290 {
6291 int32_t expected[] = {
6292 UNUM_CURRENCY_FIELD, 0, 1,
6293 UNUM_GROUPING_SEPARATOR_FIELD, 3, 4,
6294 UNUM_INTEGER_FIELD, 1, 7,
6295 UNUM_DECIMAL_SEPARATOR_FIELD, 7, 8,
6296 UNUM_FRACTION_FIELD, 8, 10,
6297 };
6298 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
6299
6300 FieldPositionIterator posIter;
6301 UnicodeString result;
6302 decFmt->format(val, result, &posIter, status);
6303 expectPositions(posIter, expected, tupleCount, result);
6304 }
6305 {
6306 FieldPosition fp(UNUM_INTEGER_FIELD);
6307 UnicodeString result;
6308 decFmt->format(val, result, fp);
6309 expectPosition(fp, UNUM_INTEGER_FIELD, 1, 7, result);
6310 }
6311 {
6312 FieldPosition fp(UNUM_FRACTION_FIELD);
6313 UnicodeString result;
6314 decFmt->format(val, result, fp);
6315 expectPosition(fp, UNUM_FRACTION_FIELD, 8, 10, result);
6316 }
6317 delete decFmt;
6318
6319 decFmt = (DecimalFormat *) NumberFormat::createInstance(locale, UNUM_SCIENTIFIC, status);
6320 val = -0.0000123;
6321 {
6322 int32_t expected[] = {
6323 UNUM_SIGN_FIELD, 0, 1,
6324 UNUM_INTEGER_FIELD, 1, 2,
6325 UNUM_DECIMAL_SEPARATOR_FIELD, 2, 3,
6326 UNUM_FRACTION_FIELD, 3, 5,
6327 UNUM_EXPONENT_SYMBOL_FIELD, 5, 6,
6328 UNUM_EXPONENT_SIGN_FIELD, 6, 7,
6329 UNUM_EXPONENT_FIELD, 7, 8
6330 };
6331 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
6332
6333 FieldPositionIterator posIter;
6334 UnicodeString result;
6335 decFmt->format(val, result, &posIter, status);
6336 expectPositions(posIter, expected, tupleCount, result);
6337 }
6338 {
6339 FieldPosition fp(UNUM_INTEGER_FIELD);
6340 UnicodeString result;
6341 decFmt->format(val, result, fp);
6342 expectPosition(fp, UNUM_INTEGER_FIELD, 1, 2, result);
6343 }
6344 {
6345 FieldPosition fp(UNUM_FRACTION_FIELD);
6346 UnicodeString result;
6347 decFmt->format(val, result, fp);
6348 expectPosition(fp, UNUM_FRACTION_FIELD, 3, 5, result);
6349 }
6350 delete decFmt;
6351
6352 fflush(stderr);
6353 }
6354
6355 const char* attrString(int32_t attrId) {
6356 switch (attrId) {
6357 case UNUM_INTEGER_FIELD: return "integer";
6358 case UNUM_FRACTION_FIELD: return "fraction";
6359 case UNUM_DECIMAL_SEPARATOR_FIELD: return "decimal separator";
6360 case UNUM_EXPONENT_SYMBOL_FIELD: return "exponent symbol";
6361 case UNUM_EXPONENT_SIGN_FIELD: return "exponent sign";
6362 case UNUM_EXPONENT_FIELD: return "exponent";
6363 case UNUM_GROUPING_SEPARATOR_FIELD: return "grouping separator";
6364 case UNUM_CURRENCY_FIELD: return "currency";
6365 case UNUM_PERCENT_FIELD: return "percent";
6366 case UNUM_PERMILL_FIELD: return "permille";
6367 case UNUM_SIGN_FIELD: return "sign";
6368 default: return "";
6369 }
6370 }
6371
6372 //
6373 // Test formatting & parsing of big decimals.
6374 // API test, not a comprehensive test.
6375 // See DecimalFormatTest/DataDrivenTests
6376 //
6377 #define ASSERT_SUCCESS(status) {if (U_FAILURE(status)) errln("file %s, line %d: status: %s", \
6378 __FILE__, __LINE__, u_errorName(status));}
6379 #define ASSERT_EQUALS(expected, actual) {if ((expected) != (actual)) \
6380 errln("file %s, line %d: %s != %s", __FILE__, __LINE__, #expected, #actual);}
6381
6382 static UBool operator != (const char *s1, UnicodeString &s2) {
6383 // This function lets ASSERT_EQUALS("literal", UnicodeString) work.
6384 UnicodeString us1(s1);
6385 return us1 != s2;
6386 }
6387
6388 void NumberFormatTest::TestDecimal() {
6389 {
6390 UErrorCode status = U_ZERO_ERROR;
6391 Formattable f("12.345678999987654321E666", status);
6392 ASSERT_SUCCESS(status);
6393 StringPiece s = f.getDecimalNumber(status);
6394 ASSERT_SUCCESS(status);
6395 ASSERT_EQUALS("1.2345678999987654321E+667", s);
6396 //printf("%s\n", s.data());
6397 }
6398
6399 {
6400 UErrorCode status = U_ZERO_ERROR;
6401 Formattable f1("this is not a number", status);
6402 ASSERT_EQUALS(U_DECIMAL_NUMBER_SYNTAX_ERROR, status);
6403 }
6404
6405 {
6406 UErrorCode status = U_ZERO_ERROR;
6407 Formattable f;
6408 f.setDecimalNumber("123.45", status);
6409 ASSERT_SUCCESS(status);
6410 ASSERT_EQUALS( Formattable::kDouble, f.getType());
6411 ASSERT_EQUALS(123.45, f.getDouble());
6412 ASSERT_EQUALS(123.45, f.getDouble(status));
6413 ASSERT_SUCCESS(status);
6414 ASSERT_EQUALS("123.45", f.getDecimalNumber(status));
6415 ASSERT_SUCCESS(status);
6416
6417 f.setDecimalNumber("4.5678E7", status);
6418 int32_t n;
6419 n = f.getLong();
6420 ASSERT_EQUALS(45678000, n);
6421
6422 status = U_ZERO_ERROR;
6423 f.setDecimalNumber("-123", status);
6424 ASSERT_SUCCESS(status);
6425 ASSERT_EQUALS( Formattable::kLong, f.getType());
6426 ASSERT_EQUALS(-123, f.getLong());
6427 ASSERT_EQUALS(-123, f.getLong(status));
6428 ASSERT_SUCCESS(status);
6429 ASSERT_EQUALS("-123", f.getDecimalNumber(status));
6430 ASSERT_SUCCESS(status);
6431
6432 status = U_ZERO_ERROR;
6433 f.setDecimalNumber("1234567890123", status); // Number too big for 32 bits
6434 ASSERT_SUCCESS(status);
6435 ASSERT_EQUALS( Formattable::kInt64, f.getType());
6436 ASSERT_EQUALS(1234567890123LL, f.getInt64());
6437 ASSERT_EQUALS(1234567890123LL, f.getInt64(status));
6438 ASSERT_SUCCESS(status);
6439 ASSERT_EQUALS("1234567890123", f.getDecimalNumber(status));
6440 ASSERT_SUCCESS(status);
6441 }
6442
6443 {
6444 UErrorCode status = U_ZERO_ERROR;
6445 NumberFormat *fmtr = NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, status);
6446 if (U_FAILURE(status) || fmtr == NULL) {
6447 dataerrln("Unable to create NumberFormat");
6448 } else {
6449 UnicodeString formattedResult;
6450 StringPiece num("244444444444444444444444444444444444446.4");
6451 fmtr->format(num, formattedResult, NULL, status);
6452 ASSERT_SUCCESS(status);
6453 ASSERT_EQUALS("244,444,444,444,444,444,444,444,444,444,444,444,446.4", formattedResult);
6454 //std::string ss; std::cout << formattedResult.toUTF8String(ss);
6455 delete fmtr;
6456 }
6457 }
6458
6459 {
6460 // Check formatting a DigitList. DigitList is internal, but this is
6461 // a critical interface that must work.
6462 UErrorCode status = U_ZERO_ERROR;
6463 NumberFormat *fmtr = NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, status);
6464 if (U_FAILURE(status) || fmtr == NULL) {
6465 dataerrln("Unable to create NumberFormat");
6466 } else {
6467 UnicodeString formattedResult;
6468 DigitList dl;
6469 StringPiece num("123.4566666666666666666666666666666666621E+40");
6470 dl.set(num, status);
6471 ASSERT_SUCCESS(status);
6472 fmtr->format(dl, formattedResult, NULL, status);
6473 ASSERT_SUCCESS(status);
6474 ASSERT_EQUALS("1,234,566,666,666,666,666,666,666,666,666,666,666,621,000", formattedResult);
6475
6476 status = U_ZERO_ERROR;
6477 num.set("666.666");
6478 dl.set(num, status);
6479 FieldPosition pos(NumberFormat::FRACTION_FIELD);
6480 ASSERT_SUCCESS(status);
6481 formattedResult.remove();
6482 fmtr->format(dl, formattedResult, pos, status);
6483 ASSERT_SUCCESS(status);
6484 ASSERT_EQUALS("666.666", formattedResult);
6485 ASSERT_EQUALS(4, pos.getBeginIndex());
6486 ASSERT_EQUALS(7, pos.getEndIndex());
6487 delete fmtr;
6488 }
6489 }
6490
6491 {
6492 // Check a parse with a formatter with a multiplier.
6493 UErrorCode status = U_ZERO_ERROR;
6494 NumberFormat *fmtr = NumberFormat::createInstance(Locale::getUS(), UNUM_PERCENT, status);
6495 if (U_FAILURE(status) || fmtr == NULL) {
6496 dataerrln("Unable to create NumberFormat");
6497 } else {
6498 UnicodeString input = "1.84%";
6499 Formattable result;
6500 fmtr->parse(input, result, status);
6501 ASSERT_SUCCESS(status);
6502 ASSERT_EQUALS(0, strcmp("0.0184", result.getDecimalNumber(status).data()));
6503 //std::cout << result.getDecimalNumber(status).data();
6504 delete fmtr;
6505 }
6506 }
6507
6508 #if U_PLATFORM != U_PF_CYGWIN || defined(CYGWINMSVC)
6509 /*
6510 * This test fails on Cygwin (1.7.16) using GCC because of a rounding issue with strtod().
6511 * See #9463
6512 */
6513 {
6514 // Check that a parse returns a decimal number with full accuracy
6515 UErrorCode status = U_ZERO_ERROR;
6516 NumberFormat *fmtr = NumberFormat::createInstance(Locale::getUS(), UNUM_DECIMAL, status);
6517 if (U_FAILURE(status) || fmtr == NULL) {
6518 dataerrln("Unable to create NumberFormat");
6519 } else {
6520 UnicodeString input = "1.002200044400088880000070000";
6521 Formattable result;
6522 fmtr->parse(input, result, status);
6523 ASSERT_SUCCESS(status);
6524 ASSERT_EQUALS(0, strcmp("1.00220004440008888000007", result.getDecimalNumber(status).data()));
6525 ASSERT_EQUALS(1.00220004440008888, result.getDouble());
6526 //std::cout << result.getDecimalNumber(status).data();
6527 delete fmtr;
6528 }
6529 }
6530 #endif
6531
6532 }
6533
6534 void NumberFormatTest::TestCurrencyFractionDigits() {
6535 UErrorCode status = U_ZERO_ERROR;
6536 UnicodeString text1, text2;
6537 double value = 99.12345;
6538
6539 // Create currenct instance
6540 NumberFormat* fmt = NumberFormat::createCurrencyInstance("ja_JP", status);
6541 if (U_FAILURE(status) || fmt == NULL) {
6542 dataerrln("Unable to create NumberFormat");
6543 } else {
6544 fmt->format(value, text1);
6545
6546 // Reset the same currency and format the test value again
6547 fmt->setCurrency(fmt->getCurrency(), status);
6548 ASSERT_SUCCESS(status);
6549 fmt->format(value, text2);
6550
6551 if (text1 != text2) {
6552 errln((UnicodeString)"NumberFormat::format() should return the same result - text1="
6553 + text1 + " text2=" + text2);
6554 }
6555 delete fmt;
6556 }
6557 }
6558
6559 void NumberFormatTest::TestExponentParse() {
6560
6561 UErrorCode status = U_ZERO_ERROR;
6562 Formattable result;
6563 ParsePosition parsePos(0);
6564
6565 // set the exponent symbol
6566 status = U_ZERO_ERROR;
6567 DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::getDefault(), status);
6568 if(U_FAILURE(status)) {
6569 dataerrln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (Default)");
6570 return;
6571 }
6572
6573 // create format instance
6574 status = U_ZERO_ERROR;
6575 DecimalFormat fmt("#####", symbols, status);
6576 if(U_FAILURE(status)) {
6577 errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern, symbols*)");
6578 }
6579
6580 // parse the text
6581 fmt.parse("5.06e-27", result, parsePos);
6582 if(result.getType() != Formattable::kDouble &&
6583 result.getDouble() != 5.06E-27 &&
6584 parsePos.getIndex() != 8
6585 )
6586 {
6587 errln("ERROR: parse failed - expected 5.06E-27, 8 - returned %d, %i",
6588 result.getDouble(), parsePos.getIndex());
6589 }
6590 }
6591
6592 void NumberFormatTest::TestExplicitParents() {
6593
6594 /* Test that number formats are properly inherited from es_419 */
6595 /* These could be subject to change if the CLDR data changes */
6596 static const char* parentLocaleTests[][2]= {
6597 /* locale ID */ /* expected */
6598 {"es_CO", "1.250,75" },
6599 {"es_CR", "1.250,75" },
6600 {"es_ES", "1.250,75" },
6601 {"es_GQ", "1.250,75" },
6602 {"es_MX", "1,250.75" },
6603 {"es_US", "1,250.75" },
6604 {"es_VE", "1.250,75" },
6605 };
6606
6607 UnicodeString s;
6608
6609 for(int i=0; i < (int)(sizeof(parentLocaleTests)/sizeof(parentLocaleTests[i])); i++){
6610 UErrorCode status = U_ZERO_ERROR;
6611 const char *localeID = parentLocaleTests[i][0];
6612 UnicodeString expected(parentLocaleTests[i][1], -1, US_INV);
6613 expected = expected.unescape();
6614 char loc[256]={0};
6615 uloc_canonicalize(localeID, loc, 256, &status);
6616 NumberFormat *fmt= NumberFormat::createInstance(Locale(loc), status);
6617 if(U_FAILURE(status)){
6618 dataerrln("Could not create number formatter for locale %s - %s",localeID, u_errorName(status));
6619 continue;
6620 }
6621 s.remove();
6622 fmt->format(1250.75, s);
6623 if(s!=expected){
6624 errln(UnicodeString("FAIL: Expected: ")+expected
6625 + UnicodeString(" Got: ") + s
6626 + UnicodeString( " for locale: ")+ UnicodeString(localeID) );
6627 }
6628 if (U_FAILURE(status)){
6629 errln((UnicodeString)"FAIL: Status " + (int32_t)status);
6630 }
6631 delete fmt;
6632 }
6633
6634 }
6635
6636 /**
6637 * Test available numbering systems API.
6638 */
6639 void NumberFormatTest::TestAvailableNumberingSystems() {
6640 UErrorCode status = U_ZERO_ERROR;
6641 StringEnumeration *availableNumberingSystems = NumberingSystem::getAvailableNames(status);
6642 CHECK_DATA(status, "NumberingSystem::getAvailableNames()")
6643
6644 int32_t nsCount = availableNumberingSystems->count(status);
6645 if ( nsCount < 36 ) {
6646 errln("FAIL: Didn't get as many numbering systems as we had hoped for. Need at least 36, got %d",nsCount);
6647 }
6648
6649 /* A relatively simple test of the API. We call getAvailableNames() and cycle through */
6650 /* each name returned, attempting to create a numbering system based on that name and */
6651 /* verifying that the name returned from the resulting numbering system is the same */
6652 /* one that we initially thought. */
6653
6654 int32_t len;
6655 for ( int32_t i = 0 ; i < nsCount ; i++ ) {
6656 const char *nsname = availableNumberingSystems->next(&len,status);
6657 NumberingSystem* ns = NumberingSystem::createInstanceByName(nsname,status);
6658 if ( uprv_strcmp(nsname,ns->getName()) ) {
6659 errln("FAIL: Numbering system name didn't match for name = %s\n",nsname);
6660 }
6661
6662 delete ns;
6663 }
6664
6665 delete availableNumberingSystems;
6666 }
6667
6668 void
6669 NumberFormatTest::Test9087(void)
6670 {
6671 U_STRING_DECL(pattern,"#",1);
6672 U_STRING_INIT(pattern,"#",1);
6673
6674 U_STRING_DECL(infstr,"INF",3);
6675 U_STRING_INIT(infstr,"INF",3);
6676
6677 U_STRING_DECL(nanstr,"NAN",3);
6678 U_STRING_INIT(nanstr,"NAN",3);
6679
6680 UChar outputbuf[50] = {0};
6681 UErrorCode status = U_ZERO_ERROR;
6682 UNumberFormat* fmt = unum_open(UNUM_PATTERN_DECIMAL,pattern,1,NULL,NULL,&status);
6683 if ( U_FAILURE(status) ) {
6684 dataerrln("FAIL: error in unum_open() - %s", u_errorName(status));
6685 return;
6686 }
6687
6688 unum_setSymbol(fmt,UNUM_INFINITY_SYMBOL,infstr,3,&status);
6689 unum_setSymbol(fmt,UNUM_NAN_SYMBOL,nanstr,3,&status);
6690 if ( U_FAILURE(status) ) {
6691 errln("FAIL: error setting symbols");
6692 }
6693
6694 double inf = uprv_getInfinity();
6695
6696 unum_setAttribute(fmt,UNUM_ROUNDING_MODE,UNUM_ROUND_HALFEVEN);
6697 unum_setDoubleAttribute(fmt,UNUM_ROUNDING_INCREMENT,0);
6698
6699 UFieldPosition position = { 0, 0, 0};
6700 unum_formatDouble(fmt,inf,outputbuf,50,&position,&status);
6701
6702 if ( u_strcmp(infstr, outputbuf)) {
6703 errln((UnicodeString)"FAIL: unexpected result for infinity - expected " + infstr + " got " + outputbuf);
6704 }
6705
6706 unum_close(fmt);
6707 }
6708
6709 #include "dcfmtimp.h"
6710
6711 void NumberFormatTest::TestFormatFastpaths() {
6712 #if UCONFIG_FORMAT_FASTPATHS_49
6713 logln("Sizeof DecimalFormat = %d, Sizeof DecimalFormatInternal=%d, UNUM_DECIMALFORMAT_INTERNAL_SIZE=%d\n",
6714 sizeof(DecimalFormat), sizeof(DecimalFormatInternal), UNUM_DECIMALFORMAT_INTERNAL_SIZE);
6715 if(UNUM_DECIMALFORMAT_INTERNAL_SIZE < sizeof(DecimalFormatInternal)) {
6716 errln("Error: sizeof(DecimalFormatInternal)=%d but UNUM_DECIMALFORMAT_INTERNAL_SIZE is only %d. Increase the #define?\n", sizeof(DecimalFormatInternal), UNUM_DECIMALFORMAT_INTERNAL_SIZE);
6717 } else if(UNUM_DECIMALFORMAT_INTERNAL_SIZE > (sizeof(DecimalFormatInternal)+16)) {
6718 infoln("Note: sizeof(DecimalFormatInternal)=%d but UNUM_DECIMALFORMAT_INTERNAL_SIZE is %d. Decrease the #define? sizeof(DecimalFormat)=%d\n", sizeof(DecimalFormatInternal), UNUM_DECIMALFORMAT_INTERNAL_SIZE, sizeof(DecimalFormat));
6719 }
6720 #else
6721 infoln("NOTE: UCONFIG_FORMAT_FASTPATHS not set, test skipped.");
6722 #endif
6723
6724 // get some additional case
6725 {
6726 UErrorCode status=U_ZERO_ERROR;
6727 DecimalFormat df(UnicodeString("0000",""),status);
6728 int64_t long_number = 1;
6729 UnicodeString expect = "0001";
6730 UnicodeString result;
6731 FieldPosition pos;
6732 df.format(long_number, result, pos);
6733 if(U_FAILURE(status)||expect!=result) {
6734 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),""));
6735 } else {
6736 logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),""));
6737 }
6738 }
6739 {
6740 UErrorCode status=U_ZERO_ERROR;
6741 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6742 int64_t long_number = U_INT64_MIN; // -9223372036854775808L;
6743 // uint8_t bits[8];
6744 // memcpy(bits,&long_number,8);
6745 // for(int i=0;i<8;i++) {
6746 // logln("bits: %02X", (unsigned int)bits[i]);
6747 // }
6748 UnicodeString expect = "-9223372036854775808";
6749 UnicodeString result;
6750 FieldPosition pos;
6751 df.format(long_number, result, pos);
6752 if(U_FAILURE(status)||expect!=result) {
6753 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
6754 } else {
6755 logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775808");
6756 }
6757 }
6758 {
6759 UErrorCode status=U_ZERO_ERROR;
6760 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6761 int64_t long_number = U_INT64_MAX; // -9223372036854775808L;
6762 // uint8_t bits[8];
6763 // memcpy(bits,&long_number,8);
6764 // for(int i=0;i<8;i++) {
6765 // logln("bits: %02X", (unsigned int)bits[i]);
6766 // }
6767 UnicodeString expect = "9223372036854775807";
6768 UnicodeString result;
6769 FieldPosition pos;
6770 df.format(long_number, result, pos);
6771 if(U_FAILURE(status)||expect!=result) {
6772 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
6773 } else {
6774 logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on U_INT64_MAX");
6775 }
6776 }
6777 {
6778 UErrorCode status=U_ZERO_ERROR;
6779 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6780 int64_t long_number = 0;
6781 // uint8_t bits[8];
6782 // memcpy(bits,&long_number,8);
6783 // for(int i=0;i<8;i++) {
6784 // logln("bits: %02X", (unsigned int)bits[i]);
6785 // }
6786 UnicodeString expect = "0000000000000000000";
6787 UnicodeString result;
6788 FieldPosition pos;
6789 df.format(long_number, result, pos);
6790 if(U_FAILURE(status)||expect!=result) {
6791 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
6792 } else {
6793 logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on 0");
6794 }
6795 }
6796 {
6797 UErrorCode status=U_ZERO_ERROR;
6798 DecimalFormat df(UnicodeString("0000000000000000000",""),status);
6799 int64_t long_number = U_INT64_MIN + 1;
6800 UnicodeString expect = "-9223372036854775807";
6801 UnicodeString result;
6802 FieldPosition pos;
6803 df.format(long_number, result, pos);
6804 if(U_FAILURE(status)||expect!=result) {
6805 errcheckln(status, "FAIL: expected '"+expect+"' got '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
6806 } else {
6807 logln("OK: got expected '"+result+"' status "+UnicodeString(u_errorName(status),"")+" on -9223372036854775807");
6808 }
6809 }
6810 }
6811
6812
6813 void NumberFormatTest::TestFormattableSize(void) {
6814 if(sizeof(FmtStackData) > UNUM_INTERNAL_STACKARRAY_SIZE) {
6815 errln("Error: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
6816 sizeof(FmtStackData), UNUM_INTERNAL_STACKARRAY_SIZE);
6817 } else if(sizeof(FmtStackData) < UNUM_INTERNAL_STACKARRAY_SIZE) {
6818 logln("Warning: sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
6819 sizeof(FmtStackData), UNUM_INTERNAL_STACKARRAY_SIZE);
6820 } else {
6821 logln("sizeof(FmtStackData)=%d, UNUM_INTERNAL_STACKARRAY_SIZE=%d\n",
6822 sizeof(FmtStackData), UNUM_INTERNAL_STACKARRAY_SIZE);
6823 }
6824 }
6825
6826 UBool NumberFormatTest::testFormattableAsUFormattable(const char *file, int line, Formattable &f) {
6827 UnicodeString fileLine = UnicodeString(file)+UnicodeString(":")+line+UnicodeString(": ");
6828
6829 UFormattable *u = f.toUFormattable();
6830 logln();
6831 if (u == NULL) {
6832 errln("%s:%d: Error: f.toUFormattable() retuned NULL.");
6833 return FALSE;
6834 }
6835 logln("%s:%d: comparing Formattable with UFormattable", file, line);
6836 logln(fileLine + toString(f));
6837
6838 UErrorCode status = U_ZERO_ERROR;
6839 UErrorCode valueStatus = U_ZERO_ERROR;
6840 UFormattableType expectUType = UFMT_COUNT; // invalid
6841
6842 UBool triedExact = FALSE; // did we attempt an exact comparison?
6843 UBool exactMatch = FALSE; // was the exact comparison true?
6844
6845 switch( f.getType() ) {
6846 case Formattable::kDate:
6847 expectUType = UFMT_DATE;
6848 exactMatch = (f.getDate()==ufmt_getDate(u, &valueStatus));
6849 triedExact = TRUE;
6850 break;
6851 case Formattable::kDouble:
6852 expectUType = UFMT_DOUBLE;
6853 exactMatch = (f.getDouble()==ufmt_getDouble(u, &valueStatus));
6854 triedExact = TRUE;
6855 break;
6856 case Formattable::kLong:
6857 expectUType = UFMT_LONG;
6858 exactMatch = (f.getLong()==ufmt_getLong(u, &valueStatus));
6859 triedExact = TRUE;
6860 break;
6861 case Formattable::kString:
6862 expectUType = UFMT_STRING;
6863 {
6864 UnicodeString str;
6865 f.getString(str);
6866 int32_t len;
6867 const UChar* uch = ufmt_getUChars(u, &len, &valueStatus);
6868 if(U_SUCCESS(valueStatus)) {
6869 UnicodeString str2(uch, len);
6870 assertTrue("UChar* NULL-terminated", uch[len]==0);
6871 exactMatch = (str == str2);
6872 }
6873 triedExact = TRUE;
6874 }
6875 break;
6876 case Formattable::kArray:
6877 expectUType = UFMT_ARRAY;
6878 triedExact = TRUE;
6879 {
6880 int32_t count = ufmt_getArrayLength(u, &valueStatus);
6881 int32_t count2;
6882 const Formattable *array2 = f.getArray(count2);
6883 exactMatch = assertEquals(fileLine + " array count", count, count2);
6884
6885 if(exactMatch) {
6886 for(int i=0;U_SUCCESS(valueStatus) && i<count;i++) {
6887 UFormattable *uu = ufmt_getArrayItemByIndex(u, i, &valueStatus);
6888 if(*Formattable::fromUFormattable(uu) != (array2[i])) {
6889 errln("%s:%d: operator== did not match at index[%d] - %p vs %p", file, line, i,
6890 (const void*)Formattable::fromUFormattable(uu), (const void*)&(array2[i]));
6891 exactMatch = FALSE;
6892 } else {
6893 if(!testFormattableAsUFormattable("(sub item)",i,*Formattable::fromUFormattable(uu))) {
6894 exactMatch = FALSE;
6895 }
6896 }
6897 }
6898 }
6899 }
6900 break;
6901 case Formattable::kInt64:
6902 expectUType = UFMT_INT64;
6903 exactMatch = (f.getInt64()==ufmt_getInt64(u, &valueStatus));
6904 triedExact = TRUE;
6905 break;
6906 case Formattable::kObject:
6907 expectUType = UFMT_OBJECT;
6908 exactMatch = (f.getObject()==ufmt_getObject(u, &valueStatus));
6909 triedExact = TRUE;
6910 break;
6911 }
6912 UFormattableType uType = ufmt_getType(u, &status);
6913
6914 if(U_FAILURE(status)) {
6915 errln("%s:%d: Error calling ufmt_getType - %s", file, line, u_errorName(status));
6916 return FALSE;
6917 }
6918
6919 if(uType != expectUType) {
6920 errln("%s:%d: got type (%d) expected (%d) from ufmt_getType", file, line, (int) uType, (int) expectUType);
6921 }
6922
6923 if(triedExact) {
6924 if(U_FAILURE(valueStatus)) {
6925 errln("%s:%d: got err %s trying to ufmt_get...() for exact match check", file, line, u_errorName(valueStatus));
6926 } else if(!exactMatch) {
6927 errln("%s:%d: failed exact match for the Formattable type", file, line);
6928 } else {
6929 logln("%s:%d: exact match OK", file, line);
6930 }
6931 } else {
6932 logln("%s:%d: note, did not attempt exact match for this formattable type", file, line);
6933 }
6934
6935 if( assertEquals(fileLine + " isNumeric()", f.isNumeric(), ufmt_isNumeric(u))
6936 && f.isNumeric()) {
6937 UErrorCode convStatus = U_ZERO_ERROR;
6938
6939 if(uType != UFMT_INT64) { // may fail to compare
6940 assertTrue(fileLine + " as doubles ==", f.getDouble(convStatus)==ufmt_getDouble(u, &convStatus));
6941 }
6942
6943 if( assertSuccess(fileLine + " (numeric conversion status)", convStatus) ) {
6944 StringPiece fDecNum = f.getDecimalNumber(convStatus);
6945 #if 1
6946 int32_t len;
6947 const char *decNumChars = ufmt_getDecNumChars(u, &len, &convStatus);
6948 #else
6949 // copy version
6950 char decNumChars[200];
6951 int32_t len = ufmt_getDecNumChars(u, decNumChars, 200, &convStatus);
6952 #endif
6953
6954 if( assertSuccess(fileLine + " (decNumbers conversion)", convStatus) ) {
6955 logln(fileLine + decNumChars);
6956 assertEquals(fileLine + " decNumChars length==", len, fDecNum.length());
6957 assertEquals(fileLine + " decNumChars digits", decNumChars, fDecNum.data());
6958 }
6959
6960 UErrorCode int64ConversionF = U_ZERO_ERROR;
6961 int64_t l = f.getInt64(int64ConversionF);
6962 UErrorCode int64ConversionU = U_ZERO_ERROR;
6963 int64_t r = ufmt_getInt64(u, &int64ConversionU);
6964
6965 if( (l==r)
6966 && ( uType != UFMT_INT64 ) // int64 better not overflow
6967 && (U_INVALID_FORMAT_ERROR==int64ConversionU)
6968 && (U_INVALID_FORMAT_ERROR==int64ConversionF) ) {
6969 logln("%s:%d: OK: 64 bit overflow", file, line);
6970 } else {
6971 assertEquals(fileLine + " as int64 ==", l, r);
6972 assertSuccess(fileLine + " Formattable.getnt64()", int64ConversionF);
6973 assertSuccess(fileLine + " ufmt_getInt64()", int64ConversionU);
6974 }
6975 }
6976 }
6977 return exactMatch || !triedExact;
6978 }
6979
6980 void NumberFormatTest::TestUFormattable(void) {
6981 {
6982 // test that a default formattable is equal to Formattable()
6983 UErrorCode status = U_ZERO_ERROR;
6984 LocalUFormattablePointer defaultUFormattable(ufmt_open(&status));
6985 assertSuccess("calling umt_open", status);
6986 Formattable defaultFormattable;
6987 assertTrue((UnicodeString)"comparing ufmt_open() with Formattable()",
6988 (defaultFormattable
6989 == *(Formattable::fromUFormattable(defaultUFormattable.getAlias()))));
6990 assertTrue((UnicodeString)"comparing ufmt_open() with Formattable()",
6991 (defaultFormattable
6992 == *(Formattable::fromUFormattable(defaultUFormattable.getAlias()))));
6993 assertTrue((UnicodeString)"comparing Formattable() round tripped through UFormattable",
6994 (defaultFormattable
6995 == *(Formattable::fromUFormattable(defaultFormattable.toUFormattable()))));
6996 assertTrue((UnicodeString)"comparing &Formattable() round tripped through UFormattable",
6997 ((&defaultFormattable)
6998 == Formattable::fromUFormattable(defaultFormattable.toUFormattable())));
6999 assertFalse((UnicodeString)"comparing &Formattable() with ufmt_open()",
7000 ((&defaultFormattable)
7001 == Formattable::fromUFormattable(defaultUFormattable.getAlias())));
7002 testFormattableAsUFormattable(__FILE__, __LINE__, defaultFormattable);
7003 }
7004 // test some random Formattables
7005 {
7006 Formattable f(ucal_getNow(), Formattable::kIsDate);
7007 testFormattableAsUFormattable(__FILE__, __LINE__, f);
7008 }
7009 {
7010 Formattable f((double)1.61803398874989484820); // golden ratio
7011 testFormattableAsUFormattable(__FILE__, __LINE__, f);
7012 }
7013 {
7014 Formattable f((int64_t)80994231587905127LL); // weight of the moon, in kilotons http://solarsystem.nasa.gov/planets/profile.cfm?Display=Facts&Object=Moon
7015 testFormattableAsUFormattable(__FILE__, __LINE__, f);
7016 }
7017 {
7018 Formattable f((int32_t)4); // random number, source: http://www.xkcd.com/221/
7019 testFormattableAsUFormattable(__FILE__, __LINE__, f);
7020 }
7021 {
7022 Formattable f("Hello world."); // should be invariant?
7023 testFormattableAsUFormattable(__FILE__, __LINE__, f);
7024 }
7025 {
7026 UErrorCode status2 = U_ZERO_ERROR;
7027 Formattable f(StringPiece("73476730924573500000000.0"), status2); // weight of the moon, kg
7028 assertSuccess("Constructing a StringPiece", status2);
7029 testFormattableAsUFormattable(__FILE__, __LINE__, f);
7030 }
7031 {
7032 UErrorCode status2 = U_ZERO_ERROR;
7033 UObject *obj = new Locale();
7034 Formattable f(obj);
7035 assertSuccess("Constructing a Formattable from a default constructed Locale()", status2);
7036 testFormattableAsUFormattable(__FILE__, __LINE__, f);
7037 }
7038 {
7039 const Formattable array[] = {
7040 Formattable(ucal_getNow(), Formattable::kIsDate),
7041 Formattable((int32_t)4),
7042 Formattable((double)1.234),
7043 };
7044
7045 Formattable fa(array, 3);
7046 testFormattableAsUFormattable(__FILE__, __LINE__, fa);
7047 }
7048 }
7049
7050 void NumberFormatTest::TestSignificantDigits(void) {
7051 double input[] = {
7052 0, 0,
7053 0.1, -0.1,
7054 123, -123,
7055 12345, -12345,
7056 123.45, -123.45,
7057 123.44501, -123.44501,
7058 0.001234, -0.001234,
7059 0.00000000123, -0.00000000123,
7060 0.0000000000000000000123, -0.0000000000000000000123,
7061 1.2, -1.2,
7062 0.0000000012344501, -0.0000000012344501,
7063 123445.01, -123445.01,
7064 12344501000000000000000000000000000.0, -12344501000000000000000000000000000.0,
7065 };
7066 const char* expected[] = {
7067 "0.00", "0.00",
7068 "0.100", "-0.100",
7069 "123", "-123",
7070 "12345", "-12345",
7071 "123.45", "-123.45",
7072 "123.45", "-123.45",
7073 "0.001234", "-0.001234",
7074 "0.00000000123", "-0.00000000123",
7075 "0.0000000000000000000123", "-0.0000000000000000000123",
7076 "1.20", "-1.20",
7077 "0.0000000012345", "-0.0000000012345",
7078 "123450", "-123450",
7079 "12345000000000000000000000000000000", "-12345000000000000000000000000000000",
7080 };
7081
7082 UErrorCode status = U_ZERO_ERROR;
7083 Locale locale("en_US");
7084 LocalPointer<DecimalFormat> numberFormat(static_cast<DecimalFormat*>(
7085 NumberFormat::createInstance(locale, status)));
7086 CHECK_DATA(status,"NumberFormat::createInstance")
7087
7088 numberFormat->setSignificantDigitsUsed(TRUE);
7089 numberFormat->setMinimumSignificantDigits(3);
7090 numberFormat->setMaximumSignificantDigits(5);
7091 numberFormat->setGroupingUsed(false);
7092
7093 UnicodeString result;
7094 UnicodeString expectedResult;
7095 for (unsigned int i = 0; i < sizeof(input)/sizeof(double); ++i) {
7096 numberFormat->format(input[i], result);
7097 UnicodeString expectedResult(expected[i]);
7098 if (result != expectedResult) {
7099 errln((UnicodeString)"Expected: '" + expectedResult + "' got '" + result);
7100 }
7101 result.remove();
7102 }
7103 }
7104
7105 void NumberFormatTest::TestShowZero() {
7106 UErrorCode status = U_ZERO_ERROR;
7107 Locale locale("en_US");
7108 LocalPointer<DecimalFormat> numberFormat(static_cast<DecimalFormat*>(
7109 NumberFormat::createInstance(locale, status)));
7110 CHECK_DATA(status, "NumberFormat::createInstance")
7111
7112 numberFormat->setSignificantDigitsUsed(TRUE);
7113 numberFormat->setMaximumSignificantDigits(3);
7114
7115 UnicodeString result;
7116 numberFormat->format(0.0, result);
7117 if (result != "0") {
7118 errln((UnicodeString)"Expected: 0, got " + result);
7119 }
7120 }
7121
7122 void NumberFormatTest::TestBug9936() {
7123 UErrorCode status = U_ZERO_ERROR;
7124 Locale locale("en_US");
7125 LocalPointer<DecimalFormat> numberFormat(static_cast<DecimalFormat*>(
7126 NumberFormat::createInstance(locale, status)));
7127 if (U_FAILURE(status)) {
7128 dataerrln("File %s, Line %d: status = %s.\n", __FILE__, __LINE__, u_errorName(status));
7129 return;
7130 }
7131
7132 if (numberFormat->areSignificantDigitsUsed() == TRUE) {
7133 errln("File %s, Line %d: areSignificantDigitsUsed() was TRUE, expected FALSE.\n", __FILE__, __LINE__);
7134 }
7135 numberFormat->setSignificantDigitsUsed(TRUE);
7136 if (numberFormat->areSignificantDigitsUsed() == FALSE) {
7137 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__, __LINE__);
7138 }
7139
7140 numberFormat->setSignificantDigitsUsed(FALSE);
7141 if (numberFormat->areSignificantDigitsUsed() == TRUE) {
7142 errln("File %s, Line %d: areSignificantDigitsUsed() was TRUE, expected FALSE.\n", __FILE__, __LINE__);
7143 }
7144
7145 numberFormat->setMinimumSignificantDigits(3);
7146 if (numberFormat->areSignificantDigitsUsed() == FALSE) {
7147 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__, __LINE__);
7148 }
7149
7150 numberFormat->setSignificantDigitsUsed(FALSE);
7151 numberFormat->setMaximumSignificantDigits(6);
7152 if (numberFormat->areSignificantDigitsUsed() == FALSE) {
7153 errln("File %s, Line %d: areSignificantDigitsUsed() was FALSE, expected TRUE.\n", __FILE__, __LINE__);
7154 }
7155
7156 }
7157
7158 void NumberFormatTest::TestParseNegativeWithFaLocale() {
7159 UErrorCode status = U_ZERO_ERROR;
7160 DecimalFormat *test = (DecimalFormat *) NumberFormat::createInstance("fa", status);
7161 CHECK_DATA(status, "NumberFormat::createInstance")
7162 test->setLenient(TRUE);
7163 Formattable af;
7164 ParsePosition ppos;
7165 UnicodeString value("\\u200e-0,5");
7166 value = value.unescape();
7167 test->parse(value, af, ppos);
7168 if (ppos.getIndex() == 0) {
7169 errln("Expected -0,5 to parse for Farsi.");
7170 }
7171 delete test;
7172 }
7173
7174 void NumberFormatTest::TestParseNegativeWithAlternateMinusSign() {
7175 UErrorCode status = U_ZERO_ERROR;
7176 DecimalFormat *test = (DecimalFormat *) NumberFormat::createInstance("en", status);
7177 CHECK_DATA(status, "NumberFormat::createInstance")
7178 test->setLenient(TRUE);
7179 Formattable af;
7180 ParsePosition ppos;
7181 UnicodeString value("\\u208B0.5");
7182 value = value.unescape();
7183 test->parse(value, af, ppos);
7184 if (ppos.getIndex() == 0) {
7185 errln(UnicodeString("Expected ") + value + UnicodeString(" to parse."));
7186 }
7187 delete test;
7188 }
7189
7190 void NumberFormatTest::TestCustomCurrencySignAndSeparator() {
7191 UErrorCode status = U_ZERO_ERROR;
7192 DecimalFormatSymbols custom(Locale::getUS(), status);
7193 CHECK(status, "DecimalFormatSymbols constructor");
7194
7195 custom.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "*");
7196 custom.setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol, "^");
7197 custom.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, ":");
7198
7199 UnicodeString pat(" #,##0.00");
7200 pat.insert(0, (UChar)0x00A4);
7201
7202 DecimalFormat fmt(pat, custom, status);
7203 CHECK(status, "DecimalFormat constructor");
7204
7205 UnicodeString numstr("* 1^234:56");
7206 expect2(fmt, (Formattable)((double)1234.56), numstr);
7207 }
7208
7209 typedef struct {
7210 const char * locale;
7211 UBool lenient;
7212 UnicodeString numString;
7213 double value;
7214 } SignsAndMarksItem;
7215
7216
7217 void NumberFormatTest::TestParseSignsAndMarks() {
7218 const SignsAndMarksItem items[] = {
7219 // locale lenient numString value
7220 { "en", FALSE, CharsToUnicodeString("12"), 12 },
7221 { "en", TRUE, CharsToUnicodeString("12"), 12 },
7222 { "en", FALSE, CharsToUnicodeString("-23"), -23 },
7223 { "en", TRUE, CharsToUnicodeString("-23"), -23 },
7224 { "en", TRUE, CharsToUnicodeString("- 23"), -23 },
7225 { "en", FALSE, CharsToUnicodeString("\\u200E-23"), -23 },
7226 { "en", TRUE, CharsToUnicodeString("\\u200E-23"), -23 },
7227 { "en", TRUE, CharsToUnicodeString("\\u200E- 23"), -23 },
7228
7229 { "en@numbers=arab", FALSE, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7230 { "en@numbers=arab", TRUE, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7231 { "en@numbers=arab", FALSE, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7232 { "en@numbers=arab", TRUE, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7233 { "en@numbers=arab", TRUE, CharsToUnicodeString("- \\u0664\\u0665"), -45 },
7234 { "en@numbers=arab", FALSE, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7235 { "en@numbers=arab", TRUE, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7236 { "en@numbers=arab", TRUE, CharsToUnicodeString("\\u200F- \\u0664\\u0665"), -45 },
7237
7238 { "en@numbers=arabext", FALSE, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7239 { "en@numbers=arabext", TRUE, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7240 { "en@numbers=arabext", FALSE, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7241 { "en@numbers=arabext", TRUE, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7242 { "en@numbers=arabext", TRUE, CharsToUnicodeString("- \\u06F6\\u06F7"), -67 },
7243 { "en@numbers=arabext", FALSE, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7244 { "en@numbers=arabext", TRUE, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7245 { "en@numbers=arabext", TRUE, CharsToUnicodeString("\\u200E-\\u200E \\u06F6\\u06F7"), -67 },
7246
7247 { "he", FALSE, CharsToUnicodeString("12"), 12 },
7248 { "he", TRUE, CharsToUnicodeString("12"), 12 },
7249 { "he", FALSE, CharsToUnicodeString("-23"), -23 },
7250 { "he", TRUE, CharsToUnicodeString("-23"), -23 },
7251 { "he", TRUE, CharsToUnicodeString("- 23"), -23 },
7252 { "he", FALSE, CharsToUnicodeString("\\u200E-23"), -23 },
7253 { "he", TRUE, CharsToUnicodeString("\\u200E-23"), -23 },
7254 { "he", TRUE, CharsToUnicodeString("\\u200E- 23"), -23 },
7255
7256 { "ar", FALSE, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7257 { "ar", TRUE, CharsToUnicodeString("\\u0663\\u0664"), 34 },
7258 { "ar", FALSE, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7259 { "ar", TRUE, CharsToUnicodeString("-\\u0664\\u0665"), -45 },
7260 { "ar", TRUE, CharsToUnicodeString("- \\u0664\\u0665"), -45 },
7261 { "ar", FALSE, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7262 { "ar", TRUE, CharsToUnicodeString("\\u200F-\\u0664\\u0665"), -45 },
7263 { "ar", TRUE, CharsToUnicodeString("\\u200F- \\u0664\\u0665"), -45 },
7264
7265 { "ar_MA", FALSE, CharsToUnicodeString("12"), 12 },
7266 { "ar_MA", TRUE, CharsToUnicodeString("12"), 12 },
7267 { "ar_MA", FALSE, CharsToUnicodeString("-23"), -23 },
7268 { "ar_MA", TRUE, CharsToUnicodeString("-23"), -23 },
7269 { "ar_MA", TRUE, CharsToUnicodeString("- 23"), -23 },
7270 { "ar_MA", FALSE, CharsToUnicodeString("\\u200E-23"), -23 },
7271 { "ar_MA", TRUE, CharsToUnicodeString("\\u200E-23"), -23 },
7272 { "ar_MA", TRUE, CharsToUnicodeString("\\u200E- 23"), -23 },
7273
7274 { "fa", FALSE, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7275 { "fa", TRUE, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7276 { "fa", FALSE, CharsToUnicodeString("\\u2212\\u06F6\\u06F7"), -67 },
7277 { "fa", TRUE, CharsToUnicodeString("\\u2212\\u06F6\\u06F7"), -67 },
7278 { "fa", TRUE, CharsToUnicodeString("\\u2212 \\u06F6\\u06F7"), -67 },
7279 { "fa", FALSE, CharsToUnicodeString("\\u200E\\u2212\\u200E\\u06F6\\u06F7"), -67 },
7280 { "fa", TRUE, CharsToUnicodeString("\\u200E\\u2212\\u200E\\u06F6\\u06F7"), -67 },
7281 { "fa", TRUE, CharsToUnicodeString("\\u200E\\u2212\\u200E \\u06F6\\u06F7"), -67 },
7282
7283 { "ps", FALSE, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7284 { "ps", TRUE, CharsToUnicodeString("\\u06F5\\u06F6"), 56 },
7285 { "ps", FALSE, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7286 { "ps", TRUE, CharsToUnicodeString("-\\u06F6\\u06F7"), -67 },
7287 { "ps", TRUE, CharsToUnicodeString("- \\u06F6\\u06F7"), -67 },
7288 { "ps", FALSE, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7289 { "ps", TRUE, CharsToUnicodeString("\\u200E-\\u200E\\u06F6\\u06F7"), -67 },
7290 { "ps", TRUE, CharsToUnicodeString("\\u200E-\\u200E \\u06F6\\u06F7"), -67 },
7291 { "ps", FALSE, CharsToUnicodeString("-\\u200E\\u06F6\\u06F7"), -67 },
7292 { "ps", TRUE, CharsToUnicodeString("-\\u200E\\u06F6\\u06F7"), -67 },
7293 { "ps", TRUE, CharsToUnicodeString("-\\u200E \\u06F6\\u06F7"), -67 },
7294 // terminator
7295 { NULL, 0, UnicodeString(""), 0 },
7296 };
7297
7298 const SignsAndMarksItem * itemPtr;
7299 for (itemPtr = items; itemPtr->locale != NULL; itemPtr++ ) {
7300 UErrorCode status = U_ZERO_ERROR;
7301 NumberFormat *numfmt = NumberFormat::createInstance(Locale(itemPtr->locale), status);
7302 if (U_SUCCESS(status)) {
7303 numfmt->setLenient(itemPtr->lenient);
7304 Formattable fmtobj;
7305 ParsePosition ppos;
7306 numfmt->parse(itemPtr->numString, fmtobj, ppos);
7307 if (ppos.getIndex() == itemPtr->numString.length()) {
7308 double parsedValue = fmtobj.getDouble(status);
7309 if (U_FAILURE(status) || parsedValue != itemPtr->value) {
7310 errln((UnicodeString)"FAIL: locale " + itemPtr->locale + ", lenient " + itemPtr->lenient + ", parse of \"" + itemPtr->numString + "\" gives value " + parsedValue);
7311 }
7312 } else {
7313 errln((UnicodeString)"FAIL: locale " + itemPtr->locale + ", lenient " + itemPtr->lenient + ", parse of \"" + itemPtr->numString + "\" gives position " + ppos.getIndex());
7314 }
7315 } else {
7316 dataerrln("FAIL: NumberFormat::createInstance for locale % gives error %s", itemPtr->locale, u_errorName(status));
7317 }
7318 delete numfmt;
7319 }
7320 }
7321
7322 typedef struct {
7323 DecimalFormat::ERoundingMode mode;
7324 double value;
7325 UnicodeString expected;
7326 } Test10419Data;
7327
7328
7329 // Tests that rounding works right when fractional digits is set to 0.
7330 void NumberFormatTest::Test10419RoundingWith0FractionDigits() {
7331 const Test10419Data items[] = {
7332 { DecimalFormat::kRoundCeiling, 1.488, "2"},
7333 { DecimalFormat::kRoundDown, 1.588, "1"},
7334 { DecimalFormat::kRoundFloor, 1.888, "1"},
7335 { DecimalFormat::kRoundHalfDown, 1.5, "1"},
7336 { DecimalFormat::kRoundHalfEven, 2.5, "2"},
7337 { DecimalFormat::kRoundHalfUp, 2.5, "3"},
7338 { DecimalFormat::kRoundUp, 1.5, "2"},
7339 };
7340 UErrorCode status = U_ZERO_ERROR;
7341 LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createInstance(Locale("en_US"), status));
7342 if (U_FAILURE(status)) {
7343 dataerrln("Failure creating DecimalFormat %s", u_errorName(status));
7344 return;
7345 }
7346 for (int32_t i = 0; i < (int32_t) (sizeof(items) / sizeof(items[0])); ++i) {
7347 decfmt->setRoundingMode(items[i].mode);
7348 decfmt->setMaximumFractionDigits(0);
7349 UnicodeString actual;
7350 if (items[i].expected != decfmt->format(items[i].value, actual)) {
7351 errln("Expected " + items[i].expected + ", got " + actual);
7352 }
7353 }
7354 }
7355
7356 void NumberFormatTest::Test10468ApplyPattern() {
7357 // Padding char of fmt is now 'a'
7358 UErrorCode status = U_ZERO_ERROR;
7359 DecimalFormat fmt("'I''ll'*a###.##", status);
7360
7361 if (U_FAILURE(status)) {
7362 errcheckln(status, "DecimalFormat constructor failed - %s", u_errorName(status));
7363 return;
7364 }
7365
7366 if (fmt.getPadCharacterString() != UnicodeString("a")) {
7367 errln("Padding character should be 'a'.");
7368 return;
7369 }
7370
7371 // Padding char of fmt ought to be '*' since that is the default and no
7372 // explicit padding char is specified in the new pattern.
7373 fmt.applyPattern("AA#,##0.00ZZ", status);
7374
7375 // Oops this still prints 'a' even though we changed the pattern.
7376 if (fmt.getPadCharacterString() != UnicodeString("*")) {
7377 errln("applyPattern did not clear padding character.");
7378 }
7379 }
7380
7381 void NumberFormatTest::TestRoundingScientific10542() {
7382 UErrorCode status = U_ZERO_ERROR;
7383 DecimalFormat format("0.00E0", status);
7384 if (U_FAILURE(status)) {
7385 errcheckln(status, "DecimalFormat constructor failed - %s", u_errorName(status));
7386 return;
7387 }
7388
7389 DecimalFormat::ERoundingMode roundingModes[] = {
7390 DecimalFormat::kRoundCeiling,
7391 DecimalFormat::kRoundDown,
7392 DecimalFormat::kRoundFloor,
7393 DecimalFormat::kRoundHalfDown,
7394 DecimalFormat::kRoundHalfEven,
7395 DecimalFormat::kRoundHalfUp,
7396 DecimalFormat::kRoundUp};
7397 const char *descriptions[] = {
7398 "Round Ceiling",
7399 "Round Down",
7400 "Round Floor",
7401 "Round half down",
7402 "Round half even",
7403 "Round half up",
7404 "Round up"};
7405
7406 {
7407 double values[] = {-0.003006, -0.003005, -0.003004, 0.003014, 0.003015, 0.003016};
7408 // The order of these expected values correspond to the order of roundingModes and the order of values.
7409 const char *expected[] = {
7410 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.02E-3", "3.02E-3", "3.02E-3",
7411 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.01E-3",
7412 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.01E-3", "3.01E-3", "3.01E-3",
7413 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.02E-3",
7414 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E-3",
7415 "-3.01E-3", "-3.01E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E-3",
7416 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.02E-3", "3.02E-3", "3.02E-3"};
7417 verifyRounding(
7418 format,
7419 values,
7420 expected,
7421 roundingModes,
7422 descriptions,
7423 (int32_t) (sizeof(values) / sizeof(values[0])),
7424 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7425 }
7426 {
7427 double values[] = {-3006.0, -3005, -3004, 3014, 3015, 3016};
7428 // The order of these expected values correspond to the order of roundingModes and the order of values.
7429 const char *expected[] = {
7430 "-3.00E3", "-3.00E3", "-3.00E3", "3.02E3", "3.02E3", "3.02E3",
7431 "-3.00E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.01E3",
7432 "-3.01E3", "-3.01E3", "-3.01E3", "3.01E3", "3.01E3", "3.01E3",
7433 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.02E3",
7434 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3",
7435 "-3.01E3", "-3.01E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3",
7436 "-3.01E3", "-3.01E3", "-3.01E3", "3.02E3", "3.02E3", "3.02E3"};
7437 verifyRounding(
7438 format,
7439 values,
7440 expected,
7441 roundingModes,
7442 descriptions,
7443 (int32_t) (sizeof(values) / sizeof(values[0])),
7444 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7445 }
7446 /* Commented out for now until we decide how rounding to zero should work, +0 vs. -0
7447 {
7448 double values[] = {0.0, -0.0};
7449 // The order of these expected values correspond to the order of roundingModes and the order of values.
7450 const char *expected[] = {
7451 "0.00E0", "-0.00E0",
7452 "0.00E0", "-0.00E0",
7453 "0.00E0", "-0.00E0",
7454 "0.00E0", "-0.00E0",
7455 "0.00E0", "-0.00E0",
7456 "0.00E0", "-0.00E0",
7457 "0.00E0", "-0.00E0"};
7458 verifyRounding(
7459 format,
7460 values,
7461 expected,
7462 roundingModes,
7463 descriptions,
7464 (int32_t) (sizeof(values) / sizeof(values[0])),
7465 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7466 }
7467 */
7468 {
7469
7470 double values[] = {1e25, 1e25 + 1e15, 1e25 - 1e15};
7471 // The order of these expected values correspond to the order of roundingModes and the order of values.
7472 const char *expected[] = {
7473 "1.00E25", "1.01E25", "1.00E25",
7474 "1.00E25", "1.00E25", "9.99E24",
7475 "1.00E25", "1.00E25", "9.99E24",
7476 "1.00E25", "1.00E25", "1.00E25",
7477 "1.00E25", "1.00E25", "1.00E25",
7478 "1.00E25", "1.00E25", "1.00E25",
7479 "1.00E25", "1.01E25", "1.00E25"};
7480 verifyRounding(
7481 format,
7482 values,
7483 expected,
7484 roundingModes,
7485 descriptions,
7486 (int32_t) (sizeof(values) / sizeof(values[0])),
7487 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7488 }
7489 {
7490 double values[] = {-1e25, -1e25 + 1e15, -1e25 - 1e15};
7491 // The order of these expected values correspond to the order of roundingModes and the order of values.
7492 const char *expected[] = {
7493 "-1.00E25", "-9.99E24", "-1.00E25",
7494 "-1.00E25", "-9.99E24", "-1.00E25",
7495 "-1.00E25", "-1.00E25", "-1.01E25",
7496 "-1.00E25", "-1.00E25", "-1.00E25",
7497 "-1.00E25", "-1.00E25", "-1.00E25",
7498 "-1.00E25", "-1.00E25", "-1.00E25",
7499 "-1.00E25", "-1.00E25", "-1.01E25"};
7500 verifyRounding(
7501 format,
7502 values,
7503 expected,
7504 roundingModes,
7505 descriptions,
7506 (int32_t) (sizeof(values) / sizeof(values[0])),
7507 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7508 }
7509 {
7510 double values[] = {1e-25, 1e-25 + 1e-35, 1e-25 - 1e-35};
7511 // The order of these expected values correspond to the order of roundingModes and the order of values.
7512 const char *expected[] = {
7513 "1.00E-25", "1.01E-25", "1.00E-25",
7514 "1.00E-25", "1.00E-25", "9.99E-26",
7515 "1.00E-25", "1.00E-25", "9.99E-26",
7516 "1.00E-25", "1.00E-25", "1.00E-25",
7517 "1.00E-25", "1.00E-25", "1.00E-25",
7518 "1.00E-25", "1.00E-25", "1.00E-25",
7519 "1.00E-25", "1.01E-25", "1.00E-25"};
7520 verifyRounding(
7521 format,
7522 values,
7523 expected,
7524 roundingModes,
7525 descriptions,
7526 (int32_t) (sizeof(values) / sizeof(values[0])),
7527 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7528 }
7529 {
7530 double values[] = {-1e-25, -1e-25 + 1e-35, -1e-25 - 1e-35};
7531 // The order of these expected values correspond to the order of roundingModes and the order of values.
7532 const char *expected[] = {
7533 "-1.00E-25", "-9.99E-26", "-1.00E-25",
7534 "-1.00E-25", "-9.99E-26", "-1.00E-25",
7535 "-1.00E-25", "-1.00E-25", "-1.01E-25",
7536 "-1.00E-25", "-1.00E-25", "-1.00E-25",
7537 "-1.00E-25", "-1.00E-25", "-1.00E-25",
7538 "-1.00E-25", "-1.00E-25", "-1.00E-25",
7539 "-1.00E-25", "-1.00E-25", "-1.01E-25"};
7540 verifyRounding(
7541 format,
7542 values,
7543 expected,
7544 roundingModes,
7545 descriptions,
7546 (int32_t) (sizeof(values) / sizeof(values[0])),
7547 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0])));
7548 }
7549 }
7550
7551 void NumberFormatTest::TestZeroScientific10547() {
7552 UErrorCode status = U_ZERO_ERROR;
7553 DecimalFormat fmt("0.00E0", status);
7554 if (!assertSuccess("Formt creation", status)) {
7555 return;
7556 }
7557 UnicodeString out;
7558 fmt.format(-0.0, out);
7559 assertEquals("format", "-0.00E0", out);
7560 }
7561
7562 void NumberFormatTest::verifyRounding(
7563 DecimalFormat& format,
7564 const double *values,
7565 const char * const *expected,
7566 const DecimalFormat::ERoundingMode *roundingModes,
7567 const char * const *descriptions,
7568 int32_t valueSize,
7569 int32_t roundingModeSize) {
7570 for (int32_t i = 0; i < roundingModeSize; ++i) {
7571 format.setRoundingMode(roundingModes[i]);
7572 for (int32_t j = 0; j < valueSize; j++) {
7573 UnicodeString currentExpected(expected[i * valueSize + j]);
7574 currentExpected = currentExpected.unescape();
7575 UnicodeString actual;
7576 format.format(values[j], actual);
7577 if (currentExpected != actual) {
7578 char buffer[256];
7579 sprintf(
7580 buffer,
7581 "For %s value %f, expected ",
7582 descriptions[i],
7583 values[j]);
7584 errln(UnicodeString(buffer) + currentExpected + ", got " + actual);
7585 }
7586 }
7587 }
7588 }
7589
7590 void NumberFormatTest::TestAccountingCurrency() {
7591 UErrorCode status = U_ZERO_ERROR;
7592 UNumberFormatStyle style = UNUM_CURRENCY_ACCOUNTING;
7593
7594 expect(NumberFormat::createInstance("en_US", style, status),
7595 (Formattable)1234.5, "$1,234.50", TRUE, status);
7596 expect(NumberFormat::createInstance("en_US", style, status),
7597 (Formattable)-1234.5, "($1,234.50)", TRUE, status);
7598 expect(NumberFormat::createInstance("en_US", style, status),
7599 (Formattable)0, "$0.00", TRUE, status);
7600 expect(NumberFormat::createInstance("en_US", style, status),
7601 (Formattable)-0.2, "($0.20)", TRUE, status);
7602 expect(NumberFormat::createInstance("ja_JP", style, status),
7603 (Formattable)10000, UnicodeString("\\u00A510,000").unescape(), TRUE, status);
7604 expect(NumberFormat::createInstance("ja_JP", style, status),
7605 (Formattable)-1000.5, UnicodeString("(\\u00A51,000)").unescape(), FALSE, status);
7606 expect(NumberFormat::createInstance("de_DE", style, status),
7607 (Formattable)-23456.7, UnicodeString("-23.456,70\\u00A0\\u20AC").unescape(), TRUE, status);
7608 }
7609
7610 // for #5186
7611 void NumberFormatTest::TestEquality() {
7612 UErrorCode status = U_ZERO_ERROR;
7613 DecimalFormatSymbols* symbols = new DecimalFormatSymbols(Locale("root"), status);
7614 if (U_FAILURE(status)) {
7615 dataerrln("Fail: can't create DecimalFormatSymbols for root");
7616 return;
7617 }
7618 UnicodeString pattern("#,##0.###");
7619 DecimalFormat* fmtBase = new DecimalFormat(pattern, symbols, status);
7620 if (U_FAILURE(status)) {
7621 dataerrln("Fail: can't create DecimalFormat using root symbols");
7622 return;
7623 }
7624
7625 DecimalFormat* fmtClone = (DecimalFormat*)fmtBase->clone();
7626 fmtClone->setFormatWidth(fmtBase->getFormatWidth() + 32);
7627 if (*fmtClone == *fmtBase) {
7628 errln("Error: DecimalFormat == does not distinguish objects that differ only in FormatWidth");
7629 }
7630 delete fmtClone;
7631
7632 delete fmtBase;
7633 }
7634
7635 void NumberFormatTest::TestCurrencyUsage() {
7636 double agent = 123.567;
7637
7638 UErrorCode status;
7639 DecimalFormat *fmt;
7640
7641 // compare the Currency and Currency Cash Digits
7642 // Note that as of CLDR 26:
7643 // * TWD switches from 0 decimals to 2; PKR still has 0, so change test to that
7644 // * CAD and all other currencies that rounded to .05 no longer do
7645 // 1st time for getter/setter, 2nd time for factory method
7646 Locale enUS_PKR("en_US@currency=PKR");
7647
7648 for(int i=0; i<2; i++){
7649 status = U_ZERO_ERROR;
7650 if(i == 0){
7651 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_PKR, UNUM_CURRENCY, status);
7652 if (assertSuccess("en_US@currency=PKR/CURRENCY", status, TRUE) == FALSE) {
7653 continue;
7654 }
7655
7656 UnicodeString original;
7657 fmt->format(agent,original);
7658 assertEquals("Test Currency Usage 1", UnicodeString("PKR124"), original);
7659
7660 // test the getter here
7661 UCurrencyUsage curUsage = fmt->getCurrencyUsage();
7662 assertEquals("Test usage getter - standard", curUsage, UCURR_USAGE_STANDARD);
7663
7664 fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status);
7665 }else{
7666 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_PKR, UNUM_CASH_CURRENCY, status);
7667 if (assertSuccess("en_US@currency=PKR/CASH", status, TRUE) == FALSE) {
7668 continue;
7669 }
7670 }
7671
7672 // must be usage = cash
7673 UCurrencyUsage curUsage = fmt->getCurrencyUsage();
7674 assertEquals("Test usage getter - cash", curUsage, UCURR_USAGE_CASH);
7675
7676 UnicodeString cash_currency;
7677 fmt->format(agent,cash_currency);
7678 assertEquals("Test Currency Usage 2", UnicodeString("PKR124"), cash_currency);
7679 delete fmt;
7680 }
7681
7682 // compare the Currency and Currency Cash Rounding
7683 // 1st time for getter/setter, 2nd time for factory method
7684 Locale enUS_CAD("en_US@currency=CAD");
7685 for(int i=0; i<2; i++){
7686 status = U_ZERO_ERROR;
7687 if(i == 0){
7688 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status);
7689 if (assertSuccess("en_US@currency=CAD/CURRENCY", status, TRUE) == FALSE) {
7690 continue;
7691 }
7692
7693 UnicodeString original_rounding;
7694 fmt->format(agent, original_rounding);
7695 assertEquals("Test Currency Usage 3", UnicodeString("CA$123.57"), original_rounding);
7696 fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status);
7697 }else{
7698 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status);
7699 if (assertSuccess("en_US@currency=CAD/CASH", status, TRUE) == FALSE) {
7700 continue;
7701 }
7702 }
7703
7704 UnicodeString cash_rounding_currency;
7705 fmt->format(agent, cash_rounding_currency);
7706 assertEquals("Test Currency Usage 4", UnicodeString("CA$123.57"), cash_rounding_currency);
7707 delete fmt;
7708 }
7709
7710 // Test the currency change
7711 // 1st time for getter/setter, 2nd time for factory method
7712 const UChar CUR_PKR[] = {0x50, 0x4B, 0x52, 0};
7713 for(int i=0; i<2; i++){
7714 status = U_ZERO_ERROR;
7715 if(i == 0){
7716 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CURRENCY, status);
7717 if (assertSuccess("en_US@currency=CAD/CURRENCY", status, TRUE) == FALSE) {
7718 continue;
7719 }
7720 fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status);
7721 }else{
7722 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_CASH_CURRENCY, status);
7723 if (assertSuccess("en_US@currency=CAD/CASH", status, TRUE) == FALSE) {
7724 continue;
7725 }
7726 }
7727
7728 UnicodeString cur_original;
7729 fmt->format(agent, cur_original);
7730 assertEquals("Test Currency Usage 5", UnicodeString("CA$123.57"), cur_original);
7731
7732 fmt->setCurrency(CUR_PKR, status);
7733 assertSuccess("Set currency to PKR", status);
7734
7735 UnicodeString PKR_changed;
7736 fmt->format(agent, PKR_changed);
7737 assertEquals("Test Currency Usage 6", UnicodeString("PKR124"), PKR_changed);
7738 delete fmt;
7739 }
7740 }
7741
7742
7743 // Check the constant MAX_INT64_IN_DOUBLE.
7744 // The value should convert to a double with no loss of precision.
7745 // A failure may indicate a platform with a different double format, requiring
7746 // a revision to the constant.
7747 //
7748 // Note that this is actually hard to test, because the language standard gives
7749 // compilers considerable flexibility to do unexpected things with rounding and
7750 // with overflow in simple int to/from float conversions. Some compilers will completely optimize
7751 // away a simple round-trip conversion from int64_t -> double -> int64_t.
7752
7753 void NumberFormatTest::TestDoubleLimit11439() {
7754 char buf[50];
7755 for (int64_t num = MAX_INT64_IN_DOUBLE-10; num<=MAX_INT64_IN_DOUBLE; num++) {
7756 sprintf(buf, "%lld", (long long)num);
7757 double fNum = 0.0;
7758 sscanf(buf, "%lf", &fNum);
7759 int64_t rtNum = fNum;
7760 if (num != rtNum) {
7761 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__, __LINE__, (long long)num, (long long)rtNum);
7762 return;
7763 }
7764 }
7765 for (int64_t num = -MAX_INT64_IN_DOUBLE+10; num>=-MAX_INT64_IN_DOUBLE; num--) {
7766 sprintf(buf, "%lld", (long long)num);
7767 double fNum = 0.0;
7768 sscanf(buf, "%lf", &fNum);
7769 int64_t rtNum = fNum;
7770 if (num != rtNum) {
7771 errln("%s:%d MAX_INT64_IN_DOUBLE test, %lld did not round trip. Got %lld", __FILE__, __LINE__, (long long)num, (long long)rtNum);
7772 return;
7773 }
7774 }
7775 }
7776
7777 void NumberFormatTest::TestFastPathConsistent11524() {
7778 UErrorCode status = U_ZERO_ERROR;
7779 NumberFormat *fmt = NumberFormat::createInstance("en", status);
7780 if (U_FAILURE(status) || fmt == NULL) {
7781 dataerrln("Failed call to NumberFormat::createInstance() - %s", u_errorName(status));
7782 return;
7783 }
7784 fmt->setMaximumIntegerDigits(INT32_MIN);
7785 UnicodeString appendTo;
7786 assertEquals("", "0", fmt->format(123, appendTo));
7787 appendTo.remove();
7788 assertEquals("", "0", fmt->format(12345, appendTo));
7789 delete fmt;
7790 }
7791
7792
7793 #endif /* #if !UCONFIG_NO_FORMATTING */