]> granicus.if.org Git - icu/commitdiff
ICU-13177 NumberFormatter tests are building.
authorShane Carr <shane@unicode.org>
Wed, 27 Sep 2017 02:16:44 +0000 (02:16 +0000)
committerShane Carr <shane@unicode.org>
Wed, 27 Sep 2017 02:16:44 +0000 (02:16 +0000)
X-SVN-Rev: 40466

icu4c/source/common/unicode/simpleformatter.h
icu4c/source/i18n/number_modifiers.cpp
icu4c/source/i18n/number_patternmodifier.cpp
icu4c/source/test/intltest/Makefile.in
icu4c/source/test/intltest/itformat.cpp
icu4c/source/test/intltest/numbertest.h
icu4c/source/test/intltest/numbertest_api.cpp
icu4c/source/test/intltest/numbertest_decimalquantity.cpp
icu4c/source/test/intltest/numbertest_modifiers.cpp
icu4c/source/test/intltest/numbertest_patternmodifier.cpp
icu4c/source/test/intltest/numbertest_patternstring.cpp

index c74bd414890967e2886ef5e43215f4a5254ce41e..850949caaf5cda32bd438f4728a7de9d01e85ae5 100644 (file)
 
 U_NAMESPACE_BEGIN
 
+// Forward declaration:
+namespace number {
+namespace impl {
+class SimpleModifier;
+}
+}
+
 /**
  * Formats simple patterns like "{1} was born in {0}".
  * Minimal subset of MessageFormat; fast, simple, minimal dependencies.
@@ -261,15 +268,6 @@ public:
         return getTextWithNoArguments(compiledPattern.getBuffer(), compiledPattern.length());
     }
 
-    /**
-     * Gets the internal compiled pattern string.
-     * @internal
-     * @deprecated ICU 60 This API is ICU internal only.
-     */
-    UnicodeString getCompiledPattern() const {
-        return compiledPattern;
-    }
-
 private:
     /**
      * Binary representation of the compiled pattern.
@@ -295,6 +293,9 @@ private:
             UnicodeString &result, const UnicodeString *resultCopy, UBool forbidResultAsValue,
             int32_t *offsets, int32_t offsetsLength,
             UErrorCode &errorCode);
+
+    // Give access to internals to SimpleModifier for number formatting
+    friend class number::impl::SimpleModifier;
 };
 
 U_NAMESPACE_END
index 6f1eae10f322335c21128ee2f17ed9e84c42b218..98cc894da6618252f7327b5df471c7ec7c6408f1 100644 (file)
@@ -67,9 +67,9 @@ bool ConstantAffixModifier::isStrong() const {
 }
 
 SimpleModifier::SimpleModifier(const SimpleFormatter &simpleFormatter, Field field, bool strong)
-        : fCompiledPattern(simpleFormatter.getCompiledPattern()), fField(field), fStrong(strong) {
+        : fCompiledPattern(simpleFormatter.compiledPattern), fField(field), fStrong(strong) {
     U_ASSERT(1 ==
-             SimpleFormatter::getArgumentLimit(compiledPattern.getBuffer(), compiledPattern.length()));
+             SimpleFormatter::getArgumentLimit(fCompiledPattern.getBuffer(), fCompiledPattern.length()));
     if (fCompiledPattern.charAt(1) != 0) {
         fPrefixLength = fCompiledPattern.charAt(1) - ARG_NUM_LIMIT;
         fSuffixOffset = 3 + fPrefixLength;
index 040a572e1799c6ab0ea81e71d921f84194c689f1..0874c83ed18f0a4673d2c9d16bc1990fec02631d 100644 (file)
@@ -307,7 +307,7 @@ void MutablePatternModifier::enterCharSequenceMode(bool isPrefix) {
 }
 
 void MutablePatternModifier::exitCharSequenceMode() {
-    U_ASSERT(inCharSequenceMode)
+    U_ASSERT(inCharSequenceMode);
     inCharSequenceMode = false;
 }
 
index 0527a4b050d963d3224f7ac181371d1616bc6072..d41ef25f52159b73d9faac5f693994bd64a20625 100644 (file)
@@ -62,10 +62,9 @@ tufmtts.o itspoof.o simplethread.o bidiconf.o locnmtst.o dcfmtest.o alphaindexts
 reldatefmttest.o simpleformattertest.o measfmttest.o numfmtspectest.o unifiedcachetest.o quantityformattertest.o \
 scientificnumberformattertest.o datadrivennumberformattestsuite.o \
 numberformattesttuple.o numberformat2test.o pluralmaptest.o \
-numbertest_affixutils.o numbertest_stringbuilder.o
-# FIXME
-#numbertest_api.o numbertest_decimalquantity.o \
-#numbertest_modifiers.o numbertest_patternmodifier.o numbertest_patternstring.o \
+numbertest_affixutils.o numbertest_api.o numbertest_decimalquantity.o \
+numbertest_modifiers.o numbertest_patternmodifier.o numbertest_patternstring.o \
+numbertest_stringbuilder.o
 
 DEPS = $(OBJECTS:.o=.d)
 
index 21092659a78508f6a18b9dcd6e90507d874b4644..6059930b7d0ffbd79b35a69d83a57f124cb4d01c 100644 (file)
@@ -214,7 +214,7 @@ void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &nam
             callTest(*test, par);
           }
           break;
-        case 50: 
+        case 50:
           name = "NumberFormat2Test"; 
           if (exec) { 
             logln("NumberFormat2Test test---"); 
@@ -222,9 +222,14 @@ void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &nam
             LocalPointer<IntlTest> test(createNumberFormat2Test()); 
             callTest(*test, par); 
           } 
-          break; 
+          break;
         TESTCLASS(51,AffixUtilsTest);
-        TESTCLASS(52,NumberStringBuilderTest);
+        TESTCLASS(52,NumberFormatterApiTest);
+        TESTCLASS(53,DecimalQuantityTest);
+        TESTCLASS(54,ModifiersTest);
+        TESTCLASS(55,PatternModifierTest);
+        TESTCLASS(56,PatternStringTest);
+        TESTCLASS(57,NumberStringBuilderTest);
         default: name = ""; break; //needed to end loop
     }
     if (exec) {
index 1b377952203b49c77ec94771e13a81406f301b8a..9848e5fd4dce1810acff6ea47121c6b650284f96 100644 (file)
@@ -13,13 +13,9 @@ using namespace icu::number::impl;
 class AffixUtilsTest : public IntlTest {
   public:
     void testEscape();
-
     void testUnescape();
-
     void testContainsReplaceType();
-
     void testInvalid();
-
     void testUnescapeWithSymbolProvider();
 
     void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
@@ -29,18 +25,128 @@ class AffixUtilsTest : public IntlTest {
                                        UErrorCode &status);
 };
 
+class NumberFormatterApiTest : public IntlTest {
+  public:
+    NumberFormatterApiTest();
+    NumberFormatterApiTest(UErrorCode &status);
+
+    void notationSimple();
+    void notationScientific();
+    void notationCompact();
+    void unitMeasure();
+    void unitCurrency();
+    void unitPercent();
+    void roundingFraction();
+    void roundingFigures();
+    void roundingFractionFigures();
+    void roundingOther();
+    void grouping();
+    void padding();
+    void integerWidth();
+    void symbols();
+    // TODO: Add this method if currency symbols override support is added.
+    //void symbolsOverride();
+    void sign();
+    void decimal();
+    void locale();
+    void errors();
+
+    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+  private:
+    CurrencyUnit USD;
+    CurrencyUnit GBP;
+    CurrencyUnit CZK;
+    CurrencyUnit CAD;
+
+    MeasureUnit METER;
+    MeasureUnit DAY;
+    MeasureUnit SQUARE_METER;
+    MeasureUnit FAHRENHEIT;
+
+    NumberingSystem MATHSANB;
+    NumberingSystem LATN;
+
+    DecimalFormatSymbols FRENCH_SYMBOLS;
+    DecimalFormatSymbols SWISS_SYMBOLS;
+    DecimalFormatSymbols MYANMAR_SYMBOLS;
+
+    void assertFormatDescending(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
+                                Locale locale, ...);
+
+    void assertFormatDescendingBig(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
+                                   Locale locale, ...);
+
+    void assertFormatSingle(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
+                            Locale locale, double input, const UnicodeString &expected);
+};
+
+class DecimalQuantityTest : public IntlTest {
+  public:
+    void testDecimalQuantityBehaviorStandalone();
+    void testSwitchStorage();
+    void testAppend();
+    void testConvertToAccurateDouble();
+    void testUseApproximateDoubleWhenAble();
+
+    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+  private:
+    void assertDoubleEquals(const char *message, double a, double b);
+    void assertHealth(const DecimalQuantity &fq);
+    void assertToStringAndHealth(const DecimalQuantity &fq, const UnicodeString &expected);
+    void checkDoubleBehavior(double d, bool explicitRequired);
+};
+
+class ModifiersTest : public IntlTest {
+  public:
+    void testConstantAffixModifier();
+    void testConstantMultiFieldModifier();
+    void testSimpleModifier();
+    void testCurrencySpacingEnabledModifier();
+
+    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+  private:
+    void assertModifierEquals(const Modifier &mod, int32_t expectedPrefixLength, bool expectedStrong,
+                              UnicodeString expectedChars, UnicodeString expectedFields,
+                              UErrorCode &status);
+
+    void assertModifierEquals(const Modifier &mod, NumberStringBuilder &sb, int32_t expectedPrefixLength,
+                              bool expectedStrong, UnicodeString expectedChars,
+                              UnicodeString expectedFields, UErrorCode &status);
+};
+
+class PatternModifierTest : public IntlTest {
+  public:
+    void testBasic();
+    void testMutableEqualsImmutable();
+
+    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+  private:
+    UnicodeString getPrefix(const MutablePatternModifier &mod, UErrorCode &status);
+    UnicodeString getSuffix(const MutablePatternModifier &mod, UErrorCode &status);
+};
+
+class PatternStringTest : public IntlTest {
+  public:
+    void testToPatternSimple();
+    void testExceptionOnInvalid();
+    void testBug13117();
+
+    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+  private:
+};
+
 class NumberStringBuilderTest : public IntlTest {
   public:
     void testInsertAppendUnicodeString();
-
     void testInsertAppendCodePoint();
-
     void testCopy();
-
     void testFields();
-
     void testUnlimitedCapacity();
-
     void testCodePoints();
 
     void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
index ec2fb98f9348711e30e456d9b04ade5ea8886fde..905867afab49d7d0195c30fd09f52ccfba2a4a8b 100644 (file)
 
 #include <charstr.h>
 #include <cstdarg>
-#include <unicode/unum.h>
-#include <unicode/uclean.h>
-#include "temp_test_helpers.h"
+#include "unicode/unum.h"
 #include "unicode/numberformatter.h"
 #include "number_types.h"
+#include "numbertest.h"
 
-#include <iostream>
-#include "unicode/ustream.h"
-
-using namespace icu;
-using namespace icu::number;
-using namespace icu::number::impl;
-
-class numbertest_api {
-  public:
-    explicit numbertest_api(UErrorCode &status) : USD(u"USD", status), GBP(u"GBP", status),
-                                                       CZK(u"CZK", status), CAD(u"CAD", status),
-                                                       FRENCH_SYMBOLS(Locale::getFrench(), status),
-                                                       SWISS_SYMBOLS(Locale("de-CH"), status),
-                                                       MYANMAR_SYMBOLS(Locale("my"), status) {
-        MeasureUnit *unit = MeasureUnit::createMeter(status);
-        METER = *unit;
-        delete unit;
-        unit = MeasureUnit::createDay(status);
-        DAY = *unit;
-        delete unit;
-        unit = MeasureUnit::createSquareMeter(status);
-        SQUARE_METER = *unit;
-        delete unit;
-        unit = MeasureUnit::createFahrenheit(status);
-        FAHRENHEIT = *unit;
-        delete unit;
-
-        NumberingSystem *ns = NumberingSystem::createInstanceByName("mathsanb", status);
-        MATHSANB = *ns;
-        delete ns;
-        ns = NumberingSystem::createInstanceByName("latn", status);
-        LATN = *ns;
-        delete ns;
-    }
-
-    void notationSimple();
-
-    void notationScientific();
-
-    void notationCompact();
-
-    void unitMeasure();
-
-    void unitCurrency();
-
-    void unitPercent();
-
-    void roundingFraction();
-
-    void roundingFigures();
-
-    void roundingFractionFigures();
-
-    void roundingOther();
-
-    void grouping();
-
-    void padding();
-
-    void integerWidth();
-
-    void symbols();
-
-    // TODO: Add this method if currency symbols override support is added.
-    //void symbolsOverride();
+// Horrible workaround for the lack of a status code in the constructor...
+UErrorCode globalNumberFormatterApiTestStatus = U_ZERO_ERROR;
 
-    void sign();
-
-    void decimal();
-
-    void locale();
-
-    void errors();
-
-  private:
-    CurrencyUnit USD;
-    CurrencyUnit GBP;
-    CurrencyUnit CZK;
-    CurrencyUnit CAD;
-
-    MeasureUnit METER;
-    MeasureUnit DAY;
-    MeasureUnit SQUARE_METER;
-    MeasureUnit FAHRENHEIT;
-
-    NumberingSystem MATHSANB;
-    NumberingSystem LATN;
-
-    DecimalFormatSymbols FRENCH_SYMBOLS;
-    DecimalFormatSymbols SWISS_SYMBOLS;
-    DecimalFormatSymbols MYANMAR_SYMBOLS;
-
-    void assertFormatDescending(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
-                                const Locale &locale, ...);
+NumberFormatterApiTest::NumberFormatterApiTest()
+        : NumberFormatterApiTest(globalNumberFormatterApiTestStatus) {
+    U_ASSERT(U_SUCCESS(globalNumberFormatterApiTestStatus));
+}
 
-    void assertFormatDescendingBig(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
-                                   const Locale &locale, ...);
+NumberFormatterApiTest::NumberFormatterApiTest(UErrorCode &status)
+              : USD(u"USD", status), GBP(u"GBP", status),
+                CZK(u"CZK", status), CAD(u"CAD", status),
+                FRENCH_SYMBOLS(Locale::getFrench(), status),
+                SWISS_SYMBOLS(Locale("de-CH"), status),
+                MYANMAR_SYMBOLS(Locale("my"), status) {
+
+    MeasureUnit *unit = MeasureUnit::createMeter(status);
+    METER = *unit;
+    delete unit;
+    unit = MeasureUnit::createDay(status);
+    DAY = *unit;
+    delete unit;
+    unit = MeasureUnit::createSquareMeter(status);
+    SQUARE_METER = *unit;
+    delete unit;
+    unit = MeasureUnit::createFahrenheit(status);
+    FAHRENHEIT = *unit;
+    delete unit;
+
+    NumberingSystem *ns = NumberingSystem::createInstanceByName("mathsanb", status);
+    MATHSANB = *ns;
+    delete ns;
+    ns = NumberingSystem::createInstanceByName("latn", status);
+    LATN = *ns;
+    delete ns;
+}
 
-    void assertFormatSingle(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
-                            const Locale &locale, double input, const UnicodeString &expected);
-};
+void NumberFormatterApiTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
+    if (exec) {
+        logln("TestSuite NumberFormatterApiTest: ");
+    }
+    TESTCASE_AUTO_BEGIN;
+        TESTCASE_AUTO(notationSimple);
+        TESTCASE_AUTO(notationScientific);
+        TESTCASE_AUTO(notationCompact);
+        TESTCASE_AUTO(unitMeasure);
+        TESTCASE_AUTO(unitCurrency);
+        TESTCASE_AUTO(unitPercent);
+        TESTCASE_AUTO(roundingFraction);
+        TESTCASE_AUTO(roundingFigures);
+        TESTCASE_AUTO(roundingFractionFigures);
+        TESTCASE_AUTO(roundingOther);
+        TESTCASE_AUTO(grouping);
+        TESTCASE_AUTO(padding);
+        TESTCASE_AUTO(integerWidth);
+        TESTCASE_AUTO(symbols);
+        // TODO: Add this method if currency symbols override support is added.
+        //TESTCASE_AUTO(symbolsOverride);
+        TESTCASE_AUTO(sign);
+        TESTCASE_AUTO(decimal);
+        TESTCASE_AUTO(locale);
+        TESTCASE_AUTO(errors);
+    TESTCASE_AUTO_END;
+}
 
-void numbertest_api::notationSimple() {
+void NumberFormatterApiTest::notationSimple() {
     assertFormatDescending(
             u"Basic",
             NumberFormatter::with(),
@@ -137,7 +98,7 @@ void numbertest_api::notationSimple() {
 }
 
 
-void numbertest_api::notationScientific() {
+void NumberFormatterApiTest::notationScientific() {
     assertFormatDescending(
             u"Scientific",
             NumberFormatter::with().notation(Notation::scientific()),
@@ -203,7 +164,7 @@ void numbertest_api::notationScientific() {
             u"-1E6");
 }
 
-void numbertest_api::notationCompact() {
+void NumberFormatterApiTest::notationCompact() {
     assertFormatDescending(
             u"Compact Short",
             NumberFormatter::with().notation(Notation::compactShort()),
@@ -386,7 +347,7 @@ void numbertest_api::notationCompact() {
             u"10M");
 }
 
-void numbertest_api::unitMeasure() {
+void NumberFormatterApiTest::unitMeasure() {
     assertFormatDescending(
             u"Meters Short",
             NumberFormatter::with().adoptUnit(new MeasureUnit(METER)),
@@ -502,7 +463,7 @@ void numbertest_api::unitMeasure() {
             u"5.43 °F");
 }
 
-void numbertest_api::unitCurrency() {
+void NumberFormatterApiTest::unitCurrency() {
     assertFormatDescending(
             u"Currency",
             NumberFormatter::with().unit(GBP),
@@ -582,7 +543,7 @@ void numbertest_api::unitCurrency() {
             u"-£9,876,543.21");
 }
 
-void numbertest_api::unitPercent() {
+void NumberFormatterApiTest::unitPercent() {
     assertFormatDescending(
             u"Percent",
             NumberFormatter::with().unit(NoUnit::percent()),
@@ -626,7 +587,7 @@ void numbertest_api::unitPercent() {
             u"-98.765432%");
 }
 
-void numbertest_api::roundingFraction() {
+void NumberFormatterApiTest::roundingFraction() {
     assertFormatDescending(
             u"Integer",
             NumberFormatter::with().rounding(Rounder::integer()),
@@ -698,7 +659,7 @@ void numbertest_api::roundingFraction() {
             u"0.0");
 }
 
-void numbertest_api::roundingFigures() {
+void NumberFormatterApiTest::roundingFigures() {
     assertFormatSingle(
             u"Fixed Significant",
             NumberFormatter::with().rounding(Rounder::fixedDigits(3)),
@@ -742,7 +703,7 @@ void numbertest_api::roundingFigures() {
             u"10.0");
 }
 
-void numbertest_api::roundingFractionFigures() {
+void NumberFormatterApiTest::roundingFractionFigures() {
     assertFormatDescending(
             u"Basic Significant", // for comparison
             NumberFormatter::with().rounding(Rounder::maxDigits(2)),
@@ -800,7 +761,7 @@ void numbertest_api::roundingFractionFigures() {
             u"0.00");
 }
 
-void numbertest_api::roundingOther() {
+void NumberFormatterApiTest::roundingOther() {
     assertFormatDescending(
             u"Rounding None",
             NumberFormatter::with().rounding(Rounder::unlimited()),
@@ -919,7 +880,7 @@ void numbertest_api::roundingOther() {
             u"0");
 }
 
-void numbertest_api::grouping() {
+void NumberFormatterApiTest::grouping() {
     assertFormatDescendingBig(
             u"Western Grouping",
             NumberFormatter::with().grouping(Grouper::defaults()),
@@ -991,7 +952,7 @@ void numbertest_api::grouping() {
             u"0");
 }
 
-void numbertest_api::padding() {
+void NumberFormatterApiTest::padding() {
     assertFormatDescending(
             u"Padding",
             NumberFormatter::with().padding(Padder::none()),
@@ -1121,7 +1082,7 @@ void numbertest_api::padding() {
             u"GBP 000514.23"); // TODO: This is broken; it renders too wide (13 instead of 12).
 }
 
-void numbertest_api::integerWidth() {
+void NumberFormatterApiTest::integerWidth() {
     assertFormatDescending(
             u"Integer Width Default",
             NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(1)),
@@ -1193,7 +1154,7 @@ void numbertest_api::integerWidth() {
             u"00");
 }
 
-void numbertest_api::symbols() {
+void NumberFormatterApiTest::symbols() {
     assertFormatDescending(
             u"French Symbols with Japanese Data 1",
             NumberFormatter::with().symbols(FRENCH_SYMBOLS),
@@ -1322,7 +1283,7 @@ void numbertest_api::symbols() {
 //            u"@ 12.30");
 //}
 
-void numbertest_api::sign() {
+void NumberFormatterApiTest::sign() {
     assertFormatSingle(
             u"Sign Auto Positive",
             NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
@@ -1403,7 +1364,7 @@ void numbertest_api::sign() {
             u"(444,444.00)");
 }
 
-void numbertest_api::decimal() {
+void NumberFormatterApiTest::decimal() {
     assertFormatDescending(
             u"Decimal Default",
             NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_AUTO),
@@ -1433,7 +1394,7 @@ void numbertest_api::decimal() {
             u"0.");
 }
 
-void numbertest_api::locale() {
+void NumberFormatterApiTest::locale() {
     // Coverage for the locale setters.
     UErrorCode status = U_ZERO_ERROR;
     UnicodeString actual = NumberFormatter::withLocale(Locale::getFrench()).formatInt(1234, status)
@@ -1441,7 +1402,7 @@ void numbertest_api::locale() {
     assertEquals("Locale withLocale()", u"1 234", actual);
 }
 
-void numbertest_api::errors() {
+void NumberFormatterApiTest::errors() {
     LocalizedNumberFormatter lnf = NumberFormatter::withLocale(Locale::getEnglish()).rounding(
             Rounder::fixedFraction(
                     -1));
@@ -1466,11 +1427,10 @@ void numbertest_api::errors() {
 }
 
 
-void numbertest_api::assertFormatDescending(const UnicodeString &message,
+void NumberFormatterApiTest::assertFormatDescending(const UnicodeString &message,
                                                  const UnlocalizedNumberFormatter &f,
-                                                 const Locale &locale, ...) {
+                                                 Locale locale, ...) {
     va_list args;
-    // TODO: Fix this? "warning: 'va_start' has undefined behavior with reference types [-Wvarargs]"
     va_start(args, locale);
     static double inputs[] = {87650, 8765, 876.5, 87.65, 8.765, 0.8765, 0.08765, 0.008765, 0};
     const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
@@ -1489,11 +1449,10 @@ void numbertest_api::assertFormatDescending(const UnicodeString &message,
     }
 }
 
-void numbertest_api::assertFormatDescendingBig(const UnicodeString &message,
+void NumberFormatterApiTest::assertFormatDescendingBig(const UnicodeString &message,
                                                     const UnlocalizedNumberFormatter &f,
-                                                    const Locale &locale, ...) {
+                                                    Locale locale, ...) {
     va_list args;
-    // TODO: Fix this? "warning: 'va_start' has undefined behavior with reference types [-Wvarargs]"
     va_start(args, locale);
     static double inputs[] = {87650000, 8765000, 876500, 87650, 8765, 876.5, 87.65, 8.765, 0};
     const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
@@ -1512,8 +1471,8 @@ void numbertest_api::assertFormatDescendingBig(const UnicodeString &message,
     }
 }
 
-void numbertest_api::assertFormatSingle(const UnicodeString &message,
-                                             const UnlocalizedNumberFormatter &f, const Locale &locale,
+void NumberFormatterApiTest::assertFormatSingle(const UnicodeString &message,
+                                             const UnlocalizedNumberFormatter &f, Locale locale,
                                              double input, const UnicodeString &expected) {
     const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
     const LocalizedNumberFormatter l2 = f.threshold(1).locale(locale); // all self-regulation
@@ -1525,28 +1484,3 @@ void numbertest_api::assertFormatSingle(const UnicodeString &message,
     assertSuccess(message + u": Safe Path", status);
     assertEquals(message + u": Safe Path", expected, actual2);
 }
-
-int main() {
-    UErrorCode status = U_ZERO_ERROR;
-    numbertest_api test(status);
-    test.notationSimple();
-    test.notationScientific();
-    test.notationCompact();
-    test.unitMeasure();
-    test.unitCurrency();
-    test.unitPercent();
-    test.roundingFraction();
-    test.roundingFigures();
-    test.roundingFractionFigures();
-    test.roundingOther();
-    test.grouping();
-    test.padding();
-    test.integerWidth();
-    test.symbols();
-    test.sign();
-    test.decimal();
-    test.locale();
-    test.errors();
-
-    u_cleanup();
-}
index 670ecb30356bad95216e094491cadd23361579b0..94dd384260e89664c3436614565c30a3fa9780a1 100644 (file)
@@ -4,43 +4,18 @@
 #include "number_decimalquantity.h"
 #include "math.h"
 #include <cmath>
-
-using namespace icu::number::impl;
-
-class DecimalQuantityTest : public IntlTest {
-  public:
-    void testDecimalQuantityBehaviorStandalone();
-
-    void testSwitchStorage();
-
-    void testAppend();
-
-    void testConvertToAccurateDouble();
-
-    void testUseApproximateDoubleWhenAble();
-
-    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
-
-  private:
-    void assertDoubleEquals(const char *message, double a, double b);
-
-    void assertHealth(const DecimalQuantity &fq);
-
-    void assertToStringAndHealth(const DecimalQuantity &fq, const UnicodeString &expected);
-
-    void checkDoubleBehavior(double d, bool explicitRequired);
-};
+#include "numbertest.h"
 
 void DecimalQuantityTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
     if (exec) {
         logln("TestSuite DecimalQuantityTest: ");
     }
     TESTCASE_AUTO_BEGIN;
-    TESTCASE_AUTO(testDecimalQuantityBehaviorStandalone);
-    TESTCASE_AUTO(testSwitchStorage);
-    TESTCASE_AUTO(testAppend);
-    TESTCASE_AUTO(testConvertToAccurateDouble);
-    TESTCASE_AUTO(testUseApproximateDoubleWhenAble);
+        TESTCASE_AUTO(testDecimalQuantityBehaviorStandalone);
+        TESTCASE_AUTO(testSwitchStorage);
+        TESTCASE_AUTO(testAppend);
+        TESTCASE_AUTO(testConvertToAccurateDouble);
+        TESTCASE_AUTO(testUseApproximateDoubleWhenAble);
     TESTCASE_AUTO_END;
 }
 
@@ -103,10 +78,10 @@ void DecimalQuantityTest::testDecimalQuantityBehaviorStandalone() {
     assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987654321E-6>");
     fq.roundToInfinity();
     assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987654321E-6>");
-    fq.roundToIncrement(0.005, RoundingMode::kRoundHalfEven, status);
+    fq.roundToIncrement(0.005, RoundingMode::UNUM_ROUND_HALFEVEN, status);
     assertSuccess("Rounding to increment", status);
     assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987655E-3>");
-    fq.roundToMagnitude(-2, RoundingMode::kRoundHalfEven, status);
+    fq.roundToMagnitude(-2, RoundingMode::UNUM_ROUND_HALFEVEN, status);
     assertSuccess("Rounding to magnitude", status);
     assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 98766E-2>");
 }
@@ -125,7 +100,7 @@ void DecimalQuantityTest::testSwitchStorage() {
     assertEquals("Failed on multiply", "12341234123412345E0", fq.toNumberString());
     assertHealth(fq);
     // Bytes -> Long
-    fq.roundToMagnitude(5, RoundingMode::kRoundHalfEven, status);
+    fq.roundToMagnitude(5, RoundingMode::UNUM_ROUND_HALFEVEN, status);
     assertSuccess("Rounding to magnitude", status);
     assertFalse("Should not be using byte array", fq.isUsingBytes());
     assertEquals("Failed on round", "123412341234E5", fq.toNumberString());
@@ -253,18 +228,18 @@ void DecimalQuantityTest::testUseApproximateDoubleWhenAble() {
         int32_t maxFrac;
         RoundingMode roundingMode;
         bool usesExact;
-    } cases[] = {{1.2345678, 1, RoundingMode::kRoundHalfEven, false},
-                 {1.2345678, 7, RoundingMode::kRoundHalfEven, false},
-                 {1.2345678, 12, RoundingMode::kRoundHalfEven, false},
-                 {1.2345678, 13, RoundingMode::kRoundHalfEven, true},
-                 {1.235, 1, RoundingMode::kRoundHalfEven, false},
-                 {1.235, 2, RoundingMode::kRoundHalfEven, true},
-                 {1.235, 3, RoundingMode::kRoundHalfEven, false},
-                 {1.000000000000001, 0, RoundingMode::kRoundHalfEven, false},
-                 {1.000000000000001, 0, RoundingMode::kRoundCeiling, true},
-                 {1.235, 1, RoundingMode::kRoundCeiling, false},
-                 {1.235, 2, RoundingMode::kRoundCeiling, false},
-                 {1.235, 3, RoundingMode::kRoundCeiling, true}};
+    } cases[] = {{1.2345678, 1, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+                 {1.2345678, 7, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+                 {1.2345678, 12, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+                 {1.2345678, 13, RoundingMode::UNUM_ROUND_HALFEVEN, true},
+                 {1.235, 1, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+                 {1.235, 2, RoundingMode::UNUM_ROUND_HALFEVEN, true},
+                 {1.235, 3, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+                 {1.000000000000001, 0, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+                 {1.000000000000001, 0, RoundingMode::UNUM_ROUND_CEILING, true},
+                 {1.235, 1, RoundingMode::UNUM_ROUND_CEILING, false},
+                 {1.235, 2, RoundingMode::UNUM_ROUND_CEILING, false},
+                 {1.235, 3, RoundingMode::UNUM_ROUND_CEILING, true}};
 
     UErrorCode status = U_ZERO_ERROR;
     for (TestCase cas : cases) {
index 8d57b5f772b97b30e2248e22f959444606d2a1b0..8df305654540e6078de2416b2030f3e6a8b11be9 100644 (file)
@@ -5,30 +5,7 @@
 #include "intltest.h"
 #include "number_stringbuilder.h"
 #include "number_modifiers.h"
-
-using namespace icu::number::impl;
-
-class ModifiersTest : public IntlTest {
-  public:
-    void testConstantAffixModifier();
-
-    void testConstantMultiFieldModifier();
-
-    void testSimpleModifier();
-
-    void testCurrencySpacingEnabledModifier();
-
-    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
-
-  private:
-    void assertModifierEquals(const Modifier &mod, int32_t expectedPrefixLength, bool expectedStrong,
-                              UnicodeString expectedChars, UnicodeString expectedFields,
-                              UErrorCode &status);
-
-    void assertModifierEquals(const Modifier &mod, NumberStringBuilder &sb, int32_t expectedPrefixLength,
-                              bool expectedStrong, UnicodeString expectedChars,
-                              UnicodeString expectedFields, UErrorCode &status);
-};
+#include "numbertest.h"
 
 void ModifiersTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
     if (exec) {
index 9cdce1f65103f5177a2b7a75ba4d255d8e897cd6..b3ad038d1cee77a5cc2fdd5e4d43e0dc8dd9be3f 100644 (file)
@@ -1,19 +1,20 @@
 // © 2017 and later: Unicode, Inc. and others.
 // License & terms of use: http://www.unicode.org/copyright.html
 
-#include "intltest.h"
+#include "numbertest.h"
+#include "number_patternmodifier.h"
 
-class PatternStringTest : public IntlTest {
-  public:
-    testBasic();
-    testMutableEqualsImmutable();
-
-  private:
-    static UnicodeString getPrefix(const MutablePatternModifier &mod, UErrorCode &status);
-    static UnicodeString getSuffix(const MutablePatternModifier &mod, UErrorCode &status);
-};
+void PatternModifierTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
+    if (exec) {
+        logln("TestSuite PatternModifierTest: ");
+    }
+    TESTCASE_AUTO_BEGIN;
+        TESTCASE_AUTO(testBasic);
+        TESTCASE_AUTO(testMutableEqualsImmutable);
+    TESTCASE_AUTO_END;
+}
 
-void PatternStringTest::testBasic() {
+void PatternModifierTest::testBasic() {
     UErrorCode status = U_ZERO_ERROR;
     MutablePatternModifier mod(false);
     ParsedPatternInfo patternInfo;
@@ -63,7 +64,7 @@ void PatternStringTest::testBasic() {
     assertSuccess("Spot 5", status);
 }
 
-void PatternStringTest::testMutableEqualsImmutable() {
+void PatternModifierTest::testMutableEqualsImmutable() {
     UErrorCode status = U_ZERO_ERROR;
     MutablePatternModifier mod(false);
     ParsedPatternInfo patternInfo;
@@ -104,14 +105,14 @@ void PatternStringTest::testMutableEqualsImmutable() {
     assertFalse(nsb1.toUnicodeString() + " vs " + nsb3.toUnicodeString(), nsb1.contentEquals(nsb3));
 }
 
-static UnicodeString PatternStringTest::getPrefix(const MutablePatternModifier &mod, UErrorCode &status) {
+UnicodeString PatternModifierTest::getPrefix(const MutablePatternModifier &mod, UErrorCode &status) {
     NumberStringBuilder nsb;
     mod.apply(nsb, 0, 0, status);
     int32_t prefixLength = mod.getPrefixLength(status);
     return UnicodeString(nsb.toUnicodeString(), 0, prefixLength);
 }
 
-static UnicodeString PatternStringTest::getSuffix(const MutablePatternModifier &mod, UErrorCode &status) {
+UnicodeString PatternModifierTest::getSuffix(const MutablePatternModifier &mod, UErrorCode &status) {
     NumberStringBuilder nsb;
     mod.apply(nsb, 0, 0, status);
     int32_t prefixLength = mod.getPrefixLength(status);
index c92b95adfdb8d9d0df05bafd04137631313127a8..7efd938094f6844a9002c19b5b414f1f08e36c96 100644 (file)
@@ -1,7 +1,21 @@
 // © 2017 and later: Unicode, Inc. and others.
 // License & terms of use: http://www.unicode.org/copyright.html
 
-void testToPatternSimple() {
+#include "numbertest.h"
+#include "number_patternstring.h"
+
+void PatternStringTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
+    if (exec) {
+        logln("TestSuite PatternStringTest: ");
+    }
+    TESTCASE_AUTO_BEGIN;
+        TESTCASE_AUTO(testToPatternSimple);
+        TESTCASE_AUTO(testExceptionOnInvalid);
+        TESTCASE_AUTO(testBug13117);
+    TESTCASE_AUTO_END;
+}
+
+void PatternStringTest::testToPatternSimple() {
     const char16_t *cases[][2] = {{u"#", u"0"},
                                   {u"0", u"0"},
                                   {u"#0", u"0"},
@@ -36,7 +50,7 @@ void testToPatternSimple() {
     }
 }
 
-void testExceptionOnInvalid() {
+void PatternStringTest::testExceptionOnInvalid() {
     static const char16_t *invalidPatterns[] = {
             u"#.#.#",
             u"0#",
@@ -59,7 +73,7 @@ void testExceptionOnInvalid() {
     }
 }
 
-void testBug13117() {
+void PatternStringTest::testBug13117() {
     UErrorCode status = U_ZERO_ERROR;
     DecimalFormatProperties expected = PatternParser::parseToProperties(
             u"0",