ICU-11645 Adding C++ test for apply-pattern equality.

X-SVN-Rev: 41333
This commit is contained in:
Shane Carr 2018-05-07 21:30:33 +00:00
parent 5cf4bdf6db
commit 076cee9ad6
2 changed files with 46 additions and 0 deletions

View file

@ -663,6 +663,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
TESTCASE_AUTO(TestParseNaN);
TESTCASE_AUTO(Test11897_LocalizedPatternSeparator);
TESTCASE_AUTO(Test10354);
TESTCASE_AUTO(Test11645_ApplyPatternEquality);
TESTCASE_AUTO_END;
}
@ -9163,4 +9164,48 @@ void NumberFormatTest::Test10354() {
errorCode.logIfFailureAndReset("DecimalFormat.format(NAN, FieldPositionIterator) failed");
}
void NumberFormatTest::Test11645_ApplyPatternEquality() {
IcuTestErrorCode status(*this, "Test11645_ApplyPatternEquality");
const char16_t* pattern = u"#,##0.0#";
LocalPointer<DecimalFormat> fmt((DecimalFormat*) NumberFormat::createInstance(status));
fmt->applyPattern(pattern, status);
LocalPointer<DecimalFormat> fmtCopy;
static int32_t newMultiplier = 37;
fmtCopy.adoptInstead(new DecimalFormat(*fmt));
assertFalse("Value before setter", fmtCopy->getMultiplier() == newMultiplier);
fmtCopy->setMultiplier(newMultiplier);
assertEquals("Value after setter", fmtCopy->getMultiplier(), newMultiplier);
fmtCopy->applyPattern(pattern, status);
assertEquals("Value after applyPattern", fmtCopy->getMultiplier(), newMultiplier);
assertFalse("multiplier", *fmt == *fmtCopy);
static NumberFormat::ERoundingMode newRoundingMode = NumberFormat::ERoundingMode::kRoundCeiling;
fmtCopy.adoptInstead(new DecimalFormat(*fmt));
assertFalse("Value before setter", fmtCopy->getRoundingMode() == newRoundingMode);
fmtCopy->setRoundingMode(newRoundingMode);
assertEquals("Value after setter", fmtCopy->getRoundingMode(), newRoundingMode);
fmtCopy->applyPattern(pattern, status);
assertEquals("Value after applyPattern", fmtCopy->getRoundingMode(), newRoundingMode);
assertFalse("roundingMode", *fmt == *fmtCopy);
static const char16_t* newCurrency = u"EAT";
fmtCopy.adoptInstead(new DecimalFormat(*fmt));
assertFalse("Value before setter", fmtCopy->getCurrency() == newCurrency);
fmtCopy->setCurrency(newCurrency);
assertEquals("Value after setter", fmtCopy->getCurrency(), newCurrency);
fmtCopy->applyPattern(pattern, status);
assertEquals("Value after applyPattern", fmtCopy->getCurrency(), newCurrency);
assertFalse("currency", *fmt == *fmtCopy);
static UCurrencyUsage newCurrencyUsage = UCurrencyUsage::UCURR_USAGE_CASH;
fmtCopy.adoptInstead(new DecimalFormat(*fmt));
assertFalse("Value before setter", fmtCopy->getCurrencyUsage() == newCurrencyUsage);
fmtCopy->setCurrencyUsage(newCurrencyUsage, status);
assertEquals("Value after setter", fmtCopy->getCurrencyUsage(), newCurrencyUsage);
fmtCopy->applyPattern(pattern, status);
assertEquals("Value after applyPattern", fmtCopy->getCurrencyUsage(), newCurrencyUsage);
assertFalse("currencyUsage", *fmt == *fmtCopy);
}
#endif /* #if !UCONFIG_NO_FORMATTING */

View file

@ -228,6 +228,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
void TestParseNaN();
void Test11897_LocalizedPatternSeparator();
void Test10354();
void Test11645_ApplyPatternEquality();
private:
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);