]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/ccaltst.c
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ccaltst.c
index e0a3e70658c18d213a5c9b2dcc6f295877fa8997..7f7f0aa833556c11966246a14bb4dccec7ee9620 100644 (file)
@@ -1,16 +1,15 @@
 /********************************************************************
- * COPYRIGHT: 
- * Copyright (c) 1997-2003, International Business Machines Corporation and
- * others. All Rights Reserved.
- ********************************************************************/
-/********************************************************************************
-*
-* File CCALTST.C
-*
-* Modification History:
-*        Name                     Description            
-*     Madhu Katragadda               Creation
-*********************************************************************************/
+ * Copyright (c) 1997-2012, 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)*/
 
@@ -19,6 +18,7 @@
 #if !UCONFIG_NO_FORMATTING
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "unicode/uloc.h"
 #include "unicode/ucal.h"
 #include "cintltst.h"
 #include "ccaltst.h"
 #include "cformtst.h"
+#include "cstring.h"
+#include "ulist.h"
+
+void TestGregorianChange(void);
+void TestFieldDifference(void);
 
 void addCalTest(TestNode** root);
 
@@ -40,7 +45,11 @@ 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");
+    addTest(root, &TestGetKeywordValuesForLocale, "tsformat/ccaltst/TestGetKeywordValuesForLocale");
+    addTest(root, &TestWeekend, "tsformat/ccaltst/TestWeekend");
+    addTest(root, &TestFieldDifference, "tsformat/ccaltst/TestFieldDifference");
+    addTest(root, &TestAmbiguousWallTime, "tsformat/ccaltst/TestAmbiguousWallTime");
 }
 
 /* "GMT" */
@@ -51,12 +60,33 @@ static const UChar PST[] = {0x50, 0x53, 0x54, 0x00}; /* "PST" */
 
 static const UChar EUROPE_PARIS[] = {0x45, 0x75, 0x72, 0x6F, 0x70, 0x65, 0x2F, 0x50, 0x61, 0x72, 0x69, 0x73, 0x00}; /* "Europe/Paris" */
 
+static const UChar AMERICA_LOS_ANGELES[] = {0x41, 0x6D, 0x65, 0x72, 0x69, 0x63, 0x61, 0x2F,
+    0x4C, 0x6F, 0x73, 0x5F, 0x41, 0x6E, 0x67, 0x65, 0x6C, 0x65, 0x73, 0x00}; /* America/Los_Angeles */
+
+typedef struct {
+    const char *    locale;
+    UCalendarType   calType;
+    const char *    expectedResult;
+} UCalGetTypeTest;
+
+static const UCalGetTypeTest ucalGetTypeTests[] = {
+    { "en_US",                   UCAL_GREGORIAN, "gregorian" },
+    { "ja_JP@calendar=japanese", UCAL_DEFAULT,   "japanese"  },
+    { "th_TH",                   UCAL_GREGORIAN, "gregorian" },
+    { "th_TH",                   UCAL_DEFAULT,   "buddhist"  },
+    { "th-TH-u-ca-gregory",      UCAL_DEFAULT,   "gregorian" },
+    { "ja_JP@calendar=japanese", UCAL_GREGORIAN, "gregorian" },
+    { "",                        UCAL_GREGORIAN, "gregorian" },
+    { NULL,                      UCAL_GREGORIAN, "gregorian" },
+    { NULL, 0, NULL } /* terminator */
+};    
+    
 static void TestCalendar()
 {
-    UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0;
+    UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0, *calfrclone = 0;
     UEnumeration* uenum = NULL;
     int32_t count, count2, i,j;
-    UChar *tzID = 0;
+    UChar tzID[4];
     UChar *tzdname = 0;
     UErrorCode status = U_ZERO_ERROR;
     UDate now;
@@ -65,6 +95,10 @@ static void TestCalendar()
     int32_t resultlength, resultlengthneeded;
     char tempMsgBuf[256];
     UChar zone1[32], zone2[32];
+    const char *tzver = 0;
+    UChar canonicalID[64];
+    UBool isSystemID = FALSE;
+    const UCalGetTypeTest * ucalGetTypeTestPtr;
 
 #ifdef U_USE_UCAL_OBSOLETE_2_8
     /*Testing countAvailableTimeZones*/
@@ -92,14 +126,38 @@ static void TestCalendar()
     status=U_ZERO_ERROR;
 #endif
     
-    /*Test ucal_openTimeZones & ucal_openCountryTimeZones*/
-    for (j=0; j<2; ++j) {
-        const char* api = (j==0) ? "ucal_openTimeZones()" :
-            "ucal_openCountryTimeZones(US)";
-        uenum = (j==0) ? ucal_openTimeZones(&status) :
-            ucal_openCountryTimeZones("US", &status);
+    /*Test ucal_openTimeZones, ucal_openCountryTimeZones and ucal_openTimeZoneIDEnumeration */
+    for (j=0; j<6; ++j) {
+        const char *api = "?";
+        const int32_t offsetMinus5 = -5*60*60*1000;
+        switch (j) {
+        case 0:
+            api = "ucal_openTimeZones()";
+            uenum = ucal_openTimeZones(&status);
+            break;
+        case 1:
+            api = "ucal_openCountryTimeZones(US)";
+            uenum = ucal_openCountryTimeZones("US", &status);
+            break;
+        case 2:
+            api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL)";
+            uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, &status);
+            break;
+        case 3:
+            api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_CANONICAL_LOCATION, CA, NULL)";
+            uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION, "CA", NULL, &status);
+            break;
+        case 4:
+            api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_ANY, NULL, -5 hour)";
+            uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, NULL, &offsetMinus5, &status);
+            break;
+        case 5:
+            api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_ANY, US, -5 hour)";
+            uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, "US", &offsetMinus5, &status);
+            break;
+        }
         if (U_FAILURE(status)) {
-            log_err("FAIL: %s failed with %s", api,
+            log_err_status(status, "FAIL: %s failed with %s\n", api,
                     u_errorName(status));
         } else {
             const char* id;
@@ -107,7 +165,7 @@ static void TestCalendar()
             count = uenum_count(uenum, &status);
             log_verbose("%s returned %d timezone id's:\n", api, count);
             if (count < 5) { /* Don't hard code an exact == test here! */
-                log_err("FAIL: in %s, got %d, expected at least 5\n", api, count);
+                log_data_err("FAIL: in %s, got %d, expected at least 5 -> %s (Are you missing data?)\n", api, count, u_errorName(status));
             }
             uenum_reset(uenum, &status);    
             if (U_FAILURE(status)){
@@ -140,7 +198,7 @@ static void TestCalendar()
         log_err("FAIL: ucal_getDSTSavings(GMT) => %s\n",
                 u_errorName(status));
     } else if (i != 0) {
-        log_err("FAIL: ucal_getDSTSavings(GMT) => %d, expect 0\n", i);
+        log_data_err("FAIL: ucal_getDSTSavings(GMT) => %d, expect 0 (Are you missing data?)\n", i);
     }
     i = ucal_getDSTSavings(PST, &status);
     if (U_FAILURE(status)) {
@@ -168,37 +226,70 @@ static void TestCalendar()
                         u_errorName(status));
             } else {
                 if (u_strcmp(zone2, EUROPE_PARIS) != 0) {
-                    log_err("FAIL: ucal_getDefaultTimeZone() did not return Europe/Paris\n");
+                    log_data_err("FAIL: ucal_getDefaultTimeZone() did not return Europe/Paris (Are you missing data?)\n");
                 }
             }
         }
         status = U_ZERO_ERROR;
         ucal_setDefaultTimeZone(zone1, &status);
     }
