/***********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2004, International Business Machines Corporation
+ * Copyright (c) 1997-2010, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
if (exec) {
logln("NumberFormat API test---"); logln("");
UErrorCode status = U_ZERO_ERROR;
+ Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln("ERROR: Could not set default locale, test may not give correct results");
}
testAPI(/* par */);
+ Locale::setDefault(saveLocale, status);
}
break;
case 1: name = "NumberFormatRegistration";
if (exec) {
logln("NumberFormat Registration test---"); logln("");
UErrorCode status = U_ZERO_ERROR;
+ Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln("ERROR: Could not set default locale, test may not give correct results");
}
testRegistration();
+ Locale::setDefault(saveLocale, status);
}
break;
default: name = ""; break;
NumberFormat *def = NumberFormat::createInstance(status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create NumberFormat (default)");
+ dataerrln("ERROR: Could not create NumberFormat (default) - %s", u_errorName(status));
}
status = U_ZERO_ERROR;
NumberFormat *fr = NumberFormat::createInstance(Locale::getFrench(), status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create NumberFormat (French)");
+ dataerrln("ERROR: Could not create NumberFormat (French) - %s", u_errorName(status));
}
NumberFormat *cur = NumberFormat::createCurrencyInstance(status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create NumberFormat (currency, default)");
+ dataerrln("ERROR: Could not create NumberFormat (currency, default) - %s", u_errorName(status));
}
status = U_ZERO_ERROR;
NumberFormat *cur_fr = NumberFormat::createCurrencyInstance(Locale::getFrench(), status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create NumberFormat (currency, French)");
+ dataerrln("ERROR: Could not create NumberFormat (currency, French) - %s", u_errorName(status));
}
NumberFormat *per = NumberFormat::createPercentInstance(status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create NumberFormat (percent, default)");
+ dataerrln("ERROR: Could not create NumberFormat (percent, default) - %s", u_errorName(status));
}
status = U_ZERO_ERROR;
NumberFormat *per_fr = NumberFormat::createPercentInstance(Locale::getFrench(), status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create NumberFormat (percent, French)");
+ dataerrln("ERROR: Could not create NumberFormat (percent, French) - %s", u_errorName(status));
}
// ======= Test equality
-
+if (per_fr != NULL && cur_fr != NULL)
+{
logln("Testing equality operator");
if( *per_fr == *cur_fr || ! ( *per_fr != *cur_fr) ) {
errln("ERROR: == failed");
}
+}
// ======= Test various format() methods
-
+if (cur_fr != NULL)
+{
logln("Testing various format() methods");
double d = -10456.0037;
errln("ERROR: format(Formattable [long]) failed");
}
logln((UnicodeString) "" + fL.getLong() + " formatted to " + res6);
-
+}
// ======= Test parse()
-
+if (fr != NULL)
+{
logln("Testing parse()");
+ double d = -10456.0037;
UnicodeString text("-10,456.0037");
Formattable result1, result2, result3;
ParsePosition pos(0), pos01(0);
errln("ERROR: Roundtrip failed (via parse()) for " + text);
}
logln(text + " parsed into " + (int32_t) result3.getDouble());
-
+}
// ======= Test getters and setters
-
+if (fr != NULL && def != NULL)
+{
logln("Testing getters and setters");
int32_t count = 0;
if(fr->getMinimumFractionDigits() != def->getMinimumFractionDigits() ) {
errln("ERROR: setMinimumFractionDigits() failed");
}
-
+}
// ======= Test getStaticClassID()
status = U_ZERO_ERROR;
NumberFormat *test = new DecimalFormat(status);
if(U_FAILURE(status)) {
- errln("ERROR: Couldn't create a NumberFormat");
+ errcheckln(status, "ERROR: Couldn't create a NumberFormat - %s", u_errorName(status));
}
if(test->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
#if !UCONFIG_NO_SERVICE
UErrorCode status = U_ZERO_ERROR;
- NumberFormat* f0 = NumberFormat::createInstance(SWAP_LOC, status);
- NumberFormat* f1 = NumberFormat::createInstance(SRC_LOC, status);
- NumberFormat* f2 = NumberFormat::createCurrencyInstance(SRC_LOC, status);
+ LocalPointer<NumberFormat> f0(NumberFormat::createInstance(SWAP_LOC, status));
+ LocalPointer<NumberFormat> f1(NumberFormat::createInstance(SRC_LOC, status));
+ LocalPointer<NumberFormat> f2(NumberFormat::createCurrencyInstance(SRC_LOC, status));
URegistryKey key = NumberFormat::registerFactory(new NFTestFactory(), status);
- NumberFormat* f3 = NumberFormat::createCurrencyInstance(SRC_LOC, status);
- NumberFormat* f3a = NumberFormat::createCurrencyInstance(SRC_LOC, status);
- NumberFormat* f4 = NumberFormat::createInstance(SRC_LOC, status);
+ LocalPointer<NumberFormat> f3(NumberFormat::createCurrencyInstance(SRC_LOC, status));
+ LocalPointer<NumberFormat> f3a(NumberFormat::createCurrencyInstance(SRC_LOC, status));
+ LocalPointer<NumberFormat> f4(NumberFormat::createInstance(SRC_LOC, status));
StringEnumeration* locs = NumberFormat::getAvailableLocales();
- UNumberFormat* uf3 = unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(),NULL, &status);
- UNumberFormat* uf4 = unum_open(UNUM_DEFAULT, NULL, 0, SRC_LOC.getName(), NULL, &status);
+ LocalUNumberFormatPointer uf3(unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(), NULL, &status));
+ LocalUNumberFormatPointer uf4(unum_open(UNUM_DEFAULT, NULL, 0, SRC_LOC.getName(), NULL, &status));
const UnicodeString* res;
for (res = locs->snext(status); res; res = locs->snext(status)) {
}
NumberFormat::unregister(key, status); // restore for other tests
- NumberFormat* f5 = NumberFormat::createCurrencyInstance(SRC_LOC, status);
- UNumberFormat* uf5 = unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(),NULL, &status);
-
- float n = 1234.567f;
- UnicodeString res0, res1, res2, res3, res4, res5;
- UChar ures3[50];
- UChar ures4[50];
- UChar ures5[50];
-
- f0->format(n, res0);
- f1->format(n, res1);
- f2->format(n, res2);
- f3->format(n, res3);
- f4->format(n, res4);
- f5->format(n, res5);
-
- unum_formatDouble(uf3, n, ures3, 50, NULL, &status);
- unum_formatDouble(uf4, n, ures4, 50, NULL, &status);
- unum_formatDouble(uf5, n, ures5, 50, NULL, &status);
-
- logln((UnicodeString)"f0 swap int: " + res0);
- logln((UnicodeString)"f1 src int: " + res1);
- logln((UnicodeString)"f2 src cur: " + res2);
- logln((UnicodeString)"f3 reg cur: " + res3);
- logln((UnicodeString)"f4 reg int: " + res4);
- logln((UnicodeString)"f5 unreg cur: " + res5);
- log("uf3 reg cur: ");
- logln(ures3);
- log("uf4 reg int: ");
- logln(ures4);
- log("uf5 ureg cur: ");
- logln(ures5);
-
- if (f3 == f3a) {
- errln("did not get new instance from service");
+ LocalPointer<NumberFormat> f5(NumberFormat::createCurrencyInstance(SRC_LOC, status));
+ LocalUNumberFormatPointer uf5(unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(), NULL, &status));
+
+ if (U_FAILURE(status)) {
+ dataerrln("Error creating instnaces.");
+ return;
} else {
- delete f3a;
- }
- if (res3 != res0) {
- errln("registered service did not match");
- }
- if (res4 != res1) {
- errln("registered service did not inherit");
- }
- if (res5 != res2) {
- errln("unregistered service did not match original");
- }
+ float n = 1234.567f;
+ UnicodeString res0, res1, res2, res3, res4, res5;
+ UChar ures3[50];
+ UChar ures4[50];
+ UChar ures5[50];
+
+ f0->format(n, res0);
+ f1->format(n, res1);
+ f2->format(n, res2);
+ f3->format(n, res3);
+ f4->format(n, res4);
+ f5->format(n, res5);
+
+ unum_formatDouble(uf3.getAlias(), n, ures3, 50, NULL, &status);
+ unum_formatDouble(uf4.getAlias(), n, ures4, 50, NULL, &status);
+ unum_formatDouble(uf5.getAlias(), n, ures5, 50, NULL, &status);
+
+ logln((UnicodeString)"f0 swap int: " + res0);
+ logln((UnicodeString)"f1 src int: " + res1);
+ logln((UnicodeString)"f2 src cur: " + res2);
+ logln((UnicodeString)"f3 reg cur: " + res3);
+ logln((UnicodeString)"f4 reg int: " + res4);
+ logln((UnicodeString)"f5 unreg cur: " + res5);
+ log("uf3 reg cur: ");
+ logln(ures3);
+ log("uf4 reg int: ");
+ logln(ures4);
+ log("uf5 ureg cur: ");
+ logln(ures5);
+
+ if (f3.getAlias() == f3a.getAlias()) {
+ errln("did not get new instance from service");
+ f3a.orphan();
+ }
+ if (res3 != res0) {
+ errln("registered service did not match");
+ }
+ if (res4 != res1) {
+ errln("registered service did not inherit");
+ }
+ if (res5 != res2) {
+ errln("unregistered service did not match original");
+ }
- if (res0 != ures3) {
- errln("registered service did not match / unum");
- }
- if (res1 != ures4) {
- errln("registered service did not inherit / unum");
- }
- if (res2 != ures5) {
- errln("unregistered service did not match original / unum");
+ if (res0 != ures3) {
+ errln("registered service did not match / unum");
+ }
+ if (res1 != ures4) {
+ errln("registered service did not inherit / unum");
+ }
+ if (res2 != ures5) {
+ errln("unregistered service did not match original / unum");
+ }
}
- unum_close(uf5);
- delete f5;
- unum_close(uf4);
- unum_close(uf3);
- delete f4;
- delete f3;
- delete f2;
- delete f1;
- delete f0;
-
for (res = locs->snext(status); res; res = locs->snext(status)) {
errln(*res); // service should be out of synch
}