From: Yoshito Umaoka Date: Wed, 6 Jul 2011 16:42:25 +0000 (+0000) Subject: ICU-8675 Simple test case for checking stand alone GMT parsing multiple times. X-Git-Tag: milestone-59-0-1~4678 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c22c678254fb331db2a91d041f96034008817ae;p=icu ICU-8675 Simple test case for checking stand alone GMT parsing multiple times. X-SVN-Rev: 30282 --- diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index 7f6078874aa..07c782e404b 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -82,9 +82,10 @@ void DateFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &nam TESTCASE(42,TestISOEra); TESTCASE(43,TestFormalChineseDate); TESTCASE(44,TestNumberAsStringParsing); + TESTCASE(45,TestStandAloneGMTParse); /* - TESTCASE(45,TestRelativeError); - TESTCASE(46,TestRelativeOther); + TESTCASE(46,TestRelativeError); + TESTCASE(47,TestRelativeOther); */ default: name = ""; break; } @@ -3577,8 +3578,27 @@ void DateFormatTest::TestFormalChineseDate() { dataerrln((UnicodeString)"FAIL: parsed -> " + parsedres + " expected -> " + expres); delete usf; } - delete sdf; -} + delete sdf; +} + +// Test case for #8675 +// Incorrect parse offset with stand alone GMT string on 2nd or later iteration. +void DateFormatTest::TestStandAloneGMTParse() { + UErrorCode status = U_ZERO_ERROR; + SimpleDateFormat *sdf = new SimpleDateFormat("ZZZZ", Locale(""), status); + failure(status, "new SimpleDateFormat"); + + UnicodeString inText("GMT$$$"); + for (int32_t i = 0; i < 10; i++) { + ParsePosition pos(0); + sdf->parse(inText, pos); + if (pos.getIndex() != 3) { + errln((UnicodeString)"FAIL: Incorrect output parse position: actual=" + pos.getIndex() + " expected=3"); + } + } + + delete sdf; +} #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/test/intltest/dtfmttst.h b/icu4c/source/test/intltest/dtfmttst.h index 58bb0a820cd..ccf46c7ebfd 100644 --- a/icu4c/source/test/intltest/dtfmttst.h +++ b/icu4c/source/test/intltest/dtfmttst.h @@ -171,6 +171,8 @@ public: // package void TestFormalChineseDate(void); + void TestStandAloneGMTParse(void); + public: /** * Test host-specific formatting.