ICU-5032 Increase code coverage

X-SVN-Rev: 19917
This commit is contained in:
George Rhoten 2006-07-28 19:35:12 +00:00
parent d9d4065306
commit d6e59fa634
2 changed files with 55 additions and 1 deletions

View file

@ -82,6 +82,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
CASE(31,TestCoverage);
CASE(32,TestJB3832);
CASE(33,TestHost);
CASE(34,TestCurrencyFormat);
default: name = ""; break;
}
}
@ -2193,7 +2194,7 @@ void NumberFormatTest::TestJB3832(){
+ UnicodeString( " for locale: ")+ UnicodeString(localeID) );
}
if (U_FAILURE(status)){
errln((UnicodeString)"FAIL: Status " + (int32_t)status);
errln("FAIL: Status %s", u_errorName(status));
}
delete currencyFmt;
}
@ -2205,4 +2206,55 @@ void NumberFormatTest::TestHost()
#endif
}
void NumberFormatTest::TestCurrencyFormat()
{
// This test is here to increase code coverage.
UErrorCode status = U_ZERO_ERROR;
MeasureFormat *cloneObj;
UnicodeString str;
Formattable toFormat, result;
static const UChar ISO_CODE[4] = {0x0047, 0x0042, 0x0050, 0};
Locale saveDefaultLocale = Locale::getDefault();
Locale::setDefault( Locale::getUK(), status );
if (U_FAILURE(status)) {
errln("couldn't set default Locale!");
return;
}
MeasureFormat *measureObj = MeasureFormat::createCurrencyFormat(status);
Locale::setDefault( saveDefaultLocale, status );
if (U_FAILURE(status)){
errln("FAIL: Status %s", u_errorName(status));
return;
}
cloneObj = (MeasureFormat *)measureObj->clone();
if (cloneObj == NULL) {
errln("Clone doesn't work");
return;
}
toFormat.adoptObject(new CurrencyAmount(1234.56, ISO_CODE, status));
measureObj->format(toFormat, str, status);
measureObj->parseObject(str, result, status);
if (U_FAILURE(status)){
errln("FAIL: Status %s", u_errorName(status));
}
if (result != toFormat) {
errln("measureObj does not round trip. Formatted string was \"" + str + "\" Got: " + toString(result) + " Expected: " + toString(toFormat));
}
status = U_ZERO_ERROR;
str.truncate(0);
cloneObj->format(toFormat, str, status);
cloneObj->parseObject(str, result, status);
if (U_FAILURE(status)){
errln("FAIL: Status %s", u_errorName(status));
}
if (result != toFormat) {
errln("Clone does not round trip. Formatted string was \"" + str + "\" Got: " + toString(result) + " Expected: " + toString(toFormat));
}
delete measureObj;
delete cloneObj;
}
#endif /* #if !UCONFIG_NO_FORMATTING */

View file

@ -122,6 +122,8 @@ class NumberFormatTest: public CalendarTimeZoneTest {
void TestJB3832(void);
void TestHost(void);
void TestCurrencyFormat(void);
private:
static UBool equalValue(const Formattable& a, const Formattable& b);