+    
+    /*Test ucal_getTZDataVersion*/
+    status = U_ZERO_ERROR;
+    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*/) {
+        log_err("FAIL: Bad version string was returned by ucal_getTZDataVersion\n");
+    } else {
+        log_verbose("PASS: ucal_getTZDataVersion returned %s\n", tzver);
+    }
+    
+    /*Testing ucal_getCanonicalTimeZoneID*/
+    status = U_ZERO_ERROR;
+    resultlength = ucal_getCanonicalTimeZoneID(PST, -1,
+        canonicalID, sizeof(canonicalID)/sizeof(UChar), &isSystemID, &status);
+    if (U_FAILURE(status)) {
+        log_err("FAIL: error in ucal_getCanonicalTimeZoneID : %s\n", u_errorName(status));
+    } else {
+        if (u_strcmp(AMERICA_LOS_ANGELES, canonicalID) != 0) {
+            log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) returned %s : expected - %s (Are you missing data?)\n",
+                PST, canonicalID, AMERICA_LOS_ANGELES);
+        }
+        if (!isSystemID) {
+            log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) set %d to isSystemID (Are you missing data?)\n",
+                PST, isSystemID);
+        }
+    }
 
     /*Testing the  ucal_open() function*/
+    status = U_ZERO_ERROR;
     log_verbose("\nTesting the ucal_open()\n");
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
     u_uastrcpy(tzID, "PST");
     caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
     if(U_FAILURE(status)){
-        log_err("FAIL: error in ucal_open caldef : %s\n", u_errorName(status));
+        log_data_err("FAIL: error in ucal_open caldef : %s\n - (Are you missing data?)", u_errorName(status));
     }
     
     caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
     if(U_FAILURE(status)){
-        log_err("FAIL: error in ucal_open caldef : %s\n", u_errorName(status));
+        log_data_err("FAIL: error in ucal_open caldef : %s - (Are you missing data?)\n", u_errorName(status));
     }
     u_strcpy(tzID, fgGMTID);
     calfr=ucal_open(tzID, u_strlen(tzID), "fr_FR", UCAL_TRADITIONAL, &status);
     if(U_FAILURE(status)){
-        log_err("FAIL: error in ucal_open calfr : %s\n", u_errorName(status));
+        log_data_err("FAIL: error in ucal_open calfr : %s - (Are you missing data?)\n", u_errorName(status));
     }
     calit=ucal_open(tzID, u_strlen(tzID), "it_IT", UCAL_TRADITIONAL, &status);
     if(U_FAILURE(status))    {
-        log_err("FAIL: error in ucal_open calit : %s\n", u_errorName(status));
+        log_data_err("FAIL: error in ucal_open calit : %s - (Are you missing data?)\n", u_errorName(status));
+    }
+
+    /*Testing the  clone() function*/
+    calfrclone = ucal_clone(calfr, &status);
+    if(U_FAILURE(status)){
+        log_data_err("FAIL: error in ucal_clone calfr : %s - (Are you missing data?)\n", u_errorName(status));
     }
-    
     
     /*Testing udat_getAvailable() and udat_countAvailable()*/ 
     log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
@@ -220,8 +311,8 @@ static void TestCalendar()
     log_verbose("\nTesting ucal_equivalentTo()\n");
     if(caldef && caldef2 && calfr && calit) { 
       if(ucal_equivalentTo(caldef, caldef2) == FALSE || ucal_equivalentTo(caldef, calfr)== TRUE || 
-        ucal_equivalentTo(caldef, calit)== TRUE) {
-          log_err("FAIL: Error. equivalentTo test failed\n");
+        ucal_equivalentTo(caldef, calit)== TRUE || ucal_equivalentTo(calfr, calfrclone) == FALSE) {
+          log_data_err("FAIL: Error. equivalentTo test failed (Are you missing data?)\n");
       } else {
           log_verbose("PASS: equivalentTo test passed\n");
       }
@@ -234,7 +325,7 @@ static void TestCalendar()
     /* open the date format and format the date to check the output */
     datdef=udat_open(UDAT_FULL,UDAT_FULL ,NULL, NULL, 0,NULL,0,&status);
     if(U_FAILURE(status)){
-        log_err("FAIL: error in creating the dateformat : %s\n", u_errorName(status));
+        log_data_err("FAIL: error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
         return;
     }
     log_verbose("PASS: The current date and time fetched is %s\n", u_austrcpy(tempMsgBuf, myDateFormat(datdef, now)) );
@@ -343,23 +434,42 @@ static void TestCalendar()
         log_err("Error in ucal_inDaylightTime: %s\n", u_errorName(status));
     }
     if(!ucal_inDaylightTime(caldef, &status))
-        log_verbose("PASS: It is  not in daylight saving's time\n");
+        log_verbose("PASS: It is not in daylight saving's time\n");
     else
         log_err("FAIL: It is not in daylight saving's time\n");
 
-    
-    
     /*closing the UCalendar*/
     ucal_close(caldef);
     ucal_close(caldef2);
     ucal_close(calfr);
     ucal_close(calit);
+    ucal_close(calfrclone);
+    
+    /*testing ucal_getType, and ucal_open with UCAL_GREGORIAN*/
+    for (ucalGetTypeTestPtr = ucalGetTypeTests; ucalGetTypeTestPtr->expectedResult != NULL; ++ucalGetTypeTestPtr) {
+        const char * localeToDisplay = (ucalGetTypeTestPtr->locale != NULL)? ucalGetTypeTestPtr->locale: "<NULL>";
+        status = U_ZERO_ERROR;
+        caldef = ucal_open(NULL, 0, ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType, &status);
+        if ( U_SUCCESS(status) ) {
+            const char * calType = ucal_getType(caldef, &status);
+            if ( U_SUCCESS(status) && calType != NULL ) {
+                if ( strcmp( calType, ucalGetTypeTestPtr->expectedResult ) != 0 ) {
+                    log_err("FAIL: ucal_open %s type %d does not return %s calendar\n", localeToDisplay,
+                                                ucalGetTypeTestPtr->calType, ucalGetTypeTestPtr->expectedResult);
+                }
+            } else {
+                log_err("FAIL: ucal_open %s type %d, then ucal_getType fails\n", localeToDisplay, ucalGetTypeTestPtr->calType);
+            }
+            ucal_close(caldef);
+        } else {
+            log_err("FAIL: ucal_open %s type %d fails\n", localeToDisplay, ucalGetTypeTestPtr->calType);
+        }
+    }
+
     /*closing the UDateFormat used */
     udat_close(datdef);
-    free(tzID);
     free(result);
     free(tzdname);
-    
 }
 
 /*------------------------------------------------------*/
