From b4573e4661893678c8d9407f62455faaa1db3795 Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Tue, 17 Apr 2018 10:58:41 +0000 Subject: [PATCH] ICU-13634 Minor test expectation updates and status variable fixes. intltest format should be mostly working now. X-SVN-Rev: 41238 --- icu4c/source/i18n/decimfmt.cpp | 3 +-- icu4c/source/i18n/numfmt.cpp | 6 ++--- .../intltest/compactdecimalformattest.cpp | 27 ++++++++++++------- icu4c/source/test/intltest/dcfmtest.cpp | 5 ++-- icu4c/source/test/intltest/measfmttest.cpp | 10 +++---- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index 5a625675c11..1708b0d2e81 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -466,8 +466,7 @@ DecimalFormat::format(int64_t number, UnicodeString& appendTo, FieldPositionIter UnicodeString& DecimalFormat::format(StringPiece number, UnicodeString& appendTo, FieldPositionIterator* posIter, UErrorCode& status) const { - ErrorCode localStatus; - FormattedNumber output = fFormatter->formatDecimal(number, localStatus); + FormattedNumber output = fFormatter->formatDecimal(number, status); if (posIter != nullptr) { output.populateFieldPositionIterator(*posIter, status); } diff --git a/icu4c/source/i18n/numfmt.cpp b/icu4c/source/i18n/numfmt.cpp index 4b45ce00a19..9d7ab667004 100644 --- a/icu4c/source/i18n/numfmt.cpp +++ b/icu4c/source/i18n/numfmt.cpp @@ -589,13 +589,13 @@ NumberFormat::format(const Formattable& obj, } else { switch (n->getType()) { case Formattable::kDouble: - format(n->getDouble(), appendTo, pos); + format(n->getDouble(), appendTo, pos, status); break; case Formattable::kLong: - format(n->getLong(), appendTo, pos); + format(n->getLong(), appendTo, pos, status); break; case Formattable::kInt64: - format(n->getInt64(), appendTo, pos); + format(n->getInt64(), appendTo, pos, status); break; default: status = U_INVALID_FORMAT_ERROR; diff --git a/icu4c/source/test/intltest/compactdecimalformattest.cpp b/icu4c/source/test/intltest/compactdecimalformattest.cpp index 9bdaaad6636..04245639d7a 100644 --- a/icu4c/source/test/intltest/compactdecimalformattest.cpp +++ b/icu4c/source/test/intltest/compactdecimalformattest.cpp @@ -331,11 +331,14 @@ void CompactDecimalFormatTest::TestAPIVariants() { } actual.remove(); + pos.setBeginIndex(0); + pos.setEndIndex(0); status = U_ZERO_ERROR; cdf->format((double)123456.0, actual, &posIter, status); - if (status != U_UNSUPPORTED_ERROR) { - errln(UnicodeString("Fail format(double,UnicodeString&,FieldPositionIterator*,UErrorCode&): Expected status U_UNSUPPORTED_ERROR;") + - "Got status " + u_errorName(status)); + posIter.next(pos); + if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { + errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", first pos 3, status U_ZERO_ERROR; " + + "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); } actual.remove(); @@ -358,11 +361,14 @@ void CompactDecimalFormatTest::TestAPIVariants() { } actual.remove(); + pos.setBeginIndex(0); + pos.setEndIndex(0); status = U_ZERO_ERROR; cdf->format((int32_t)123456, actual, &posIter, status); - if (status != U_UNSUPPORTED_ERROR) { - errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPositionIterator*,UErrorCode&): Expected status U_UNSUPPORTED_ERROR;") + - "Got status " + u_errorName(status)); + posIter.next(pos); + if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { + errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", first pos 3, status U_ZERO_ERROR; " + + "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); } actual.remove(); @@ -385,11 +391,14 @@ void CompactDecimalFormatTest::TestAPIVariants() { } actual.remove(); + pos.setBeginIndex(0); + pos.setEndIndex(0); status = U_ZERO_ERROR; cdf->format((int64_t)123456, actual, &posIter, status); - if (status != U_UNSUPPORTED_ERROR) { - errln(UnicodeString("Fail format(int64_t,UnicodeString&,FieldPositionIterator*,UErrorCode&): Expected status U_UNSUPPORTED_ERROR;") + - "Got status " + u_errorName(status)); + posIter.next(pos); + if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { + errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", first pos 3, status U_ZERO_ERROR; " + + "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); } } diff --git a/icu4c/source/test/intltest/dcfmtest.cpp b/icu4c/source/test/intltest/dcfmtest.cpp index 63fff8146a2..2dc9f82a442 100644 --- a/icu4c/source/test/intltest/dcfmtest.cpp +++ b/icu4c/source/test/intltest/dcfmtest.cpp @@ -454,8 +454,9 @@ void DecimalFormatTest::execFormatTest(int32_t lineNum, } if (result != expected) { - errln("[%s] file dcfmtest.txt, line %d: expected \"%s\", got \"%s\"", - typeStr, lineNum, UnicodeStringPiece(expected).data(), UnicodeStringPiece(result).data()); + errln("[%s] file dcfmtest.txt, line %d: expected \"%s\", got \"%s\", %s", + typeStr, lineNum, UnicodeStringPiece(expected).data(), UnicodeStringPiece(result).data(), + u_errorName(status)); } } diff --git a/icu4c/source/test/intltest/measfmttest.cpp b/icu4c/source/test/intltest/measfmttest.cpp index 7be9adfed02..fd58d72b5f4 100644 --- a/icu4c/source/test/intltest/measfmttest.cpp +++ b/icu4c/source/test/intltest/measfmttest.cpp @@ -1876,9 +1876,9 @@ void MeasureFormatTest::TestCurrencies() { if (!assertSuccess("Error creating format object", status)) { return; } - verifyFormat("TestCurrenciesShort", fmt, &USD_NEG_1, 1, "-USD1.00"); - verifyFormat("TestCurrenciesShort", fmt, &USD_1, 1, "USD1.00"); - verifyFormat("TestCurrenciesShort", fmt, &USD_2, 1, "USD2.00"); + verifyFormat("TestCurrenciesShort", fmt, &USD_NEG_1, 1, "-USD\\u00A01.00"); + verifyFormat("TestCurrenciesShort", fmt, &USD_1, 1, "USD\\u00A01.00"); + verifyFormat("TestCurrenciesShort", fmt, &USD_2, 1, "USD\\u00A02.00"); fmt = MeasureFormat(en, UMEASFMT_WIDTH_NARROW, status); if (!assertSuccess("Error creating format object", status)) { return; @@ -2099,8 +2099,8 @@ void MeasureFormatTest::TestGroupingSeparator() { "grouping separator", "2,147,483,647 yrs, -2,147,483,648 mths, -987 days, 1,362 hr, 987 min", appendTo); - assertEquals("begin index", 9, pos.getBeginIndex()); - assertEquals("end index", 10, pos.getEndIndex()); + assertEquals("begin index", 1, pos.getBeginIndex()); + assertEquals("end index", 2, pos.getEndIndex()); } void MeasureFormatTest::TestDoubleZero() { -- 2.40.0