1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2015, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
9 #ifndef _NUMBER_FORMAT_TEST_TUPLE
10 #define _NUMBER_FORMAT_TEST_TUPLE
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_FORMATTING
16 #include "decimalformatpattern.h"
17 #include "unicode/decimfmt.h"
18 #include "unicode/ucurr.h"
20 #define NFTT_GET_FIELD(tuple, fieldName, defaultValue) ((tuple).fieldName##Flag ? (tuple).fieldName : (defaultValue))
24 enum ENumberFormatTestTupleField {
50 kMinimumExponentDigits,
51 kExponentSignAlwaysShown,
52 kDecimalSeparatorAlwaysShown,
66 kDecimalPatternMatchRequired,
69 kNumberFormatTestTupleFieldCount
73 * NumberFormatTestTuple represents the data for a single data driven test.
74 * It consist of named fields each of which may or may not be set. Each field
75 * has a particular meaning in the test. For more information on what each
76 * field means and how the data drive tests work, please see
77 * https://docs.google.com/document/d/1T2P0p953_Lh1pRwo-5CuPVrHlIBa_wcXElG-Hhg_WHM/edit?usp=sharing
78 * Each field is optional. That is, a certain field may be unset for a given
79 * test. The UBool fields ending in "Flag" indicate whether the corrresponding
80 * field is set or not. TRUE means set; FALSE means unset. An unset field
81 * generally means that the corresponding setter method is not called on
82 * the NumberFormat object.
85 class NumberFormatTestTuple {
88 UnicodeString currency;
89 UnicodeString pattern;
92 UnicodeString comment;
93 int32_t minIntegerDigits;
94 int32_t maxIntegerDigits;
95 int32_t minFractionDigits;
96 int32_t maxFractionDigits;
97 int32_t minGroupingDigits;
100 int32_t minSigDigits;
101 int32_t maxSigDigits;
104 double roundingIncrement;
106 UnicodeString padCharacter;
107 int32_t useScientific;
110 DecimalFormat::ERoundingMode roundingMode;
111 UCurrencyUsage currencyUsage;
112 int32_t minimumExponentDigits;
113 int32_t exponentSignAlwaysShown;
114 int32_t decimalSeparatorAlwaysShown;
115 DecimalFormat::EPadPosition padPosition;
116 UnicodeString positivePrefix;
117 UnicodeString positiveSuffix;
118 UnicodeString negativePrefix;
119 UnicodeString negativeSuffix;
120 UnicodeString localizedPattern;
121 UnicodeString toPattern;
122 UnicodeString toLocalizedPattern;
123 UNumberFormatStyle style;
126 UnicodeString plural;
127 int32_t parseIntegerOnly;
128 int32_t decimalPatternMatchRequired;
129 int32_t parseNoExponent;
130 UnicodeString outputCurrency;
138 UBool minIntegerDigitsFlag;
139 UBool maxIntegerDigitsFlag;
140 UBool minFractionDigitsFlag;
141 UBool maxFractionDigitsFlag;
142 UBool minGroupingDigitsFlag;
144 UBool useSigDigitsFlag;
145 UBool minSigDigitsFlag;
146 UBool maxSigDigitsFlag;
147 UBool useGroupingFlag;
148 UBool multiplierFlag;
149 UBool roundingIncrementFlag;
150 UBool formatWidthFlag;
151 UBool padCharacterFlag;
152 UBool useScientificFlag;
155 UBool roundingModeFlag;
156 UBool currencyUsageFlag;
157 UBool minimumExponentDigitsFlag;
158 UBool exponentSignAlwaysShownFlag;
159 UBool decimalSeparatorAlwaysShownFlag;
160 UBool padPositionFlag;
161 UBool positivePrefixFlag;
162 UBool positiveSuffixFlag;
163 UBool negativePrefixFlag;
164 UBool negativeSuffixFlag;
165 UBool localizedPatternFlag;
167 UBool toLocalizedPatternFlag;
172 UBool parseIntegerOnlyFlag;
173 UBool decimalPatternMatchRequiredFlag;
174 UBool parseNoExponentFlag;
175 UBool outputCurrencyFlag;
177 NumberFormatTestTuple() {
182 * Sets a particular field using the string representation of that field.
183 * @param field the field to set.
184 * @param fieldValue the string representation of the field value.
185 * @param status error returned here such as when the string representation
186 * of the field value cannot be parsed.
187 * @return TRUE on success or FALSE if an error was set in status.
190 ENumberFormatTestTupleField field,
191 const UnicodeString &fieldValue,
194 * Clears a particular field.
195 * @param field the field to clear.
196 * @param status error set here.
197 * @return TRUE on success or FALSE if error was set.
200 ENumberFormatTestTupleField field,
203 * Clears every field.
208 * Returns the string representation of the test case this object
209 * currently represents.
210 * @param appendTo the result appended here.
213 UnicodeString &toString(UnicodeString &appendTo) const;
216 * Converts the name of a field to the corresponding enum value.
217 * @param name the name of the field as a string.
218 * @return the corresponding enum value or kNumberFormatTestFieldCount
219 * if name does not map to any recognized field name.
221 static ENumberFormatTestTupleField getFieldByName(const UnicodeString &name);
223 const void *getFieldAddress(int32_t fieldId) const;
224 void *getMutableFieldAddress(int32_t fieldId);
225 void setFlag(int32_t fieldId, UBool value);
226 UBool isFlag(int32_t fieldId) const;
229 #endif /* !UCONFIG_NO_FORMATTING */