]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/tztest.cpp
ICU-64252.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / tztest.cpp
index 696957253fe8e658540220f7e2d7f005450731ab..c531395871041a026e62263a37ae7b1242cefe84 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /***********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2015, International Business Machines Corporation
+ * Copyright (c) 1997-2016, International Business Machines Corporation
  * and others. All Rights Reserved.
  ***********************************************************************/
 
@@ -21,8 +23,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) {                        \
@@ -72,6 +72,7 @@ void TimeZoneTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
     TESTCASE_AUTO(TestGetRegion);
     TESTCASE_AUTO(TestGetAvailableIDsNew);
     TESTCASE_AUTO(TestGetUnknown);
+    TESTCASE_AUTO(TestGetGMT);
     TESTCASE_AUTO(TestGetWindowsID);
     TESTCASE_AUTO(TestGetIDForWindowsID);
     TESTCASE_AUTO_END;
@@ -137,11 +138,21 @@ TimeZoneTest::TestGenericAPI()
         infoln("WARNING: t_timezone may be incorrect. It is not a multiple of 15min.", tzoffset);
     }
 
+    TimeZone* hostZone = TimeZone::detectHostTimeZone();
+    int32_t hostZoneRawOffset = hostZone->getRawOffset();
+    logln("hostZone->getRawOffset() = %d , tzoffset = %d", hostZoneRawOffset, tzoffset * (-1000));
+
+    /* Host time zone's offset should match the offset returned by uprv_timezone() */
+    if (hostZoneRawOffset != tzoffset * (-1000)) {
+        errln("FAIL: detectHostTimeZone()'s raw offset != host timezone's offset");
+    }
+    delete hostZone;
+
     UErrorCode status = U_ZERO_ERROR;
     const char* tzver = TimeZone::getTZDataVersion(status);
     if (U_FAILURE(status)) {
         errcheckln(status, "FAIL: getTZDataVersion failed - %s", u_errorName(status));
-    } else if (uprv_strlen(tzver) != 5 /* 4 digits + 1 letter */) {
+    } else if (uprv_strlen(tzver) < 5 || uprv_strlen(tzver) > 7 /*4 digits + 1-3 letters*/) {
         errln((UnicodeString)"FAIL: getTZDataVersion returned " + tzver);
     } else {
         logln((UnicodeString)"tzdata version: " + tzver);
@@ -856,7 +867,7 @@ void TimeZoneTest::TestShortZoneIDs()
         {"ECT", 60, TRUE},    // ICU Link - Europe/Paris
         {"MET", 60, TRUE},    // Olson europe 1:00 C-Eur
         {"CAT", 120, FALSE},  // ICU Link - Africa/Maputo
-        {"ART", 120, TRUE},   // ICU Link - Africa/Cairo
+        {"ART", 120, FALSE},  // 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
@@ -1198,31 +1209,43 @@ TimeZoneTest::TestAliasedNames()
         /* Generated by org.unicode.cldr.tool.CountItems */
 
         /* zoneID, canonical zoneID */
-        {"Africa/Timbuktu", "Africa/Bamako"},
+        {"Africa/Asmara", "Africa/Addis_Ababa"},
+        {"Africa/Timbuktu", "Africa/Abidjan"},
         {"America/Argentina/Buenos_Aires", "America/Buenos_Aires"},
         {"America/Argentina/Catamarca", "America/Catamarca"},
         {"America/Argentina/ComodRivadavia", "America/Catamarca"},
         {"America/Argentina/Cordoba", "America/Cordoba"},
         {"America/Argentina/Jujuy", "America/Jujuy"},
         {"America/Argentina/Mendoza", "America/Mendoza"},
+        {"America/Atikokan", "America/Coral_Harbour"},
         {"America/Atka", "America/Adak"},
         {"America/Ensenada", "America/Tijuana"},
-        {"America/Fort_Wayne", "America/Indiana/Indianapolis"},
-        {"America/Indianapolis", "America/Indiana/Indianapolis"},
+        {"America/Fort_Wayne", "America/Indianapolis"},
+        {"America/Indiana/Indianapolis", "America/Indianapolis"},
+        {"America/Kentucky/Louisville", "America/Louisville"},
         {"America/Knox_IN", "America/Indiana/Knox"},
-        {"America/Louisville", "America/Kentucky/Louisville"},
         {"America/Porto_Acre", "America/Rio_Branco"},
         {"America/Rosario", "America/Cordoba"},
-        {"America/Virgin", "America/St_Thomas"},
+        {"America/Shiprock", "America/Denver"},
+        {"America/Virgin", "America/Anguilla"},
+        {"Antarctica/South_Pole", "Antarctica/McMurdo"},
         {"Asia/Ashkhabad", "Asia/Ashgabat"},
-        {"Asia/Chungking", "Asia/Chongqing"},
+        {"Asia/Chongqing", "Asia/Shanghai"},
+        {"Asia/Chungking", "Asia/Shanghai"},
         {"Asia/Dacca", "Asia/Dhaka"},
+        {"Asia/Harbin", "Asia/Shanghai"},
+        {"Asia/Ho_Chi_Minh", "Asia/Saigon"},
         {"Asia/Istanbul", "Europe/Istanbul"},
+        {"Asia/Kashgar", "Asia/Urumqi"},
+        {"Asia/Kathmandu", "Asia/Katmandu"},
+        {"Asia/Kolkata", "Asia/Calcutta"},
         {"Asia/Macao", "Asia/Macau"},
         {"Asia/Tel_Aviv", "Asia/Jerusalem"},
         {"Asia/Thimbu", "Asia/Thimphu"},
         {"Asia/Ujung_Pandang", "Asia/Makassar"},
         {"Asia/Ulan_Bator", "Asia/Ulaanbaatar"},
+        {"Atlantic/Faroe", "Atlantic/Faeroe"},
+        {"Atlantic/Jan_Mayen", "Arctic/Longyearbyen"},
         {"Australia/ACT", "Australia/Sydney"},
         {"Australia/Canberra", "Australia/Sydney"},
         {"Australia/LHI", "Australia/Lord_Howe"},
@@ -1250,16 +1273,16 @@ TimeZoneTest::TestAliasedNames()
         {"Chile/Continental", "America/Santiago"},
         {"Chile/EasterIsland", "Pacific/Easter"},
         {"Cuba", "America/Havana"},
+        {"EST", "Etc/GMT+5"},
         {"Egypt", "Africa/Cairo"},
         {"Eire", "Europe/Dublin"},
         {"Etc/GMT+0", "Etc/GMT"},
         {"Etc/GMT-0", "Etc/GMT"},
         {"Etc/GMT0", "Etc/GMT"},
         {"Etc/Greenwich", "Etc/GMT"},
-        {"Etc/UCT", "Etc/GMT"},
-        {"Etc/UTC", "Etc/GMT"},
-        {"Etc/Universal", "Etc/GMT"},
-        {"Etc/Zulu", "Etc/GMT"},
+        {"Etc/UCT", "Etc/UTC"},
+        {"Etc/Universal", "Etc/UTC"},
+        {"Etc/Zulu", "Etc/UTC"},
         {"Europe/Belfast", "Europe/London"},
         {"Europe/Nicosia", "Asia/Nicosia"},
         {"Europe/Tiraspol", "Europe/Chisinau"},
@@ -1270,6 +1293,7 @@ TimeZoneTest::TestAliasedNames()
         {"GMT-0", "Etc/GMT"},
         {"GMT0", "Etc/GMT"},
         {"Greenwich", "Etc/GMT"},
+        {"HST", "Etc/GMT+10"},
         {"Hongkong", "Asia/Hong_Kong"},
         {"Iceland", "Atlantic/Reykjavik"},
         {"Iran", "Asia/Tehran"},
@@ -1278,27 +1302,37 @@ TimeZoneTest::TestAliasedNames()
         {"Japan", "Asia/Tokyo"},
         {"Kwajalein", "Pacific/Kwajalein"},
         {"Libya", "Africa/Tripoli"},
+        {"MST", "Etc/GMT+7"},
         {"Mexico/BajaNorte", "America/Tijuana"},
         {"Mexico/BajaSur", "America/Mazatlan"},
         {"Mexico/General", "America/Mexico_City"},
-        {"NZ", "Pacific/Auckland"},
+        {"NZ", "Antarctica/McMurdo"},
         {"NZ-CHAT", "Pacific/Chatham"},
-        {"Navajo", "America/Shiprock"},
+        {"Navajo", "America/Denver"},
         {"PRC", "Asia/Shanghai"},
-        {"Pacific/Samoa", "Pacific/Pago_Pago"},
+        {"Pacific/Chuuk", "Pacific/Truk"},
+        {"Pacific/Pohnpei", "Pacific/Ponape"},
+        {"Pacific/Samoa", "Pacific/Midway"},
         {"Pacific/Yap", "Pacific/Truk"},
         {"Poland", "Europe/Warsaw"},
         {"Portugal", "Europe/Lisbon"},
         {"ROC", "Asia/Taipei"},
         {"ROK", "Asia/Seoul"},
         {"Singapore", "Asia/Singapore"},
+        {"SystemV/AST4", "Etc/GMT+4"},
+        {"SystemV/CST6", "Etc/GMT+6"},
+        {"SystemV/EST5", "Etc/GMT+5"},
+        {"SystemV/HST10", "Etc/GMT+10"},
+        {"SystemV/MST7", "Etc/GMT+7"},
+        {"SystemV/PST8", "Etc/GMT+8"},
+        {"SystemV/YST9", "Etc/GMT+9"},
         {"Turkey", "Europe/Istanbul"},
-        {"UCT", "Etc/GMT"},
+        {"UCT", "Etc/UTC"},
         {"US/Alaska", "America/Anchorage"},
         {"US/Aleutian", "America/Adak"},
         {"US/Arizona", "America/Phoenix"},
         {"US/Central", "America/Chicago"},
-        {"US/East-Indiana", "America/Indiana/Indianapolis"},
+        {"US/East-Indiana", "America/Indianapolis"},
         {"US/Eastern", "America/New_York"},
         {"US/Hawaii", "Pacific/Honolulu"},
         {"US/Indiana-Starke", "America/Indiana/Knox"},
@@ -1306,13 +1340,12 @@ TimeZoneTest::TestAliasedNames()
         {"US/Mountain", "America/Denver"},
         {"US/Pacific", "America/Los_Angeles"},
         {"US/Pacific-New", "America/Los_Angeles"},
-        {"US/Samoa", "Pacific/Pago_Pago"},
-        {"UTC", "Etc/GMT"},
-        {"Universal", "Etc/GMT"},
+        {"US/Samoa", "Pacific/Midway"},
+        {"UTC", "Etc/UTC"},
+        {"Universal", "Etc/UTC"},
         {"W-SU", "Europe/Moscow"},
-        {"Zulu", "Etc/GMT"},
-        /* Total: 113 */
-
+        {"Zulu", "Etc/UTC"},
+        /* Total: 136 */
     };
 
     TimeZone::EDisplayType styles[] = { TimeZone::SHORT, TimeZone::LONG };
