scuffed-code/icu4c/source/test/intltest/dtfmtrtts.h

99 lines
2.7 KiB
C
Raw Normal View History

// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2006, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
1999-08-16 21:50:52 +00:00
#ifndef _DATEFORMATROUNDTRIPTEST_
#define _DATEFORMATROUNDTRIPTEST_
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include "unicode/unistr.h"
#include "unicode/datefmt.h"
#include "unicode/smpdtfmt.h"
#include "unicode/calendar.h"
#include "intltest.h"
1999-08-16 21:50:52 +00:00
/**
* Performs round-trip tests for DateFormat
**/
class DateFormatRoundTripTest : public IntlTest {
// IntlTest override
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
1999-08-16 21:50:52 +00:00
public:
DateFormatRoundTripTest();
virtual ~DateFormatRoundTripTest();
1999-08-16 21:50:52 +00:00
void TestDateFormatRoundTrip(void);
void TestCentury(void);
1999-08-16 21:50:52 +00:00
void test(const Locale& loc);
void test(DateFormat *fmt, const Locale &origLocale, UBool timeOnly = FALSE );
1999-08-16 21:50:52 +00:00
int32_t getField(UDate d, int32_t f);
UnicodeString& escape(const UnicodeString& src, UnicodeString& dst);
UDate generateDate(void);
UDate generateDate(UDate minDate);
1999-08-16 21:50:52 +00:00
//============================================================
// statics
//============================================================
/**
* Return a random uint32_t
**/
static uint32_t randLong() {
// The portable IntlTest::random() function has sufficient
// resolution for a 16-bit value, but not for 32 bits.
return ((uint32_t) (IntlTest::random() * (1<<16))) |
(((uint32_t) (IntlTest::random() * (1<<16))) << 16);
1999-08-16 21:50:52 +00:00
}
/**
* Return a random double 0 <= x <= 1.0
1999-08-16 21:50:52 +00:00
**/
static double randFraction()
{
return (double)randLong() / (double)0xFFFFFFFF;
}
/**
* Return a random value from -range..+range (closed).
1999-08-16 21:50:52 +00:00
**/
static double randDouble(double range)
{
double a = randFraction();
//while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
// a = randFraction();
return (2.0 * range * a) - range;
}
protected:
UBool failure(UErrorCode status, const char* msg);
UBool failure(UErrorCode status, const char* msg, const UnicodeString& str);
1999-08-16 21:50:52 +00:00
const UnicodeString& fullFormat(UDate d);
1999-08-16 21:50:52 +00:00
private:
static int32_t SPARSENESS;
static int32_t TRIALS;
static int32_t DEPTH;
UBool optionv; // TRUE if @v option is given on command line
1999-08-16 21:50:52 +00:00
SimpleDateFormat *dateFormat;
UnicodeString fgStr;
1999-08-16 21:50:52 +00:00
Calendar *getFieldCal;
};
#endif /* #if !UCONFIG_NO_FORMATTING */
1999-08-16 21:50:52 +00:00
#endif // _DATEFORMATROUNDTRIPTEST_
//eof