* and others. All Rights Reserved.
***********************************************************************/
* and others. All Rights Reserved.
***********************************************************************/
#include "unicode/calendar.h"
#include "unicode/datefmt.h"
#include "unicode/ucurr.h"
#include "unicode/calendar.h"
#include "unicode/datefmt.h"
#include "unicode/ucurr.h"
logln(UnicodeString("d = ") + d);
logln(UnicodeString("maxFractionDigits = ") + df->getMaximumFractionDigits());
logln(" format(d) = '" + df->format(d, sBuf1, fp1) + "'");
df->setMaximumFractionDigits(17);
UnicodeString sBuf2;
logln(UnicodeString("d = ") + d);
logln(UnicodeString("maxFractionDigits = ") + df->getMaximumFractionDigits());
logln(" format(d) = '" + df->format(d, sBuf1, fp1) + "'");
df->setMaximumFractionDigits(17);
UnicodeString sBuf2;
logln(UnicodeString("maxFractionDigits = ") + df->getMaximumFractionDigits());
sBuf2 = df->format(d, sBuf2, fp2);
if(sBuf2 != "100")
logln(UnicodeString("maxFractionDigits = ") + df->getMaximumFractionDigits());
sBuf2 = df->format(d, sBuf2, fp2);
if(sBuf2 != "100")
- failure(status, "new DecimalFormat", "");
+ if (U_FAILURE(status)) {
+ dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
+ return;
+ }
- failure(status, "new DecimalFormat", "");
+ if (U_FAILURE(status)) {
+ dataerrln("Error creating DecimalFormat - %s", u_errorName(status));
+ return;
+ }
df->setGroupingSize(0);
UnicodeString sBuf;
FieldPosition fp(FieldPosition::DONT_CARE);
//try {
logln(df->format((int32_t)123, sBuf, fp));
df->setGroupingSize(0);
UnicodeString sBuf;
FieldPosition fp(FieldPosition::DONT_CARE);
//try {
logln(df->format((int32_t)123, sBuf, fp));
// errln("Test for bug 4088503 failed.");
/*} catch (Exception foo) {
errln("Test for bug 4088503 failed.");
// errln("Test for bug 4088503 failed.");
/*} catch (Exception foo) {
errln("Test for bug 4088503 failed.");
- 0x23, 0x00a0, 0x23, 0x23, 0x23, 0x2c, 0x30, 0x30, 0x3b,
- 0x28, 0x23, 0x00a0, 0x23, 0x23, 0x23, 0x2c, 0x30, 0x30, 0x29
+ 0x23, 0x202f, 0x23, 0x23, 0x23, 0x2c, 0x30, 0x30, 0x3b,
+ 0x28, 0x23, 0x202f, 0x23, 0x23, 0x23, 0x2c, 0x30, 0x30, 0x29
};
UnicodeString pat(patChars, 19, 19);
nf->applyLocalizedPattern(pat, status);
};
UnicodeString pat(patChars, 19, 19);
nf->applyLocalizedPattern(pat, status);
buffer = nf->format((int32_t)1234, buffer, pos);
//if (buffer != UnicodeString("1\u00a0234,00"))
UChar c[] = {
buffer = nf->format((int32_t)1234, buffer, pos);
//if (buffer != UnicodeString("1\u00a0234,00"))
UChar c[] = {
- 0x31, 0x00a0, 0x32, 0x33, 0x34, 0x2c, 0x30, 0x30
+ 0x31, 0x202f, 0x32, 0x33, 0x34, 0x2c, 0x30, 0x30
- 0x28, 0x31, 0x00a0, 0x32, 0x33, 0x34, 0x2c, 0x30, 0x30, 0x29
+ 0x28, 0x31, 0x202f, 0x32, 0x33, 0x34, 0x2c, 0x30, 0x30, 0x29
dfFoo->applyPattern("0000;-000", status);
failure(status, "dfFoo->applyPattern");
UnicodeString temp;
dfFoo->applyPattern("0000;-000", status);
failure(status, "dfFoo->applyPattern");
UnicodeString temp;
- if (dfFoo->toPattern(temp) != UnicodeString("#0000"))
- errln("dfFoo.toPattern : " + dfFoo->toPattern(temp));
+ if (dfFoo->toPattern(temp) != UnicodeString("0000"))
+ errln("ERROR: dfFoo.toPattern : " + dfFoo->toPattern(temp));
FieldPosition pos(FieldPosition::DONT_CARE);
logln(dfFoo->format((int32_t)42, temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
dfFoo->applyPattern("000;-000", status);
failure(status, "dfFoo->applyPattern");
FieldPosition pos(FieldPosition::DONT_CARE);
logln(dfFoo->format((int32_t)42, temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
dfFoo->applyPattern("000;-000", status);
failure(status, "dfFoo->applyPattern");
- if (dfFoo->toPattern(temp) != UnicodeString("#000"))
- errln("dfFoo.toPattern : " + dfFoo->toPattern(temp));
+ if (dfFoo->toPattern(temp) != UnicodeString("000"))
+ errln("ERROR: dfFoo.toPattern : " + dfFoo->toPattern(temp));
logln(dfFoo->format((int32_t)42,temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
dfFoo->applyPattern("000;-0000", status);
failure(status, "dfFoo->applyPattern");
logln(dfFoo->format((int32_t)42,temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
dfFoo->applyPattern("000;-0000", status);
failure(status, "dfFoo->applyPattern");
- if (dfFoo->toPattern(temp) != UnicodeString("#000"))
- errln("dfFoo.toPattern : " + dfFoo->toPattern(temp));
+ if (dfFoo->toPattern(temp) != UnicodeString("000"))
+ errln("ERROR: dfFoo.toPattern : " + dfFoo->toPattern(temp));
logln(dfFoo->format((int32_t)42, temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
dfFoo->applyPattern("0000;-000", status);
failure(status, "dfFoo->applyPattern");
logln(dfFoo->format((int32_t)42, temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
dfFoo->applyPattern("0000;-000", status);
failure(status, "dfFoo->applyPattern");
- if (dfFoo->toPattern(temp) != UnicodeString("#0000"))
- errln("dfFoo.toPattern : " + dfFoo->toPattern(temp));
+ if (dfFoo->toPattern(temp) != UnicodeString("0000"))
+ errln("ERROR: dfFoo.toPattern : " + dfFoo->toPattern(temp));
logln(dfFoo->format((int32_t)42, temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
/*} catch (Exception foo) {
logln(dfFoo->format((int32_t)42, temp, pos));
logln(dfFoo->format((int32_t)-42, temp, pos));
/*} catch (Exception foo) {
- uloc_canonicalize("pt_PT_PREEURO", loc, 256, &status);
- Locale *de = new Locale(loc);
- NumberFormat *nf = NumberFormat::createCurrencyInstance(*de, status);
+
+ uloc_canonicalize("pt_PT@currency=PTE", loc, 256, &status);
+ Locale de(loc);
+ LocalPointer<NumberFormat> nf(NumberFormat::createCurrencyInstance(de, status));
- String expectedDefault = "-5\u00a0789,987";
- String expectedCurrency = "5\u00a0789,98\u00a0F";
- String expectedPercent = "-578\u00a0998%";
+ String expectedDefault = "-5\u202f789,987";
+ String expectedCurrency = "5\u202f789,98\u00a0F";
+ String expectedPercent = "-578\u202f998%";
- 0x2d, 0x35, 0x00a0, 0x37, 0x38, 0x39, 0x2c, 0x39, 0x38, 0x38
+ 0x2d, 0x35, 0x202f, 0x37, 0x38, 0x39, 0x2c, 0x39, 0x38, 0x38
- 0x35, 0x00a0, 0x37, 0x38, 0x39, 0x2c, 0x39, 0x39, 0x00a0, 0x46
+ 0x35, 0x202f, 0x37, 0x38, 0x39, 0x2c, 0x39, 0x39, 0x00a0, 0x46
- 0x2d, 0x35, 0x37, 0x38, 0x00a0, 0x39, 0x39, 0x39, 0x00a0, 0x25
+ 0x2d, 0x35, 0x37, 0x38, 0x202f, 0x39, 0x39, 0x39, 0x00a0, 0x25
};
UnicodeString expectedDefault(chars1, 10, 10);
UnicodeString expectedCurrency(chars2, 10, 10);
};
UnicodeString expectedDefault(chars1, 10, 10);
UnicodeString expectedCurrency(chars2, 10, 10);
- int len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status);
+ int len = uloc_canonicalize("fr_FR@currency=FRF", loc, 256, &status);
(void)len; // Suppress set but not used warning.
formatter = NumberFormat::createInstance(Locale(loc), status);
if(U_FAILURE(status)) {
(void)len; // Suppress set but not used warning.
formatter = NumberFormat::createInstance(Locale(loc), status);
if(U_FAILURE(status)) {
tempString = formatter->format (-5789.9876, tempString);
if (tempString == expectedDefault) {
tempString = formatter->format (-5789.9876, tempString);
if (tempString == expectedDefault) {
- len = uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status);
+ len = uloc_canonicalize("fr_FR@currency=FRF", loc, 256, &status);
formatter = NumberFormat::createCurrencyInstance(loc, status);
failure(status, "NumberFormat::createCurrencyInstance", loc);
tempString.remove();
formatter = NumberFormat::createCurrencyInstance(loc, status);
failure(status, "NumberFormat::createCurrencyInstance", loc);
tempString.remove();
- uloc_canonicalize("fr_FR_PREEURO", loc, 256, &status);
+ uloc_canonicalize("fr_FR@currency=FRF", loc, 256, &status);
formatter = NumberFormat::createPercentInstance(Locale(loc), status);
failure(status, "NumberFormat::createPercentInstance", loc);
tempString.remove();
formatter = NumberFormat::createPercentInstance(Locale(loc), status);
failure(status, "NumberFormat::createPercentInstance", loc);
tempString.remove();
UErrorCode status = U_ZERO_ERROR;
formatter = NumberFormat::createInstance(Locale::getCanadaFrench(), status);
UErrorCode status = U_ZERO_ERROR;
formatter = NumberFormat::createInstance(Locale::getCanadaFrench(), status);
- if (failure(status, "NumberFormat::createNumberInstance", Locale::getCanadaFrench(), TRUE)){
+ if (failure(status, "NumberFormat::createInstance", Locale::getCanadaFrench(), TRUE)){
tempString = formatter->format (-5789.9876, tempString);
if (tempString == expectedDefault) {
tempString = formatter->format (-5789.9876, tempString);
if (tempString == expectedDefault) {
UnicodeString tempString;
/* user error :
String expectedDefault = "-5.789,987";
UnicodeString tempString;
/* user error :
String expectedDefault = "-5.789,987";
String expectedPercent = "-578.998%";
*/
UnicodeString expectedDefault("-5.789,988");
String expectedPercent = "-578.998%";
*/
UnicodeString expectedDefault("-5.789,988");
- uloc_canonicalize("de_DE_PREEURO", loc, 256, &status);
+ uloc_canonicalize("de_DE@currency=DEM", loc, 256, &status);
- if (failure(status, "NumberFormat::createNumberInstance", loc, TRUE)){
+ if (failure(status, "NumberFormat::createInstance", loc, TRUE)){
- uloc_canonicalize("de_DE_PREEURO", loc, 256, &status);
+ uloc_canonicalize("de_DE@currency=DEM", loc, 256, &status);
formatter = NumberFormat::createCurrencyInstance(Locale(loc), status);
failure(status, "NumberFormat::createCurrencyInstance", loc);
tempString.remove();
formatter = NumberFormat::createCurrencyInstance(Locale(loc), status);
failure(status, "NumberFormat::createCurrencyInstance", loc);
tempString.remove();
- uloc_canonicalize("it_IT_PREEURO", loc, 256, &status);
+ uloc_canonicalize("it_IT@currency=ITL", loc, 256, &status);
formatter = NumberFormat::createInstance(Locale(loc), status);
if (failure(status, "NumberFormat::createNumberInstance", TRUE)){
delete formatter;
return;
formatter = NumberFormat::createInstance(Locale(loc), status);
if (failure(status, "NumberFormat::createNumberInstance", TRUE)){
delete formatter;
return;
tempString = formatter->format (-5789.9876, tempString);
if (tempString == expectedDefault) {
tempString = formatter->format (-5789.9876, tempString);
if (tempString == expectedDefault) {
- uloc_canonicalize("it_IT_PREEURO", loc, 256, &status);
+ uloc_canonicalize("it_IT@currency=ITL", loc, 256, &status);
formatter = NumberFormat::createCurrencyInstance(Locale(loc), status);
failure(status, "NumberFormat::createCurrencyInstance");
tempString.remove();
formatter = NumberFormat::createCurrencyInstance(Locale(loc), status);
failure(status, "NumberFormat::createCurrencyInstance");
tempString.remove();
- uloc_canonicalize("it_IT_PREEURO", loc, 256, &status);
+ uloc_canonicalize("it_IT@currency=ITL", loc, 256, &status);
formatter = NumberFormat::createPercentInstance(Locale(loc), status);
failure(status, "NumberFormat::createPercentInstance");
tempString.remove();
formatter = NumberFormat::createPercentInstance(Locale(loc), status);
failure(status, "NumberFormat::createPercentInstance");
tempString.remove();
- roundingTest(df, 12.35, s);
- roundingTest(df, 12.45, s);
+ roundingTest(&df, 12.35, s);
+ roundingTest(&df, 12.45, s);
- roundingTest(df, 12.55, s);
- roundingTest(df, 12.65, s);
+ roundingTest(&df, 12.55, s);
+ roundingTest(&df, 12.65, s);
- roundingTest(df, 12.75, s);
- roundingTest(df, 12.752,s);
- roundingTest(df, 12.85, s);
+ roundingTest(&df, 12.75, s);
+ roundingTest(&df, 12.752,s);
+ roundingTest(&df, 12.85, s);
- roundingTest(df, 12.95, s);
- roundingTest(df, 12.952,s);
+ roundingTest(&df, 12.95, s);
+ roundingTest(&df, 12.952,s);
FieldPosition pos(FieldPosition::DONT_CARE);
out = df->format(x, out, pos);
logln(UnicodeString("") + x + " formats with 1 fractional digits to " + out);
FieldPosition pos(FieldPosition::DONT_CARE);
out = df->format(x, out, pos);
logln(UnicodeString("") + x + " formats with 1 fractional digits to " + out);
UnicodeString currency(fmt->getSymbol(DecimalFormatSymbols::kCurrencySymbol));
UnicodeString intlCurrency(fmt->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol));
UnicodeString monDecSeparator(fmt->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol));
UnicodeString currency(fmt->getSymbol(DecimalFormatSymbols::kCurrencySymbol));
UnicodeString intlCurrency(fmt->getSymbol(DecimalFormatSymbols::kIntlCurrencySymbol));
UnicodeString monDecSeparator(fmt->getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol));
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *fmt = new DecimalFormat(UnicodeString("#,##0.00"), status);
{
UErrorCode status = U_ZERO_ERROR;
DecimalFormat *fmt = new DecimalFormat(UnicodeString("#,##0.00"), status);
double num = 1234.5;
fmt->format(num, formatted, field);
if (field.getBeginIndex() != 0 && field.getEndIndex() != 5)
double num = 1234.5;
fmt->format(num, formatted, field);
if (field.getBeginIndex() != 0 && field.getEndIndex() != 5)
// Create a DecimalFormat using the pattern we got and format a number
DecimalFormatSymbols *symbols = new DecimalFormatSymbols(locales[i], status);
failure(status, "new DecimalFormatSymbols");
// Create a DecimalFormat using the pattern we got and format a number
DecimalFormatSymbols *symbols = new DecimalFormatSymbols(locales[i], status);
failure(status, "new DecimalFormatSymbols");
+
+ // Disable currency spacing for the purposes of this test.
+ // To do this, set the spacing insert to the empty string both before and after the symbol.
+ symbols->setPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, FALSE, u"");
+ symbols->setPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, TRUE, u"");
+
DecimalFormat *fmt1 = new DecimalFormat(pattern, *symbols, status);
failure(status, "new DecimalFormat");
DecimalFormat *fmt1 = new DecimalFormat(pattern, *symbols, status);
failure(status, "new DecimalFormat");
- DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::getEnglish(), status);
- failure(status, "new DecimalFormatSymbols");
- DecimalFormat *f = new DecimalFormat(UnicodeString(""), syms, status);
+ LocalPointer<DecimalFormatSymbols> syms(new DecimalFormatSymbols(Locale::getEnglish(), status), status);
+ if (failure(status, "new DecimalFormatSymbols")) {
+ return;
+ }
+ DecimalFormat *f = new DecimalFormat(UnicodeString(u""), syms.orphan(), status);
if (!failure(status, "new DecimalFormat")) {
UnicodeString s;
FieldPosition pos(FieldPosition::DONT_CARE);
if (!failure(status, "new DecimalFormat")) {
UnicodeString s;
FieldPosition pos(FieldPosition::DONT_CARE);
* DecimalFormat.applyPattern() sets minimum integer digits incorrectly.
* CANNOT REPRODUCE
* This bug is a duplicate of 4139344, which is a duplicate of 4134300
* DecimalFormat.applyPattern() sets minimum integer digits incorrectly.
* CANNOT REPRODUCE
* This bug is a duplicate of 4139344, which is a duplicate of 4134300
sdf->applyPattern(pattern, status);
if (!failure(status, "sdf->applyPattern")) {
int minIntDig = sdf->getMinimumIntegerDigits();
sdf->applyPattern(pattern, status);
if (!failure(status, "sdf->applyPattern")) {
int minIntDig = sdf->getMinimumIntegerDigits();
- NumberFormat *f = (i == 0) ? NumberFormat::createInstance(status)
- : NumberFormat::createPercentInstance(status);
+ LocalPointer<NumberFormat> f(
+ ((i == 0) ? NumberFormat::createInstance(status) : NumberFormat::createPercentInstance(status)),
+ status);
- logln(UnicodeString("") +
- d + " -> " +
- '"' + s + '"' + " -> " + e);
+ logln("%f -> \"%s\" -> %f", d, CStr(s)(), e);
* DecimalFormat.parse() fails when ParseIntegerOnly set to true
*/
void NumberFormatRegressionTest::Test4170798(void) {
* DecimalFormat.parse() fails when ParseIntegerOnly set to true
*/
void NumberFormatRegressionTest::Test4170798(void) {
- UErrorCode status = U_ZERO_ERROR;
- NumberFormat *nf = NumberFormat::createInstance(Locale::getUS(), status);
- if (failure(status, "NumberFormat::createInstance", TRUE)){
- delete nf;
- return;
- };
- DecimalFormat *df = dynamic_cast<DecimalFormat *>(nf);
- if(df == NULL) {
- errln("DecimalFormat needed to continue");
+ IcuTestErrorCode status(*this, "Test4170798");
+ LocalPointer<DecimalFormat> df(dynamic_cast<DecimalFormat*>(
+ NumberFormat::createInstance(Locale::getUS(), status)), status);
+ if (!assertSuccess("", status, true, __FILE__, __LINE__)) {
+ {
+ Formattable n;
+ ParsePosition pos(0);
+ df->parse("-0.0", n, pos);
+ if (n.getType() != Formattable::kDouble
+ || n.getDouble() != -0.0) {
+ errln(UnicodeString("FAIL: default parse(\"-0.0\") returns ") + toString(n));
+ }
+ }
- Formattable n;
- ParsePosition pos(0);
- df->parse("-0.0", n, pos);
- if (n.getType() != Formattable::kLong
- || n.getLong() != 0) {
- errln(UnicodeString("FAIL: parse(\"-0.0\") returns ") + toString(n));
+ {
+ Formattable n;
+ ParsePosition pos(0);
+ df->parse("-0.0", n, pos);
+ if (n.getType() != Formattable::kLong
+ || n.getLong() != 0) {
+ errln(UnicodeString("FAIL: integer parse(\"-0.0\") returns ") + toString(n));
+ }
- "00", "#00",
- "000", "#000", // No grouping
- "#000", "#000", // No grouping
+ "00", "00",
+ "000", "000", // No grouping
+ "#000", "000", // No grouping
- "0,000", "#0,000",
- "00,000", "#00,000",
- "000,000", "#,000,000",
- "0,000,000,000,000.0000", "#0,000,000,000,000.0000", // Reported
+ "0,000", "0,000",
+ "00,000", "00,000",
+ "000,000", "000,000",
+ "0,000,000,000,000.0000", "0,000,000,000,000.0000", // Reported
sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "usd");
fmt.setDecimalFormatSymbols(sym);
s.remove();
sym.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "usd");
fmt.setDecimalFormatSymbols(sym);
s.remove();
sym.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, "DOL");
fmt.setDecimalFormatSymbols(sym);
s.remove();
sym.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, "DOL");
fmt.setDecimalFormatSymbols(sym);
s.remove();
- df->toLocalizedPattern(pat);
- f2.applyLocalizedPattern(pat, status);
+// TODO(refactor): don't worry about localized patterns for now.
+// df->toLocalizedPattern(pat);
+// f2.applyLocalizedPattern(pat, status);
- if (j == 1) { // Currency format
- f2.setCurrency(f2.getCurrency(), status);
- }
+// if (j == 1) { // Currency format
+// f2.setCurrency(f2.getCurrency(), status);
+// }
if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete fmt;
return;
if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete fmt;
return;
int32_t DATA[] = { INT32_MIN, INT32_MAX, -100000000, 100000000 };
int32_t DATA[] = { INT32_MIN, INT32_MAX, -100000000, 100000000 };
for (int i=0; i<DATA_length; ++i) {
UnicodeString str((UnicodeString)"" + DATA[i]);
for (int m = 1; m <= 100; m++) {
for (int i=0; i<DATA_length; ++i) {
UnicodeString str((UnicodeString)"" + DATA[i]);
for (int m = 1; m <= 100; m++) {
void NumberFormatRegressionTest::Test4217661(void) {
const double D[] = { 0.001, 1.001, 0.006, 1.006 };
const char* S[] = { "0", "1", "0.01", "1.01" };
void NumberFormatRegressionTest::Test4217661(void) {
const double D[] = { 0.001, 1.001, 0.006, 1.006 };
const char* S[] = { "0", "1", "0.01", "1.01" };
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmt = NumberFormat::createInstance(Locale::getUS(), status);
if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete fmt;
return;
UErrorCode status = U_ZERO_ERROR;
NumberFormat *fmt = NumberFormat::createInstance(Locale::getUS(), status);
if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete fmt;
return;
if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete nf;
return;
if (failure(status, "createInstance", Locale::getUS(), TRUE)){
delete nf;
return;
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." };
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." };
- UnicodeString udt("11.10.2000", "");
- UnicodeString exp("11.10.00", "");
+ UnicodeString udt(u"11.10.2000");
+ UnicodeString exp(u"11.10.00");
if (U_FAILURE(status)) {
dataerrln("FAIL: Calendar::createInstance() returned " + (UnicodeString)u_errorName(status));
return;
}
// create a NumberFormat for this locale
if (U_FAILURE(status)) {
dataerrln("FAIL: Calendar::createInstance() returned " + (UnicodeString)u_errorName(status));
return;
}
// create a NumberFormat for this locale
// Error Checking / Reporting macros
//
//---------------------------------------------------------------------------
// Error Checking / Reporting macros
//
//---------------------------------------------------------------------------
if (U_FAILURE(status)) { \
if (status == U_MISSING_RESOURCE_ERROR) { \
dataerrln("File %s, Line %d: status=%s", __FILE__, __LINE__, u_errorName(status)); \
} else { \
errln("File %s, Line %d: status=%s", __FILE__, __LINE__, u_errorName(status)); \
} return; \
if (U_FAILURE(status)) { \
if (status == U_MISSING_RESOURCE_ERROR) { \
dataerrln("File %s, Line %d: status=%s", __FILE__, __LINE__, u_errorName(status)); \
} else { \
errln("File %s, Line %d: status=%s", __FILE__, __LINE__, u_errorName(status)); \
} return; \
if ((expr)==FALSE) {\
errln("File %s, line %d: Assertion Failed: " #expr "\n", __FILE__, __LINE__);\
if ((expr)==FALSE) {\
errln("File %s, line %d: Assertion Failed: " #expr "\n", __FILE__, __LINE__);\
+ } \
+} UPRV_BLOCK_MACRO_END
+#define TEST_ASSERT_EQUALS(x,y) UPRV_BLOCK_MACRO_BEGIN { \
+ char _msg[1000]; \
+ int32_t len = sprintf (_msg,"File %s, line %d: " #x "==" #y, __FILE__, __LINE__); \
+ (void)len; \
+ U_ASSERT(len < (int32_t) sizeof(_msg)); \
+ assertEquals((const char*) _msg, x,y); \
+} UPRV_BLOCK_MACRO_END
Formattable val;
nf->parse(numStr, val, status);
TEST_CHECK_STATUS(status);
Formattable val;
nf->parse(numStr, val, status);
TEST_CHECK_STATUS(status);
- TEST_ASSERT(Formattable::kDouble == val.getType());
- TEST_ASSERT(1000000000 == val.getInt64(status));
+ TEST_ASSERT_EQUALS(Formattable::kDouble, val.getType());
+ TEST_ASSERT_EQUALS(1000000000LL, val.getInt64(status));
TEST_CHECK_STATUS(status);
numStr = "100000000000000001.1"; // approx 1E17, parses as a double rather
TEST_CHECK_STATUS(status);
numStr = "100000000000000001.1"; // approx 1E17, parses as a double rather
// even though int64 is more precise.
nf->parse(numStr, val, status);
TEST_CHECK_STATUS(status);
// 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_ASSERT_EQUALS(Formattable::kDouble, val.getType());
+ TEST_ASSERT_EQUALS(100000000000000001LL, val.getInt64(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_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_ASSERT_EQUALS(Formattable::kInt64, val.getType());
+ TEST_ASSERT_EQUALS(100000000000000000LL, val.getInt64());
+ TEST_ASSERT_EQUALS(1.0E17, val.getDouble(status));
TEST_CHECK_STATUS(status);
numStr = "9223372036854775807"; // largest int64_t
nf->parse(numStr, val, status);
TEST_CHECK_STATUS(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());
+ TEST_ASSERT_EQUALS(Formattable::kInt64, val.getType());
+ TEST_ASSERT_EQUALS(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.
// 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.
numStr = "-9223372036854775808"; // smallest int64_t
nf->parse(numStr, val, 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_ASSERT_EQUALS(Formattable::kInt64, val.getType());
+ // TEST_ASSERT_EQUALS(-9223372036854775808LL, val.getInt64()); // Compiler chokes on constant.
+ TEST_ASSERT_EQUALS((int64_t)0x8000000000000000LL, val.getInt64());
+ TEST_ASSERT_EQUALS(-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_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);
+ TEST_ASSERT_EQUALS(Formattable::kDouble, val.getType());
+ TEST_ASSERT_EQUALS(9223372036854775807LL, val.getInt64(status));
+ TEST_ASSERT_EQUALS(status, U_INVALID_FORMAT_ERROR);
TEST_CHECK_STATUS(status);
numStr = "-9223372036854775809"; // smallest int64_t - 1
nf->parse(numStr, val, status);
TEST_CHECK_STATUS(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);
+ TEST_ASSERT_EQUALS(Formattable::kDouble, val.getType());
+ // TEST_ASSERT_EQUALS(-9223372036854775808LL, val.getInt64(status)); // spurious compiler warnings
+ TEST_ASSERT_EQUALS((int64_t)0x8000000000000000LL, val.getInt64(status));
+ TEST_ASSERT_EQUALS(status, U_INVALID_FORMAT_ERROR);
TEST_CHECK_STATUS(status);
// Test values near the limit of where doubles can represent all integers.
TEST_CHECK_STATUS(status);
// Test values near the limit of where doubles can represent all integers.
nf->parse(numStr, val, status);
TEST_CHECK_STATUS(status);
// printf("getInt64() returns %lld\n", val.getInt64(status));
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_ASSERT_EQUALS(Formattable::kDouble, val.getType());
+ TEST_ASSERT_EQUALS(9007199254740991LL, val.getInt64(status));
+ TEST_ASSERT_EQUALS(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_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_ASSERT_EQUALS(Formattable::kDouble, val.getType());
+ TEST_ASSERT_EQUALS(9007199254740992LL, val.getInt64(status));
+ TEST_ASSERT_EQUALS(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_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_ASSERT_EQUALS(Formattable::kDouble, val.getType());
+ TEST_ASSERT_EQUALS((int64_t)9007199254740993LL,val.getInt64(status));
+ TEST_ASSERT_EQUALS((double)9007199254740994.0,(double)val.getDouble(status));
if(n!=-123456789) {
errln("FAIL: with different neg prefix , unum_parse status %s, result %d expected -123456789\n", u_errorName(status), n);
} else {
if(n!=-123456789) {
errln("FAIL: with different neg prefix , unum_parse status %s, result %d expected -123456789\n", u_errorName(status), n);
} else {
// preventing formatting of big decimals.
UErrorCode status = U_ZERO_ERROR;
DecimalFormatSymbols symbols(Locale::getEnglish(), status);
// preventing formatting of big decimals.
UErrorCode status = U_ZERO_ERROR;
DecimalFormatSymbols symbols(Locale::getEnglish(), status);
- LocalPointer<DecimalFormat> df(new DecimalFormat("###.##", symbols, status));
+ LocalPointer<DecimalFormat> df(new DecimalFormat("###.##", symbols, status), status);