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);
102 * Test localized currency patterns.
104 void TestCurrency(void);
107 * Test the Currency object handling, new as of ICU 2.2.
109 void TestCurrencyObject(void);
111 void TestCurrencyPatterns(void);
114 * Do rudimentary testing of parsing.
116 void TestParse(void);
118 * Test proper rounding by the format method.
120 void TestRounding487(void);
122 // New tests for alphaWorks upgrade
123 void TestExponent(void);
125 void TestScientific(void);
127 void TestScientific2(void);
129 void TestScientificGrouping(void);
131 void TestInt64(void);
133 void TestSurrogateSupport(void);
136 * Test the functioning of the secondary grouping value.
138 void TestSecondaryGrouping(void);
140 void TestWhiteSpaceParsing(void);
142 void TestComplexCurrency(void);
145 void TestPatterns2(void);
148 * Test currency registration.
150 void TestRegCurrency(void);
152 void TestCurrencyNames(void);
154 void TestCurrencyAmount(void);
156 void TestCurrencyUnit(void);
158 void TestSymbolsWithBadLocale(void);
160 void TestAdoptDecimalFormatSymbols(void);
162 void TestPerMill(void);
164 void TestIllegalPatterns(void);
166 void TestCases(void);
168 void TestJB3832(void);
172 void TestHostClone(void);
174 void TestCurrencyFormat(void);
176 /* Port of ICU4J rounding test. */
177 void TestRounding(void);
179 void TestRoundingPattern(void);
181 void TestNonpositiveMultiplier(void);
183 void TestNumberingSystems();
186 void TestSpaceParsing();
187 void TestMultiCurrencySign();
188 void TestCurrencyFormatForMixParsing();
189 void TestMismatchedCurrencyFormatFail();
190 void TestDecimalFormatCurrencyParse();
191 void TestCurrencyIsoPluralFormat();
192 void TestCurrencyParsing();
193 void TestParseCurrencyInUCurr();
194 void TestFormatAttributes();
195 void TestFieldPositionIterator();
197 void TestLenientParse();
200 void TestCurrencyFractionDigits();
202 void TestExponentParse();
203 void TestExplicitParents();
204 void TestAvailableNumberingSystems();
206 void TestFormatFastpaths();
208 void TestFormattableSize();
210 void TestUFormattable();
214 void TestSignificantDigits();
217 void TestCompatibleCurrencies();
219 void TestParseNegativeWithFaLocale();
220 void TestParseNegativeWithAlternateMinusSign();
222 void TestCustomCurrencySignAndSeparator();
224 void TestParseSignsAndMarks();
225 void Test10419RoundingWith0FractionDigits();
226 void Test10468ApplyPattern();
227 void TestRoundingScientific10542();
228 void TestZeroScientific10547();
229 void TestAccountingCurrency();
232 void TestCurrencyUsage();
234 void TestDoubleLimit11439();
235 void TestFastPathConsistent11524();
236 void TestGetAffixes();
237 void TestToPatternScientific11648();
238 void TestBenchmark();
239 void TestCtorApplyPatternDifference();
240 void TestFractionalDigitsForCurrency();
241 void TestFormatCurrencyPlural();
243 void Test11739_ParseLongCurrency();
244 void Test13035_MultiCodePointPaddingInPattern();
245 void Test13737_ParseScientificStrict();
246 void Test10727_RoundingZero();
247 void Test11376_getAndSetPositivePrefix();
248 void Test11475_signRecognition();
249 void Test11640_getAffixes();
250 void Test11649_toPatternWithMultiCurrency();
251 void Test13327_numberingSystemBufferOverflow();
252 void Test13391_chakmaParsing();
254 void Test11735_ExceptionIssue();
255 void Test11035_FormatCurrencyAmount();
256 void Test11318_DoubleConversion();
257 void TestParsePercentRegression();
258 void TestMultiplierWithScale();
259 void TestFastFormatInt32();
260 void Test11646_Equality();
262 void Test11897_LocalizedPatternSeparator();
263 void Test13055_PercentageRounding();
266 void Test11645_ApplyPatternEquality();
268 void Test11626_CustomizeCurrencyPluralInfo();
269 void Test13056_GroupingSize();
270 void Test11025_CurrencyPadding();
271 void Test11648_ExpDecFormatMalPattern();
272 void Test11649_DecFmtCurrencies();
273 void Test13148_ParseGroupingSeparators();
274 void Test12753_PatternDecimalPoint();
275 void Test11647_PatternCurrencySymbols();
276 void Test11913_BigDecimal();
277 void Test11020_RoundingInScientificNotation();
278 void Test11640_TripleCurrencySymbol();
279 void Test13763_FieldPositionIteratorOffset();
280 void Test13777_ParseLongNameNonCurrencyMode();
281 void Test13804_EmptyStringsWhenParsing();
282 void Test13840_ParseLongStringCrash();
285 UBool
testFormattableAsUFormattable(const char *file
, int line
, Formattable
&f
);
287 void expectParseCurrency(const NumberFormat
&fmt
, const UChar
* currency
, double amount
, const char *text
);
289 static UBool
equalValue(const Formattable
& a
, const Formattable
& b
);
291 void expectPositions(FieldPositionIterator
& iter
, int32_t *values
, int32_t tupleCount
,
292 const UnicodeString
& str
);
294 void expectPosition(FieldPosition
& pos
, int32_t id
, int32_t start
, int32_t limit
,
295 const UnicodeString
& str
);
297 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
299 void expect3(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
301 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const char* str
) {
302 expect2(fmt
, n
, UnicodeString(str
, ""));
305 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const UnicodeString
& str
, UErrorCode ec
);
307 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const char* str
, UErrorCode ec
) {
308 expect2(fmt
, n
, UnicodeString(str
, ""), ec
);
311 void expect(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
313 void expect(NumberFormat
& fmt
, const char *str
, const Formattable
& n
) {
314 expect(fmt
, UnicodeString(str
, ""), n
);
317 void expect(NumberFormat
& fmt
, const Formattable
& n
,
318 const UnicodeString
& exp
, UBool rt
=TRUE
);
320 void expect(NumberFormat
& fmt
, const Formattable
& n
,
321 const char *exp
, UBool rt
=TRUE
) {
322 expect(fmt
, n
, UnicodeString(exp
, ""), rt
);
325 void expect(NumberFormat
* fmt
, const Formattable
& n
,
326 const UnicodeString
& exp
, UBool rt
, UErrorCode errorCode
);
328 void expect(NumberFormat
* fmt
, const Formattable
& n
,
329 const char *exp
, UBool rt
, UErrorCode errorCode
) {
330 expect(fmt
, n
, UnicodeString(exp
, ""), rt
, errorCode
);
333 void expect(NumberFormat
* fmt
, const Formattable
& n
,
334 const UnicodeString
& exp
, UErrorCode errorCode
) {
335 expect(fmt
, n
, exp
, TRUE
, errorCode
);
338 void expect(NumberFormat
* fmt
, const Formattable
& n
,
339 const char *exp
, UErrorCode errorCode
) {
340 expect(fmt
, n
, UnicodeString(exp
, ""), TRUE
, errorCode
);
343 void expectCurrency(NumberFormat
& nf
, const Locale
& locale
,
344 double value
, const UnicodeString
& string
);
346 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
347 int32_t pos
, int32_t width
, UChar pad
);
349 void expectPad(DecimalFormat
& fmt
, const char *pat
,
350 int32_t pos
, int32_t width
, UChar pad
) {
351 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
354 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
355 int32_t pos
, int32_t width
, const UnicodeString
& pad
);
357 void expectPad(DecimalFormat
& fmt
, const char *pat
,
358 int32_t pos
, int32_t width
, const UnicodeString
& pad
) {
359 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
362 void expectPat(DecimalFormat
& fmt
, const UnicodeString
& exp
);
364 void expectPat(DecimalFormat
& fmt
, const char *exp
) {
365 expectPat(fmt
, UnicodeString(exp
, ""));
368 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
371 void expectPad(DecimalFormat
& fmt
, const char *pat
,
373 expectPad(fmt
, pat
, pos
, 0, (UChar
)0);
376 void expect_rbnf(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
378 void expect_rbnf(NumberFormat
& fmt
, const Formattable
& n
,
379 const UnicodeString
& exp
, UBool rt
=TRUE
);
381 // internal utility routine
382 static UnicodeString
& escape(UnicodeString
& s
);
384 enum { ILLEGAL
= -1 };
386 // internal subtest used by TestRounding487
387 void roundingTest(NumberFormat
& nf
, double x
, int32_t maxFractionDigits
, const char* expected
);
389 // internal rounding checking for TestRounding
390 void checkRounding(DecimalFormat
* df
, double base
, int iterations
, double increment
);
392 double checkRound(DecimalFormat
* df
, double iValue
, double lastParsed
);
395 DecimalFormat
& format
,
396 const double *values
,
397 const char * const *expected
,
398 const DecimalFormat::ERoundingMode
*roundingModes
,
399 const char * const *descriptions
,
401 int32_t roundingModeSize
);
403 void verifyFieldPositionIterator(
404 NumberFormatTest_Attributes
*expected
,
405 FieldPositionIterator
&iter
);
409 #endif /* #if !UCONFIG_NO_FORMATTING */
411 #endif // _NUMBERFORMATTEST_