From b9243a05226634974bcec2c221c05fcaf92301e3 Mon Sep 17 00:00:00 2001 From: Travis Keep Date: Tue, 12 Feb 2013 19:47:49 +0000 Subject: [PATCH] ICU-9919 Add test to ensure that DateIntervalInfo.setIntervalPattern has no unwanted side effects. X-SVN-Rev: 33194 --- icu4c/source/test/intltest/dtifmtts.cpp | 20 +++++++++++++++++++- icu4c/source/test/intltest/dtifmtts.h | 8 +++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/icu4c/source/test/intltest/dtifmtts.cpp b/icu4c/source/test/intltest/dtifmtts.cpp index 26d848470f1..a1a7f4e14e0 100644 --- a/icu4c/source/test/intltest/dtifmtts.cpp +++ b/icu4c/source/test/intltest/dtifmtts.cpp @@ -45,7 +45,8 @@ void DateIntervalFormatTest::runIndexedTest( int32_t index, UBool exec, const ch TESTCASE(0, testAPI); TESTCASE(1, testFormat); TESTCASE(2, testFormatUserDII); - TESTCASE(3, testStress); + TESTCASE(3, testSetIntervalPatternNoSideEffect); + TESTCASE(4, testStress); default: name = ""; break; } } @@ -1102,6 +1103,23 @@ void DateIntervalFormatTest::testFormatUserDII() { } +void DateIntervalFormatTest::testSetIntervalPatternNoSideEffect() { + UErrorCode ec = U_ZERO_ERROR; + DateIntervalInfo* dtitvinf = new DateIntervalInfo(ec); + UnicodeString expected; + dtitvinf->getIntervalPattern(ctou("yMd"), UCAL_DATE, expected, ec); + dtitvinf->setIntervalPattern(ctou("yMd"), UCAL_DATE, ctou("M/d/y \\u2013 d"), ec); + delete dtitvinf; + dtitvinf = new DateIntervalInfo(ec); + UnicodeString actual; + dtitvinf->getIntervalPattern(ctou("yMd"), UCAL_DATE, actual, ec); + delete dtitvinf; + if (expected != actual) { + errln("DateIntervalInfo.setIntervalPattern should have no side effects."); + } +} + + void DateIntervalFormatTest::expectUserDII(const char** data, int32_t data_length) { int32_t i = 0; diff --git a/icu4c/source/test/intltest/dtifmtts.h b/icu4c/source/test/intltest/dtifmtts.h index 847de1c918b..3f62b09eb1c 100644 --- a/icu4c/source/test/intltest/dtifmtts.h +++ b/icu4c/source/test/intltest/dtifmtts.h @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2008, International Business Machines Corporation and + * Copyright (c) 2008-2013 International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -36,6 +36,12 @@ public: */ void testFormatUserDII(); + /** + * Test for no unwanted side effects when setting + * interval patterns. + */ + void testSetIntervalPatternNoSideEffect(); + /** * Stress test -- stress test formatting on 40 locales */