]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/dtfmtrtts.h
1 /********************************************************************
3 * Copyright (c) 1997-2003, 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 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);
38 UDate
generateDate(UDate minDate
);
41 //============================================================
43 //============================================================
46 * Return a random uint32_t
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);
56 * Return a random double 0 <= x <= 1.0
58 static double randFraction()
60 return (double)randLong() / (double)0xFFFFFFFF;
64 * Return a random value from -range..+range (closed).
66 static double randDouble(double range
)
68 double a
= randFraction();
69 //while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
70 // a = randFraction();
71 return (2.0 * range
* a
) - range
;
75 UBool
failure(UErrorCode status
, const char* msg
);
76 UBool
failure(UErrorCode status
, const char* msg
, const UnicodeString
& str
);
78 const UnicodeString
& fullFormat(UDate d
);
82 static int32_t SPARSENESS
;
83 static int32_t TRIALS
;
86 UBool optionv
; // TRUE if @v option is given on command line
87 SimpleDateFormat
*dateFormat
;
89 Calendar
*getFieldCal
;
92 #endif /* #if !UCONFIG_NO_FORMATTING */
94 #endif // _DATEFORMATROUNDTRIPTEST_