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 _INTLTESTNUMBERFORMAT
|
|
|
|
#define _INTLTESTNUMBERFORMAT
|
|
|
|
|
|
|
|
|
2000-08-24 01:12:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "intltest.h"
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/fmtable.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
class NumberFormat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test does round-trip testing (format -> parse -> format -> parse -> etc.) of
|
|
|
|
* NumberFormat.
|
|
|
|
*/
|
|
|
|
class IntlTestNumberFormat: public IntlTest {
|
2000-08-14 21:42:36 +00:00
|
|
|
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* call tryIt with many variations, called by testLocale
|
|
|
|
**/
|
2000-08-23 19:11:16 +00:00
|
|
|
void testFormat(/* char* par */);
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* perform tests using aNumber and fFormat, called in many variations
|
|
|
|
**/
|
|
|
|
void tryIt(double aNumber);
|
|
|
|
/**
|
|
|
|
* perform tests using aNumber and fFormat, called in many variations
|
|
|
|
**/
|
|
|
|
void tryIt(int32_t aNumber);
|
|
|
|
/**
|
|
|
|
* test NumberFormat::getAvailableLocales
|
|
|
|
**/
|
2000-08-23 19:11:16 +00:00
|
|
|
void testAvailableLocales(/* char* par */);
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* call testLocale for all locales
|
|
|
|
**/
|
2000-08-23 19:11:16 +00:00
|
|
|
void monsterTest(/* char *par */);
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* call testFormat for currency, percent and plain number instances
|
|
|
|
**/
|
2000-08-23 19:11:16 +00:00
|
|
|
void testLocale(/* char *par, */const Locale& locale, const UnicodeString& localeName);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
NumberFormat* fFormat;
|
2000-12-06 17:10:54 +00:00
|
|
|
UErrorCode fStatus;
|
|
|
|
Locale fLocale;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2000-12-20 21:19:54 +00:00
|
|
|
virtual ~IntlTestNumberFormat() {}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a random double
|
|
|
|
**/
|
|
|
|
static double randDouble()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-12-20 21:19:54 +00:00
|
|
|
// Assume 8-bit (or larger) rand values. Also assume
|
|
|
|
// that the system rand() function is very poor, which it always is.
|
|
|
|
// Call srand(currentTime) in intltest to make it truly random.
|
|
|
|
double d;
|
|
|
|
uint32_t i;
|
|
|
|
char* poke = (char*)&d;
|
|
|
|
for (i=0; i < sizeof(double); ++i)
|
|
|
|
{
|
|
|
|
poke[i] = (char)(rand() & 0xFF);
|
|
|
|
}
|
|
|
|
return d;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-12-20 21:19:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a random uint32_t
|
|
|
|
**/
|
|
|
|
static uint32_t randLong()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-12-20 21:19:54 +00:00
|
|
|
// Assume 8-bit (or larger) rand values. Also assume
|
|
|
|
// that the system rand() function is very poor, which it always is.
|
|
|
|
// Call srand(currentTime) in intltest to make it truly random.
|
|
|
|
uint32_t d;
|
|
|
|
uint32_t i;
|
|
|
|
char* poke = (char*)&d;
|
|
|
|
for (i=0; i < sizeof(uint32_t); ++i)
|
|
|
|
{
|
|
|
|
poke[i] = (char)(rand() & 0xFF);
|
|
|
|
}
|
|
|
|
return d;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-12-20 21:19:54 +00:00
|
|
|
/**
|
|
|
|
* Return a random double 0 <= x < 1.0
|
|
|
|
**/
|
|
|
|
static double randFraction()
|
|
|
|
{
|
|
|
|
return (double)randLong() / (double)0xFFFFFFFF;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|