@@ -368,7 +478,7 @@ static void TestCalendar()
 static void TestGetSetDateAPI()
 {
     UCalendar *caldef = 0, *caldef2 = 0;
-    UChar *tzID =0;
+    UChar tzID[4];
     UDate d1;
     int32_t hour;
     int32_t zoneOffset;
@@ -378,7 +488,6 @@ static void TestGetSetDateAPI()
     UChar temp[30];
 
     log_verbose("\nOpening the calendars()\n");
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
     u_strcpy(tzID, fgGMTID);
     /*open the calendars used */
     caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
@@ -390,7 +499,7 @@ static void TestGetSetDateAPI()
     datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US",fgGMTID,-1,NULL,0, &status);
     if(U_FAILURE(status))
     {
-        log_err("error in creating the dateformat : %s\n", u_errorName(status));
+        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
         return;
     }
     
@@ -552,8 +661,6 @@ static void TestGetSetDateAPI()
     ucal_close(caldef);
     ucal_close(caldef2);
     udat_close(datdef);
-    free(tzID);
-
 }
 
 /*----------------------------------------------------------- */
@@ -563,34 +670,33 @@ static void TestGetSetDateAPI()
 static void TestFieldGetSet()
 {
     UCalendar *cal = 0;
-    UChar *tzID = 0;
+    UChar tzID[4];
     UDateFormat *datdef = 0;
     UDate d1;
     UErrorCode status=U_ZERO_ERROR;
     log_verbose("\nFetching pointer to UCalendar using the ucal_open()\n");
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
     u_strcpy(tzID, fgGMTID);
     /*open the calendar used */
     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
     if (U_FAILURE(status)) {
-        log_err("ucal_open failed: %s\n", u_errorName(status));
+        log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status));
         return; 
     }
     datdef=udat_open(UDAT_SHORT,UDAT_SHORT ,NULL,fgGMTID,-1,NULL, 0, &status);
     if(U_FAILURE(status))
     {
-        log_err("error in creating the dateformat : %s\n", u_errorName(status));
+        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
     }
     
     /*Testing ucal_get()*/
     log_verbose("\nTesting the ucal_get() function of Calendar\n");
     ucal_setDateTime(cal, 1999, UCAL_MARCH, 12, 5, 25, 30, &status);
     if(U_FAILURE(status)){
-        log_err("error in the setDateTime() : %s\n", u_errorName(status));
+        log_data_err("error in the setDateTime() : %s (Are you missing data?)\n", u_errorName(status));
     }
     if(ucal_get(cal, UCAL_YEAR, &status)!=1999 || ucal_get(cal, UCAL_MONTH, &status)!=2 || 
         ucal_get(cal, UCAL_DATE, &status)!=12 || ucal_get(cal, UCAL_HOUR, &status)!=5)
-        log_err("error in ucal_get()\n");    
+        log_data_err("error in ucal_get() -> %s (Are you missing data?)\n", u_errorName(status));    
     else if(ucal_get(cal, UCAL_DAY_OF_WEEK_IN_MONTH, &status)!=2 || ucal_get(cal, UCAL_DAY_OF_WEEK, &status)!=6
         || ucal_get(cal, UCAL_WEEK_OF_MONTH, &status)!=2 || ucal_get(cal, UCAL_WEEK_OF_YEAR, &status)!= 11)
         log_err("FAIL: error in ucal_get()\n");
@@ -619,19 +725,18 @@ static void TestFieldGetSet()
     verify1("1997 last Tuesday in June = ", cal, datdef,1997,   UCAL_JUNE, 24);
     /*give undesirable input    */
     status = U_ZERO_ERROR;
-        ucal_clear(cal);
-        ucal_set(cal, UCAL_YEAR, 1997);
-        ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
-        ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
-        ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 0);
-        d1=ucal_getMillis(cal,&status);
-        if (status != U_ILLEGAL_ARGUMENT_ERROR){ 
-            log_err("FAIL: No IllegalArgumentError for :");
-            log_err("1997 zero-th Tuesday in June \n");
-        }
-        else 
-            log_verbose("PASS: IllegalArgumentError as expected\n");
-   
+    ucal_clear(cal);
+    ucal_set(cal, UCAL_YEAR, 1997);
+    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
+    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
+    ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 0);
+    d1 = ucal_getMillis(cal, &status);
+    if (status != U_ILLEGAL_ARGUMENT_ERROR) { 
+        log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 zero-th Tuesday in June\n");
+    } else {
+        log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
+    }
+    status = U_ZERO_ERROR;
     ucal_clear(cal);
     ucal_set(cal, UCAL_YEAR, 1997);
     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
@@ -650,7 +755,14 @@ static void TestFieldGetSet()
     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
     ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
     ucal_set(cal, UCAL_WEEK_OF_MONTH, 0);
-    verify1("1997 Tuesday in week 0 of June = ", cal, datdef , 1997, UCAL_MAY, 27);
+    ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
+    d1 = ucal_getMillis(cal,&status);
+    if (status != U_ILLEGAL_ARGUMENT_ERROR){ 
+        log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 Tuesday zero-th week in June\n");
+    } else {
+        log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
+    }
+    status = U_ZERO_ERROR;
     ucal_clear(cal);
     ucal_set(cal, UCAL_YEAR_WOY, 1997);
     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
@@ -666,13 +778,13 @@ static void TestFieldGetSet()
     ucal_set(cal, UCAL_DAY_OF_YEAR, 1);
     verify1("1999 1st day of the year =", cal, datdef, 1999, UCAL_JANUARY, 1);
     ucal_set(cal, UCAL_MONTH, -3);
-    d1=ucal_getMillis(cal,&status);
-        if (status != U_ILLEGAL_ARGUMENT_ERROR){ 
-            log_err("FAIL: No IllegalArgumentError for :\"1999 -3th month \" ");
-        }
-        else 
-            log_verbose("PASS: IllegalArgumentError as expected\n");
-    
+    d1 = ucal_getMillis(cal,&status);
+    if (status != U_ILLEGAL_ARGUMENT_ERROR){ 
+        log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1999 -3th month\n");
+    } else {
+        log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
+    }
+
     ucal_setAttribute(cal, UCAL_LENIENT, 1);
     
     ucal_set(cal, UCAL_MONTH, -3);
@@ -694,21 +806,32 @@ static void TestFieldGetSet()
 
     ucal_close(cal);
     udat_close(datdef);
-    free(tzID);
-    
 }
  
