From: Shane Carr Date: Wed, 27 Sep 2017 02:16:44 +0000 (+0000) Subject: ICU-13177 NumberFormatter tests are building. X-Git-Tag: release-60-rc~98^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a88300f2735b416d53d206c06f400271fcd379d6;p=icu ICU-13177 NumberFormatter tests are building. X-SVN-Rev: 40466 --- diff --git a/icu4c/source/common/unicode/simpleformatter.h b/icu4c/source/common/unicode/simpleformatter.h index c74bd414890..850949caaf5 100644 --- a/icu4c/source/common/unicode/simpleformatter.h +++ b/icu4c/source/common/unicode/simpleformatter.h @@ -21,6 +21,13 @@ 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 diff --git a/icu4c/source/i18n/number_modifiers.cpp b/icu4c/source/i18n/number_modifiers.cpp index 6f1eae10f32..98cc894da66 100644 --- a/icu4c/source/i18n/number_modifiers.cpp +++ b/icu4c/source/i18n/number_modifiers.cpp @@ -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; diff --git a/icu4c/source/i18n/number_patternmodifier.cpp b/icu4c/source/i18n/number_patternmodifier.cpp index 040a572e179..0874c83ed18 100644 --- a/icu4c/source/i18n/number_patternmodifier.cpp +++ b/icu4c/source/i18n/number_patternmodifier.cpp @@ -307,7 +307,7 @@ void MutablePatternModifier::enterCharSequenceMode(bool isPrefix) { } void MutablePatternModifier::exitCharSequenceMode() { - U_ASSERT(inCharSequenceMode) + U_ASSERT(inCharSequenceMode); inCharSequenceMode = false; } diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in index 0527a4b050d..d41ef25f521 100644 --- a/icu4c/source/test/intltest/Makefile.in +++ b/icu4c/source/test/intltest/Makefile.in @@ -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) diff --git a/icu4c/source/test/intltest/itformat.cpp b/icu4c/source/test/intltest/itformat.cpp index 21092659a78..6059930b7d0 100644 --- a/icu4c/source/test/intltest/itformat.cpp +++ b/icu4c/source/test/intltest/itformat.cpp @@ -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 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) { diff --git a/icu4c/source/test/intltest/numbertest.h b/icu4c/source/test/intltest/numbertest.h index 1b377952203..9848e5fd4dc 100644 --- a/icu4c/source/test/intltest/numbertest.h +++ b/icu4c/source/test/intltest/numbertest.h @@ -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); diff --git a/icu4c/source/test/intltest/numbertest_api.cpp b/icu4c/source/test/intltest/numbertest_api.cpp index ec2fb98f934..905867afab4 100644 --- a/icu4c/source/test/intltest/numbertest_api.cpp +++ b/icu4c/source/test/intltest/numbertest_api.cpp @@ -5,115 +5,76 @@ #include #include -#include -#include -#include "temp_test_helpers.h" +#include "unicode/unum.h" #include "unicode/numberformatter.h" #include "number_types.h" +#include "numbertest.h" -#include -#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(); -} diff --git a/icu4c/source/test/intltest/numbertest_decimalquantity.cpp b/icu4c/source/test/intltest/numbertest_decimalquantity.cpp index 670ecb30356..94dd384260e 100644 --- a/icu4c/source/test/intltest/numbertest_decimalquantity.cpp +++ b/icu4c/source/test/intltest/numbertest_decimalquantity.cpp @@ -4,43 +4,18 @@ #include "number_decimalquantity.h" #include "math.h" #include - -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, ""); fq.roundToInfinity(); assertToStringAndHealth(fq, ""); - fq.roundToIncrement(0.005, RoundingMode::kRoundHalfEven, status); + fq.roundToIncrement(0.005, RoundingMode::UNUM_ROUND_HALFEVEN, status); assertSuccess("Rounding to increment", status); assertToStringAndHealth(fq, ""); - fq.roundToMagnitude(-2, RoundingMode::kRoundHalfEven, status); + fq.roundToMagnitude(-2, RoundingMode::UNUM_ROUND_HALFEVEN, status); assertSuccess("Rounding to magnitude", status); assertToStringAndHealth(fq, ""); } @@ -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) { diff --git a/icu4c/source/test/intltest/numbertest_modifiers.cpp b/icu4c/source/test/intltest/numbertest_modifiers.cpp index 8d57b5f772b..8df30565454 100644 --- a/icu4c/source/test/intltest/numbertest_modifiers.cpp +++ b/icu4c/source/test/intltest/numbertest_modifiers.cpp @@ -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) { diff --git a/icu4c/source/test/intltest/numbertest_patternmodifier.cpp b/icu4c/source/test/intltest/numbertest_patternmodifier.cpp index 9cdce1f6510..b3ad038d1ce 100644 --- a/icu4c/source/test/intltest/numbertest_patternmodifier.cpp +++ b/icu4c/source/test/intltest/numbertest_patternmodifier.cpp @@ -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); diff --git a/icu4c/source/test/intltest/numbertest_patternstring.cpp b/icu4c/source/test/intltest/numbertest_patternstring.cpp index c92b95adfdb..7efd938094f 100644 --- a/icu4c/source/test/intltest/numbertest_patternstring.cpp +++ b/icu4c/source/test/intltest/numbertest_patternstring.cpp @@ -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",