]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/dtfmtrtts.h
1 /********************************************************************
3 * Copyright (c) 1997-2006, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #ifndef _DATEFORMATROUNDTRIPTEST_
8 #define _DATEFORMATROUNDTRIPTEST_
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/unistr.h"
15 #include "unicode/datefmt.h"
16 #include "unicode/smpdtfmt.h"
17 #include "unicode/calendar.h"
21 * Performs round-trip tests for DateFormat
23 class DateFormatRoundTripTest
: public IntlTest
{
26 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
29 DateFormatRoundTripTest();
30 virtual ~DateFormatRoundTripTest();
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
);
42 //============================================================
44 //============================================================
47 * Return a random uint32_t
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);
57 * Return a random double 0 <= x <= 1.0
59 static double randFraction()
61 return (double)randLong() / (double)0xFFFFFFFF;
65 * Return a random value from -range..+range (closed).
67 static double randDouble(double range
)
69 double a
= randFraction();
70 //while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
71 // a = randFraction();
72 return (2.0 * range
* a
) - range
;
76 UBool
failure(UErrorCode status
, const char* msg
);
77 UBool
failure(UErrorCode status
, const char* msg
, const UnicodeString
& str
);
79 const UnicodeString
& fullFormat(UDate d
);
83 static int32_t SPARSENESS
;
84 static int32_t TRIALS
;
87 UBool optionv
; // TRUE if @v option is given on command line
88 SimpleDateFormat
*dateFormat
;
90 Calendar
*getFieldCal
;
93 #endif /* #if !UCONFIG_NO_FORMATTING */
95 #endif // _DATEFORMATROUNDTRIPTEST_