1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /************************************************************************
5 * Copyright (c) 1997-2016, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ************************************************************************/
9 #ifndef _NUMBERFORMATTEST_
10 #define _NUMBERFORMATTEST_
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_FORMATTING
16 #include "unicode/numfmt.h"
17 #include "unicode/decimfmt.h"
19 #include "datadrivennumberformattestsuite.h"
22 * Expected field positions from field position iterator. Tests should
23 * stack allocate an array of these making sure that the last element is
24 * {0, -1, 0} (The sentinel element indicating end of iterator). Then test
25 * should call verifyFieldPositionIterator() passing both this array of
26 * expected results and the field position iterator from the format method.
28 struct NumberFormatTest_Attributes
{
36 * Header for the data-driven test, powered by numberformattestspecification.txt
38 class NumberFormatDataDrivenTest
: public DataDrivenNumberFormatTestSuite
{
40 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
41 void TestNumberFormatTestTuple();
42 void TestDataDrivenICU4C();
46 const NumberFormatTestTuple
&tuple
,
47 UnicodeString
&appendErrorMessage
,
49 UBool
isToPatternPass(
50 const NumberFormatTestTuple
&tuple
,
51 UnicodeString
&appendErrorMessage
,
54 const NumberFormatTestTuple
&tuple
,
55 UnicodeString
&appendErrorMessage
,
57 UBool
isParseCurrencyPass(
58 const NumberFormatTestTuple
&tuple
,
59 UnicodeString
&appendErrorMessage
,
64 * Performs various in-depth test on NumberFormat
66 class NumberFormatTest
: public CalendarTimeZoneTest
{
69 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
73 * Test APIs (to increase code coverage)
77 void TestCoverage(void);
78 void TestLocalizedPatternSymbolCoverage();
81 * Test the handling of quotes
83 void TestQuotes(void);
85 * Test patterns with exponential representation
87 void TestExponential(void);
89 * Test handling of patterns with currency symbols
91 void TestCurrencySign(void);
93 * Test different format patterns
95 void TestPatterns(void);
97 * API coverage for DigitList
99 //void TestDigitList(void);
101 void Test20186_SpacesAroundSemicolon(void);
104 * Test localized currency patterns.
106 void TestCurrency(void);
109 * Test the Currency object handling, new as of ICU 2.2.
111 void TestCurrencyObject(void);
113 void TestCurrencyPatterns(void);
116 * Do rudimentary testing of parsing.
118 void TestParse(void);
120 * Test proper rounding by the format method.
122 void TestRounding487(void);
124 // New tests for alphaWorks upgrade
125 void TestExponent(void);
127 void TestScientific(void);
129 void TestScientific2(void);
131 void TestScientificGrouping(void);
133 void TestInt64(void);
135 void TestSurrogateSupport(void);
138 * Test the functioning of the secondary grouping value.
140 void TestSecondaryGrouping(void);
142 void TestWhiteSpaceParsing(void);
144 void TestComplexCurrency(void);
147 void TestPatterns2(void);
150 * Test currency registration.
152 void TestRegCurrency(void);
154 void TestCurrencyNames(void);
156 void Test20484_NarrowSymbolFallback(void);
158 void TestCurrencyAmount(void);
160 void TestCurrencyUnit(void);
162 void TestSymbolsWithBadLocale(void);
164 void TestAdoptDecimalFormatSymbols(void);
166 void TestPerMill(void);
168 void TestIllegalPatterns(void);
170 void TestCases(void);
172 void TestJB3832(void);
176 void TestHostClone(void);
178 void TestCurrencyFormat(void);
180 /* Port of ICU4J rounding test. */
181 void TestRounding(void);
183 void TestRoundingPattern(void);
185 void TestNonpositiveMultiplier(void);
187 void TestNumberingSystems();
190 void TestSpaceParsing();
191 void TestMultiCurrencySign();
192 void TestCurrencyFormatForMixParsing();
193 void TestMismatchedCurrencyFormatFail();
194 void TestDecimalFormatCurrencyParse();
195 void TestCurrencyIsoPluralFormat();
196 void TestCurrencyParsing();
197 void TestParseCurrencyInUCurr();
198 void TestFormatAttributes();
199 void TestFieldPositionIterator();
201 void TestLenientParse();
204 void TestCurrencyFractionDigits();
206 void TestExponentParse();
207 void TestExplicitParents();
208 void TestAvailableNumberingSystems();
210 void TestFormatFastpaths();
212 void TestFormattableSize();
214 void TestUFormattable();
218 void TestSignificantDigits();
221 void TestCompatibleCurrencies();
223 void TestParseNegativeWithFaLocale();
224 void TestParseNegativeWithAlternateMinusSign();
226 void TestCustomCurrencySignAndSeparator();
228 void TestParseSignsAndMarks();
229 void Test10419RoundingWith0FractionDigits();
230 void Test10468ApplyPattern();
231 void TestRoundingScientific10542();
232 void TestZeroScientific10547();
233 void TestAccountingCurrency();
236 void TestCurrencyUsage();
238 void TestDoubleLimit11439();
239 void TestFastPathConsistent11524();
240 void TestGetAffixes();
241 void TestToPatternScientific11648();
242 void TestBenchmark();
243 void TestCtorApplyPatternDifference();
244 void TestFractionalDigitsForCurrency();
245 void TestFormatCurrencyPlural();
247 void Test11739_ParseLongCurrency();
248 void Test13035_MultiCodePointPaddingInPattern();
249 void Test13737_ParseScientificStrict();
250 void Test10727_RoundingZero();
251 void Test11376_getAndSetPositivePrefix();
252 void Test11475_signRecognition();
253 void Test11640_getAffixes();
254 void Test11649_toPatternWithMultiCurrency();
255 void Test13327_numberingSystemBufferOverflow();
256 void Test13391_chakmaParsing();
258 void Test11735_ExceptionIssue();
259 void Test11035_FormatCurrencyAmount();
260 void Test11318_DoubleConversion();
261 void TestParsePercentRegression();
262 void TestMultiplierWithScale();
263 void TestFastFormatInt32();
264 void Test11646_Equality();
266 void TestFormatFailIfMoreThanMaxDigits();
267 void TestParseCaseSensitive();
268 void TestParseNoExponent();
269 void TestSignAlwaysShown();
270 void TestMinimumGroupingDigits();
271 void Test11897_LocalizedPatternSeparator();
272 void Test13055_PercentageRounding();
275 void Test11645_ApplyPatternEquality();
277 void Test11626_CustomizeCurrencyPluralInfo();
278 void Test20073_StrictPercentParseErrorIndex();
279 void Test13056_GroupingSize();
280 void Test11025_CurrencyPadding();
281 void Test11648_ExpDecFormatMalPattern();
282 void Test11649_DecFmtCurrencies();
283 void Test13148_ParseGroupingSeparators();
284 void Test12753_PatternDecimalPoint();
285 void Test11647_PatternCurrencySymbols();
286 void Test11913_BigDecimal();
287 void Test11020_RoundingInScientificNotation();
288 void Test11640_TripleCurrencySymbol();
289 void Test13763_FieldPositionIteratorOffset();
290 void Test13777_ParseLongNameNonCurrencyMode();
291 void Test13804_EmptyStringsWhenParsing();
292 void Test20037_ScientificIntegerOverflow();
293 void Test13840_ParseLongStringCrash();
294 void Test13850_EmptyStringCurrency();
295 void Test20348_CurrencyPrefixOverride();
296 void Test20358_GroupingInPattern();
297 void Test13731_DefaultCurrency();
298 void Test20499_CurrencyVisibleDigitsPlural();
301 UBool
testFormattableAsUFormattable(const char *file
, int line
, Formattable
&f
);
303 void expectParseCurrency(const NumberFormat
&fmt
, const UChar
* currency
, double amount
, const char *text
);
305 static UBool
equalValue(const Formattable
& a
, const Formattable
& b
);
307 void expectPositions(FieldPositionIterator
& iter
, int32_t *values
, int32_t tupleCount
,
308 const UnicodeString
& str
);
310 void expectPosition(FieldPosition
& pos
, int32_t id
, int32_t start
, int32_t limit
,
311 const UnicodeString
& str
);
313 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
315 void expect3(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
317 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const char* str
) {
318 expect2(fmt
, n
, UnicodeString(str
, ""));
321 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const UnicodeString
& str
, UErrorCode ec
);
323 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const char* str
, UErrorCode ec
) {
324 expect2(fmt
, n
, UnicodeString(str
, ""), ec
);
327 void expect(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
329 void expect(NumberFormat
& fmt
, const char *str
, const Formattable
& n
) {
330 expect(fmt
, UnicodeString(str
, ""), n
);
333 void expect(NumberFormat
& fmt
, const Formattable
& n
,
334 const UnicodeString
& exp
, UBool rt
=TRUE
);
336 void expect(NumberFormat
& fmt
, const Formattable
& n
,
337 const char *exp
, UBool rt
=TRUE
) {
338 expect(fmt
, n
, UnicodeString(exp
, ""), rt
);
341 void expect(NumberFormat
* fmt
, const Formattable
& n
,
342 const UnicodeString
& exp
, UBool rt
, UErrorCode errorCode
);
344 void expect(NumberFormat
* fmt
, const Formattable
& n
,
345 const char *exp
, UBool rt
, UErrorCode errorCode
) {
346 expect(fmt
, n
, UnicodeString(exp
, ""), rt
, errorCode
);
349 void expect(NumberFormat
* fmt
, const Formattable
& n
,
350 const UnicodeString
& exp
, UErrorCode errorCode
) {
351 expect(fmt
, n
, exp
, TRUE
, errorCode
);
354 void expect(NumberFormat
* fmt
, const Formattable
& n
,
355 const char *exp
, UErrorCode errorCode
) {
356 expect(fmt
, n
, UnicodeString(exp
, ""), TRUE
, errorCode
);
359 void expectCurrency(NumberFormat
& nf
, const Locale
& locale
,
360 double value
, const UnicodeString
& string
);
362 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
363 int32_t pos
, int32_t width
, UChar pad
);
365 void expectPad(DecimalFormat
& fmt
, const char *pat
,
366 int32_t pos
, int32_t width
, UChar pad
) {
367 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
370 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
371 int32_t pos
, int32_t width
, const UnicodeString
& pad
);
373 void expectPad(DecimalFormat
& fmt
, const char *pat
,
374 int32_t pos
, int32_t width
, const UnicodeString
& pad
) {
375 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
378 void expectPat(DecimalFormat
& fmt
, const UnicodeString
& exp
);
380 void expectPat(DecimalFormat
& fmt
, const char *exp
) {
381 expectPat(fmt
, UnicodeString(exp
, ""));
384 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
387 void expectPad(DecimalFormat
& fmt
, const char *pat
,
389 expectPad(fmt
, pat
, pos
, 0, (UChar
)0);
392 void expect_rbnf(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
394 void expect_rbnf(NumberFormat
& fmt
, const Formattable
& n
,
395 const UnicodeString
& exp
, UBool rt
=TRUE
);
397 // internal utility routine
398 static UnicodeString
& escape(UnicodeString
& s
);
400 enum { ILLEGAL
= -1 };
402 // internal subtest used by TestRounding487
403 void roundingTest(NumberFormat
& nf
, double x
, int32_t maxFractionDigits
, const char* expected
);
405 // internal rounding checking for TestRounding
406 void checkRounding(DecimalFormat
* df
, double base
, int iterations
, double increment
);
408 double checkRound(DecimalFormat
* df
, double iValue
, double lastParsed
);
411 DecimalFormat
& format
,
412 const double *values
,
413 const char * const *expected
,
414 const DecimalFormat::ERoundingMode
*roundingModes
,
415 const char * const *descriptions
,
417 int32_t roundingModeSize
);
419 void verifyFieldPositionIterator(
420 NumberFormatTest_Attributes
*expected
,
421 FieldPositionIterator
&iter
);
425 #endif /* #if !UCONFIG_NO_FORMATTING */
427 #endif // _NUMBERFORMATTEST_