]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/ccaltst.c
ICU-8.11.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ccaltst.c
index 0c67b1c0916cec50ccbcc27191137f2cbabf0e19..08a81699e387116d3b63d94dce5bc9daa85feb27 100644 (file)
@@ -1,16 +1,16 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2003, International Business Machines Corporation and
+ * Copyright (c) 1997-2006, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
-/********************************************************************************
+/******************************************************************************
 *
 * File CCALTST.C
 *
 * Modification History:
 *        Name                     Description            
 *     Madhu Katragadda               Creation
-*********************************************************************************/
+*******************************************************************************/
 
 /* C API AND FUNCTIONALITY TEST FOR CALENDAR (ucol.h)*/
 
@@ -28,6 +28,8 @@
 #include "ccaltst.h"
 #include "cformtst.h"
 
+void TestGregorianChange(void);
+
 void addCalTest(TestNode** root);
 
 void addCalTest(TestNode** root)
@@ -40,7 +42,7 @@ void addCalTest(TestNode** root)
     addTest(root, &TestGetLimits, "tsformat/ccaltst/TestGetLimits");
     addTest(root, &TestDOWProgression, "tsformat/ccaltst/TestDOWProgression");
     addTest(root, &TestGMTvsLocal, "tsformat/ccaltst/TestGMTvsLocal");
-
+    addTest(root, &TestGregorianChange, "tsformat/ccaltst/TestGregorianChange");
 }
 
 /* "GMT" */
@@ -55,7 +57,7 @@ static void TestCalendar()
 {
     UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0;
     UEnumeration* uenum = NULL;
-    int32_t count, count2, offset,i,j;
+    int32_t count, count2, i,j;
     UChar *tzID = 0;
     UChar *tzdname = 0;
     UErrorCode status = U_ZERO_ERROR;
@@ -66,8 +68,9 @@ static void TestCalendar()
     char tempMsgBuf[256];
     UChar zone1[32], zone2[32];
 
+#ifdef U_USE_UCAL_OBSOLETE_2_8
     /*Testing countAvailableTimeZones*/
-    offset=0;
+    int32_t offset=0;
     log_verbose("\nTesting ucal_countAvailableTZIDs\n");
     count=ucal_countAvailableTZIDs(offset);
     log_verbose("The number of timezone id's present with offset 0 are %d:\n", count);
@@ -89,6 +92,7 @@ static void TestCalendar()
         log_err("FAIL:for TZID index >= count Expected INDEX_OUTOFBOUNDS_ERROR Got %s\n", u_errorName(status));
     }
     status=U_ZERO_ERROR;
+#endif
     
     /*Test ucal_openTimeZones & ucal_openCountryTimeZones*/
     for (j=0; j<2; ++j) {
@@ -415,7 +419,8 @@ static void TestGetSetDateAPI()
     
     
     
-    
+    ctest_setTimeZone(NULL, &status);
+
     /*testing ucal_setTimeZone() function*/
     log_verbose("\nTesting if the function ucal_setTimeZone() works fine\n");
     ucal_setMillis(caldef2, d2, &status); 
@@ -474,6 +479,9 @@ static void TestGetSetDateAPI()
     else if (zoneOffset != -28800000) {
         log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset);
     }
+
+    ctest_resetTimeZone();
+
 /*----------------------------*     */
     
     
@@ -789,6 +797,7 @@ static void TestAddRollExtensive()
         return;
     }
     status=U_ZERO_ERROR;
