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"
21 * Expected field positions from field position iterator. Tests should
22 * stack allocate an array of these making sure that the last element is
23 * {0, -1, 0} (The sentinel element indicating end of iterator). Then test
24 * should call verifyFieldPositionIterator() passing both this array of
25 * expected results and the field position iterator from the format method.
27 struct NumberFormatTest_Attributes
{
34 * Performs various in-depth test on NumberFormat
36 class NumberFormatTest
: public CalendarTimeZoneTest
{
39 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
43 * Test APIs (to increase code coverage)
47 void TestCoverage(void);
50 * Test the handling of quotes
52 void TestQuotes(void);
54 * Test patterns with exponential representation
56 void TestExponential(void);
58 * Test handling of patterns with currency symbols
60 void TestCurrencySign(void);
62 * Test different format patterns
64 void TestPatterns(void);
66 * API coverage for DigitList
68 //void TestDigitList(void);
71 * Test localized currency patterns.
73 void TestCurrency(void);
76 * Test the Currency object handling, new as of ICU 2.2.
78 void TestCurrencyObject(void);
80 void TestCurrencyPatterns(void);
83 * Do rudimentary testing of parsing.
87 * Test proper rounding by the format method.
89 void TestRounding487(void);
91 // New tests for alphaWorks upgrade
92 void TestExponent(void);
94 void TestScientific(void);
96 void TestScientific2(void);
98 void TestScientificGrouping(void);
100 void TestInt64(void);
102 void TestSurrogateSupport(void);
105 * Test the functioning of the secondary grouping value.
107 void TestSecondaryGrouping(void);
109 void TestWhiteSpaceParsing(void);
111 void TestComplexCurrency(void);
114 void TestPatterns2(void);
117 * Test currency registration.
119 void TestRegCurrency(void);
121 void TestCurrencyNames(void);
123 void TestCurrencyAmount(void);
125 void TestCurrencyUnit(void);
127 void TestSymbolsWithBadLocale(void);
129 void TestAdoptDecimalFormatSymbols(void);
131 void TestPerMill(void);
133 void TestIllegalPatterns(void);
135 void TestCases(void);
137 void TestJB3832(void);
141 void TestHostClone(void);
143 void TestCurrencyFormat(void);
145 /* Port of ICU4J rounding test. */
146 void TestRounding(void);
148 void TestRoundingPattern(void);
150 void TestNonpositiveMultiplier(void);
152 void TestNumberingSystems();
155 void TestSpaceParsing();
156 void TestMultiCurrencySign();
157 void TestCurrencyFormatForMixParsing();
158 void TestDecimalFormatCurrencyParse();
159 void TestCurrencyIsoPluralFormat();
160 void TestCurrencyParsing();
161 void TestParseCurrencyInUCurr();
162 void TestFormatAttributes();
163 void TestFieldPositionIterator();
165 void TestLenientParse();
168 void TestCurrencyFractionDigits();
170 void TestExponentParse();
171 void TestExplicitParents();
172 void TestAvailableNumberingSystems();
174 void TestFormatFastpaths();
176 void TestFormattableSize();
178 void TestUFormattable();
182 void TestSignificantDigits();
185 void TestCompatibleCurrencies();
187 void TestParseNegativeWithFaLocale();
188 void TestParseNegativeWithAlternateMinusSign();
190 void TestCustomCurrencySignAndSeparator();
192 void TestParseSignsAndMarks();
193 void Test10419RoundingWith0FractionDigits();
194 void Test10468ApplyPattern();
195 void TestRoundingScientific10542();
196 void TestZeroScientific10547();
197 void TestAccountingCurrency();
200 void TestCurrencyUsage();
201 void TestNumberFormatTestTuple();
202 void TestDataDriven();
204 void TestDoubleLimit11439();
205 void TestFastPathConsistent11524();
206 void TestGetAffixes();
207 void TestToPatternScientific11648();
208 void TestBenchmark();
209 void TestCtorApplyPatternDifference();
210 void TestFractionalDigitsForCurrency();
211 void TestFormatCurrencyPlural();
213 void Test10727_RoundingZero();
214 void Test11376_getAndSetPositivePrefix();
215 void Test11475_signRecognition();
216 void Test11640_getAffixes();
217 void Test11649_toPatternWithMultiCurrency();
219 void checkExceptionIssue11735();
222 UBool
testFormattableAsUFormattable(const char *file
, int line
, Formattable
&f
);
224 void expectParseCurrency(const NumberFormat
&fmt
, const UChar
* currency
, double amount
, const char *text
);
226 static UBool
equalValue(const Formattable
& a
, const Formattable
& b
);
228 void expectPositions(FieldPositionIterator
& iter
, int32_t *values
, int32_t tupleCount
,
229 const UnicodeString
& str
);
231 void expectPosition(FieldPosition
& pos
, int32_t id
, int32_t start
, int32_t limit
,
232 const UnicodeString
& str
);
234 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
236 void expect3(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
238 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const char* str
) {
239 expect2(fmt
, n
, UnicodeString(str
, ""));
242 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const UnicodeString
& str
, UErrorCode ec
);
244 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const char* str
, UErrorCode ec
) {
245 expect2(fmt
, n
, UnicodeString(str
, ""), ec
);
248 void expect(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
250 void expect(NumberFormat
& fmt
, const char *str
, const Formattable
& n
) {
251 expect(fmt
, UnicodeString(str
, ""), n
);
254 void expect(NumberFormat
& fmt
, const Formattable
& n
,
255 const UnicodeString
& exp
, UBool rt
=TRUE
);
257 void expect(NumberFormat
& fmt
, const Formattable
& n
,
258 const char *exp
, UBool rt
=TRUE
) {
259 expect(fmt
, n
, UnicodeString(exp
, ""), rt
);
262 void expect(NumberFormat
* fmt
, const Formattable
& n
,
263 const UnicodeString
& exp
, UBool rt
, UErrorCode errorCode
);
265 void expect(NumberFormat
* fmt
, const Formattable
& n
,
266 const char *exp
, UBool rt
, UErrorCode errorCode
) {
267 expect(fmt
, n
, UnicodeString(exp
, ""), rt
, errorCode
);
270 void expect(NumberFormat
* fmt
, const Formattable
& n
,
271 const UnicodeString
& exp
, UErrorCode errorCode
) {
272 expect(fmt
, n
, exp
, TRUE
, errorCode
);
275 void expect(NumberFormat
* fmt
, const Formattable
& n
,
276 const char *exp
, UErrorCode errorCode
) {
277 expect(fmt
, n
, UnicodeString(exp
, ""), TRUE
, errorCode
);
280 void expectCurrency(NumberFormat
& nf
, const Locale
& locale
,
281 double value
, const UnicodeString
& string
);
283 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
284 int32_t pos
, int32_t width
, UChar pad
);
286 void expectPad(DecimalFormat
& fmt
, const char *pat
,
287 int32_t pos
, int32_t width
, UChar pad
) {
288 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
291 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
292 int32_t pos
, int32_t width
, const UnicodeString
& pad
);
294 void expectPad(DecimalFormat
& fmt
, const char *pat
,
295 int32_t pos
, int32_t width
, const UnicodeString
& pad
) {
296 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
299 void expectPat(DecimalFormat
& fmt
, const UnicodeString
& exp
);
301 void expectPat(DecimalFormat
& fmt
, const char *exp
) {
302 expectPat(fmt
, UnicodeString(exp
, ""));
305 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
308 void expectPad(DecimalFormat
& fmt
, const char *pat
,
310 expectPad(fmt
, pat
, pos
, 0, (UChar
)0);
313 void expect_rbnf(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
315 void expect_rbnf(NumberFormat
& fmt
, const Formattable
& n
,
316 const UnicodeString
& exp
, UBool rt
=TRUE
);
318 // internal utility routine
319 static UnicodeString
& escape(UnicodeString
& s
);
321 enum { ILLEGAL
= -1 };
323 // internal subtest used by TestRounding487
324 void roundingTest(NumberFormat
& nf
, double x
, int32_t maxFractionDigits
, const char* expected
);
326 // internal rounding checking for TestRounding
327 void checkRounding(DecimalFormat
* df
, double base
, int iterations
, double increment
);
329 double checkRound(DecimalFormat
* df
, double iValue
, double lastParsed
);
332 DecimalFormat
& format
,
333 const double *values
,
334 const char * const *expected
,
335 const DecimalFormat::ERoundingMode
*roundingModes
,
336 const char * const *descriptions
,
338 int32_t roundingModeSize
);
340 void verifyFieldPositionIterator(
341 NumberFormatTest_Attributes
*expected
,
342 FieldPositionIterator
&iter
);
346 #endif /* #if !UCONFIG_NO_FORMATTING */
348 #endif // _NUMBERFORMATTEST_