File: numfmtst.h

package info (click to toggle)
icu 78.2-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 123,988 kB
  • sloc: cpp: 527,891; ansic: 112,789; sh: 4,983; makefile: 4,657; perl: 3,199; python: 2,933; xml: 749; sed: 36; lisp: 12
file content (443 lines) | stat: -rw-r--r-- 13,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/************************************************************************
 * COPYRIGHT:
 * Copyright (c) 1997-2016, International Business Machines Corporation
 * and others. All Rights Reserved.
 ************************************************************************/

#ifndef _NUMBERFORMATTEST_
#define _NUMBERFORMATTEST_

#include "unicode/utypes.h"

#if !UCONFIG_NO_FORMATTING

#include "unicode/numfmt.h"
#include "unicode/decimfmt.h"
#include "caltztst.h"
#include "datadrivennumberformattestsuite.h"

/**
 * Expected field positions from field position iterator. Tests should
 * stack allocate an array of these making sure that the last element is
 * {0, -1, 0} (The sentinel element indicating end of iterator). Then test
 * should call verifyFieldPositionIterator() passing both this array of
 * expected results and the field position iterator from the format method.
 */
struct NumberFormatTest_Attributes {
    int32_t id;
    int32_t spos;
    int32_t epos;
};


/**
 * Header for the data-driven test, powered by numberformattestspecification.txt
 */
class NumberFormatDataDrivenTest : public DataDrivenNumberFormatTestSuite {
  public:
    void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ) override;
    void TestNumberFormatTestTuple();
    void TestDataDrivenICU4C();

  protected:
    UBool isFormatPass(
            const NumberFormatTestTuple &tuple,
            UnicodeString &appendErrorMessage,
            UErrorCode &status) override;
    UBool isToPatternPass(
            const NumberFormatTestTuple &tuple,
            UnicodeString &appendErrorMessage,
            UErrorCode &status) override;
    UBool isParsePass(
            const NumberFormatTestTuple &tuple,
            UnicodeString &appendErrorMessage,
            UErrorCode &status) override;
    UBool isParseCurrencyPass(
            const NumberFormatTestTuple &tuple,
            UnicodeString &appendErrorMessage,
            UErrorCode &status) override;
};

/**
 * Performs various in-depth test on NumberFormat
 **/
class NumberFormatTest: public CalendarTimeZoneTest {

