2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2001-03-21 20:09:56 +00:00
|
|
|
* Copyright (c) 1997-2001, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#ifndef _DATEFORMATROUNDTRIPTEST_
|
|
|
|
#define _DATEFORMATROUNDTRIPTEST_
|
|
|
|
|
2000-08-24 01:12:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unistr.h"
|
2001-10-08 23:26:58 +00:00
|
|
|
#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
|
2000-08-14 21:42:36 +00:00
|
|
|
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
void TestDateFormatRoundTrip(void);
|
|
|
|
void test(const Locale& loc);
|
2002-04-11 02:44:53 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
// statics
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random uint32_t
|
|
|
|
**/
|
|
|
|
static uint32_t randLong()
|
|
|
|
{
|
|
|
|
// Assume 8-bit (or larger) rand values. Also assume
|
|
|
|
// that the system rand() function is very poor, which it always is.
|
|
|
|
uint32_t d;
|
2000-08-24 01:12:12 +00:00
|
|
|
uint32_t i;
|
2000-08-11 22:19:54 +00:00
|
|
|
char* poke = (char*)&d;
|
1999-08-16 21:50:52 +00:00
|
|
|
for (i=0; i < sizeof(uint32_t); ++i)
|
|
|
|
{
|
2000-08-11 22:19:54 +00:00
|
|
|
poke[i] = (char)(rand() & 0xFF);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random double 0 <= x < 1.0
|
|
|
|
**/
|
|
|
|
static double randFraction()
|
|
|
|
{
|
|
|
|
return (double)randLong() / (double)0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random value from -range..+range.
|
|
|
|
**/
|
|
|
|
static double randDouble(double range)
|
|
|
|
{
|
|
|
|
double a = randFraction();
|
|
|
|
//while(TPlatformUtilities::isInfinite(a) || TPlatformUtilities::isNaN(a))
|
|
|
|
// a = randFraction();
|
|
|
|
return (2.0 * range * a) - range;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool failure(UErrorCode status, const char* msg);
|
2003-05-30 00:52:43 +00:00
|
|
|
UBool failure(UErrorCode status, const char* msg, const UnicodeString& str);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static int32_t SPARSENESS;
|
|
|
|
static int32_t TRIALS;
|
|
|
|
static int32_t DEPTH;
|
|
|
|
|
|
|
|
SimpleDateFormat *dateFormat;
|
|
|
|
Calendar *getFieldCal;
|
|
|
|
};
|
2002-09-21 00:43:14 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#endif // _DATEFORMATROUNDTRIPTEST_
|
|
|
|
//eof
|