]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/numfmtst.h
ICU-62135.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / numfmtst.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /************************************************************************
4 * COPYRIGHT:
5 * Copyright (c) 1997-2016, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ************************************************************************/
8
9 #ifndef _NUMBERFORMATTEST_
10 #define _NUMBERFORMATTEST_
11
12 #include "unicode/utypes.h"
13
14 #if !UCONFIG_NO_FORMATTING
15
16 #include "unicode/numfmt.h"
17 #include "unicode/decimfmt.h"
18 #include "caltztst.h"
19 #include "datadrivennumberformattestsuite.h"
20
21 /**
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.
27 */
28 struct NumberFormatTest_Attributes {
29 int32_t id;
30 int32_t spos;
31 int32_t epos;
32 };
33
34
35 /**
36 * Header for the data-driven test, powered by numberformattestspecification.txt
37 */
38 class NumberFormatDataDrivenTest : public DataDrivenNumberFormatTestSuite {
39 public:
40 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
41 void TestNumberFormatTestTuple();
42 void TestDataDrivenICU4C();
43
44 protected:
45 UBool isFormatPass(
46 const NumberFormatTestTuple &tuple,
47 UnicodeString &appendErrorMessage,
48 UErrorCode &status);
49 UBool isToPatternPass(
50 const NumberFormatTestTuple &tuple,
51 UnicodeString &appendErrorMessage,
52 UErrorCode &status);
53 UBool isParsePass(
54 const NumberFormatTestTuple &tuple,
55 UnicodeString &appendErrorMessage,
56 UErrorCode &status);
57 UBool isParseCurrencyPass(
58 const NumberFormatTestTuple &tuple,
59 UnicodeString &appendErrorMessage,
60 UErrorCode &status);
61 };
62
63 /**
64 * Performs various in-depth test on NumberFormat
65 **/
66 class NumberFormatTest: public CalendarTimeZoneTest {
67
68 // IntlTest override
69 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
70 public:
71
72 /**
73 * Test APIs (to increase code coverage)
74 */
75 void TestAPI(void);
76
77 void TestCoverage(void);
78 void TestLocalizedPatternSymbolCoverage();
79
80 /**
81 * Test the handling of quotes
82 **/
83 void TestQuotes(void);
84 /**
85 * Test patterns with exponential representation
86 **/
87 void TestExponential(void);
88 /**
89 * Test handling of patterns with currency symbols
90 **/
91 void TestCurrencySign(void);
92 /**
93 * Test different format patterns
94 **/
95 void TestPatterns(void);
96 /**
97 * API coverage for DigitList
98 **/
99 //void TestDigitList(void);
100
101 /**
102 * Test localized currency patterns.
103 */
104 void TestCurrency(void);
105
106 /**
107 * Test the Currency object handling, new as of ICU 2.2.
108 */
109 void TestCurrencyObject(void);
110
111 void TestCurrencyPatterns(void);
112
113 /**
114 * Do rudimentary testing of parsing.
115 */
116 void TestParse(void);
117 /**
118 * Test proper rounding by the format method.
119 */
120 void TestRounding487(void);
121
122 // New tests for alphaWorks upgrade
123 void TestExponent(void);
124
125 void TestScientific(void);
126
127 void TestScientific2(void);
128
129 void TestScientificGrouping(void);
130
131 void TestInt64(void);
132
133 void TestSurrogateSupport(void);
134
135 /**
136 * Test the functioning of the secondary grouping value.
137 */
138 void TestSecondaryGrouping(void);
139
140 void TestWhiteSpaceParsing(void);
141
142 void TestComplexCurrency(void);
143
144 void TestPad(void);
145 void TestPatterns2(void);
146
147 /**
148 * Test currency registration.
149 */
150 void TestRegCurrency(void);
151
152 void TestCurrencyNames(void);
153
154 void TestCurrencyAmount(void);
155
156 void TestCurrencyUnit(void);
157
158 void TestSymbolsWithBadLocale(void);
159
160 void TestAdoptDecimalFormatSymbols(void);
161
162 void TestPerMill(void);
163
164 void TestIllegalPatterns(void);
165
166 void TestCases(void);
167
168 void TestJB3832(void);
169
170 void TestHost(void);
171
172 void TestHostClone(void);
173
174 void TestCurrencyFormat(void);
175
176 /* Port of ICU4J rounding test. */
177 void TestRounding(void);
178
179 void TestRoundingPattern(void);
180
181 void TestNonpositiveMultiplier(void);
182
183 void TestNumberingSystems();
184
185
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();
196
197 void TestLenientParse();
198
199 void TestDecimal();
200 void TestCurrencyFractionDigits();
201
202 void TestExponentParse();
203 void TestExplicitParents();
204 void TestAvailableNumberingSystems();
205 void Test9087();
206 void TestFormatFastpaths();
207
208 void TestFormattableSize();
209
210 void TestUFormattable();
211
212 void TestEnumSet();
213
214 void TestSignificantDigits();
215 void TestShowZero();
216
217 void TestCompatibleCurrencies();
218 void TestBug9936();
219 void TestParseNegativeWithFaLocale();
220 void TestParseNegativeWithAlternateMinusSign();
221
222 void TestCustomCurrencySignAndSeparator();
223
224 void TestParseSignsAndMarks();
225 void Test10419RoundingWith0FractionDigits();
226 void Test10468ApplyPattern();
227 void TestRoundingScientific10542();
228 void TestZeroScientific10547();
229 void TestAccountingCurrency();
230 void TestEquality();
231
232 void TestCurrencyUsage();
233
234 void TestDoubleLimit11439();
235 void TestFastPathConsistent11524();
236 void TestGetAffixes();
237 void TestToPatternScientific11648();
238 void TestBenchmark();
239 void TestCtorApplyPatternDifference();
240 void TestFractionalDigitsForCurrency();
241 void TestFormatCurrencyPlural();
242 void Test11868();
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();
253
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();
261 void TestParseNaN();
262 void Test11897_LocalizedPatternSeparator();
263 void Test13055_PercentageRounding();
264 void Test11839();
265 void Test10354();
266 void Test11645_ApplyPatternEquality();
267 void Test12567();
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();
283
284 private:
285 UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
286
287 void expectParseCurrency(const NumberFormat &fmt, const UChar* currency, double amount, const char *text);
288
289 static UBool equalValue(const Formattable& a, const Formattable& b);
290
291 void expectPositions(FieldPositionIterator& iter, int32_t *values, int32_t tupleCount,
292 const UnicodeString& str);
293
294 void expectPosition(FieldPosition& pos, int32_t id, int32_t start, int32_t limit,
295 const UnicodeString& str);
296
297 void expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
298
299 void expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
300
301 void expect2(NumberFormat& fmt, const Formattable& n, const char* str) {
302 expect2(fmt, n, UnicodeString(str, ""));
303 }
304
305 void expect2(NumberFormat* fmt, const Formattable& n, const UnicodeString& str, UErrorCode ec);
306
307 void expect2(NumberFormat* fmt, const Formattable& n, const char* str, UErrorCode ec) {
308 expect2(fmt, n, UnicodeString(str, ""), ec);
309 }
310
311 void expect(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
312
313 void expect(NumberFormat& fmt, const char *str, const Formattable& n) {
314 expect(fmt, UnicodeString(str, ""), n);
315 }
316
317 void expect(NumberFormat& fmt, const Formattable& n,
318 const UnicodeString& exp, UBool rt=TRUE);
319
320 void expect(NumberFormat& fmt, const Formattable& n,
321 const char *exp, UBool rt=TRUE) {
322 expect(fmt, n, UnicodeString(exp, ""), rt);
323 }
324
325 void expect(NumberFormat* fmt, const Formattable& n,
326 const UnicodeString& exp, UBool rt, UErrorCode errorCode);
327
328 void expect(NumberFormat* fmt, const Formattable& n,
329 const char *exp, UBool rt, UErrorCode errorCode) {
330 expect(fmt, n, UnicodeString(exp, ""), rt, errorCode);
331 }
332
333 void expect(NumberFormat* fmt, const Formattable& n,
334 const UnicodeString& exp, UErrorCode errorCode) {
335 expect(fmt, n, exp, TRUE, errorCode);
336 }
337
338 void expect(NumberFormat* fmt, const Formattable& n,
339 const char *exp, UErrorCode errorCode) {
340 expect(fmt, n, UnicodeString(exp, ""), TRUE, errorCode);
341 }
342
343 void expectCurrency(NumberFormat& nf, const Locale& locale,
344 double value, const UnicodeString& string);
345
346 void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
347 int32_t pos, int32_t width, UChar pad);
348
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);
352 }
353
354 void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
355 int32_t pos, int32_t width, const UnicodeString& pad);
356
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);
360 }
361
362 void expectPat(DecimalFormat& fmt, const UnicodeString& exp);
363
364 void expectPat(DecimalFormat& fmt, const char *exp) {
365 expectPat(fmt, UnicodeString(exp, ""));
366 }
367
368 void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
369 int32_t pos);
370
371 void expectPad(DecimalFormat& fmt, const char *pat,
372 int32_t pos) {
373 expectPad(fmt, pat, pos, 0, (UChar)0);
374 }
375
376 void expect_rbnf(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
377
378 void expect_rbnf(NumberFormat& fmt, const Formattable& n,
379 const UnicodeString& exp, UBool rt=TRUE);
380
381 // internal utility routine
382 static UnicodeString& escape(UnicodeString& s);
383
384 enum { ILLEGAL = -1 };
385
386 // internal subtest used by TestRounding487
387 void roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected);
388
389 // internal rounding checking for TestRounding
390 void checkRounding(DecimalFormat* df, double base, int iterations, double increment);
391
392 double checkRound(DecimalFormat* df, double iValue, double lastParsed);
393
394 void verifyRounding(
395 DecimalFormat& format,
396 const double *values,
397 const char * const *expected,
398 const DecimalFormat::ERoundingMode *roundingModes,
399 const char * const *descriptions,
400 int32_t valueSize,
401 int32_t roundingModeSize);
402
403 void verifyFieldPositionIterator(
404 NumberFormatTest_Attributes *expected,
405 FieldPositionIterator &iter);
406
407 };
408
409 #endif /* #if !UCONFIG_NO_FORMATTING */
410
411 #endif // _NUMBERFORMATTEST_