OLD | NEW |
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 #include "unicode/utypes.h" | 7 #include "unicode/utypes.h" |
8 | 8 |
9 #if !UCONFIG_NO_FORMATTING | 9 #if !UCONFIG_NO_FORMATTING |
10 | 10 |
11 #include "dcfmapts.h" | 11 #include "dcfmapts.h" |
12 | 12 |
13 #include "unicode/currpinf.h" | 13 #include "unicode/currpinf.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s
", u_errorName(status)); | 106 errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s
", u_errorName(status)); |
107 return; | 107 return; |
108 } | 108 } |
109 | 109 |
110 // bug 10864 | 110 // bug 10864 |
111 status = U_ZERO_ERROR; | 111 status = U_ZERO_ERROR; |
112 DecimalFormat noGrouping("###0.##", status); | 112 DecimalFormat noGrouping("###0.##", status); |
113 if (noGrouping.getGroupingSize() != 0) { | 113 if (noGrouping.getGroupingSize() != 0) { |
114 errln("Grouping size should be 0 for no grouping."); | 114 errln("Grouping size should be 0 for no grouping."); |
115 } | 115 } |
| 116 noGrouping.setGroupingUsed(TRUE); |
| 117 if (noGrouping.getGroupingSize() != 0) { |
| 118 errln("Grouping size should still be 0."); |
| 119 } |
116 // end bug 10864 | 120 // end bug 10864 |
117 | 121 |
118 status = U_ZERO_ERROR; | 122 status = U_ZERO_ERROR; |
119 const UnicodeString pattern("#,##0.# FF"); | 123 const UnicodeString pattern("#,##0.# FF"); |
120 DecimalFormat pat(pattern, status); | 124 DecimalFormat pat(pattern, status); |
121 if(U_FAILURE(status)) { | 125 if(U_FAILURE(status)) { |
122 errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern)"); | 126 errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern)"); |
123 return; | 127 return; |
124 } | 128 } |
125 | 129 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 440 } |
437 | 441 |
438 cpi->setPluralRules("",status); | 442 cpi->setPluralRules("",status); |
439 if(U_FAILURE(status)) { | 443 if(U_FAILURE(status)) { |
440 errln((UnicodeString)"ERROR: CurrencyPluralInfo::setPluralRules"); | 444 errln((UnicodeString)"ERROR: CurrencyPluralInfo::setPluralRules"); |
441 } | 445 } |
442 | 446 |
443 DecimalFormat *df = new DecimalFormat(status); | 447 DecimalFormat *df = new DecimalFormat(status); |
444 if(U_FAILURE(status)) { | 448 if(U_FAILURE(status)) { |
445 errcheckln(status, "ERROR: Could not create DecimalFormat - %s", u_error
Name(status)); | 449 errcheckln(status, "ERROR: Could not create DecimalFormat - %s", u_error
Name(status)); |
| 450 return; |
446 } | 451 } |
447 | 452 |
448 df->adoptCurrencyPluralInfo(cpi); | 453 df->adoptCurrencyPluralInfo(cpi); |
449 | 454 |
450 df->getCurrencyPluralInfo(); | 455 df->getCurrencyPluralInfo(); |
451 | 456 |
452 df->setCurrencyPluralInfo(cpi1); | 457 df->setCurrencyPluralInfo(cpi1); |
453 | 458 |
454 delete df; | 459 delete df; |
455 } | 460 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 } | 599 } |
595 } | 600 } |
596 | 601 |
597 | 602 |
598 #define ASSERT_EQUAL(expect, actual) { char tmp[200]; sprintf(tmp, "(%g==%g)", (
double)(expect), (double)(actual)); \ | 603 #define ASSERT_EQUAL(expect, actual) { char tmp[200]; sprintf(tmp, "(%g==%g)", (
double)(expect), (double)(actual)); \ |
599 assertTrue(tmp, ((expect)==(actual)), FALSE, TRUE, __FILE__, __LINE__); } | 604 assertTrue(tmp, ((expect)==(actual)), FALSE, TRUE, __FILE__, __LINE__); } |
600 | 605 |
601 void IntlTestDecimalFormatAPI::TestFixedDecimal() { | 606 void IntlTestDecimalFormatAPI::TestFixedDecimal() { |
602 UErrorCode status = U_ZERO_ERROR; | 607 UErrorCode status = U_ZERO_ERROR; |
603 | 608 |
604 LocalPointer<DecimalFormat> df(new DecimalFormat("###", status)); | 609 LocalPointer<DecimalFormat> df(new DecimalFormat("###", status), status); |
605 TEST_ASSERT_STATUS(status); | 610 TEST_ASSERT_STATUS(status); |
| 611 if (status == U_MISSING_RESOURCE_ERROR) { |
| 612 return; |
| 613 } |
606 FixedDecimal fd = df->getFixedDecimal(44, status); | 614 FixedDecimal fd = df->getFixedDecimal(44, status); |
607 TEST_ASSERT_STATUS(status); | 615 TEST_ASSERT_STATUS(status); |
608 ASSERT_EQUAL(44, fd.source); | 616 ASSERT_EQUAL(44, fd.source); |
609 ASSERT_EQUAL(0, fd.visibleDecimalDigitCount); | 617 ASSERT_EQUAL(0, fd.visibleDecimalDigitCount); |
| 618 ASSERT_EQUAL(FALSE, fd.isNegative); |
610 | 619 |
611 df.adoptInstead(new DecimalFormat("###.00##", status)); | 620 fd = df->getFixedDecimal(-44, status); |
| 621 TEST_ASSERT_STATUS(status); |
| 622 ASSERT_EQUAL(44, fd.source); |
| 623 ASSERT_EQUAL(0, fd.visibleDecimalDigitCount); |
| 624 ASSERT_EQUAL(TRUE, fd.isNegative); |
| 625 |
| 626 df.adoptInsteadAndCheckErrorCode(new DecimalFormat("###.00##", status), stat
us); |
612 TEST_ASSERT_STATUS(status); | 627 TEST_ASSERT_STATUS(status); |
613 fd = df->getFixedDecimal(123.456, status); | 628 fd = df->getFixedDecimal(123.456, status); |
614 TEST_ASSERT_STATUS(status); | 629 TEST_ASSERT_STATUS(status); |
615 ASSERT_EQUAL(3, fd.visibleDecimalDigitCount); | 630 ASSERT_EQUAL(3, fd.visibleDecimalDigitCount); // v |
616 ASSERT_EQUAL(456, fd.decimalDigits); | 631 ASSERT_EQUAL(456, fd.decimalDigits); // f |
617 ASSERT_EQUAL(456, fd.decimalDigitsWithoutTrailingZeros); | 632 ASSERT_EQUAL(456, fd.decimalDigitsWithoutTrailingZeros); // t |
618 ASSERT_EQUAL(123, fd.intValue); | 633 ASSERT_EQUAL(123, fd.intValue); // i |
| 634 ASSERT_EQUAL(123.456, fd.source); // n |
619 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); | 635 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
620 ASSERT_EQUAL(FALSE, fd.isNegative); | 636 ASSERT_EQUAL(FALSE, fd.isNegative); |
621 | 637 |
622 df.adoptInstead(new DecimalFormat("###", status)); | 638 fd = df->getFixedDecimal(-123.456, status); |
| 639 TEST_ASSERT_STATUS(status); |
| 640 ASSERT_EQUAL(3, fd.visibleDecimalDigitCount); // v |
| 641 ASSERT_EQUAL(456, fd.decimalDigits); // f |
| 642 ASSERT_EQUAL(456, fd.decimalDigitsWithoutTrailingZeros); // t |
| 643 ASSERT_EQUAL(123, fd.intValue); // i |
| 644 ASSERT_EQUAL(123.456, fd.source); // n |
| 645 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 646 ASSERT_EQUAL(TRUE, fd.isNegative); |
| 647 |
| 648 // test max int digits |
| 649 df->setMaximumIntegerDigits(2); |
| 650 fd = df->getFixedDecimal(123.456, status); |
| 651 TEST_ASSERT_STATUS(status); |
| 652 ASSERT_EQUAL(3, fd.visibleDecimalDigitCount); // v |
| 653 ASSERT_EQUAL(456, fd.decimalDigits); // f |
| 654 ASSERT_EQUAL(456, fd.decimalDigitsWithoutTrailingZeros); // t |
| 655 ASSERT_EQUAL(23, fd.intValue); // i |
| 656 ASSERT_EQUAL(23.456, fd.source); // n |
| 657 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 658 ASSERT_EQUAL(FALSE, fd.isNegative); |
| 659 |
| 660 fd = df->getFixedDecimal(-123.456, status); |
| 661 TEST_ASSERT_STATUS(status); |
| 662 ASSERT_EQUAL(3, fd.visibleDecimalDigitCount); // v |
| 663 ASSERT_EQUAL(456, fd.decimalDigits); // f |
| 664 ASSERT_EQUAL(456, fd.decimalDigitsWithoutTrailingZeros); // t |
| 665 ASSERT_EQUAL(23, fd.intValue); // i |
| 666 ASSERT_EQUAL(23.456, fd.source); // n |
| 667 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 668 ASSERT_EQUAL(TRUE, fd.isNegative); |
| 669 |
| 670 // test max fraction digits |
| 671 df->setMaximumIntegerDigits(2000000000); |
| 672 df->setMaximumFractionDigits(2); |
| 673 fd = df->getFixedDecimal(123.456, status); |
| 674 TEST_ASSERT_STATUS(status); |
| 675 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); // v |
| 676 ASSERT_EQUAL(46, fd.decimalDigits); // f |
| 677 ASSERT_EQUAL(46, fd.decimalDigitsWithoutTrailingZeros); // t |
| 678 ASSERT_EQUAL(123, fd.intValue); // i |
| 679 ASSERT_EQUAL(123.46, fd.source); // n |
| 680 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 681 ASSERT_EQUAL(FALSE, fd.isNegative); |
| 682 |
| 683 fd = df->getFixedDecimal(-123.456, status); |
| 684 TEST_ASSERT_STATUS(status); |
| 685 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); // v |
| 686 ASSERT_EQUAL(46, fd.decimalDigits); // f |
| 687 ASSERT_EQUAL(46, fd.decimalDigitsWithoutTrailingZeros); // t |
| 688 ASSERT_EQUAL(123, fd.intValue); // i |
| 689 ASSERT_EQUAL(123.46, fd.source); // n |
| 690 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 691 ASSERT_EQUAL(TRUE, fd.isNegative); |
| 692 |
| 693 // test esoteric rounding |
| 694 df->setMaximumFractionDigits(6); |
| 695 df->setRoundingIncrement(7.3); |
| 696 |
| 697 fd = df->getFixedDecimal(30.0, status); |
| 698 TEST_ASSERT_STATUS(status); |
| 699 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); // v |
| 700 ASSERT_EQUAL(20, fd.decimalDigits); // f |
| 701 ASSERT_EQUAL(2, fd.decimalDigitsWithoutTrailingZeros); // t |
| 702 ASSERT_EQUAL(29, fd.intValue); // i |
| 703 ASSERT_EQUAL(29.2, fd.source); // n |
| 704 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 705 ASSERT_EQUAL(FALSE, fd.isNegative); |
| 706 |
| 707 fd = df->getFixedDecimal(-30.0, status); |
| 708 TEST_ASSERT_STATUS(status); |
| 709 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); // v |
| 710 ASSERT_EQUAL(20, fd.decimalDigits); // f |
| 711 ASSERT_EQUAL(2, fd.decimalDigitsWithoutTrailingZeros); // t |
| 712 ASSERT_EQUAL(29, fd.intValue); // i |
| 713 ASSERT_EQUAL(29.2, fd.source); // n |
| 714 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 715 ASSERT_EQUAL(TRUE, fd.isNegative); |
| 716 |
| 717 df.adoptInsteadAndCheckErrorCode(new DecimalFormat("###", status), status); |
623 TEST_ASSERT_STATUS(status); | 718 TEST_ASSERT_STATUS(status); |
624 fd = df->getFixedDecimal(123.456, status); | 719 fd = df->getFixedDecimal(123.456, status); |
625 TEST_ASSERT_STATUS(status); | 720 TEST_ASSERT_STATUS(status); |
626 ASSERT_EQUAL(0, fd.visibleDecimalDigitCount); | 721 ASSERT_EQUAL(0, fd.visibleDecimalDigitCount); |
627 ASSERT_EQUAL(0, fd.decimalDigits); | 722 ASSERT_EQUAL(0, fd.decimalDigits); |
628 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); | 723 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); |
629 ASSERT_EQUAL(123, fd.intValue); | 724 ASSERT_EQUAL(123, fd.intValue); |
630 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); | 725 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); |
631 ASSERT_EQUAL(FALSE, fd.isNegative); | 726 ASSERT_EQUAL(FALSE, fd.isNegative); |
632 | 727 |
633 df.adoptInstead(new DecimalFormat("###.0", status)); | 728 df.adoptInsteadAndCheckErrorCode(new DecimalFormat("###.0", status), status)
; |
634 TEST_ASSERT_STATUS(status); | 729 TEST_ASSERT_STATUS(status); |
635 fd = df->getFixedDecimal(123.01, status); | 730 fd = df->getFixedDecimal(123.01, status); |
636 TEST_ASSERT_STATUS(status); | 731 TEST_ASSERT_STATUS(status); |
637 ASSERT_EQUAL(1, fd.visibleDecimalDigitCount); | 732 ASSERT_EQUAL(1, fd.visibleDecimalDigitCount); |
638 ASSERT_EQUAL(0, fd.decimalDigits); | 733 ASSERT_EQUAL(0, fd.decimalDigits); |
639 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); | 734 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); |
640 ASSERT_EQUAL(123, fd.intValue); | 735 ASSERT_EQUAL(123, fd.intValue); |
641 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); | 736 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); |
642 ASSERT_EQUAL(FALSE, fd.isNegative); | 737 ASSERT_EQUAL(FALSE, fd.isNegative); |
643 | 738 |
644 df.adoptInstead(new DecimalFormat("###.0", status)); | 739 df.adoptInsteadAndCheckErrorCode(new DecimalFormat("###.0", status), status)
; |
645 TEST_ASSERT_STATUS(status); | 740 TEST_ASSERT_STATUS(status); |
646 fd = df->getFixedDecimal(123.06, status); | 741 fd = df->getFixedDecimal(123.06, status); |
647 TEST_ASSERT_STATUS(status); | 742 TEST_ASSERT_STATUS(status); |
648 ASSERT_EQUAL(1, fd.visibleDecimalDigitCount); | 743 ASSERT_EQUAL(1, fd.visibleDecimalDigitCount); |
649 ASSERT_EQUAL(1, fd.decimalDigits); | 744 ASSERT_EQUAL(1, fd.decimalDigits); |
650 ASSERT_EQUAL(1, fd.decimalDigitsWithoutTrailingZeros); | 745 ASSERT_EQUAL(1, fd.decimalDigitsWithoutTrailingZeros); |
651 ASSERT_EQUAL(123, fd.intValue); | 746 ASSERT_EQUAL(123, fd.intValue); |
652 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); | 747 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
653 ASSERT_EQUAL(FALSE, fd.isNegative); | 748 ASSERT_EQUAL(FALSE, fd.isNegative); |
654 | 749 |
655 df.adoptInstead(new DecimalFormat("@@@@@", status)); // Significant Digits | 750 df.adoptInsteadAndCheckErrorCode(new DecimalFormat("@@@@@", status), status)
; // Significant Digits |
656 TEST_ASSERT_STATUS(status); | 751 TEST_ASSERT_STATUS(status); |
657 fd = df->getFixedDecimal(123, status); | 752 fd = df->getFixedDecimal(123, status); |
658 TEST_ASSERT_STATUS(status); | 753 TEST_ASSERT_STATUS(status); |
659 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); | 754 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); |
660 ASSERT_EQUAL(0, fd.decimalDigits); | 755 ASSERT_EQUAL(0, fd.decimalDigits); |
661 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); | 756 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); |
662 ASSERT_EQUAL(123, fd.intValue); | 757 ASSERT_EQUAL(123, fd.intValue); |
663 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); | 758 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); |
664 ASSERT_EQUAL(FALSE, fd.isNegative); | 759 ASSERT_EQUAL(FALSE, fd.isNegative); |
665 | 760 |
666 df.adoptInstead(new DecimalFormat("@@@@@", status)); // Significant Digits | 761 df.adoptInsteadAndCheckErrorCode(new DecimalFormat("@@@@@", status), status)
; // Significant Digits |
667 TEST_ASSERT_STATUS(status); | 762 TEST_ASSERT_STATUS(status); |
668 fd = df->getFixedDecimal(1.23, status); | 763 fd = df->getFixedDecimal(1.23, status); |
669 TEST_ASSERT_STATUS(status); | 764 TEST_ASSERT_STATUS(status); |
670 ASSERT_EQUAL(4, fd.visibleDecimalDigitCount); | 765 ASSERT_EQUAL(4, fd.visibleDecimalDigitCount); |
671 ASSERT_EQUAL(2300, fd.decimalDigits); | 766 ASSERT_EQUAL(2300, fd.decimalDigits); |
672 ASSERT_EQUAL(23, fd.decimalDigitsWithoutTrailingZeros); | 767 ASSERT_EQUAL(23, fd.decimalDigitsWithoutTrailingZeros); |
673 ASSERT_EQUAL(1, fd.intValue); | 768 ASSERT_EQUAL(1, fd.intValue); |
674 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); | 769 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
675 ASSERT_EQUAL(FALSE, fd.isNegative); | 770 ASSERT_EQUAL(FALSE, fd.isNegative); |
676 | 771 |
677 fd = df->getFixedDecimal(uprv_getInfinity(), status); | 772 fd = df->getFixedDecimal(uprv_getInfinity(), status); |
678 TEST_ASSERT_STATUS(status); | 773 TEST_ASSERT_STATUS(status); |
679 ASSERT_EQUAL(TRUE, fd.isNanOrInfinity); | 774 ASSERT_EQUAL(TRUE, fd.isNanOrInfinity); |
680 fd = df->getFixedDecimal(0.0, status); | 775 fd = df->getFixedDecimal(0.0, status); |
681 ASSERT_EQUAL(FALSE, fd.isNanOrInfinity); | 776 ASSERT_EQUAL(FALSE, fd.isNanOrInfinity); |
682 fd = df->getFixedDecimal(uprv_getNaN(), status); | 777 fd = df->getFixedDecimal(uprv_getNaN(), status); |
683 ASSERT_EQUAL(TRUE, fd.isNanOrInfinity); | 778 ASSERT_EQUAL(TRUE, fd.isNanOrInfinity); |
684 TEST_ASSERT_STATUS(status); | 779 TEST_ASSERT_STATUS(status); |
685 | 780 |
686 // Test Big Decimal input. | 781 // Test Big Decimal input. |
687 // 22 digits before and after decimal, will exceed the precision of a double | 782 // 22 digits before and after decimal, will exceed the precision of a double |
688 // and force DecimalFormat::getFixedDecimal() to work with a digit list. | 783 // and force DecimalFormat::getFixedDecimal() to work with a digit list. |
689 df.adoptInstead(new DecimalFormat("#####################0.00################
####", status)); | 784 df.adoptInsteadAndCheckErrorCode( |
| 785 new DecimalFormat("#####################0.00####################", statu
s), status); |
690 TEST_ASSERT_STATUS(status); | 786 TEST_ASSERT_STATUS(status); |
691 Formattable fable("12.34", status); | 787 Formattable fable("12.34", status); |
692 TEST_ASSERT_STATUS(status); | 788 TEST_ASSERT_STATUS(status); |
693 fd = df->getFixedDecimal(fable, status); | 789 fd = df->getFixedDecimal(fable, status); |
694 TEST_ASSERT_STATUS(status); | 790 TEST_ASSERT_STATUS(status); |
695 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); | 791 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); |
696 ASSERT_EQUAL(34, fd.decimalDigits); | 792 ASSERT_EQUAL(34, fd.decimalDigits); |
697 ASSERT_EQUAL(34, fd.decimalDigitsWithoutTrailingZeros); | 793 ASSERT_EQUAL(34, fd.decimalDigitsWithoutTrailingZeros); |
698 ASSERT_EQUAL(12, fd.intValue); | 794 ASSERT_EQUAL(12, fd.intValue); |
699 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); | 795 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 TEST_ASSERT_STATUS(status); | 859 TEST_ASSERT_STATUS(status); |
764 fd = df->getFixedDecimal(fable, status); | 860 fd = df->getFixedDecimal(fable, status); |
765 TEST_ASSERT_STATUS(status); | 861 TEST_ASSERT_STATUS(status); |
766 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); | 862 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); |
767 ASSERT_EQUAL(30, fd.decimalDigits); | 863 ASSERT_EQUAL(30, fd.decimalDigits); |
768 ASSERT_EQUAL(3, fd.decimalDigitsWithoutTrailingZeros); | 864 ASSERT_EQUAL(3, fd.decimalDigitsWithoutTrailingZeros); |
769 ASSERT_EQUAL(100000000000000000LL, fd.intValue); | 865 ASSERT_EQUAL(100000000000000000LL, fd.intValue); |
770 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); | 866 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
771 ASSERT_EQUAL(FALSE, fd.isNegative); | 867 ASSERT_EQUAL(FALSE, fd.isNegative); |
772 | 868 |
| 869 fable.setDecimalNumber("1000000000000000050000.3", status); |
| 870 TEST_ASSERT_STATUS(status); |
| 871 fd = df->getFixedDecimal(fable, status); |
| 872 TEST_ASSERT_STATUS(status); |
| 873 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); |
| 874 ASSERT_EQUAL(30, fd.decimalDigits); |
| 875 ASSERT_EQUAL(3, fd.decimalDigitsWithoutTrailingZeros); |
| 876 ASSERT_EQUAL(50000LL, fd.intValue); |
| 877 ASSERT_EQUAL(FALSE, fd.hasIntegerValue); |
| 878 ASSERT_EQUAL(FALSE, fd.isNegative); |
| 879 |
773 // Test some int64_t values that are out of the range of a double | 880 // Test some int64_t values that are out of the range of a double |
774 fable.setInt64(4503599627370496LL); | 881 fable.setInt64(4503599627370496LL); |
775 TEST_ASSERT_STATUS(status); | 882 TEST_ASSERT_STATUS(status); |
776 fd = df->getFixedDecimal(fable, status); | 883 fd = df->getFixedDecimal(fable, status); |
777 TEST_ASSERT_STATUS(status); | 884 TEST_ASSERT_STATUS(status); |
778 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); | 885 ASSERT_EQUAL(2, fd.visibleDecimalDigitCount); |
779 ASSERT_EQUAL(0, fd.decimalDigits); | 886 ASSERT_EQUAL(0, fd.decimalDigits); |
780 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); | 887 ASSERT_EQUAL(0, fd.decimalDigitsWithoutTrailingZeros); |
781 ASSERT_EQUAL(4503599627370496LL, fd.intValue); | 888 ASSERT_EQUAL(4503599627370496LL, fd.intValue); |
782 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); | 889 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); |
(...skipping 24 matching lines...) Expand all Loading... |
807 dataerrln("File %s, Line %d, fd.intValue = %lld", __FILE__, __LINE__, fd
.intValue); | 914 dataerrln("File %s, Line %d, fd.intValue = %lld", __FILE__, __LINE__, fd
.intValue); |
808 } | 915 } |
809 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); | 916 ASSERT_EQUAL(TRUE, fd.hasIntegerValue); |
810 ASSERT_EQUAL(FALSE, fd.isNegative); | 917 ASSERT_EQUAL(FALSE, fd.isNegative); |
811 | 918 |
812 } | 919 } |
813 | 920 |
814 void IntlTestDecimalFormatAPI::TestBadFastpath() { | 921 void IntlTestDecimalFormatAPI::TestBadFastpath() { |
815 UErrorCode status = U_ZERO_ERROR; | 922 UErrorCode status = U_ZERO_ERROR; |
816 | 923 |
817 LocalPointer<DecimalFormat> df(new DecimalFormat("###", status)); | 924 LocalPointer<DecimalFormat> df(new DecimalFormat("###", status), status); |
818 if (U_FAILURE(status)) { | 925 if (U_FAILURE(status)) { |
819 dataerrln("Error creating new DecimalFormat - %s", u_errorName(status)); | 926 dataerrln("Error creating new DecimalFormat - %s", u_errorName(status)); |
820 return; | 927 return; |
821 } | 928 } |
822 | 929 |
823 UnicodeString fmt; | 930 UnicodeString fmt; |
824 fmt.remove(); | 931 fmt.remove(); |
825 assertEquals("Format 1234", "1234", df->format(1234, fmt)); | 932 assertEquals("Format 1234", "1234", df->format(1234, fmt)); |
826 df->setGroupingUsed(FALSE); | 933 df->setGroupingUsed(FALSE); |
827 fmt.remove(); | 934 fmt.remove(); |
828 assertEquals("Format 1234", "1234", df->format(1234, fmt)); | 935 assertEquals("Format 1234", "1234", df->format(1234, fmt)); |
829 df->setGroupingUsed(TRUE); | 936 df->setGroupingUsed(TRUE); |
| 937 df->setGroupingSize(3); |
830 fmt.remove(); | 938 fmt.remove(); |
831 assertEquals("Format 1234 w/ grouping", "1,234", df->format(1234, fmt)); | 939 assertEquals("Format 1234 w/ grouping", "1,234", df->format(1234, fmt)); |
832 } | 940 } |
833 | 941 |
834 void IntlTestDecimalFormatAPI::TestRequiredDecimalPoint() { | 942 void IntlTestDecimalFormatAPI::TestRequiredDecimalPoint() { |
835 UErrorCode status = U_ZERO_ERROR; | 943 UErrorCode status = U_ZERO_ERROR; |
836 UnicodeString text("99"); | 944 UnicodeString text("99"); |
837 Formattable result1; | 945 Formattable result1; |
838 UnicodeString pat1("##.0000"); | 946 UnicodeString pat1("##.0000"); |
839 UnicodeString pat2("00.0"); | 947 UnicodeString pat2("00.0"); |
840 | 948 |
841 LocalPointer<DecimalFormat> df(new DecimalFormat(pat1, status)); | 949 LocalPointer<DecimalFormat> df(new DecimalFormat(pat1, status), status); |
842 if (U_FAILURE(status)) { | 950 if (U_FAILURE(status)) { |
843 dataerrln("Error creating new DecimalFormat - %s", u_errorName(status)); | 951 dataerrln("Error creating new DecimalFormat - %s", u_errorName(status)); |
844 return; | 952 return; |
845 } | 953 } |
846 | 954 |
847 status = U_ZERO_ERROR; | 955 status = U_ZERO_ERROR; |
848 df->applyPattern(pat1, status); | 956 df->applyPattern(pat1, status); |
849 if(U_FAILURE(status)) { | 957 if(U_FAILURE(status)) { |
850 errln((UnicodeString)"ERROR: applyPattern() failed"); | 958 errln((UnicodeString)"ERROR: applyPattern() failed"); |
851 } | 959 } |
(...skipping 19 matching lines...) Expand all Loading... |
871 errln((UnicodeString)"ERROR: parse(2) failed - " + u_errorName(status)); | 979 errln((UnicodeString)"ERROR: parse(2) failed - " + u_errorName(status)); |
872 } | 980 } |
873 df->setDecimalPatternMatchRequired(TRUE); | 981 df->setDecimalPatternMatchRequired(TRUE); |
874 df->parse(text, result1, status); | 982 df->parse(text, result1, status); |
875 if(U_SUCCESS(status)) { | 983 if(U_SUCCESS(status)) { |
876 errln((UnicodeString)"ERROR: unexpected parse(2)"); | 984 errln((UnicodeString)"ERROR: unexpected parse(2)"); |
877 } | 985 } |
878 } | 986 } |
879 | 987 |
880 #endif /* #if !UCONFIG_NO_FORMATTING */ | 988 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |