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