Imported Upstream version 58.1
[platform/upstream/icu.git] / source / test / intltest / callimts.h
1 // Copyright (C) 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 Corporation and
6  * others. All Rights Reserved.
7  ********************************************************************/
8  
9 #ifndef __CalendarLimitTest__
10 #define __CalendarLimitTest__
11  
12 #include "unicode/utypes.h"
13
14 #if !UCONFIG_NO_FORMATTING
15
16 #include "caltztst.h"
17
18 /**
19  * This test verifies the behavior of Calendar around the very earliest limits
20  * which it can handle.  It also verifies the behavior for large values of millis.
21  *
22  * Bug ID 4033662.
23  */
24 class CalendarLimitTest: public CalendarTimeZoneTest {
25     // IntlTest override
26     void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
27 public: // package
28     //test routine used by TestCalendarLimit
29     virtual void test(UDate millis, Calendar *cal, DateFormat *fmt);
30
31     // bug 986c: deprecate nextDouble/previousDouble
32     //static double nextDouble(double a);
33     //static double previousDouble(double a);
34     static UBool withinErr(double a, double b, double err);
35
36 public:
37     // test behaviour and error reporting at boundaries of defined range
38     virtual void TestCalendarExtremeLimit(void);
39
40     void TestLimits(void);
41     void TestLimitsThread(int32_t threadNumber);
42
43 private:
44     /*
45      * Test the functions getMaximum/getGeratestMinimum logically correct.
46      * This method assumes day of week cycle is consistent.
47      * @param cal The calendar instance to be tested.
48      * @param leapMonth true if the calendar system has leap months
49      */
50     void doTheoreticalLimitsTest(Calendar& cal, UBool leapMonth);
51
52     /*
53      * Test the functions getXxxMinimum() and getXxxMaximum() by marching a
54      * test calendar 'cal' through 'numberOfDays' sequential days starting
55      * with 'startDate'.  For each date, read a field value along with its
56      * reported actual minimum and actual maximum.  These values are
57      * checked against one another as well as against getMinimum(),
58      * getGreatestMinimum(), getLeastMaximum(), and getMaximum().  We
59      * expect to see:
60      *
61      * 1. minimum <= actualMinimum <= greatestMinimum <=
62      *    leastMaximum <= actualMaximum <= maximum
63      *
64      * 2. actualMinimum <= value <= actualMaximum
65      *
66      * Note: In addition to outright failures, this test reports some
67      * results as warnings.  These are not generally of concern, but they
68      * should be evaluated by a human.  To see these, run this test in
69      * verbose mode.
70      * @param cal the calendar to be tested
71      * @param fieldsToTest an array of field values to be tested, e.g., new
72      * int[] { UCAL_MONTH, UCAL_DAY_OF_MONTH }.  It only makes
73      * sense to test the day fields; the time fields are not tested by this
74      * method.  If null, then test all standard fields.
75      * @param startDate the first date to test
76      * @param testDuration if positive, the number of days to be tested.
77      * If negative, the number of seconds to run the test.
78      */
79     void doLimitsTest(Calendar& cal, const int32_t* fieldsToTest, UDate startDate, int32_t testDuration);
80
81     /**
82      * doLimitsTest with default test duration and fields
83      */
84     void doLimitsTest(Calendar& cal, UDate startDate, int32_t endTime);
85
86     UnicodeString& ymdToString(const Calendar& cal, UnicodeString& str);
87 };
88
89 #endif /* #if !UCONFIG_NO_FORMATTING */
90  
91 #endif // __CalendarLimitTest__