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-2016, International Business Machines Corporation and 6 * others. All Rights Reserved. 7 ********************************************************************/ 8 9 #ifndef _DATEFORMATTEST_ 10 #define _DATEFORMATTEST_ 11 12 #include "unicode/utypes.h" 13 14 #if !UCONFIG_NO_FORMATTING 15 16 #include "unicode/datefmt.h" 17 #include "unicode/smpdtfmt.h" 18 #include "caltztst.h" 19 20 /** 21 * Performs many different tests for DateFormat and SimpleDateFormat 22 **/ 23 class DateFormatTest: public CalendarTimeZoneTest { 24 // IntlTest override 25 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ) override; 26 public: 27 /** 28 * Verify that patterns have the correct values and could produce 29 * the DateFormat instances that contain the correct localized patterns. 30 */ 31 void TestPatterns(); 32 /** 33 * "Test written by Wally Wedel and emailed to me." 34 * Test handling of timezone offsets 35 **/ 36 virtual void TestWallyWedel(); 37 /** 38 * Test operator== 39 */ 40 virtual void TestEquals(); 41 /** 42 * Test the parsing of 2-digit years. 43 */ 44 virtual void TestTwoDigitYearDSTParse(); 45 46 public: // package 47 // internal utility routine (generates escape sequences for characters) 48 static UnicodeString& escape(UnicodeString& s); 49 50 public: 51 /** 52 * Verify that returned field position indices are correct. 53 */ 54 void TestFieldPosition(); 55 56 void TestGeneral(); 57 58 public: // package 59 // internal utility function 60 static void getFieldText(DateFormat* df, int32_t field, UDate date, UnicodeString& str); 61 62 public: 63 /** 64 * Verify that strings which contain incomplete specifications are parsed 65 * correctly. In some instances, this means not being parsed at all, and 66 * returning an appropriate error. 67 */ 68 virtual void TestPartialParse994(); 69 70 public: // package 71 // internal test subroutine, used by TestPartialParse994 72 virtual void tryPat994(SimpleDateFormat* format, const char* pat, const char* str, UDate expected); 73 74 public: 75 /** 76 * Verify the behavior of patterns in which digits for different fields run together 77 * without intervening separators. 78 */ 79 virtual void TestRunTogetherPattern985(); 80 /** 81 * Verify the behavior of patterns in which digits for different fields run together 82 * without intervening separators. 83 */ 84 virtual void TestRunTogetherPattern917(); 85 86 public: // package 87 // internal test subroutine, used by TestRunTogetherPattern917 88 virtual void testIt917(SimpleDateFormat* fmt, UnicodeString& str, UDate expected); 89 90 public: 91 /** 92 * Verify the handling of Czech June and July, which have the unique attribute that 93 * one is a proper prefix substring of the other. 94 */ 95 virtual void TestCzechMonths459(); 96 /** 97 * Test the handling of 'D' in patterns. 98 */ 99 virtual void TestLetterDPattern212(); 100 /** 101 * Test the day of year pattern. 102 */ 103 virtual void TestDayOfYearPattern195(); 104 105 public: // package 106 // interl test subroutine, used by TestDayOfYearPattern195 107 virtual void tryPattern(SimpleDateFormat& sdf, UDate d, const char* pattern, UDate expected); 108 109 public: 110 /** 111 * Test the handling of single quotes in patterns. 112 */ 113 virtual void TestQuotePattern161(); 114 /** 115 * Verify the correct behavior when handling invalid input strings. 116 */ 117 virtual void TestBadInput135(); 118 119 public: 120 /** 121 * Verify the correct behavior when parsing an array of inputs against an 122 * array of patterns, with known results. The results are encoded after 123 * the input strings in each row. 124 */ 125 virtual void TestBadInput135a(); 126 /** 127 * Test the parsing of two-digit years. 128 */ 129 virtual void TestTwoDigitYear(); 130 131 public: // package 132 // internal test subroutine, used by TestTwoDigitYear 133 virtual void parse2DigitYear(DateFormat& fmt, const char* str, UDate expected); 134 135 public: 136 /** 137 * Test the formatting of time zones. 138 */ 139 virtual void TestDateFormatZone061(); 140 /** 141 * Further test the formatting of time zones. 142 */ 143 virtual void TestDateFormatZone146(); 144 145 void TestTimeZoneStringsAPI(); 146 147 void TestGMTParsing(); 148 149 public: // package 150 /** 151 * Test the formatting of dates in different locales. 152 */ 153 virtual void TestLocaleDateFormat(); 154 155 virtual void TestFormattingLocaleTimeSeparator(); 156 157 virtual void TestDateFormatCalendar(); 158 159 virtual void TestSpaceParsing(); 160 161 void TestExactCountFormat(); 162 163 void TestWhiteSpaceParsing(); 164 165 void TestInvalidPattern(); 166 167 void TestGreekMay(); 168 169 void TestGenericTime(); 170 171 void TestGenericTimeZoneOrder(); 172 173 void Test6338(); 174 175 void Test6726(); 176 177 void Test6880(); 178 179 void TestISOEra(); 180 181 void TestFormalChineseDate(); 182 183 void TestStandAloneGMTParse(); 184 185 void TestParsePosition(); 186 187 void TestMonthPatterns(); 188 189 void TestContext(); 190 191 void TestNonGregoFmtParse(); 192 193 void TestFormatsWithNumberSystems(); 194 195 public: 196 /** 197 * Test host-specific formatting. 198 */ 199 void TestHost(); 200 201 public: 202 /** 203 * Test patterns added in CLDR 1.4, CLDR 23 204 */ 205 void TestEras(); 206 207 void TestNarrowNames(); 208 209 void TestShortDays(); 210 211 void TestStandAloneDays(); 212 213 void TestStandAloneMonths(); 214 215 void TestQuarters(); 216 217 void TestZTimeZoneParsing(); 218 219 void TestRelativeClone(); 220 221 void TestHostClone(); 222 223 void TestHebrewClone(); 224 225 void TestDateFormatSymbolsClone(); 226 227 void TestTimeZoneDisplayName(); 228 229 void TestTimeZoneInLocale(); 230 231 void TestRoundtripWithCalendar(); 232 233 public: 234 /*** 235 * Test Relative Dates 236 */ 237 void TestRelative(); 238 /* void TestRelativeError(); 239 void TestRelativeOther(); 240 */ 241 242 void TestDotAndAtLeniency(); 243 244 void TestDateFormatLeniency(); 245 246 void TestParseMultiPatternMatch(); 247 248 void TestParseLeniencyAPIs(); 249 250 // test override NumberFormat 251 void TestNumberFormatOverride(); 252 void TestCreateInstanceForSkeleton(); 253 void TestCreateInstanceForSkeletonDefault(); 254 void TestCreateInstanceForSkeletonWithCalendar(); 255 void TestDFSCreateForLocaleNonGregorianLocale(); 256 void TestDFSCreateForLocaleWithCalendarInLocale(); 257 void TestChangeCalendar(); 258 259 void TestPatternFromSkeleton(); 260 261 void TestAmPmMidnightNoon(); 262 void TestFlexibleDayPeriod(); 263 void TestDayPeriodWithLocales(); 264 void TestMinuteSecondFieldsInOddPlaces(); 265 void TestDayPeriodParsing(); 266 void TestParseRegression13744(); 267 void TestAdoptCalendarLeak(); 268 void Test20741_ABFields(); 269 void Test22023_UTCWithMinusZero(); 270 void TestNumericFieldStrictParse(); 271 void TestHourCycle(); 272 void TestHCInLocale(); 273 void TestBogusLocale(); 274 void TestLongLocale(); 275 276 private: 277 UBool showParse(DateFormat &format, const UnicodeString &formattedString); 278 279 public: 280 /** 281 * Test parsing a number as a string 282 */ 283 void TestNumberAsStringParsing(); 284 285 private: 286 void TestRelative(int daysdelta, 287 const Locale& loc, 288 const char *expectChars); 289 290 private: 291 void expectParse(const char** data, int32_t data_length, 292 const Locale& locale); 293 294 void expect(const char** data, int32_t data_length, 295 const Locale& loc); 296 297 void expectFormat(const char **data, int32_t data_length, 298 const Locale &locale); 299 300 }; 301 302 #endif /* #if !UCONFIG_NO_FORMATTING */ 303 304 #endif // _DATEFORMATTEST_ 305 //eof 306