+typedef struct {
+    const char * zone;
+    int32_t      year;
+    int32_t      month;
+    int32_t      day;
+    int32_t      hour;
+} TransitionItem;
+
+static const TransitionItem transitionItems[] = {
+    { "America/Caracas", 2007, UCAL_DECEMBER,  8, 10 }, /* day before change in UCAL_ZONE_OFFSET */
+    { "US/Pacific",      2011,    UCAL_MARCH, 12, 10 }, /* day before change in UCAL_DST_OFFSET */
+    { NULL,                 0,             0,  0,  0 }
+};
 
 /* ------------------------------------- */
 /**
  * Execute adding and rolling in Calendar extensively,
  */
 static void TestAddRollExtensive()
 {
+    const TransitionItem * itemPtr;
     UCalendar *cal = 0;
     int32_t i,limit;
-    UChar* tzID = 0;
+    UChar tzID[32];
     UCalendarDateFields e;
     int32_t y,m,d,hr,min,sec,ms;
     int32_t maxlimit = 40;
@@ -717,18 +840,18 @@ static void TestAddRollExtensive()
    
     log_verbose("Testing add and roll extensively\n");
     
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
     u_uastrcpy(tzID, "PST");
     /*open the calendar used */
     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);;
     if (U_FAILURE(status)) {
-        log_err("ucal_open() failed : %s\n", u_errorName(status)); 
+        log_data_err("ucal_open() failed : %s - (Are you missing data?)\n", u_errorName(status)); 
         return; 
     }
 
     ucal_set(cal, UCAL_YEAR, y);
     ucal_set(cal, UCAL_MONTH, m);
     ucal_set(cal, UCAL_DATE, d);
+    ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
 
     /* Confirm that adding to various fields works.*/
     log_verbose("\nTesting to confirm that adding to various fields works with ucal_add()\n");
@@ -795,6 +918,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));
@@ -822,6 +946,7 @@ static void TestAddRollExtensive()
     ucal_set(cal, UCAL_MINUTE, min);
     ucal_set(cal, UCAL_SECOND,sec);
     ucal_set(cal, UCAL_MILLISECOND, ms);
+    ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
     status=U_ZERO_ERROR;
 
     log_verbose("\nTesting UCalendar add...\n");
@@ -863,7 +988,34 @@ static void TestAddRollExtensive()
     }
 
     ucal_close(cal);
-    free(tzID);
+/*--------------- */
+    log_verbose("\nTesting ucal_add() across ZONE_OFFSET and DST_OFFSE transitions.\n");
+    for (itemPtr = transitionItems; itemPtr->zone != NULL; itemPtr++) {
+        status=U_ZERO_ERROR;
+        u_uastrcpy(tzID, itemPtr->zone);
+        cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);
+        if (U_FAILURE(status)) {
+            log_err("ucal_open failed for zone %s: %s\n", itemPtr->zone, u_errorName(status));
+            continue; 
+        }
+        ucal_setDateTime(cal, itemPtr->year, itemPtr->month, itemPtr->day, itemPtr->hour, 0, 0, &status);
+        ucal_add(cal, UCAL_DATE, 1, &status);
+        hr = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
+        if ( U_FAILURE(status) ) {
+            log_err("ucal_add failed adding day across transition for zone %s: %s\n", itemPtr->zone, u_errorName(status));
+        } else if ( hr != itemPtr->hour ) {
+            log_err("ucal_add produced wrong hour %d when adding day across transition for zone %s\n", hr, itemPtr->zone);
+        } else {
+            ucal_add(cal, UCAL_DATE, -1, &status);
+            hr = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
+            if ( U_FAILURE(status) ) {
+                log_err("ucal_add failed subtracting day across transition for zone %s: %s\n", itemPtr->zone, u_errorName(status));
+            } else if ( hr != itemPtr->hour ) {
+                log_err("ucal_add produced wrong hour %d when subtracting day across transition for zone %s\n", hr, itemPtr->zone);
+            }
+        }
+        ucal_close(cal);
+    }
 }
 
 /*------------------------------------------------------ */
@@ -872,16 +1024,15 @@ static void TestGetLimits()
 {
     UCalendar *cal = 0;
     int32_t min, max, gr_min, le_max, ac_min, ac_max, val;
-    UChar* tzID = 0;
+    UChar tzID[4];
     UErrorCode status = U_ZERO_ERROR;
     
     
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
     u_uastrcpy(tzID, "PST");
     /*open the calendar used */
     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);;
     if (U_FAILURE(status)) {
-        log_err("ucal_open() for gregorian calendar failed in TestGetLimits: %s\n", u_errorName(status));
+        log_data_err("ucal_open() for gregorian calendar failed in TestGetLimits: %s - (Are you missing data?)\n", u_errorName(status));
         return; 
     }
     
@@ -893,7 +1044,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);
@@ -904,7 +1055,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);
@@ -936,7 +1087,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);
@@ -955,7 +1106,6 @@ static void TestGetLimits()
 
 
     ucal_close(cal);
-    free(tzID);
 }
 
 
@@ -974,20 +1124,19 @@ static void TestDOWProgression()
     UDate date1;
     int32_t delta=24;
     UErrorCode status = U_ZERO_ERROR;
-    UChar* tzID = 0;
+    UChar tzID[4];
     char tempMsgBuf[256];
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
     u_strcpy(tzID, fgGMTID);
     /*open the calendar used */
     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);;
     if (U_FAILURE(status)) {
-        log_err("ucal_open failed: %s\n", u_errorName(status));
+        log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status));
         return; 
     }
 
     datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1,NULL, 0, &status);
     if(U_FAILURE(status)){
-        log_err("error in creating the dateformat : %s\n", u_errorName(status));
+        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
     }
     
 
@@ -996,7 +1145,7 @@ static void TestDOWProgression()
     log_verbose("\nTesting the DOW progression\n");
     
     initialDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
-    if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", u_errorName(status) ); return; }
+    if (U_FAILURE(status)) { log_data_err("ucal_get() failed: %s (Are you missing data?)\n", u_errorName(status) ); return; }
     newDOW = initialDOW;
     do {
         DOW = newDOW;
@@ -1023,8 +1172,6 @@ static void TestDOWProgression()
     
     ucal_close(cal);
     udat_close(datfor);
-    free(tzID);
-    
 }
  
 /* ------------------------------------- */
@@ -1050,14 +1197,13 @@ static void testZones(int32_t yr, int32_t mo, int32_t dt, int32_t hr, int32_t mn
     double temp;
     UDateFormat *datfor = 0;
     UErrorCode status = U_ZERO_ERROR;
-    UChar* tzID = 0;
+    UChar tzID[4];
     char tempMsgBuf[256];
 
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
     u_strcpy(tzID, fgGMTID);
     gmtcal=ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);;
     if (U_FAILURE(status)) {
-        log_err("ucal_open failed: %s\n", u_errorName(status)); 
+        log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status)); 
         return; 
     }
     u_uastrcpy(tzID, "PST");
@@ -1069,12 +1215,12 @@ static void testZones(int32_t yr, int32_t mo, int32_t dt, int32_t hr, int32_t mn
     
     datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1,NULL, 0, &status);
     if(U_FAILURE(status)){
-        log_err("error in creating the dateformat : %s\n", u_errorName(status));
+        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
     }
    
     ucal_setDateTime(gmtcal, yr, mo - 1, dt, hr, mn, sc, &status);
     if (U_FAILURE(status)) {
-        log_err("ucal_setDateTime failed: %s\n", u_errorName(status));
+        log_data_err("ucal_setDateTime failed: %s (Are you missing data?)\n", u_errorName(status));
         return; 
     }
     ucal_set(gmtcal, UCAL_MILLISECOND, 0);