+    ucal_clear(cal);
     ucal_setDateTime(cal, 1999, UCAL_FEBRUARY, 28, 10, 30, 45,  &status);
     if(U_FAILURE(status)){
         log_err("error is setting the datetime: %s\n", u_errorName(status));
@@ -887,7 +896,7 @@ static void TestGetLimits()
     val = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
     min = ucal_getLimit(cal, UCAL_DAY_OF_WEEK, UCAL_MINIMUM, &status);
     max = ucal_getLimit(cal, UCAL_DAY_OF_WEEK, UCAL_MAXIMUM, &status);
-    if ( (min != UCAL_SUNDAY || max != UCAL_SATURDAY ) && (min > val > max)  && (val != UCAL_FRIDAY)){
+    if ( (min != UCAL_SUNDAY || max != UCAL_SATURDAY ) && (min > val && val > max)  && (val != UCAL_FRIDAY)){
            log_err("FAIL: Min/max bad\n");
            log_err("FAIL: Day of week %d out of range\n", val);
            log_err("FAIL: FAIL: Day of week should be SUNDAY Got %d\n", val);
@@ -898,7 +907,7 @@ static void TestGetLimits()
     val = ucal_get(cal, UCAL_DAY_OF_WEEK_IN_MONTH, &status);
     min = ucal_getLimit(cal, UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_MINIMUM, &status);
     max = ucal_getLimit(cal, UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_MAXIMUM, &status);
-    if ( (min != 0 || max != 5 ) && (min > val > max)  && (val != 1)){
+    if ( (min != 0 || max != 5 ) && (min > val && val > max)  && (val != 1)){
            log_err("FAIL: Min/max bad\n");
            log_err("FAIL: Day of week in month %d out of range\n", val);
            log_err("FAIL: FAIL: Day of week in month should be SUNDAY Got %d\n", val);
@@ -930,7 +939,7 @@ static void TestGetLimits()
     ac_min=ucal_getLimit(cal, UCAL_MINUTE, UCAL_ACTUAL_MINIMUM, &status);
     ac_max=ucal_getLimit(cal, UCAL_SECOND, UCAL_ACTUAL_MAXIMUM, &status);
     if( (min!=0 || max!= 11 || gr_min!=0 || le_max!=60 || ac_min!=0 || ac_max!=60) &&
-        (min>val>max) && val!=4){
+        (min>val && val>max) && val!=4){
                 
         log_err("FAIL: Min/max bad\n");
         log_err("FAIL: Hour of Day %d out of range\n", val);
@@ -1266,4 +1275,50 @@ static void verify2(const char* msg, UCalendar* c, UDateFormat* dat, int32_t yea
         
 }
 
+void TestGregorianChange() {
+    static const UChar utc[] = { 0x45, 0x74, 0x63, 0x2f, 0x47, 0x4d, 0x54, 0 }; /* "Etc/GMT" */
+    const int32_t dayMillis = 86400 * INT64_C(1000);    /* 1 day = 86400 seconds */
+    UCalendar *cal;
+    UDate date;
+    UErrorCode errorCode = U_ZERO_ERROR;
+
+    /* Test ucal_setGregorianChange() on a Gregorian calendar. */
+    errorCode = U_ZERO_ERROR;
+    cal = ucal_open(utc, -1, "", UCAL_GREGORIAN, &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("ucal_open(UTC) failed: %s\n", u_errorName(errorCode));
+        return;
+    }
+    ucal_setGregorianChange(cal, -365 * (dayMillis * (UDate)1), &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("ucal_setGregorianChange(1969) failed: %s\n", u_errorName(errorCode));
+    } else {
+        date = ucal_getGregorianChange(cal, &errorCode);
+        if(U_FAILURE(errorCode) || date != -365 * (dayMillis * (UDate)1)) {
+            log_err("ucal_getGregorianChange() failed: %s, date = %f\n", u_errorName(errorCode), date);
+        }
+    }
+    ucal_close(cal);
+
+    /* Test ucal_setGregorianChange() on a non-Gregorian calendar where it should fail. */
+    errorCode = U_ZERO_ERROR;
+    cal = ucal_open(utc, -1, "th@calendar=buddhist", UCAL_TRADITIONAL, &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("ucal_open(UTC, non-Gregorian) failed: %s\n", u_errorName(errorCode));
+        return;
+    }
+    ucal_setGregorianChange(cal, -730 * (dayMillis * (UDate)1), &errorCode);
+    if(errorCode != U_UNSUPPORTED_ERROR) {
+        log_err("ucal_setGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
+                u_errorName(errorCode));
+    }
+    errorCode = U_ZERO_ERROR;
+    date = ucal_getGregorianChange(cal, &errorCode);
+    if(errorCode != U_UNSUPPORTED_ERROR) {
+        log_err("ucal_getGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
+                u_errorName(errorCode));
+    }
+    ucal_close(cal);
+}
+
 #endif /* #if !UCONFIG_NO_FORMATTING */