1 // Copyright (C) 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
63 extern IntlTest *createCompactDecimalFormatTest();
64 extern IntlTest *createGenderInfoTest();
65 #if !UCONFIG_NO_BREAK_ITERATION
66 extern IntlTest *createRelativeDateTimeFormatterTest();
67 #endif
68 extern IntlTest *createTimeUnitTest();
69 extern IntlTest *createMeasureFormatTest();
70 extern IntlTest *createNumberFormatSpecificationTest();
71 extern IntlTest *createScientificNumberFormatterTest();
72 extern IntlTest *createNumberFormat2Test();
73
74
75 #define TESTCLASS(id, TestClass) \
76 case id: \
77 name = #TestClass; \
78 if (exec) { \
79 logln(#TestClass " test---"); \
80 logln((UnicodeString)""); \
81 TestClass test; \
82 callTest(test, par); \
83 } \
84 break
85
runIndexedTest(int32_t index,UBool exec,const char * & name,char * par)86 void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
87 {
88 // for all format tests, always set default Locale and TimeZone to ENGLISH and PST.
89 TimeZone* saveDefaultTimeZone = NULL;
90 Locale saveDefaultLocale = Locale::getDefault();
91 if (exec) {
92 saveDefaultTimeZone = TimeZone::createDefault();
93 TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles");
94 TimeZone::setDefault(*tz);
95 delete tz;
96 UErrorCode status = U_ZERO_ERROR;
97 Locale::setDefault( Locale::getEnglish(), status );
98 if (U_FAILURE(status)) {
99 errln("itformat: couldn't set default Locale to ENGLISH!");
100 }
101 }
102 if (exec) logln("TestSuite Format: ");
103 switch (index) {
104 TESTCLASS(0,IntlTestDateFormat);
105 TESTCLASS(1,IntlTestNumberFormat);
106 TESTCLASS(2,CalendarTest);
107 TESTCLASS(3,CalendarLimitTest);
108 TESTCLASS(4,TimeZoneTest);
109 TESTCLASS(5,TimeZoneBoundaryTest);
110 TESTCLASS(6,TestChoiceFormat);
111 TESTCLASS(7,IntlTestDecimalFormatSymbols);
112 TESTCLASS(8,IntlTestDateFormatSymbols);
113 TESTCLASS(9,IntlTestDecimalFormatAPI);
114 TESTCLASS(10,TestFormatSmallClasses);
115 TESTCLASS(11,IntlTestNumberFormatAPI);
116 TESTCLASS(12,IntlTestSimpleDateFormatAPI);
117 TESTCLASS(13,IntlTestDateFormatAPI);
118 TESTCLASS(14,DateFormatTest);
119 TESTCLASS(15,TestMessageFormat);
120 TESTCLASS(16,NumberFormatTest);
121 TESTCLASS(17,DateFormatRegressionTest);
122 TESTCLASS(18,MessageFormatRegressionTest);
123 TESTCLASS(19,DateFormatMiscTests);
124 TESTCLASS(20,NumberFormatRoundTripTest);
125 TESTCLASS(21,NumberFormatRegressionTest);
126 TESTCLASS(22,DateFormatRoundTripTest);
127 TESTCLASS(23,ParsePositionTest);
128 TESTCLASS(24,CalendarRegressionTest);
129 TESTCLASS(25,TimeZoneRegressionTest);
130 TESTCLASS(26,IntlCalendarTest);
131 TESTCLASS(27,AstroTest);
132 TESTCLASS(28,CalendarCaseTest);
133 TESTCLASS(29,TimeZoneRuleTest);
134 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
135 TESTCLASS(30,DataDrivenCalendarTest);
136 TESTCLASS(31,DataDrivenFormatTest);
137 #endif
138 TESTCLASS(32,IntlTestDateTimePatternGeneratorAPI);
139 TESTCLASS(33,TimeZoneOffsetLocalTest);
140 TESTCLASS(34,TimeZoneFormatTest);
141 TESTCLASS(35,PluralRulesTest);
142 TESTCLASS(36,PluralFormatTest);
143 TESTCLASS(37,DateIntervalFormatTest);
144 case 38:
145 name = "TimeUnitTest";
146 if (exec) {
147 logln("TimeUnitTest test---");
148 logln((UnicodeString)"");
149 LocalPointer<IntlTest> test(createTimeUnitTest());
150 callTest(*test, par);
151 }
152 break;
153 TESTCLASS(39,SelectFormatTest);
154 TESTCLASS(40,LocaleDisplayNamesTest);
155 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
156 TESTCLASS(41,DecimalFormatTest);
157 #endif
158 TESTCLASS(42,ListFormatterTest);
159 case 43:
160 name = "GenderInfoTest";
161 if (exec) {
162 logln("GenderInfoTest test---");
163 logln((UnicodeString)"");
164 LocalPointer<IntlTest> test(createGenderInfoTest());
165 callTest(*test, par);
166 }
167 break;
168 case 44:
169 name = "CompactDecimalFormatTest";
170 if (exec) {
171 logln("CompactDecimalFormatTest test---");
172 logln((UnicodeString)"");
173 LocalPointer<IntlTest> test(createCompactDecimalFormatTest());
174 callTest(*test, par);
175 }
176 break;
177 TESTCLASS(45,RegionTest);
178 case 46:
179 #if !UCONFIG_NO_BREAK_ITERATION
180 name = "RelativeDateTimeFormatterTest";
181 if (exec) {
182 logln("RelativeDateTimeFormatterTest test---");
183 logln((UnicodeString)"");
184 LocalPointer<IntlTest> test(createRelativeDateTimeFormatterTest());
185 callTest(*test, par);
186 }
187 #endif
188 break;
189 case 47:
190 name = "MeasureFormatTest";
191 if (exec) {
192 logln("MeasureFormatTest test---");
193 logln((UnicodeString)"");
194 LocalPointer<IntlTest> test(createMeasureFormatTest());
195 callTest(*test, par);
196 }
197 break;
198 case 48:
199 name = "NumberFormatSpecificationTest";
200 if (exec) {
201 logln("NumberFormatSpecificationTest test---");
202 logln((UnicodeString)"");
203 LocalPointer<IntlTest> test(createNumberFormatSpecificationTest());
204 callTest(*test, par);
205 }
206 break;
207 case 49:
208 name = "ScientificNumberFormatterTest";
209 if (exec) {
210 logln("ScientificNumberFormatterTest test---");
211 logln((UnicodeString)"");
212 LocalPointer<IntlTest> test(createScientificNumberFormatterTest());
213 callTest(*test, par);
214 }
215 break;
216 case 50:
217 name = "NumberFormat2Test";
218 if (exec) {
219 logln("NumberFormat2Test test---");
220 logln((UnicodeString)"");
221 LocalPointer<IntlTest> test(createNumberFormat2Test());
222 callTest(*test, par);
223 }
224 break;
225 default: name = ""; break; //needed to end loop
226 }
227 if (exec) {
228 // restore saved Locale and TimeZone
229 TimeZone::adoptDefault(saveDefaultTimeZone);
230 UErrorCode status = U_ZERO_ERROR;
231 Locale::setDefault( saveDefaultLocale, status );
232 if (U_FAILURE(status)) {
233 errln("itformat: couldn't re-set default Locale!");
234 }
235 }
236 }
237
238 #endif /* #if !UCONFIG_NO_FORMATTING */
239