ICU-10354 port NumberFormatTest.Test10354 to C++
authorMarkus Scherer <markus.icu@gmail.com>
Mon, 7 May 2018 21:21:18 +0000 (21:21 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Mon, 7 May 2018 21:21:18 +0000 (21:21 +0000)
X-SVN-Rev: 41332

icu4c/source/test/intltest/numfmtst.cpp
icu4c/source/test/intltest/numfmtst.h

index 2c504b26cd6a8c3580ed48408186db114459a0bc..35c8a4661fbd4cfd528ab0ef1bf61c3feca108e3 100644 (file)
@@ -662,6 +662,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
   TESTCASE_AUTO(TestFastFormatInt32);
   TESTCASE_AUTO(TestParseNaN);
   TESTCASE_AUTO(Test11897_LocalizedPatternSeparator);
+  TESTCASE_AUTO(Test10354);
   TESTCASE_AUTO_END;
 }
 
@@ -9148,4 +9149,18 @@ void NumberFormatTest::Test11897_LocalizedPatternSeparator() {
     assertEquals("should apply the localized pattern", df.getNegativePrefix(result.remove()), "d");
 }
 
+void NumberFormatTest::Test10354() {
+    IcuTestErrorCode errorCode(*this, "Test10354");
+    // Ticket #10354: invalid FieldPositionIterator when formatting with empty NaN
+    DecimalFormatSymbols dfs(errorCode);
+    UnicodeString empty;
+    dfs.setSymbol(DecimalFormatSymbols::kNaNSymbol, empty);
+    DecimalFormat df(errorCode);
+    df.setDecimalFormatSymbols(dfs);
+    UnicodeString result;
+    FieldPositionIterator positions;
+    df.format(NAN, result, &positions, errorCode);
+    errorCode.logIfFailureAndReset("DecimalFormat.format(NAN, FieldPositionIterator) failed");
+}
+
 #endif /* #if !UCONFIG_NO_FORMATTING */
index 3f97bc682c2d563c0ac8a5b40693dc6c8263fdb1..e82ed7190e36c9e815b2bc9d1607f57afcbf567d 100644 (file)
@@ -227,6 +227,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
     void TestFastFormatInt32();
     void TestParseNaN();
     void Test11897_LocalizedPatternSeparator();
+    void Test10354();
 
  private:
     UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);