1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4 * COPYRIGHT:
5 * Copyright (c) 1997-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************/
8
9 /**
10 * IntlTestFormat is the medium level test class for everything in the directory "format".
11 */
12
13 #include "unicode/utypes.h"
14 #include "unicode/localpointer.h"
15
16 #if !UCONFIG_NO_FORMATTING
17
18 #include "itformat.h"
19 #include "tsdate.h"
20 #include "tsnmfmt.h"
21 #include "caltest.h"
22 #include "callimts.h"
23 #include "tztest.h"
24 #include "tzbdtest.h"
25 #include "tsdcfmsy.h" // DecimalFormatSymbols
26 #include "tchcfmt.h"
27 #include "tsdtfmsy.h" // DateFormatSymbols
28 #include "dcfmapts.h" // DecimalFormatAPI
29 #include "tfsmalls.h" // Format Small Classes
30 #include "nmfmapts.h" // NumberFormatAPI
31 #include "numfmtst.h" // NumberFormatTest
32 #include "sdtfmtts.h" // SimpleDateFormatAPI
33 #include "dtfmapts.h" // DateFormatAPI
34 #include "dtfmttst.h" // DateFormatTest
35 #include "tmsgfmt.h" // TestMessageFormat
36 #include "dtfmrgts.h" // DateFormatRegressionTest
37 #include "msfmrgts.h" // MessageFormatRegressionTest
38 #include "miscdtfm.h" // DateFormatMiscTests
39 #include "nmfmtrt.h" // NumberFormatRoundTripTest
40 #include "numrgts.h" // NumberFormatRegressionTest
41 #include "dtfmtrtts.h" // DateFormatRoundTripTest
42 #include "pptest.h" // ParsePositionTest
43 #include "calregts.h" // CalendarRegressionTest
44 #include "tzregts.h" // TimeZoneRegressionTest
45 #include "astrotst.h" // AstroTest
46 #include "incaltst.h" // IntlCalendarTest
47 #include "calcasts.h" // CalendarCaseTest
48 #include "tzrulets.h" // TimeZoneRuleTest
49 #include "dadrcal.h" // DataDrivenCalendarTest
50 #include "dadrfmt.h" // DataDrivenFormatTest
51 #include "dtptngts.h" // IntlTestDateTimePatternGeneratorAPI
52 #include "tzoffloc.h" // TimeZoneOffsetLocalTest
53 #include "tzfmttst.h" // TimeZoneFormatTest
54 #include "plurults.h" // PluralRulesTest
55 #include "plurfmts.h" // PluralFormatTest
56 #include "selfmts.h" // PluralFormatTest
57 #include "dtifmtts.h" // DateIntervalFormatTest
58 #include "locnmtst.h" // LocaleDisplayNamesTest
59 #include "dcfmtest.h" // DecimalFormatTest
60 #include "listformattertest.h" // ListFormatterTest
61 #include "regiontst.h" // RegionTest
62 #include "numbertest.h" // NumberTest
63 #include "erarulestest.h" // EraRulesTest
64
65 extern IntlTest *createCompactDecimalFormatTest();
66 extern IntlTest *createGenderInfoTest();
67 #if !UCONFIG_NO_BREAK_ITERATION
68 extern IntlTest *createRelativeDateTimeFormatterTest();
69 #endif
70 extern IntlTest *createTimeUnitTest();
71 extern IntlTest *createMeasureFormatTest();
72 extern IntlTest *createNumberFormatSpecificationTest();
73 extern IntlTest *createScientificNumberFormatterTest();
74 extern IntlTest *createFormattedValueTest();
75 extern IntlTest *createFormattedStringBuilderTest();
76 extern IntlTest *createStringSegmentTest();
77 extern IntlTest *createUnitsDataTest();
78 extern IntlTest *createUnitsTest();
79 extern IntlTest *createUnitsRouterTest();
80 extern IntlTest *createDisplayOptionsTest();
81
82
83 #define TESTCLASS(id, TestClass) \
84 case id: \
85 name = #TestClass; \
86 if (exec) { \
87 logln(#TestClass " test---"); \
88 logln((UnicodeString)""); \
89 TestClass test; \
90 callTest(test, par); \
91 } \
92 break
93
runIndexedTest(int32_t index,UBool exec,const char * & name,char * par)94 void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
95 {
96 // for all format tests, always set default Locale and TimeZone to ENGLISH and PST.
97 TimeZone* saveDefaultTimeZone = NULL;
98 Locale saveDefaultLocale = Locale::getDefault();
99 if (exec) {
100 saveDefaultTimeZone = TimeZone::createDefault();
101 TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles");
102 TimeZone::setDefault(*tz);
103 delete tz;
104 UErrorCode status = U_ZERO_ERROR;
105 Locale::setDefault( Locale::getEnglish(), status );
106 if (U_FAILURE(status)) {
107 errln("itformat: couldn't set default Locale to ENGLISH!");
108 }
109 }
110 if (exec) logln("TestSuite Format: ");
111 switch (index) {
112 TESTCLASS(0,IntlTestDateFormat);
113 TESTCLASS(1,IntlTestNumberFormat);
114 TESTCLASS(2,CalendarTest);
115 TESTCLASS(3,CalendarLimitTest);
116 TESTCLASS(4,TimeZoneTest);
117 TESTCLASS(5,TimeZoneBoundaryTest);
118 TESTCLASS(6,TestChoiceFormat);
119 TESTCLASS(7,IntlTestDecimalFormatSymbols);
120 TESTCLASS(8,IntlTestDateFormatSymbols);
121 TESTCLASS(9,IntlTestDecimalFormatAPI);
122 TESTCLASS(10,TestFormatSmallClasses);
123 TESTCLASS(11,IntlTestNumberFormatAPI);
124 TESTCLASS(12,IntlTestSimpleDateFormatAPI);
125 TESTCLASS(13,IntlTestDateFormatAPI);
126 TESTCLASS(14,DateFormatTest);
127 TESTCLASS(15,TestMessageFormat);
128 TESTCLASS(16,NumberFormatTest);
129 TESTCLASS(17,DateFormatRegressionTest);
130 TESTCLASS(18,MessageFormatRegressionTest);
131 TESTCLASS(19,DateFormatMiscTests);
132 TESTCLASS(20,NumberFormatRoundTripTest);
133 TESTCLASS(21,NumberFormatRegressionTest);
134 TESTCLASS(22,DateFormatRoundTripTest);
135 TESTCLASS(23,ParsePositionTest);
136 TESTCLASS(24,CalendarRegressionTest);
137 TESTCLASS(25,TimeZoneRegressionTest);
138 TESTCLASS(26,IntlCalendarTest);
139 TESTCLASS(27,AstroTest);
140 TESTCLASS(28,CalendarCaseTest);
141 TESTCLASS(29,TimeZoneRuleTest);
142 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
143 TESTCLASS(30,DataDrivenCalendarTest);
144 TESTCLASS(31,DataDrivenFormatTest);
145 #endif
146 TESTCLASS(32,IntlTestDateTimePatternGeneratorAPI);
147 TESTCLASS(33,TimeZoneOffsetLocalTest);
148 TESTCLASS(34,TimeZoneFormatTest);
149 TESTCLASS(35,PluralRulesTest);
150 TESTCLASS(36,PluralFormatTest);
151 TESTCLASS(37,DateIntervalFormatTest);
152 case 38:
153 name = "TimeUnitTest";
154 if (exec) {
155 logln("TimeUnitTest test---");
156 logln((UnicodeString)"");
157 LocalPointer<IntlTest> test(createTimeUnitTest());
158 callTest(*test, par);
159 }
160 break;
161 TESTCLASS(39,SelectFormatTest);
162 TESTCLASS(40,LocaleDisplayNamesTest);
163 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
164 TESTCLASS(41,DecimalFormatTest);
165 #endif
166 TESTCLASS(42,ListFormatterTest);
167 case 43:
168 name = "GenderInfoTest";
169 if (exec) {
170 logln("GenderInfoTest test---");
171 logln((UnicodeString)"");
172 LocalPointer<IntlTest> test(createGenderInfoTest());
173 callTest(*test, par);
174 }
175 break;
176 case 44:
177 name = "CompactDecimalFormatTest";
178 if (exec) {
179 logln("CompactDecimalFormatTest test---");
180 logln((UnicodeString)"");
181 LocalPointer<IntlTest> test(createCompactDecimalFormatTest());
182 callTest(*test, par);
183 }
184 break;
185 TESTCLASS(45,RegionTest);
186 case 46:
187 #if !UCONFIG_NO_BREAK_ITERATION
188 name = "RelativeDateTimeFormatterTest";
189 if (exec) {
190 logln("RelativeDateTimeFormatterTest test---");
191 logln((UnicodeString)"");
192 LocalPointer<IntlTest> test(createRelativeDateTimeFormatterTest());
193 callTest(*test, par);
194 }
195 #endif
196 break;
197 case 47:
198 name = "MeasureFormatTest";
199 if (exec) {
200 logln("MeasureFormatTest test---");
201 logln((UnicodeString)"");
202 LocalPointer<IntlTest> test(createMeasureFormatTest());
203 callTest(*test, par);
204 }
205 break;
206 case 48:
207 name = "NumberFormatSpecificationTest";
208 if (exec) {
209 logln("NumberFormatSpecificationTest test---");
210 logln((UnicodeString)"");
211 LocalPointer<IntlTest> test(createNumberFormatSpecificationTest());
212 callTest(*test, par);
213 }
214 break;
215 case 49:
216 name = "ScientificNumberFormatterTest";
217 if (exec) {
218 logln("ScientificNumberFormatterTest test---");
219 logln((UnicodeString)"");
220 LocalPointer<IntlTest> test(createScientificNumberFormatterTest());
221 callTest(*test, par);
222 }
223 break;
224 TESTCLASS(50,NumberFormatDataDrivenTest);
225 TESTCLASS(51,NumberTest);
226 TESTCLASS(52,EraRulesTest);
227 case 53:
228 name = "FormattedValueTest";
229 if (exec) {
230 logln("FormattedValueTest test---");
231 logln((UnicodeString)"");
232 LocalPointer<IntlTest> test(createFormattedValueTest());
233 callTest(*test, par);
234 }
235 break;
236 case 54:
237 name = "FormattedStringBuilderTest";
238 if (exec) {
239 logln("FormattedStringBuilderTest test---");
240 logln((UnicodeString)"");
241 LocalPointer<IntlTest> test(createFormattedStringBuilderTest());
242 callTest(*test, par);
243 }
244 break;
245 case 55:
246 name = "StringSegmentTest";
247 if (exec) {
248 logln("StringSegmentTest test---");
249 logln((UnicodeString)"");
250 LocalPointer<IntlTest> test(createStringSegmentTest());
251 callTest(*test, par);
252 }
253 break;
254 case 56:
255 name = "UnitsTest";
256 if (exec) {
257 logln("UnitsTest test---");
258 logln((UnicodeString)"");
259 LocalPointer<IntlTest> test(createUnitsTest());
260 callTest(*test, par);
261 }
262 break;
263 case 57:
264 name = "UnitsDataTest";
265 if (exec) {
266 logln("UnitsDataTest test---");
267 logln((UnicodeString)"");
268 LocalPointer<IntlTest> test(createUnitsDataTest());
269 callTest(*test, par);
270 }
271 break;
272 case 58:
273 name = "UnitsRouterTest";
274 if (exec) {
275 logln("UnitsRouterTest test---");
276 logln((UnicodeString)"");
277 LocalPointer<IntlTest> test(createUnitsRouterTest());
278 callTest(*test, par);
279 }
280 break;
281 case 59:
282 name = "DisplayOptionsTest";
283 if (exec) {
284 logln("DisplayOptionsTest test---");
285 logln((UnicodeString)"");
286 LocalPointer<IntlTest> test(createDisplayOptionsTest());
287 callTest(*test, par);
288 }
289 break;
290 default: name = ""; break; //needed to end loop
291 }
292 if (exec) {
293 // restore saved Locale and TimeZone
294 TimeZone::adoptDefault(saveDefaultTimeZone);
295 UErrorCode status = U_ZERO_ERROR;
296 Locale::setDefault( saveDefaultLocale, status );
297 if (U_FAILURE(status)) {
298 errln("itformat: couldn't re-set default Locale!");
299 }
300 }
301 }
302
303 #endif /* #if !UCONFIG_NO_FORMATTING */
304