]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/numberformattesttuple.h
ICU-59180.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / numberformattesttuple.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
2ca993e8
A
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 kParseNoExponent,
68 kOutputCurrency,
69 kNumberFormatTestTupleFieldCount
70};
71
72/**
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.
83 */
84
85class NumberFormatTestTuple {
86public:
87 Locale locale;
88 UnicodeString currency;
89 UnicodeString pattern;
90 UnicodeString format;
91 UnicodeString output;
92 UnicodeString comment;
93 int32_t minIntegerDigits;
94 int32_t maxIntegerDigits;
95 int32_t minFractionDigits;
96 int32_t maxFractionDigits;
97 int32_t minGroupingDigits;
98 UnicodeString breaks;
99 int32_t useSigDigits;
100 int32_t minSigDigits;
101 int32_t maxSigDigits;
102 int32_t useGrouping;
103 int32_t multiplier;
104 double roundingIncrement;
105 int32_t formatWidth;
106 UnicodeString padCharacter;
107 int32_t useScientific;
108 int32_t grouping;
109 int32_t grouping2;
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;
124 UnicodeString parse;
125 int32_t lenient;
126 UnicodeString plural;
127 int32_t parseIntegerOnly;
128 int32_t decimalPatternMatchRequired;
129 int32_t parseNoExponent;
130 UnicodeString outputCurrency;
131
132 UBool localeFlag;
133 UBool currencyFlag;
134 UBool patternFlag;
135 UBool formatFlag;
136 UBool outputFlag;
137 UBool commentFlag;
138 UBool minIntegerDigitsFlag;
139 UBool maxIntegerDigitsFlag;
140 UBool minFractionDigitsFlag;
141 UBool maxFractionDigitsFlag;
142 UBool minGroupingDigitsFlag;
143 UBool breaksFlag;
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;
153 UBool groupingFlag;
154 UBool grouping2Flag;
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;
166 UBool toPatternFlag;
167 UBool toLocalizedPatternFlag;
168 UBool styleFlag;
169 UBool parseFlag;
170 UBool lenientFlag;
171 UBool pluralFlag;
172 UBool parseIntegerOnlyFlag;
173 UBool decimalPatternMatchRequiredFlag;
174 UBool parseNoExponentFlag;
175 UBool outputCurrencyFlag;
176
177 NumberFormatTestTuple() {
178 clear();
179 }
180
181 /**
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.
188 */
189 UBool setField(
190 ENumberFormatTestTupleField field,
191 const UnicodeString &fieldValue,
192 UErrorCode &status);
193 /**
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.
198 */
199 UBool clearField(
200 ENumberFormatTestTupleField field,
201 UErrorCode &status);
202 /**
203 * Clears every field.
204 */
205 void clear();
206
207 /**
208 * Returns the string representation of the test case this object
209 * currently represents.
210 * @param appendTo the result appended here.
211 * @return appendTo
212 */
213 UnicodeString &toString(UnicodeString &appendTo) const;
214
215 /**
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.
220 */
221 static ENumberFormatTestTupleField getFieldByName(const UnicodeString &name);
222private:
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;
227};
228
229#endif /* !UCONFIG_NO_FORMATTING */
230#endif