]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/test/intltest/numbertest.h
ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / numbertest.h
... / ...
CommitLineData
1// © 2017 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3
4#include "unicode/utypes.h"
5
6#if !UCONFIG_NO_FORMATTING
7#pragma once
8
9#include "number_stringbuilder.h"
10#include "intltest.h"
11#include "number_affixutils.h"
12#include "numparse_stringsegment.h"
13#include "unicode/locid.h"
14
15using namespace icu::number;
16using namespace icu::number::impl;
17using namespace icu::numparse;
18using namespace icu::numparse::impl;
19
20////////////////////////////////////////////////////////////////////////////////////////
21// INSTRUCTIONS: //
22// To add new NumberFormat unit test classes, create a new class like the ones below, //
23// and then add it as a switch statement in NumberTest at the bottom of this file. /////////
24// To add new methods to existing unit test classes, add the method to the class declaration //
25// below, and also add it to the class's implementation of runIndexedTest(). //
26///////////////////////////////////////////////////////////////////////////////////////////////
27
28class AffixUtilsTest : public IntlTest {
29 public:
30 void testEscape();
31 void testUnescape();
32 void testContainsReplaceType();
33 void testInvalid();
34 void testUnescapeWithSymbolProvider();
35
36 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
37
38 private:
39 UnicodeString unescapeWithDefaults(const SymbolProvider &defaultProvider, UnicodeString input,
40 UErrorCode &status);
41};
42
43class NumberFormatterApiTest : public IntlTest {
44 public:
45 NumberFormatterApiTest();
46 NumberFormatterApiTest(UErrorCode &status);
47
48 void notationSimple();
49 void notationScientific();
50 void notationCompact();
51 void unitMeasure();
52 void unitCompoundMeasure();
53 void unitCurrency();
54 void unitPercent();
55 void roundingFraction();
56 void roundingFigures();
57 void roundingFractionFigures();
58 void roundingOther();
59 void grouping();
60 void padding();
61 void integerWidth();
62 void symbols();
63 // TODO: Add this method if currency symbols override support is added.
64 //void symbolsOverride();
65 void sign();
66 void decimal();
67 void scale();
68 void locale();
69 void formatTypes();
70 void fieldPosition();
71 void toFormat();
72 void errors();
73 void validRanges();
74 void copyMove();
75 void localPointerCAPI();
76
77 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
78
79 private:
80 CurrencyUnit USD;
81 CurrencyUnit GBP;
82 CurrencyUnit CZK;
83 CurrencyUnit CAD;
84 CurrencyUnit ESP;
85 CurrencyUnit PTE;
86
87 MeasureUnit METER;
88 MeasureUnit DAY;
89 MeasureUnit SQUARE_METER;
90 MeasureUnit FAHRENHEIT;
91 MeasureUnit SECOND;
92 MeasureUnit POUND;
93 MeasureUnit SQUARE_MILE;
94 MeasureUnit JOULE;
95 MeasureUnit FURLONG;
96 MeasureUnit KELVIN;
97
98 NumberingSystem MATHSANB;
99 NumberingSystem LATN;
100
101 DecimalFormatSymbols FRENCH_SYMBOLS;
102 DecimalFormatSymbols SWISS_SYMBOLS;
103 DecimalFormatSymbols MYANMAR_SYMBOLS;
104
105 void assertFormatDescending(const char16_t* message, const char16_t* skeleton,
106 const UnlocalizedNumberFormatter& f, Locale locale, ...);
107
108 void assertFormatDescendingBig(const char16_t* message, const char16_t* skeleton,
109 const UnlocalizedNumberFormatter& f, Locale locale, ...);
110
111 void assertFormatSingle(const char16_t* message, const char16_t* skeleton,
112 const UnlocalizedNumberFormatter& f, Locale locale, double input,
113 const UnicodeString& expected);
114
115 void assertUndefinedSkeleton(const UnlocalizedNumberFormatter& f);
116};
117
118class DecimalQuantityTest : public IntlTest {
119 public:
120 void testDecimalQuantityBehaviorStandalone();
121 void testSwitchStorage();
122 void testCopyMove();
123 void testAppend();
124 void testConvertToAccurateDouble();
125 void testUseApproximateDoubleWhenAble();
126 void testHardDoubleConversion();
127 void testToDouble();
128 void testMaxDigits();
129
130 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
131
132 private:
133 void assertDoubleEquals(UnicodeString message, double a, double b);
134 void assertHealth(const DecimalQuantity &fq);
135 void assertToStringAndHealth(const DecimalQuantity &fq, const UnicodeString &expected);
136 void checkDoubleBehavior(double d, bool explicitRequired);
137};
138
139class DoubleConversionTest : public IntlTest {
140 public:
141 void testDoubleConversionApi();
142
143 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
144};
145
146class ModifiersTest : public IntlTest {
147 public:
148 void testConstantAffixModifier();
149 void testConstantMultiFieldModifier();
150 void testSimpleModifier();
151 void testCurrencySpacingEnabledModifier();
152
153 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
154
155 private:
156 void assertModifierEquals(const Modifier &mod, int32_t expectedPrefixLength, bool expectedStrong,
157 UnicodeString expectedChars, UnicodeString expectedFields,
158 UErrorCode &status);
159
160 void assertModifierEquals(const Modifier &mod, NumberStringBuilder &sb, int32_t expectedPrefixLength,
161 bool expectedStrong, UnicodeString expectedChars,
162 UnicodeString expectedFields, UErrorCode &status);
163};
164
165class PatternModifierTest : public IntlTest {
166 public:
167 void testBasic();
168 void testPatternWithNoPlaceholder();
169 void testMutableEqualsImmutable();
170
171 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
172
173 private:
174 UnicodeString getPrefix(const MutablePatternModifier &mod, UErrorCode &status);
175 UnicodeString getSuffix(const MutablePatternModifier &mod, UErrorCode &status);
176};
177
178class PatternStringTest : public IntlTest {
179 public:
180 void testLocalized();
181 void testToPatternSimple();
182 void testExceptionOnInvalid();
183 void testBug13117();
184
185 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
186
187 private:
188};
189
190class NumberStringBuilderTest : public IntlTest {
191 public:
192 void testInsertAppendUnicodeString();
193 void testSplice();
194 void testInsertAppendCodePoint();
195 void testCopy();
196 void testFields();
197 void testUnlimitedCapacity();
198 void testCodePoints();
199
200 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
201
202 private:
203 void assertEqualsImpl(const UnicodeString &a, const NumberStringBuilder &b);
204};
205
206class StringSegmentTest : public IntlTest {
207 public:
208 void testOffset();
209 void testLength();
210 void testCharAt();
211 void testGetCodePoint();
212 void testCommonPrefixLength();
213
214 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
215};
216
217class NumberParserTest : public IntlTest {
218 public:
219 void testBasic();
220 void testLocaleFi();
221 void testSeriesMatcher();
222 void testCombinedCurrencyMatcher();
223 void testAffixPatternMatcher();
224 void testGroupingDisabled();
225 void testCaseFolding();
226
227 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
228};
229
230class NumberSkeletonTest : public IntlTest {
231 public:
232 void validTokens();
233 void invalidTokens();
234 void unknownTokens();
235 void unexpectedTokens();
236 void duplicateValues();
237 void stemsRequiringOption();
238 void defaultTokens();
239 void flexibleSeparators();
240
241 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
242
243 private:
244 void expectedErrorSkeleton(const char16_t** cases, int32_t casesLen);
245};
246
247
248// NOTE: This macro is identical to the one in itformat.cpp
249#define TESTCLASS(id, TestClass) \
250 case id: \
251 name = #TestClass; \
252 if (exec) { \
253 logln(#TestClass " test---"); \
254 logln((UnicodeString)""); \
255 TestClass test; \
256 callTest(test, par); \
257 } \
258 break
259
260class NumberTest : public IntlTest {
261 public:
262 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0) {
263 if (exec) {
264 logln("TestSuite NumberTest: ");
265 }
266
267 switch (index) {
268 TESTCLASS(0, AffixUtilsTest);
269 TESTCLASS(1, NumberFormatterApiTest);
270 TESTCLASS(2, DecimalQuantityTest);
271 TESTCLASS(3, ModifiersTest);
272 TESTCLASS(4, PatternModifierTest);
273 TESTCLASS(5, PatternStringTest);
274 TESTCLASS(6, NumberStringBuilderTest);
275 TESTCLASS(7, DoubleConversionTest);
276 TESTCLASS(8, StringSegmentTest);
277 TESTCLASS(9, NumberParserTest);
278 TESTCLASS(10, NumberSkeletonTest);
279 default: name = ""; break; // needed to end loop
280 }
281 }
282};
283
284#endif /* #if !UCONFIG_NO_FORMATTING */