@@ -1121,7 +1267,6 @@ static void testZones(int32_t yr, int32_t mo, int32_t dt, int32_t hr, int32_t mn
     ucal_close(gmtcal);
     ucal_close(cal);
     udat_close(datfor);
-    free(tzID);
 }
  
 /* ------------------------------------- */
@@ -1272,4 +1417,524 @@ 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_data_err("ucal_open(UTC) failed: %s - (Are you missing data?)\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);
+}
+
+static void TestGetKeywordValuesForLocale() {
+#define PREFERRED_SIZE 15
+#define MAX_NUMBER_OF_KEYWORDS 4
+    const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = {
+            { "root",        "gregorian", NULL, NULL, NULL },
+            { "und",         "gregorian", NULL, NULL, NULL },
+            { "en_US",       "gregorian", NULL, NULL, NULL },
+            { "en_029",      "gregorian", NULL, NULL, NULL },
+            { "th_TH",       "buddhist", "gregorian", NULL, NULL },
+            { "und_TH",      "buddhist", "gregorian", NULL, NULL },
+            { "en_TH",       "buddhist", "gregorian", NULL, NULL },
+            { "he_IL",       "gregorian", "hebrew", "islamic", "islamic-civil" },
+            { "ar_EG",       "gregorian", "coptic", "islamic", "islamic-civil" },
+            { "ja",          "gregorian", "japanese", NULL, NULL },
+            { "ps_Guru_IN",  "gregorian", "indian", NULL, NULL },
+            { "th@calendar=gregorian", "buddhist", "gregorian", NULL, NULL },
+            { "en@calendar=islamic",   "gregorian", NULL, NULL, NULL },
+            { "zh_TW",       "gregorian", "roc", "chinese", NULL },
+            { "ar_IR",       "gregorian", "persian", "islamic", "islamic-civil" },
+    };
+    const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = { 1, 1, 1, 1, 2, 2, 2, 4, 4, 2, 2, 2, 1, 3, 4 };
+    UErrorCode status = U_ZERO_ERROR;
+    int32_t i, size, j;
+    UEnumeration *all, *pref;
+    const char *loc = NULL;
+    UBool matchPref, matchAll;
+    const char *value;
+    int32_t valueLength;
+    UList *ALLList = NULL;
+    
+    UEnumeration *ALL = ucal_getKeywordValuesForLocale("calendar", uloc_getDefault(), FALSE, &status);
+    if (U_SUCCESS(status)) {
+        for (i = 0; i < PREFERRED_SIZE; i++) {
+            pref = NULL;
+            all = NULL;
+            loc = PREFERRED[i][0];
+            pref = ucal_getKeywordValuesForLocale("calendar", loc, TRUE, &status);
+            matchPref = FALSE;
+            matchAll = FALSE;
+            
+            value = NULL;
+            valueLength = 0;
+            
+            if (U_SUCCESS(status) && uenum_count(pref, &status) == EXPECTED_SIZE[i]) {
+                matchPref = TRUE;
+                for (j = 0; j < EXPECTED_SIZE[i]; j++) {
+                    if ((value = uenum_next(pref, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
+                        if (uprv_strcmp(value, PREFERRED[i][j+1]) != 0) {
+                            matchPref = FALSE;
+                            break;
+                        }
+                    } else {
+                        matchPref = FALSE;
+                        log_err("ERROR getting keyword value for locale \"%s\"\n", loc);
+                        break;
+                    }
+                }
+            }
+            
+            if (!matchPref) {
+                log_err("FAIL: Preferred values for locale \"%s\" does not match expected.\n", loc);
+                break;
+            }
+            uenum_close(pref);
+            
+            all = ucal_getKeywordValuesForLocale("calendar", loc, FALSE, &status);
+            
+            size = uenum_count(all, &status);
+            
+            if (U_SUCCESS(status) && size == uenum_count(ALL, &status)) {
+                matchAll = TRUE;
+                ALLList = ulist_getListFromEnum(ALL);
+                for (j = 0; j < size; j++) {
+                    if ((value = uenum_next(all, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
+                        if (!ulist_containsString(ALLList, value, uprv_strlen(value))) {
+                            log_err("Locale %s have %s not in ALL\n", loc, value);
+                            matchAll = FALSE;
+                            break;
+                        }
+                    } else {
+                        matchAll = FALSE;
+                        log_err("ERROR getting \"all\" keyword value for locale \"%s\"\n", loc);
+                        break;
+                    }
+                }
+            }
+            if (!matchAll) {
+                log_err("FAIL: All values for locale \"%s\" does not match expected.\n", loc);
+            }
+            
+            uenum_close(all);
+        }
+    } else {
+        log_err_status(status, "Failed to get ALL keyword values for default locale %s: %s.\n", uloc_getDefault(), u_errorName(status));
+    }
+    uenum_close(ALL);
+}
+
+/*
+ * Weekend tests, ported from
+ * icu4j/trunk/main/tests/core/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java
+ * and extended a bit. Notes below from IBMCalendarTest.java ...
+ * This test tests for specific locale data. This is probably okay
+ * as far as US data is concerned, but if the Arabic/Yemen data
+ * changes, this test will have to be updated.
+ */
+
+typedef struct {
+    int32_t year;
+    int32_t month;
+    int32_t day;
+    int32_t hour;
+    int32_t millisecOffset;
+    UBool   isWeekend;
+} TestWeekendDates;
+typedef struct {
+    const char * locale;
+    const        TestWeekendDates * dates;
+    int32_t      numDates;
+} TestWeekendDatesList;
+
+static const TestWeekendDates weekendDates_en_US[] = {
+    { 2000, UCAL_MARCH, 17, 23,  0, 0 }, /* Fri 23:00        */
+    { 2000, UCAL_MARCH, 18,  0, -1, 0 }, /* Fri 23:59:59.999 */
+    { 2000, UCAL_MARCH, 18,  0,  0, 1 }, /* Sat 00:00        */
+    { 2000, UCAL_MARCH, 18, 15,  0, 1 }, /* Sat 15:00        */
+    { 2000, UCAL_MARCH, 19, 23,  0, 1 }, /* Sun 23:00        */
+    { 2000, UCAL_MARCH, 20,  0, -1, 1 }, /* Sun 23:59:59.999 */
+    { 2000, UCAL_MARCH, 20,  0,  0, 0 }, /* Mon 00:00        */
+    { 2000, UCAL_MARCH, 20,  8,  0, 0 }, /* Mon 08:00        */
+};
+static const TestWeekendDates weekendDates_ar_YE[] = {
+    { 2000, UCAL_MARCH, 15, 23,  0, 0 }, /* Wed 23:00        */
+    { 2000, UCAL_MARCH, 16,  0, -1, 0 }, /* Wed 23:59:59.999 */
+    { 2000, UCAL_MARCH, 16,  0,  0, 1 }, /* Thu 00:00        */
+    { 2000, UCAL_MARCH, 16, 15,  0, 1 }, /* Thu 15:00        */
+    { 2000, UCAL_MARCH, 17, 23,  0, 1 }, /* Fri 23:00        */
+    { 2000, UCAL_MARCH, 18,  0, -1, 1 }, /* Fri 23:59:59.999 */
+    { 2000, UCAL_MARCH, 18,  0,  0, 0 }, /* Sat 00:00        */
+    { 2000, UCAL_MARCH, 18,  8,  0, 0 }, /* Sat 08:00        */
+};
+static const TestWeekendDatesList testDates[] = {
+    { "en_US", weekendDates_en_US, sizeof(weekendDates_en_US)/sizeof(weekendDates_en_US[0]) },
+    { "ar_YE", weekendDates_ar_YE, sizeof(weekendDates_ar_YE)/sizeof(weekendDates_ar_YE[0]) },
+};
+
+typedef struct {
+    UCalendarDaysOfWeek  dayOfWeek;
+    UCalendarWeekdayType dayType;
+    int32_t              transition; /* transition time if dayType is UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE; else must be 0 */
+} TestDaysOfWeek;
+typedef struct {
+    const char *           locale;
+    const TestDaysOfWeek * days;
+    int32_t                numDays;
+} TestDaysOfWeekList;
+
+static const TestDaysOfWeek daysOfWeek_en_US[] = {
+    { UCAL_MONDAY,   UCAL_WEEKDAY,       0        },
+    { UCAL_FRIDAY,   UCAL_WEEKDAY,       0        },
+    { UCAL_SATURDAY, UCAL_WEEKEND,       0        },
+    { UCAL_SUNDAY,   UCAL_WEEKEND_CEASE, 86400000 },
+};
+static const TestDaysOfWeek daysOfWeek_ar_YE[] = { /* Thursday:Friday */
+    { UCAL_WEDNESDAY,UCAL_WEEKDAY,       0        },
+    { UCAL_SATURDAY, UCAL_WEEKDAY,       0        },
+    { UCAL_THURSDAY, UCAL_WEEKEND,       0        },
+    { UCAL_FRIDAY,   UCAL_WEEKEND_CEASE, 86400000 },
+};
+static const TestDaysOfWeekList testDays[] = {
+    { "en_US", daysOfWeek_en_US, sizeof(daysOfWeek_en_US)/sizeof(daysOfWeek_en_US[0]) },
+    { "ar_YE", daysOfWeek_ar_YE, sizeof(daysOfWeek_ar_YE)/sizeof(daysOfWeek_ar_YE[0]) },
+};
+
+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]) };
+
+static void TestWeekend() {
+    const TestWeekendDatesList * testDatesPtr = testDates;
+    const TestDaysOfWeekList *   testDaysPtr = testDays;
+    int32_t count, subCount;
+
+    UErrorCode fmtStatus = U_ZERO_ERROR;
+    UDateFormat * fmt = udat_open(UDAT_NONE, UDAT_NONE, "en", NULL, 0, NULL, 0, &fmtStatus);
+    if (U_SUCCESS(fmtStatus)) {
+        udat_applyPattern(fmt, FALSE, logDateFormat, -1);
+    } else {
+        log_data_err("Unable to create UDateFormat - %s\n", u_errorName(fmtStatus));
+        return;
+    }
+       for (count = sizeof(testDates)/sizeof(testDates[0]); 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);
+               if (U_SUCCESS(status)) {
+                       const TestWeekendDates * weekendDatesPtr = testDatesPtr->dates;
+                       for (subCount = testDatesPtr->numDates; subCount--; ++weekendDatesPtr) {
+                               UDate dateToTest;
+                               UBool isWeekend;
+                               char  fmtDateBytes[kFormattedDateMax] = "<could not format test date>"; /* initialize for failure */
+
+                               ucal_clear(cal);
+                               ucal_setDateTime(cal, weekendDatesPtr->year, weekendDatesPtr->month, weekendDatesPtr->day,
+                                                                weekendDatesPtr->hour, 0, 0, &status);
+                               dateToTest = ucal_getMillis(cal, &status) + weekendDatesPtr->millisecOffset;
+                               isWeekend = ucal_isWeekend(cal, dateToTest, &status);
+                               if (U_SUCCESS(fmtStatus)) {
+                                   UChar fmtDate[kFormattedDateMax];
+                                   (void)udat_format(fmt, dateToTest, fmtDate, kFormattedDateMax, NULL, &fmtStatus);
+                                   if (U_SUCCESS(fmtStatus)) {
+                                               u_austrncpy(fmtDateBytes, fmtDate, kFormattedDateMax);
+                                               fmtDateBytes[kFormattedDateMax-1] = 0;
+                                   } else {
+                                       fmtStatus = U_ZERO_ERROR;
+                                   }
+                               }
+                               if ( U_FAILURE(status) ) {
+                                       log_err("FAIL: locale %s date %s isWeekend() status %s\n", testDatesPtr->locale, fmtDateBytes, u_errorName(status) );
+                                       status = U_ZERO_ERROR;
+                               } else if ( (isWeekend!=0) != (weekendDatesPtr->isWeekend!=0) ) {
+                                       log_err("FAIL: locale %s date %s isWeekend %d, expected the opposite\n", testDatesPtr->locale, fmtDateBytes, isWeekend );
+                               } else {
+                                       log_verbose("OK:   locale %s date %s isWeekend %d\n", testDatesPtr->locale, fmtDateBytes, isWeekend );
+                               }
+                       }
+                       ucal_close(cal);
+               } else {
+                       log_data_err("FAIL: ucal_open for locale %s failed: %s - (Are you missing data?)\n", testDatesPtr->locale, u_errorName(status) );
+               }
+       }
+    if (U_SUCCESS(fmtStatus)) {
+        udat_close(fmt);
+    }
+
+    for (count = sizeof(testDays)/sizeof(testDays[0]); 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);
+        if (U_SUCCESS(status)) {
+            const TestDaysOfWeek * daysOfWeekPtr = testDaysPtr->days;
+            for (subCount = testDaysPtr->numDays; subCount--; ++daysOfWeekPtr) {
+                int32_t transition = 0;
+                UCalendarWeekdayType dayType = ucal_getDayOfWeekType(cal, daysOfWeekPtr->dayOfWeek, &status);
+                if ( dayType == UCAL_WEEKEND_ONSET || dayType == UCAL_WEEKEND_CEASE ) {
+                    transition = ucal_getWeekendTransition(cal, daysOfWeekPtr->dayOfWeek, &status); 
+                }
+                if ( U_FAILURE(status) ) {
+                                       log_err("FAIL: locale %s DOW %d getDayOfWeekType() status %s\n", testDaysPtr->locale, daysOfWeekPtr->dayOfWeek, u_errorName(status) );
+                                       status = U_ZERO_ERROR;
+                } else if ( dayType != daysOfWeekPtr->dayType || transition != daysOfWeekPtr->transition ) {
+                                       log_err("FAIL: locale %s DOW %d type %d, expected %d\n", testDaysPtr->locale, daysOfWeekPtr->dayOfWeek, dayType, daysOfWeekPtr->dayType );
+                } else {
+                                       log_verbose("OK:   locale %s DOW %d type %d\n", testDaysPtr->locale, daysOfWeekPtr->dayOfWeek, dayType );
+                }
+            }
+            ucal_close(cal);
+        } else {
+            log_data_err("FAIL: ucal_open for locale %s failed: %s - (Are you missing data?)\n", testDaysPtr->locale, u_errorName(status) );
+        }
+    }
+}
+
+/**
+ * TestFieldDifference
+ */
+
+typedef struct {
+    const UChar * timezone;
+    const char *  locale;
+    UDate         start;
+    UDate         target;
+    int32_t       yDiff;
+    int32_t       MDiff;
+    int32_t       dDiff;
+    int32_t       HDiff;
+    int32_t       mDiff;
+    int32_t       sDiff; /* 0x7FFFFFFF indicates overflow error expected */
+} TFDItem;
+
+static const UChar tzUSPacific[] = { 0x55,0x53,0x2F,0x50,0x61,0x63,0x69,0x66,0x69,0x63,0 }; /* "US/Pacific" */
+static const UChar tzGMT[] = { 0x47,0x4D,0x54,0 }; /* "GMT" */
+
+static const TFDItem tfdItems[] = {
+    /* timezone    locale   start            target            yDf  MDf    dDf     HDf       mDf         sDf */
+    /* For these we compute the progressive difference for each field - not resetting the calendar after each call */
+    { tzUSPacific, "en_US", 1267459800000.0, 1277772600000.0,    0,   3,    27,      9,       40,          0 }, /* 2010-Mar-01 08:10 -> 2010-Jun-28 17:50 */
+    { tzUSPacific, "en_US", 1267459800000.0, 1299089280000.0,    1,   0,     1,      1,       58,          0 }, /* 2010-Mar-01 08:10 -> 2011-Mar-02 10:08 */
+    /* For these we compute the total difference for each field - resetting the calendar after each call */
+    { tzGMT,       "en_US", 0.0,             1073692800000.0,   34, 408, 12427, 298248, 17894880, 1073692800 }, /* 1970-Jan-01 00:00 -> 2004-Jan-10 00:00:00 */
+    { tzGMT,       "en_US", 0.0,             1073779200000.0,   34, 408, 12428, 298272, 17896320, 1073779200 }, /* 1970-Jan-01 00:00 -> 2004-Jan-11 00:00:00 */
+    { tzGMT,       "en_US", 0.0,             2147472000000.0,   68, 816, 24855, 596520, 35791200, 2147472000 }, /* 1970-Jan-01 00:00 -> 2038-Jan-19 00:00:00 */
+    { tzGMT,       "en_US", 0.0,             2147558400000.0,   68, 816, 24856, 596544, 35792640, 0x7FFFFFFF }, /* 1970-Jan-01 00:00 -> 2038-Jan-20 00:00:00, seconds diff overflow */
+    { tzGMT,       "en_US", 0.0,            -1073692800000.0,  -34,-408,-12427,-298248,-17894880,-1073692800 }, /* 1970-Jan-01 00:00 -> 1935-Dec-24 00:00:00 */
+    { tzGMT,       "en_US", 0.0,            -1073779200000.0,  -34,-408,-12428,-298272,-17896320,-1073779200 }, /* 1970-Jan-01 00:00 -> 1935-Dec-23 00:00:00 */
+    { NULL,        NULL,    0.0,             0.0,                0,   0,     0,      0,        0,          0 }  /* terminator */
+};
+
+void TestFieldDifference() {
+    const TFDItem * tfdItemPtr;
+    for (tfdItemPtr = tfdItems; tfdItemPtr->timezone != NULL; tfdItemPtr++) {
+        UErrorCode status = U_ZERO_ERROR;
+        UCalendar* ucal = ucal_open(tfdItemPtr->timezone, -1, tfdItemPtr->locale, UCAL_DEFAULT, &status);
+        if (U_FAILURE(status)) {
+            log_err("FAIL: for locale \"%s\", ucal_open had status %s\n", tfdItemPtr->locale, u_errorName(status) );
+        } else {
+            int32_t yDf, MDf, dDf, HDf, mDf, sDf;
+            if (tfdItemPtr->start != 0.0) {
+                ucal_setMillis(ucal, tfdItemPtr->start, &status);
+                yDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_YEAR, &status);
+                MDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_MONTH, &status);
+                dDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_DATE, &status);
+                HDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_HOUR, &status);
+                mDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_MINUTE, &status);
+                sDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_SECOND, &status);
+                if (U_FAILURE(status)) {
+                    log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, ucal_setMillis or ucal_getFieldDifference had status %s\n",
+                            tfdItemPtr->locale, tfdItemPtr->start, tfdItemPtr->target, u_errorName(status) );
+                } else if ( yDf !=  tfdItemPtr->yDiff ||
+                            MDf !=  tfdItemPtr->MDiff ||
+                            dDf !=  tfdItemPtr->dDiff ||
+                            HDf !=  tfdItemPtr->HDiff ||
+                            mDf !=  tfdItemPtr->mDiff ||
+                            sDf !=  tfdItemPtr->sDiff ) {
+                    log_data_err("FAIL: for locale \"%s\", start %.1f, target %.1f, expected y-M-d-H-m-s progressive diffs %d-%d-%d-%d-%d-%d, got %d-%d-%d-%d-%d-%d\n",
+                            tfdItemPtr->locale, tfdItemPtr->start, tfdItemPtr->target,
+                            tfdItemPtr->yDiff, tfdItemPtr->MDiff, tfdItemPtr->dDiff, tfdItemPtr->HDiff, tfdItemPtr->mDiff, tfdItemPtr->sDiff,
+                            yDf, MDf, dDf, HDf, mDf, sDf);
+                }
+            } else {
+                ucal_setMillis(ucal, tfdItemPtr->start, &status);
+                yDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_YEAR, &status);
+                ucal_setMillis(ucal, tfdItemPtr->start, &status);
+                MDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_MONTH, &status);
+                ucal_setMillis(ucal, tfdItemPtr->start, &status);
+                dDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_DATE, &status);
+                ucal_setMillis(ucal, tfdItemPtr->start, &status);
+                HDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_HOUR, &status);
+                ucal_setMillis(ucal, tfdItemPtr->start, &status);
+                mDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_MINUTE, &status);
+                if (U_FAILURE(status)) {
+                    log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, ucal_setMillis or ucal_getFieldDifference (y-M-d-H-m) had status %s\n",
+                            tfdItemPtr->locale, tfdItemPtr->start, tfdItemPtr->target, u_errorName(status) );
+                } else if ( yDf !=  tfdItemPtr->yDiff ||
+                            MDf !=  tfdItemPtr->MDiff ||
+                            dDf !=  tfdItemPtr->dDiff ||
+                            HDf !=  tfdItemPtr->HDiff ||
+                            mDf !=  tfdItemPtr->mDiff ) {
+                    log_data_err("FAIL: for locale \"%s\", start %.1f, target %.1f, expected y-M-d-H-m total diffs %d-%d-%d-%d-%d, got %d-%d-%d-%d-%d\n",
+                            tfdItemPtr->locale, tfdItemPtr->start, tfdItemPtr->target,
+                            tfdItemPtr->yDiff, tfdItemPtr->MDiff, tfdItemPtr->dDiff, tfdItemPtr->HDiff, tfdItemPtr->mDiff,
+                            yDf, MDf, dDf, HDf, mDf);
+                }
+                ucal_setMillis(ucal, tfdItemPtr->start, &status);
+                sDf = ucal_getFieldDifference(ucal, tfdItemPtr->target, UCAL_SECOND, &status);
+                if (tfdItemPtr->sDiff != 0x7FFFFFFF) {
+                    if (U_FAILURE(status)) {
+                        log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, ucal_setMillis or ucal_getFieldDifference (seconds) had status %s\n",
+                                tfdItemPtr->locale, tfdItemPtr->start, tfdItemPtr->target, u_errorName(status) );
+                    } else if (sDf !=  tfdItemPtr->sDiff) {
+                        log_data_err("FAIL: for locale \"%s\", start %.1f, target %.1f, expected seconds progressive diff %d, got %d\n",
+                                tfdItemPtr->locale, tfdItemPtr->start, tfdItemPtr->target, tfdItemPtr->sDiff, sDf);
+                    }
+                } else if (!U_FAILURE(status)) {
+                    log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, for ucal_getFieldDifference (seconds) expected overflow error, got none\n",
+                            tfdItemPtr->locale, tfdItemPtr->start, tfdItemPtr->target );
+                }
+            }
+            ucal_close(ucal);
+        }
+    }
+}
+
+void TestAmbiguousWallTime() {
+    UErrorCode status = U_ZERO_ERROR;
+    UChar tzID[32];
+    UCalendar* ucal;
+    UDate t, expected;
+
+    u_uastrcpy(tzID, "America/New_York");
+    ucal = ucal_open(tzID, -1, NULL, UCAL_DEFAULT, &status);
+    if (U_FAILURE(status)) {
+        log_err("FAIL: Failed to create a calendar");
+        return;
+    }
+
+    if (ucal_getAttribute(ucal, UCAL_REPEATED_WALL_TIME) != UCAL_WALLTIME_LAST) {
+        log_err("FAIL: Default UCAL_REPEATED_WALL_TIME value is not UCAL_WALLTIME_LAST");
+    }
+
+    if (ucal_getAttribute(ucal, UCAL_SKIPPED_WALL_TIME) != UCAL_WALLTIME_LAST) {
+        log_err("FAIL: Default UCAL_SKIPPED_WALL_TIME value is not UCAL_WALLTIME_LAST");
+    }
+
+    /* UCAL_WALLTIME_FIRST on US fall transition */
+    ucal_setAttribute(ucal, UCAL_REPEATED_WALL_TIME, UCAL_WALLTIME_FIRST);
+    ucal_clear(ucal);
+    ucal_setDateTime(ucal, 2011, 11-1, 6, 1, 30, 0, &status);
+    t = ucal_getMillis(ucal, &status);
+    expected = 1320557400000.0; /* 2011-11-06T05:30:00Z */
+    if (U_FAILURE(status)) {
+        log_err("FAIL: Calculating time 2011-11-06 01:30:00 with UCAL_WALLTIME_FIRST - %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
+    } else if (t != expected) {
+        log_data_err("FAIL: 2011-11-06 01:30:00 with UCAL_WALLTIME_FIRST - got: %f, expected: %f\n", t, expected);
+    }
+
+    /* UCAL_WALLTIME_LAST on US fall transition */
+    ucal_setAttribute(ucal, UCAL_REPEATED_WALL_TIME, UCAL_WALLTIME_LAST);
+    ucal_clear(ucal);
+    ucal_setDateTime(ucal, 2011, 11-1, 6, 1, 30, 0, &status);
+    t = ucal_getMillis(ucal, &status);
+    expected = 1320561000000.0; /* 2011-11-06T06:30:00Z */
+    if (U_FAILURE(status)) {
+        log_err("FAIL: Calculating time 2011-11-06 01:30:00 with UCAL_WALLTIME_LAST - %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
+    } else if (t != expected) {
+        log_data_err("FAIL: 2011-11-06 01:30:00 with UCAL_WALLTIME_LAST - got: %f, expected: %f\n", t, expected);
+    }
+
+    /* UCAL_WALLTIME_FIRST on US spring transition */
+    ucal_setAttribute(ucal, UCAL_SKIPPED_WALL_TIME, UCAL_WALLTIME_FIRST);
+    ucal_clear(ucal);
+    ucal_setDateTime(ucal, 2011, 3-1, 13, 2, 30, 0, &status);
+    t = ucal_getMillis(ucal, &status);
+    expected = 1299997800000.0; /* 2011-03-13T06:30:00Z */
+    if (U_FAILURE(status)) {
+        log_err("FAIL: Calculating time 2011-03-13 02:30:00 with UCAL_WALLTIME_FIRST - %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
+    } else if (t != expected) {
+        log_data_err("FAIL: 2011-03-13 02:30:00 with UCAL_WALLTIME_FIRST - got: %f, expected: %f\n", t, expected);
+    }
+
+    /* UCAL_WALLTIME_LAST on US spring transition */
+    ucal_setAttribute(ucal, UCAL_SKIPPED_WALL_TIME, UCAL_WALLTIME_LAST);
+    ucal_clear(ucal);
+    ucal_setDateTime(ucal, 2011, 3-1, 13, 2, 30, 0, &status);
+    t = ucal_getMillis(ucal, &status);
+    expected = 1300001400000.0; /* 2011-03-13T07:30:00Z */
+    if (U_FAILURE(status)) {
+        log_err("FAIL: Calculating time 2011-03-13 02:30:00 with UCAL_WALLTIME_LAST - %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
+    } else if (t != expected) {
+        log_data_err("FAIL: 2011-03-13 02:30:00 with UCAL_WALLTIME_LAST - got: %f, expected: %f\n", t, expected);
+    }
+
+    /* UCAL_WALLTIME_NEXT_VALID on US spring transition */
+    ucal_setAttribute(ucal, UCAL_SKIPPED_WALL_TIME, UCAL_WALLTIME_NEXT_VALID);
+    ucal_clear(ucal);
+    ucal_setDateTime(ucal, 2011, 3-1, 13, 2, 30, 0, &status);
+    t = ucal_getMillis(ucal, &status);
+    expected = 1299999600000.0; /* 2011-03-13T07:00:00Z */
+    if (U_FAILURE(status)) {
+        log_err("FAIL: Calculating time 2011-03-13 02:30:00 with UCAL_WALLTIME_NEXT_VALID - %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
+    } else if (t != expected) {
+        log_data_err("FAIL: 2011-03-13 02:30:00 with UCAL_WALLTIME_NEXT_VALID - got: %f, expected: %f\n", t, expected);
+    }
+
+    /* non-lenient on US spring transition */
+    ucal_setAttribute(ucal, UCAL_LENIENT, 0);
+    ucal_clear(ucal);
+    ucal_setDateTime(ucal, 2011, 3-1, 13, 2, 30, 0, &status);
+    t = ucal_getMillis(ucal, &status);
+    if (U_SUCCESS(status)) {
+        /* must return error */
+        log_data_err("FAIL: Non-lenient did not fail with 2011-03-13 02:30:00\n");
+        status = U_ZERO_ERROR;
+    }
+
+    ucal_close(ucal);
+}
+
 #endif /* #if !UCONFIG_NO_FORMATTING */