• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /************************************************************************
2  * COPYRIGHT:
3  * Copyright (c) 1997-2012, 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  * 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)
29      */
30     void TestAPI(void);
31 
32     void TestCoverage(void);
33 
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      **/
53     //void TestDigitList(void);
54 
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 
81     void TestScientific2(void);
82 
83     void TestScientificGrouping(void);
84 
85     void TestInt64(void);
86 
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);
95 
96     void TestComplexCurrency(void);
97 
98     void TestPad(void);
99     void TestPatterns2(void);
100 
101     /**
102      * Test currency registration.
103      */
104     void TestRegCurrency(void);
105 
106     void TestCurrencyNames(void);
107 
108     void TestCurrencyAmount(void);
109 
110     void TestCurrencyUnit(void);
111 
112     void TestSymbolsWithBadLocale(void);
113 
114     void TestAdoptDecimalFormatSymbols(void);
115 
116     void TestPerMill(void);
117 
118     void TestIllegalPatterns(void);
119 
120     void TestCases(void);
121 
122     void TestJB3832(void);
123 
124     void TestHost(void);
125 
126     void TestHostClone(void);
127 
128     void TestCurrencyFormat(void);
129 
130     /* Port of ICU4J rounding test. */
131     void TestRounding(void);
132 
133     void TestRoundingPattern(void);
134 
135     void TestNonpositiveMultiplier(void);
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();
156     void TestExplicitParents();
157     void TestAvailableNumberingSystems();
158     void Test9087();
159     void TestFormatFastpaths();
160 
161     void TestFormattableSize();
162 
163     void TestEnumSet();
164 
165  private:
166 
167     static UBool equalValue(const Formattable& a, const Formattable& b);
168 
169     void expectPositions(FieldPositionIterator& iter, int32_t *values, int32_t tupleCount,
170                          const UnicodeString& str);
171 
172     void expectPosition(FieldPosition& pos, int32_t id, int32_t start, int32_t limit,
173                         const UnicodeString& str);
174 
175     void expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
176 
177     void expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);
178 
expect2(NumberFormat & fmt,const Formattable & n,const char * str)179     void expect2(NumberFormat& fmt, const Formattable& n, const char* str) {
180         expect2(fmt, n, UnicodeString(str, ""));
181     }
182 
183     void expect2(NumberFormat* fmt, const Formattable& n, const UnicodeString& str, UErrorCode ec);
184 
expect2(NumberFormat * fmt,const Formattable & n,const char * str,UErrorCode ec)185     void expect2(NumberFormat* fmt, const Formattable& n, const char* str, UErrorCode ec) {
186         expect2(fmt, n, UnicodeString(str, ""), ec);
187     }
188 
189     void expect(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
190 
expect(NumberFormat & fmt,const char * str,const Formattable & n)191     void expect(NumberFormat& fmt, const char *str, const Formattable& n) {
192         expect(fmt, UnicodeString(str, ""), n);
193     }
194 
195     void expect(NumberFormat& fmt, const Formattable& n,
196                 const UnicodeString& exp, UBool rt=TRUE);
197 
198     void expect(NumberFormat& fmt, const Formattable& n,
199                 const char *exp, UBool rt=TRUE) {
200         expect(fmt, n, UnicodeString(exp, ""), rt);
201     }
202 
203     void expect(NumberFormat* fmt, const Formattable& n,
204                 const UnicodeString& exp, UErrorCode);
205 
expect(NumberFormat * fmt,const Formattable & n,const char * exp,UErrorCode errorCode)206     void expect(NumberFormat* fmt, const Formattable& n,
207                 const char *exp, UErrorCode errorCode) {
208         expect(fmt, n, UnicodeString(exp, ""), errorCode);
209     }
210 
211     void expectCurrency(NumberFormat& nf, const Locale& locale,
212                         double value, const UnicodeString& string);
213 
214     void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
215                    int32_t pos, int32_t width, UChar pad);
216 
expectPad(DecimalFormat & fmt,const char * pat,int32_t pos,int32_t width,UChar pad)217     void expectPad(DecimalFormat& fmt, const char *pat,
218                    int32_t pos, int32_t width, UChar pad) {
219         expectPad(fmt, UnicodeString(pat, ""), pos, width, pad);
220     }
221 
222     void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
223                    int32_t pos, int32_t width, const UnicodeString& pad);
224 
expectPad(DecimalFormat & fmt,const char * pat,int32_t pos,int32_t width,const UnicodeString & pad)225     void expectPad(DecimalFormat& fmt, const char *pat,
226                    int32_t pos, int32_t width, const UnicodeString& pad) {
227         expectPad(fmt, UnicodeString(pat, ""), pos, width, pad);
228     }
229 
230     void expectPat(DecimalFormat& fmt, const UnicodeString& exp);
231 
expectPat(DecimalFormat & fmt,const char * exp)232     void expectPat(DecimalFormat& fmt, const char *exp) {
233         expectPat(fmt, UnicodeString(exp, ""));
234     }
235 
236     void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
237                    int32_t pos);
238 
expectPad(DecimalFormat & fmt,const char * pat,int32_t pos)239     void expectPad(DecimalFormat& fmt, const char *pat,
240                    int32_t pos) {
241         expectPad(fmt, pat, pos, 0, (UChar)0);
242     }
243 
244     void expect_rbnf(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);
245 
246     void expect_rbnf(NumberFormat& fmt, const Formattable& n,
247                 const UnicodeString& exp, UBool rt=TRUE);
248 
249     // internal utility routine
250     static UnicodeString& escape(UnicodeString& s);
251 
252     enum { ILLEGAL = -1 };
253 
254     // internal subtest used by TestRounding487
255     void roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected);
256 
257     // internal rounding checking for TestRounding
258     void checkRounding(DecimalFormat* df, double base, int iterations, double increment);
259 
260     double checkRound(DecimalFormat* df, double iValue, double lastParsed);
261 };
262 
263 #endif /* #if !UCONFIG_NO_FORMATTING */
264 
265 #endif // _NUMBERFORMATTEST_
266