]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/dtfmtrtts.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2006, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
9 #ifndef _DATEFORMATROUNDTRIPTEST_
10 #define _DATEFORMATROUNDTRIPTEST_
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_FORMATTING
16 #include "unicode/unistr.h"
17 #include "unicode/datefmt.h"
18 #include "unicode/smpdtfmt.h"
19 #include "unicode/calendar.h"
23 * Performs round-trip tests for DateFormat
25 class DateFormatRoundTripTest
: public IntlTest
{
28 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
31 DateFormatRoundTripTest();
32 virtual ~DateFormatRoundTripTest();
34 void TestDateFormatRoundTrip(void);
35 void TestCentury(void);
36 void test(const Locale
& loc
);
37 void test(DateFormat
*fmt
, const Locale
&origLocale
, UBool timeOnly
= FALSE
);
38 int32_t getField(UDate d
, int32_t f
);
39 UnicodeString
& escape(const UnicodeString
& src
, UnicodeString
& dst
);
40 UDate
generateDate(void);
41 UDate
generateDate(UDate minDate
);
44 //============================================================
46 //============================================================
49 * Return a random uint32_t
51 static uint32_t randLong() {
52 // The portable IntlTest::random() function has sufficient
53 // resolution for a 16-bit value, but not for 32 bits.
54 return ((uint32_t) (IntlTest::random() * (1<<16))) |
55 (((uint32_t) (IntlTest::random() * (1<<16))) << 16);
59 * Return a random double 0 <= x <= 1.0
61 static double randFraction()
63 return (double)randLong() / (double)0xFFFFFFFF;
67 * Return a random value from -range..+range (closed).
69 static double randDouble(double range
)
71 double a
= randFraction();
72 //while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
73 // a = randFraction();
74 return (2.0 * range
* a
) - range
;
78 UBool
failure(UErrorCode status
, const char* msg
);
79 UBool
failure(UErrorCode status
, const char* msg
, const UnicodeString
& str
);
81 const UnicodeString
& fullFormat(UDate d
);
85 static int32_t SPARSENESS
;
86 static int32_t TRIALS
;
89 UBool optionv
; // TRUE if @v option is given on command line
90 SimpleDateFormat
*dateFormat
;
92 Calendar
*getFieldCal
;
95 #endif /* #if !UCONFIG_NO_FORMATTING */
97 #endif // _DATEFORMATROUNDTRIPTEST_