1 /************************************************************************ 2 * COPYRIGHT: 3 * Copyright (c) 1997-2011, 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 TestNonpositiveMultiplier(void); 134 135 void TestNumberingSystems(); 136 137 138 void TestSpaceParsing(); 139 void TestMultiCurrencySign(); 140 void TestCurrencyFormatForMixParsing(); 141 void TestDecimalFormatCurrencyParse(); 142 void TestCurrencyIsoPluralFormat(); 143 void TestCurrencyParsing(); 144 void TestParseCurrencyInUCurr(); 145 void TestFormatAttributes(); 146 void TestFieldPositionIterator(); 147 148 void TestLenientParse(); 149 150 void TestDecimal(); 151 void TestCurrencyFractionDigits(); 152 153 void TestExponentParse(); 154 void TestExplicitParents(); 155 156 private: 157 158 static UBool equalValue(const Formattable& a, const Formattable& b); 159 160 void expectPositions(FieldPositionIterator& iter, int32_t *values, int32_t tupleCount, 161 const UnicodeString& str); 162 163 void expectPosition(FieldPosition& pos, int32_t id, int32_t start, int32_t limit, 164 const UnicodeString& str); 165 166 void expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str); 167 168 void expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str); 169 expect2(NumberFormat & fmt,const Formattable & n,const char * str)170 void expect2(NumberFormat& fmt, const Formattable& n, const char* str) { 171 expect2(fmt, n, UnicodeString(str, "")); 172 } 173 174 void expect2(NumberFormat* fmt, const Formattable& n, const UnicodeString& str, UErrorCode ec); 175 expect2(NumberFormat * fmt,const Formattable & n,const char * str,UErrorCode ec)176 void expect2(NumberFormat* fmt, const Formattable& n, const char* str, UErrorCode ec) { 177 expect2(fmt, n, UnicodeString(str, ""), ec); 178 } 179 180 void expect(NumberFormat& fmt, const UnicodeString& str, const Formattable& n); 181 expect(NumberFormat & fmt,const char * str,const Formattable & n)182 void expect(NumberFormat& fmt, const char *str, const Formattable& n) { 183 expect(fmt, UnicodeString(str, ""), n); 184 } 185 186 void expect(NumberFormat& fmt, const Formattable& n, 187 const UnicodeString& exp, UBool rt=TRUE); 188 189 void expect(NumberFormat& fmt, const Formattable& n, 190 const char *exp, UBool rt=TRUE) { 191 expect(fmt, n, UnicodeString(exp, ""), rt); 192 } 193 194 void expect(NumberFormat* fmt, const Formattable& n, 195 const UnicodeString& exp, UErrorCode); 196 expect(NumberFormat * fmt,const Formattable & n,const char * exp,UErrorCode errorCode)197 void expect(NumberFormat* fmt, const Formattable& n, 198 const char *exp, UErrorCode errorCode) { 199 expect(fmt, n, UnicodeString(exp, ""), errorCode); 200 } 201 202 void expectCurrency(NumberFormat& nf, const Locale& locale, 203 double value, const UnicodeString& string); 204 205 void expectPad(DecimalFormat& fmt, const UnicodeString& pat, 206 int32_t pos, int32_t width, UChar pad); 207 expectPad(DecimalFormat & fmt,const char * pat,int32_t pos,int32_t width,UChar pad)208 void expectPad(DecimalFormat& fmt, const char *pat, 209 int32_t pos, int32_t width, UChar pad) { 210 expectPad(fmt, UnicodeString(pat, ""), pos, width, pad); 211 } 212 213 void expectPad(DecimalFormat& fmt, const UnicodeString& pat, 214 int32_t pos, int32_t width, const UnicodeString& pad); 215 expectPad(DecimalFormat & fmt,const char * pat,int32_t pos,int32_t width,const UnicodeString & pad)216 void expectPad(DecimalFormat& fmt, const char *pat, 217 int32_t pos, int32_t width, const UnicodeString& pad) { 218 expectPad(fmt, UnicodeString(pat, ""), pos, width, pad); 219 } 220 221 void expectPat(DecimalFormat& fmt, const UnicodeString& exp); 222 expectPat(DecimalFormat & fmt,const char * exp)223 void expectPat(DecimalFormat& fmt, const char *exp) { 224 expectPat(fmt, UnicodeString(exp, "")); 225 } 226 227 void expectPad(DecimalFormat& fmt, const UnicodeString& pat, 228 int32_t pos); 229 expectPad(DecimalFormat & fmt,const char * pat,int32_t pos)230 void expectPad(DecimalFormat& fmt, const char *pat, 231 int32_t pos) { 232 expectPad(fmt, pat, pos, 0, (UChar)0); 233 } 234 235 void expect_rbnf(NumberFormat& fmt, const UnicodeString& str, const Formattable& n); 236 237 void expect_rbnf(NumberFormat& fmt, const Formattable& n, 238 const UnicodeString& exp, UBool rt=TRUE); 239 240 // internal utility routine 241 static UnicodeString& escape(UnicodeString& s); 242 243 enum { ILLEGAL = -1 }; 244 245 // internal subtest used by TestRounding487 246 void roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected); 247 248 // internal rounding checking for TestRounding 249 void checkRounding(DecimalFormat* df, double base, int iterations, double increment); 250 251 double checkRound(DecimalFormat* df, double iValue, double lastParsed); 252 }; 253 254 #endif /* #if !UCONFIG_NO_FORMATTING */ 255 256 #endif // _NUMBERFORMATTEST_ 257