1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /*********************************************************************** 4 * Copyright (c) 1997-2016, International Business Machines Corporation 5 * and others. All Rights Reserved. 6 ***********************************************************************/ 7 8 #ifndef __CalendarTest__ 9 #define __CalendarTest__ 10 11 #include "unicode/utypes.h" 12 13 #if !UCONFIG_NO_FORMATTING 14 15 #include "unicode/calendar.h" 16 #include "unicode/smpdtfmt.h" 17 #include "caltztst.h" 18 19 class CalendarTest: public CalendarTimeZoneTest { 20 public: 21 // IntlTest override 22 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ) override; 23 public: 24 /** 25 * This test confirms the correct behavior of add when incrementing 26 * through subsequent days. 27 */ 28 virtual void TestRog(); 29 /** 30 * Test the handling of the day of the week, checking for correctness and 31 * for correct minimum and maximum values. 32 */ 33 virtual void TestDOW943(); 34 /** 35 * test subroutine use by TestDOW943 36 */ 37 void dowTest(UBool lenient); 38 /** 39 * Confirm that cloned Calendar objects do not inadvertently share substructures. 40 */ 41 virtual void TestClonesUnique908(); 42 /** 43 * Confirm that the Gregorian cutoff value works as advertised. 44 */ 45 virtual void TestGregorianChange768(); 46 /** 47 * Confirm the functioning of the field disambiguation algorithm. 48 */ 49 virtual void TestDisambiguation765(); 50 /** 51 * Test various API methods for API completeness. 52 */ 53 virtual void TestGenericAPI(); // New to C++ -- needs to be back ported to Java 54 55 virtual void TestWOY(); 56 57 virtual void TestDebug(); 58 59 public: // package 60 /** 61 * test subroutine used by TestDisambiguation765 62 */ 63 virtual void verify765(const UnicodeString& msg, Calendar* c, int32_t year, int32_t month, int32_t day); 64 /** 65 * test subroutine used by TestDisambiguation765 66 */ 67 virtual void verify765(const UnicodeString& msg/*, IllegalArgumentException e*/, UErrorCode status); 68 69 public: 70 /** 71 * Confirm that the offset between local time and GMT behaves as expected. 72 */ 73 virtual void TestGMTvsLocal4064654(); 74 75 public: // package 76 /** 77 * test subroutine used by TestGMTvsLocal4064654 78 */ 79 virtual void test4064654(int32_t yr, int32_t mo, int32_t dt, int32_t hr, int32_t mn, int32_t sc); 80 81 public: 82 /** 83 * The operations of adding and setting should not exhibit pathological 84 * dependence on the order of operations. This test checks for this. 85 */ 86 virtual void TestAddSetOrder621(); 87 /** 88 * Confirm that adding to various fields works. 89 */ 90 virtual void TestAdd520(); 91 /** 92 * Execute and test adding and rolling in GregorianCalendar extensively. 93 */ 94 virtual void TestAddRollExtensive(); 95 96 public: // package 97 // internal utility routine for checking date 98 virtual void check520(Calendar* c, 99 int32_t y, int32_t m, int32_t d, 100 int32_t hr, int32_t min, int32_t sec, 101 int32_t ms, UCalendarDateFields field); 102 103 virtual void check520(Calendar* c, 104 int32_t y, int32_t m, int32_t d); 105 106 public: 107 /** 108 * Test that setting of fields works. In particular, make sure that all instances 109 * of GregorianCalendar don't share a static instance of the fields array. 110 */ 111 virtual void TestFieldSet4781(); 112 /* virtual void TestSerialize337(); 113 114 public: // package 115 static UnicodeString& PREFIX; 116 static UnicodeString& POSTFIX; 117 static UnicodeString& FILENAME; 118 */ 119 public: 120 /** 121 * Verify that the seconds of a Calendar can be zeroed out through the 122 * expected sequence of operations. 123 */ 124 virtual void TestSecondsZero121(); 125 /** 126 * Verify that a specific sequence of adding and setting works as expected; 127 * it should not vary depending on when and whether the get method is 128 * called. 129 */ 130 virtual void TestAddSetGet0610(); 131 132 public: // package 133 // internal routine for checking date 134 static UnicodeString value(Calendar* calendar); 135 136 public: 137 /** 138 * Verify that various fields on a known date are set correctly. 139 */ 140 virtual void TestFields060(); 141 142 public: // package 143 static int32_t EXPECTED_FIELDS[]; 144 static const int32_t EXPECTED_FIELDS_length; 145 146 public: 147 /** 148 * Verify that various fields on a known date are set correctly. In this 149 * case, the start of the epoch (January 1 1970). 150 */ 151 virtual void TestEpochStartFields(); 152 153 public: // package 154 static int32_t EPOCH_FIELDS[]; 155 156 public: 157 /** 158 * Test that the days of the week progress properly when add is called repeatedly 159 * for increments of 24 days. 160 */ 161 virtual void TestDOWProgression(); 162 /** 163 * Test newly added fields - DOW_LOCAL and YEAR_WOY 164 */ 165 virtual void TestDOW_LOCALandYEAR_WOY(); 166 // test subroutine used by TestDOW_LOCALandYEAR_WOY 167 virtual void doYEAR_WOYLoop(Calendar *cal, 168 SimpleDateFormat *sdf, int32_t times, UErrorCode& status); 169 // test subroutine used by TestDOW_LOCALandYEAR_WOY 170 virtual void loop_addroll(Calendar *cal, /*SimpleDateFormat *sdf, */ 171 int times, UCalendarDateFields field, UCalendarDateFields field2, 172 UErrorCode& errorCode); 173 174 void TestYWOY(); 175 void TestJD(); 176 177 void yearAddTest(Calendar& cal, UErrorCode& status); 178 179 public: // package 180 // test subroutine use by TestDOWProgression 181 virtual void marchByDelta(Calendar* cal, int32_t delta); 182 183 public: 184 // for other tests' use 185 static UnicodeString fieldName(UCalendarDateFields f); 186 static UnicodeString calToStr(const Calendar & cal); 187 188 // List of non-installed locales with interesting calendars 189 190 /** 191 * @return the count of 'other' locales to test 192 */ 193 static int32_t testLocaleCount(); 194 195 /** 196 * @param i index of 'other' locale to return 197 * @return locale ID 198 */ 199 static const char* testLocaleID(int32_t i); 200 201 /** 202 * Clone the specified calendar, and determine its earliest supported date 203 * by setting the extended year to the minimum value. 204 * @param cal Calendar (will be cloned) 205 * @param isGregorian output: returns 'true' if the calendar's class is GregorianCalendar 206 * @param status error code 207 */ 208 static UDate minDateOfCalendar(const Calendar& cal, UBool &isGregorian, UErrorCode& status); 209 210 /** 211 * Construct a calendar of the specified locale, and determine its earliest supported date 212 * by setting the extended year to the minimum value. 213 * @param locale locale of calendar to check 214 * @param isGregorian output: returns 'true' if the calendar's class is GregorianCalendar 215 * @param status error code 216 */ 217 static UDate minDateOfCalendar(const Locale& locale, UBool &isGregorian, UErrorCode& status); 218 219 // internal - for other test use 220 public: 221 void Test6703(); 222 void Test3785(); 223 void Test1624(); 224 void TestIslamicUmAlQura(); 225 void TestIslamicTabularDates(); 226 227 /** 228 * Test the time stamp array recalculation during heavy Calendar usage 229 */ 230 void TestTimeStamp(); 231 /** 232 * Test the ISO8601 calendar type 233 */ 234 void TestISO8601(); 235 236 /** 237 * Test cases for [set|get][Repeated|Skipped]WallTimeOption 238 */ 239 void TestAmbiguousWallTimeAPIs(); 240 void TestRepeatedWallTime(); 241 void TestSkippedWallTime(); 242 243 void TestCloneLocale(); 244 245 void TestTimeZoneInLocale(); 246 247 void TestHebrewMonthValidation(); 248 249 /* 250 * utility methods for TestIslamicUmAlQura 251 */ 252 void setAndTestCalendar(Calendar* cal, int32_t initMonth, int32_t initDay, int32_t initYear, UErrorCode& status); 253 void setAndTestWholeYear(Calendar* cal, int32_t startYear, UErrorCode& status); 254 255 void TestWeekData(); 256 257 void TestAddAcrossZoneTransition(); 258 259 void TestChineseCalendarMapping(); 260 261 void TestBasicConversionGregorian(); 262 void TestBasicConversionISO8601(); 263 void TestBasicConversionJapanese(); 264 void TestBasicConversionBuddhist(); 265 void TestBasicConversionTaiwan(); 266 void TestBasicConversionPersian(); 267 void TestBasicConversionIslamic(); 268 void TestBasicConversionIslamicTBLA(); 269 void TestBasicConversionIslamicCivil(); 270 void TestBasicConversionIslamicRGSA(); 271 void TestBasicConversionIslamicUmalqura(); 272 void TestBasicConversionHebrew(); 273 void TestBasicConversionChinese(); 274 void TestBasicConversionDangi(); 275 void TestBasicConversionIndian(); 276 void TestBasicConversionCoptic(); 277 void TestBasicConversionEthiopic(); 278 void TestBasicConversionEthiopicAmeteAlem(); 279 280 void AsssertCalendarFieldValue( 281 Calendar* cal, double time, const char* type, 282 int32_t era, int32_t year, int32_t month, int32_t week_of_year, 283 int32_t week_of_month, int32_t date, int32_t day_of_year, int32_t day_of_week, 284 int32_t day_of_week_in_month, int32_t am_pm, int32_t hour, int32_t hour_of_day, 285 int32_t minute, int32_t second, int32_t millisecond, int32_t zone_offset, 286 int32_t dst_offset, int32_t year_woy, int32_t dow_local, int32_t extended_year, 287 int32_t julian_day, int32_t milliseconds_in_day, int32_t is_leap_month); 288 289 void TestChineseCalendarMonthInSpecialYear(); 290 void TestGregorianCalendarInTemporalLeapYear(); 291 void TestChineseCalendarInTemporalLeapYear(); 292 void TestDangiCalendarInTemporalLeapYear(); 293 void TestHebrewCalendarInTemporalLeapYear(); 294 void TestIslamicCalendarInTemporalLeapYear(); 295 void TestIslamicCivilCalendarInTemporalLeapYear(); 296 void TestIslamicUmalquraCalendarInTemporalLeapYear(); 297 void TestIslamicRGSACalendarInTemporalLeapYear(); 298 void TestIslamicTBLACalendarInTemporalLeapYear(); 299 void TestPersianCalendarInTemporalLeapYear(); 300 void TestIndianCalendarInTemporalLeapYear(); 301 void TestTaiwanCalendarInTemporalLeapYear(); 302 void TestJapaneseCalendarInTemporalLeapYear(); 303 void TestBuddhistCalendarInTemporalLeapYear(); 304 void TestCopticCalendarInTemporalLeapYear(); 305 void TestEthiopicCalendarInTemporalLeapYear(); 306 void TestEthiopicAmeteAlemCalendarInTemporalLeapYear(); 307 308 void TestChineseCalendarGetTemporalMonthCode(); 309 void TestDangiCalendarGetTemporalMonthCode(); 310 void TestHebrewCalendarGetTemporalMonthCode(); 311 void TestCopticCalendarGetTemporalMonthCode(); 312 void TestEthiopicCalendarGetTemporalMonthCode(); 313 void TestEthiopicAmeteAlemCalendarGetTemporalMonthCode(); 314 315 void TestGregorianCalendarSetTemporalMonthCode(); 316 void TestChineseCalendarSetTemporalMonthCode(); 317 void TestHebrewCalendarSetTemporalMonthCode(); 318 void TestCopticCalendarSetTemporalMonthCode(); 319 void TestEthiopicCalendarSetTemporalMonthCode(); 320 321 void TestMostCalendarsOrdinalMonthSet(); 322 void TestChineseCalendarOrdinalMonthSet(); 323 void TestDangiCalendarOrdinalMonthSet(); 324 void TestHebrewCalendarOrdinalMonthSet(); 325 326 void TestCalendarAddOrdinalMonth(); 327 void TestCalendarRollOrdinalMonth(); 328 void TestLimitsOrdinalMonth(); 329 void TestActualLimitsOrdinalMonth(); 330 331 void RunChineseCalendarInTemporalLeapYearTest(Calendar* cal); 332 void RunIslamicCalendarInTemporalLeapYearTest(Calendar* cal); 333 void Run366DaysIsLeapYearCalendarInTemporalLeapYearTest(Calendar* cal); 334 void RunChineseCalendarGetTemporalMonthCode(Calendar* cal); 335 void RunCECalendarGetTemporalMonthCode(Calendar* cal); 336 }; 337 338 #endif /* #if !UCONFIG_NO_FORMATTING */ 339 340 #endif // __CalendarTest__ 341