OLD | NEW |
1 /******************************************************************** | 1 /******************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2013, International Business Machines Corporation and | 3 * Copyright (c) 1997-2014, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ********************************************************************/ | 5 ********************************************************************/ |
6 /* Modification History: | 6 /* Modification History: |
7 * Date Name Description | 7 * Date Name Description |
8 * 07/15/99 helena Ported to HPUX 10/11 CC. | 8 * 07/15/99 helena Ported to HPUX 10/11 CC. |
9 */ | 9 */ |
10 | 10 |
11 #include "unicode/utypes.h" | 11 #include "unicode/utypes.h" |
12 | 12 |
13 #if !UCONFIG_NO_FORMATTING | 13 #if !UCONFIG_NO_FORMATTING |
(...skipping 18 matching lines...) Expand all Loading... |
32 #include "cstring.h" | 32 #include "cstring.h" |
33 #include "unicode/numsys.h" | 33 #include "unicode/numsys.h" |
34 #include "fmtableimp.h" | 34 #include "fmtableimp.h" |
35 | 35 |
36 //#define NUMFMTST_CACHE_DEBUG 1 | 36 //#define NUMFMTST_CACHE_DEBUG 1 |
37 #include "stdio.h" /* for sprintf */ | 37 #include "stdio.h" /* for sprintf */ |
38 // #include "iostream" // for cout | 38 // #include "iostream" // for cout |
39 | 39 |
40 //#define NUMFMTST_DEBUG 1 | 40 //#define NUMFMTST_DEBUG 1 |
41 | 41 |
42 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof(array[0])) | |
43 | |
44 static const UChar EUR[] = {69,85,82,0}; // "EUR" | 42 static const UChar EUR[] = {69,85,82,0}; // "EUR" |
45 static const UChar JPY[] = {0x4A, 0x50, 0x59, 0}; | |
46 static const UChar CNY[] = {0x43, 0x4E, 0x59, 0}; | |
47 static const UChar ISO_CURRENCY_USD[] = {0x55, 0x53, 0x44, 0}; // "USD" | 43 static const UChar ISO_CURRENCY_USD[] = {0x55, 0x53, 0x44, 0}; // "USD" |
48 | 44 |
49 | 45 |
50 // ***************************************************************************** | 46 // ***************************************************************************** |
51 // class NumberFormatTest | 47 // class NumberFormatTest |
52 // ***************************************************************************** | 48 // ***************************************************************************** |
53 | 49 |
54 #define CHECK(status,str) if (U_FAILURE(status)) { errcheckln(status, UnicodeStr
ing("FAIL: ") + str + " - " + u_errorName(status)); return; } | 50 #define CHECK(status,str) if (U_FAILURE(status)) { errcheckln(status, UnicodeStr
ing("FAIL: ") + str + " - " + u_errorName(status)); return; } |
55 #define CHECK_DATA(status,str) if (U_FAILURE(status)) { dataerrln(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; } |
56 | 52 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 TESTCASE_AUTO(TestFormattableSize); | 119 TESTCASE_AUTO(TestFormattableSize); |
124 TESTCASE_AUTO(TestUFormattable); | 120 TESTCASE_AUTO(TestUFormattable); |
125 TESTCASE_AUTO(TestSignificantDigits); | 121 TESTCASE_AUTO(TestSignificantDigits); |
126 TESTCASE_AUTO(TestShowZero); | 122 TESTCASE_AUTO(TestShowZero); |
127 TESTCASE_AUTO(TestCompatibleCurrencies); | 123 TESTCASE_AUTO(TestCompatibleCurrencies); |
128 TESTCASE_AUTO(TestBug9936); | 124 TESTCASE_AUTO(TestBug9936); |
129 TESTCASE_AUTO(TestParseNegativeWithFaLocale); | 125 TESTCASE_AUTO(TestParseNegativeWithFaLocale); |
130 TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign); | 126 TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign); |
131 TESTCASE_AUTO(TestCustomCurrencySignAndSeparator); | 127 TESTCASE_AUTO(TestCustomCurrencySignAndSeparator); |
132 TESTCASE_AUTO(TestParseSignsAndMarks); | 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); |
133 TESTCASE_AUTO_END; | 136 TESTCASE_AUTO_END; |
134 } | 137 } |
135 | 138 |
136 // ------------------------------------- | 139 // ------------------------------------- |
137 | 140 |
138 // Test API (increase code coverage) | 141 // Test API (increase code coverage) |
139 void | 142 void |
140 NumberFormatTest::TestAPI(void) | 143 NumberFormatTest::TestAPI(void) |
141 { | 144 { |
142 logln("Test API"); | 145 logln("Test API"); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 } | 704 } |
702 | 705 |
703 | 706 |
704 // ------------------------------------- | 707 // ------------------------------------- |
705 static const char* testCases[][2]= { | 708 static const char* testCases[][2]= { |
706 /* locale ID */ /* expected */ | 709 /* locale ID */ /* expected */ |
707 {"ca_ES_PREEURO", "\\u20A7\\u00A01.150" }, | 710 {"ca_ES_PREEURO", "\\u20A7\\u00A01.150" }, |
708 {"de_LU_PREEURO", "1,150\\u00A0F" }, | 711 {"de_LU_PREEURO", "1,150\\u00A0F" }, |
709 {"el_GR_PREEURO", "1.150,50\\u00A0\\u0394\\u03C1\\u03C7" }, | 712 {"el_GR_PREEURO", "1.150,50\\u00A0\\u0394\\u03C1\\u03C7" }, |
710 {"en_BE_PREEURO", "1.150,50\\u00A0BEF" }, | 713 {"en_BE_PREEURO", "1.150,50\\u00A0BEF" }, |
711 {"es_ES_PREEURO", "1\\u00A0150\\u00A0\\u20A7" }, | 714 {"es_ES_PREEURO", "1.150\\u00A0\\u20A7" }, |
712 {"eu_ES_PREEURO", "\\u20A7\\u00A01.150" }, | 715 {"eu_ES_PREEURO", "\\u20A7\\u00A01.150" }, |
713 {"gl_ES_PREEURO", "1.150\\u00A0\\u20A7" }, | 716 {"gl_ES_PREEURO", "1.150\\u00A0\\u20A7" }, |
714 {"it_IT_PREEURO", "ITL\\u00A01.150" }, | 717 {"it_IT_PREEURO", "ITL\\u00A01.150" }, |
715 {"pt_PT_PREEURO", "1,150$50\\u00A0Esc."}, | 718 {"pt_PT_PREEURO", "1,150$50\\u00A0\\u200B"}, // per cldrbug 7670 |
716 {"en_US@currency=JPY", "\\u00A51,150"}, | 719 {"en_US@currency=JPY", "\\u00A51,150"}, |
717 {"en_US@currency=jpy", "\\u00A51,150"}, | 720 {"en_US@currency=jpy", "\\u00A51,150"}, |
718 {"en-US-u-cu-jpy", "\\u00A51,150"} | 721 {"en-US-u-cu-jpy", "\\u00A51,150"} |
719 }; | 722 }; |
720 /** | 723 /** |
721 * Test localized currency patterns. | 724 * Test localized currency patterns. |
722 */ | 725 */ |
723 void | 726 void |
724 NumberFormatTest::TestCurrency(void) | 727 NumberFormatTest::TestCurrency(void) |
725 { | 728 { |
726 UErrorCode status = U_ZERO_ERROR; | 729 UErrorCode status = U_ZERO_ERROR; |
727 NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(Locale::get
CanadaFrench(), status); | 730 NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(Locale::get
CanadaFrench(), status); |
728 if (U_FAILURE(status)) { | 731 if (U_FAILURE(status)) { |
729 dataerrln("Error calling NumberFormat::createCurrencyInstance()"); | 732 dataerrln("Error calling NumberFormat::createCurrencyInstance()"); |
730 return; | 733 return; |
731 } | 734 } |
732 | 735 |
733 UnicodeString s; currencyFmt->format(1.50, s); | 736 UnicodeString s; currencyFmt->format(1.50, s); |
734 logln((UnicodeString)"Un pauvre ici a..........." + s); | 737 logln((UnicodeString)"Un pauvre ici a..........." + s); |
735 if (!(s==CharsToUnicodeString("1,50\\u00A0$"))) | 738 if (!(s==CharsToUnicodeString("1,50\\u00A0$"))) |
736 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>$"); | 739 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>$"); |
737 delete currencyFmt; | 740 delete currencyFmt; |
738 s.truncate(0); | 741 s.truncate(0); |
739 char loc[256]={0}; | 742 char loc[256]={0}; |
740 int len = uloc_canonicalize("de_DE_PREEURO", loc, 256, &status); | 743 int len = uloc_canonicalize("de_DE_PREEURO", loc, 256, &status); |
741 (void)len; // Suppress unused variable warning. | 744 (void)len; // Suppress unused variable warning. |
742 currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc),status); | 745 currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc),status); |
743 currencyFmt->format(1.50, s); | 746 currencyFmt->format(1.50, s); |
744 logln((UnicodeString)"Un pauvre en Allemagne a.." + s); | 747 logln((UnicodeString)"Un pauvre en Allemagne a.." + s); |
745 if (!(s==CharsToUnicodeString("1,50\\u00A0DEM"))) | 748 if (!(s==CharsToUnicodeString("1,50\\u00A0DM"))) |
746 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>DEM"); | 749 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>DM"); |
747 delete currencyFmt; | 750 delete currencyFmt; |
748 s.truncate(0); | 751 s.truncate(0); |
749 len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status); | 752 len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status); |
750 currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status); | 753 currencyFmt = NumberFormat::createCurrencyInstance(Locale(loc), status); |
751 currencyFmt->format(1.50, s); | 754 currencyFmt->format(1.50, s); |
752 logln((UnicodeString)"Un pauvre en France a....." + s); | 755 logln((UnicodeString)"Un pauvre en France a....." + s); |
753 if (!(s==CharsToUnicodeString("1,50\\u00A0F"))) | 756 if (!(s==CharsToUnicodeString("1,50\\u00A0F"))) |
754 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>F"); | 757 errln((UnicodeString)"FAIL: Expected 1,50<nbsp>F"); |
755 delete currencyFmt; | 758 delete currencyFmt; |
756 if (U_FAILURE(status)) | 759 if (U_FAILURE(status)) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 | 822 |
820 if (U_FAILURE(ec)) { | 823 if (U_FAILURE(ec)) { |
821 errln("FAIL: getCurrencyInstance(FRANCE)"); | 824 errln("FAIL: getCurrencyInstance(FRANCE)"); |
822 delete fmt; | 825 delete fmt; |
823 return; | 826 return; |
824 } | 827 } |
825 | 828 |
826 expectCurrency(*fmt, null, 1234.56, CharsToUnicodeString("1 234,56 \\u20AC")
); | 829 expectCurrency(*fmt, null, 1234.56, CharsToUnicodeString("1 234,56 \\u20AC")
); |
827 | 830 |
828 expectCurrency(*fmt, Locale::getJapan(), | 831 expectCurrency(*fmt, Locale::getJapan(), |
829 1234.56, CharsToUnicodeString("1 235 \\u00A5JP")); // Yen | 832 1234.56, CharsToUnicodeString("1 235 JPY")); // Yen |
830 | 833 |
831 expectCurrency(*fmt, Locale("fr", "CH", ""), | 834 expectCurrency(*fmt, Locale("fr", "CH", ""), |
832 1234.56, "1 234,56 CHF"); // no more 0.05 rounding here, see
cldrbug 5548 | 835 1234.56, "1 234,56 CHF"); // no more 0.05 rounding here, see
cldrbug 5548 |
833 | 836 |
834 expectCurrency(*fmt, Locale::getUS(), | 837 expectCurrency(*fmt, Locale::getUS(), |
835 1234.56, "1 234,56 $US"); | 838 1234.56, "1 234,56 $US"); |
836 | 839 |
837 expectCurrency(*fmt, Locale::getFrance(), | 840 expectCurrency(*fmt, Locale::getFrance(), |
838 1234.56, CharsToUnicodeString("1 234,56 \\u20AC")); // Euro | 841 1234.56, CharsToUnicodeString("1 234,56 \\u20AC")); // Euro |
839 | 842 |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 &len, &ec); | 1891 &len, &ec); |
1889 assertTrue("ucurr_getName (cy default to root)", | 1892 assertTrue("ucurr_getName (cy default to root)", |
1890 U_USING_DEFAULT_WARNING == ec, TRUE); | 1893 U_USING_DEFAULT_WARNING == ec, TRUE); |
1891 | 1894 |
1892 // TODO add more tests later | 1895 // TODO add more tests later |
1893 } | 1896 } |
1894 | 1897 |
1895 void NumberFormatTest::TestCurrencyUnit(void){ | 1898 void NumberFormatTest::TestCurrencyUnit(void){ |
1896 UErrorCode ec = U_ZERO_ERROR; | 1899 UErrorCode ec = U_ZERO_ERROR; |
1897 static const UChar USD[] = {85, 83, 68, 0}; /*USD*/ | 1900 static const UChar USD[] = {85, 83, 68, 0}; /*USD*/ |
| 1901 static const UChar BAD[] = {63, 63, 63, 0}; /*???*/ |
| 1902 static const UChar BAD2[] = {63, 63, 65, 0}; /*???*/ |
1898 CurrencyUnit cu(USD, ec); | 1903 CurrencyUnit cu(USD, ec); |
1899 assertSuccess("CurrencyUnit", ec); | 1904 assertSuccess("CurrencyUnit", ec); |
1900 | 1905 |
1901 const UChar * r = cu.getISOCurrency(); // who is the buffer owner ? | 1906 const UChar * r = cu.getISOCurrency(); // who is the buffer owner ? |
1902 assertEquals("getISOCurrency()", USD, r); | 1907 assertEquals("getISOCurrency()", USD, r); |
1903 | 1908 |
1904 CurrencyUnit cu2(cu); | 1909 CurrencyUnit cu2(cu); |
1905 if (!(cu2 == cu)){ | 1910 if (!(cu2 == cu)){ |
1906 errln("CurrencyUnit copy constructed object should be same"); | 1911 errln("CurrencyUnit copy constructed object should be same"); |
1907 } | 1912 } |
1908 | 1913 |
1909 CurrencyUnit * cu3 = (CurrencyUnit *)cu.clone(); | 1914 CurrencyUnit * cu3 = (CurrencyUnit *)cu.clone(); |
1910 if (!(*cu3 == cu)){ | 1915 if (!(*cu3 == cu)){ |
1911 errln("CurrencyUnit cloned object should be same"); | 1916 errln("CurrencyUnit cloned object should be same"); |
1912 } | 1917 } |
| 1918 CurrencyUnit bad(BAD, ec); |
| 1919 assertSuccess("CurrencyUnit", ec); |
| 1920 if (cu.getIndex() == bad.getIndex()) { |
| 1921 errln("Indexes of different currencies should differ."); |
| 1922 } |
| 1923 CurrencyUnit bad2(BAD2, ec); |
| 1924 assertSuccess("CurrencyUnit", ec); |
| 1925 if (bad2.getIndex() != bad.getIndex()) { |
| 1926 errln("Indexes of unrecognized currencies should be the same."); |
| 1927 } |
| 1928 if (bad == bad2) { |
| 1929 errln("Different unrecognized currencies should not be equal."); |
| 1930 } |
| 1931 bad = bad2; |
| 1932 if (bad != bad2) { |
| 1933 errln("Currency unit assignment should be the same."); |
| 1934 } |
1913 delete cu3; | 1935 delete cu3; |
1914 } | 1936 } |
1915 | 1937 |
1916 void NumberFormatTest::TestCurrencyAmount(void){ | 1938 void NumberFormatTest::TestCurrencyAmount(void){ |
1917 UErrorCode ec = U_ZERO_ERROR; | 1939 UErrorCode ec = U_ZERO_ERROR; |
1918 static const UChar USD[] = {85, 83, 68, 0}; /*USD*/ | 1940 static const UChar USD[] = {85, 83, 68, 0}; /*USD*/ |
1919 CurrencyAmount ca(9, USD, ec); | 1941 CurrencyAmount ca(9, USD, ec); |
1920 assertSuccess("CurrencyAmount", ec); | 1942 assertSuccess("CurrencyAmount", ec); |
1921 | 1943 |
1922 CurrencyAmount ca2(ca); | 1944 CurrencyAmount ca2(ca); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2261 Locale::createFromName( | 2283 Locale::createFromName( |
2262 CharString().appendInvariantChars(mloc, ec).data()), ec)
; | 2284 CharString().appendInvariantChars(mloc, ec).data()), ec)
; |
2263 if (U_FAILURE(ec)) { | 2285 if (U_FAILURE(ec)) { |
2264 errln("FAIL: " + where + "Loc \"" + mloc + "\": " + u_errorN
ame(ec)); | 2286 errln("FAIL: " + where + "Loc \"" + mloc + "\": " + u_errorN
ame(ec)); |
2265 ec = U_ZERO_ERROR; | 2287 ec = U_ZERO_ERROR; |
2266 if (!tokens.next(tok, ec)) goto error; | 2288 if (!tokens.next(tok, ec)) goto error; |
2267 if (!tokens.next(tok, ec)) goto error; | 2289 if (!tokens.next(tok, ec)) goto error; |
2268 if (!tokens.next(tok, ec)) goto error; | 2290 if (!tokens.next(tok, ec)) goto error; |
2269 continue; | 2291 continue; |
2270 } | 2292 } |
| 2293 } else if (mfmt == NULL) { |
| 2294 errln("FAIL: " + where + "Loc \"" + mloc + "\": skip case using
previous locale, no valid MeasureFormat"); |
| 2295 if (!tokens.next(tok, ec)) goto error; |
| 2296 if (!tokens.next(tok, ec)) goto error; |
| 2297 if (!tokens.next(tok, ec)) goto error; |
| 2298 continue; |
2271 } | 2299 } |
2272 // fpc: <loc or '-'> <curr.amt> <exp. string> <exp. curr.amt> | 2300 // fpc: <loc or '-'> <curr.amt> <exp. string> <exp. curr.amt> |
2273 if (!tokens.next(currAmt, ec)) goto error; | 2301 if (!tokens.next(currAmt, ec)) goto error; |
2274 if (!tokens.next(str, ec)) goto error; | 2302 if (!tokens.next(str, ec)) goto error; |
2275 parseCurrencyAmount(currAmt, *ref, (UChar)0x2F/*'/'*/, n, ec); | 2303 parseCurrencyAmount(currAmt, *ref, (UChar)0x2F/*'/'*/, n, ec); |
2276 if (assertSuccess("parseCurrencyAmount", ec)) { | 2304 if (assertSuccess("parseCurrencyAmount", ec)) { |
2277 assertEquals(where + "getCurrencyFormat(" + mloc + ").format(" +
currAmt + ")", | 2305 assertEquals(where + "getCurrencyFormat(" + mloc + ").format(" +
currAmt + ")", |
2278 str, mfmt->format(n, out.remove(), ec)); | 2306 str, mfmt->format(n, out.remove(), ec)); |
2279 assertSuccess("format", ec); | 2307 assertSuccess("format", ec); |
2280 } | 2308 } |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 } | 2549 } |
2522 } | 2550 } |
2523 } else { | 2551 } else { |
2524 dataerrln(UnicodeString("FAIL ") + toString(n) + " x " + | 2552 dataerrln(UnicodeString("FAIL ") + toString(n) + " x " + |
2525 escape(pat) + " = \"" + | 2553 escape(pat) + " = \"" + |
2526 escape(saw) + "\", expected \"" + exp + "\""); | 2554 escape(saw) + "\", expected \"" + exp + "\""); |
2527 } | 2555 } |
2528 } | 2556 } |
2529 | 2557 |
2530 void NumberFormatTest::expect(NumberFormat* fmt, const Formattable& n, | 2558 void NumberFormatTest::expect(NumberFormat* fmt, const Formattable& n, |
2531 const UnicodeString& exp, | 2559 const UnicodeString& exp, UBool rt, |
2532 UErrorCode status) { | 2560 UErrorCode status) { |
2533 if (fmt == NULL || U_FAILURE(status)) { | 2561 if (fmt == NULL || U_FAILURE(status)) { |
2534 dataerrln("FAIL: NumberFormat constructor"); | 2562 dataerrln("FAIL: NumberFormat constructor"); |
2535 } else { | 2563 } else { |
2536 expect(*fmt, n, exp); | 2564 expect(*fmt, n, exp, rt); |
2537 } | 2565 } |
2538 delete fmt; | 2566 delete fmt; |
2539 } | 2567 } |
2540 | 2568 |
2541 void NumberFormatTest::expectCurrency(NumberFormat& nf, const Locale& locale, | 2569 void NumberFormatTest::expectCurrency(NumberFormat& nf, const Locale& locale, |
2542 double value, const UnicodeString& string)
{ | 2570 double value, const UnicodeString& string)
{ |
2543 UErrorCode ec = U_ZERO_ERROR; | 2571 UErrorCode ec = U_ZERO_ERROR; |
2544 DecimalFormat& fmt = * (DecimalFormat*) &nf; | 2572 DecimalFormat& fmt = * (DecimalFormat*) &nf; |
2545 const UChar DEFAULT_CURR[] = {45/*-*/,0}; | 2573 const UChar DEFAULT_CURR[] = {45/*-*/,0}; |
2546 UChar curr[4]; | 2574 UChar curr[4]; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2621 } else { | 2649 } else { |
2622 errln(UnicodeString("FAIL \"") + pat + "\" pos=" + apos + | 2650 errln(UnicodeString("FAIL \"") + pat + "\" pos=" + apos + |
2623 " width=" + awidth + " pad=" + apadStr + | 2651 " width=" + awidth + " pad=" + apadStr + |
2624 ", expected " + pos + " " + width + " " + pad); | 2652 ", expected " + pos + " " + width + " " + pad); |
2625 } | 2653 } |
2626 } | 2654 } |
2627 | 2655 |
2628 // This test is flaky b/c the symbols for CNY and JPY are equivalent in this loc
ale - FIXME | 2656 // This test is flaky b/c the symbols for CNY and JPY are equivalent in this loc
ale - FIXME |
2629 void NumberFormatTest::TestCompatibleCurrencies() { | 2657 void NumberFormatTest::TestCompatibleCurrencies() { |
2630 /* | 2658 /* |
| 2659 static const UChar JPY[] = {0x4A, 0x50, 0x59, 0}; |
| 2660 static const UChar CNY[] = {0x43, 0x4E, 0x59, 0}; |
2631 UErrorCode status = U_ZERO_ERROR; | 2661 UErrorCode status = U_ZERO_ERROR; |
2632 LocalPointer<NumberFormat> fmt( | 2662 LocalPointer<NumberFormat> fmt( |
2633 NumberFormat::createCurrencyInstance(Locale::getUS(), status)); | 2663 NumberFormat::createCurrencyInstance(Locale::getUS(), status)); |
2634 if (U_FAILURE(status)) { | 2664 if (U_FAILURE(status)) { |
2635 errln("Could not create number format instance."); | 2665 errln("Could not create number format instance."); |
2636 return; | 2666 return; |
2637 } | 2667 } |
2638 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__); | 2668 logln("%s:%d - testing parse of halfwidth yen sign\n", __FILE__, __LINE__); |
2639 expectParseCurrency(*fmt, JPY, 1235, "\\u00A51,235"); | 2669 expectParseCurrency(*fmt, JPY, 1235, "\\u00A51,235"); |
2640 logln("%s:%d - testing parse of fullwidth yen sign\n", __FILE__, __LINE__); | 2670 logln("%s:%d - testing parse of fullwidth yen sign\n", __FILE__, __LINE__); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2687 uprv_strcpy(theOperation, theInfo); | 2717 uprv_strcpy(theOperation, theInfo); |
2688 uprv_strcat(theOperation, ", check currency:"); | 2718 uprv_strcat(theOperation, ", check currency:"); |
2689 assertEquals(theOperation, currency, currencyAmount->getISOCurrency()); | 2719 assertEquals(theOperation, currency, currencyAmount->getISOCurrency()); |
2690 } | 2720 } |
2691 | 2721 |
2692 | 2722 |
2693 void NumberFormatTest::TestJB3832(){ | 2723 void NumberFormatTest::TestJB3832(){ |
2694 const char* localeID = "pt_PT@currency=PTE"; | 2724 const char* localeID = "pt_PT@currency=PTE"; |
2695 Locale loc(localeID); | 2725 Locale loc(localeID); |
2696 UErrorCode status = U_ZERO_ERROR; | 2726 UErrorCode status = U_ZERO_ERROR; |
2697 UnicodeString expected(CharsToUnicodeString("1,150$50\\u00A0Esc.")); | 2727 UnicodeString expected(CharsToUnicodeString("1,150$50\\u00A0\\u200B")); // p
er cldrbug 7670 |
2698 UnicodeString s; | 2728 UnicodeString s; |
2699 NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(loc, status
); | 2729 NumberFormat* currencyFmt = NumberFormat::createCurrencyInstance(loc, status
); |
2700 if(U_FAILURE(status)){ | 2730 if(U_FAILURE(status)){ |
2701 dataerrln("Could not create currency formatter for locale %s - %s", loca
leID, u_errorName(status)); | 2731 dataerrln("Could not create currency formatter for locale %s - %s", loca
leID, u_errorName(status)); |
2702 return; | 2732 return; |
2703 } | 2733 } |
2704 currencyFmt->format(1150.50, s); | 2734 currencyFmt->format(1150.50, s); |
2705 if(s!=expected){ | 2735 if(s!=expected){ |
2706 errln(UnicodeString("FAIL: Expected: ")+expected | 2736 errln(UnicodeString("FAIL: Expected: ")+expected |
2707 + UnicodeString(" Got: ") + s | 2737 + UnicodeString(" Got: ") + s |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3104 { "zh_TW@numbers=finance", 1234.567, TRUE, "\\u58F9\\u4EDF\\u8CB3\\u4F70
\\u53C3\\u62FE\\u8086\\u9EDE\\u4F0D\\u9678\\u67D2" }, | 3134 { "zh_TW@numbers=finance", 1234.567, TRUE, "\\u58F9\\u4EDF\\u8CB3\\u4F70
\\u53C3\\u62FE\\u8086\\u9EDE\\u4F0D\\u9678\\u67D2" }, |
3105 { NULL, 0, FALSE, NULL } | 3135 { NULL, 0, FALSE, NULL } |
3106 }; | 3136 }; |
3107 | 3137 |
3108 UErrorCode ec; | 3138 UErrorCode ec; |
3109 | 3139 |
3110 const TestNumberingSystemItem *item; | 3140 const TestNumberingSystemItem *item; |
3111 for (item = DATA; item->localeName != NULL; item++) { | 3141 for (item = DATA; item->localeName != NULL; item++) { |
3112 ec = U_ZERO_ERROR; | 3142 ec = U_ZERO_ERROR; |
3113 Locale loc = Locale::createFromName(item->localeName); | 3143 Locale loc = Locale::createFromName(item->localeName); |
3114 NumberFormat *fmt = NumberFormat::createInstance(loc,ec); | |
3115 | 3144 |
| 3145 NumberFormat *origFmt = NumberFormat::createInstance(loc,ec); |
3116 if (U_FAILURE(ec)) { | 3146 if (U_FAILURE(ec)) { |
3117 dataerrln("FAIL: getInstance(%s) - %s", item->localeName, u_errorNam
e(ec)); | 3147 dataerrln("FAIL: getInstance(%s) - %s", item->localeName, u_errorNam
e(ec)); |
3118 continue; | 3148 continue; |
3119 } | 3149 } |
| 3150 // Clone to test ticket #10682 |
| 3151 NumberFormat *fmt = (NumberFormat *) origFmt->clone(); |
| 3152 delete origFmt; |
| 3153 |
3120 | 3154 |
3121 if (item->isRBNF) { | 3155 if (item->isRBNF) { |
3122 expect3(*fmt,item->value,CharsToUnicodeString(item->expectedResult))
; | 3156 expect3(*fmt,item->value,CharsToUnicodeString(item->expectedResult))
; |
3123 } else { | 3157 } else { |
3124 expect2(*fmt,item->value,CharsToUnicodeString(item->expectedResult))
; | 3158 expect2(*fmt,item->value,CharsToUnicodeString(item->expectedResult))
; |
3125 } | 3159 } |
3126 delete fmt; | 3160 delete fmt; |
3127 } | 3161 } |
3128 | 3162 |
3129 | 3163 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3366 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 US
D"}, | 3400 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 US
D"}, |
3367 // test choice format | 3401 // test choice format |
3368 {"es_AR", "1", "INR", "INR1,00", "INR1,00", "1,00 rupia india"}, | 3402 {"es_AR", "1", "INR", "INR1,00", "INR1,00", "1,00 rupia india"}, |
3369 }; | 3403 }; |
3370 static const UNumberFormatStyle currencyStyles[] = { | 3404 static const UNumberFormatStyle currencyStyles[] = { |
3371 UNUM_CURRENCY, | 3405 UNUM_CURRENCY, |
3372 UNUM_CURRENCY_ISO, | 3406 UNUM_CURRENCY_ISO, |
3373 UNUM_CURRENCY_PLURAL | 3407 UNUM_CURRENCY_PLURAL |
3374 }; | 3408 }; |
3375 | 3409 |
3376 for (int32_t i=0; i<LENGTHOF(DATA); ++i) { | 3410 for (int32_t i=0; i<UPRV_LENGTHOF(DATA); ++i) { |
3377 for (int32_t kIndex = 0; kIndex < LENGTHOF(currencyStyles); ++kIndex) { | 3411 for (int32_t kIndex = 0; kIndex < UPRV_LENGTHOF(currencyStyles); ++kIndex)
{ |
3378 UNumberFormatStyle k = currencyStyles[kIndex]; | 3412 UNumberFormatStyle k = currencyStyles[kIndex]; |
3379 const char* localeString = DATA[i][0]; | 3413 const char* localeString = DATA[i][0]; |
3380 double numberToBeFormat = atof(DATA[i][1]); | 3414 double numberToBeFormat = atof(DATA[i][1]); |
3381 const char* currencyISOCode = DATA[i][2]; | 3415 const char* currencyISOCode = DATA[i][2]; |
3382 Locale locale(localeString); | 3416 Locale locale(localeString); |
3383 UErrorCode status = U_ZERO_ERROR; | 3417 UErrorCode status = U_ZERO_ERROR; |
3384 NumberFormat* numFmt = NumberFormat::createInstance(locale, k, status); | 3418 NumberFormat* numFmt = NumberFormat::createInstance(locale, k, status); |
3385 if (U_FAILURE(status)) { | 3419 if (U_FAILURE(status)) { |
3386 delete numFmt; | 3420 delete numFmt; |
3387 dataerrln((UnicodeString)"can not create instance, locale:" + locale
String + ", style: " + k + " - " + u_errorName(status)); | 3421 dataerrln((UnicodeString)"can not create instance, locale:" + locale
String + ", style: " + k + " - " + u_errorName(status)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3444 // currency amount to be formatted, | 3478 // currency amount to be formatted, |
3445 // currency ISO code to be formatted, | 3479 // currency ISO code to be formatted, |
3446 // format result using CURRENCYSTYLE, | 3480 // format result using CURRENCYSTYLE, |
3447 // format result using ISOCURRENCYSTYLE, | 3481 // format result using ISOCURRENCYSTYLE, |
3448 // format result using PLURALCURRENCYSTYLE, | 3482 // format result using PLURALCURRENCYSTYLE, |
3449 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollar"}, | 3483 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollar"}, |
3450 {"pa_IN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00 \\u0a2f\
\u0a42.\\u0a10\\u0a38. \\u0a21\\u0a3e\\u0a32\\u0a30"}, | 3484 {"pa_IN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00 \\u0a2f\
\u0a42.\\u0a10\\u0a38. \\u0a21\\u0a3e\\u0a32\\u0a30"}, |
3451 {"es_AR", "1", "USD", "US$1,00", "USD1,00", "1,00 d\\u00f3lar estadounid
ense"}, | 3485 {"es_AR", "1", "USD", "US$1,00", "USD1,00", "1,00 d\\u00f3lar estadounid
ense"}, |
3452 {"ar_EG", "1", "USD", "US$\\u00a0\\u0661\\u066b\\u0660\\u0660", "USD\\u0
0a0\\u0661\\u066b\\u0660\\u0660", "\\u0661\\u066b\\u0660\\u0660 \\u062f\\u0648\\
u0644\\u0627\\u0631 \\u0623\\u0645\\u0631\\u064a\\u0643\\u064a"}, | 3486 {"ar_EG", "1", "USD", "US$\\u00a0\\u0661\\u066b\\u0660\\u0660", "USD\\u0
0a0\\u0661\\u066b\\u0660\\u0660", "\\u0661\\u066b\\u0660\\u0660 \\u062f\\u0648\\
u0644\\u0627\\u0631 \\u0623\\u0645\\u0631\\u064a\\u0643\\u064a"}, |
3453 {"fa_CA", "1", "USD", "\\u200e$\\u06f1\\u066b\\u06f0\\u06f0", "\\u200eUS
D\\u06f1\\u066b\\u06f0\\u06f0", "\\u200e\\u062f\\u0644\\u0627\\u0631 \\u0627\\u0
645\\u0631\\u06cc\\u06a9\\u0627\\u06f1\\u066b\\u06f0\\u06f0"}, | 3487 {"fa_CA", "1", "USD", "\\u200e$\\u06f1\\u066b\\u06f0\\u06f0", "\\u200eUS
D\\u06f1\\u066b\\u06f0\\u06f0", "\\u200e\\u062f\\u0644\\u0627\\u0631 \\u0627\\u0
645\\u0631\\u06cc\\u06a9\\u0627\\u06f1\\u066b\\u06f0\\u06f0"}, |
3454 {"he_IL", "1", "USD", "1.00\\u00a0US$", "1.00\\u00a0USD", "1.00 \\u05d3\
\u05d5\\u05dc\\u05e8 \\u05d0\\u05de\\u05e8\\u05d9\\u05e7\\u05d0\\u05d9"}, | 3488 {"he_IL", "1", "USD", "1.00\\u00a0$", "1.00\\u00a0USD", "1.00 \\u05d3\\u
05d5\\u05dc\\u05e8 \\u05d0\\u05de\\u05e8\\u05d9\\u05e7\\u05d0\\u05d9"}, |
3455 {"hr_HR", "1", "USD", "1,00\\u00a0USD", "1,00\\u00a0USD", "1,00 Ameri\\u
010dki dolar"}, | 3489 {"hr_HR", "1", "USD", "1,00\\u00a0USD", "1,00\\u00a0USD", "1,00 Ameri\\u
010dki dolar"}, |
3456 {"id_ID", "1", "USD", "US$1,00", "USD1,00", "1,00 Dolar Amerika Serikat"
}, | 3490 {"id_ID", "1", "USD", "US$1,00", "USD1,00", "1,00 Dolar Amerika Serikat"
}, |
3457 {"it_IT", "1", "USD", "1,00\\u00a0US$", "1,00\\u00a0USD", "1,00 Dollaro
Statunitense"}, | 3491 {"it_IT", "1", "USD", "1,00\\u00a0US$", "1,00\\u00a0USD", "1,00 Dollaro
Statunitense"}, |
3458 {"ko_KR", "1", "USD", "US$1.00", "USD1.00", "1.00 \\ubbf8\\uad6d \\ub2ec
\\ub7ec"}, | 3492 {"ko_KR", "1", "USD", "US$1.00", "USD1.00", "1.00 \\ubbf8\\uad6d \\ub2ec
\\ub7ec"}, |
3459 {"ja_JP", "1", "USD", "$1.00", "USD1.00", "1.00 \\u7c73\\u30c9\\u30eb"}, | 3493 {"ja_JP", "1", "USD", "$1.00", "USD1.00", "1.00 \\u7c73\\u30c9\\u30eb"}, |
3460 {"zh_CN", "1", "CNY", "\\uFFE5\\u00a01.00", "CNY\\u00a01.00", "1.00\\u4E
BA\\u6C11\\u5E01"}, | 3494 {"zh_CN", "1", "CNY", "\\uFFE5\\u00a01.00", "CNY\\u00a01.00", "1.00\\u4E
BA\\u6C11\\u5E01"}, |
3461 {"zh_TW", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\
u5e63"}, | 3495 {"zh_TW", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11\\
u5e63"}, |
3462 {"zh_Hant", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11
\\u5e63"}, | 3496 {"zh_Hant", "1", "CNY", "CN\\u00A51.00", "CNY1.00", "1.00 \\u4eba\\u6c11
\\u5e63"}, |
3463 {"zh_Hant", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u5713"}
, | 3497 {"zh_Hant", "1", "JPY", "\\u00A51.00", "JPY1.00", "1.00 \\u65e5\\u5713"}
, |
3464 {"ja_JP", "1", "JPY", "\\uFFE51.00", "JPY1.00", "1.00 \\u65e5\\u672c\\u5
186"}, | 3498 {"ja_JP", "1", "JPY", "\\uFFE51.00", "JPY1.00", "1.00 \\u65e5\\u672c\\u5
186"}, |
(...skipping 10 matching lines...) Expand all Loading... |
3475 "UNUM_CURRENCY_ISO", | 3509 "UNUM_CURRENCY_ISO", |
3476 "UNUM_CURRENCY_PLURAL" | 3510 "UNUM_CURRENCY_PLURAL" |
3477 }; | 3511 }; |
3478 | 3512 |
3479 #ifdef NUMFMTST_CACHE_DEBUG | 3513 #ifdef NUMFMTST_CACHE_DEBUG |
3480 int deadloop = 0; | 3514 int deadloop = 0; |
3481 for (;;) { | 3515 for (;;) { |
3482 printf("loop: %d\n", deadloop++); | 3516 printf("loop: %d\n", deadloop++); |
3483 #endif | 3517 #endif |
3484 for (uint32_t i=0; i< sizeof(DATA)/sizeof(DATA[0]); ++i) { /* i = test case
# - should be i=0*/ | 3518 for (uint32_t i=0; i< sizeof(DATA)/sizeof(DATA[0]); ++i) { /* i = test case
# - should be i=0*/ |
3485 for (int32_t kIndex = 2; kIndex < LENGTHOF(currencyStyles); ++kIndex) { | 3519 for (int32_t kIndex = 2; kIndex < UPRV_LENGTHOF(currencyStyles); ++kIndex)
{ |
3486 UNumberFormatStyle k = currencyStyles[kIndex]; /* k = style */ | 3520 UNumberFormatStyle k = currencyStyles[kIndex]; /* k = style */ |
3487 const char* localeString = DATA[i][0]; | 3521 const char* localeString = DATA[i][0]; |
3488 double numberToBeFormat = atof(DATA[i][1]); | 3522 double numberToBeFormat = atof(DATA[i][1]); |
3489 const char* currencyISOCode = DATA[i][2]; | 3523 const char* currencyISOCode = DATA[i][2]; |
3490 Locale locale(localeString); | 3524 Locale locale(localeString); |
3491 UErrorCode status = U_ZERO_ERROR; | 3525 UErrorCode status = U_ZERO_ERROR; |
3492 NumberFormat* numFmt = NumberFormat::createInstance(locale, k, status); | 3526 NumberFormat* numFmt = NumberFormat::createInstance(locale, k, status); |
3493 logln("#%d NumberFormat(%s, %s) Currency=%s\n", | 3527 logln("#%d NumberFormat(%s, %s) Currency=%s\n", |
3494 i, localeString, currencyStyleNames[kIndex], | 3528 i, localeString, currencyStyleNames[kIndex], |
3495 currencyISOCode); | 3529 currencyISOCode); |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4474 "SRD1.00", | 4508 "SRD1.00", |
4475 "SRD1.00", | 4509 "SRD1.00", |
4476 "SRG1.00", | 4510 "SRG1.00", |
4477 "STD1.00", | 4511 "STD1.00", |
4478 "SUR1.00", | 4512 "SUR1.00", |
4479 "SUR1.00", | 4513 "SUR1.00", |
4480 "SVC1.00", | 4514 "SVC1.00", |
4481 "SVC1.00", | 4515 "SVC1.00", |
4482 "SYP1.00", | 4516 "SYP1.00", |
4483 "SZL1.00", | 4517 "SZL1.00", |
4484 "Saint Helena Pound1.00", | 4518 "St. Helena Pound1.00", |
4485 "Saint Helena pound1.00", | 4519 "St. Helena pound1.00", |
4486 "Saint Helena pounds1.00", | 4520 "St. Helena pounds1.00", |
4487 "S\\u00e3o Tom\\u00e9 and Pr\\u00edncipe Dobra1.00", | 4521 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra1.00", |
4488 "S\\u00e3o Tom\\u00e9 and Pr\\u00edncipe dobra1.00", | 4522 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra1.00", |
4489 "S\\u00e3o Tom\\u00e9 and Pr\\u00edncipe dobras1.00", | 4523 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras1.00", |
4490 "Saudi Riyal1.00", | 4524 "Saudi Riyal1.00", |
4491 "Saudi riyal1.00", | 4525 "Saudi riyal1.00", |
4492 "Saudi riyals1.00", | 4526 "Saudi riyals1.00", |
4493 "Serbian Dinar1.00", | 4527 "Serbian Dinar1.00", |
4494 "Serbian dinar1.00", | 4528 "Serbian dinar1.00", |
4495 "Serbian dinars1.00", | 4529 "Serbian dinars1.00", |
4496 "Seychellois Rupee1.00", | 4530 "Seychellois Rupee1.00", |
4497 "Seychellois rupee1.00", | 4531 "Seychellois rupee1.00", |
4498 "Seychellois rupees1.00", | 4532 "Seychellois rupees1.00", |
4499 "Sierra Leonean Leone1.00", | 4533 "Sierra Leonean Leone1.00", |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4596 "Testing Currency Code1.00", | 4630 "Testing Currency Code1.00", |
4597 "Thai Baht1.00", | 4631 "Thai Baht1.00", |
4598 "Thai baht1.00", | 4632 "Thai baht1.00", |
4599 "Thai baht1.00", | 4633 "Thai baht1.00", |
4600 "Timorese Escudo1.00", | 4634 "Timorese Escudo1.00", |
4601 "Timorese escudo1.00", | 4635 "Timorese escudo1.00", |
4602 "Timorese escudos1.00", | 4636 "Timorese escudos1.00", |
4603 "Tongan Pa\\u02bbanga1.00", | 4637 "Tongan Pa\\u02bbanga1.00", |
4604 "Tongan pa\\u02bbanga1.00", | 4638 "Tongan pa\\u02bbanga1.00", |
4605 "Tongan pa\\u02bbanga1.00", | 4639 "Tongan pa\\u02bbanga1.00", |
4606 "Trinidad and Tobago Dollar1.00", | 4640 "Trinidad & Tobago Dollar1.00", |
4607 "Trinidad and Tobago dollar1.00", | 4641 "Trinidad & Tobago dollar1.00", |
4608 "Trinidad and Tobago dollars1.00", | 4642 "Trinidad & Tobago dollars1.00", |
4609 "Tunisian Dinar1.00", | 4643 "Tunisian Dinar1.00", |
4610 "Tunisian dinar1.00", | 4644 "Tunisian dinar1.00", |
4611 "Tunisian dinars1.00", | 4645 "Tunisian dinars1.00", |
4612 "Turkish Lira1.00", | 4646 "Turkish Lira1.00", |
4613 "Turkish Lira1.00", | 4647 "Turkish Lira1.00", |
4614 "Turkish lira1.00", | 4648 "Turkish lira1.00", |
4615 "Turkmenistani Manat1.00", | 4649 "Turkmenistani Manat1.00", |
4616 "Turkmenistani manat1.00", | 4650 "Turkmenistani manat1.00", |
4617 "Turkmenistani manat1.00", | 4651 "Turkmenistani manat1.00", |
4618 "UAE dirham1.00", | 4652 "UAE dirham1.00", |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4782 "Zimbabwean dollars (1980\\u20132008)1.00", | 4816 "Zimbabwean dollars (1980\\u20132008)1.00", |
4783 "euro1.00", | 4817 "euro1.00", |
4784 "euros1.00", | 4818 "euros1.00", |
4785 "Turkish lira (1922\\u20132005)1.00", | 4819 "Turkish lira (1922\\u20132005)1.00", |
4786 "special drawing rights1.00", | 4820 "special drawing rights1.00", |
4787 "Colombian real value unit1.00", | 4821 "Colombian real value unit1.00", |
4788 "Colombian real value units1.00", | 4822 "Colombian real value units1.00", |
4789 "unknown currency1.00", | 4823 "unknown currency1.00", |
4790 "\\u00a31.00", | 4824 "\\u00a31.00", |
4791 "\\u00a51.00", | 4825 "\\u00a51.00", |
4792 "\\u0e3f1.00", | |
4793 "\\u20ab1.00", | 4826 "\\u20ab1.00", |
4794 "\\u20aa1.00", | 4827 "\\u20aa1.00", |
4795 "\\u20ac1.00", | 4828 "\\u20ac1.00", |
4796 "\\u20b91.00", | 4829 "\\u20b91.00", |
4797 // | 4830 // |
4798 // Following has extra text, should be parsed correctly too | 4831 // Following has extra text, should be parsed correctly too |
4799 "$1.00 random", | 4832 "$1.00 random", |
4800 "USD1.00 random", | 4833 "USD1.00 random", |
4801 "1.00 US dollar random", | 4834 "1.00 US dollar random", |
4802 "1.00 US dollars random", | 4835 "1.00 US dollars random", |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5367 "1.00 Romanian leu random", | 5400 "1.00 Romanian leu random", |
5368 "1.00 Russian Ruble (1991\\u20131998) random", | 5401 "1.00 Russian Ruble (1991\\u20131998) random", |
5369 "1.00 Russian Ruble random", | 5402 "1.00 Russian Ruble random", |
5370 "1.00 Russian ruble (1991\\u20131998) random", | 5403 "1.00 Russian ruble (1991\\u20131998) random", |
5371 "1.00 Russian ruble random", | 5404 "1.00 Russian ruble random", |
5372 "1.00 Russian rubles (1991\\u20131998) random", | 5405 "1.00 Russian rubles (1991\\u20131998) random", |
5373 "1.00 Russian rubles random", | 5406 "1.00 Russian rubles random", |
5374 "1.00 Rwandan Franc random", | 5407 "1.00 Rwandan Franc random", |
5375 "1.00 Rwandan franc random", | 5408 "1.00 Rwandan franc random", |
5376 "1.00 Rwandan francs random", | 5409 "1.00 Rwandan francs random", |
5377 "1.00 Saint Helena Pound random", | 5410 "1.00 St. Helena Pound random", |
5378 "1.00 Saint Helena pound random", | 5411 "1.00 St. Helena pound random", |
5379 "1.00 Saint Helena pounds random", | 5412 "1.00 St. Helena pounds random", |
5380 "1.00 S\\u00e3o Tom\\u00e9 and Pr\\u00edncipe Dobra random", | 5413 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobra random", |
5381 "1.00 S\\u00e3o Tom\\u00e9 and Pr\\u00edncipe dobra random", | 5414 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobra random", |
5382 "1.00 S\\u00e3o Tom\\u00e9 and Pr\\u00edncipe dobras random", | 5415 "1.00 S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe dobras random", |
5383 "1.00 Saudi Riyal random", | 5416 "1.00 Saudi Riyal random", |
5384 "1.00 Saudi riyal random", | 5417 "1.00 Saudi riyal random", |
5385 "1.00 Saudi riyals random", | 5418 "1.00 Saudi riyals random", |
5386 "1.00 Serbian Dinar random", | 5419 "1.00 Serbian Dinar random", |
5387 "1.00 Serbian dinar random", | 5420 "1.00 Serbian dinar random", |
5388 "1.00 Serbian dinars random", | 5421 "1.00 Serbian dinars random", |
5389 "1.00 Seychellois Rupee random", | 5422 "1.00 Seychellois Rupee random", |
5390 "1.00 Seychellois rupee random", | 5423 "1.00 Seychellois rupee random", |
5391 "1.00 Seychellois rupees random", | 5424 "1.00 Seychellois rupees random", |
5392 "1.00 Sierra Leonean Leone random", | 5425 "1.00 Sierra Leonean Leone random", |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5466 "1.00 Tanzanian shilling random", | 5499 "1.00 Tanzanian shilling random", |
5467 "1.00 Tanzanian shillings random", | 5500 "1.00 Tanzanian shillings random", |
5468 "1.00 Testing Currency Code random", | 5501 "1.00 Testing Currency Code random", |
5469 "1.00 Testing Currency Code random", | 5502 "1.00 Testing Currency Code random", |
5470 "1.00 Thai Baht random", | 5503 "1.00 Thai Baht random", |
5471 "1.00 Thai baht random", | 5504 "1.00 Thai baht random", |
5472 "1.00 Thai baht random", | 5505 "1.00 Thai baht random", |
5473 "1.00 Timorese Escudo random", | 5506 "1.00 Timorese Escudo random", |
5474 "1.00 Timorese escudo random", | 5507 "1.00 Timorese escudo random", |
5475 "1.00 Timorese escudos random", | 5508 "1.00 Timorese escudos random", |
5476 "1.00 Trinidad and Tobago Dollar random", | 5509 "1.00 Trinidad & Tobago Dollar random", |
5477 "1.00 Trinidad and Tobago dollar random", | 5510 "1.00 Trinidad & Tobago dollar random", |
5478 "1.00 Trinidad and Tobago dollars random", | 5511 "1.00 Trinidad & Tobago dollars random", |
5479 "1.00 Tunisian Dinar random", | 5512 "1.00 Tunisian Dinar random", |
5480 "1.00 Tunisian dinar random", | 5513 "1.00 Tunisian dinar random", |
5481 "1.00 Tunisian dinars random", | 5514 "1.00 Tunisian dinars random", |
5482 "1.00 Turkish Lira random", | 5515 "1.00 Turkish Lira random", |
5483 "1.00 Turkish Lira random", | 5516 "1.00 Turkish Lira random", |
5484 "1.00 Turkish lira random", | 5517 "1.00 Turkish lira random", |
5485 "1.00 Turkmenistani Manat random", | 5518 "1.00 Turkmenistani Manat random", |
5486 "1.00 Turkmenistani manat random", | 5519 "1.00 Turkmenistani manat random", |
5487 "1.00 Turkmenistani manat random", | 5520 "1.00 Turkmenistani manat random", |
5488 "1.00 US Dollar (Next day) random", | 5521 "1.00 US Dollar (Next day) random", |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5975 "SI1.00", | 6008 "SI1.00", |
5976 "SK1.00", | 6009 "SK1.00", |
5977 "SL R1.00", | 6010 "SL R1.00", |
5978 "SL1.00", | 6011 "SL1.00", |
5979 "SO1.00", | 6012 "SO1.00", |
5980 "ST1.00", | 6013 "ST1.00", |
5981 "SU1.00", | 6014 "SU1.00", |
5982 "SV1.00", | 6015 "SV1.00", |
5983 "SY1.00", | 6016 "SY1.00", |
5984 "SZ1.00", | 6017 "SZ1.00", |
5985 "Saint Helena Poun1.00", | 6018 "St. Helena Poun1.00", |
5986 "S\\u00e3o Tom\\u00e9 and Pr\\u00edncipe Dobr1.00", | 6019 "S\\u00e3o Tom\\u00e9 & Pr\\u00edncipe Dobr1.00", |
5987 "Saudi Riya1.00", | 6020 "Saudi Riya1.00", |
5988 "Serbian Dina1.00", | 6021 "Serbian Dina1.00", |
5989 "Seychellois Rupe1.00", | 6022 "Seychellois Rupe1.00", |
5990 "Sh1.00", | 6023 "Sh1.00", |
5991 "Sierra Leonean Leon1.00", | 6024 "Sierra Leonean Leon1.00", |
5992 "Silve1.00", | 6025 "Silve1.00", |
5993 "Singapore Dolla1.00", | 6026 "Singapore Dolla1.00", |
5994 "Slovak Korun1.00", | 6027 "Slovak Korun1.00", |
5995 "Slovenian Tola1.00", | 6028 "Slovenian Tola1.00", |
5996 "Solomon Islands Dolla1.00", | 6029 "Solomon Islands Dolla1.00", |
(...skipping 26 matching lines...) Expand all Loading... |
6023 "TW1.00", | 6056 "TW1.00", |
6024 "TZ1.00", | 6057 "TZ1.00", |
6025 "New Taiwan Dolla1.00", | 6058 "New Taiwan Dolla1.00", |
6026 "Tajikistani Rubl1.00", | 6059 "Tajikistani Rubl1.00", |
6027 "Tajikistani Somon1.00", | 6060 "Tajikistani Somon1.00", |
6028 "Tanzanian Shillin1.00", | 6061 "Tanzanian Shillin1.00", |
6029 "Testing Currency Cod1.00", | 6062 "Testing Currency Cod1.00", |
6030 "Thai Bah1.00", | 6063 "Thai Bah1.00", |
6031 "Timorese Escud1.00", | 6064 "Timorese Escud1.00", |
6032 "Tongan Pa\\u20bbang1.00", | 6065 "Tongan Pa\\u20bbang1.00", |
6033 "Trinidad and Tobago Dolla1.00", | 6066 "Trinidad & Tobago Dolla1.00", |
6034 "Tunisian Dina1.00", | 6067 "Tunisian Dina1.00", |
6035 "Turkish Lir1.00", | 6068 "Turkish Lir1.00", |
6036 "Turkmenistani Mana1.00", | 6069 "Turkmenistani Mana1.00", |
6037 "U S1.00", | 6070 "U S1.00", |
6038 "U1.00", | 6071 "U1.00", |
6039 "UA1.00", | 6072 "UA1.00", |
6040 "UG1.00", | 6073 "UG1.00", |
6041 "US Dolla1.00", | 6074 "US Dolla1.00", |
6042 "US Dollar (Next day1.00", | 6075 "US Dollar (Next day1.00", |
6043 "US Dollar (Same day1.00", | 6076 "US Dollar (Same day1.00", |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6555 } | 6588 } |
6556 | 6589 |
6557 void NumberFormatTest::TestExplicitParents() { | 6590 void NumberFormatTest::TestExplicitParents() { |
6558 | 6591 |
6559 /* Test that number formats are properly inherited from es_419 */ | 6592 /* Test that number formats are properly inherited from es_419 */ |
6560 /* These could be subject to change if the CLDR data changes */ | 6593 /* These could be subject to change if the CLDR data changes */ |
6561 static const char* parentLocaleTests[][2]= { | 6594 static const char* parentLocaleTests[][2]= { |
6562 /* locale ID */ /* expected */ | 6595 /* locale ID */ /* expected */ |
6563 {"es_CO", "1.250,75" }, | 6596 {"es_CO", "1.250,75" }, |
6564 {"es_CR", "1.250,75" }, | 6597 {"es_CR", "1.250,75" }, |
6565 {"es_ES", "1\\u00A0250,75" }, | 6598 {"es_ES", "1.250,75" }, |
6566 {"es_GQ", "1\\u00A0250,75" }, | 6599 {"es_GQ", "1.250,75" }, |
6567 {"es_MX", "1,250.75" }, | 6600 {"es_MX", "1,250.75" }, |
6568 {"es_US", "1,250.75" }, | 6601 {"es_US", "1,250.75" }, |
6569 {"es_VE", "1.250,75" }, | 6602 {"es_VE", "1.250,75" }, |
6570 }; | 6603 }; |
6571 | 6604 |
6572 UnicodeString s; | 6605 UnicodeString s; |
6573 | 6606 |
6574 for(int i=0; i < (int)(sizeof(parentLocaleTests)/sizeof(parentLocaleTests[i]
)); i++){ | 6607 for(int i=0; i < (int)(sizeof(parentLocaleTests)/sizeof(parentLocaleTests[i]
)); i++){ |
6575 UErrorCode status = U_ZERO_ERROR; | 6608 UErrorCode status = U_ZERO_ERROR; |
6576 const char *localeID = parentLocaleTests[i][0]; | 6609 const char *localeID = parentLocaleTests[i][0]; |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7277 } else { | 7310 } else { |
7278 errln((UnicodeString)"FAIL: locale " + itemPtr->locale + ", leni
ent " + itemPtr->lenient + ", parse of \"" + itemPtr->numString + "\" gives posi
tion " + ppos.getIndex()); | 7311 errln((UnicodeString)"FAIL: locale " + itemPtr->locale + ", leni
ent " + itemPtr->lenient + ", parse of \"" + itemPtr->numString + "\" gives posi
tion " + ppos.getIndex()); |
7279 } | 7312 } |
7280 } else { | 7313 } else { |
7281 dataerrln("FAIL: NumberFormat::createInstance for locale % gives err
or %s", itemPtr->locale, u_errorName(status)); | 7314 dataerrln("FAIL: NumberFormat::createInstance for locale % gives err
or %s", itemPtr->locale, u_errorName(status)); |
7282 } | 7315 } |
7283 delete numfmt; | 7316 delete numfmt; |
7284 } | 7317 } |
7285 } | 7318 } |
7286 | 7319 |
| 7320 typedef struct { |
| 7321 DecimalFormat::ERoundingMode mode; |
| 7322 double value; |
| 7323 UnicodeString expected; |
| 7324 } Test10419Data; |
| 7325 |
| 7326 |
| 7327 // Tests that rounding works right when fractional digits is set to 0. |
| 7328 void NumberFormatTest::Test10419RoundingWith0FractionDigits() { |
| 7329 const Test10419Data items[] = { |
| 7330 { DecimalFormat::kRoundCeiling, 1.488, "2"}, |
| 7331 { DecimalFormat::kRoundDown, 1.588, "1"}, |
| 7332 { DecimalFormat::kRoundFloor, 1.888, "1"}, |
| 7333 { DecimalFormat::kRoundHalfDown, 1.5, "1"}, |
| 7334 { DecimalFormat::kRoundHalfEven, 2.5, "2"}, |
| 7335 { DecimalFormat::kRoundHalfUp, 2.5, "3"}, |
| 7336 { DecimalFormat::kRoundUp, 1.5, "2"}, |
| 7337 }; |
| 7338 UErrorCode status = U_ZERO_ERROR; |
| 7339 LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createIns
tance(Locale("en_US"), status)); |
| 7340 if (U_FAILURE(status)) { |
| 7341 dataerrln("Failure creating DecimalFormat %s", u_errorName(status)); |
| 7342 return; |
| 7343 } |
| 7344 for (int32_t i = 0; i < (int32_t) (sizeof(items) / sizeof(items[0])); ++i) { |
| 7345 decfmt->setRoundingMode(items[i].mode); |
| 7346 decfmt->setMaximumFractionDigits(0); |
| 7347 UnicodeString actual; |
| 7348 if (items[i].expected != decfmt->format(items[i].value, actual)) { |
| 7349 errln("Expected " + items[i].expected + ", got " + actual); |
| 7350 } |
| 7351 } |
| 7352 } |
| 7353 |
| 7354 void NumberFormatTest::Test10468ApplyPattern() { |
| 7355 // Padding char of fmt is now 'a' |
| 7356 UErrorCode status = U_ZERO_ERROR; |
| 7357 DecimalFormat fmt("'I''ll'*a###.##", status); |
| 7358 |
| 7359 if (U_FAILURE(status)) { |
| 7360 errcheckln(status, "DecimalFormat constructor failed - %s", u_errorName(
status)); |
| 7361 return; |
| 7362 } |
| 7363 |
| 7364 if (fmt.getPadCharacterString() != UnicodeString("a")) { |
| 7365 errln("Padding character should be 'a'."); |
| 7366 return; |
| 7367 } |
| 7368 |
| 7369 // Padding char of fmt ought to be '*' since that is the default and no |
| 7370 // explicit padding char is specified in the new pattern. |
| 7371 fmt.applyPattern("AA#,##0.00ZZ", status); |
| 7372 |
| 7373 // Oops this still prints 'a' even though we changed the pattern. |
| 7374 if (fmt.getPadCharacterString() != UnicodeString("*")) { |
| 7375 errln("applyPattern did not clear padding character."); |
| 7376 } |
| 7377 } |
| 7378 |
| 7379 void NumberFormatTest::TestRoundingScientific10542() { |
| 7380 UErrorCode status = U_ZERO_ERROR; |
| 7381 DecimalFormat format("0.00E0", status); |
| 7382 if (U_FAILURE(status)) { |
| 7383 errcheckln(status, "DecimalFormat constructor failed - %s", u_errorName(
status)); |
| 7384 return; |
| 7385 } |
| 7386 |
| 7387 DecimalFormat::ERoundingMode roundingModes[] = { |
| 7388 DecimalFormat::kRoundCeiling, |
| 7389 DecimalFormat::kRoundDown, |
| 7390 DecimalFormat::kRoundFloor, |
| 7391 DecimalFormat::kRoundHalfDown, |
| 7392 DecimalFormat::kRoundHalfEven, |
| 7393 DecimalFormat::kRoundHalfUp, |
| 7394 DecimalFormat::kRoundUp}; |
| 7395 const char *descriptions[] = { |
| 7396 "Round Ceiling", |
| 7397 "Round Down", |
| 7398 "Round Floor", |
| 7399 "Round half down", |
| 7400 "Round half even", |
| 7401 "Round half up", |
| 7402 "Round up"}; |
| 7403 |
| 7404 { |
| 7405 double values[] = {-0.003006, -0.003005, -0.003004, 0.003014, 0.003015,
0.003016}; |
| 7406 // The order of these expected values correspond to the order of roundin
gModes and the order of values. |
| 7407 const char *expected[] = { |
| 7408 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.02E-3", "3.02E-3", "3.02E
-3", |
| 7409 "-3.00E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.01E
-3", |
| 7410 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.01E-3", "3.01E-3", "3.01E
-3", |
| 7411 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.01E-3", "3.02E
-3", |
| 7412 "-3.01E-3", "-3.00E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E
-3", |
| 7413 "-3.01E-3", "-3.01E-3", "-3.00E-3", "3.01E-3", "3.02E-3", "3.02E
-3", |
| 7414 "-3.01E-3", "-3.01E-3", "-3.01E-3", "3.02E-3", "3.02E-3", "3.02E
-3"}; |
| 7415 verifyRounding( |
| 7416 format, |
| 7417 values, |
| 7418 expected, |
| 7419 roundingModes, |
| 7420 descriptions, |
| 7421 (int32_t) (sizeof(values) / sizeof(values[0])), |
| 7422 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0]))); |
| 7423 } |
| 7424 { |
| 7425 double values[] = {-3006.0, -3005, -3004, 3014, 3015, 3016}; |
| 7426 // The order of these expected values correspond to the order of roundin
gModes and the order of values. |
| 7427 const char *expected[] = { |
| 7428 "-3.00E3", "-3.00E3", "-3.00E3", "3.02E3", "3.02E3", "3.02E3", |
| 7429 "-3.00E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.01E3", |
| 7430 "-3.01E3", "-3.01E3", "-3.01E3", "3.01E3", "3.01E3", "3.01E3", |
| 7431 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.01E3", "3.02E3", |
| 7432 "-3.01E3", "-3.00E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3", |
| 7433 "-3.01E3", "-3.01E3", "-3.00E3", "3.01E3", "3.02E3", "3.02E3", |
| 7434 "-3.01E3", "-3.01E3", "-3.01E3", "3.02E3", "3.02E3", "3.02E3"}; |
| 7435 verifyRounding( |
| 7436 format, |
| 7437 values, |
| 7438 expected, |
| 7439 roundingModes, |
| 7440 descriptions, |
| 7441 (int32_t) (sizeof(values) / sizeof(values[0])), |
| 7442 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0]))); |
| 7443 } |
| 7444 /* Commented out for now until we decide how rounding to zero should work, +0 vs
. -0 |
| 7445 { |
| 7446 double values[] = {0.0, -0.0}; |
| 7447 // The order of these expected values correspond to the order of roundin
gModes and the order of values. |
| 7448 const char *expected[] = { |
| 7449 "0.00E0", "-0.00E0", |
| 7450 "0.00E0", "-0.00E0", |
| 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 verifyRounding( |
| 7457 format, |
| 7458 values, |
| 7459 expected, |
| 7460 roundingModes, |
| 7461 descriptions, |
| 7462 (int32_t) (sizeof(values) / sizeof(values[0])), |
| 7463 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0]))); |
| 7464 } |
| 7465 */ |
| 7466 { |
| 7467 |
| 7468 double values[] = {1e25, 1e25 + 1e15, 1e25 - 1e15}; |
| 7469 // The order of these expected values correspond to the order of roundin
gModes and the order of values. |
| 7470 const char *expected[] = { |
| 7471 "1.00E25", "1.01E25", "1.00E25", |
| 7472 "1.00E25", "1.00E25", "9.99E24", |
| 7473 "1.00E25", "1.00E25", "9.99E24", |
| 7474 "1.00E25", "1.00E25", "1.00E25", |
| 7475 "1.00E25", "1.00E25", "1.00E25", |
| 7476 "1.00E25", "1.00E25", "1.00E25", |
| 7477 "1.00E25", "1.01E25", "1.00E25"}; |
| 7478 verifyRounding( |
| 7479 format, |
| 7480 values, |
| 7481 expected, |
| 7482 roundingModes, |
| 7483 descriptions, |
| 7484 (int32_t) (sizeof(values) / sizeof(values[0])), |
| 7485 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0]))); |
| 7486 } |
| 7487 { |
| 7488 double values[] = {-1e25, -1e25 + 1e15, -1e25 - 1e15}; |
| 7489 // The order of these expected values correspond to the order of roundin
gModes and the order of values. |
| 7490 const char *expected[] = { |
| 7491 "-1.00E25", "-9.99E24", "-1.00E25", |
| 7492 "-1.00E25", "-9.99E24", "-1.00E25", |
| 7493 "-1.00E25", "-1.00E25", "-1.01E25", |
| 7494 "-1.00E25", "-1.00E25", "-1.00E25", |
| 7495 "-1.00E25", "-1.00E25", "-1.00E25", |
| 7496 "-1.00E25", "-1.00E25", "-1.00E25", |
| 7497 "-1.00E25", "-1.00E25", "-1.01E25"}; |
| 7498 verifyRounding( |
| 7499 format, |
| 7500 values, |
| 7501 expected, |
| 7502 roundingModes, |
| 7503 descriptions, |
| 7504 (int32_t) (sizeof(values) / sizeof(values[0])), |
| 7505 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0]))); |
| 7506 } |
| 7507 { |
| 7508 double values[] = {1e-25, 1e-25 + 1e-35, 1e-25 - 1e-35}; |
| 7509 // The order of these expected values correspond to the order of roundin
gModes and the order of values. |
| 7510 const char *expected[] = { |
| 7511 "1.00E-25", "1.01E-25", "1.00E-25", |
| 7512 "1.00E-25", "1.00E-25", "9.99E-26", |
| 7513 "1.00E-25", "1.00E-25", "9.99E-26", |
| 7514 "1.00E-25", "1.00E-25", "1.00E-25", |
| 7515 "1.00E-25", "1.00E-25", "1.00E-25", |
| 7516 "1.00E-25", "1.00E-25", "1.00E-25", |
| 7517 "1.00E-25", "1.01E-25", "1.00E-25"}; |
| 7518 verifyRounding( |
| 7519 format, |
| 7520 values, |
| 7521 expected, |
| 7522 roundingModes, |
| 7523 descriptions, |
| 7524 (int32_t) (sizeof(values) / sizeof(values[0])), |
| 7525 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0]))); |
| 7526 } |
| 7527 { |
| 7528 double values[] = {-1e-25, -1e-25 + 1e-35, -1e-25 - 1e-35}; |
| 7529 // The order of these expected values correspond to the order of roundin
gModes and the order of values. |
| 7530 const char *expected[] = { |
| 7531 "-1.00E-25", "-9.99E-26", "-1.00E-25", |
| 7532 "-1.00E-25", "-9.99E-26", "-1.00E-25", |
| 7533 "-1.00E-25", "-1.00E-25", "-1.01E-25", |
| 7534 "-1.00E-25", "-1.00E-25", "-1.00E-25", |
| 7535 "-1.00E-25", "-1.00E-25", "-1.00E-25", |
| 7536 "-1.00E-25", "-1.00E-25", "-1.00E-25", |
| 7537 "-1.00E-25", "-1.00E-25", "-1.01E-25"}; |
| 7538 verifyRounding( |
| 7539 format, |
| 7540 values, |
| 7541 expected, |
| 7542 roundingModes, |
| 7543 descriptions, |
| 7544 (int32_t) (sizeof(values) / sizeof(values[0])), |
| 7545 (int32_t) (sizeof(roundingModes) / sizeof(roundingModes[0]))); |
| 7546 } |
| 7547 } |
| 7548 |
| 7549 void NumberFormatTest::TestZeroScientific10547() { |
| 7550 UErrorCode status = U_ZERO_ERROR; |
| 7551 DecimalFormat fmt("0.00E0", status); |
| 7552 if (!assertSuccess("Formt creation", status)) { |
| 7553 return; |
| 7554 } |
| 7555 UnicodeString out; |
| 7556 fmt.format(-0.0, out); |
| 7557 assertEquals("format", "-0.00E0", out); |
| 7558 } |
| 7559 |
| 7560 void NumberFormatTest::verifyRounding( |
| 7561 DecimalFormat& format, |
| 7562 const double *values, |
| 7563 const char * const *expected, |
| 7564 const DecimalFormat::ERoundingMode *roundingModes, |
| 7565 const char * const *descriptions, |
| 7566 int32_t valueSize, |
| 7567 int32_t roundingModeSize) { |
| 7568 for (int32_t i = 0; i < roundingModeSize; ++i) { |
| 7569 format.setRoundingMode(roundingModes[i]); |
| 7570 for (int32_t j = 0; j < valueSize; j++) { |
| 7571 UnicodeString currentExpected(expected[i * valueSize + j]); |
| 7572 currentExpected = currentExpected.unescape(); |
| 7573 UnicodeString actual; |
| 7574 format.format(values[j], actual); |
| 7575 if (currentExpected != actual) { |
| 7576 char buffer[256]; |
| 7577 sprintf( |
| 7578 buffer, |
| 7579 "For %s value %f, expected ", |
| 7580 descriptions[i], |
| 7581 values[j]); |
| 7582 errln(UnicodeString(buffer) + currentExpected + ", got " + actua
l); |
| 7583 } |
| 7584 } |
| 7585 } |
| 7586 } |
| 7587 |
| 7588 void NumberFormatTest::TestAccountingCurrency() { |
| 7589 UErrorCode status = U_ZERO_ERROR; |
| 7590 UNumberFormatStyle style = UNUM_CURRENCY_ACCOUNTING; |
| 7591 |
| 7592 expect(NumberFormat::createInstance("en_US", style, status), |
| 7593 (Formattable)1234.5, "$1,234.50", TRUE, status); |
| 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)0, "$0.00", TRUE, status); |
| 7598 expect(NumberFormat::createInstance("en_US", style, status), |
| 7599 (Formattable)-0.2, "($0.20)", TRUE, status); |
| 7600 expect(NumberFormat::createInstance("ja_JP", style, status), |
| 7601 (Formattable)10000, UnicodeString("\\uFFE510,000").unescape(), TRUE, sta
tus); |
| 7602 expect(NumberFormat::createInstance("ja_JP", style, status), |
| 7603 (Formattable)-1000.5, UnicodeString("(\\uFFE51,000)").unescape(), FALSE,
status); |
| 7604 expect(NumberFormat::createInstance("de_DE", style, status), |
| 7605 (Formattable)-23456.7, UnicodeString("-23.456,70\\u00A0\\u20AC").unescap
e(), TRUE, status); |
| 7606 } |
| 7607 |
| 7608 // for #5186 |
| 7609 void NumberFormatTest::TestEquality() { |
| 7610 UErrorCode status = U_ZERO_ERROR; |
| 7611 DecimalFormatSymbols* symbols = new DecimalFormatSymbols(Locale("root"), sta
tus); |
| 7612 if (U_FAILURE(status)) { |
| 7613 dataerrln("Fail: can't create DecimalFormatSymbols for root"); |
| 7614 return; |
| 7615 } |
| 7616 UnicodeString pattern("#,##0.###"); |
| 7617 DecimalFormat* fmtBase = new DecimalFormat(pattern, symbols, status); |
| 7618 if (U_FAILURE(status)) { |
| 7619 dataerrln("Fail: can't create DecimalFormat using root symbols"); |
| 7620 return; |
| 7621 } |
| 7622 |
| 7623 DecimalFormat* fmtClone = (DecimalFormat*)fmtBase->clone(); |
| 7624 fmtClone->setFormatWidth(fmtBase->getFormatWidth() + 32); |
| 7625 if (*fmtClone == *fmtBase) { |
| 7626 errln("Error: DecimalFormat == does not distinguish objects that differ
only in FormatWidth"); |
| 7627 } |
| 7628 delete fmtClone; |
| 7629 |
| 7630 delete fmtBase; |
| 7631 } |
| 7632 |
| 7633 void NumberFormatTest::TestCurrencyUsage() { |
| 7634 double agent = 123.567; |
| 7635 |
| 7636 UErrorCode status; |
| 7637 DecimalFormat *fmt; |
| 7638 |
| 7639 // compare the Currency and Currency Cash Digits |
| 7640 // Note that as of CLDR 26: |
| 7641 // * TWD switches from 0 decimals to 2; PKR still has 0, so change test to t
hat |
| 7642 // * CAD and all other currencies that rounded to .05 no longer do |
| 7643 // 1st time for getter/setter, 2nd time for factory method |
| 7644 Locale enUS_PKR("en_US@currency=PKR"); |
| 7645 |
| 7646 for(int i=0; i<2; i++){ |
| 7647 status = U_ZERO_ERROR; |
| 7648 if(i == 0){ |
| 7649 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_PKR, UNUM_
CURRENCY, status); |
| 7650 if (assertSuccess("en_US@currency=PKR/CURRENCY", status, TRUE) == FA
LSE) { |
| 7651 continue; |
| 7652 } |
| 7653 |
| 7654 UnicodeString original; |
| 7655 fmt->format(agent,original); |
| 7656 assertEquals("Test Currency Usage 1", UnicodeString("PKR124"), origi
nal); |
| 7657 |
| 7658 // test the getter here |
| 7659 UCurrencyUsage curUsage = fmt->getCurrencyUsage(); |
| 7660 assertEquals("Test usage getter - standard", curUsage, UCURR_USAGE_S
TANDARD); |
| 7661 |
| 7662 fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status); |
| 7663 }else{ |
| 7664 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_PKR, UNUM_
CASH_CURRENCY, status); |
| 7665 if (assertSuccess("en_US@currency=PKR/CASH", status, TRUE) == FALSE)
{ |
| 7666 continue; |
| 7667 } |
| 7668 } |
| 7669 |
| 7670 // must be usage = cash |
| 7671 UCurrencyUsage curUsage = fmt->getCurrencyUsage(); |
| 7672 assertEquals("Test usage getter - cash", curUsage, UCURR_USAGE_CASH); |
| 7673 |
| 7674 UnicodeString cash_currency; |
| 7675 fmt->format(agent,cash_currency); |
| 7676 assertEquals("Test Currency Usage 2", UnicodeString("PKR124"), cash_curr
ency); |
| 7677 delete fmt; |
| 7678 } |
| 7679 |
| 7680 // compare the Currency and Currency Cash Rounding |
| 7681 // 1st time for getter/setter, 2nd time for factory method |
| 7682 Locale enUS_CAD("en_US@currency=CAD"); |
| 7683 for(int i=0; i<2; i++){ |
| 7684 status = U_ZERO_ERROR; |
| 7685 if(i == 0){ |
| 7686 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_
CURRENCY, status); |
| 7687 if (assertSuccess("en_US@currency=CAD/CURRENCY", status, TRUE) == FA
LSE) { |
| 7688 continue; |
| 7689 } |
| 7690 |
| 7691 UnicodeString original_rounding; |
| 7692 fmt->format(agent, original_rounding); |
| 7693 assertEquals("Test Currency Usage 3", UnicodeString("CA$123.57"), or
iginal_rounding); |
| 7694 fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status); |
| 7695 }else{ |
| 7696 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_
CASH_CURRENCY, status); |
| 7697 if (assertSuccess("en_US@currency=CAD/CASH", status, TRUE) == FALSE)
{ |
| 7698 continue; |
| 7699 } |
| 7700 } |
| 7701 |
| 7702 UnicodeString cash_rounding_currency; |
| 7703 fmt->format(agent, cash_rounding_currency); |
| 7704 assertEquals("Test Currency Usage 4", UnicodeString("CA$123.57"), cash_r
ounding_currency); |
| 7705 delete fmt; |
| 7706 } |
| 7707 |
| 7708 // Test the currency change |
| 7709 // 1st time for getter/setter, 2nd time for factory method |
| 7710 const UChar CUR_PKR[] = {0x50, 0x4B, 0x52, 0}; |
| 7711 for(int i=0; i<2; i++){ |
| 7712 status = U_ZERO_ERROR; |
| 7713 if(i == 0){ |
| 7714 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_
CURRENCY, status); |
| 7715 if (assertSuccess("en_US@currency=CAD/CURRENCY", status, TRUE) == FA
LSE) { |
| 7716 continue; |
| 7717 } |
| 7718 fmt->setCurrencyUsage(UCURR_USAGE_CASH, &status); |
| 7719 }else{ |
| 7720 fmt = (DecimalFormat *) NumberFormat::createInstance(enUS_CAD, UNUM_
CASH_CURRENCY, status); |
| 7721 if (assertSuccess("en_US@currency=CAD/CASH", status, TRUE) == FALSE)
{ |
| 7722 continue; |
| 7723 } |
| 7724 } |
| 7725 |
| 7726 UnicodeString cur_original; |
| 7727 fmt->format(agent, cur_original); |
| 7728 assertEquals("Test Currency Usage 5", UnicodeString("CA$123.57"), cur_or
iginal); |
| 7729 |
| 7730 fmt->setCurrency(CUR_PKR, status); |
| 7731 assertSuccess("Set currency to PKR", status); |
| 7732 |
| 7733 UnicodeString PKR_changed; |
| 7734 fmt->format(agent, PKR_changed); |
| 7735 assertEquals("Test Currency Usage 6", UnicodeString("PKR124"), PKR_chang
ed); |
| 7736 delete fmt; |
| 7737 } |
| 7738 } |
7287 #endif /* #if !UCONFIG_NO_FORMATTING */ | 7739 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |