/********************************************************************
* 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)*/
#include "ccaltst.h"
#include "cformtst.h"
+void TestGregorianChange(void);
+
void addCalTest(TestNode** root);
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" */
{
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;
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);
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) {
-
+ ctest_setTimeZone(NULL, &status);
+
/*testing ucal_setTimeZone() function*/
log_verbose("\nTesting if the function ucal_setTimeZone() works fine\n");
ucal_setMillis(caldef2, d2, &status);
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();
+
/*----------------------------* */
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));
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);
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);
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);
}
+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 */