]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/dtfmtrtts.h
ICU-551.41.tar.gz
[apple/icu.git] / icuSources / test / intltest / dtfmtrtts.h
CommitLineData
b75a7d8f
A
1/********************************************************************
2 * COPYRIGHT:
73c04bcf 3 * Copyright (c) 1997-2006, International Business Machines Corporation and
b75a7d8f
A
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 **/
23class DateFormatRoundTripTest : public IntlTest {
24
25 // IntlTest override
26 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
27
28public:
374ca955
A
29 DateFormatRoundTripTest();
30 virtual ~DateFormatRoundTripTest();
31
b75a7d8f 32 void TestDateFormatRoundTrip(void);
73c04bcf 33 void TestCentury(void);
b75a7d8f
A
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);
374ca955 39 UDate generateDate(UDate minDate);
b75a7d8f
A
40
41
42//============================================================
43// statics
44//============================================================
45
46/**
47 * Return a random uint32_t
48 **/
374ca955
A
49static 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);
b75a7d8f
A
54}
55
56/**
374ca955 57 * Return a random double 0 <= x <= 1.0
b75a7d8f
A
58 **/
59static double randFraction()
60{
61 return (double)randLong() / (double)0xFFFFFFFF;
62}
63
64/**
374ca955 65 * Return a random value from -range..+range (closed).
b75a7d8f
A
66 **/
67static 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
75protected:
76 UBool failure(UErrorCode status, const char* msg);
77 UBool failure(UErrorCode status, const char* msg, const UnicodeString& str);
78
374ca955
A
79 const UnicodeString& fullFormat(UDate d);
80
b75a7d8f
A
81private:
82
83 static int32_t SPARSENESS;
84 static int32_t TRIALS;
85 static int32_t DEPTH;
86
374ca955 87 UBool optionv; // TRUE if @v option is given on command line
b75a7d8f 88 SimpleDateFormat *dateFormat;
374ca955 89 UnicodeString fgStr;
b75a7d8f
A
90 Calendar *getFieldCal;
91};
92
93#endif /* #if !UCONFIG_NO_FORMATTING */
94
95#endif // _DATEFORMATROUNDTRIPTEST_
96//eof