]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/dtfmtrtts.h
ICU-64252.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / dtfmtrtts.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/********************************************************************
4 * COPYRIGHT:
73c04bcf 5 * Copyright (c) 1997-2006, International Business Machines Corporation and
b75a7d8f
A
6 * others. All Rights Reserved.
7 ********************************************************************/
8
9#ifndef _DATEFORMATROUNDTRIPTEST_
10#define _DATEFORMATROUNDTRIPTEST_
11
b75a7d8f
A
12#include "unicode/utypes.h"
13
14#if !UCONFIG_NO_FORMATTING
15
16#include "unicode/unistr.h"
17#include "unicode/datefmt.h"
18#include "unicode/smpdtfmt.h"
19#include "unicode/calendar.h"
20#include "intltest.h"
21
22/**
23 * Performs round-trip tests for DateFormat
24 **/
25class DateFormatRoundTripTest : public IntlTest {
26
27 // IntlTest override
28 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
29
30public:
374ca955
A
31 DateFormatRoundTripTest();
32 virtual ~DateFormatRoundTripTest();
33
b75a7d8f 34 void TestDateFormatRoundTrip(void);
73c04bcf 35 void TestCentury(void);
b75a7d8f
A
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);
374ca955 41 UDate generateDate(UDate minDate);
b75a7d8f
A
42
43
44//============================================================
45// statics
46//============================================================
47
48/**
49 * Return a random uint32_t
50 **/
374ca955
A
51static 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);
b75a7d8f
A
56}
57
58/**
374ca955 59 * Return a random double 0 <= x <= 1.0
b75a7d8f
A
60 **/
61static double randFraction()
62{
63 return (double)randLong() / (double)0xFFFFFFFF;
64}
65
66/**
374ca955 67 * Return a random value from -range..+range (closed).
b75a7d8f
A
68 **/
69static double randDouble(double range)
70{
71 double a = randFraction();
72 //while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
73 // a = randFraction();
74 return (2.0 * range * a) - range;
75}
76
77protected:
78 UBool failure(UErrorCode status, const char* msg);
79 UBool failure(UErrorCode status, const char* msg, const UnicodeString& str);
80
374ca955
A
81 const UnicodeString& fullFormat(UDate d);
82
b75a7d8f
A
83private:
84
85 static int32_t SPARSENESS;
86 static int32_t TRIALS;
87 static int32_t DEPTH;
88
374ca955 89 UBool optionv; // TRUE if @v option is given on command line
b75a7d8f 90 SimpleDateFormat *dateFormat;
374ca955 91 UnicodeString fgStr;
b75a7d8f
A
92 Calendar *getFieldCal;
93};
94
95#endif /* #if !UCONFIG_NO_FORMATTING */
96
97#endif // _DATEFORMATROUNDTRIPTEST_
98//eof