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

Side by Side Diff: source/test/cintltst/cnumtst.c

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/cintltst/cmsccoll.c ('k') | source/test/cintltst/creststn.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2014, International Business Machines Corporation and 3 * Copyright (c) 1997-2015, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ********************************************************************/ 5 ********************************************************************/
6 /******************************************************************************* * 6 /******************************************************************************* *
7 * 7 *
8 * File CNUMTST.C 8 * File CNUMTST.C
9 * 9 *
10 * Madhu Katragadda Creation 10 * Madhu Katragadda Creation
11 * 11 *
12 * Modification History: 12 * Modification History:
13 * 13 *
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 static void TestInt64Parse(void); 54 static void TestInt64Parse(void);
55 static void TestParseCurrency(void); 55 static void TestParseCurrency(void);
56 static void TestMaxInt(void); 56 static void TestMaxInt(void);
57 static void TestNoExponent(void); 57 static void TestNoExponent(void);
58 static void TestUFormattable(void); 58 static void TestUFormattable(void);
59 static void TestUNumberingSystem(void); 59 static void TestUNumberingSystem(void);
60 static void TestCurrencyIsoPluralFormat(void); 60 static void TestCurrencyIsoPluralFormat(void);
61 static void TestContext(void); 61 static void TestContext(void);
62 static void TestCurrencyUsage(void); 62 static void TestCurrencyUsage(void);
63 static void TestCurrFmtNegSameAsPositive(void); 63 static void TestCurrFmtNegSameAsPositive(void);
64 static void TestVariousStylesAndAttributes(void);
64 65
65 #define TESTCASE(x) addTest(root, &x, "tsformat/cnumtst/" #x) 66 #define TESTCASE(x) addTest(root, &x, "tsformat/cnumtst/" #x)
66 67
67 void addNumForTest(TestNode** root) 68 void addNumForTest(TestNode** root)
68 { 69 {
69 TESTCASE(TestNumberFormat); 70 TESTCASE(TestNumberFormat);
70 TESTCASE(TestSpelloutNumberParse); 71 TESTCASE(TestSpelloutNumberParse);
71 TESTCASE(TestSignificantDigits); 72 TESTCASE(TestSignificantDigits);
72 TESTCASE(TestSigDigRounding); 73 TESTCASE(TestSigDigRounding);
73 TESTCASE(TestNumberFormatPadding); 74 TESTCASE(TestNumberFormatPadding);
74 TESTCASE(TestInt64Format); 75 TESTCASE(TestInt64Format);
75 TESTCASE(TestNonExistentCurrency); 76 TESTCASE(TestNonExistentCurrency);
76 TESTCASE(TestCurrencyRegression); 77 TESTCASE(TestCurrencyRegression);
77 TESTCASE(TestTextAttributeCrash); 78 TESTCASE(TestTextAttributeCrash);
78 TESTCASE(TestRBNFFormat); 79 TESTCASE(TestRBNFFormat);
79 TESTCASE(TestNBSPInPattern); 80 TESTCASE(TestNBSPInPattern);
80 TESTCASE(TestInt64Parse); 81 TESTCASE(TestInt64Parse);
81 TESTCASE(TestParseZero); 82 TESTCASE(TestParseZero);
82 TESTCASE(TestParseCurrency); 83 TESTCASE(TestParseCurrency);
83 TESTCASE(TestCloneWithRBNF); 84 TESTCASE(TestCloneWithRBNF);
84 TESTCASE(TestMaxInt); 85 TESTCASE(TestMaxInt);
85 TESTCASE(TestNoExponent); 86 TESTCASE(TestNoExponent);
86 TESTCASE(TestUFormattable); 87 TESTCASE(TestUFormattable);
87 TESTCASE(TestUNumberingSystem); 88 TESTCASE(TestUNumberingSystem);
88 TESTCASE(TestCurrencyIsoPluralFormat); 89 TESTCASE(TestCurrencyIsoPluralFormat);
89 TESTCASE(TestContext); 90 TESTCASE(TestContext);
90 TESTCASE(TestCurrencyUsage); 91 TESTCASE(TestCurrencyUsage);
91 TESTCASE(TestCurrFmtNegSameAsPositive); 92 TESTCASE(TestCurrFmtNegSameAsPositive);
93 TESTCASE(TestVariousStylesAndAttributes);
92 } 94 }
93 95
94 /* test Parse int 64 */ 96 /* test Parse int 64 */
95 97
96 static void TestInt64Parse() 98 static void TestInt64Parse()
97 { 99 {
98 100
99 UErrorCode st = U_ZERO_ERROR; 101 UErrorCode st = U_ZERO_ERROR;
100 UErrorCode* status = &st; 102 UErrorCode* status = &st;
101 103
(...skipping 2280 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 numsysCount, foundLatn, foundArab); 2384 numsysCount, foundLatn, foundArab);
2383 } 2385 }
2384 } else { 2386 } else {
2385 log_data_err("unumsys_openAvailableNames fails with status %s\n", myErro rName(status)); 2387 log_data_err("unumsys_openAvailableNames fails with status %s\n", myErro rName(status));
2386 } 2388 }
2387 } 2389 }
2388 2390
2389 /* plain-C version of test in numfmtst.cpp */ 2391 /* plain-C version of test in numfmtst.cpp */
2390 enum { kUBufMax = 64 }; 2392 enum { kUBufMax = 64 };
2391 static void TestCurrencyIsoPluralFormat(void) { 2393 static void TestCurrencyIsoPluralFormat(void) {
2392 static const char* DATA[][6] = { 2394 static const char* DATA[][8] = {
2393 // the data are: 2395 // the data are:
2394 // locale, 2396 // locale,
2395 // currency amount to be formatted, 2397 // currency amount to be formatted,
2396 // currency ISO code to be formatted, 2398 // currency ISO code to be formatted,
2397 // format result using CURRENCYSTYLE, 2399 // format result using CURRENCYSTYLE,
2400 // format result using CURRENCY_STANDARD,
2401 // format result using CURRENCY_ACCOUNTING,
2398 // format result using ISOCURRENCYSTYLE, 2402 // format result using ISOCURRENCYSTYLE,
2399 // format result using PLURALCURRENCYSTYLE, 2403 // format result using PLURALCURRENCYSTYLE,
2400 2404
2401 {"en_US", "1", "USD", "$1.00", "USD1.00", "1.00 US dollars"}, 2405 // locale amount ISOcode CURRENCYSTYLE CURRENCY_ STANDARD CURRENCY_ACCOUNTING ISOCURRENCYSTYLE PLURALCURRENCYSTYLE
2402 {"en_US", "1234.56", "USD", "$1,234.56", "USD1,234.56", "1,234.56 US dol lars"}, 2406 {"en_US", "1", "USD", "$1.00", "$1.00", "$1.00", "USD1.00", "1.00 US dollars"},
2403 {"en_US", "-1234.56", "USD", "-$1,234.56", "-USD1,234.56", "-1,234.56 US dollars"}, 2407 {"en_US", "1234.56", "USD", "$1,234.56", "$1,234.5 6", "$1,234.56", "USD1,234.56", "1,234.56 US dollars"},
2404 {"zh_CN", "1", "USD", "US$\\u00A01.00", "USD\\u00A01.00", "1.00\\u7F8E\\ u5143"}, 2408 {"en_US@cf=account", "1234.56", "USD", "$1,234.56", "$1,234.5 6", "$1,234.56", "USD1,234.56", "1,234.56 US dollars"},
2405 {"zh_CN", "1234.56", "USD", "US$\\u00A01,234.56", "USD\\u00A01,234.56", "1,234.56\\u7F8E\\u5143"}, 2409 {"en_US", "-1234.56", "USD", "-$1,234.56", "-$1,234. 56", "($1,234.56)", "-USD1,234.56", "-1,234.56 US dollars"},
2406 // wrong ISO code {"zh_CN", "1", "CHY", "CHY1.00", "CHY1.00", "1.00 CHY" }, 2410 {"en_US@cf=account", "-1234.56", "USD", "($1,234.56)", "-$1,234. 56", "($1,234.56)", "-USD1,234.56", "-1,234.56 US dollars"},
2407 // wrong ISO code {"zh_CN", "1234.56", "CHY", "CHY1,234.56", "CHY1,234.5 6", "1,234.56 CHY"}, 2411 {"en_US@cf=standard", "-1234.56", "USD", "-$1,234.56", "-$1,234. 56", "($1,234.56)", "-USD1,234.56", "-1,234.56 US dollars"},
2408 {"zh_CN", "1", "CNY", "\\uFFE5\\u00A01.00", "CNY\\u00A01.00", "1.00\\u4E BA\\u6C11\\u5E01"}, 2412 {"zh_CN", "1", "USD", "US$1.00", "US$1.00" , "US$1.00", "USD1.00", "1.00\\u7F8E\\u5143"},
2409 {"zh_CN", "1234.56", "CNY", "\\uFFE5\\u00A01,234.56", "CNY\\u00A01,234.5 6", "1,234.56\\u4EBA\\u6C11\\u5E01"}, 2413 {"zh_CN", "-1", "USD", "-US$1.00", "-US$1.00 ", "(US$1.00)", "-USD1.00", "-1.00\\u7F8E\\u5143"},
2410 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u0440\\u0443\\u0431.", "1,00\\u00A0R UB", "1,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u043 3\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"}, 2414 {"zh_CN@cf=account", "-1", "USD", "(US$1.00)", "-US$1.00 ", "(US$1.00)", "-USD1.00", "-1.00\\u7F8E\\u5143"},
2411 {"ru_RU", "2", "RUB", "2,00\\u00A0\\u0440\\u0443\\u0431.", "2,00\\u00A0R UB", "2,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u043 3\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"}, 2415 {"zh_CN@cf=standard", "-1", "USD", "-US$1.00", "-US$1.00 ", "(US$1.00)", "-USD1.00", "-1.00\\u7F8E\\u5143"},
2412 {"ru_RU", "5", "RUB", "5,00\\u00A0\\u0440\\u0443\\u0431.", "5,00\\u00A0R UB", "5,00 \\u0440\\u043E\\u0441\\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u043 3\\u043E \\u0440\\u0443\\u0431\\u043B\\u044F"}, 2416 {"zh_CN", "1234.56", "USD", "US$1,234.56", "US$1,234 .56", "US$1,234.56", "USD1,234.56", "1,234.56\\u7F8E\\u5143"},
2417 // {"zh_CN", "1", "CHY", "CHY1.00", "CHY1.00" , "CHY1.00", "CHY1.00", "1.00 CHY"}, // wrong ISO c ode
2418 // {"zh_CN", "1234.56", "CHY", "CHY1,234.56", "CHY1,234 .56", "CHY1,234.56", "CHY1,234.56", "1,234.56 CHY"}, // wrong I SO code
2419 {"zh_CN", "1", "CNY", "\\uFFE51.00", "\\uFFE51 .00", "\\uFFE51.00", "CNY1.00", "1.00\\u4EBA\\u6C11\\u5E01" },
2420 {"zh_CN", "1234.56", "CNY", "\\uFFE51,234.56", "\\uFFE51 ,234.56", "\\uFFE51,234.56", "CNY1,234.56", "1,234.56\\u4EBA\\u6C11\\u5 E01"},
2421 {"ru_RU", "1", "RUB", "1,00\\u00A0\\u20BD", "1,00\\u0 0A0\\u20BD", "1,00\\u00A0\\u20BD", "1,00\\u00A0RUB", "1,00 \\u0440\\u043E\\u0441 \\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E "
2422 "\\u0440\\u0443\\u043 1\\u043B\\u044F"},
2423 {"ru_RU", "2", "RUB", "2,00\\u00A0\\u20BD", "2,00\\u0 0A0\\u20BD", "2,00\\u00A0\\u20BD", "2,00\\u00A0RUB", "2,00 \\u0440\\u043E\\u0441 \\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E "
2424 "\\u0440\\u0443\\u043 1\\u043B\\u044F"},
2425 {"ru_RU", "5", "RUB", "5,00\\u00A0\\u20BD", "5,00\\u0 0A0\\u20BD", "5,00\\u00A0\\u20BD", "5,00\\u00A0RUB", "5,00 \\u0440\\u043E\\u0441 \\u0441\\u0438\\u0439\\u0441\\u043A\\u043E\\u0433\\u043E "
2426 "\\u0440\\u0443\\u043 1\\u043B\\u044F"},
2413 // test locale without currency information 2427 // test locale without currency information
2414 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 US D"}, 2428 {"root", "-1.23", "USD", "-US$\\u00A01.23", "-US$\\u0 0A01.23", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 USD"},
2429 {"root@cf=account", "-1.23", "USD", "-US$\\u00A01.23", "-US$\\u0 0A01.23", "-US$\\u00A01.23", "-USD\\u00A01.23", "-1.23 USD"},
2415 // test choice format 2430 // test choice format
2416 {"es_AR", "1", "INR", "INR1,00", "INR1,00", "1,00 rupia india"}, 2431 {"es_AR", "1", "INR", "INR\\u00A01,00", "INR\\u00 A01,00", "INR\\u00A01,00", "INR\\u00A01,00", "1,00 rupia india"},
2417 }; 2432 };
2418 static const UNumberFormatStyle currencyStyles[] = { 2433 static const UNumberFormatStyle currencyStyles[] = {
2419 UNUM_CURRENCY, 2434 UNUM_CURRENCY,
2435 UNUM_CURRENCY_STANDARD,
2436 UNUM_CURRENCY_ACCOUNTING,
2420 UNUM_CURRENCY_ISO, 2437 UNUM_CURRENCY_ISO,
2421 UNUM_CURRENCY_PLURAL 2438 UNUM_CURRENCY_PLURAL
2422 }; 2439 };
2423 2440
2424 int32_t i, sIndex; 2441 int32_t i, sIndex;
2425 2442
2426 for (i=0; i<LENGTH(DATA); ++i) { 2443 for (i=0; i<LENGTH(DATA); ++i) {
2427 const char* localeString = DATA[i][0]; 2444 const char* localeString = DATA[i][0];
2428 double numberToBeFormat = atof(DATA[i][1]); 2445 double numberToBeFormat = atof(DATA[i][1]);
2429 const char* currencyISOCode = DATA[i][2]; 2446 const char* currencyISOCode = DATA[i][2];
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 {0xA4,0x23,0x2C,0x23,0x23,0x30,0x2E,0x30,0x30,0x3B,0xA4,0x23,0x2C,0x23,0x23, 0x30,0x2E,0x30,0x30,0}; 2631 {0xA4,0x23,0x2C,0x23,0x23,0x30,0x2E,0x30,0x30,0x3B,0xA4,0x23,0x2C,0x23,0x23, 0x30,0x2E,0x30,0x30,0};
2615 2632
2616 static UChar currFmtToPatExpected[] = /* "\u00A4#,##0.00" */ 2633 static UChar currFmtToPatExpected[] = /* "\u00A4#,##0.00" */
2617 {0xA4,0x23,0x2C,0x23,0x23,0x30,0x2E,0x30,0x30,0}; 2634 {0xA4,0x23,0x2C,0x23,0x23,0x30,0x2E,0x30,0x30,0};
2618 2635
2619 static UChar currFmtResultExpected[] = /* "$100.00" */ 2636 static UChar currFmtResultExpected[] = /* "$100.00" */
2620 {0x24,0x31,0x30,0x30,0x2E,0x30,0x30,0}; 2637 {0x24,0x31,0x30,0x30,0x2E,0x30,0x30,0};
2621 2638
2622 static UChar emptyString[] = {0}; 2639 static UChar emptyString[] = {0};
2623 2640
2624 enum { kUBufSize = 64 }; 2641 enum { kUBufSize = 64, kBBufSize = 128 };
2625 2642
2626 static void TestCurrFmtNegSameAsPositive(void) { 2643 static void TestCurrFmtNegSameAsPositive(void) {
2627 UErrorCode status = U_ZERO_ERROR; 2644 UErrorCode status = U_ZERO_ERROR;
2628 UNumberFormat* unumfmt = unum_open(UNUM_CURRENCY, NULL, 0, "en_US", NULL, &s tatus); 2645 UNumberFormat* unumfmt = unum_open(UNUM_CURRENCY, NULL, 0, "en_US", NULL, &s tatus);
2629 if ( U_SUCCESS(status) ) { 2646 if ( U_SUCCESS(status) ) {
2630 unum_applyPattern(unumfmt, FALSE, currFmtNegSameAsPos, -1, NULL, &status ); 2647 unum_applyPattern(unumfmt, FALSE, currFmtNegSameAsPos, -1, NULL, &status );
2631 if (U_SUCCESS(status)) { 2648 if (U_SUCCESS(status)) {
2632 UChar ubuf[kUBufSize]; 2649 UChar ubuf[kUBufSize];
2633 int32_t ulen = unum_toPattern(unumfmt, FALSE, ubuf, kUBufSize, &stat us); 2650 int32_t ulen = unum_toPattern(unumfmt, FALSE, ubuf, kUBufSize, &stat us);
2634 if (U_FAILURE(status)) { 2651 if (U_FAILURE(status)) {
(...skipping 14 matching lines...) Expand all
2649 } 2666 }
2650 } else { 2667 } else {
2651 log_err("unum_applyPattern fails with status %s\n", myErrorName(stat us)); 2668 log_err("unum_applyPattern fails with status %s\n", myErrorName(stat us));
2652 } 2669 }
2653 unum_close(unumfmt); 2670 unum_close(unumfmt);
2654 } else { 2671 } else {
2655 log_data_err("unum_open UNUM_CURRENCY for en_US fails with status %s\n", myErrorName(status)); 2672 log_data_err("unum_open UNUM_CURRENCY for en_US fails with status %s\n", myErrorName(status));
2656 } 2673 }
2657 } 2674 }
2658 2675
2676
2677 typedef struct {
2678 double value;
2679 const char *expected;
2680 } ValueAndExpectedString;
2681
2682 static const ValueAndExpectedString enShort[] = {
2683 {0.0, "0"},
2684 {0.17, "0.17"},
2685 {1.0, "1"},
2686 {1234.0, "1.23K"},
2687 {12345.0, "12.3K"},
2688 {123456.0, "123K"},
2689 {1234567.0, "1.23M"},
2690 {12345678.0, "12.3M"},
2691 {123456789.0, "123M"},
2692 {1.23456789E9, "1.23B"},
2693 {1.23456789E10, "12.3B"},
2694 {1.23456789E11, "123B"},
2695 {1.23456789E12, "1.23T"},
2696 {1.23456789E13, "12.3T"},
2697 {1.23456789E14, "123T"},
2698 {1.23456789E15, "1230T"},
2699 {0.0, NULL}
2700 };
2701
2702 static const ValueAndExpectedString enShortMax2[] = {
2703 {0.0, "0"},
2704 {0.17, "0.17"},
2705 {1.0, "1"},
2706 {1234.0, "1.2K"},
2707 {12345.0, "12K"},
2708 {123456.0, "120K"},
2709 {1234567.0, "1.2M"},
2710 {12345678.0, "12M"},
2711 {123456789.0, "120M"},
2712 {1.23456789E9, "1.2B"},
2713 {1.23456789E10, "12B"},
2714 {1.23456789E11, "120B"},
2715 {1.23456789E12, "1.2T"},
2716 {1.23456789E13, "12T"},
2717 {1.23456789E14, "120T"},
2718 {1.23456789E15, "1200T"},
2719 {0.0, NULL}
2720 };
2721
2722 static const ValueAndExpectedString enShortMax5[] = {
2723 {0.0, "0"},
2724 {0.17, "0.17"},
2725 {1.0, "1"},
2726 {1234.0, "1.234K"},
2727 {12345.0, "12.345K"},
2728 {123456.0, "123.46K"},
2729 {1234567.0, "1.2346M"},
2730 {12345678.0, "12.346M"},
2731 {123456789.0, "123.46M"},
2732 {1.23456789E9, "1.2346B"},
2733 {1.23456789E10, "12.346B"},
2734 {1.23456789E11, "123.46B"},
2735 {1.23456789E12, "1.2346T"},
2736 {1.23456789E13, "12.346T"},
2737 {1.23456789E14, "123.46T"},
2738 {1.23456789E15, "1234.6T"},
2739 {0.0, NULL}
2740 };
2741
2742 static const ValueAndExpectedString enShortMin3[] = {
2743 {0.0, "0.00"},
2744 {0.17, "0.170"},
2745 {1.0, "1.00"},
2746 {1234.0, "1.23K"},
2747 {12345.0, "12.3K"},
2748 {123456.0, "123K"},
2749 {1234567.0, "1.23M"},
2750 {12345678.0, "12.3M"},
2751 {123456789.0, "123M"},
2752 {1.23456789E9, "1.23B"},
2753 {1.23456789E10, "12.3B"},
2754 {1.23456789E11, "123B"},
2755 {1.23456789E12, "1.23T"},
2756 {1.23456789E13, "12.3T"},
2757 {1.23456789E14, "123T"},
2758 {1.23456789E15, "1230T"},
2759 {0.0, NULL}
2760 };
2761
2762 static const ValueAndExpectedString jaShortMax2[] = {
2763 {1234.0, "1200"},
2764 {12345.0, "1.2\\u4E07"},
2765 {123456.0, "12\\u4E07"},
2766 {1234567.0, "120\\u4E07"},
2767 {12345678.0, "1200\\u4E07"},
2768 {123456789.0, "1.2\\u5104"},
2769 {1.23456789E9, "12\\u5104"},
2770 {1.23456789E10, "120\\u5104"},
2771 {1.23456789E11, "1200\\u5104"},
2772 {1.23456789E12, "1.2\\u5146"},
2773 {1.23456789E13, "12\\u5146"},
2774 {1.23456789E14, "120\\u5146"},
2775 {0.0, NULL}
2776 };
2777
2778 static const ValueAndExpectedString srLongMax2[] = {
2779 {1234.0, "1,2 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"}, // 10^3 few
2780 {12345.0, "12 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"}, // 10^3 other
2781 {21789.0, "22 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"}, // 10^3 few
2782 {123456.0, "120 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"}, // 10^3 other
2783 {999999.0, "1 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D"}, // 10^6 one
2784 {1234567.0, "1,2 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^6 few
2785 {12345678.0, "12 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^6 other
2786 {123456789.0, "120 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^ 6 other
2787 {1.23456789E9, "1,2 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\ u0435"}, // 10^9 few
2788 {1.23456789E10, "12 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\ u0438"}, // 10^9 other
2789 {2.08901234E10, "21 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\ u0430"}, // 10^9 one
2790 {2.18901234E10, "22 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\ u0435"}, // 10^9 few
2791 {1.23456789E11, "120 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\ \u0438"}, // 10^9 other
2792 {-1234.0, "-1,2 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"},
2793 {-12345.0, "-12 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"},
2794 {-21789.0, "-22 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"},
2795 {-123456.0, "-120 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"},
2796 {-999999.0, "-1 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D"},
2797 {-1234567.0, "-1,2 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"},
2798 {-12345678.0, "-12 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"},
2799 {-123456789.0, "-120 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"},
2800 {-1.23456789E9, "-1,2 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434 \\u0435"},
2801 {-1.23456789E10, "-12 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434 \\u0438"},
2802 {-2.08901234E10, "-21 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434 \\u0430"},
2803 {-2.18901234E10, "-22 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434 \\u0435"},
2804 {-1.23456789E11, "-120 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u043 4\\u0438"},
2805 {0.0, NULL}
2806 };
2807
2808 typedef struct {
2809 const char * locale;
2810 UNumberFormatStyle style;
2811 int32_t attribute; // UNumberFormatAttribute, or -1 for none
2812 int32_t attrValue; //
2813 const ValueAndExpectedString * veItems;
2814 } LocStyleAttributeTest;
2815
2816 static const LocStyleAttributeTest lsaTests[] = {
2817 { "en", UNUM_DECIMAL_COMPACT_SHORT, -1, 0, enShort },
2818 { "en", UNUM_DECIMAL_COMPACT_SHORT, UNUM_MAX_SIGNIFICANT_DIGITS, 2, enShortMax2 },
2819 { "en", UNUM_DECIMAL_COMPACT_SHORT, UNUM_MAX_SIGNIFICANT_DIGITS, 5, enShortMax5 },
2820 { "en", UNUM_DECIMAL_COMPACT_SHORT, UNUM_MIN_SIGNIFICANT_DIGITS, 3, enShortMin3 },
2821 { "ja", UNUM_DECIMAL_COMPACT_SHORT, UNUM_MAX_SIGNIFICANT_DIGITS, 2, jaShortMax2 },
2822 { "sr", UNUM_DECIMAL_COMPACT_LONG, UNUM_MAX_SIGNIFICANT_DIGITS, 2, srLongMax2 },
2823 { NULL, (UNumberFormatStyle)0, -1, 0, NULL }
2824 };
2825
2826 static void TestVariousStylesAndAttributes(void) {
2827 const LocStyleAttributeTest * lsaTestPtr;
2828 for (lsaTestPtr = lsaTests; lsaTestPtr->locale != NULL; lsaTestPtr++) {
2829 UErrorCode status = U_ZERO_ERROR;
2830 UNumberFormat * unum = unum_open(lsaTestPtr->style, NULL, 0, lsaTestPtr- >locale, NULL, &status);
2831 if ( U_FAILURE(status) ) {
2832 log_data_err("FAIL: unum_open style %d, locale %s: error %s\n", (int )lsaTestPtr->style, lsaTestPtr->locale, u_errorName(status));
2833 } else {
2834 const ValueAndExpectedString * veItemPtr;
2835 if (lsaTestPtr->attribute >= 0) {
2836 unum_setAttribute(unum, (UNumberFormatAttribute)lsaTestPtr->attr ibute, lsaTestPtr->attrValue);
2837 }
2838 for (veItemPtr = lsaTestPtr->veItems; veItemPtr->expected != NULL; v eItemPtr++) {
2839 UChar uexp[kUBufSize];
2840 UChar uget[kUBufSize];
2841 int32_t uexplen, ugetlen;
2842
2843 status = U_ZERO_ERROR;
2844 uexplen = u_unescape(veItemPtr->expected, uexp, kUBufSize);
2845 ugetlen = unum_formatDouble(unum, veItemPtr->value, uget, kUBufS ize, NULL, &status);
2846 if ( U_FAILURE(status) ) {
2847 log_err("FAIL: unum_formatDouble style %d, locale %s, attr % d, value %.2f: error %s\n",
2848 (int)lsaTestPtr->style, lsaTestPtr->locale, lsaTestP tr->attribute, veItemPtr->value, u_errorName(status));
2849 } else if (ugetlen != uexplen || u_strncmp(uget, uexp, uexplen) != 0) {
2850 char bexp[kBBufSize];
2851 char bget[kBBufSize];
2852 u_strToUTF8(bexp, kBBufSize, NULL, uexp, uexplen, &status);
2853 u_strToUTF8(bget, kBBufSize, NULL, uget, ugetlen, &status);
2854 log_err("FAIL: unum_formatDouble style %d, locale %s, attr % d, value %.2f: expect \"%s\", get \"%s\"\n",
2855 (int)lsaTestPtr->style, lsaTestPtr->locale, lsaTestP tr->attribute, veItemPtr->value, bexp, bget);
2856 }
2857 }
2858 unum_close(unum);
2859 }
2860 }
2861 }
2862
2659 #endif /* #if !UCONFIG_NO_FORMATTING */ 2863 #endif /* #if !UCONFIG_NO_FORMATTING */
OLDNEW
« no previous file with comments | « source/test/cintltst/cmsccoll.c ('k') | source/test/cintltst/creststn.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698