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-2005, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8
9#ifndef __TimeZoneBoundaryTest__
10#define __TimeZoneBoundaryTest__
11
12#include "unicode/utypes.h"
13
14#if !UCONFIG_NO_FORMATTING
15
16#include "unicode/timezone.h"
17#include "unicode/simpletz.h"
18#include "caltztst.h"
19
20/**
21 * A test which discovers the boundaries of DST programmatically and verifies
22 * that they are correct.
23 */
24class TimeZoneBoundaryTest: public CalendarTimeZoneTest {
25    // IntlTest override
26    void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
27public: // package
28
29    TimeZoneBoundaryTest();
30
31    /**
32     * Date.toString().substring() Boundary Test
33     * Look for a DST changeover to occur within 6 months of the given Date.
34     * The initial Date.toString() should yield a string containing the
35     * startMode as a SUBSTRING.  The boundary will be tested to be
36     * at the expectedBoundary value.
37     */
38
39    /**
40     * internal routines used by major test routines to perform subtests
41     **/
42    virtual void findDaylightBoundaryUsingDate(UDate d, const char* startMode, UDate expectedBoundary);
43    virtual void findDaylightBoundaryUsingTimeZone(UDate d, UBool startsInDST, UDate expectedBoundary);
44    virtual void findDaylightBoundaryUsingTimeZone(UDate d, UBool startsInDST, UDate expectedBoundary, TimeZone* tz);
45
46private:
47    //static UnicodeString* showDate(long l);
48    UnicodeString showDate(UDate d);
49    static UnicodeString showNN(int32_t n);
50
51public: // package
52    /**
53     * Given a date, a TimeZone, and expected values for inDaylightTime,
54     * useDaylightTime, zone and DST offset, verify that this is the case.
55     */
56    virtual void verifyDST(UDate d, TimeZone* time_zone, UBool expUseDaylightTime, UBool expInDaylightTime, UDate expZoneOffset, UDate expDSTOffset);
57
58    /**
59     * Test the behavior of SimpleTimeZone at the transition into and out of DST.
60     * Use a binary search to find boundaries.
61     */
62    virtual void TestBoundaries(void);
63
64    /**
65     * internal subroutine used by TestNewRules
66     **/
67    virtual void testUsingBinarySearch(SimpleTimeZone* tz, UDate d, UDate expectedBoundary);
68
69    /**
70     * Test the handling of the "new" rules; that is, rules other than nth Day of week.
71     */
72    virtual void TestNewRules(void);
73
74    /**
75     * Find boundaries by stepping.
76     */
77    virtual void findBoundariesStepwise(int32_t year, UDate interval, TimeZone* z, int32_t expectedChanges);
78
79    /**
80     * Test the behavior of SimpleTimeZone at the transition into and out of DST.
81     * Use a stepwise march to find boundaries.
82     */
83    virtual void TestStepwise(void);
84    void verifyMapping(Calendar& cal, int year, int month, int dom, int hour,
85                    double epochHours) ;
86private:
87    const UDate ONE_SECOND;
88    const UDate ONE_MINUTE;
89    const UDate ONE_HOUR;
90    const UDate ONE_DAY;
91    const UDate ONE_YEAR;
92    const UDate SIX_MONTHS;
93    static const int32_t MONTH_LENGTH[];
94    static const UDate PST_1997_BEG;
95    static const UDate PST_1997_END;
96    static const UDate INTERVAL;
97};
98
99#endif /* #if !UCONFIG_NO_FORMATTING */
100
101#endif // __TimeZoneBoundaryTest__
102