    // IntlTest override
    void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ) override;
 public:

    /**
     * Test APIs (to increase code coverage)
     */
    void TestAPI();

    void TestCoverage();
    void TestLocalizedPatternSymbolCoverage();

    /**
     * Test the handling of quotes
     **/
    void TestQuotes();
    /**
     * Test patterns with exponential representation
     **/
    void TestExponential();
    /**
     * Test handling of patterns with currency symbols
     **/
    void TestCurrencySign();
    /**
     * Test different format patterns
     **/
    void TestPatterns();
    /**
     * API coverage for DigitList
     **/
    //void TestDigitList();

    void Test20186_SpacesAroundSemicolon();

    /**
     * Test localized currency patterns.
     */
    void TestCurrency();

    /**
     * Test the Currency object handling, new as of ICU 2.2.
     */
    void TestCurrencyObject();

    void TestCurrencyPatterns();

    /**
     * Do rudimentary testing of parsing.
     */
    void TestParse();
    /**
     * Test proper rounding by the format method.
     */
    void TestRounding487();

    // New tests for alphaWorks upgrade
    void TestExponent();

    void TestScientific();

    void TestScientific2();

    void TestScientificGrouping();

    void TestInt64();

    void TestSurrogateSupport();

    /**
     * Test the functioning of the secondary grouping value.
     */
    void TestSecondaryGrouping();

    void TestWhiteSpaceParsing();

    void TestComplexCurrency();

    void TestPad();
    void TestPatterns2();

    /**
     * Test currency registration.
     */
    void TestRegCurrency();

    void TestCurrencyNames();

    void TestCurrencyVariants();

    void TestCurrencyAmount();

    void TestCurrencyUnit();

    void TestSymbolsWithBadLocale();

    void TestAdoptDecimalFormatSymbols();

    void TestPerMill();

    void TestIllegalPatterns();

    void TestCases();

    void TestJB3832();

    void TestHost();

    void TestHostClone();

    void TestCurrencyFormat();

    /* Port of ICU4J rounding test. */
    void TestRounding();

    void TestRoundingPattern();

    void TestNonpositiveMultiplier();

    void TestNumberingSystems();


    void TestSpaceParsing();
    void TestMultiCurrencySign();
    void TestCurrencyFormatForMixParsing();
    void TestMismatchedCurrencyFormatFail();
    void TestDecimalFormatCurrencyParse();
    void TestCurrencyIsoPluralFormat();
    void TestCurrencyParsing();
    void TestParseCurrencyInUCurr();
    void TestFormatAttributes();
    void TestFieldPositionIterator();

    void TestLenientParse();

    void TestDecimal();
    void TestDecimalFormatParse7E();
    void TestCurrencyFractionDigits();

    void TestExponentParse();
    void TestExplicitParents();
    void TestAvailableNumberingSystems();
    void Test9087();
    void TestFormatFastpaths();

    void TestFormattableSize();

    void TestUFormattable();

    void TestEnumSet();

    void TestSignificantDigits();
    void TestShowZero();

    void TestCompatibleCurrencies();
    void TestBug9936();
    void TestParseNegativeWithFaLocale();
    void TestParseNegativeWithAlternateMinusSign();

    void TestCustomCurrencySignAndSeparator();

    void TestParseSignsAndMarks();
    void Test10419RoundingWith0FractionDigits();
    void Test10468ApplyPattern();
    void TestRoundingScientific10542();
    void TestZeroScientific10547();
    void TestAccountingCurrency();
    void TestCurrencyFormatForMissingLocale();
    void TestEquality();

    void TestCurrencyUsage();

    void TestDoubleLimit11439();
    void TestFastPathConsistent11524();
    void TestGetAffixes();
    void TestToPatternScientific11648();
    void TestBenchmark();
    void TestCtorApplyPatternDifference();
    void TestFractionalDigitsForCurrency();
    void TestFormatCurrencyPlural();
    void Test11868();
    void Test11739_ParseLongCurrency();
    void Test13035_MultiCodePointPaddingInPattern();
    void Test13737_ParseScientificStrict();
    void Test10727_RoundingZero();
    void Test11376_getAndSetPositivePrefix();
    void Test11475_signRecognition();
    void Test11640_getAffixes();
    void Test11649_toPatternWithMultiCurrency();
    void Test13327_numberingSystemBufferOverflow();
    void Test13391_chakmaParsing();

    void Test11735_ExceptionIssue();
    void Test11035_FormatCurrencyAmount();
    void Test11318_DoubleConversion();
    void TestParsePercentRegression();
    void TestMultiplierWithScale();
    void TestFastFormatInt32();
    void Test11646_Equality();
    void TestParseNaN();
    void TestFormatFailIfMoreThanMaxDigits();
    void TestParseCaseSensitive();
    void TestParseNoExponent();
    void TestSignAlwaysShown();
    void TestMinimumGroupingDigits();
    void Test11897_LocalizedPatternSeparator();
    void Test13055_PercentageRounding();
    void Test11839();
    void Test10354();
    void Test11645_ApplyPatternEquality();
    void Test12567();
    void Test11626_CustomizeCurrencyPluralInfo();
    void Test20073_StrictPercentParseErrorIndex();
    void Test13056_GroupingSize();
    void Test11025_CurrencyPadding();
    void Test11648_ExpDecFormatMalPattern();
    void Test11649_DecFmtCurrencies();
    void Test13148_ParseGroupingSeparators();
    void Test12753_PatternDecimalPoint();
    void Test22303_PatternDecimalPoint_InfNaN();
    void Test11647_PatternCurrencySymbols();
    void Test11913_BigDecimal();
    void Test11020_RoundingInScientificNotation();
    void Test11640_TripleCurrencySymbol();
    void Test13763_FieldPositionIteratorOffset();
    void Test13777_ParseLongNameNonCurrencyMode();
    void Test13804_EmptyStringsWhenParsing();
    void Test20037_ScientificIntegerOverflow();
    void Test13840_ParseLongStringCrash();
    void Test13850_EmptyStringCurrency();
    void Test20348_CurrencyPrefixOverride();
    void Test20956_MonetarySymbolGetters();
    void Test20358_GroupingInPattern();
    void Test13731_DefaultCurrency();
    void Test20499_CurrencyVisibleDigitsPlural();
    void Test13735_GroupingSizeGetter();
    void Test13734_StrictFlexibleWhitespace();
    void Test20961_CurrencyPluralPattern();
    void Test21134_ToNumberFormatter();
    void Test13733_StrictAndLenient();
    void Test20425_IntegerIncrement();
    void Test20425_FractionWithIntegerIncrement();
    void Test21232_ParseTimeout();
    void Test10997_FormatCurrency();
    void Test21556_CurrencyAsDecimal();
    void Test22088_Ethiopic();
    void Test22983_LongFraction();

 private:
    UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);

    void expectParseCurrency(const NumberFormat &fmt, const char16_t* currency, double amount, const char *text);

    static UBool equalValue(const Formattable& a, const Formattable& b);

    void expectPositions(FieldPositionIterator& iter, int32_t *values, int32_t tupleCount,
                         const UnicodeString& str);

    void expectPosition(FieldPosition& pos, int32_t id, int32_t start, int32_t limit,
                        const UnicodeString& str);

    void expect2(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);

    void expect3(NumberFormat& fmt, const Formattable& n, const UnicodeString& str);

    void expect2(NumberFormat& fmt, const Formattable& n, const char* str) {
        expect2(fmt, n, UnicodeString(str, ""));
    }

    void expect2(NumberFormat* fmt, const Formattable& n, const UnicodeString& str, UErrorCode ec);

    void expect2(NumberFormat* fmt, const Formattable& n, const char* str, UErrorCode ec) {
        expect2(fmt, n, UnicodeString(str, ""), ec);
    }

    void expect(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);

    void expect(NumberFormat& fmt, const char *str, const Formattable& n) {
        expect(fmt, UnicodeString(str, ""), n);
    }

    void expect(NumberFormat& fmt, const Formattable& n,
                const UnicodeString& exp, UBool rt=true);

    void expect(NumberFormat& fmt, const Formattable& n,
                const char *exp, UBool rt=true) {
        expect(fmt, n, UnicodeString(exp, ""), rt);
    }

    void expect(NumberFormat* fmt, const Formattable& n,
                const UnicodeString& exp, UBool rt, UErrorCode errorCode);

    void expect(NumberFormat* fmt, const Formattable& n,
                const char *exp, UBool rt, UErrorCode errorCode) {
        expect(fmt, n, UnicodeString(exp, ""), rt, errorCode);
    }

    void expect(NumberFormat* fmt, const Formattable& n,
                const UnicodeString& exp, UErrorCode errorCode) {
        expect(fmt, n, exp, true, errorCode);
    }

    void expect(NumberFormat* fmt, const Formattable& n,
                const char *exp, UErrorCode errorCode) {
        expect(fmt, n, UnicodeString(exp, ""), true, errorCode);
    }

    void expectCurrency(NumberFormat& nf, const Locale& locale,
                        double value, const UnicodeString& string);

    void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
                   int32_t pos, int32_t width, char16_t pad);

    void expectPad(DecimalFormat& fmt, const char *pat,
                   int32_t pos, int32_t width, char16_t pad) {
        expectPad(fmt, UnicodeString(pat, ""), pos, width, pad);
    }

    void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
                   int32_t pos, int32_t width, const UnicodeString& pad);

    void expectPad(DecimalFormat& fmt, const char *pat,
                   int32_t pos, int32_t width, const UnicodeString& pad) {
        expectPad(fmt, UnicodeString(pat, ""), pos, width, pad);
    }

    void expectPat(DecimalFormat& fmt, const UnicodeString& exp);

    void expectPat(DecimalFormat& fmt, const char *exp) {
        expectPat(fmt, UnicodeString(exp, ""));
    }

    void expectPad(DecimalFormat& fmt, const UnicodeString& pat,
                   int32_t pos);

    void expectPad(DecimalFormat& fmt, const char *pat,
                   int32_t pos) {
        expectPad(fmt, pat, pos, 0, static_cast<char16_t>(0));
    }

    void expect_rbnf(NumberFormat& fmt, const UnicodeString& str, const Formattable& n);

    void expect_rbnf(NumberFormat& fmt, const Formattable& n,
                const UnicodeString& exp, UBool rt=true);

    // internal utility routine
    static UnicodeString& escape(UnicodeString& s);

    enum { ILLEGAL = -1 };

    // internal subtest used by TestRounding487
    void roundingTest(NumberFormat& nf, double x, int32_t maxFractionDigits, const char* expected);

    // internal rounding checking for TestRounding
    void checkRounding(DecimalFormat* df, double base, int iterations, double increment);

    double checkRound(DecimalFormat* df, double iValue, double lastParsed);

    void verifyRounding(
        DecimalFormat& format,
        const double *values,
        const char * const *expected,
        const DecimalFormat::ERoundingMode *roundingModes,
        const char * const *descriptions,
        int32_t valueSize,
        int32_t roundingModeSize);

    void verifyFieldPositionIterator(
            NumberFormatTest_Attributes *expected,
            FieldPositionIterator &iter);

};

#endif /* #if !UCONFIG_NO_FORMATTING */

#endif // _NUMBERFORMATTEST_