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