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