1 /************************************************************************
3 * Copyright (c) 1997-2016, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 ************************************************************************/
7 #ifndef _NUMBERFORMATTEST_
8 #define _NUMBERFORMATTEST_
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/numfmt.h"
15 #include "unicode/decimfmt.h"
19 * Expected field positions from field position iterator. Tests should
20 * stack allocate an array of these making sure that the last element is
21 * {0, -1, 0} (The sentinel element indicating end of iterator). Then test
22 * should call verifyFieldPositionIterator() passing both this array of
23 * expected results and the field position iterator from the format method.
25 struct NumberFormatTest_Attributes
{
32 * Performs various in-depth test on NumberFormat
34 class NumberFormatTest
: public CalendarTimeZoneTest
{
37 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
41 * Test APIs (to increase code coverage)
45 void TestCoverage(void);
48 * Test the handling of quotes
50 void TestQuotes(void);
52 * Test patterns with exponential representation
54 void TestExponential(void);
56 * Test handling of patterns with currency symbols
58 void TestCurrencySign(void);
60 * Test different format patterns
62 void TestPatterns(void);
64 * API coverage for DigitList
66 //void TestDigitList(void);
69 * Test localized currency patterns.
71 void TestCurrency(void);
74 * Test the Currency object handling, new as of ICU 2.2.
76 void TestCurrencyObject(void);
78 void TestCurrencyPatterns(void);
81 * Do rudimentary testing of parsing.
85 * Test proper rounding by the format method.
87 void TestRounding487(void);
89 // New tests for alphaWorks upgrade
90 void TestExponent(void);
92 void TestScientific(void);
94 void TestScientific2(void);
96 void TestScientificGrouping(void);
100 void TestSurrogateSupport(void);
103 * Test the functioning of the secondary grouping value.
105 void TestSecondaryGrouping(void);
107 void TestWhiteSpaceParsing(void);
109 void TestComplexCurrency(void);
112 void TestPatterns2(void);
115 * Test currency registration.
117 void TestRegCurrency(void);
119 void TestCurrencyNames(void);
121 void TestCurrencyAmount(void);
123 void TestCurrencyUnit(void);
125 void TestSymbolsWithBadLocale(void);
127 void TestAdoptDecimalFormatSymbols(void);
129 void TestPerMill(void);
131 void TestIllegalPatterns(void);
133 void TestCases(void);
135 void TestJB3832(void);
139 void TestHostClone(void);
141 void TestCurrencyFormat(void);
143 /* Port of ICU4J rounding test. */
144 void TestRounding(void);
146 void TestRoundingPattern(void);
148 void TestNonpositiveMultiplier(void);
150 void TestNumberingSystems();
153 void TestSpaceParsing();
154 void TestMultiCurrencySign();
155 void TestCurrencyFormatForMixParsing();
156 void TestDecimalFormatCurrencyParse();
157 void TestCurrencyIsoPluralFormat();
158 void TestCurrencyParsing();
159 void TestParseCurrencyInUCurr();
160 void TestFormatAttributes();
161 void TestFieldPositionIterator();
163 void TestLenientParse();
166 void TestCurrencyFractionDigits();
168 void TestExponentParse();
169 void TestExplicitParents();
170 void TestAvailableNumberingSystems();
172 void TestFormatFastpaths();
174 void TestFormattableSize();
176 void TestUFormattable();
180 void TestSignificantDigits();
183 void TestCompatibleCurrencies();
185 void TestParseNegativeWithFaLocale();
186 void TestParseNegativeWithAlternateMinusSign();
188 void TestCustomCurrencySignAndSeparator();
190 void TestParseSignsAndMarks();
191 void Test10419RoundingWith0FractionDigits();
192 void Test10468ApplyPattern();
193 void TestRoundingScientific10542();
194 void TestZeroScientific10547();
195 void TestAccountingCurrency();
198 void TestCurrencyUsage();
199 void TestNumberFormatTestTuple();
200 void TestDataDriven();
202 void TestDoubleLimit11439();
203 void TestFastPathConsistent11524();
204 void TestGetAffixes();
205 void TestToPatternScientific11648();
206 void TestBenchmark();
207 void TestCtorApplyPatternDifference();
208 void TestFractionalDigitsForCurrency();
209 void TestFormatCurrencyPlural();
211 void Test10727_RoundingZero();
212 void Test11376_getAndSetPositivePrefix();
213 void Test11475_signRecognition();
214 void Test11640_getAffixes();
215 void Test11649_toPatternWithMultiCurrency();
217 void checkExceptionIssue11735();
220 UBool
testFormattableAsUFormattable(const char *file
, int line
, Formattable
&f
);
222 void expectParseCurrency(const NumberFormat
&fmt
, const UChar
* currency
, double amount
, const char *text
);
224 static UBool
equalValue(const Formattable
& a
, const Formattable
& b
);
226 void expectPositions(FieldPositionIterator
& iter
, int32_t *values
, int32_t tupleCount
,
227 const UnicodeString
& str
);
229 void expectPosition(FieldPosition
& pos
, int32_t id
, int32_t start
, int32_t limit
,
230 const UnicodeString
& str
);
232 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
234 void expect3(NumberFormat
& fmt
, const Formattable
& n
, const UnicodeString
& str
);
236 void expect2(NumberFormat
& fmt
, const Formattable
& n
, const char* str
) {
237 expect2(fmt
, n
, UnicodeString(str
, ""));
240 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const UnicodeString
& str
, UErrorCode ec
);
242 void expect2(NumberFormat
* fmt
, const Formattable
& n
, const char* str
, UErrorCode ec
) {
243 expect2(fmt
, n
, UnicodeString(str
, ""), ec
);
246 void expect(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
248 void expect(NumberFormat
& fmt
, const char *str
, const Formattable
& n
) {
249 expect(fmt
, UnicodeString(str
, ""), n
);
252 void expect(NumberFormat
& fmt
, const Formattable
& n
,
253 const UnicodeString
& exp
, UBool rt
=TRUE
);
255 void expect(NumberFormat
& fmt
, const Formattable
& n
,
256 const char *exp
, UBool rt
=TRUE
) {
257 expect(fmt
, n
, UnicodeString(exp
, ""), rt
);
260 void expect(NumberFormat
* fmt
, const Formattable
& n
,
261 const UnicodeString
& exp
, UBool rt
, UErrorCode errorCode
);
263 void expect(NumberFormat
* fmt
, const Formattable
& n
,
264 const char *exp
, UBool rt
, UErrorCode errorCode
) {
265 expect(fmt
, n
, UnicodeString(exp
, ""), rt
, errorCode
);
268 void expect(NumberFormat
* fmt
, const Formattable
& n
,
269 const UnicodeString
& exp
, UErrorCode errorCode
) {
270 expect(fmt
, n
, exp
, TRUE
, errorCode
);
273 void expect(NumberFormat
* fmt
, const Formattable
& n
,
274 const char *exp
, UErrorCode errorCode
) {
275 expect(fmt
, n
, UnicodeString(exp
, ""), TRUE
, errorCode
);
278 void expectCurrency(NumberFormat
& nf
, const Locale
& locale
,
279 double value
, const UnicodeString
& string
);
281 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
282 int32_t pos
, int32_t width
, UChar pad
);
284 void expectPad(DecimalFormat
& fmt
, const char *pat
,
285 int32_t pos
, int32_t width
, UChar pad
) {
286 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
289 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
290 int32_t pos
, int32_t width
, const UnicodeString
& pad
);
292 void expectPad(DecimalFormat
& fmt
, const char *pat
,
293 int32_t pos
, int32_t width
, const UnicodeString
& pad
) {
294 expectPad(fmt
, UnicodeString(pat
, ""), pos
, width
, pad
);
297 void expectPat(DecimalFormat
& fmt
, const UnicodeString
& exp
);
299 void expectPat(DecimalFormat
& fmt
, const char *exp
) {
300 expectPat(fmt
, UnicodeString(exp
, ""));
303 void expectPad(DecimalFormat
& fmt
, const UnicodeString
& pat
,
306 void expectPad(DecimalFormat
& fmt
, const char *pat
,
308 expectPad(fmt
, pat
, pos
, 0, (UChar
)0);
311 void expect_rbnf(NumberFormat
& fmt
, const UnicodeString
& str
, const Formattable
& n
);
313 void expect_rbnf(NumberFormat
& fmt
, const Formattable
& n
,
314 const UnicodeString
& exp
, UBool rt
=TRUE
);
316 // internal utility routine
317 static UnicodeString
& escape(UnicodeString
& s
);
319 enum { ILLEGAL
= -1 };
321 // internal subtest used by TestRounding487
322 void roundingTest(NumberFormat
& nf
, double x
, int32_t maxFractionDigits
, const char* expected
);
324 // internal rounding checking for TestRounding
325 void checkRounding(DecimalFormat
* df
, double base
, int iterations
, double increment
);
327 double checkRound(DecimalFormat
* df
, double iValue
, double lastParsed
);
330 DecimalFormat
& format
,
331 const double *values
,
332 const char * const *expected
,
333 const DecimalFormat::ERoundingMode
*roundingModes
,
334 const char * const *descriptions
,
336 int32_t roundingModeSize
);
338 void verifyFieldPositionIterator(
339 NumberFormatTest_Attributes
*expected
,
340 FieldPositionIterator
&iter
);
344 #endif /* #if !UCONFIG_NO_FORMATTING */
346 #endif // _NUMBERFORMATTEST_