• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "unicode/decimfmt.h"
17 #include "unicode/ucurr.h"
18 
19 #define NFTT_GET_FIELD(tuple, fieldName, defaultValue) ((tuple).fieldName##Flag ? (tuple).fieldName : (defaultValue))
20 
21 U_NAMESPACE_USE
22 
23 enum ENumberFormatTestTupleField {
24     kLocale,
25     kCurrency,
26     kPattern,
27     kFormat,
28     kOutput,
29     kComment,
30     kMinIntegerDigits,
31     kMaxIntegerDigits,
32     kMinFractionDigits,
33     kMaxFractionDigits,
34     kMinGroupingDigits,
35     kBreaks,
36     kUseSigDigits,
37     kMinSigDigits,
38     kMaxSigDigits,
39     kUseGrouping,
40     kMultiplier,
41     kRoundingIncrement,
42     kFormatWidth,
43     kPadCharacter,
44     kUseScientific,
45     kGrouping,
46     kGrouping2,
47     kRoundingMode,
48     kCurrencyUsage,
49     kMinimumExponentDigits,
50     kExponentSignAlwaysShown,
51     kDecimalSeparatorAlwaysShown,
52     kPadPosition,
53     kPositivePrefix,
54     kPositiveSuffix,
55     kNegativePrefix,
56     kNegativeSuffix,
57     kSignAlwaysShown,
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 
86 class NumberFormatTestTuple {
87 public:
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     int32_t signAlwaysShown;
122     UnicodeString localizedPattern;
123     UnicodeString toPattern;
124     UnicodeString toLocalizedPattern;
125     UNumberFormatStyle style;
126     UnicodeString parse;
127     int32_t lenient;
128     UnicodeString plural;
129     int32_t parseIntegerOnly;
130     int32_t decimalPatternMatchRequired;
131     int32_t parseNoExponent;
132     int32_t parseCaseSensitive;
133     UnicodeString outputCurrency;
134 
135     UBool localeFlag;
136     UBool currencyFlag;
137     UBool patternFlag;
138     UBool formatFlag;
139     UBool outputFlag;
140     UBool commentFlag;
141     UBool minIntegerDigitsFlag;
142     UBool maxIntegerDigitsFlag;
143     UBool minFractionDigitsFlag;
144     UBool maxFractionDigitsFlag;
145     UBool minGroupingDigitsFlag;
146     UBool breaksFlag;
147     UBool useSigDigitsFlag;
148     UBool minSigDigitsFlag;
149     UBool maxSigDigitsFlag;
150     UBool useGroupingFlag;
151     UBool multiplierFlag;
152     UBool roundingIncrementFlag;
153     UBool formatWidthFlag;
154     UBool padCharacterFlag;
155     UBool useScientificFlag;
156     UBool groupingFlag;
157     UBool grouping2Flag;
158     UBool roundingModeFlag;
159     UBool currencyUsageFlag;
160     UBool minimumExponentDigitsFlag;
161     UBool exponentSignAlwaysShownFlag;
162     UBool decimalSeparatorAlwaysShownFlag;
163     UBool padPositionFlag;
164     UBool positivePrefixFlag;
165     UBool positiveSuffixFlag;
166     UBool negativePrefixFlag;
167     UBool negativeSuffixFlag;
168     UBool signAlwaysShownFlag;
169     UBool localizedPatternFlag;
170     UBool toPatternFlag;
171     UBool toLocalizedPatternFlag;
172     UBool styleFlag;
173     UBool parseFlag;
174     UBool lenientFlag;
175     UBool pluralFlag;
176     UBool parseIntegerOnlyFlag;
177     UBool decimalPatternMatchRequiredFlag;
178     UBool parseNoExponentFlag;
179     UBool parseCaseSensitiveFlag;
180     UBool outputCurrencyFlag;
181 
NumberFormatTestTuple()182     NumberFormatTestTuple() {
183         clear();
184     }
185 
186     /**
187      * Sets a particular field using the string representation of that field.
188      * @param field the field to set.
189      * @param fieldValue the string representation of the field value.
190      * @param status error returned here such as when the string representation
191      *  of the field value cannot be parsed.
192      * @return TRUE on success or FALSE if an error was set in status.
193      */
194     UBool setField(
195             ENumberFormatTestTupleField field,
196             const UnicodeString &fieldValue,
197             UErrorCode &status);
198     /**
199      * Clears a particular field.
200      * @param field the field to clear.
201      * @param status error set here.
202      * @return TRUE on success or FALSE if error was set.
203      */
204     UBool clearField(
205             ENumberFormatTestTupleField field,
206             UErrorCode &status);
207     /**
208      * Clears every field.
209      */
210     void clear();
211 
212     /**
213      * Returns the string representation of the test case this object
214      * currently represents.
215      * @param appendTo the result appended here.
216      * @return appendTo
217      */
218     UnicodeString &toString(UnicodeString &appendTo) const;
219 
220     /**
221      * Converts the name of a field to the corresponding enum value.
222      * @param name the name of the field as a string.
223      * @return the corresponding enum value or kNumberFormatTestFieldCount
224      *   if name does not map to any recognized field name.
225      */
226     static ENumberFormatTestTupleField getFieldByName(const UnicodeString &name);
227 private:
228     const void *getFieldAddress(int32_t fieldId) const;
229     void *getMutableFieldAddress(int32_t fieldId);
230     void setFlag(int32_t fieldId, UBool value);
231     UBool isFlag(int32_t fieldId) const;
232 };
233 
234 #endif /* !UCONFIG_NO_FORMATTING */
235 #endif
236