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
81
82 #define TESTCLASS(id, TestClass) \
83 case id: \
84 name = #TestClass; \
85 if (exec) { \
86 logln(#TestClass " test---"); \
87 logln((UnicodeString)""); \
88 TestClass test; \
89 callTest(test, par); \
90 } \
91 break
92
runIndexedTest(int32_t index,UBool exec,const char * & name,char * par)93 void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
94 {
95 // for all format tests, always set default Locale and TimeZone to ENGLISH and PST.
96 TimeZone* saveDefaultTimeZone = NULL;
97 Locale saveDefaultLocale = Locale::getDefault();
98 if (exec) {
99 saveDefaultTimeZone = TimeZone::createDefault();
100 TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles");
101 TimeZone::setDefault(*tz);
102 delete tz;
103 UErrorCode status = U_ZERO_ERROR;
104 Locale::setDefault( Locale::getEnglish(), status );
105 if (U_FAILURE(status)) {
106 errln("itformat: couldn't set default Locale to ENGLISH!");
107 }
108 }
109 if (exec) logln("TestSuite Format: ");
110 switch (index) {
111 TESTCLASS(0,IntlTestDateFormat);
112 TESTCLASS(1,IntlTestNumberFormat);
113 TESTCLASS(2,CalendarTest);
114 TESTCLASS(3,CalendarLimitTest);
115 TESTCLASS(4,TimeZoneTest);
116 TESTCLASS(5,TimeZoneBoundaryTest);
117 TESTCLASS(6,TestChoiceFormat);
118 TESTCLASS(7,IntlTestDecimalFormatSymbols);
119 TESTCLASS(8,IntlTestDateFormatSymbols);
120 TESTCLASS(9,IntlTestDecimalFormatAPI);
121 TESTCLASS(10,TestFormatSmallClasses);
122 TESTCLASS(11,IntlTestNumberFormatAPI);
123 TESTCLASS(12,IntlTestSimpleDateFormatAPI);
124 TESTCLASS(13,IntlTestDateFormatAPI);
125 TESTCLASS(14,DateFormatTest);
126 TESTCLASS(15,TestMessageFormat);
127 TESTCLASS(16,NumberFormatTest);
128 TESTCLASS(17,DateFormatRegressionTest);
129 TESTCLASS(18,MessageFormatRegressionTest);
130 TESTCLASS(19,DateFormatMiscTests);
131 TESTCLASS(20,NumberFormatRoundTripTest);
132 TESTCLASS(21,NumberFormatRegressionTest);
133 TESTCLASS(22,DateFormatRoundTripTest);
134 TESTCLASS(23,ParsePositionTest);
135 TESTCLASS(24,CalendarRegressionTest);
136 TESTCLASS(25,TimeZoneRegressionTest);
137 TESTCLASS(26,IntlCalendarTest);
138 TESTCLASS(27,AstroTest);
139 TESTCLASS(28,CalendarCaseTest);
140 TESTCLASS(29,TimeZoneRuleTest);
141 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
142 TESTCLASS(30,DataDrivenCalendarTest);
143 TESTCLASS(31,DataDrivenFormatTest);
144 #endif
145 TESTCLASS(32,IntlTestDateTimePatternGeneratorAPI);
146 TESTCLASS(33,TimeZoneOffsetLocalTest);
147 TESTCLASS(34,TimeZoneFormatTest);
148 TESTCLASS(35,PluralRulesTest);
149 TESTCLASS(36,PluralFormatTest);
150 TESTCLASS(37,DateIntervalFormatTest);
151 case 38:
152 name = "TimeUnitTest";
153 if (exec) {
154 logln("TimeUnitTest test---");
155 logln((UnicodeString)"");
156 LocalPointer<IntlTest> test(createTimeUnitTest());
157 callTest(*test, par);
158 }
159 break;
160 TESTCLASS(39,SelectFormatTest);
161 TESTCLASS(40,LocaleDisplayNamesTest);
162 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
163 TESTCLASS(41,DecimalFormatTest);
164 #endif
165 TESTCLASS(42,ListFormatterTest);
166 case 43:
167 name = "GenderInfoTest";
168 if (exec) {
169 logln("GenderInfoTest test---");
170 logln((UnicodeString)"");
171 LocalPointer<IntlTest> test(createGenderInfoTest());
172 callTest(*test, par);
173 }
174 break;
175 case 44:
176 name = "CompactDecimalFormatTest";
177 if (exec) {
178 logln("CompactDecimalFormatTest test---");
179 logln((UnicodeString)"");
180 LocalPointer<IntlTest> test(createCompactDecimalFormatTest());
181 callTest(*test, par);
182 }
183 break;
184 TESTCLASS(45,RegionTest);
185 case 46:
186 #if !UCONFIG_NO_BREAK_ITERATION
187 name = "RelativeDateTimeFormatterTest";
188 if (exec) {
189 logln("RelativeDateTimeFormatterTest test---");
190 logln((UnicodeString)"");
191 LocalPointer<IntlTest> test(createRelativeDateTimeFormatterTest());
192 callTest(*test, par);
193 }
194 #endif
195 break;
196 case 47:
197 name = "MeasureFormatTest";
198 if (exec) {
199 logln("MeasureFormatTest test---");
200 logln((UnicodeString)"");
201 LocalPointer<IntlTest> test(createMeasureFormatTest());
202 callTest(*test, par);
203 }
204 break;
205 case 48:
206 name = "NumberFormatSpecificationTest";
207 if (exec) {
208 logln("NumberFormatSpecificationTest test---");
209 logln((UnicodeString)"");
210 LocalPointer<IntlTest> test(createNumberFormatSpecificationTest());
211 callTest(*test, par);
212 }
213 break;
214 case 49:
215 name = "ScientificNumberFormatterTest";
216 if (exec) {
217 logln("ScientificNumberFormatterTest test---");
218 logln((UnicodeString)"");
219 LocalPointer<IntlTest> test(createScientificNumberFormatterTest());
220 callTest(*test, par);
221 }
222 break;
223 TESTCLASS(50,NumberFormatDataDrivenTest);
224 TESTCLASS(51,NumberTest);
225 TESTCLASS(52,EraRulesTest);
226 case 53:
227 name = "FormattedValueTest";
228 if (exec) {
229 logln("FormattedValueTest test---");
230 logln((UnicodeString)"");
231 LocalPointer<IntlTest> test(createFormattedValueTest());
232 callTest(*test, par);
233 }
234 break;
235 case 54:
236 name = "FormattedStringBuilderTest";
237 if (exec) {
238 logln("FormattedStringBuilderTest test---");
239 logln((UnicodeString)"");
240 LocalPointer<IntlTest> test(createFormattedStringBuilderTest());
241 callTest(*test, par);
242 }
243 break;
244 case 55:
245 name = "StringSegmentTest";
246 if (exec) {
247 logln("StringSegmentTest test---");
248 logln((UnicodeString)"");
249 LocalPointer<IntlTest> test(createStringSegmentTest());
250 callTest(*test, par);
251 }
252 break;
253 case 56:
254 name = "UnitsTest";
255 if (exec) {
256 logln("UnitsTest test---");
257 logln((UnicodeString)"");
258 LocalPointer<IntlTest> test(createUnitsTest());
259 callTest(*test, par);
260 }
261 break;
262 case 57:
263 name = "UnitsDataTest";
264 if (exec) {
265 logln("UnitsDataTest test---");
266 logln((UnicodeString)"");
267 LocalPointer<IntlTest> test(createUnitsDataTest());
268 callTest(*test, par);
269 }
270 break;
271 case 58:
272 name = "UnitsRouterTest";
273 if (exec) {
274 logln("UnitsRouterTest test---");
275 logln((UnicodeString)"");
276 LocalPointer<IntlTest> test(createUnitsRouterTest());
277 callTest(*test, par);
278 }
279 break;
280 default: name = ""; break; //needed to end loop
281 }
282 if (exec) {
283 // restore saved Locale and TimeZone
284 TimeZone::adoptDefault(saveDefaultTimeZone);
285 UErrorCode status = U_ZERO_ERROR;
286 Locale::setDefault( saveDefaultLocale, status );
287 if (U_FAILURE(status)) {
288 errln("itformat: couldn't re-set default Locale!");
289 }
290 }
291 }
292
293 #endif /* #if !UCONFIG_NO_FORMATTING */
294