]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/numfmtst.h
ICU-62123.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / numfmtst.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
729e4ab9
A
3/************************************************************************
4 * COPYRIGHT:
2ca993e8 5 * Copyright (c) 1997-2016, International Business Machines Corporation
729e4ab9
A
6 * and others. All Rights Reserved.
7 ************************************************************************/
8
b75a7d8f
A
9#ifndef _NUMBERFORMATTEST_
10#define _NUMBERFORMATTEST_
11
12#include "unicode/utypes.h"
13
14#if !UCONFIG_NO_FORMATTING
15
16#include "unicode/numfmt.h"
729e4ab9 17#include "unicode/decimfmt.h"
b75a7d8f 18#include "caltztst.h"
0f5d89e8 19#include "datadrivennumberformattestsuite.h"
b75a7d8f 20
2ca993e8
A
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 */
28struct NumberFormatTest_Attributes {
29 int32_t id;
30 int32_t spos;
31 int32_t epos;
32};
33
0f5d89e8
A
34
35/**
36 * Header for the data-driven test, powered by numberformattestspecification.txt
37 */
38class 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
b75a7d8f
A
63/**
64 * Performs various in-depth test on NumberFormat
65 **/
66class 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)
729e4ab9 74 */
b75a7d8f 75 void TestAPI(void);
73c04bcf
A
76
77 void TestCoverage(void);
0f5d89e8 78 void TestLocalizedPatternSymbolCoverage();
73c04bcf 79
b75a7d8f
A
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 **/
46f4442e 99 //void TestDigitList(void);
729e4ab9 100
b75a7d8f
A
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
374ca955
A
127 void TestScientific2(void);
128
129 void TestScientificGrouping(void);
130
131 void TestInt64(void);
132
b75a7d8f
A
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);
729e4ab9 141
b75a7d8f 142 void TestComplexCurrency(void);
729e4ab9 143
b75a7d8f
A
144 void TestPad(void);
145 void TestPatterns2(void);
146
147 /**
148 * Test currency registration.
149 */
150 void TestRegCurrency(void);
151
374ca955
A
152 void TestCurrencyNames(void);
153
73c04bcf
A
154 void TestCurrencyAmount(void);
155
156 void TestCurrencyUnit(void);
157
b75a7d8f
A
158 void TestSymbolsWithBadLocale(void);
159
160 void TestAdoptDecimalFormatSymbols(void);
161
374ca955
A
162 void TestPerMill(void);
163
164 void TestIllegalPatterns(void);
729e4ab9 165
374ca955
A
166 void TestCases(void);
167
73c04bcf
A
168 void TestJB3832(void);
169
170 void TestHost(void);
171
46f4442e
A
172 void TestHostClone(void);
173
73c04bcf 174 void TestCurrencyFormat(void);
729e4ab9 175
46f4442e
A
176 /* Port of ICU4J rounding test. */
177 void TestRounding(void);
178
4388f060
A
179 void TestRoundingPattern(void);
180
46f4442e 181 void TestNonpositiveMultiplier(void);
729e4ab9
A
182
183 void TestNumberingSystems();
184
185
186 void TestSpaceParsing();
187 void TestMultiCurrencySign();
188 void TestCurrencyFormatForMixParsing();
0f5d89e8 189 void TestMismatchedCurrencyFormatFail();
729e4ab9
A
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();
4388f060
A
203 void TestExplicitParents();
204 void TestAvailableNumberingSystems();
205 void Test9087();
51004dcb 206 void TestFormatFastpaths();
4388f060 207
51004dcb
A
208 void TestFormattableSize();
209
57a6839d
A
210 void TestUFormattable();
211
51004dcb 212 void TestEnumSet();
729e4ab9 213
57a6839d
A
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
b331163b 232 void TestCurrencyUsage();
2ca993e8 233
b331163b
A
234 void TestDoubleLimit11439();
235 void TestFastPathConsistent11524();
2ca993e8
A
236 void TestGetAffixes();
237 void TestToPatternScientific11648();
238 void TestBenchmark();
239 void TestCtorApplyPatternDifference();
240 void TestFractionalDigitsForCurrency();
241 void TestFormatCurrencyPlural();
242 void Test11868();
0f5d89e8
A
243 void Test11739_ParseLongCurrency();
244 void Test13035_MultiCodePointPaddingInPattern();
245 void Test13737_ParseScientificStrict();
2ca993e8
A
246 void Test10727_RoundingZero();
247 void Test11376_getAndSetPositivePrefix();
248 void Test11475_signRecognition();
249 void Test11640_getAffixes();
250 void Test11649_toPatternWithMultiCurrency();
0f5d89e8
A
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();
b331163b 283
b75a7d8f 284 private:
57a6839d
A
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);
b75a7d8f
A
288
289 static UBool equalValue(const Formattable& a, const Formattable& b);
290
729e4ab9
A
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
b75a7d8f
A
297 void expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
298
729e4ab9
A
299 void expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
300
b75a7d8f
A
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,
57a6839d
A
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 }
b75a7d8f
A
337
338 void expect(NumberFormat* fmt, const Formattable& n,
339 const char *exp, UErrorCode errorCode) {
57a6839d 340 expect(fmt, n, UnicodeString(exp, ""), TRUE, errorCode);
b75a7d8f
A
341 }
342
343 void expectCurrency(NumberFormat& nf, const Locale& locale,
344 double value, const UnicodeString& string);
345
b75a7d8f
A
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
73c04bcf
A
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
729e4ab9
A
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
b75a7d8f
A
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);
729e4ab9 388
46f4442e
A
389 // internal rounding checking for TestRounding
390 void checkRounding(DecimalFormat* df, double base, int iterations, double increment);
729e4ab9 391
46f4442e 392 double checkRound(DecimalFormat* df, double iValue, double lastParsed);
57a6839d
A
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
2ca993e8
A
403 void verifyFieldPositionIterator(
404 NumberFormatTest_Attributes *expected,
405 FieldPositionIterator &iter);
406
b75a7d8f
A
407};
408
409#endif /* #if !UCONFIG_NO_FORMATTING */
729e4ab9 410
b75a7d8f 411#endif // _NUMBERFORMATTEST_