]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/numfmtst.h
ICU-57165.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / numfmtst.h
1 /************************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2016, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 ************************************************************************/
6
7 #ifndef _NUMBERFORMATTEST_
8 #define _NUMBERFORMATTEST_
9
10 #include "unicode/utypes.h"
11
12 #if !UCONFIG_NO_FORMATTING
13
14 #include "unicode/numfmt.h"
15 #include "unicode/decimfmt.h"
16 #include "caltztst.h"
17
18 /**
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.
24 */
25 struct NumberFormatTest_Attributes {
26 int32_t id;
27 int32_t spos;
28 int32_t epos;
29 };
30
31 /**
32 * Performs various in-depth test on NumberFormat
33 **/
34 class NumberFormatTest: public CalendarTimeZoneTest {
35
36 // IntlTest override
37 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
38 public:
39
40 /**
41 * Test APIs (to increase code coverage)
42 */
43 void TestAPI(void);
44
45 void TestCoverage(void);
46
47 /**
48 * Test the handling of quotes
49 **/
50 void TestQuotes(void);
51 /**
52 * Test patterns with exponential representation
53 **/
54 void TestExponential(void);
55 /**
56 * Test handling of patterns with currency symbols
57 **/
58 void TestCurrencySign(void);
59 /**
60 * Test different format patterns
61 **/
62 void TestPatterns(void);
63 /**
64 * API coverage for DigitList
65 **/
66 //void TestDigitList(void);
67
68 /**
69 * Test localized currency patterns.
70 */
71 void TestCurrency(void);
72
73 /**
74 * Test the Currency object handling, new as of ICU 2.2.
75 */
76 void TestCurrencyObject(void);
77
78 void TestCurrencyPatterns(void);
79
80 /**
81 * Do rudimentary testing of parsing.
82 */
83 void TestParse(void);
84 /**
85 * Test proper rounding by the format method.
86 */
87 void TestRounding487(void);
88
89 // New tests for alphaWorks upgrade
90 void TestExponent(void);
91
92 void TestScientific(void);
93
94 void TestScientific2(void);
95
96 void TestScientificGrouping(void);
97
98 void TestInt64(void);
99
100 void TestSurrogateSupport(void);
101
102 /**
103 * Test the functioning of the secondary grouping value.
104 */
105 void TestSecondaryGrouping(void);
106
107 void TestWhiteSpaceParsing(void);
108
109 void TestComplexCurrency(void);
110
111 void TestPad(void);
112 void TestPatterns2(void);
113
114 /**
115 * Test currency registration.
116 */
117 void TestRegCurrency(void);
118
119 void TestCurrencyNames(void);
120
121 void TestCurrencyAmount(void);
122
123 void TestCurrencyUnit(void);
124
125 void TestSymbolsWithBadLocale(void);
126
127 void TestAdoptDecimalFormatSymbols(void);
128
129 void TestPerMill(void);
130
131 void TestIllegalPatterns(void);
132
133 void TestCases(void);
134
135 void TestJB3832(void);
136
137 void TestHost(void);
138
139 void TestHostClone(void);
140
141 void TestCurrencyFormat(void);
142
143 /* Port of ICU4J rounding test. */
144 void TestRounding(void);
145
146 void TestRoundingPattern(void);
147
148 void TestNonpositiveMultiplier(void);
149
150 void TestNumberingSystems();
151
152
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();
162
163 void TestLenientParse();
164
165 void TestDecimal();
166 void TestCurrencyFractionDigits();
167
168 void TestExponentParse();
169 void TestExplicitParents();
170 void TestAvailableNumberingSystems();
171 void Test9087();
172 void TestFormatFastpaths();
173
174 void TestFormattableSize();
175
176 void TestUFormattable();
177
178 void TestEnumSet();
179
180 void TestSignificantDigits();
181 void TestShowZero();
182
183 void TestCompatibleCurrencies();
184 void TestBug9936();
185 void TestParseNegativeWithFaLocale();
186 void TestParseNegativeWithAlternateMinusSign();
187
188 void TestCustomCurrencySignAndSeparator();
189
190 void TestParseSignsAndMarks();
191 void Test10419RoundingWith0FractionDigits();
192 void Test10468ApplyPattern();
193 void TestRoundingScientific10542();
194 void TestZeroScientific10547();
195 void TestAccountingCurrency();
196 void TestEquality();
197
198 void TestCurrencyUsage();
199 void TestNumberFormatTestTuple();
200 void TestDataDriven();
201
202 void TestDoubleLimit11439();
203 void TestFastPathConsistent11524();
204 void TestGetAffixes();
205 void TestToPatternScientific11648();
206 void TestBenchmark();
207 void TestCtorApplyPatternDifference();
208 void TestFractionalDigitsForCurrency();
209 void TestFormatCurrencyPlural();
210 void Test11868();
211 void Test10727_RoundingZero();
212 void Test11376_getAndSetPositivePrefix();
213 void Test11475_signRecognition();
214 void Test11640_getAffixes();
215 void Test11649_toPatternWithMultiCurrency();
216
217 void checkExceptionIssue11735();
218
219 private:
220 UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
221
222 void expectParseCurrency(const NumberFormat &fmt, const UChar* currency, double amount, const char *text);
223
224 static UBool equalValue(const Formattable& a, const Formattable& b);
225
226 void expectPositions(FieldPositionIterator& iter, int32_t *values, int32_t tupleCount,
227 const UnicodeString& str);
228
229 void expectPosition(FieldPosition& pos, int32_t id, int32_t start, int32_t limit,
230 const UnicodeString& str);
231
232 void expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
233
234 void expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
235
236 void expect2(NumberFormat& fmt, const Formattable& n, const char* str) {
237 expect2(fmt, n, UnicodeString(str, ""));
238 }
239
240 void expect2(NumberFormat* fmt, const Formattable& n, const UnicodeString& str, UErrorCode ec);
241
242 void expect2(NumberFormat* fmt, const Formattable& n, const char* str, UErrorCode ec) {
243 expect2(fmt, n, UnicodeString(str, ""), ec);
244 }
245
246 void expect(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
247
248 void expect(NumberFormat& fmt, const char *str, const Formattable& n) {
249 expect(fmt, UnicodeString(str, ""), n);
250 }
251
252 void expect(NumberFormat& fmt, const Formattable& n,
253 const UnicodeString& exp, UBool rt=TRUE);
254
255 void expect(NumberFormat& fmt, const Formattable& n,
256 const char *exp, UBool rt=TRUE) {
257 expect(fmt, n, UnicodeString(exp, ""), rt);
258 }
259
260 void expect(NumberFormat* fmt, const Formattable& n,
261 const UnicodeString& exp, UBool rt, UErrorCode errorCode);
262
263 void expect(NumberFormat* fmt, const Formattable& n,
264 const char *exp, UBool rt, UErrorCode errorCode) {
265 expect(fmt, n, UnicodeString(exp, ""), rt, errorCode);
266 }
267
268 void expect(NumberFormat* fmt, const Formattable& n,
269 const UnicodeString& exp, UErrorCode errorCode) {
270 expect(fmt, n, exp, TRUE, errorCode);
271 }
272
273 void expect(NumberFormat* fmt, const Formattable& n,
274 const char *exp, UErrorCode errorCode) {
275 expect(fmt, n, UnicodeString(exp, ""), TRUE, errorCode);
276 }
277
278 void expectCurrency(NumberFormat& nf, const Locale& locale,
279 double value, const UnicodeString& string);
280
281 void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
282 int32_t pos, int32_t width, UChar pad);
283
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);
287 }
288
289 void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
290 int32_t pos, int32_t width, const UnicodeString& pad);
291
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);
295 }
296
297 void expectPat(DecimalFormat& fmt, const UnicodeString& exp);
298
299 void expectPat(DecimalFormat& fmt, const char *exp) {
300 expectPat(fmt, UnicodeString(exp, ""));
301 }
302
303 void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
304 int32_t pos);
305
306 void expectPad(DecimalFormat& fmt, const char *pat,
307 int32_t pos) {
308 expectPad(fmt, pat, pos, 0, (UChar)0);
309 }
310
311 void expect_rbnf(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
312
313 void expect_rbnf(NumberFormat& fmt, const Formattable& n,
314 const UnicodeString& exp, UBool rt=TRUE);
315
316 // internal utility routine
317 static UnicodeString& escape(UnicodeString& s);
318
319 enum { ILLEGAL = -1 };
320
321 // internal subtest used by TestRounding487
322 void roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected);
323
324 // internal rounding checking for TestRounding
325 void checkRounding(DecimalFormat* df, double base, int iterations, double increment);
326
327 double checkRound(DecimalFormat* df, double iValue, double lastParsed);
328
329 void verifyRounding(
330 DecimalFormat& format,
331 const double *values,
332 const char * const *expected,
333 const DecimalFormat::ERoundingMode *roundingModes,
334 const char * const *descriptions,
335 int32_t valueSize,
336 int32_t roundingModeSize);
337
338 void verifyFieldPositionIterator(
339 NumberFormatTest_Attributes *expected,
340 FieldPositionIterator &iter);
341
342 };
343
344 #endif /* #if !UCONFIG_NO_FORMATTING */
345
346 #endif // _NUMBERFORMATTEST_