2004-11-01 18:56:24 +00:00
|
|
|
/***********************************************************************
|
2000-01-15 02:00:06 +00:00
|
|
|
* COPYRIGHT:
|
2011-03-07 20:02:28 +00:00
|
|
|
* Copyright (c) 1997-2011, International Business Machines Corporation
|
2004-11-01 18:56:24 +00:00
|
|
|
* and others. All Rights Reserved.
|
|
|
|
***********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
2002-09-21 00:43:14 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/decimfmt.h"
|
2001-10-08 23:26:58 +00:00
|
|
|
#include "tsnmfmt.h"
|
2004-10-18 02:43:33 +00:00
|
|
|
#include "putilimp.h"
|
2011-03-09 17:17:19 +00:00
|
|
|
#include "cstring.h"
|
2002-08-08 23:47:09 +00:00
|
|
|
#include <float.h>
|
2003-12-03 06:58:28 +00:00
|
|
|
#include <stdlib.h>
|
2001-01-02 21:17:18 +00:00
|
|
|
|
2003-08-29 15:57:38 +00:00
|
|
|
IntlTestNumberFormat::~IntlTestNumberFormat() {}
|
|
|
|
|
2000-12-06 17:10:54 +00:00
|
|
|
static const char * formattableTypeName(Formattable::Type t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
|
|
|
case Formattable::kDate: return "kDate";
|
|
|
|
case Formattable::kDouble: return "kDouble";
|
|
|
|
case Formattable::kLong: return "kLong";
|
|
|
|
case Formattable::kString: return "kString";
|
|
|
|
case Formattable::kArray: return "kArray";
|
2003-10-31 22:47:25 +00:00
|
|
|
case Formattable::kInt64: return "kInt64";
|
2000-12-06 17:10:54 +00:00
|
|
|
default: return "??unknown??";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* This test does round-trip testing (format -> parse -> format -> parse -> etc.) of
|
|
|
|
* NumberFormat.
|
|
|
|
*/
|
2000-08-23 19:11:16 +00:00
|
|
|
void IntlTestNumberFormat::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (exec) logln((UnicodeString)"TestSuite NumberFormat");
|
|
|
|
switch (index) {
|
|
|
|
case 0: name = "createInstance";
|
|
|
|
if (exec)
|
|
|
|
{
|
|
|
|
logln(name);
|
1999-10-07 00:07:53 +00:00
|
|
|
fStatus = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
fFormat = NumberFormat::createInstance(fStatus);
|
2000-08-23 19:11:16 +00:00
|
|
|
testFormat(/*par*/);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-09-18 18:04:14 +00:00
|
|
|
case 1: name = "DefaultLocale";
|
|
|
|
if (exec) testLocale(/*par, */Locale::getDefault(), name);
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
2001-09-18 18:04:14 +00:00
|
|
|
case 2: name = "testAvailableLocales";
|
1999-08-16 21:50:52 +00:00
|
|
|
if (exec) {
|
|
|
|
logln(name);
|
2000-08-23 19:11:16 +00:00
|
|
|
testAvailableLocales(/*par*/);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-09-18 18:04:14 +00:00
|
|
|
case 3: name = "monsterTest";
|
1999-08-16 21:50:52 +00:00
|
|
|
if (exec) {
|
|
|
|
logln(name);
|
2000-08-23 19:11:16 +00:00
|
|
|
monsterTest(/*par*/);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-23 19:11:16 +00:00
|
|
|
IntlTestNumberFormat::testLocale(/* char* par, */const Locale& locale, const UnicodeString& localeName)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
|
2000-12-06 17:10:54 +00:00
|
|
|
fLocale = locale;
|
1999-08-16 21:50:52 +00:00
|
|
|
name = "Number test";
|
|
|
|
logln((UnicodeString)name + " (" + localeName + ")");
|
1999-10-07 00:07:53 +00:00
|
|
|
fStatus = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
fFormat = NumberFormat::createInstance(locale, fStatus);
|
2000-08-23 19:11:16 +00:00
|
|
|
testFormat(/* par */);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
name = "Currency test";
|
|
|
|
logln((UnicodeString)name + " (" + localeName + ")");
|
1999-10-07 00:07:53 +00:00
|
|
|
fStatus = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
fFormat = NumberFormat::createCurrencyInstance(locale, fStatus);
|
2000-08-23 19:11:16 +00:00
|
|
|
testFormat(/* par */);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
name = "Percent test";
|
|
|
|
logln((UnicodeString)name + " (" + localeName + ")");
|
1999-10-07 00:07:53 +00:00
|
|
|
fStatus = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
fFormat = NumberFormat::createPercentInstance(locale, fStatus);
|
2000-08-23 19:11:16 +00:00
|
|
|
testFormat(/* par */);
|
2011-03-07 20:02:28 +00:00
|
|
|
|
2011-03-09 17:17:19 +00:00
|
|
|
if (uprv_strcmp(locale.getName(), "en_US_POSIX") != 0) {
|
|
|
|
name = "Scientific test";
|
|
|
|
logln((UnicodeString)name + " (" + localeName + ")");
|
|
|
|
fStatus = U_ZERO_ERROR;
|
|
|
|
fFormat = NumberFormat::createScientificInstance(locale, fStatus);
|
|
|
|
testFormat(/* par */);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-08-08 23:47:09 +00:00
|
|
|
double IntlTestNumberFormat::randDouble()
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
do {
|
|
|
|
for (i=0; i < sizeof(double); ++i)
|
|
|
|
{
|
|
|
|
poke[i] = (char)(rand() & 0xFF);
|
|
|
|
}
|
|
|
|
} while (uprv_isNaN(d) || uprv_isInfinite(d)
|
|
|
|
|| !((-DBL_MAX < d && d < DBL_MAX) || (d < -DBL_MIN && DBL_MIN < d)));
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a random uint32_t
|
|
|
|
**/
|
|
|
|
uint32_t IntlTestNumberFormat::randLong()
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-04 22:34:37 +00:00
|
|
|
/* Make sure that we don't get something too large and multiply into infinity.
|
|
|
|
@param smallerThanMax the requested maximum value smaller than DBL_MAX */
|
2002-08-08 23:47:09 +00:00
|
|
|
double IntlTestNumberFormat::getSafeDouble(double smallerThanMax) {
|
|
|
|
double it;
|
2003-12-04 22:34:37 +00:00
|
|
|
double high = (DBL_MAX/smallerThanMax)/10.0;
|
|
|
|
double low = -high;
|
2002-08-08 23:47:09 +00:00
|
|
|
do {
|
|
|
|
it = randDouble();
|
2003-12-04 22:34:37 +00:00
|
|
|
} while (low > it || it > high);
|
2002-08-08 23:47:09 +00:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
2000-08-23 19:11:16 +00:00
|
|
|
IntlTestNumberFormat::testFormat(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(fStatus))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln((UnicodeString)"**** FAIL: createXxxInstance failed. - " + u_errorName(fStatus));
|
2000-08-23 19:11:16 +00:00
|
|
|
if (fFormat != 0)
|
2000-12-12 22:54:36 +00:00
|
|
|
errln("**** FAIL: Non-null format returned by createXxxInstance upon failure.");
|
1999-08-16 21:50:52 +00:00
|
|
|
delete fFormat;
|
|
|
|
fFormat = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fFormat == 0)
|
|
|
|
{
|
2000-12-12 22:54:36 +00:00
|
|
|
errln((UnicodeString)"**** FAIL: Null format returned by createXxxInstance.");
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString str;
|
|
|
|
|
|
|
|
// Assume it's a DecimalFormat and get some info
|
|
|
|
DecimalFormat *s = (DecimalFormat*)fFormat;
|
|
|
|
logln((UnicodeString)" Pattern " + s->toPattern(str));
|
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(-2.02147304840132e-68);
|
|
|
|
tryIt(3.88057859588817e-68); // Test rounding when only some digits are shown because exponent is close to -maxfrac
|
|
|
|
tryIt(-2.64651110485945e+65); // Overflows to +INF when shown as a percent
|
|
|
|
tryIt(9.29526819488338e+64); // Ok -- used to fail?
|
2000-03-22 23:17:42 +00:00
|
|
|
#else
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(-2.02147304840132e-100);
|
|
|
|
tryIt(3.88057859588817e-096); // Test rounding when only some digits are shown because exponent is close to -maxfrac
|
|
|
|
tryIt(-2.64651110485945e+306); // Overflows to +INF when shown as a percent
|
|
|
|
tryIt(9.29526819488338e+250); // Ok -- used to fail?
|
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
// These PASS now, with the sprintf/atof based format-parse.
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
// These fail due to round-off
|
|
|
|
// The least significant digit drops by one during each format-parse cycle.
|
|
|
|
// Both numbers DON'T have a round-off problem when multiplied by 100! (shown as %)
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM == U_PF_OS390
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(-9.18228054496402e+64);
|
|
|
|
tryIt(-9.69413034454191e+64);
|
2000-03-22 23:17:42 +00:00
|
|
|
#else
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(-9.18228054496402e+255);
|
|
|
|
tryIt(-9.69413034454191e+273);
|
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM != U_PF_OS390
|
2001-04-17 00:37:06 +00:00
|
|
|
tryIt(1.234e-200);
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(-2.3e-168);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(uprv_getNaN());
|
|
|
|
tryIt(uprv_getInfinity());
|
|
|
|
tryIt(-uprv_getInfinity());
|
2000-03-22 23:17:42 +00:00
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-04-17 00:37:06 +00:00
|
|
|
tryIt((int32_t)251887531);
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(5e-20 / 9);
|
|
|
|
tryIt(5e20 / 9);
|
|
|
|
tryIt(1.234e-50);
|
|
|
|
tryIt(9.99999999999996);
|
|
|
|
tryIt(9.999999999999996);
|
2011-03-07 20:02:28 +00:00
|
|
|
|
|
|
|
tryIt(5.06e-27);
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
tryIt((int32_t)INT32_MIN);
|
|
|
|
tryIt((int32_t)INT32_MAX);
|
2001-04-17 00:37:06 +00:00
|
|
|
tryIt((double)INT32_MIN);
|
|
|
|
tryIt((double)INT32_MAX);
|
|
|
|
tryIt((double)INT32_MIN - 1.0);
|
|
|
|
tryIt((double)INT32_MAX + 1.0);
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
tryIt(5.0 / 9.0 * 1e-20);
|
|
|
|
tryIt(4.0 / 9.0 * 1e-20);
|
|
|
|
tryIt(5.0 / 9.0 * 1e+20);
|
|
|
|
tryIt(4.0 / 9.0 * 1e+20);
|
|
|
|
|
|
|
|
tryIt(2147483647.);
|
|
|
|
tryIt((int32_t)0);
|
|
|
|
tryIt(0.0);
|
|
|
|
tryIt((int32_t)1);
|
|
|
|
tryIt((int32_t)10);
|
|
|
|
tryIt((int32_t)100);
|
|
|
|
tryIt((int32_t)-1);
|
|
|
|
tryIt((int32_t)-10);
|
|
|
|
tryIt((int32_t)-100);
|
2000-12-12 22:54:36 +00:00
|
|
|
tryIt((int32_t)-1913860352);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
for (int32_t z=0; z<10; ++z)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-08-14 21:42:36 +00:00
|
|
|
double d = randFraction() * 2e10 - 1e10;
|
|
|
|
tryIt(d);
|
|
|
|
}
|
|
|
|
|
2002-08-08 23:47:09 +00:00
|
|
|
double it = getSafeDouble(100000.0);
|
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(0.0);
|
|
|
|
tryIt(it);
|
|
|
|
tryIt((int32_t)0);
|
2002-08-08 23:47:09 +00:00
|
|
|
tryIt(uprv_floor(it));
|
|
|
|
tryIt((int32_t)randLong());
|
2000-08-14 21:42:36 +00:00
|
|
|
|
|
|
|
// try again
|
2002-08-08 23:47:09 +00:00
|
|
|
it = getSafeDouble(100.0);
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(it);
|
2002-08-08 23:47:09 +00:00
|
|
|
tryIt(uprv_floor(it));
|
|
|
|
tryIt((int32_t)randLong());
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-04-17 00:37:06 +00:00
|
|
|
// try again with very large numbers
|
2002-08-08 23:47:09 +00:00
|
|
|
it = getSafeDouble(100000000000.0);
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt(it);
|
2001-04-17 00:47:46 +00:00
|
|
|
|
|
|
|
// try again with very large numbers
|
|
|
|
// and without going outside of the int32_t range
|
|
|
|
it = randFraction() * INT32_MAX;
|
2001-04-17 00:37:06 +00:00
|
|
|
tryIt(it);
|
2000-08-14 21:42:36 +00:00
|
|
|
tryIt((int32_t)uprv_floor(it));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
delete fFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IntlTestNumberFormat::tryIt(double aNumber)
|
|
|
|
{
|
|
|
|
const int32_t DEPTH = 10;
|
|
|
|
Formattable number[DEPTH];
|
|
|
|
UnicodeString string[DEPTH];
|
|
|
|
|
|
|
|
int32_t numberMatch = 0;
|
|
|
|
int32_t stringMatch = 0;
|
2003-05-19 20:03:53 +00:00
|
|
|
UnicodeString errMsg;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<DEPTH; ++i)
|
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
errMsg.truncate(0); // if non-empty, we failed this iteration
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2003-05-19 20:03:53 +00:00
|
|
|
string[i] = "(n/a)"; // "format was never done" value
|
|
|
|
if (i == 0) {
|
2000-10-19 21:08:05 +00:00
|
|
|
number[i].setDouble(aNumber);
|
2003-05-19 20:03:53 +00:00
|
|
|
} else {
|
2000-10-19 21:08:05 +00:00
|
|
|
fFormat->parse(string[i-1], number[i], status);
|
2003-05-19 20:03:53 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
number[i].setDouble(1234.5); // "parse failed" value
|
|
|
|
errMsg = "**** FAIL: Parse of " + prettify(string[i-1]) + " failed.";
|
|
|
|
--i; // don't show empty last line: "1234.5 F> (n/a) P>"
|
|
|
|
break;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
// Convert from long to double
|
2000-10-19 21:08:05 +00:00
|
|
|
if (number[i].getType() == Formattable::kLong)
|
|
|
|
number[i].setDouble(number[i].getLong());
|
2004-11-11 23:34:58 +00:00
|
|
|
else if (number[i].getType() == Formattable::kInt64)
|
|
|
|
number[i].setDouble((double)number[i].getInt64());
|
1999-08-16 21:50:52 +00:00
|
|
|
else if (number[i].getType() != Formattable::kDouble)
|
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
errMsg = ("**** FAIL: Parse of " + prettify(string[i-1])
|
2000-12-12 22:54:36 +00:00
|
|
|
+ " returned non-numeric Formattable, type " + UnicodeString(formattableTypeName(number[i].getType()))
|
|
|
|
+ ", Locale=" + UnicodeString(fLocale.getName())
|
|
|
|
+ ", longValue=" + number[i].getLong());
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-05-19 20:03:53 +00:00
|
|
|
string[i].truncate(0);
|
1999-08-16 21:50:52 +00:00
|
|
|
fFormat->format(number[i].getDouble(), string[i]);
|
|
|
|
if (i > 0)
|
|
|
|
{
|
2000-10-19 21:08:05 +00:00
|
|
|
if (numberMatch == 0 && number[i] == number[i-1])
|
|
|
|
numberMatch = i;
|
1999-08-16 21:50:52 +00:00
|
|
|
else if (numberMatch > 0 && number[i] != number[i-1])
|
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
errMsg = ("**** FAIL: Numeric mismatch after match.");
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-10-19 21:08:05 +00:00
|
|
|
if (stringMatch == 0 && string[i] == string[i-1])
|
|
|
|
stringMatch = i;
|
1999-08-16 21:50:52 +00:00
|
|
|
else if (stringMatch > 0 && string[i] != string[i-1])
|
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
errMsg = ("**** FAIL: String mismatch after match.");
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-12 22:54:36 +00:00
|
|
|
if (numberMatch > 0 && stringMatch > 0)
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-10-19 21:08:05 +00:00
|
|
|
if (i == DEPTH)
|
|
|
|
--i;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (stringMatch > 2 || numberMatch > 2)
|
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
errMsg = ("**** FAIL: No string and/or number match within 2 iterations.");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 20:03:53 +00:00
|
|
|
if (errMsg.length() != 0)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
for (int32_t k=0; k<=i; ++k)
|
|
|
|
{
|
|
|
|
logln((UnicodeString)"" + k + ": " + number[k].getDouble() + " F> " +
|
2003-05-19 20:03:53 +00:00
|
|
|
prettify(string[k]) + " P> ");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2003-05-19 20:03:53 +00:00
|
|
|
errln(errMsg);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IntlTestNumberFormat::tryIt(int32_t aNumber)
|
|
|
|
{
|
2000-12-12 22:54:36 +00:00
|
|
|
Formattable number(aNumber);
|
|
|
|
UnicodeString stringNum;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-12-12 22:54:36 +00:00
|
|
|
fFormat->format(number, stringNum, status);
|
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-12-12 22:54:36 +00:00
|
|
|
errln("**** FAIL: Formatting " + aNumber);
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-12-12 22:54:36 +00:00
|
|
|
fFormat->parse(stringNum, number, status);
|
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
errln("**** FAIL: Parse of " + prettify(stringNum) + " failed.");
|
2000-12-12 22:54:36 +00:00
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-12-12 22:54:36 +00:00
|
|
|
if (number.getType() != Formattable::kLong)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
errln("**** FAIL: Parse of " + prettify(stringNum)
|
2000-12-12 22:54:36 +00:00
|
|
|
+ " returned non-long Formattable, type " + UnicodeString(formattableTypeName(number.getType()))
|
|
|
|
+ ", Locale=" + UnicodeString(fLocale.getName())
|
|
|
|
+ ", doubleValue=" + number.getDouble()
|
|
|
|
+ ", longValue=" + number.getLong()
|
|
|
|
+ ", origValue=" + aNumber
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (number.getLong() != aNumber) {
|
2003-05-19 20:03:53 +00:00
|
|
|
errln("**** FAIL: Parse of " + prettify(stringNum) + " failed. Got:" + number.getLong()
|
2000-12-12 22:54:36 +00:00
|
|
|
+ " Expected:" + aNumber);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void IntlTestNumberFormat::testAvailableLocales(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
int32_t count = 0;
|
|
|
|
const Locale* locales = NumberFormat::getAvailableLocales(count);
|
|
|
|
logln((UnicodeString)"" + count + " available locales");
|
|
|
|
if (locales && count)
|
|
|
|
{
|
|
|
|
UnicodeString name;
|
|
|
|
UnicodeString all;
|
|
|
|
for (int32_t i=0; i<count; ++i)
|
|
|
|
{
|
2000-12-12 22:54:36 +00:00
|
|
|
if (i!=0)
|
|
|
|
all += ", ";
|
2000-04-15 21:28:17 +00:00
|
|
|
all += locales[i].getName();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
logln(all);
|
|
|
|
}
|
2000-12-12 22:54:36 +00:00
|
|
|
else
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln((UnicodeString)"**** FAIL: Zero available locales or null array pointer");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void IntlTestNumberFormat::monsterTest(/* char* par */)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
const char *SEP = "============================================================\n";
|
|
|
|
int32_t count;
|
2003-05-19 20:03:53 +00:00
|
|
|
const Locale* allLocales = NumberFormat::getAvailableLocales(count);
|
|
|
|
Locale* locales = (Locale*)allLocales;
|
|
|
|
Locale quickLocales[6];
|
|
|
|
if (allLocales && count)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-05-19 20:03:53 +00:00
|
|
|
if (quick && count > 6) {
|
|
|
|
logln("quick test: testing just 6 locales!");
|
|
|
|
count = 6;
|
|
|
|
locales = quickLocales;
|
|
|
|
locales[0] = allLocales[0];
|
|
|
|
locales[1] = allLocales[1];
|
|
|
|
locales[2] = allLocales[2];
|
|
|
|
// In a quick test, make sure we test locales that use
|
|
|
|
// currency prefix, currency suffix, and choice currency
|
|
|
|
// logic. Otherwise bugs in these areas can slip through.
|
|
|
|
locales[3] = Locale("ar", "AE", "");
|
|
|
|
locales[4] = Locale("cs", "CZ", "");
|
|
|
|
locales[5] = Locale("en", "IN", "");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
for (int32_t i=0; i<count; ++i)
|
|
|
|
{
|
2000-04-15 21:28:17 +00:00
|
|
|
UnicodeString name(locales[i].getName(), "");
|
1999-08-16 21:50:52 +00:00
|
|
|
logln(SEP);
|
2000-08-23 19:11:16 +00:00
|
|
|
testLocale(/* par, */locales[i], name);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logln(SEP);
|
|
|
|
}
|
2002-09-21 00:43:14 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|