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