]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
3 | * Copyright (c) 1997-2003, International Business Machines Corporation and | |
4 | * others. All Rights Reserved. | |
5 | ********************************************************************/ | |
6 | ||
7 | #ifndef _DATEFORMATROUNDTRIPTEST_ | |
8 | #define _DATEFORMATROUNDTRIPTEST_ | |
9 | ||
b75a7d8f A |
10 | #include "unicode/utypes.h" |
11 | ||
12 | #if !UCONFIG_NO_FORMATTING | |
13 | ||
14 | #include "unicode/unistr.h" | |
15 | #include "unicode/datefmt.h" | |
16 | #include "unicode/smpdtfmt.h" | |
17 | #include "unicode/calendar.h" | |
18 | #include "intltest.h" | |
19 | ||
20 | /** | |
21 | * Performs round-trip tests for DateFormat | |
22 | **/ | |
23 | class DateFormatRoundTripTest : public IntlTest { | |
24 | ||
25 | // IntlTest override | |
26 | void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ); | |
27 | ||
28 | public: | |
374ca955 A |
29 | DateFormatRoundTripTest(); |
30 | virtual ~DateFormatRoundTripTest(); | |
31 | ||
b75a7d8f A |
32 | void TestDateFormatRoundTrip(void); |
33 | void test(const Locale& loc); | |
34 | void test(DateFormat *fmt, const Locale &origLocale, UBool timeOnly = FALSE ); | |
35 | int32_t getField(UDate d, int32_t f); | |
36 | UnicodeString& escape(const UnicodeString& src, UnicodeString& dst); | |
37 | UDate generateDate(void); | |
374ca955 | 38 | UDate generateDate(UDate minDate); |
b75a7d8f A |
39 | |
40 | ||
41 | //============================================================ | |
42 | // statics | |
43 | //============================================================ | |
44 | ||
45 | /** | |
46 | * Return a random uint32_t | |
47 | **/ | |
374ca955 A |
48 | static uint32_t randLong() { |
49 | // The portable IntlTest::random() function has sufficient | |
50 | // resolution for a 16-bit value, but not for 32 bits. | |
51 | return ((uint32_t) (IntlTest::random() * (1<<16))) | | |
52 | (((uint32_t) (IntlTest::random() * (1<<16))) << 16); | |
b75a7d8f A |
53 | } |
54 | ||
55 | /** | |
374ca955 | 56 | * Return a random double 0 <= x <= 1.0 |
b75a7d8f A |
57 | **/ |
58 | static double randFraction() | |
59 | { | |
60 | return (double)randLong() / (double)0xFFFFFFFF; | |
61 | } | |
62 | ||
63 | /** | |
374ca955 | 64 | * Return a random value from -range..+range (closed). |
b75a7d8f A |
65 | **/ |
66 | static double randDouble(double range) | |
67 | { | |
68 | double a = randFraction(); | |
69 | //while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a)) | |
70 | // a = randFraction(); | |
71 | return (2.0 * range * a) - range; | |
72 | } | |
73 | ||
74 | protected: | |
75 | UBool failure(UErrorCode status, const char* msg); | |
76 | UBool failure(UErrorCode status, const char* msg, const UnicodeString& str); | |
77 | ||
374ca955 A |
78 | const UnicodeString& fullFormat(UDate d); |
79 | ||
b75a7d8f A |
80 | private: |
81 | ||
82 | static int32_t SPARSENESS; | |
83 | static int32_t TRIALS; | |
84 | static int32_t DEPTH; | |
85 | ||
374ca955 | 86 | UBool optionv; // TRUE if @v option is given on command line |
b75a7d8f | 87 | SimpleDateFormat *dateFormat; |
374ca955 | 88 | UnicodeString fgStr; |
b75a7d8f A |
89 | Calendar *getFieldCal; |
90 | }; | |
91 | ||
92 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
93 | ||
94 | #endif // _DATEFORMATROUNDTRIPTEST_ | |
95 | //eof |