Index: source/test/intltest/tztest.cpp |
diff --git a/source/test/intltest/tztest.cpp b/source/test/intltest/tztest.cpp |
index 3b16244e4e882137108a6957e8e4b5d6aec7d104..4111e51a5d7ab72c293ac964a26132ad64baea89 100644 |
--- a/source/test/intltest/tztest.cpp |
+++ b/source/test/intltest/tztest.cpp |
@@ -1,6 +1,6 @@ |
/*********************************************************************** |
* COPYRIGHT: |
- * Copyright (c) 1997-2013, International Business Machines Corporation |
+ * Copyright (c) 1997-2014, International Business Machines Corporation |
* and others. All Rights Reserved. |
***********************************************************************/ |
@@ -21,8 +21,6 @@ |
#include "cstring.h" |
#include "olsontz.h" |
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) |
- |
#define CASE(id,test) case id: \ |
name = #test; \ |
if (exec) { \ |
@@ -66,6 +64,7 @@ void TimeZoneTest::runIndexedTest( int32_t index, UBool exec, const char* &name, |
TESTCASE_AUTO(TestAliasedNames); |
TESTCASE_AUTO(TestFractionalDST); |
TESTCASE_AUTO(TestFebruary); |
+ TESTCASE_AUTO(TestCanonicalIDAPI); |
TESTCASE_AUTO(TestCanonicalID); |
TESTCASE_AUTO(TestDisplayNamesMeta); |
TESTCASE_AUTO(TestGetRegion); |
@@ -110,21 +109,21 @@ TimeZoneTest::TestGenericAPI() |
TimeZone* saveDefault = TimeZone::createDefault(); |
logln((UnicodeString)"TimeZone::createDefault() => " + saveDefault->getID(id)); |
- TimeZone* pstZone = TimeZone::createTimeZone("America/Los_Angeles"); |
+ |
+ TimeZone::adoptDefault(zone); |
+ TimeZone* defaultzone = TimeZone::createDefault(); |
+ if (defaultzone == zone || |
+ !(*defaultzone == *zone)) |
+ errln("FAIL: createDefault failed"); |
+ TimeZone::adoptDefault(saveDefault); |
+ delete defaultzone; |
+ delete zoneclone; |
logln("call uprv_timezone() which uses the host"); |
logln("to get the difference in seconds between coordinated universal"); |
logln("time and local time. E.g., -28,800 for PST (GMT-8hrs)"); |
int32_t tzoffset = uprv_timezone(); |
- logln(UnicodeString("Value returned from uprv_timezone = ") + tzoffset); |
- // Invert sign because UNIX semantics are backwards |
- if (tzoffset < 0) |
- tzoffset = -tzoffset; |
- if ((*saveDefault == *pstZone) && (tzoffset != 28800)) { |
- errln("FAIL: t_timezone may be incorrect. It is not 28800"); |
- } |
- |
if ((tzoffset % 900) != 0) { |
/* |
* Ticket#6364 and #7648 |
@@ -136,16 +135,6 @@ TimeZoneTest::TestGenericAPI() |
infoln("WARNING: t_timezone may be incorrect. It is not a multiple of 15min.", tzoffset); |
} |
- TimeZone::adoptDefault(zone); |
- TimeZone* defaultzone = TimeZone::createDefault(); |
- if (defaultzone == zone || |
- !(*defaultzone == *zone)) |
- errln("FAIL: createDefault failed"); |
- TimeZone::adoptDefault(saveDefault); |
- delete defaultzone; |
- delete zoneclone; |
- delete pstZone; |
- |
UErrorCode status = U_ZERO_ERROR; |
const char* tzver = TimeZone::getTZDataVersion(status); |
if (U_FAILURE(status)) { |
@@ -864,8 +853,8 @@ void TimeZoneTest::TestShortZoneIDs() |
{"UTC", 0, FALSE}, // Olson etcetera 0 |
{"ECT", 60, TRUE}, // ICU Link - Europe/Paris |
{"MET", 60, TRUE}, // Olson europe 1:00 C-Eur |
- {"CAT", 120, FALSE}, // ICU Link - Africa/Harare |
- {"ART", 120, FALSE}, // ICU Link - Africa/Cairo |
+ {"CAT", 120, FALSE}, // ICU Link - Africa/Maputo |
+ {"ART", 120, TRUE}, // ICU Link - Africa/Cairo |
{"EET", 120, TRUE}, // Olson europe 2:00 EU |
{"EAT", 180, FALSE}, // ICU Link - Africa/Addis_Ababa |
{"NET", 240, FALSE}, // ICU Link - Asia/Yerevan |
@@ -963,7 +952,7 @@ void TimeZoneTest::TestShortZoneIDs() |
"AST", "America/Anchorage", |
"BET", "America/Sao_Paulo", |
"BST", "Asia/Dhaka", // # spelling changed in 2000h; was Asia/Dacca |
- "CAT", "Africa/Harare", |
+ "CAT", "Africa/Maputo", |
"CNT", "America/St_Johns", |
"CST", "America/Chicago", |
"CTT", "Asia/Shanghai", |
@@ -1916,9 +1905,9 @@ void TimeZoneTest::TestFebruary() { |
TimeZone *tz; |
UDate dt; |
int32_t t, i, raw, dst; |
- for (t = 0; t < LENGTHOF(timezones); ++t) { |
+ for (t = 0; t < UPRV_LENGTHOF(timezones); ++t) { |
tz = timezones[t]; |
- for (i = 0; i < LENGTHOF(data); ++i) { |
+ for (i = 0; i < UPRV_LENGTHOF(data); ++i) { |
gc.set(data[i].year, data[i].month, data[i].day, |
data[i].hour, data[i].minute, data[i].second); |
dt = gc.getTime(status); |
@@ -1948,6 +1937,34 @@ void TimeZoneTest::TestFebruary() { |
} |
} |
} |
+ |
+void TimeZoneTest::TestCanonicalIDAPI() { |
+ // Bogus input string. |
+ UnicodeString bogus; |
+ bogus.setToBogus(); |
+ UnicodeString canonicalID; |
+ UErrorCode ec = U_ZERO_ERROR; |
+ UnicodeString *pResult = &TimeZone::getCanonicalID(bogus, canonicalID, ec); |
+ assertEquals("TimeZone::getCanonicalID(bogus) should fail", U_ILLEGAL_ARGUMENT_ERROR, ec); |
+ assertTrue("TimeZone::getCanonicalID(bogus) should return the dest string", pResult == &canonicalID); |
+ |
+ // U_FAILURE on input. |
+ UnicodeString berlin("Europe/Berlin"); |
+ ec = U_MEMORY_ALLOCATION_ERROR; |
+ pResult = &TimeZone::getCanonicalID(berlin, canonicalID, ec); |
+ assertEquals("TimeZone::getCanonicalID(failure) should fail", U_MEMORY_ALLOCATION_ERROR, ec); |
+ assertTrue("TimeZone::getCanonicalID(failure) should return the dest string", pResult == &canonicalID); |
+ |
+ // Valid input should un-bogus the dest string. |
+ canonicalID.setToBogus(); |
+ ec = U_ZERO_ERROR; |
+ pResult = &TimeZone::getCanonicalID(berlin, canonicalID, ec); |
+ assertSuccess("TimeZone::getCanonicalID(bogus dest) should succeed", ec, TRUE); |
+ assertTrue("TimeZone::getCanonicalID(bogus dest) should return the dest string", pResult == &canonicalID); |
+ assertFalse("TimeZone::getCanonicalID(bogus dest) should un-bogus the dest string", canonicalID.isBogus()); |
+ assertEquals("TimeZone::getCanonicalID(bogus dest) unexpected result", canonicalID, berlin, TRUE); |
+} |
+ |
void TimeZoneTest::TestCanonicalID() { |
// Some canonical IDs in CLDR are defined as "Link" |
@@ -1956,14 +1973,44 @@ void TimeZoneTest::TestCanonicalID() { |
const char *alias; |
const char *zone; |
} excluded1[] = { |
+ {"Africa/Bamako", "Africa/Abidjan"}, |
+ {"Africa/Bangui", "Africa/Lagos"}, |
+ {"Africa/Banjul", "Africa/Abidjan"}, |
+ {"Africa/Blantyre", "Africa/Maputo"}, |
+ {"Africa/Brazzaville", "Africa/Lagos"}, |
+ {"Africa/Bujumbura", "Africa/Maputo"}, |
+ {"Africa/Conakry", "Africa/Abidjan"}, |
+ {"Africa/Dakar", "Africa/Abidjan"}, |
+ {"Africa/Douala", "Africa/Lagos"}, |
+ {"Africa/Freetown", "Africa/Abidjan"}, |
+ {"Africa/Gaborone", "Africa/Maputo"}, |
+ {"Africa/Harare", "Africa/Maputo"}, |
{"Africa/Khartoum", "Africa/Juba"}, |
- {"America/Shiprock", "America/Denver"}, // America/Shiprock is defined as a Link to America/Denver in tzdata |
+ {"Africa/Kigali", "Africa/Maputo"}, |
+ {"Africa/Kinshasa", "Africa/Lagos"}, |
+ {"Africa/Libreville", "Africa/Lagos"}, |
+ {"Africa/Lome", "Africa/Abidjan"}, |
+ {"Africa/Luanda", "Africa/Lagos"}, |
+ {"Africa/Lubumbashi", "Africa/Maputo"}, |
+ {"Africa/Lusaka", "Africa/Maputo"}, |
+ {"Africa/Maseru", "Africa/Johannesburg"}, |
+ {"Africa/Malabo", "Africa/Lagos"}, |
+ {"Africa/Mbabane", "Africa/Johannesburg"}, |
+ {"Africa/Niamey", "Africa/Lagos"}, |
+ {"Africa/Nouakchott", "Africa/Abidjan"}, |
+ {"Africa/Ouagadougou", "Africa/Abidjan"}, |
+ {"Africa/Porto-Novo", "Africa/Lagos"}, |
+ {"Africa/Sao_Tome", "Africa/Abidjan"}, |
+ {"America/Curacao", "America/Aruba"}, |
{"America/Dominica", "America/Anguilla"}, |
{"America/Grenada", "America/Anguilla"}, |
{"America/Guadeloupe", "America/Anguilla"}, |
+ {"America/Kralendijk", "America/Aruba"}, |
+ {"America/Lower_Princes", "America/Aruba"}, |
{"America/Marigot", "America/Anguilla"}, |
{"America/Montserrat", "America/Anguilla"}, |
{"America/Port_of_Spain", "America/Anguilla"}, |
+ {"America/Shiprock", "America/Denver"}, // America/Shiprock is defined as a Link to America/Denver in tzdata |
{"America/St_Barthelemy", "America/Anguilla"}, |
{"America/St_Kitts", "America/Anguilla"}, |
{"America/St_Lucia", "America/Anguilla"}, |
@@ -1971,26 +2018,24 @@ void TimeZoneTest::TestCanonicalID() { |
{"America/St_Vincent", "America/Anguilla"}, |
{"America/Tortola", "America/Anguilla"}, |
{"America/Virgin", "America/Anguilla"}, |
- {"America/Curacao", "America/Aruba"}, |
- {"America/Kralendijk", "America/Aruba"}, |
- {"America/Lower_Princes", "America/Aruba"}, |
{"Antarctica/South_Pole", "Antarctica/McMurdo"}, |
- {"Atlantic/Jan_Mayen", "Europe/Oslo"}, |
{"Arctic/Longyearbyen", "Europe/Oslo"}, |
+ {"Atlantic/Jan_Mayen", "Europe/Oslo"}, |
+ {"Atlantic/St_Helena", "Africa/Abidjan"}, |
+ {"Europe/Bratislava", "Europe/Prague"}, |
{"Europe/Busingen", "Europe/Zurich"}, |
{"Europe/Guernsey", "Europe/London"}, |
{"Europe/Isle_of_Man", "Europe/London"}, |
{"Europe/Jersey", "Europe/London"}, |
{"Europe/Ljubljana", "Europe/Belgrade"}, |
+ {"Europe/Mariehamn", "Europe/Helsinki"}, |
{"Europe/Podgorica", "Europe/Belgrade"}, |
+ {"Europe/San_Marino", "Europe/Rome"}, |
{"Europe/Sarajevo", "Europe/Belgrade"}, |
{"Europe/Skopje", "Europe/Belgrade"}, |
- {"Europe/Zagreb", "Europe/Belgrade"}, |
- {"Europe/Bratislava", "Europe/Prague"}, |
- {"Europe/Mariehamn", "Europe/Helsinki"}, |
- {"Europe/San_Marino", "Europe/Rome"}, |
- {"Europe/Vatican", "Europe/Rome"}, |
{"Europe/Vaduz", "Europe/Zurich"}, |
+ {"Europe/Vatican", "Europe/Rome"}, |
+ {"Europe/Zagreb", "Europe/Belgrade"}, |
{"Pacific/Auckland", "Antarctica/McMurdo"}, |
{"Pacific/Johnston", "Pacific/Honolulu"}, |
{0, 0} |
@@ -2241,7 +2286,8 @@ void TimeZoneTest::TestGetRegion() |
{"Europe/Helsinki", "FI"}, |
{"Europe/Mariehamn", "AX"}, // Link Europe/Helsinki, but in zone.tab |
{"Asia/Riyadh", "SA"}, |
- {"Asia/Riyadh87", "001"}, // this should be "SA" actually, but not in zone.tab |
+ // tz file solar87 was removed from tzdata2013i |
+ // {"Asia/Riyadh87", "001"}, // this should be "SA" actually, but not in zone.tab |
{"Etc/Unknown", 0}, // CLDR canonical, but not a sysmte zone ID |
{"bogus", 0}, // bogus |
{"GMT+08:00", 0}, // a custom ID, not a system zone ID |