/***********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2007, International Business Machines Corporation
+ * Copyright (c) 1997-2015, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
UBool NumberFormatRoundTripTest::verbose = FALSE;
UBool NumberFormatRoundTripTest::STRING_COMPARE = TRUE;
UBool NumberFormatRoundTripTest::EXACT_NUMERIC_COMPARE = FALSE;
-UBool NumberFormatRoundTripTest::DEBUG = FALSE;
+UBool NumberFormatRoundTripTest::DEBUG_VAR = FALSE;
double NumberFormatRoundTripTest::MAX_ERROR = 1e-14;
double NumberFormatRoundTripTest::max_numeric_error = 0.0;
double NumberFormatRoundTripTest::min_numeric_error = 1.0;
}
UBool
-NumberFormatRoundTripTest::failure(UErrorCode status, const char* msg)
+NumberFormatRoundTripTest::failure(UErrorCode status, const char* msg, UBool possibleDataError)
{
if(U_FAILURE(status)) {
- errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ if (possibleDataError) {
+ dataerrln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ } else {
+ errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ }
return TRUE;
}
logln("Default Locale");
fmt = NumberFormat::createInstance(status);
- if (!failure(status, "NumberFormat::createInstance")){
+ if (!failure(status, "NumberFormat::createInstance", TRUE)){
test(fmt);
}
delete fmt;
fmt = NumberFormat::createCurrencyInstance(status);
- if (!failure(status, "NumberFormat::createCurrencyInstance")){
+ if (!failure(status, "NumberFormat::createCurrencyInstance", TRUE)){
test(fmt);
}
delete fmt;
fmt = NumberFormat::createPercentInstance(status);
- if (!failure(status, "NumberFormat::createPercentInstance")){
+ if (!failure(status, "NumberFormat::createPercentInstance", TRUE)){
test(fmt);
}
delete fmt;
void
NumberFormatRoundTripTest::test(NumberFormat *fmt)
{
-#if IEEE_754 && !defined(OS400)
+#if IEEE_754 && U_PLATFORM != U_PF_OS400
test(fmt, uprv_getNaN());
test(fmt, uprv_getInfinity());
test(fmt, -uprv_getInfinity());
test(fmt, uprv_floor((randomDouble(10000))));
test(fmt, randomDouble(1e50));
test(fmt, randomDouble(1e-50));
-#if !defined(OS390) && !defined(OS400)
+#if !(U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400)
test(fmt, randomDouble(1e100));
#elif IEEE_754
- test(fmt, randomDouble(1e75)); /*OS390 and OS400*/
+ test(fmt, randomDouble(1e75));
#endif /* OS390 and OS400 */
// {sfb} When formatting with a percent instance, numbers very close to
// DBL_MAX will fail the round trip. This is because:
// I'll get around this by dividing by the multiplier to make sure
// the double will stay in range.
//if(fmt->getMultipler() == 1)
- if(fmt->getDynamicClassID() == DecimalFormat::getStaticClassID())
+ DecimalFormat *df = dynamic_cast<DecimalFormat *>(fmt);
+ if(df != NULL)
{
-#if !defined(OS390) && !defined(OS400)
+#if !(U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400)
/* DBL_MAX/2 is here because randomDouble does a *2 in the math */
- test(fmt, randomDouble(DBL_MAX/2.0) / ((DecimalFormat*)fmt)->getMultiplier());
+ test(fmt, randomDouble(DBL_MAX/2.0) / df->getMultiplier());
#elif IEEE_754
- test(fmt, randomDouble(1e75) / ((DecimalFormat*)fmt)->getMultiplier());
+ test(fmt, randomDouble(1e75) / df->getMultiplier());
#else
- test(fmt, randomDouble(1e65) / ((DecimalFormat*)fmt)->getMultiplier()); /*OS390*/
+ test(fmt, randomDouble(1e65) / df->getMultiplier());
#endif
}
// These machines and compilers don't fully support denormalized doubles,
test(fmt, randomDouble(1e-292));
test(fmt, randomDouble(1e-100));
-#elif defined(OS390) || defined(OS400)
- // i5/OS (OS400) throws exceptions on denormalized numbers
+#elif U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400
+ // i5/OS (OS/400) throws exceptions on denormalized numbers
# if IEEE_754
test(fmt, randomDouble(1e-78));
test(fmt, randomDouble(1e-78));
NumberFormatRoundTripTest::test(NumberFormat *fmt, const Formattable& value)
{
fmt->setMaximumFractionDigits(999);
- if(fmt->getDynamicClassID() == DecimalFormat::getStaticClassID()) {
- ((DecimalFormat *)fmt)->setRoundingIncrement(0.0);
+ DecimalFormat *df = dynamic_cast<DecimalFormat *>(fmt);
+ if(df != NULL) {
+ df->setRoundingIncrement(0.0);
}
UErrorCode status = U_ZERO_ERROR;
UnicodeString s, s2, temp;
Formattable n;
UBool show = verbose;
- if(DEBUG)
+ if(DEBUG_VAR)
logln(/*value.getString(temp) +*/ " F> " + escape(s));
fmt->parse(s, n, status);
failure(status, "fmt->parse");
- if(DEBUG)
+ if(DEBUG_VAR)
logln(escape(s) + " P> " /*+ n.getString(temp)*/);
if(isDouble(n))
else
s2 = fmt->format(n.getLong(), s2);
- if(DEBUG)
+ if(DEBUG_VAR)
logln(/*n.getString(temp) +*/ " F> " + escape(s2));
if(STRING_COMPARE) {