1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5* Copyright (C) 2015, International Business Machines Corporation and         *
6* others. All Rights Reserved.                                                *
7*******************************************************************************
8*/
9#ifndef _NUMBER_FORMAT_TEST_TUPLE
10#define _NUMBER_FORMAT_TEST_TUPLE
11
12#include "unicode/utypes.h"
13
14#if !UCONFIG_NO_FORMATTING
15
16#include "decimalformatpattern.h"
17#include "unicode/decimfmt.h"
18#include "unicode/ucurr.h"
19
20#define NFTT_GET_FIELD(tuple, fieldName, defaultValue) ((tuple).fieldName##Flag ? (tuple).fieldName : (defaultValue))
21
22U_NAMESPACE_USE
23
24enum ENumberFormatTestTupleField {
25    kLocale,
26    kCurrency,
27    kPattern,
28    kFormat,
29    kOutput,
30    kComment,
31    kMinIntegerDigits,
32    kMaxIntegerDigits,
33    kMinFractionDigits,
34    kMaxFractionDigits,
35    kMinGroupingDigits,
36    kBreaks,
37    kUseSigDigits,
38    kMinSigDigits,
39    kMaxSigDigits,
40    kUseGrouping,
41    kMultiplier,
42    kRoundingIncrement,
43    kFormatWidth,
44    kPadCharacter,
45    kUseScientific,
46    kGrouping,
47    kGrouping2,
48    kRoundingMode,
49    kCurrencyUsage,
50    kMinimumExponentDigits,
51    kExponentSignAlwaysShown,
52    kDecimalSeparatorAlwaysShown,
53    kPadPosition,
54    kPositivePrefix,
55    kPositiveSuffix,
56    kNegativePrefix,
57    kNegativeSuffix,
58    kLocalizedPattern,
59    kToPattern,
60    kToLocalizedPattern,
61    kStyle,
62    kParse,
63    kLenient,
64    kPlural,
65    kParseIntegerOnly,
66    kDecimalPatternMatchRequired,
67    kParseCaseSensitive,
68    kParseNoExponent,
69    kOutputCurrency,
70    kNumberFormatTestTupleFieldCount
71};
72
73/**
74 * NumberFormatTestTuple represents the data for a single data driven test.
75 * It consist of named fields each of which may or may not be set. Each field
76 * has a particular meaning in the test. For more information on what each
77 * field means and how the data drive tests work, please see
78 * https://docs.google.com/document/d/1T2P0p953_Lh1pRwo-5CuPVrHlIBa_wcXElG-Hhg_WHM/edit?usp=sharing
79 * Each field is optional. That is, a certain field may be unset for a given
80 * test. The UBool fields ending in "Flag" indicate whether the corrresponding
81 * field is set or not. TRUE means set; FALSE means unset. An unset field
82 * generally means that the corresponding setter method is not called on
83 * the NumberFormat object.
84 */
85
86class NumberFormatTestTuple {
87public:
88    Locale locale;
89    UnicodeString currency;
90    UnicodeString pattern;
91    UnicodeString format;
92    UnicodeString output;
93    UnicodeString comment;
94    int32_t minIntegerDigits;
95    int32_t maxIntegerDigits;
96    int32_t minFractionDigits;
97    int32_t maxFractionDigits;
98    int32_t minGroupingDigits;
99    UnicodeString breaks;
100    int32_t useSigDigits;
101    int32_t minSigDigits;
102    int32_t maxSigDigits;
103    int32_t useGrouping;
104    int32_t multiplier;
105    double roundingIncrement;
106    int32_t formatWidth;
107    UnicodeString padCharacter;
108    int32_t useScientific;
109    int32_t grouping;
110    int32_t grouping2;
111    DecimalFormat::ERoundingMode roundingMode;
112    UCurrencyUsage currencyUsage;
113    int32_t minimumExponentDigits;
114    int32_t exponentSignAlwaysShown;
115    int32_t decimalSeparatorAlwaysShown;
116    DecimalFormat::EPadPosition padPosition;
117    UnicodeString positivePrefix;
118    UnicodeString positiveSuffix;
119    UnicodeString negativePrefix;
120    UnicodeString negativeSuffix;
121    UnicodeString localizedPattern;
122    UnicodeString toPattern;
123    UnicodeString toLocalizedPattern;
124    UNumberFormatStyle style;
125    UnicodeString parse;
126    int32_t lenient;
127    UnicodeString plural;
128    int32_t parseIntegerOnly;
129    int32_t decimalPatternMatchRequired;
130    int32_t parseNoExponent;
131    int32_t parseCaseSensitive;
132    UnicodeString outputCurrency;
133
134    UBool localeFlag;
135    UBool currencyFlag;
136    UBool patternFlag;
137    UBool formatFlag;
138    UBool outputFlag;
139    UBool commentFlag;
140    UBool minIntegerDigitsFlag;
141    UBool maxIntegerDigitsFlag;
142    UBool minFractionDigitsFlag;
143    UBool maxFractionDigitsFlag;
144    UBool minGroupingDigitsFlag;
145    UBool breaksFlag;
146    UBool useSigDigitsFlag;
147    UBool minSigDigitsFlag;
148    UBool maxSigDigitsFlag;
149    UBool useGroupingFlag;
150    UBool multiplierFlag;
151    UBool roundingIncrementFlag;
152    UBool formatWidthFlag;
153    UBool padCharacterFlag;
154    UBool useScientificFlag;
155    UBool groupingFlag;
156    UBool grouping2Flag;
157    UBool roundingModeFlag;
158    UBool currencyUsageFlag;
159    UBool minimumExponentDigitsFlag;
160    UBool exponentSignAlwaysShownFlag;
161    UBool decimalSeparatorAlwaysShownFlag;
162    UBool padPositionFlag;
163    UBool positivePrefixFlag;
164    UBool positiveSuffixFlag;
165    UBool negativePrefixFlag;
166    UBool negativeSuffixFlag;
167    UBool localizedPatternFlag;
168    UBool toPatternFlag;
169    UBool toLocalizedPatternFlag;
170    UBool styleFlag;
171    UBool parseFlag;
172    UBool lenientFlag;
173    UBool pluralFlag;
174    UBool parseIntegerOnlyFlag;
175    UBool decimalPatternMatchRequiredFlag;
176    UBool parseNoExponentFlag;
177    UBool parseCaseSensitiveFlag;
178    UBool outputCurrencyFlag;
179
180    NumberFormatTestTuple() {
181        clear();
182    }
183
184    /**
185     * Sets a particular field using the string representation of that field.
186     * @param field the field to set.
187     * @param fieldValue the string representation of the field value.
188     * @param status error returned here such as when the string representation
189     *  of the field value cannot be parsed.
190     * @return TRUE on success or FALSE if an error was set in status.
191     */
192    UBool setField(
193            ENumberFormatTestTupleField field,
194            const UnicodeString &fieldValue,
195            UErrorCode &status);
196    /**
197     * Clears a particular field.
198     * @param field the field to clear.
199     * @param status error set here.
200     * @return TRUE on success or FALSE if error was set.
201     */
202    UBool clearField(
203            ENumberFormatTestTupleField field,
204            UErrorCode &status);
205    /**
206     * Clears every field.
207     */
208    void clear();
209
210    /**
211     * Returns the string representation of the test case this object
212     * currently represents.
213     * @param appendTo the result appended here.
214     * @return appendTo
215     */
216    UnicodeString &toString(UnicodeString &appendTo) const;
217
218    /**
219     * Converts the name of a field to the corresponding enum value.
220     * @param name the name of the field as a string.
221     * @return the corresponding enum value or kNumberFormatTestFieldCount
222     *   if name does not map to any recognized field name.
223     */
224    static ENumberFormatTestTupleField getFieldByName(const UnicodeString &name);
225private:
226    const void *getFieldAddress(int32_t fieldId) const;
227    void *getMutableFieldAddress(int32_t fieldId);
228    void setFlag(int32_t fieldId, UBool value);
229    UBool isFlag(int32_t fieldId) const;
230};
231
232#endif /* !UCONFIG_NO_FORMATTING */
233#endif
234