]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/ccaltst.c
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ccaltst.c
index 36e1ea639bfce48cdd8b1cd35632ea6276487b5e..73457baae363d0b889fc91241f3e9c3d062b1b79 100644 (file)
@@ -1,5 +1,7 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
- * Copyright (c) 1997-2015, International Business Machines
+ * Copyright (c) 1997-2016, International Business Machines
  * Corporation and others. All Rights Reserved.
  ********************************************************************
  *
@@ -27,6 +29,7 @@
 #include "cintltst.h"
 #include "ccaltst.h"
 #include "cformtst.h"
+#include "cmemory.h"
 #include "cstring.h"
 #include "ulist.h"
 
@@ -89,6 +92,12 @@ static const UCalGetTypeTest ucalGetTypeTests[] = {
     { "th_TH",                   UCAL_DEFAULT,   "buddhist"  },
     { "th-TH-u-ca-gregory",      UCAL_DEFAULT,   "gregorian" },
     { "ja_JP@calendar=japanese", UCAL_GREGORIAN, "gregorian" },
+    { "fr_CH",                   UCAL_DEFAULT,   "gregorian" },
+    { "fr_SA",                   UCAL_DEFAULT,   "islamic-umalqura" },
+    { "fr_CH@rg=sazzzz",         UCAL_DEFAULT,   "islamic-umalqura" },
+    { "fr_CH@calendar=japanese;rg=sazzzz", UCAL_DEFAULT, "japanese" },
+    { "fr_TH@rg=SA",             UCAL_DEFAULT,   "buddhist"  }, /* ignore malformed rg tag */
+    { "th@rg=SA",                UCAL_DEFAULT,   "buddhist"  }, /* ignore malformed rg tag */
     { "",                        UCAL_GREGORIAN, "gregorian" },
     { NULL,                      UCAL_GREGORIAN, "gregorian" },
     { NULL, 0, NULL } /* terminator */
@@ -223,7 +232,7 @@ static void TestCalendar()
 
     /*Test ucal_set/getDefaultTimeZone*/
     status = U_ZERO_ERROR;
-    i = ucal_getDefaultTimeZone(zone1, sizeof(zone1)/sizeof(zone1[0]), &status);
+    i = ucal_getDefaultTimeZone(zone1, UPRV_LENGTHOF(zone1), &status);
     if (U_FAILURE(status)) {
         log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
                 u_errorName(status));
@@ -233,7 +242,7 @@ static void TestCalendar()
             log_err("FAIL: ucal_setDefaultTimeZone(Europe/Paris) => %s\n",
                     u_errorName(status));
         } else {
-            i = ucal_getDefaultTimeZone(zone2, sizeof(zone2)/sizeof(zone2[0]), &status);
+            i = ucal_getDefaultTimeZone(zone2, UPRV_LENGTHOF(zone2), &status);
             if (U_FAILURE(status)) {
                 log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
                         u_errorName(status));
@@ -252,7 +261,7 @@ static void TestCalendar()
     tzver = ucal_getTZDataVersion(&status);
     if (U_FAILURE(status)) {
         log_err_status(status, "FAIL: ucal_getTZDataVersion() => %s\n", 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*/) {
         log_err("FAIL: Bad version string was returned by ucal_getTZDataVersion\n");
     } else {
         log_verbose("PASS: ucal_getTZDataVersion returned %s\n", tzver);
@@ -261,7 +270,7 @@ static void TestCalendar()
     /*Testing ucal_getCanonicalTimeZoneID*/
     status = U_ZERO_ERROR;
     resultlength = ucal_getCanonicalTimeZoneID(PST, -1,
-        canonicalID, sizeof(canonicalID)/sizeof(UChar), &isSystemID, &status);
+        canonicalID, UPRV_LENGTHOF(canonicalID), &isSystemID, &status);
     if (U_FAILURE(status)) {
         log_data_err("FAIL: error in ucal_getCanonicalTimeZoneID : %s\n", u_errorName(status));
     } else {
@@ -594,7 +603,7 @@ static void TestGetSetDateAPI()
 
     /*testing ucal_setTimeZone() and ucal_getTimeZoneID function*/
     log_verbose("\nTesting if the function ucal_setTimeZone() and ucal_getTimeZoneID work fine\n");
-    idLen = ucal_getTimeZoneID(caldef2, id, sizeof(id)/sizeof(id[0]), &status);
+    idLen = ucal_getTimeZoneID(caldef2, id, UPRV_LENGTHOF(id), &status);
     (void)idLen;    /* Suppress set but not used warning. */
     if (U_FAILURE(status)) {
         log_err("Error in getTimeZoneID : %s\n", u_errorName(status));
@@ -618,7 +627,7 @@ static void TestGetSetDateAPI()
     else
         log_verbose("ucal_setTimeZone worked fine\n");
 
-    idLen = ucal_getTimeZoneID(caldef2, id, sizeof(id)/sizeof(id[0]), &status);
+    idLen = ucal_getTimeZoneID(caldef2, id, UPRV_LENGTHOF(id), &status);
     if (U_FAILURE(status)) {
         log_err("Error in getTimeZoneID : %s\n", u_errorName(status));
     } else if (u_strcmp(id, tzID) != 0) {
@@ -679,7 +688,7 @@ static void TestGetSetDateAPI()
 
     /*Testing  if setDate works fine  */
     log_verbose("\nTesting the ucal_setDate() function \n");
-    u_uastrcpy(temp, "Dec 17, 1971, 11:05:28 PM");
+    u_uastrcpy(temp, "Dec 17, 1971 at 11:05:28 PM");
     ucal_setDate(caldef,1971, UCAL_DECEMBER, 17, &status);
     if(U_FAILURE(status)){
         log_err("error in setting the calendar date : %s\n", u_errorName(status));
@@ -710,7 +719,7 @@ static void TestGetSetDateAPI()
 
     /*Testing if setDateTime works fine */
     log_verbose("\nTesting the ucal_setDateTime() function \n");
-    u_uastrcpy(temp, "May 3, 1972, 4:30:42 PM");
+    u_uastrcpy(temp, "May 3, 1972 at 4:30:42 PM");
     ucal_setDateTime(caldef,1972, UCAL_MAY, 3, 16, 30, 42, &status);
     if(U_FAILURE(status)){
         log_err("error in setting the calendar date : %s\n", u_errorName(status));
@@ -1550,7 +1559,7 @@ void TestGregorianChange() {
 }
 
 static void TestGetKeywordValuesForLocale() {
-#define PREFERRED_SIZE 15
+#define PREFERRED_SIZE 16
 #define MAX_NUMBER_OF_KEYWORDS 5
     const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = {
             { "root",        "gregorian", NULL, NULL, NULL, NULL },
@@ -1568,8 +1577,9 @@ static void TestGetKeywordValuesForLocale() {
             { "en@calendar=islamic",   "gregorian", NULL, NULL, NULL, NULL },
             { "zh_TW",       "gregorian", "roc", "chinese", NULL, NULL },
             { "ar_IR",       "persian", "gregorian", "islamic", "islamic-civil", "islamic-tbla" },
+            { "th@rg=SAZZZZ", "islamic-umalqura", "islamic-rgsa", "islamic", "gregorian", NULL },
     };
-    const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = { 1, 1, 1, 1, 2, 2, 2, 5, 5, 2, 2, 2, 1, 3, 5 };
+    const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = { 1, 1, 1, 1, 2, 2, 2, 5, 5, 2, 2, 2, 1, 3, 5, 4 };
     UErrorCode status = U_ZERO_ERROR;
     int32_t i, size, j;
     UEnumeration *all, *pref;
@@ -1691,8 +1701,8 @@ static const TestWeekendDates weekendDates_ar_OM[] = {
     { 2000, UCAL_MARCH, 18,  8,  0, 1 }, /* Sat 08:00        */
 };
 static const TestWeekendDatesList testDates[] = {
-    { "en_US", weekendDates_en_US, sizeof(weekendDates_en_US)/sizeof(weekendDates_en_US[0]) },
-    { "ar_OM", weekendDates_ar_OM, sizeof(weekendDates_ar_OM)/sizeof(weekendDates_ar_OM[0]) },
+    { "en_US", weekendDates_en_US, UPRV_LENGTHOF(weekendDates_en_US) },
+    { "ar_OM", weekendDates_ar_OM, UPRV_LENGTHOF(weekendDates_ar_OM) },
 };
 
 typedef struct {
@@ -1725,15 +1735,17 @@ static const TestDaysOfWeek daysOfWeek_hi_IN[] = { /* Sunday only */
     { UCAL_SUNDAY,   UCAL_WEEKEND,       0        },
 };
 static const TestDaysOfWeekList testDays[] = {
-    { "en_US", daysOfWeek_en_US, sizeof(daysOfWeek_en_US)/sizeof(daysOfWeek_en_US[0]) },
-    { "ar_OM", daysOfWeek_ar_OM, sizeof(daysOfWeek_ar_OM)/sizeof(daysOfWeek_ar_OM[0]) },
-    { "hi_IN", daysOfWeek_hi_IN, sizeof(daysOfWeek_hi_IN)/sizeof(daysOfWeek_hi_IN[0]) },
+    { "en_US", daysOfWeek_en_US, UPRV_LENGTHOF(daysOfWeek_en_US) },
+    { "ar_OM", daysOfWeek_ar_OM, UPRV_LENGTHOF(daysOfWeek_ar_OM) },
+    { "hi_IN", daysOfWeek_hi_IN, UPRV_LENGTHOF(daysOfWeek_hi_IN) },
+    { "en_US@rg=OMZZZZ", daysOfWeek_ar_OM, UPRV_LENGTHOF(daysOfWeek_ar_OM) },
+    { "hi@rg=USZZZZ",    daysOfWeek_en_US, UPRV_LENGTHOF(daysOfWeek_en_US) },
 };
 
 static const UChar logDateFormat[] = { 0x0045,0x0045,0x0045,0x0020,0x004D,0x004D,0x004D,0x0020,0x0064,0x0064,0x0020,0x0079,
                                        0x0079,0x0079,0x0079,0x0020,0x0047,0x0020,0x0048,0x0048,0x003A,0x006D,0x006D,0x003A,
                                        0x0073,0x0073,0x002E,0x0053,0x0053,0x0053,0 }; /* "EEE MMM dd yyyy G HH:mm:ss.SSS" */
-enum { kFormattedDateMax = 2*sizeof(logDateFormat)/sizeof(logDateFormat[0]) };
+enum { kFormattedDateMax = 2*UPRV_LENGTHOF(logDateFormat) };
 
 static void TestWeekend() {
     const TestWeekendDatesList * testDatesPtr = testDates;
@@ -1748,7 +1760,7 @@ static void TestWeekend() {
         log_data_err("Unable to create UDateFormat - %s\n", u_errorName(fmtStatus));
         return;
     }
-    for (count = sizeof(testDates)/sizeof(testDates[0]); count-- > 0; ++testDatesPtr) {
+    for (count = UPRV_LENGTHOF(testDates); count-- > 0; ++testDatesPtr) {
         UErrorCode status = U_ZERO_ERROR;
         UCalendar * cal = ucal_open(NULL, 0, testDatesPtr->locale, UCAL_GREGORIAN, &status);
         log_verbose("locale: %s\n", testDatesPtr->locale);
@@ -1792,7 +1804,7 @@ static void TestWeekend() {
         udat_close(fmt);
     }
 
-    for (count = sizeof(testDays)/sizeof(testDays[0]); count-- > 0; ++testDaysPtr) {
+    for (count = UPRV_LENGTHOF(testDays); count-- > 0; ++testDaysPtr) {
         UErrorCode status = U_ZERO_ERROR;
         UCalendar * cal = ucal_open(NULL, 0, testDaysPtr->locale, UCAL_GREGORIAN, &status);
         log_verbose("locale: %s\n", testDaysPtr->locale);
@@ -2376,7 +2388,7 @@ void TestGetWindowsTimeZoneID() {
 
     {
         status = U_ZERO_ERROR;
-        len = ucal_getWindowsTimeZoneID(tzNewYork, u_strlen(tzNewYork), winID, sizeof(winID)/sizeof(winID[0]), &status);
+        len = ucal_getWindowsTimeZoneID(tzNewYork, u_strlen(tzNewYork), winID, UPRV_LENGTHOF(winID), &status);
         if (U_FAILURE(status)) {
             log_data_err("FAIL: Windows ID for America/New_York, status %s\n", u_errorName(status)); 
         } else if (len != u_strlen(winEastern) || u_strncmp(winID, winEastern, len) != 0) {
@@ -2385,7 +2397,7 @@ void TestGetWindowsTimeZoneID() {
     }
     {
         status = U_ZERO_ERROR;
-        len = ucal_getWindowsTimeZoneID(tzTronto, u_strlen(tzTronto), winID, sizeof(winID)/sizeof(winID[0]), &status);
+        len = ucal_getWindowsTimeZoneID(tzTronto, u_strlen(tzTronto), winID, UPRV_LENGTHOF(winID), &status);
         if (U_FAILURE(status)) {
             log_data_err("FAIL: Windows ID for America/Toronto, status %s\n", u_errorName(status)); 
         } else if (len != u_strlen(winEastern) || u_strncmp(winID, winEastern, len) != 0) {
@@ -2394,7 +2406,7 @@ void TestGetWindowsTimeZoneID() {
     }
     {
         status = U_ZERO_ERROR;
-        len = ucal_getWindowsTimeZoneID(sBogus, u_strlen(sBogus), winID, sizeof(winID)/sizeof(winID[0]), &status);
+        len = ucal_getWindowsTimeZoneID(sBogus, u_strlen(sBogus), winID, UPRV_LENGTHOF(winID), &status);
         if (U_FAILURE(status)) {
             log_data_err("FAIL: Windows ID for Bogus, status %s\n", u_errorName(status)); 
         } else if (len != 0) {
@@ -2410,7 +2422,7 @@ void TestGetTimeZoneIDByWindowsID() {
 
     {
         status = U_ZERO_ERROR;
-        len = ucal_getTimeZoneIDForWindowsID(winEastern, -1, NULL, tzID, sizeof(tzID)/sizeof(tzID[0]), &status);
+        len = ucal_getTimeZoneIDForWindowsID(winEastern, -1, NULL, tzID, UPRV_LENGTHOF(tzID), &status);
         if (U_FAILURE(status)) {
             log_data_err("FAIL: TZ ID for Eastern Standard Time, status %s\n", u_errorName(status)); 
         } else if (len != u_strlen(tzNewYork) || u_strncmp(tzID, tzNewYork, len) != 0) {
@@ -2419,7 +2431,7 @@ void TestGetTimeZoneIDByWindowsID() {
     }
     {
         status = U_ZERO_ERROR;
-        len = ucal_getTimeZoneIDForWindowsID(winEastern, u_strlen(winEastern), "US", tzID, sizeof(tzID)/sizeof(tzID[0]), &status);
+        len = ucal_getTimeZoneIDForWindowsID(winEastern, u_strlen(winEastern), "US", tzID, UPRV_LENGTHOF(tzID), &status);
         if (U_FAILURE(status)) {
             log_data_err("FAIL: TZ ID for Eastern Standard Time - US, status %s\n", u_errorName(status)); 
         } else if (len != u_strlen(tzNewYork) || u_strncmp(tzID, tzNewYork, len) != 0) {
@@ -2428,7 +2440,7 @@ void TestGetTimeZoneIDByWindowsID() {
     }
     {
         status = U_ZERO_ERROR;
-        len = ucal_getTimeZoneIDForWindowsID(winEastern, u_strlen(winEastern), "CA", tzID, sizeof(tzID)/sizeof(tzID[0]), &status);
+        len = ucal_getTimeZoneIDForWindowsID(winEastern, u_strlen(winEastern), "CA", tzID, UPRV_LENGTHOF(tzID), &status);
         if (U_FAILURE(status)) {
             log_data_err("FAIL: TZ ID for Eastern Standard Time - CA, status %s\n", u_errorName(status)); 
         } else if (len != u_strlen(tzTronto) || u_strncmp(tzID, tzTronto, len) != 0) {
@@ -2438,7 +2450,7 @@ void TestGetTimeZoneIDByWindowsID() {
 
     {
         status = U_ZERO_ERROR;
-        len = ucal_getTimeZoneIDForWindowsID(sBogus, -1, NULL, tzID, sizeof(tzID)/sizeof(tzID[0]), &status);
+        len = ucal_getTimeZoneIDForWindowsID(sBogus, -1, NULL, tzID, UPRV_LENGTHOF(tzID), &status);
         if (U_FAILURE(status)) {
             log_data_err("FAIL: TZ ID for Bogus, status %s\n", u_errorName(status)); 
         } else if (len != 0) {
@@ -2491,6 +2503,7 @@ void TestClear() {
             } else if (date != calAndClearDatesPtr->clearDate) {
                 log_err("FAIL: ucal_clear, ucal_getMillis for locale %s, expected %.1f, got %.1f\n", calAndClearDatesPtr->localeWithCal, calAndClearDatesPtr->clearDate, date); 
             }
+            ucal_close(ucal);
         }
     }
 }