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