/***********************************************************************
- * Copyright (c) 1997-2008, International Business Machines Corporation
+ * Copyright (c) 1997-2011, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
CASE(58,Test4243011);
CASE(59,Test4243108);
CASE(60,TestJ691);
+ CASE(61,Test8199);
default: name = ""; break;
}
}
UBool
-NumberFormatRegressionTest::failure(UErrorCode status, const UnicodeString& msg, const Locale& l)
+NumberFormatRegressionTest::failure(UErrorCode status, const UnicodeString& msg, const Locale& l, UBool possibleDataError)
{
if(U_FAILURE(status)) {
- errln(UnicodeString("FAIL: ", "") + msg
- + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), "") + UnicodeString(l.getName(),""));
+ if (possibleDataError) {
+ dataerrln(UnicodeString("FAIL: ", "") + msg
+ + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), "") + UnicodeString(l.getName(),""));
+ } else {
+ errcheckln(status, UnicodeString("FAIL: ", "") + msg
+ + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), "") + UnicodeString(l.getName(),""));
+ }
return TRUE;
}
}
UBool
-NumberFormatRegressionTest::failure(UErrorCode status, const UnicodeString& msg, const char *l)
+NumberFormatRegressionTest::failure(UErrorCode status, const UnicodeString& msg, const char *l, UBool possibleDataError)
{
if(U_FAILURE(status)) {
- errln(UnicodeString("FAIL: ", "") + msg
- + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), "") + UnicodeString(l, ""));
+ if (possibleDataError) {
+ dataerrln(UnicodeString("FAIL: ", "") + msg
+ + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), "") + UnicodeString(l, ""));
+ } else {
+ errcheckln(status, UnicodeString("FAIL: ", "") + msg
+ + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), "") + UnicodeString(l, ""));
+ }
return TRUE;
}
}
UBool
-NumberFormatRegressionTest::failure(UErrorCode status, const UnicodeString& msg)
+NumberFormatRegressionTest::failure(UErrorCode status, const UnicodeString& msg, UBool possibleDataError)
{
if(U_FAILURE(status)) {
- errln(UnicodeString("FAIL: ", "") + msg
- + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), ""));
+ if (possibleDataError) {
+ dataerrln(UnicodeString("FAIL: ", "") + msg
+ + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), ""));
+ } else {
+ errcheckln(status, UnicodeString("FAIL: ", "") + msg
+ + UnicodeString(" failed, error ", "") + UnicodeString(u_errorName(status), ""));
+ }
return TRUE;
}
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
- failure(status, "new DecimalFormat", "");
- double d = 100;
- df->setMinimumFractionDigits(0);
- df->setMaximumFractionDigits(16);
- UnicodeString sBuf1;
- FieldPosition fp1(0);
- logln(UnicodeString("d = ") + d);
- logln("maxFractionDigits = " + df->getMaximumFractionDigits());
-
- logln(" format(d) = '" + df->format(d, sBuf1, fp1) + "'");
- df->setMaximumFractionDigits(17);
- UnicodeString sBuf2;
- FieldPosition fp2(0);
- logln("maxFractionDigits = " + df->getMaximumFractionDigits());
- sBuf2 = df->format(d, sBuf2, fp2);
- if(sBuf2 != "100")
- errln(" format(d) = '" + sBuf2 + "'");
+ if (!failure(status, "new DecimalFormat", "")) {
+ double d = 100;
+ df->setMinimumFractionDigits(0);
+ df->setMaximumFractionDigits(16);
+ UnicodeString sBuf1;
+ FieldPosition fp1(0);
+ logln(UnicodeString("d = ") + d);
+ logln("maxFractionDigits = " + df->getMaximumFractionDigits());
+
+ logln(" format(d) = '" + df->format(d, sBuf1, fp1) + "'");
+ df->setMaximumFractionDigits(17);
+ UnicodeString sBuf2;
+ FieldPosition fp2(0);
+ logln("maxFractionDigits = " + df->getMaximumFractionDigits());
+ sBuf2 = df->format(d, sBuf2, fp2);
+ if(sBuf2 != "100")
+ errln(" format(d) = '" + sBuf2 + "'");
+ }
delete df;
}
logln(UnicodeString(" VALUE ") + returnfloat);
UErrorCode status = U_ZERO_ERROR;
NumberFormat *nfcommon = NumberFormat::createCurrencyInstance(Locale::getUS(), status);
- if (failure(status, "NumberFormat::createCurrencyInstance", Locale::getUS())){
+ if (failure(status, "NumberFormat::createCurrencyInstance", Locale::getUS(), TRUE)){
delete nfcommon;
return returnfloat;
}
double x = 0.00159999;
UErrorCode status = U_ZERO_ERROR;
NumberFormat *nf = NumberFormat::createInstance(status);
- if (failure(status, "NumberFormat::createInstance", Locale::getUS())) {
+ if (failure(status, "NumberFormat::createInstance", Locale::getUS(), TRUE)) {
delete nf;
return;
}
// TODO: There is not a good way to find out that the creation of this number format has
// failed. Major rewiring of format construction proposed.
if(U_FAILURE(status)) {
- errln("Something is wrong with French number format - it should not fallback. Exitting");
+ dataerrln("Something is wrong with French number format - it should not fallback. Exitting - %s", u_errorName(status));
delete nf1;
return;
}
failure(status, "NumberFormat::createInstance", Locale::getFrance());
-
+
// C++ workaround to make sure cast works
- // Wouldn't dynamic_cast<DecimalFormat*> be great?
- if(nf1->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
+ DecimalFormat *nf = dynamic_cast<DecimalFormat *>(nf1);
+ if(nf == NULL) {
errln("NumberFormat::createInstance returned incorrect type.");
return;
}
- DecimalFormat *nf = (DecimalFormat*) nf1;
UnicodeString temp;
logln("nf toPattern1: " + nf->toPattern(temp));
logln("nf toLocPattern1: " + nf->toLocalizedPattern(temp));
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *dfFoo = new DecimalFormat(UnicodeString("000"), status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete dfFoo;
return;
}
Locale *de = new Locale(loc);
NumberFormat *nf = NumberFormat::createCurrencyInstance(*de, status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ dataerrln("Error creating DecimalFormat: %s", u_errorName(status));
delete nf;
return;
}
- if (nf->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
+ DecimalFormat *df = dynamic_cast<DecimalFormat *>(nf);
+ if(df == NULL) {
errln("expected DecimalFormat!");
return;
}
- DecimalFormat *df = (DecimalFormat*) nf;
const DecimalFormatSymbols *sym = df->getDecimalFormatSymbols();
UnicodeString decSep = sym->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
UnicodeString monSep = sym->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol);
int len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status);
formatter = NumberFormat::createInstance(Locale(loc), status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ dataerrln("Error creating DecimalFormat: %s", u_errorName(status));
delete formatter;
return;
}
UErrorCode status = U_ZERO_ERROR;
formatter = NumberFormat::createInstance(Locale::getCanadaFrench(), status);
- if (failure(status, "NumberFormat::createNumberInstance", Locale::getCanadaFrench())){
+ if (failure(status, "NumberFormat::createNumberInstance", Locale::getCanadaFrench(), TRUE)){
delete formatter;
return;
};
char loc[256]={0};
uloc_canonicalize("de_DE_PREEURO", loc, 256, &status);
formatter = NumberFormat::createInstance(Locale(loc), status);
- if (failure(status, "NumberFormat::createNumberInstance", loc)){
+ if (failure(status, "NumberFormat::createNumberInstance", loc, TRUE)){
delete formatter;
return;
}
String expectedPercent = "-578.998%";
*/
UnicodeString expectedDefault("-5.789,988");
- UnicodeString expectedCurrency("-\\u20A4\\u00A05.790", -1, US_INV);
+ UnicodeString expectedCurrency("-IT\\u20A4\\u00A05.790", -1, US_INV);
UnicodeString expectedPercent("-578.999%");
expectedCurrency = expectedCurrency.unescape();
char loc[256]={0};
uloc_canonicalize("it_IT_PREEURO", loc, 256, &status);
formatter = NumberFormat::createInstance(Locale(loc), status);
- if (failure(status, "NumberFormat::createNumberInstance")){
+ if (failure(status, "NumberFormat::createNumberInstance", TRUE)){
delete formatter;
return;
};
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat("#0.#", status);
- failure(status, "new DecimalFormat");
- UnicodeString s("12.4");
- roundingTest(df, 12.35, s);
- roundingTest(df, 12.45, s);
- s = "12.5";
- roundingTest(df, 12.452,s);
- s = "12.6";
- roundingTest(df, 12.55, s);
- roundingTest(df, 12.65, s);
- s = "12.7";
- roundingTest(df, 12.652,s);
- s = "12.8";
- roundingTest(df, 12.75, s);
- roundingTest(df, 12.752,s);
- roundingTest(df, 12.85, s);
- s = "12.9";
- roundingTest(df, 12.852,s);
- s = "13";
- roundingTest(df, 12.95, s);
- roundingTest(df, 12.952,s);
+ if (!failure(status, "new DecimalFormat")) {
+ UnicodeString s("12.4");
+ roundingTest(df, 12.35, s);
+ roundingTest(df, 12.45, s);
+ s = "12.5";
+ roundingTest(df, 12.452,s);
+ s = "12.6";
+ roundingTest(df, 12.55, s);
+ roundingTest(df, 12.65, s);
+ s = "12.7";
+ roundingTest(df, 12.652,s);
+ s = "12.8";
+ roundingTest(df, 12.75, s);
+ roundingTest(df, 12.752,s);
+ roundingTest(df, 12.85, s);
+ s = "12.9";
+ roundingTest(df, 12.852,s);
+ s = "13";
+ roundingTest(df, 12.95, s);
+ roundingTest(df, 12.952,s);
+ }
delete df;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *fmt = new DecimalFormat("#,#00.00;-#.#", status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete fmt;
return;
}
FieldPosition pos(FieldPosition::DONT_CARE);
tempString = newFmt->format(3456.78, tempString, pos);
if (tempString != UnicodeString("3,456.78 p'ieces"))
- errln("Failed! 3456.78 p'ieces expected, but got : " + tempString);
+ dataerrln("Failed! 3456.78 p'ieces expected, but got : " + tempString);
/*} catch (Exception foo) {
errln("An exception was thrown for any inconsistent negative pattern.");
}*/
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *sdf = new DecimalFormat(UnicodeString("#,##0"), status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete sdf;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *fmt = new DecimalFormat(UnicodeString("#,#00.00"), status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete fmt;
return;
}
failure(status, "new DecimalFormatSymbols");
DecimalFormat *df = new DecimalFormat("#,##0.###", syms, status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status); // Corrected; see 4147706
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
NumberFormat *format = NumberFormat::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ dataerrln("Error creating DecimalFormat: %s", u_errorName(status));
delete format;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete df;
return;
}
UErrorCode status = U_ZERO_ERROR;
NumberFormat *nf = NumberFormat::createInstance(status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ dataerrln("Error creating DecimalFormat: %s", u_errorName(status));
delete nf;
return;
}
NULL/*"java.text.resources.LocaleElements"*/,
locales[i], status);
failure(status, "new ResourceBundle");
- ResourceBundle numPat = rb->get("NumberPatterns", status);
- failure(status, "new ResourceBundle(NumberPatterns)");
- //
+ ResourceBundle numPat = rb->getWithFallback("NumberElements", status);
+ failure(status, "rb.get(NumberElements)");
+ numPat = numPat.getWithFallback("latn",status);
+ failure(status, "rb.get(latn)");
+ numPat = numPat.getWithFallback("patterns",status);
+ failure(status, "rb.get(patterns)");
+ numPat = numPat.getWithFallback("currencyFormat",status);
+ failure(status, "rb.get(currencyFormat)");
+ //
// Get the currency pattern for this locale. We have to fish it
// out of the ResourceBundle directly, since DecimalFormat.toPattern
// will return the localized symbol, not \00a4
//
- UnicodeString pattern = numPat.getStringEx(1, status);
- failure(status, "rb->getStringArray");
+ UnicodeString pattern = numPat.getString(status);
+ failure(status, "rb->getString()");
UChar fo[] = { 0x00A4 };
UnicodeString foo(fo, 1, 1);
double rate = 12.34;
DecimalFormat *formatDec = new DecimalFormat ("000.00", status);
if(U_FAILURE(status)) {
- errln("Error creating DecimalFormat: %s", u_errorName(status));
+ errcheckln(status, "Error creating DecimalFormat: %s", u_errorName(status));
delete formatDec;
return;
}
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *nf = new DecimalFormat("##,###,###.00", status);
- failure(status, "new DecimalFormat");
-
- UnicodeString f;
- FieldPosition pos(FieldPosition::DONT_CARE);
- f = nf->format(9.02, f, pos);
- if (f == UnicodeString("9.02"))
- logln(f + " ok");
- else
- errln("9.02 -> " + f + "; want 9.02");
+ if (!failure(status, "new DecimalFormat")) {
+ UnicodeString f;
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ f = nf->format(9.02, f, pos);
+ if (f == UnicodeString("9.02"))
+ logln(f + " ok");
+ else
+ errln("9.02 -> " + f + "; want 9.02");
- f.remove();
- f = nf->format((int32_t)0, f, pos);
- if (f == UnicodeString(".00"))
- logln(f + " ok");
- else
- errln("0 -> " + f + "; want .00");
+ f.remove();
+ f = nf->format((int32_t)0, f, pos);
+ if (f == UnicodeString(".00"))
+ logln(f + " ok");
+ else
+ errln("0 -> " + f + "; want .00");
+ }
delete nf;
}
UnicodeString result;
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *df = new DecimalFormat(DATA[i], status);
- failure(status, "new DecimalFormat");
- FieldPosition pos(FieldPosition::DONT_CARE);
- result = df->format(1.2, result, pos);
- if (result != DATA[i+1]) {
- errln("Fail: 1.2 x " + DATA[i] + " = " + result +
- "; want " + DATA[i+1]);
- }
- else {
- logln("Ok: 1.2 x " + DATA[i] + " = " + result);
+ if (!failure(status, "new DecimalFormat")) {
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ result = df->format(1.2, result, pos);
+ if (result != DATA[i+1]) {
+ errln("Fail: 1.2 x " + DATA[i] + " = " + result +
+ "; want " + DATA[i+1]);
+ }
+ else {
+ logln("Ok: 1.2 x " + DATA[i] + " = " + result);
+ }
}
delete df;
DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::getEnglish(), status);
failure(status, "new DecimalFormatSymbols");
DecimalFormat *f = new DecimalFormat(UnicodeString(""), syms, status);
- failure(status, "new DecimalFormat");
- UnicodeString s;
- FieldPosition pos(FieldPosition::DONT_CARE);
- s = f->format(123.456, s, pos);
- if (s != UnicodeString("123.456"))
- errln("Fail: Format empty pattern x 123.456 => " + s);
- s.remove();
- s = f->format(-123.456, s, pos);
- if (s != UnicodeString("-123.456"))
- errln("Fail: Format empty pattern x -123.456 => " + s);
+ if (!failure(status, "new DecimalFormat")) {
+ UnicodeString s;
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ s = f->format(123.456, s, pos);
+ if (s != UnicodeString("123.456"))
+ errln("Fail: Format empty pattern x 123.456 => " + s);
+ s.remove();
+ s = f->format(-123.456, s, pos);
+ if (s != UnicodeString("-123.456"))
+ errln("Fail: Format empty pattern x -123.456 => " + s);
+ }
delete f;
}
//try {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *nff = NumberFormat::createInstance(status);
- if (failure(status, "NumberFormat::createInstance")){
+ if (failure(status, "NumberFormat::createInstance", TRUE)){
delete nff;
return;
};
- if(nff->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
+ DecimalFormat *nf = dynamic_cast<DecimalFormat *>(nff);
+ if(nf == NULL) {
errln("DecimalFormat needed to continue");
return;
}
- DecimalFormat *nf = (DecimalFormat*)nff;
DecimalFormatSymbols *sym = (DecimalFormatSymbols*) nf->getDecimalFormatSymbols();
sym->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, (UChar)/*'\''*/0x0027);
nf->setDecimalFormatSymbols(*sym);
out2 = nf->format(pi, out2, pos);
UnicodeString pat2;
pat2 = nf->toPattern(pat2);
+ pp.setIndex(0);
nf->parse(out2, num, pp);
double val2 = num.getDouble();
UnicodeString pattern("#,###");
logln("Applying pattern \"" + pattern + "\"");
sdf->applyPattern(pattern, status);
- failure(status, "sdf->applyPattern");
- int minIntDig = sdf->getMinimumIntegerDigits();
- if (minIntDig != 0) {
- errln("Test failed");
- errln(" Minimum integer digits : " + minIntDig);
- UnicodeString temp;
- errln(" new pattern: " + sdf->toPattern(temp));
- } else {
- logln("Test passed");
- logln(" Minimum integer digits : " + minIntDig);
+ if (!failure(status, "sdf->applyPattern")) {
+ int minIntDig = sdf->getMinimumIntegerDigits();
+ if (minIntDig != 0) {
+ errln("Test failed");
+ errln(" Minimum integer digits : " + minIntDig);
+ UnicodeString temp;
+ errln(" new pattern: " + sdf->toPattern(temp));
+ } else {
+ logln("Test passed");
+ logln(" Minimum integer digits : " + minIntDig);
+ }
}
delete sdf;
}
DecimalFormat *df = new DecimalFormat("#,##0.0##", status);
failure(status, "new DecimalFormat");
DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::getEnglish(), status);
- failure(status, "new DecimalFormatSymbols");
- UnicodeString f1;
- UnicodeString f2, temp;
- FieldPosition pos(FieldPosition::DONT_CARE);
- volatile double d1 = 0.0; // volatile to prevent code optimization
- double d2 = -0.0001;
+ if (!failure(status, "new DecimalFormatSymbols")) {
+ UnicodeString f1;
+ UnicodeString f2, temp;
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ volatile double d1 = 0.0; // volatile to prevent code optimization
+ double d2 = -0.0001;
#if defined(U_HPUX)
- d1 = 0.0 * -1.0; // old HPUX compiler ignores volatile keyword
+ d1 = 0.0 * -1.0; // old HPUX compiler ignores volatile keyword
#else
- d1 *= -1.0; // Some compilers have a problem with defining -0.0
+ d1 *= -1.0; // Some compilers have a problem with defining -0.0
#endif
- df->adoptDecimalFormatSymbols(syms);
- f1 = df->format(d1, f1, pos);
- f2 = df->format(d2, f2, pos);
- if (f1 != UnicodeString("-0.0")) {
- errln(UnicodeString("") + d1 + UnicodeString(" x \"") + df->toPattern(temp) + "\" is formatted as \"" + f1 + '"');
- }
- if (f2 != UnicodeString("-0.0")) {
- errln(UnicodeString("") + d2 + UnicodeString(" x \"") + df->toPattern(temp) + "\" is formatted as \"" + f2 + '"');
+ df->adoptDecimalFormatSymbols(syms);
+ f1 = df->format(d1, f1, pos);
+ f2 = df->format(d2, f2, pos);
+ if (f1 != UnicodeString("-0.0")) {
+ errln(UnicodeString("") + d1 + UnicodeString(" x \"") + df->toPattern(temp) + "\" is formatted as \"" + f1 + '"');
+ }
+ if (f2 != UnicodeString("-0.0")) {
+ errln(UnicodeString("") + d2 + UnicodeString(" x \"") + df->toPattern(temp) + "\" is formatted as \"" + f2 + '"');
+ }
}
-
+
delete df;
}
UErrorCode status = U_ZERO_ERROR;
NumberFormat *f = NumberFormat::createInstance(status);
if(U_FAILURE(status)) {
- errln("Couldn't create number format");
+ dataerrln("Couldn't create number format - %s", u_errorName(status));
return;
}
f->setMaximumFractionDigits(INT32_MAX);
NumberFormat *f = (i == 0) ? NumberFormat::createInstance(status)
: NumberFormat::createPercentInstance(status);
if(U_FAILURE(status)) {
- errln("Couldn't create number format");
+ dataerrln("Couldn't create number format - %s", u_errorName(status));
return;
}
double d = 0.0;
void NumberFormatRegressionTest::Test4167494(void) {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmt = NumberFormat::createInstance(Locale::getUS(), status);
- if (failure(status, "NumberFormat::createInstance")){
+ if (failure(status, "NumberFormat::createInstance", TRUE)){
delete fmt;
return;
};
void NumberFormatRegressionTest::Test4170798(void) {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *nf = NumberFormat::createInstance(Locale::getUS(), status);
- if (failure(status, "NumberFormat::createInstance")){
+ if (failure(status, "NumberFormat::createInstance", TRUE)){
delete nf;
return;
};
- if(nf->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
+ DecimalFormat *df = dynamic_cast<DecimalFormat *>(nf);
+ if(df == NULL) {
errln("DecimalFormat needed to continue");
return;
}
- DecimalFormat *df = (DecimalFormat*) nf;
df->setParseIntegerOnly(TRUE);
Formattable n;
ParsePosition pos(0);
UnicodeString s;
for (int i=0; i<DATA_length; i+=2) {
DecimalFormat df(DATA[i], status);
- failure(status, "DecimalFormat constructor");
- df.toPattern(s);
- UnicodeString exp(DATA[i+1]);
- if (s != exp) {
- errln(UnicodeString("FAIL: ") + DATA[i] + " -> " +
- s + ", want " + exp);
+ if (!failure(status, "DecimalFormat constructor")) {
+ df.toPattern(s);
+ UnicodeString exp(DATA[i+1]);
+ if (s != exp) {
+ errln(UnicodeString("FAIL: ") + DATA[i] + " -> " +
+ s + ", want " + exp);
+ }
}
}
}
DecimalFormatSymbols sym(Locale::getUS(), status);
failure(status, "Construct DecimalFormatSymbols");
DecimalFormat fmt("#", sym, status);
- failure(status, "Construct DecimalFormat");
- for (int i=0; i<DATA_length; i+=3) {
- double in = DOUBLE[i/3];
- UnicodeString pat(DATA[i+1]);
- UnicodeString exp(DATA[i+2]);
- fmt.applyPattern(pat, status);
- failure(status, "applyPattern");
- UnicodeString out;
- FieldPosition pos;
- fmt.format(in, out, pos);
- if (out == exp) {
- logln(UnicodeString("Ok: ") + in + " x " + pat + " = " + out);
- } else {
- errln(UnicodeString("FAIL: ") + in + " x " + pat + " = " + out +
- ", expected " + exp);
+ if (!failure(status, "Construct DecimalFormat")) {
+ for (int i=0; i<DATA_length; i+=3) {
+ double in = DOUBLE[i/3];
+ UnicodeString pat(DATA[i+1]);
+ UnicodeString exp(DATA[i+2]);
+ fmt.applyPattern(pat, status);
+ failure(status, "applyPattern");
+ UnicodeString out;
+ FieldPosition pos;
+ fmt.format(in, out, pos);
+ if (out == exp) {
+ logln(UnicodeString("Ok: ") + in + " x " + pat + " = " + out);
+ } else {
+ errln(UnicodeString("FAIL: ") + in + " x " + pat + " = " + out +
+ ", expected " + exp);
+ }
}
}
}
failure(status, "DecimalFormatSymbols ct", Locale::getUS());
DecimalFormat fmt(UnicodeString("#"), sym, status);
- failure(status, "DecimalFormat ct", Locale::getUS());
+ if(failure(status, "DecimalFormat ct", Locale::getUS())) {
+ return;
+ }
UnicodeString s;
FieldPosition pos;
errln(UnicodeString("FAIL: ") + type[j] + avail[i].getDisplayName(l) +
" -> \"" + pat +
"\" -> \"" + f2.toPattern(p) + "\"");
+ } else {
+ UnicodeString l, p;
+ logln(UnicodeString("PASS: ") + type[j] + avail[i].getDisplayName(l) +
+ " -> \"" + pat +
+ "\"");
}
// Test toLocalizedPattern/applyLocalizedPattern round trip
void NumberFormatRegressionTest::Test4216742(void) {
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *fmt = (DecimalFormat*) NumberFormat::createInstance(Locale::getUS(), status);
- if (failure(status, "createInstance", Locale::getUS())){
+ if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete fmt;
return;
};
} else {
double d = num.getType() == Formattable::kDouble ?
num.getDouble() : (double) num.getLong();
- if (d > 0 != DATA[i] > 0) {
+ if ((d > 0) != (DATA[i] > 0)) {
errln(UnicodeString("\"") + str + "\" parse(x " +
fmt->getMultiplier() +
") => " + toString(num));
int D_length = (int)(sizeof(D) / sizeof(D[0]));
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmt = NumberFormat::createInstance(Locale::getUS(), status);
- if (failure(status, "createInstance", Locale::getUS())){
+ if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete fmt;
return;
};
void NumberFormatRegressionTest::Test4161100(void) {
UErrorCode status = U_ZERO_ERROR;
NumberFormat *nf = NumberFormat::createInstance(Locale::getUS(), status);
- if (failure(status, "createInstance", Locale::getUS())){
+ if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete nf;
return;
};
DecimalFormatSymbols sym(Locale::getUS(), status);
failure(status, "DecimalFormatSymbols ct", Locale::getUS());
DecimalFormat fmt(UnicodeString("0."), sym, status);
- failure(status, "DecimalFormat ct", Locale::getUS());
-
- const double NUM[] = { -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5 };
- const char* STR[] = { "-2.", "-2.", "-0.", "0.", "2.", "2.", "4.", "4." };
- int32_t N = (int32_t)(sizeof(NUM) / sizeof(NUM[0]));
-
- for (int32_t i=0; i<N; ++i) {
- UnicodeString str;
- UnicodeString exp(STR[i]);
- FieldPosition pos;
- fmt.format(NUM[i], str, pos);
- if (str == exp) {
- logln(UnicodeString("Ok ") + NUM[i] + " x 0. = " + str);
- } else {
- errln(UnicodeString("FAIL ") + NUM[i] + " x 0. = " + str +
- ", want " + exp);
+
+ if (!failure(status, "DecimalFormat ct", Locale::getUS())) {
+ const double NUM[] = { -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5 };
+ const char* STR[] = { "-2.", "-2.", "-0.", "0.", "2.", "2.", "4.", "4." };
+ int32_t N = (int32_t)(sizeof(NUM) / sizeof(NUM[0]));
+
+ for (int32_t i=0; i<N; ++i) {
+ UnicodeString str;
+ UnicodeString exp(STR[i]);
+ FieldPosition pos;
+ fmt.format(NUM[i], str, pos);
+ if (str == exp) {
+ logln(UnicodeString("Ok ") + NUM[i] + " x 0. = " + str);
+ } else {
+ errln(UnicodeString("FAIL ") + NUM[i] + " x 0. = " + str +
+ ", want " + exp);
+ }
}
}
}
DecimalFormatSymbols sym(Locale::getUS(), status);
failure(status, "DecimalFormatSymbols ct", Locale::getUS());
DecimalFormat fmt(UnicodeString("#.#"), sym, status);
- failure(status, "DecimalFormat ct", Locale::getUS());
+ if (failure(status, "DecimalFormat ct", Locale::getUS())) {
+ return;
+ }
UnicodeString str;
FieldPosition pos;
// create a Calendar for this locale
Calendar *cal = Calendar::createInstance(loc, status);
if (U_FAILURE(status)) {
- errln("FAIL: Calendar::createInstance() returned " + (UnicodeString)u_errorName(status));
+ dataerrln("FAIL: Calendar::createInstance() returned " + (UnicodeString)u_errorName(status));
return;
}
// create a NumberFormat for this locale
NumberFormat *nf = NumberFormat::createInstance(loc, status);
if (U_FAILURE(status)) {
- errln("FAIL: NumberFormat::createInstance() returned " + (UnicodeString)u_errorName(status));
+ dataerrln("FAIL: NumberFormat::createInstance() returned " + (UnicodeString)u_errorName(status));
return;
}
delete df;
}
+//---------------------------------------------------------------------------
+//
+// Error Checking / Reporting macros
+//
+//---------------------------------------------------------------------------
+#define TEST_CHECK_STATUS(status) \
+ if (U_FAILURE(status)) {\
+ errln("File %s, Line %d. status=%s\n", __FILE__, __LINE__, u_errorName(status));\
+ return;\
+ }
+
+#define TEST_ASSERT(expr) \
+ if ((expr)==FALSE) {\
+ errln("File %s, line %d: Assertion Failed: " #expr "\n", __FILE__, __LINE__);\
+ }
+
+
+// Ticket 8199: Parse failure for numbers in the range of 1E10 - 1E18
+
+void NumberFormatRegressionTest::Test8199(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ NumberFormat *nf = NumberFormat::createInstance(Locale::getEnglish(), status);
+ TEST_CHECK_STATUS(status);
+
+ // Note: Retrieving parsed values from a Formattable as a reduced-precision type
+ // should always truncate, no other rounding scheme.
+
+ UnicodeString numStr = "1000000000.6"; // 9 zeroes
+ Formattable val;
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kDouble == val.getType());
+ TEST_ASSERT(1000000000 == val.getInt64(status));
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(1000000000.6 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ numStr = "100000000000000001.1"; // approx 1E17, parses as a double rather
+ // than int64 because of the fraction
+ // even though int64 is more precise.
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kDouble == val.getType());
+ TEST_ASSERT(100000000000000001LL == val.getInt64(status));
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(100000000000000000.0 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ numStr = "1E17"; // Parses with the internal decimal number having non-zero exponent
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kInt64 == val.getType());
+ TEST_ASSERT(100000000000000000LL == val.getInt64());
+ TEST_ASSERT(1.0E17 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ numStr = "9223372036854775807"; // largest int64_t
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kInt64 == val.getType());
+ TEST_ASSERT(9223372036854775807LL == val.getInt64());
+ // In the following check, note that a substantial range of integers will
+ // convert to the same double value. There are also platform variations
+ // in the rounding at compile time of double constants.
+ TEST_ASSERT(9223372036854775808.0 >= val.getDouble(status));
+ TEST_ASSERT(9223372036854774700.0 <= val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ numStr = "-9223372036854775808"; // smallest int64_t
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kInt64 == val.getType());
+ // TEST_ASSERT(-9223372036854775808LL == val.getInt64()); // Compiler chokes on constant.
+ TEST_ASSERT((int64_t)0x8000000000000000LL == val.getInt64());
+ TEST_ASSERT(-9223372036854775808.0 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ numStr = "9223372036854775808"; // largest int64_t + 1
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kDouble == val.getType());
+ TEST_ASSERT(9223372036854775807LL == val.getInt64(status));
+ TEST_ASSERT(status == U_INVALID_FORMAT_ERROR);
+ status = U_ZERO_ERROR;
+ TEST_ASSERT(9223372036854775810.0 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ numStr = "-9223372036854775809"; // smallest int64_t - 1
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kDouble == val.getType());
+ // TEST_ASSERT(-9223372036854775808LL == val.getInt64(status)); // spurious compiler warnings
+ TEST_ASSERT((int64_t)0x8000000000000000LL == val.getInt64(status));
+ TEST_ASSERT(status == U_INVALID_FORMAT_ERROR);
+ status = U_ZERO_ERROR;
+ TEST_ASSERT(-9223372036854775810.0 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ // Test values near the limit of where doubles can represent all integers.
+ // The implementation strategy of getInt64() changes at this boundary.
+ // Strings to be parsed include a decimal fraction to force them to be
+ // parsed as doubles rather than ints. The fraction is discarded
+ // from the parsed double value because it is beyond what can be represented.
+
+ status = U_ZERO_ERROR;
+ numStr = "9007199254740991.1"; // largest 53 bit int
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ // printf("getInt64() returns %lld\n", val.getInt64(status));
+ TEST_ASSERT(Formattable::kDouble == val.getType());
+ TEST_ASSERT(9007199254740991LL == val.getInt64(status));
+ TEST_ASSERT(9007199254740991.0 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ status = U_ZERO_ERROR;
+ numStr = "9007199254740992.1"; // 54 bits for the int part.
+ nf->parse(numStr, val, status);
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kDouble == val.getType());
+ TEST_ASSERT(9007199254740992LL == val.getInt64(status));
+ TEST_ASSERT(9007199254740992.0 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ status = U_ZERO_ERROR;
+ numStr = "9007199254740993.1"; // 54 bits for the int part. Double will round
+ nf->parse(numStr, val, status); // the ones digit, putting it up to ...994
+ TEST_CHECK_STATUS(status);
+ TEST_ASSERT(Formattable::kDouble == val.getType());
+ TEST_ASSERT(9007199254740993LL == val.getInt64(status));
+ TEST_ASSERT(9007199254740994.0 == val.getDouble(status));
+ TEST_CHECK_STATUS(status);
+
+ delete nf;
+}
+
+
#endif /* #if !UCONFIG_NO_FORMATTING */