1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2008, International Business Machines Corporation and
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef __CalendarLimitTest__
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define __CalendarLimitTest__
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "caltztst.h"
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This test verifies the behavior of Calendar around the very earliest limits
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * which it can handle.  It also verifies the behavior for large values of millis.
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Bug ID 4033662.
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass CalendarLimitTest: public CalendarTimeZoneTest {
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // IntlTest override
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: // package
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //test routine used by TestCalendarLimit
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void test(UDate millis, Calendar *cal, DateFormat *fmt);
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // bug 986c: deprecate nextDouble/previousDouble
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //static double nextDouble(double a);
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //static double previousDouble(double a);
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UBool withinErr(double a, double b, double err);
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic:
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // test behaviour and error reporting at boundaries of defined range
3685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    virtual void TestCalendarExtremeLimit(void);
3785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
3885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    void TestLimits(void);
3985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
4085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hoprivate:
4185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /*
4285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * Test the functions getMaximum/getGeratestMinimum logically correct.
4385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * This method assumes day of week cycle is consistent.
4485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * @param cal The calendar instance to be tested.
4585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * @param leapMonth true if the calendar system has leap months
4685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     */
4785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    void doTheoreticalLimitsTest(Calendar& cal, UBool leapMonth);
4885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
4985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /*
5085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * Test the functions getXxxMinimum() and getXxxMaximum() by marching a
5185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * test calendar 'cal' through 'numberOfDays' sequential days starting
5285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * with 'startDate'.  For each date, read a field value along with its
5385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * reported actual minimum and actual maximum.  These values are
5485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * checked against one another as well as against getMinimum(),
5585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * getGreatestMinimum(), getLeastMaximum(), and getMaximum().  We
5685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * expect to see:
5785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *
5885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * 1. minimum <= actualMinimum <= greatestMinimum <=
5985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *    leastMaximum <= actualMaximum <= maximum
6085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *
6185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * 2. actualMinimum <= value <= actualMaximum
6285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *
6385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * Note: In addition to outright failures, this test reports some
6485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * results as warnings.  These are not generally of concern, but they
6585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * should be evaluated by a human.  To see these, run this test in
6685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * verbose mode.
6785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * @param cal the calendar to be tested
6885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * @param fieldsToTest an array of field values to be tested, e.g., new
6985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * int[] { UCAL_MONTH, UCAL_DAY_OF_MONTH }.  It only makes
7085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * sense to test the day fields; the time fields are not tested by this
7185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * method.  If null, then test all standard fields.
7285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * @param startDate the first date to test
7385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * @param testDuration if positive, the number of days to be tested.
7485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * If negative, the number of seconds to run the test.
7585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     */
7685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    void doLimitsTest(Calendar& cal, const int32_t* fieldsToTest, UDate startDate, int32_t testDuration);
7785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
7885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /**
7985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * doLimitsTest with default test duration and fields
8085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     */
8185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    void doLimitsTest(Calendar& cal, UDate startDate);
8285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
8385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UnicodeString& ymdToString(const Calendar& cal, UnicodeString& str);
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_FORMATTING */
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif // __CalendarLimitTest__
89