1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
9 #include "number_stringbuilder.h"
11 #include "number_affixutils.h"
12 #include "numparse_stringsegment.h"
13 #include "unicode/locid.h"
15 using namespace icu::number
;
16 using namespace icu::number::impl
;
17 using namespace icu::numparse
;
18 using namespace icu::numparse::impl
;
20 ////////////////////////////////////////////////////////////////////////////////////////
22 // To add new NumberFormat unit test classes, create a new class like the ones below, //
23 // and then add it as a switch statement in NumberTest at the bottom of this file. /////////
24 // To add new methods to existing unit test classes, add the method to the class declaration //
25 // below, and also add it to the class's implementation of runIndexedTest(). //
26 ///////////////////////////////////////////////////////////////////////////////////////////////
28 class AffixUtilsTest
: public IntlTest
{
32 void testContainsReplaceType();
34 void testUnescapeWithSymbolProvider();
36 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
39 UnicodeString
unescapeWithDefaults(const SymbolProvider
&defaultProvider
, UnicodeString input
,
43 class NumberFormatterApiTest
: public IntlTest
{
45 NumberFormatterApiTest();
46 NumberFormatterApiTest(UErrorCode
&status
);
48 void notationSimple();
49 void notationScientific();
50 void notationCompact();
52 void unitCompoundMeasure();
55 void roundingFraction();
56 void roundingFigures();
57 void roundingFractionFigures();
63 // TODO: Add this method if currency symbols override support is added.
64 //void symbolsOverride();
75 void localPointerCAPI();
77 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
89 MeasureUnit SQUARE_METER
;
90 MeasureUnit FAHRENHEIT
;
93 MeasureUnit SQUARE_MILE
;
98 NumberingSystem MATHSANB
;
101 DecimalFormatSymbols FRENCH_SYMBOLS
;
102 DecimalFormatSymbols SWISS_SYMBOLS
;
103 DecimalFormatSymbols MYANMAR_SYMBOLS
;
105 void assertFormatDescending(const char16_t* message
, const char16_t* skeleton
,
106 const UnlocalizedNumberFormatter
& f
, Locale locale
, ...);
108 void assertFormatDescendingBig(const char16_t* message
, const char16_t* skeleton
,
109 const UnlocalizedNumberFormatter
& f
, Locale locale
, ...);
111 void assertFormatSingle(const char16_t* message
, const char16_t* skeleton
,
112 const UnlocalizedNumberFormatter
& f
, Locale locale
, double input
,
113 const UnicodeString
& expected
);
115 void assertUndefinedSkeleton(const UnlocalizedNumberFormatter
& f
);
118 class DecimalQuantityTest
: public IntlTest
{
120 void testDecimalQuantityBehaviorStandalone();
121 void testSwitchStorage();
124 void testConvertToAccurateDouble();
125 void testUseApproximateDoubleWhenAble();
126 void testHardDoubleConversion();
128 void testMaxDigits();
130 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
133 void assertDoubleEquals(UnicodeString message
, double a
, double b
);
134 void assertHealth(const DecimalQuantity
&fq
);
135 void assertToStringAndHealth(const DecimalQuantity
&fq
, const UnicodeString
&expected
);
136 void checkDoubleBehavior(double d
, bool explicitRequired
);
139 class DoubleConversionTest
: public IntlTest
{
141 void testDoubleConversionApi();
143 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
146 class ModifiersTest
: public IntlTest
{
148 void testConstantAffixModifier();
149 void testConstantMultiFieldModifier();
150 void testSimpleModifier();
151 void testCurrencySpacingEnabledModifier();
153 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
156 void assertModifierEquals(const Modifier
&mod
, int32_t expectedPrefixLength
, bool expectedStrong
,
157 UnicodeString expectedChars
, UnicodeString expectedFields
,
160 void assertModifierEquals(const Modifier
&mod
, NumberStringBuilder
&sb
, int32_t expectedPrefixLength
,
161 bool expectedStrong
, UnicodeString expectedChars
,
162 UnicodeString expectedFields
, UErrorCode
&status
);
165 class PatternModifierTest
: public IntlTest
{
168 void testPatternWithNoPlaceholder();
169 void testMutableEqualsImmutable();
171 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
174 UnicodeString
getPrefix(const MutablePatternModifier
&mod
, UErrorCode
&status
);
175 UnicodeString
getSuffix(const MutablePatternModifier
&mod
, UErrorCode
&status
);
178 class PatternStringTest
: public IntlTest
{
180 void testLocalized();
181 void testToPatternSimple();
182 void testExceptionOnInvalid();
185 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
190 class NumberStringBuilderTest
: public IntlTest
{
192 void testInsertAppendUnicodeString();
194 void testInsertAppendCodePoint();
197 void testUnlimitedCapacity();
198 void testCodePoints();
200 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
203 void assertEqualsImpl(const UnicodeString
&a
, const NumberStringBuilder
&b
);
206 class StringSegmentTest
: public IntlTest
{
211 void testGetCodePoint();
212 void testCommonPrefixLength();
214 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
217 class NumberParserTest
: public IntlTest
{
221 void testSeriesMatcher();
222 void testCombinedCurrencyMatcher();
223 void testAffixPatternMatcher();
224 void testGroupingDisabled();
225 void testCaseFolding();
227 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
230 class NumberSkeletonTest
: public IntlTest
{
233 void invalidTokens();
234 void unknownTokens();
235 void unexpectedTokens();
236 void duplicateValues();
237 void stemsRequiringOption();
238 void defaultTokens();
239 void flexibleSeparators();
241 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
244 void expectedErrorSkeleton(const char16_t** cases
, int32_t casesLen
);
248 // NOTE: This macro is identical to the one in itformat.cpp
249 #define TESTCLASS(id, TestClass) \
253 logln(#TestClass " test---"); \
254 logln((UnicodeString)""); \
256 callTest(test, par); \
260 class NumberTest
: public IntlTest
{
262 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0) {
264 logln("TestSuite NumberTest: ");
268 TESTCLASS(0, AffixUtilsTest
);
269 TESTCLASS(1, NumberFormatterApiTest
);
270 TESTCLASS(2, DecimalQuantityTest
);
271 TESTCLASS(3, ModifiersTest
);
272 TESTCLASS(4, PatternModifierTest
);
273 TESTCLASS(5, PatternStringTest
);
274 TESTCLASS(6, NumberStringBuilderTest
);
275 TESTCLASS(7, DoubleConversionTest
);
276 TESTCLASS(8, StringSegmentTest
);
277 TESTCLASS(9, NumberParserTest
);
278 TESTCLASS(10, NumberSkeletonTest
);
279 default: name
= ""; break; // needed to end loop
284 #endif /* #if !UCONFIG_NO_FORMATTING */