@@ -1322,7 +1355,7 @@ TimeZoneTest::TestAliasedNames()
     int32_t i, j, k, loc;
     UnicodeString fromName, toName;
     TimeZone *from = NULL, *to = NULL;
-    for(i = 0; i < (int32_t)(sizeof(kData)/sizeof(kData[0])); i++) {
+    for(i = 0; i < UPRV_LENGTHOF(kData); i++) {
         from = TimeZone::createTimeZone(kData[i].from);
         to = TimeZone::createTimeZone(kData[i].to);
         if(!from->hasSameRules(*to)) {
@@ -1331,8 +1364,8 @@ TimeZoneTest::TestAliasedNames()
         if(!quick) {
             for(loc = 0; loc < noLoc; loc++) {
                 const char* locale = uloc_getAvailable(loc); 
-                for(j = 0; j < (int32_t)(sizeof(styles)/sizeof(styles[0])); j++) {
-                    for(k = 0; k < (int32_t)(sizeof(useDst)/sizeof(useDst[0])); k++) {
+                for(j = 0; j < UPRV_LENGTHOF(styles); j++) {
+                    for(k = 0; k < UPRV_LENGTHOF(useDst); k++) {
                         fromName.remove();
                         toName.remove();
                         from->getDisplayName(useDst[k], styles[j],locale, fromName);
@@ -1907,9 +1940,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);
@@ -1947,14 +1980,14 @@ void TimeZoneTest::TestCanonicalIDAPI() {
     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);
+    assertEquals("TimeZone::getCanonicalID(bogus) should fail", (int32_t)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);
+    assertEquals("TimeZone::getCanonicalID(failure) should fail", (int32_t)U_MEMORY_ALLOCATION_ERROR, ec);
     assertTrue("TimeZone::getCanonicalID(failure) should return the dest string", pResult == &canonicalID);
 
     // Valid input should un-bogus the dest string.
@@ -2009,23 +2042,27 @@ void TimeZoneTest::TestCanonicalID() {
         {"Africa/Ouagadougou", "Africa/Abidjan"},
         {"Africa/Porto-Novo", "Africa/Lagos"},
         {"Africa/Sao_Tome", "Africa/Abidjan"},
+        {"America/Antigua", "America/Port_of_Spain"},
+        {"America/Anguilla", "America/Port_of_Spain"},
         {"America/Curacao", "America/Aruba"},
-        {"America/Dominica", "America/Anguilla"},
-        {"America/Grenada", "America/Anguilla"},
-        {"America/Guadeloupe", "America/Anguilla"},
+        {"America/Dominica", "America/Port_of_Spain"},
+        {"America/Grenada", "America/Port_of_Spain"},
+        {"America/Guadeloupe", "America/Port_of_Spain"},
         {"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"},
-        {"America/St_Thomas", "America/Anguilla"},
-        {"America/St_Vincent", "America/Anguilla"},
-        {"America/Tortola", "America/Anguilla"},
-        {"America/Virgin", "America/Anguilla"},
+        {"America/Marigot", "America/Port_of_Spain"},
+        {"America/Montserrat", "America/Port_of_Spain"},
+        {"America/Panama", "America/Cayman"},
+        {"America/Santa_Isabel", "America/Tijuana"},
+        {"America/Shiprock", "America/Denver"},
+        {"America/St_Barthelemy", "America/Port_of_Spain"},
+        {"America/St_Kitts", "America/Port_of_Spain"},
+        {"America/St_Lucia", "America/Port_of_Spain"},
+        {"America/St_Thomas", "America/Port_of_Spain"},
+        {"America/St_Vincent", "America/Port_of_Spain"},
+        {"America/Toronto", "America/Montreal"},
+        {"America/Tortola", "America/Port_of_Spain"},
+        {"America/Virgin", "America/Port_of_Spain"},
         {"Antarctica/South_Pole", "Antarctica/McMurdo"},
         {"Arctic/Longyearbyen", "Europe/Oslo"},
         {"Asia/Kuwait", "Asia/Aden"},
@@ -2055,6 +2092,8 @@ void TimeZoneTest::TestCanonicalID() {
         {"Indian/Mayotte", "Africa/Nairobi"},
         {"Pacific/Auckland", "Antarctica/McMurdo"},
         {"Pacific/Johnston", "Pacific/Honolulu"},
+        {"Pacific/Midway", "Pacific/Pago_Pago"},
+        {"Pacific/Saipan", "Pacific/Guam"},
         {0, 0}
     };
 
@@ -2382,6 +2421,15 @@ void TimeZoneTest::TestGetUnknown() {
     assertFalse("getUnknown() uses DST", unknown.useDaylightTime());
 }
 
+void TimeZoneTest::TestGetGMT() {
+    const TimeZone *gmt = TimeZone::getGMT();
+    UnicodeString expectedID = UNICODE_STRING_SIMPLE("GMT");
+    UnicodeString id;
+    assertEquals("getGMT() wrong ID", expectedID, gmt->getID(id));
+    assertTrue("getGMT() wrong offset", 0 == gmt->getRawOffset());
+    assertFalse("getGMT() uses DST", gmt->useDaylightTime());
+}
+
 void TimeZoneTest::TestGetWindowsID(void) {
     static const struct {
         const char *id;
@@ -2396,7 +2444,7 @@ void TimeZoneTest::TestGetWindowsID(void) {
         {"America/Indianapolis",    "US Eastern Standard Time"},            // CLDR canonical name
         {"America/Indiana/Indianapolis",    "US Eastern Standard Time"},    // tzdb canonical name
         {"Asia/Khandyga",           "Yakutsk Standard Time"},
-        {"Australia/Eucla",         ""}, // No Windows ID mapping
+        {"Australia/Eucla",         "Aus Central W. Standard Time"}, // formerly no Windows ID mapping, now has one
         {"Bogus",                   ""},
         {0,                         0},
     };