]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/dtfmtrtts.h
ICU-511.34.tar.gz
[apple/icu.git] / icuSources / test / intltest / dtfmtrtts.h
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2006, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7 #ifndef _DATEFORMATROUNDTRIPTEST_
8 #define _DATEFORMATROUNDTRIPTEST_
9
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:
29 DateFormatRoundTripTest();
30 virtual ~DateFormatRoundTripTest();
31
32 void TestDateFormatRoundTrip(void);
33 void TestCentury(void);
34 void test(const Locale& loc);
35 void test(DateFormat *fmt, const Locale &origLocale, UBool timeOnly = FALSE );
36 int32_t getField(UDate d, int32_t f);
37 UnicodeString& escape(const UnicodeString& src, UnicodeString& dst);
38 UDate generateDate(void);
39 UDate generateDate(UDate minDate);
40
41
42 //============================================================
43 // statics
44 //============================================================
45
46 /**
47 * Return a random uint32_t
48 **/
49 static uint32_t randLong() {
50 // The portable IntlTest::random() function has sufficient
51 // resolution for a 16-bit value, but not for 32 bits.
52 return ((uint32_t) (IntlTest::random() * (1<<16))) |
53 (((uint32_t) (IntlTest::random() * (1<<16))) << 16);
54 }
55
56 /**
57 * Return a random double 0 <= x <= 1.0
58 **/
59 static double randFraction()
60 {
61 return (double)randLong() / (double)0xFFFFFFFF;
62 }
63
64 /**
65 * Return a random value from -range..+range (closed).
66 **/
67 static double randDouble(double range)
68 {
69 double a = randFraction();
70 //while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
71 // a = randFraction();
72 return (2.0 * range * a) - range;
73 }
74
75 protected:
76 UBool failure(UErrorCode status, const char* msg);
77 UBool failure(UErrorCode status, const char* msg, const UnicodeString& str);
78
79 const UnicodeString& fullFormat(UDate d);
80
81 private:
82
83 static int32_t SPARSENESS;
84 static int32_t TRIALS;
85 static int32_t DEPTH;
86
87 UBool optionv; // TRUE if @v option is given on command line
88 SimpleDateFormat *dateFormat;
89 UnicodeString fgStr;
90 Calendar *getFieldCal;
91 };
92
93 #endif /* #if !UCONFIG_NO_FORMATTING */
94
95 #endif // _DATEFORMATROUNDTRIPTEST_
96 //eof