X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..340931cb2e044a2141d11567dd0f782524e32994:/icuSources/test/intltest/tzrulets.cpp diff --git a/icuSources/test/intltest/tzrulets.cpp b/icuSources/test/intltest/tzrulets.cpp index dddc4dd3..dc644329 100644 --- a/icuSources/test/intltest/tzrulets.cpp +++ b/icuSources/test/intltest/tzrulets.cpp @@ -1,7 +1,9 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* -* Copyright (C) 2007-2010, International Business Machines Corporation and * -* others. All Rights Reserved. * +* Copyright (C) 2007-2016, International Business Machines Corporation and +* others. All Rights Reserved. ******************************************************************************* */ @@ -16,6 +18,7 @@ #include "unicode/tzrule.h" #include "unicode/calendar.h" #include "unicode/gregocal.h" +#include "unicode/strenum.h" #include "unicode/ucal.h" #include "unicode/unistr.h" #include "unicode/ustring.h" @@ -30,8 +33,6 @@ #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break #define HOUR (60*60*1000) -static const UVersionInfo ICU_453 = {4,5,3,0}; - static const char *const TESTZIDS[] = { "AGT", "America/New_York", @@ -86,7 +87,7 @@ TestZIDEnumeration::TestZIDEnumeration(UBool all) len = tzenum->count(status); } else { tzenum = NULL; - len = (int32_t)sizeof(TESTZIDS)/sizeof(TESTZIDS[0]); + len = UPRV_LENGTHOF(TESTZIDS); } } @@ -140,6 +141,7 @@ void TimeZoneRuleTest::runIndexedTest( int32_t index, UBool exec, const char* &n CASE(14, TestT6216); CASE(15, TestT6669); CASE(16, TestVTimeZoneWrapper); + CASE(17, TestT8943); default: name = ""; break; } } @@ -264,7 +266,7 @@ TimeZoneRuleTest::TestSimpleRuleBasedTimeZone(void) { if (rbtz1->hasSameRules(*rbtz3)) { errln("FAIL: rbtz1 and rbtz3 have different rules, but returned true."); } - RuleBasedTimeZone *rbtz1c = (RuleBasedTimeZone*)rbtz1->clone(); + RuleBasedTimeZone *rbtz1c = rbtz1->clone(); if (!rbtz1->hasSameRules(*rbtz1c)) { errln("FAIL: Cloned RuleBasedTimeZone must have the same rules with the original."); } @@ -546,7 +548,7 @@ TimeZoneRuleTest::TestHistoricalRuleBasedTimeZone(void) { if (ny->hasSameRules(*rbtz) || rbtz->hasSameRules(*ny)) { errln("FAIL: hasSameRules must return false"); } - RuleBasedTimeZone *rbtzc = (RuleBasedTimeZone*)rbtz->clone(); + RuleBasedTimeZone *rbtzc = rbtz->clone(); if (!rbtz->hasSameRules(*rbtzc) || !rbtz->hasEquivalentTransitions(*rbtzc, jan1_1950, jan1_2010, TRUE, status)) { errln("FAIL: hasSameRules/hasEquivalentTransitions must return true for cloned RBTZs"); } @@ -740,7 +742,7 @@ TimeZoneRuleTest::TestHasEquivalentTransitions(void) { } // Cloned TimeZone - BasicTimeZone *newyork2 = (BasicTimeZone*)newyork->clone(); + BasicTimeZone *newyork2 = newyork->clone(); if (!newyork->hasEquivalentTransitions(*newyork2, jan1_1971, jan1_2011, FALSE, status)) { errln("FAIL: Cloned TimeZone must have the same transitions"); } @@ -1112,7 +1114,7 @@ TimeZoneRuleTest::TestGetSimpleRules(void) { getUTCMillis(2005, UCAL_JULY, 1), getUTCMillis(2010, UCAL_NOVEMBER, 1), }; - int32_t numTimes = sizeof(testTimes)/sizeof(UDate); + int32_t numTimes = UPRV_LENGTHOF(testTimes); UErrorCode status = U_ZERO_ERROR; TestZIDEnumeration tzenum(!quick); InitialTimeZoneRule *initial; @@ -1693,7 +1695,7 @@ TimeZoneRuleTest::TestVTimeZoneCoverage(void) { // setRawOffset const int32_t RAW = -10*HOUR; - VTimeZone *tmpvtz = (VTimeZone*)vtz->clone(); + VTimeZone *tmpvtz = vtz->clone(); tmpvtz->setRawOffset(RAW); if (tmpvtz->getRawOffset() != RAW) { logln("setRawOffset is implemented in VTimeZone"); @@ -2105,7 +2107,7 @@ TimeZoneRuleTest::TestT6216(void) { int32_t i, j; // Get test times - UDate times[sizeof(TestDates) / (3 * sizeof(int32_t))]; + UDate times[UPRV_LENGTHOF(TestDates)]; int32_t numTimes; UErrorCode status = U_ZERO_ERROR; @@ -2616,6 +2618,49 @@ static UBool hasEquivalentTransitions(/*const*/ BasicTimeZone& tz1, /*const*/Bas return TRUE; } +// Test case for ticket#8943 +// RuleBasedTimeZone#getOffsets throws NPE +void +TimeZoneRuleTest::TestT8943(void) { + UErrorCode status = U_ZERO_ERROR; + UnicodeString id("Ekaterinburg Time"); + UnicodeString stdName("Ekaterinburg Standard Time"); + UnicodeString dstName("Ekaterinburg Daylight Time"); + + InitialTimeZoneRule *initialRule = new InitialTimeZoneRule(stdName, 18000000, 0); + RuleBasedTimeZone *rbtz = new RuleBasedTimeZone(id, initialRule); + + DateTimeRule *dtRule = new DateTimeRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 10800000, DateTimeRule::WALL_TIME); + AnnualTimeZoneRule *atzRule = new AnnualTimeZoneRule(stdName, 18000000, 0, dtRule, 2000, 2010); + rbtz->addTransitionRule(atzRule, status); + + dtRule = new DateTimeRule(UCAL_MARCH, -1, UCAL_SUNDAY, 7200000, DateTimeRule::WALL_TIME); + atzRule = new AnnualTimeZoneRule(dstName, 18000000, 3600000, dtRule, 2000, 2010); + rbtz->addTransitionRule(atzRule, status); + + dtRule = new DateTimeRule(UCAL_JANUARY, 1, 0, DateTimeRule::WALL_TIME); + atzRule = new AnnualTimeZoneRule(stdName, 21600000, 0, dtRule, 2011, AnnualTimeZoneRule::MAX_YEAR); + rbtz->addTransitionRule(atzRule, status); + + dtRule = new DateTimeRule(UCAL_JANUARY, 1, 1, DateTimeRule::WALL_TIME); + atzRule = new AnnualTimeZoneRule(dstName, 21600000, 0, dtRule, 2011, AnnualTimeZoneRule::MAX_YEAR); + rbtz->addTransitionRule(atzRule, status); + rbtz->complete(status); + + if (U_FAILURE(status)) { + errln("Failed to construct a RuleBasedTimeZone"); + } else { + int32_t raw, dst; + rbtz->getOffset(1293822000000.0 /* 2010-12-31 19:00:00 UTC */, FALSE, raw, dst, status); + if (U_FAILURE(status)) { + errln("Error invoking getOffset"); + } else if (raw != 21600000 || dst != 0) { + errln(UnicodeString("Fail: Wrong offsets: ") + raw + "/" + dst + " Expected: 21600000/0"); + } + } + + delete rbtz; +} #endif /* #if !UCONFIG_NO_FORMATTING */