home *** CD-ROM | disk | FTP | other *** search
- /*
- *****************************************************************************************
- * *
- * COPYRIGHT: *
- * (C) Copyright Taligent, Inc., 1996 *
- * (C) Copyright International Business Machines Corporation, 1999 *
- * Licensed Material - Program-Property of IBM - All Rights Reserved. *
- * US Government Users Restricted Rights - Use, duplication, or disclosure *
- * restricted by GSA ADP Schedule Contract with IBM Corp. *
- * *
- *****************************************************************************************
- ********************************************************************************
- *
- * File CCALTST.C
- *
- * Modification History:
- * Name Description
- * Madhu Katragadda Creation
- *********************************************************************************
-
- /* C API AND FUNCTIONALITY TEST FOR CALENDAR (ucol.h)*/
-
- #include "uloc.h"
- #include "utypes.h"
- #include "ucal.h"
- #include "udat.h"
- #include "ustring.h"
- #include "cintltst.h"
- #include "ccaltst.h"
- #include <stdio.h>
- #include <string.h>
- #include "cformtst.h"
-
-
- void addCalTest(TestNode** root)
- {
-
- addTest(root, &TestCalendar, "tsformat/ccaltst/TestCalendar");
- addTest(root, &TestGetSetDateAPI, "tsformat/ccaltst/TestGetSetDateAPI");
- addTest(root, &TestFieldGetSet, "tsformat/ccaltst/TestFieldGetSet");
- addTest(root, &TestAddRollExtensive, "tsformat/ccaltst/TestAddRollExtensive");
- addTest(root, &TestGetLimits, "tsformat/ccaltst/TestGetLimits");
- addTest(root, &TestDOWProgression, "tsformat/ccaltst/TestDOWProgression");
- addTest(root, &TestGMTvsLocal, "tsformat/ccaltst/TestGMTvsLocal");
-
- }
-
- void TestCalendar()
- {
- UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0;
- int32_t count, count2, offset,i;
- UChar *tzID = 0;
- UChar *tzdname = 0;
- UErrorCode status = U_ZERO_ERROR;
- UDate now;
- UDateFormat *datdef = 0;
- UChar *result = 0;
- int32_t resultlength, resultlengthneeded;
-
-
- /*Testing countAvailableTimeZones*/
- offset=0;
- log_verbose("\nTesting countAvialableTimeZoneIds\n");
- count=ucal_countAvailableTZIDs(offset);
- log_verbose("The number of timezone id's present with offset 0 are %d:\n", count);
- if(count!=23)
- log_err("FAIL: error in the countAvialabelTZIDs\n");
-
- /*Testing getAvialableTZIDs*/
- log_verbose("\nTesting getAvialableTimezoneids");
- for(i=0;i<count;i++){
- ucal_getAvailableTZIDs(offset, i, &status);
- if(U_FAILURE(status)){
- log_err("FAIL: There is an error in the getAvialableTZIDs the error is %s\n", myErrorName(status));
- }
- log_verbose("%s\n", austrdup(ucal_getAvailableTZIDs(offset, i, &status)));
- }
-
-
-
- /*Testing the ucal_open() function*/
- 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", myErrorName(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", myErrorName(status));
- }
- u_uastrcpy(tzID, "GMT");
- 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", myErrorName(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", myErrorName(status));
- }
-
-
- /*Testing udat_getAvailable() and udat_countAvailable()*/
- log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
- count=ucal_countAvailable();
- /* use something sensible w/o hardcoding the count */
- if(count > 0){
- log_verbose("PASS: ucal_countAvialable() works fine\n");
- log_verbose("The no: of locales for which calendars are avilable are %d\n", count);
- }
- else
- log_err("FAIL: Error in countAvialable()\n");
-
- /*for(i=0;i<count;i++) */
- /*log_verbose("%s\n", uloc_getName(ucal_getAvailable(i))); */
-
-
- /*Testing the equality between calendar's*/
- log_verbose("\nTesting ucal_equivalentTo()\n");
- if(ucal_equivalentTo(caldef, caldef2) == FALSE || ucal_equivalentTo(caldef, calfr)== TRUE ||
- ucal_equivalentTo(caldef, calit)== TRUE)
- log_err("FAIL: Error. equivalentTo test failed\n");
- else
- log_verbose("PASS: equivalentTo test passed\n");
-
-
- /*Testing the current time and date using ucal_getnow()*/
- log_verbose("\nTesting the ucal_getNow function to check if it is fetching tbe current time\n");
- now=ucal_getNow();
- /* open the date format and format the date to check the output */
- datdef=udat_open(UDAT_FULL,UDAT_FULL ,NULL, NULL, 0,&status);
- if(U_FAILURE(status)){
- log_err("FAIL: error in creating the dateformat : %s\n", myErrorName(status));
- }
- log_verbose("PASS: The current date and time fetched is %s\n", austrdup(myDateFormat(datdef, now)) );
-
-
- /*Testing the TimeZoneDisplayName */
- log_verbose("\nTesting the fetching of time zone display name\n");
- /*for the US locale */
- resultlength=0;
- resultlengthneeded=ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", NULL, resultlength, &status);
-
- if(status==U_BUFFER_OVERFLOW_ERROR)
- {
- status=U_ZERO_ERROR;
- resultlength=resultlengthneeded+1;
- result=(UChar*)malloc(sizeof(UChar) * resultlength);
- ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", result, resultlength, &status);
- }
- if(U_FAILURE(status)) {
- log_err("FAIL: Error in getting the timezone display name : %s\n", myErrorName(status));
- }
- else{
- log_verbose("PASS: getting the time zone display name successful : \n");
- }
-
- tzdname=(UChar*)malloc(sizeof(UChar) * (resultlengthneeded+1));
- u_uastrcpy(tzdname, "Pacific Daylight Time");
- if(u_strcmp(tzdname, result)==0){
- log_verbose("PASS: got the correct time zone display name %s\n", austrdup(result) );
- }
- else{
- log_err("FAIL: got the wrong time zone display name %s\n", austrdup(result) );
- }
-
-
-
- /*testing the setAttributes and getAttributes of a UCalendar*/
- log_verbose("\nTesting the getAttributes and set Attributes\n");
- count=ucal_getAttribute(calit, UCAL_LENIENT);
- count2=ucal_getAttribute(calfr, UCAL_LENIENT);
- ucal_setAttribute(calit, UCAL_LENIENT, 0);
- ucal_setAttribute(caldef, UCAL_LENIENT, count2);
- if( ucal_getAttribute(calit, UCAL_LENIENT) !=0 ||
- ucal_getAttribute(calfr, UCAL_LENIENT)!=ucal_getAttribute(caldef, UCAL_LENIENT) )
- log_err("FAIL: there is an error in getAttributes or setAttributes\n");
- else
- log_verbose("PASS: attribute set and got successfully\n");
- /*set it back to orginal value */
- log_verbose("Setting it back to normal\n");
- ucal_setAttribute(calit, UCAL_LENIENT, count);
- if(ucal_getAttribute(calit, UCAL_LENIENT)!=count)
- log_err("FAIL: Error in setting the attribute back to normal\n");
-
- /*setting the first day of the week to other values */
- count=ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK);
- for (i=1; i<=7; ++i) {
- ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,i);
- if (ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK) != i)
- log_err("FAIL: set/getFirstDayOfWeek failed\n");
- }
-
- /*set it back to normal */
- ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,count);
- /*setting minimal days of the week to other values */
- count=ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK);
- for (i=0; i<=7; ++i) {
- ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,i);
- if (ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK) != i)
- log_err("FAIL: set/getMinimalDaysInFirstWeek failed\n");
- }
- /*set it back to normal */
- ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,count);
-
-
- /*testing if the UCalendar's timezone is currently in day light saving's time*/
- log_verbose("\nTesting if the UCalendar is currently in daylight saving's time\n");
- ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 10, 45, 20, &status);
- ucal_inDaylightTime(caldef, &status );
- if(U_FAILURE(status)) {
- log_err("Error in ucal_inDaylightTime: %s\n", myErrorName(status));
- }
- if(!ucal_inDaylightTime(caldef, &status))
- 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);
- /*closing the UDateFormat used */
- udat_close(datdef);
- free(tzID);
- free(result);
- free(tzdname);
-
- }
-
- /*------------------------------------------------------*/
- /*Testing the getMillis, setMillis, setDate and setDateTime functions extensively*/
-
- /* "GMT" */
- static const UChar fgGMTID [] = { 0x0047, 0x004d, 0x0054, 0x0000 };
-
- void TestGetSetDateAPI()
- {
- UCalendar *caldef = 0, *caldef2 = 0;
- UChar *tzID =0;
- UDate d1;
- int32_t hour;
- UDateFormat *datdef = 0;
- UErrorCode status=U_ZERO_ERROR;
- UDate d2= 837039928046.0;
- UChar temp[30];
-
- log_verbose("\nOpening the calendars()\n");
- tzID=(UChar*)malloc(sizeof(UChar) * 4);
- u_uastrcpy(tzID, "GMT");
- /*open the calendars used */
- caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
- caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
- /*open the dateformat */
- datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL,fgGMTID,-1, &status);
- if(U_FAILURE(status))
- {
- log_err("error in creating the dateformat : %s\n", myErrorName(status));
- }
-
-
- /*Testing getMillis and setMillis */
- log_verbose("\nTesting the date and time fetched in millis for a calendar using getMillis\n");
- d1=ucal_getMillis(caldef, &status);
- if(U_FAILURE(status)){
- log_err("Error in getMillis : %s\n", myErrorName(status));
- }
-
- /*testing setMillis */
- log_verbose("\nTesting the set date and time function using setMillis\n");
- ucal_setMillis(caldef, d2, &status);
- if(U_FAILURE(status)){
- log_err("Error in setMillis : %s\n", myErrorName(status));
- }
-
- /*testing if the calendar date is set properly or not */
- d1=ucal_getMillis(caldef, &status);
- if(u_strcmp(myDateFormat(datdef, d1), myDateFormat(datdef, d2))!=0)
- log_err("error in setMillis or getMillis\n");
- /*-------------------*/
-
-
-
-
- /*testing ucal_setTimeZone() function*/
- log_verbose("\nTesting if the function ucal_setTimeZone() works fine\n");
- ucal_setMillis(caldef2, d2, &status);
- if(U_FAILURE(status)){
- log_err("Error in getMillis : %s\n", myErrorName(status));;
- }
- hour=ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status);
-
- u_uastrcpy(tzID, "PST");
- ucal_setTimeZone(caldef2,tzID, 3, &status);
- if(U_FAILURE(status)){
- log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", myErrorName(status));
- }
- else
- log_verbose("ucal_setTimeZone worked fine\n");
- if(hour == ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status))
- log_err("FAIL: Error setting the time zone doesn't change the represented time\n");
- else if((hour-8 + 1) != ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status)) /*because it is not in daylight savings time */
- log_err("FAIL: Error setTimeZone doesn't change the represented time correctly with 8 hour offset\n");
- else
- log_verbose("PASS: setTimeZone works fine\n");
-
- /*testing setTimeZone roundtrip */
- log_verbose("\nTesting setTimeZone() roundtrip\n");
- u_uastrcpy(tzID, "GMT");
- ucal_setTimeZone(caldef2, tzID, 3, &status);
- if(U_FAILURE(status)){
- log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", myErrorName(status));
- }
- if(d2==ucal_getMillis(caldef2, &status))
- log_verbose("PASS: setTimeZone roundtrip test passed\n");
- else
- log_err("FAIL: setTimeZone roundtrip test failed\n");
- /*----------------------------* */
-
-
-
- /*Testing if setDate works fine */
- log_verbose("\nTesting the ucal_setDate() function \n");
- u_uastrcpy(temp, "Dec 17, 1971 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", myErrorName(status));
- }
- /*checking if the calendar date is set properly or not */
- d1=ucal_getMillis(caldef, &status);
- if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
- log_verbose("PASS:setDate works fine\n");
- else
- log_err("FAIL:Error in setDate()\n");
-
-
- /* Testing setDate Extensively with various input values */
- log_verbose("\nTesting ucal_setDate() extensively\n");
- ucal_setDate(caldef, 1999, UCAL_JANUARY, 10, &status);
- verify1("1999 10th day of January is :", caldef, datdef, 1999, UCAL_JANUARY, 10);
- ucal_setDate(caldef, 1999, UCAL_DECEMBER, 3, &status);
- verify1("1999 3rd day of December is :", caldef, datdef, 1999, UCAL_DECEMBER, 3);
- ucal_setDate(caldef, 2000, UCAL_MAY, 3, &status);
- verify1("2000 3rd day of May is :", caldef, datdef, 2000, UCAL_MAY, 3);
- ucal_setDate(caldef, 1999, UCAL_AUGUST, 32, &status);
- verify1("1999 32th day of August is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1);
- ucal_setDate(caldef, 1999, UCAL_MARCH, 0, &status);
- verify1("1999 0th day of March is :", caldef, datdef, 1999, UCAL_FEBRUARY, 28);
- ucal_setDate(caldef, 0, UCAL_MARCH, 12, &status);
-
- /*--------------------*/
-
- /*Testing if setDateTime works fine */
- log_verbose("\nTesting the ucal_setDateTime() function \n");
- u_uastrcpy(temp, "May 3, 1972 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", myErrorName(status));
- }
- /*checking if the calendar date is set properly or not */
- d1=ucal_getMillis(caldef, &status);
- if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
- log_verbose("PASS: setDateTime works fine\n");
- else
- log_err("FAIL: Error in setDateTime\n");
-
-
-
- /*Testing setDateTime extensively with various input values*/
- log_verbose("\nTesting ucal_setDateTime() function extensively\n");
- ucal_setDateTime(caldef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, &status);
- verify2("1999 10th day of October at 6:45:30 is :", caldef, datdef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, 0 );
- ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 15, 10, 55, &status);
- verify2("1999 3rd day of March at 15:10:55 is :", caldef, datdef, 1999, UCAL_MARCH, 3, 3, 10, 55, 1);
- ucal_setDateTime(caldef, 1999, UCAL_MAY, 3, 25, 30, 45, &status);
- verify2("1999 3rd day of May at 25:30:45 is :", caldef, datdef, 1999, UCAL_MAY, 4, 1, 30, 45, 0);
- ucal_setDateTime(caldef, 1999, UCAL_AUGUST, 32, 22, 65, 40, &status);
- verify2("1999 32th day of August at 22:65:40 is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1, 11, 5, 40,1);
- ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, 0, 0, 0,&status);
- verify2("1999 12th day of March at 0:0:0 is :", caldef, datdef, 1999, UCAL_MARCH, 12, 0, 0, 0, 0);
- ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, -10, -10,0, &status);
- verify2("1999 12th day of March is at -10:-10:0 :", caldef, datdef, 1999, UCAL_MARCH, 11, 1, 50, 0, 1);
-
-
-
- /*close caldef and datdef*/
- ucal_close(caldef);
- udat_close(datdef);
- free(tzID);
-
- }
-
- /*----------------------------------------------------------- */
- /**
- * Confirm the functioning of the calendar field related functions.
- */
- void TestFieldGetSet()
- {
- UCalendar *cal = 0;
- UChar *tzID = 0;
- 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_uastrcpy(tzID, "GMT");
- /*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", myErrorName(status));
- return;
- }
- datdef=udat_open(UDAT_SHORT,UDAT_SHORT ,NULL,fgGMTID,-1, &status);
- if(U_FAILURE(status))
- {
- log_err("error in creating the dateformat : %s\n", myErrorName(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", myErrorName(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");
- 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");
- else
- log_verbose("PASS: ucal_get() works fine\n");
-
- /*Testing the ucal_set() , ucal_clear() functions of calendar*/
- log_verbose("\nTesting the set, and clear field functions of calendar\n");
- ucal_setAttribute(cal, UCAL_LENIENT, 0);
- ucal_clear(cal);
- ucal_set(cal, UCAL_YEAR, 1997);
- ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
- ucal_set(cal, UCAL_DATE, 3);
- verify1("1997 third day of June = ", cal, datdef, 1997, UCAL_JUNE, 3);
- 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, 1);
- verify1("1997 first Tuesday in June = ", cal, datdef, 1997, UCAL_JUNE, 3);
- 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, - 1);
- 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_WEEK_OF_MONTH, 1);
- verify1("1997 Tuesday in week 1 of June = ", cal,datdef, 1997, UCAL_JUNE, 3);
- 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_WEEK_OF_MONTH, 5);
- verify1("1997 Tuesday in week 5 of June = ", cal,datdef, 1997, UCAL_JULY, 1);
- 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_WEEK_OF_MONTH, 0);
- verify1("1997 Tuesday in week 0 of June = ", cal, datdef , 1997, UCAL_MAY, 27);
- ucal_clear(cal);
- ucal_set(cal, UCAL_YEAR, 1997);
- ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
- ucal_set(cal, UCAL_WEEK_OF_YEAR, 1);
- verify1("1997 Tuesday in week 1 of year = ", cal, datdef,1996, UCAL_DECEMBER, 31);
- ucal_clear(cal);
- ucal_set(cal, UCAL_YEAR, 1997);
- ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
- ucal_set(cal, UCAL_WEEK_OF_YEAR, 10);
- verify1("1997 Tuesday in week 10 of year = ", cal,datdef, 1997, UCAL_MARCH, 4);
- ucal_clear(cal);
- ucal_set(cal, UCAL_YEAR, 1999);
- 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");
-
- ucal_setAttribute(cal, UCAL_LENIENT, 1);
-
- ucal_set(cal, UCAL_MONTH, -3);
- verify1("1999 -3th month should be", cal, datdef, 1998, UCAL_OCTOBER, 1);
-
-
- /*testing isSet and clearField()*/
- if(!ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
- log_err("FAIL: error in isSet\n");
- else
- log_verbose("PASS: isSet working fine\n");
- ucal_clearField(cal, UCAL_WEEK_OF_YEAR);
- if(ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
- log_err("FAIL: there is an error in clearField or isSet\n");
- else
- log_verbose("PASS :clearField working fine\n");
-
- /*-------------------------------*/
-
- ucal_close(cal);
- udat_close(datdef);
- free(tzID);
-
- }
-
-
-
- /* ------------------------------------- */
- /**
- * Execute adding and rolling in Calendar extensively,
- */
- void TestAddRollExtensive()
- {
- UCalendar *cal = 0;
- int32_t i,limit;
- UChar* tzID = 0;
- UCalendarDateFields e;
- int32_t y,m,d,hr,min,sec,ms;
- int32_t maxlimit = 40;
- UErrorCode status = U_ZERO_ERROR;
- y = 1997; m = UCAL_FEBRUARY; d = 1; hr = 1; min = 1; sec = 0; ms = 0;
-
- 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", myErrorName(status));
- return;
- }
-
- ucal_set(cal, UCAL_YEAR, y);
- ucal_set(cal, UCAL_MONTH, m);
- ucal_set(cal, UCAL_DATE, d);
-
- /* Confirm that adding to various fields works.*/
- log_verbose("\nTesting to confirm that adding to various fields works with ucal_add()\n");
- checkDate(cal, y, m, d);
- ucal_add(cal,UCAL_YEAR, 1, &status);
- if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status)); return; }
- y++;
- checkDate(cal, y, m, d);
- ucal_add(cal,UCAL_MONTH, 12, &status);
- if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
- y+=1;
- checkDate(cal, y, m, d);
- ucal_add(cal,UCAL_DATE, 1, &status);
- if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
- d++;
- checkDate(cal, y, m, d);
- ucal_add(cal,UCAL_DATE, 2, &status);
- if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
- d += 2;
- checkDate(cal, y, m, d);
- ucal_add(cal,UCAL_DATE, 28, &status);
- if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
- ++m;
- checkDate(cal, y, m, d);
- ucal_add(cal, -1, 10, &status);
- if(status==U_ILLEGAL_ARGUMENT_ERROR)
- log_verbose("Pass: Illegal argument error as expected\n");
- else{
- log_err("Fail: No, illegal argument error as expected. Got....: %s\n", myErrorName(status));
- }
- status=U_ZERO_ERROR;
-
-
- /*confirm that applying roll to various fields works fine*/
- log_verbose("\nTesting to confirm that ucal_roll() works\n");
- ucal_roll(cal, UCAL_DATE, -1, &status);
- if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
- d -=1;
- checkDate(cal, y, m, d);
- ucal_roll(cal, UCAL_MONTH, -2, &status);
- if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
- m -=2;
- checkDate(cal, y, m, d);
- ucal_roll(cal, UCAL_DATE, 1, &status);
- if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
- d +=1;
- checkDate(cal, y, m, d);
- ucal_roll(cal, UCAL_MONTH, -12, &status);
- if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
- checkDate(cal, y, m, d);
- ucal_roll(cal, UCAL_YEAR, -1, &status);
- if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
- y -=1;
- checkDate(cal, y, m, d);
- ucal_roll(cal, UCAL_DATE, 29, &status);
- if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
- d = 2;
- checkDate(cal, y, m, d);
- ucal_roll(cal, -1, 10, &status);
- if(status==U_ILLEGAL_ARGUMENT_ERROR)
- log_verbose("Pass: illegal arguement error as expected\n");
- else{
- log_err("Fail: no illegal argument error got..: %s\n", myErrorName(status));
- return;
- }
- status=U_ZERO_ERROR;
- ucal_setDateTime(cal, 1999, UCAL_FEBRUARY, 28, 10, 30, 45, &status);
- if(U_FAILURE(status)){
- log_err("error is setting the datetime: %s\n", myErrorName(status));
- }
- ucal_add(cal, UCAL_MONTH, 1, &status);
- checkDate(cal, 1999, UCAL_MARCH, 28);
- ucal_add(cal, UCAL_MILLISECOND, 1000, &status);
- checkDateTime(cal, 1999, UCAL_MARCH, 28, 10, 30, 46, 0, UCAL_MILLISECOND);
-
- ucal_close(cal);
- /*--------------- */
- status=U_ZERO_ERROR;
- /* Testing add and roll extensively */
- log_verbose("\nTesting the ucal_add() and ucal_roll() functions extensively\n");
- y = 1997; m = UCAL_FEBRUARY; d = 1; hr = 1; min = 1; sec = 0; ms = 0;
- cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_open failed: %s\n", myErrorName(status));
- return;
- }
- ucal_set(cal, UCAL_YEAR, y);
- ucal_set(cal, UCAL_MONTH, m);
- ucal_set(cal, UCAL_DATE, d);
- ucal_set(cal, UCAL_HOUR, hr);
- ucal_set(cal, UCAL_MINUTE, min);
- ucal_set(cal, UCAL_SECOND,sec);
- ucal_set(cal, UCAL_MILLISECOND, ms);
- status=U_ZERO_ERROR;
-
- log_verbose("\nTesting UCalendar add...\n");
- for(e = UCAL_YEAR;e < UCAL_FIELD_COUNT; e=(UCalendarDateFields)((int32_t)e + 1)) {
- limit = maxlimit;
- status = U_ZERO_ERROR;
- for (i = 0; i < limit; i++) {
- ucal_add(cal, e, 1, &status);
- if (U_FAILURE(status)) { limit = i; status = U_ZERO_ERROR; }
- }
- for (i = 0; i < limit; i++) {
- ucal_add(cal, e, -1, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_add -1 failed: %s\n", myErrorName(status));
- return;
- }
- }
- checkDateTime(cal, y, m, d, hr, min, sec, ms, e);
- }
- log_verbose("\nTesting calendar ucal_roll()...\n");
- for(e = UCAL_YEAR;e < UCAL_FIELD_COUNT; e=(UCalendarDateFields)((int32_t)e + 1)) {
- int32_t limit = maxlimit;
- status = U_ZERO_ERROR;
- for (i = 0; i < limit; i++) {
- ucal_roll(cal, e, 1, &status);
- if (U_FAILURE(status)) { limit = i; status = U_ZERO_ERROR; }
- }
- for (i = 0; i < limit; i++) {
- ucal_roll(cal, e, -1, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_roll -1 failed: %s\n", myErrorName(status));
- return;
- }
- }
- checkDateTime(cal, y, m, d, hr, min, sec, ms, e);
- }
-
- ucal_close(cal);
- free(tzID);
- }
-
- /*------------------------------------------------------ */
- /*Testing the Limits for various Fields of Calendar*/
- void TestGetLimits()
- {
- UCalendar *cal = 0;
- int32_t min, max, gr_min, le_max, ac_min, ac_max, val;
- UChar* tzID = 0;
- 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", myErrorName(status));
- return;
- }
-
- log_verbose("\nTesting the getLimits function for various fields\n");
-
-
-
- ucal_setDate(cal, 1999, UCAL_MARCH, 5, &status); /* Set the date to be March 5, 1999 */
- 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)){
- 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);
- }
- else
- log_verbose("getLimits successful\n");
-
- 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)){
- 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);
-
- }
- else
- log_verbose("getLimits successful\n");
-
- min=ucal_getLimit(cal, UCAL_MONTH, UCAL_MINIMUM, &status);
- max=ucal_getLimit(cal, UCAL_MONTH, UCAL_MAXIMUM, &status);
- gr_min=ucal_getLimit(cal, UCAL_MONTH, UCAL_GREATEST_MINIMUM, &status);
- le_max=ucal_getLimit(cal, UCAL_MONTH, UCAL_LEAST_MAXIMUM, &status);
- ac_min=ucal_getLimit(cal, UCAL_MONTH, UCAL_ACTUAL_MINIMUM, &status);
- ac_max=ucal_getLimit(cal, UCAL_MONTH, UCAL_ACTUAL_MAXIMUM, &status);
- if(U_FAILURE(status)){
- log_err("Error in getLimits: %s\n", myErrorName(status));
- }
- if(min!=0 || max!=11 || gr_min!=0 || le_max!=11 || ac_min!=0 || ac_max!=11)
- log_err("There is and error in getLimits in fetching the values\n");
- else
- log_verbose("getLimits successful\n");
-
- ucal_setDateTime(cal, 1999, UCAL_MARCH, 5, 4, 10, 35, &status);
- val=ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
- min=ucal_getLimit(cal, UCAL_HOUR_OF_DAY, UCAL_MINIMUM, &status);
- max=ucal_getLimit(cal, UCAL_HOUR_OF_DAY, UCAL_MAXIMUM, &status);
- gr_min=ucal_getLimit(cal, UCAL_MINUTE, UCAL_GREATEST_MINIMUM, &status);
- le_max=ucal_getLimit(cal, UCAL_MINUTE, UCAL_LEAST_MAXIMUM, &status);
- 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){
-
- log_err("FAIL: Min/max bad\n");
- log_err("FAIL: Hour of Day %d out of range\n", val);
- log_err("FAIL: HOUR_OF_DAY should be 4 Got %d\n", val);
- }
- else
- log_verbose("getLimits successful\n");
-
-
-
- ucal_close(cal);
- free(tzID);
- }
-
-
-
- /* ------------------------------------- */
-
- /**
- * Test that the days of the week progress properly when add is called repeatedly
- * for increments of 24 days.
- */
- void TestDOWProgression()
- {
- int32_t initialDOW, DOW, newDOW, expectedDOW;
- UCalendar *cal = 0;
- UDateFormat *datfor = 0;
- UDate date1;
- int32_t delta=24;
- UErrorCode status = U_ZERO_ERROR;
- UChar* tzID = 0;
- tzID=(UChar*)malloc(sizeof(UChar) * 4);
- u_uastrcpy(tzID, "GMT");
- /*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", myErrorName(status));
- return;
- }
-
- datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1, &status);
- if(U_FAILURE(status)){
- log_err("error in creating the dateformat : %s\n", myErrorName(status));
- }
-
-
- ucal_setDate(cal, 1999, UCAL_JANUARY, 1, &status);
-
- 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", myErrorName(status) ); return; }
- newDOW = initialDOW;
- do {
- DOW = newDOW;
- log_verbose("DOW = %d...\n", DOW);
- date1=ucal_getMillis(cal, &status);
- if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", myErrorName(status)); return;}
- log_verbose("%s\n", austrdup(myDateFormat(datfor, date1)));
-
- ucal_add(cal,UCAL_DAY_OF_WEEK, delta, &status);
- if (U_FAILURE(status)) { log_err("ucal_add() failed: %s\n", myErrorName(status)); return; }
-
- newDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
- if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", myErrorName(status)); return; }
- expectedDOW = 1 + (DOW + delta - 1) % 7;
- date1=ucal_getMillis(cal, &status);
- if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", myErrorName(status)); return;}
- if (newDOW != expectedDOW) {
- log_err("Day of week should be %d instead of %d on %s", expectedDOW, newDOW,
- austrdup(myDateFormat(datfor, date1)) );
- return;
- }
- }
- while (newDOW != initialDOW);
-
- ucal_close(cal);
- udat_close(datfor);
- free(tzID);
-
- }
-
- /* ------------------------------------- */
-
- /**
- * Confirm that the offset between local time and GMT behaves as expected.
- */
- void TestGMTvsLocal()
- {
- log_verbose("\nTesting the offset between the GMT and local time\n");
- testZones(1999, 1, 1, 12, 0, 0);
- testZones(1999, 4, 16, 18, 30, 0);
- testZones(1998, 12, 17, 19, 0, 0);
- }
-
- /* ------------------------------------- */
-
- void testZones(int32_t yr, int32_t mo, int32_t dt, int32_t hr, int32_t mn, int32_t sc)
- {
- int32_t offset,utc, expected;
- UCalendar *gmtcal = 0, *cal = 0;
- UDate date1;
- double temp;
- UDateFormat *datfor = 0;
- UErrorCode status = U_ZERO_ERROR;
- UChar* tzID = 0;
- tzID=(UChar*)malloc(sizeof(UChar) * 4);
- u_uastrcpy(tzID, "GMT");
- gmtcal=ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);;
- if (U_FAILURE(status)) {
- log_err("ucal_open failed: %s\n", myErrorName(status));
- return;
- }
- u_uastrcpy(tzID, "PST");
- cal = ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_open failed: %s\n", myErrorName(status));
- return;
- }
-
- datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1, &status);
- if(U_FAILURE(status)){
- log_err("error in creating the dateformat : %s\n", myErrorName(status));
- }
-
- ucal_setDateTime(gmtcal, yr, mo - 1, dt, hr, mn, sc, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_setDateTime failed: %s\n", myErrorName(status));
- return;
- }
- ucal_set(gmtcal, UCAL_MILLISECOND, 0);
- date1 = ucal_getMillis(gmtcal, &status);
- if (U_FAILURE(status)) { log_err("ucal_getMillis failed: %s\n", myErrorName(status)); return; }
- log_verbose("date = %s\n", austrdup(myDateFormat(datfor, date1)) );
-
-
- ucal_setMillis(cal, date1, &status);
- if (U_FAILURE(status)) { log_err("ucal_setMillis() failed: %s\n", myErrorName(status)); return; }
-
- offset = ucal_get(cal, UCAL_ZONE_OFFSET, &status);
- offset += ucal_get(cal, UCAL_DST_OFFSET, &status);
-
- if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", myErrorName(status)); return; }
- temp=(double)((double)offset / 1000.0 / 60.0 / 60.0);
- /*printf("offset for %s %f hr\n", austrdup(myDateFormat(datfor, date1)), temp);*/
-
- utc = ((ucal_get(cal, UCAL_HOUR_OF_DAY, &status) * 60 +
- ucal_get(cal, UCAL_MINUTE, &status)) * 60 +
- ucal_get(cal, UCAL_SECOND, &status)) * 1000 +
- ucal_get(cal, UCAL_MILLISECOND, &status) - offset;
- if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", myErrorName(status)); return; }
-
- expected = ((hr * 60 + mn) * 60 + sc) * 1000;
- if (utc != expected) {
- temp=(double)(utc - expected)/ 1000 / 60 / 60.0;
- printf("FAIL: Discrepancy of %d millis = %fhr\n", utc-expected, temp );
- }
- else
- log_verbose("PASS: the offset between local and GMT is correct\n");
- ucal_close(gmtcal);
- ucal_close(cal);
- udat_close(datfor);
- free(tzID);
- }
-
- /* ------------------------------------- */
-
-
-
-
- /* INTERNAL FUNCTIONS USED */
- /*------------------------------------------------------------------------------------------- */
-
- /* ------------------------------------- */
- void checkDateTime(UCalendar* c,
- int32_t y, int32_t m, int32_t d,
- int32_t hr, int32_t min, int32_t sec,
- int32_t ms, UCalendarDateFields field)
-
- {
- UErrorCode status = U_ZERO_ERROR;
- if (ucal_get(c, UCAL_YEAR, &status) != y ||
- ucal_get(c, UCAL_MONTH, &status) != m ||
- ucal_get(c, UCAL_DATE, &status) != d ||
- ucal_get(c, UCAL_HOUR, &status) != hr ||
- ucal_get(c, UCAL_MINUTE, &status) != min ||
- ucal_get(c, UCAL_SECOND, &status) != sec ||
- ucal_get(c, UCAL_MILLISECOND, &status) != ms) {
- log_err("U_FAILURE for field %d, Expected y/m/d h:m:s:ms of %d/%d/%d %d:%d:%d:%d got %d/%d/%d %d:%d:%d:%d\n",
- (int32_t)field, y, m + 1, d, hr, min, sec, ms,
- ucal_get(c, UCAL_YEAR, &status),
- ucal_get(c, UCAL_MONTH, &status) + 1,
- ucal_get(c, UCAL_DATE, &status),
- ucal_get(c, UCAL_HOUR, &status),
- ucal_get(c, UCAL_MINUTE, &status) + 1,
- ucal_get(c, UCAL_SECOND, &status),
- ucal_get(c, UCAL_MILLISECOND, &status) );
-
- if (U_FAILURE(status)){
- log_err("ucal_get failed: %s\n", myErrorName(status));
- return;
- }
-
- }
- else
- log_verbose("Confirmed: %d/%d/%d %d:%d:%d:%d\n", y, m + 1, d, hr, min, sec, ms);
-
- }
-
- /* ------------------------------------- */
- void checkDate(UCalendar* c, int32_t y, int32_t m, int32_t d)
-
- {
- UErrorCode status = U_ZERO_ERROR;
- if (ucal_get(c,UCAL_YEAR, &status) != y ||
- ucal_get(c, UCAL_MONTH, &status) != m ||
- ucal_get(c, UCAL_DATE, &status) != d) {
-
- log_err("FAILURE: Expected y/m/d of %d/%d/%d got %d/%d/%d\n", y, m + 1, d,
- ucal_get(c, UCAL_YEAR, &status),
- ucal_get(c, UCAL_MONTH, &status) + 1,
- ucal_get(c, UCAL_DATE, &status) );
-
- if (U_FAILURE(status)) {
- log_err("ucal_get failed: %s\n", myErrorName(status));
- return;
- }
- }
- else
- log_verbose("Confirmed: %d/%d/%d\n", y, m + 1, d);
-
-
- }
-
- /* ------------------------------------- */
-
- /* ------------------------------------- */
-
- void verify1(const char* msg, UCalendar* c, UDateFormat* dat, int32_t year, int32_t month, int32_t day)
- {
- UDate d1;
- UErrorCode status = U_ZERO_ERROR;
- if (ucal_get(c, UCAL_YEAR, &status) == year &&
- ucal_get(c, UCAL_MONTH, &status) == month &&
- ucal_get(c, UCAL_DATE, &status) == day) {
- if (U_FAILURE(status)) {
- log_err("FAIL: Calendar::get failed: %s\n", myErrorName(status));
- return;
- }
- log_verbose("PASS: %s\n", msg);
- d1=ucal_getMillis(c, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_getMillis failed: %s\n", myErrorName(status));
- return;
- }
- /*log_verbose(austrdup(myDateFormat(dat, d1)) );*/
- }
- else {
- log_err("FAIL: %s\n", msg);
- d1=ucal_getMillis(c, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_getMillis failed: %s\n", myErrorName(status) );
- return;
- }
- log_err("Got %s Expected %d/%d/%d \n", austrdup(myDateFormat(dat, d1)), year, month + 1, day );
- return;
- }
-
-
- }
-
- /* ------------------------------------ */
- void verify2(const char* msg, UCalendar* c, UDateFormat* dat, int32_t year, int32_t month, int32_t day,
- int32_t hour, int32_t min, int32_t sec, int32_t am_pm)
- {
- UDate d1;
- char str[3];
- UErrorCode status = U_ZERO_ERROR;
- if (ucal_get(c, UCAL_YEAR, &status) == year &&
- ucal_get(c, UCAL_MONTH, &status) == month &&
- ucal_get(c, UCAL_DATE, &status) == day &&
- ucal_get(c, UCAL_HOUR, &status) == hour &&
- ucal_get(c, UCAL_MINUTE, &status) == min &&
- ucal_get(c, UCAL_SECOND, &status) == sec &&
- ucal_get(c, UCAL_AM_PM, &status) == am_pm ){
- if (U_FAILURE(status)) {
- log_err("FAIL: Calendar::get failed: %s\n", myErrorName(status));
- return;
- }
- log_verbose("PASS: %s\n", msg);
- d1=ucal_getMillis(c, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_getMillis failed: %s\n", myErrorName(status));
- return;
- }
- log_verbose("%s\n" , austrdup(myDateFormat(dat, d1)) );
- }
- else {
- log_err("FAIL: %s\n", msg);
- d1=ucal_getMillis(c, &status);
- if (U_FAILURE(status)) {
- log_err("ucal_getMillis failed: %s\n", myErrorName(status));
- return;
- }
- if(am_pm==0)
- strcpy(str,"AM");
- else
- strcpy(str,"PM");
- log_err("Got %s Expected %d/%d/%d/ %d:%d:%d %s\n", austrdup(myDateFormat(dat, d1)),
- year, month + 1, day, hour, min, sec, str);
-
- return;
- }
-
-
- }
-
- /*--------------------------------------------- */
-