home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / ccaltst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  41.6 KB  |  1,094 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1999                    *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. ********************************************************************************
  13. *
  14. * File CCALTST.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda               Creation
  19. *********************************************************************************
  20.  
  21. /* C API AND FUNCTIONALITY TEST FOR CALENDAR (ucol.h)*/
  22.  
  23. #include "uloc.h"
  24. #include "utypes.h"
  25. #include "ucal.h"
  26. #include "udat.h"
  27. #include "ustring.h"
  28. #include "cintltst.h"
  29. #include "ccaltst.h"
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include "cformtst.h"
  33.  
  34.  
  35. void addCalTest(TestNode** root)
  36. {
  37.  
  38.     addTest(root, &TestCalendar, "tsformat/ccaltst/TestCalendar");
  39.     addTest(root, &TestGetSetDateAPI, "tsformat/ccaltst/TestGetSetDateAPI");
  40.     addTest(root, &TestFieldGetSet, "tsformat/ccaltst/TestFieldGetSet");
  41.     addTest(root, &TestAddRollExtensive, "tsformat/ccaltst/TestAddRollExtensive");
  42.     addTest(root, &TestGetLimits, "tsformat/ccaltst/TestGetLimits");
  43.     addTest(root, &TestDOWProgression, "tsformat/ccaltst/TestDOWProgression");
  44.     addTest(root, &TestGMTvsLocal, "tsformat/ccaltst/TestGMTvsLocal");
  45.  
  46. }
  47.  
  48. void TestCalendar()
  49. {
  50.     UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0;
  51.     int32_t count, count2, offset,i;
  52.     UChar *tzID = 0;
  53.     UChar *tzdname = 0;
  54.     UErrorCode status = U_ZERO_ERROR;
  55.     UDate now;
  56.     UDateFormat *datdef = 0;
  57.     UChar *result = 0;
  58.     int32_t resultlength, resultlengthneeded;
  59.  
  60.     
  61.     /*Testing countAvailableTimeZones*/
  62.     offset=0;
  63.     log_verbose("\nTesting countAvialableTimeZoneIds\n");
  64.     count=ucal_countAvailableTZIDs(offset);
  65.     log_verbose("The number of timezone id's present with offset 0 are %d:\n", count);
  66.     if(count!=23)
  67.         log_err("FAIL: error in the countAvialabelTZIDs\n");
  68.  
  69.     /*Testing getAvialableTZIDs*/
  70.     log_verbose("\nTesting getAvialableTimezoneids");
  71.     for(i=0;i<count;i++){
  72.         ucal_getAvailableTZIDs(offset, i, &status);
  73.         if(U_FAILURE(status)){
  74.             log_err("FAIL: There is an error in the getAvialableTZIDs the error is %s\n", myErrorName(status));
  75.         }
  76.         log_verbose("%s\n", austrdup(ucal_getAvailableTZIDs(offset, i, &status)));
  77.     }
  78.  
  79.     
  80.  
  81.     /*Testing the  ucal_open() function*/
  82.     log_verbose("\nTesting the ucal_open()\n");
  83.     tzID=(UChar*)malloc(sizeof(UChar) * 4);
  84.     u_uastrcpy(tzID, "PST");
  85.     caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
  86.     if(U_FAILURE(status)){
  87.         log_err("FAIL: error in ucal_open caldef : %s\n", myErrorName(status));
  88.     }
  89.     
  90.     caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
  91.     if(U_FAILURE(status)){
  92.         log_err("FAIL: error in ucal_open caldef : %s\n", myErrorName(status));
  93.     }
  94.     u_uastrcpy(tzID, "GMT");
  95.     calfr=ucal_open(tzID, u_strlen(tzID), "fr_FR", UCAL_TRADITIONAL, &status);
  96.     if(U_FAILURE(status)){
  97.         log_err("FAIL: error in ucal_open calfr : %s\n", myErrorName(status));
  98.     }
  99.     calit=ucal_open(tzID, u_strlen(tzID), "it_IT", UCAL_TRADITIONAL, &status);
  100.     if(U_FAILURE(status))    {
  101.         log_err("FAIL: error in ucal_open calit : %s\n", myErrorName(status));
  102.     }
  103.     
  104.     
  105.     /*Testing udat_getAvailable() and udat_countAvailable()*/ 
  106.     log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
  107.     count=ucal_countAvailable();
  108.     /* use something sensible w/o hardcoding the count */
  109.     if(count > 0){
  110.         log_verbose("PASS: ucal_countAvialable() works fine\n");
  111.         log_verbose("The no: of locales for which calendars are avilable are %d\n", count);
  112.     }
  113.     else
  114.         log_err("FAIL: Error in countAvialable()\n");
  115.  
  116.     /*for(i=0;i<count;i++) */
  117.         /*log_verbose("%s\n", uloc_getName(ucal_getAvailable(i))); */
  118.     
  119.  
  120.     /*Testing the equality between calendar's*/
  121.     log_verbose("\nTesting ucal_equivalentTo()\n");
  122.     if(ucal_equivalentTo(caldef, caldef2) == FALSE || ucal_equivalentTo(caldef, calfr)== TRUE || 
  123.         ucal_equivalentTo(caldef, calit)== TRUE)
  124.         log_err("FAIL: Error. equivalentTo test failed\n");
  125.     else
  126.         log_verbose("PASS: equivalentTo test passed\n");
  127.     
  128.  
  129.     /*Testing the current time and date using ucal_getnow()*/
  130.     log_verbose("\nTesting the ucal_getNow function to check if it is fetching tbe current time\n");
  131.     now=ucal_getNow();
  132.     /* open the date format and format the date to check the output */
  133.     datdef=udat_open(UDAT_FULL,UDAT_FULL ,NULL, NULL, 0,&status);
  134.     if(U_FAILURE(status)){
  135.         log_err("FAIL: error in creating the dateformat : %s\n", myErrorName(status));
  136.     }
  137.     log_verbose("PASS: The current date and time fetched is %s\n", austrdup(myDateFormat(datdef, now)) );
  138.     
  139.     
  140.     /*Testing the TimeZoneDisplayName */
  141.     log_verbose("\nTesting the fetching of time zone display name\n");
  142.     /*for the US locale */
  143.     resultlength=0;
  144.     resultlengthneeded=ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", NULL, resultlength, &status);
  145.     
  146.     if(status==U_BUFFER_OVERFLOW_ERROR)
  147.     {
  148.         status=U_ZERO_ERROR;
  149.         resultlength=resultlengthneeded+1;
  150.         result=(UChar*)malloc(sizeof(UChar) * resultlength);
  151.         ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", result, resultlength, &status);
  152.     }
  153.     if(U_FAILURE(status))    {
  154.         log_err("FAIL: Error in getting the timezone display name : %s\n", myErrorName(status));
  155.     }
  156.     else{    
  157.         log_verbose("PASS: getting the time zone display name successful : \n");
  158.     }
  159.     
  160.     tzdname=(UChar*)malloc(sizeof(UChar) * (resultlengthneeded+1));
  161.     u_uastrcpy(tzdname, "Pacific Daylight Time");
  162.     if(u_strcmp(tzdname, result)==0){
  163.         log_verbose("PASS: got the correct time zone display name %s\n", austrdup(result) );
  164.     }
  165.     else{
  166.         log_err("FAIL: got the wrong time zone display name %s\n", austrdup(result) );
  167.     }
  168.  
  169.  
  170.     
  171.     /*testing the setAttributes and getAttributes of a UCalendar*/
  172.     log_verbose("\nTesting the getAttributes and set Attributes\n");
  173.     count=ucal_getAttribute(calit, UCAL_LENIENT);
  174.     count2=ucal_getAttribute(calfr, UCAL_LENIENT);
  175.     ucal_setAttribute(calit, UCAL_LENIENT, 0);
  176.     ucal_setAttribute(caldef, UCAL_LENIENT, count2);
  177.     if( ucal_getAttribute(calit, UCAL_LENIENT) !=0 || 
  178.         ucal_getAttribute(calfr, UCAL_LENIENT)!=ucal_getAttribute(caldef, UCAL_LENIENT) )
  179.         log_err("FAIL: there is an error in getAttributes or setAttributes\n");
  180.     else
  181.         log_verbose("PASS: attribute set and got successfully\n");
  182.         /*set it back to orginal value */
  183.     log_verbose("Setting it back to normal\n");
  184.     ucal_setAttribute(calit, UCAL_LENIENT, count);
  185.     if(ucal_getAttribute(calit, UCAL_LENIENT)!=count)
  186.         log_err("FAIL: Error in setting the attribute back to normal\n");
  187.     
  188.     /*setting the first day of the week to other values  */
  189.     count=ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK);
  190.     for (i=1; i<=7; ++i) {
  191.         ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,i);
  192.         if (ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK) != i) 
  193.             log_err("FAIL: set/getFirstDayOfWeek failed\n");
  194.     }
  195.  
  196.     /*set it back to normal */
  197.     ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,count);
  198.     /*setting minimal days of the week to other values */
  199.     count=ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK);
  200.     for (i=0; i<=7; ++i) {
  201.         ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,i);
  202.         if (ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK) != i) 
  203.             log_err("FAIL: set/getMinimalDaysInFirstWeek failed\n");
  204.     }
  205.     /*set it back to normal */
  206.     ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,count);
  207.     
  208.     
  209.     /*testing if the UCalendar's timezone is currently in day light saving's time*/
  210.     log_verbose("\nTesting if the UCalendar is currently in daylight saving's time\n");
  211.     ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 10, 45, 20, &status); 
  212.     ucal_inDaylightTime(caldef, &status );
  213.     if(U_FAILURE(status))    {
  214.         log_err("Error in ucal_inDaylightTime: %s\n", myErrorName(status));
  215.     }
  216.     if(!ucal_inDaylightTime(caldef, &status))
  217.         log_verbose("PASS: It is  not in daylight saving's time\n");
  218.     else
  219.         log_err("FAIL: It is not in daylight saving's time\n");
  220.  
  221.     
  222.     
  223.     /*closing the UCalendar*/
  224.     ucal_close(caldef);
  225.     ucal_close(caldef2);
  226.     ucal_close(calfr);
  227.     ucal_close(calit);
  228.     /*closing the UDateFormat used */
  229.     udat_close(datdef);
  230.     free(tzID);
  231.     free(result);
  232.     free(tzdname);
  233.     
  234. }
  235.  
  236. /*------------------------------------------------------*/
  237. /*Testing the getMillis, setMillis, setDate and setDateTime functions extensively*/
  238.  
  239. /* "GMT" */
  240. static const UChar fgGMTID [] = { 0x0047, 0x004d, 0x0054, 0x0000 };
  241.  
  242. void TestGetSetDateAPI()
  243. {
  244.     UCalendar *caldef = 0, *caldef2 = 0;
  245.     UChar *tzID =0;
  246.     UDate d1;
  247.     int32_t hour;
  248.     UDateFormat *datdef = 0;
  249.     UErrorCode status=U_ZERO_ERROR;
  250.     UDate d2= 837039928046.0;
  251.     UChar temp[30];
  252.  
  253.     log_verbose("\nOpening the calendars()\n");
  254.     tzID=(UChar*)malloc(sizeof(UChar) * 4);
  255.     u_uastrcpy(tzID, "GMT");
  256.     /*open the calendars used */
  257.     caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
  258.     caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
  259.     /*open the dateformat */
  260.     datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL,fgGMTID,-1, &status);
  261.     if(U_FAILURE(status))
  262.     {
  263.         log_err("error in creating the dateformat : %s\n", myErrorName(status));
  264.     }
  265.     
  266.  
  267.     /*Testing getMillis and setMillis */
  268.     log_verbose("\nTesting the date and time fetched in millis for a calendar using getMillis\n");
  269.     d1=ucal_getMillis(caldef, &status);
  270.     if(U_FAILURE(status)){
  271.         log_err("Error in getMillis : %s\n", myErrorName(status));
  272.     }
  273.     
  274.     /*testing setMillis */
  275.     log_verbose("\nTesting the set date and time function using setMillis\n");
  276.     ucal_setMillis(caldef, d2, &status);
  277.     if(U_FAILURE(status)){
  278.         log_err("Error in setMillis : %s\n", myErrorName(status));
  279.     }
  280.  
  281.     /*testing if the calendar date is set properly or not  */
  282.     d1=ucal_getMillis(caldef, &status);
  283.     if(u_strcmp(myDateFormat(datdef, d1), myDateFormat(datdef, d2))!=0)
  284.         log_err("error in setMillis or getMillis\n");
  285.     /*-------------------*/
  286.     
  287.     
  288.     
  289.     
  290.     /*testing ucal_setTimeZone() function*/
  291.     log_verbose("\nTesting if the function ucal_setTimeZone() works fine\n");
  292.     ucal_setMillis(caldef2, d2, &status); 
  293.     if(U_FAILURE(status)){
  294.         log_err("Error in getMillis : %s\n", myErrorName(status));;
  295.     }
  296.     hour=ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status);
  297.         
  298.     u_uastrcpy(tzID, "PST");
  299.     ucal_setTimeZone(caldef2,tzID, 3, &status);
  300.     if(U_FAILURE(status)){
  301.         log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", myErrorName(status));
  302.     }
  303.     else
  304.         log_verbose("ucal_setTimeZone worked fine\n");
  305.     if(hour == ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status))
  306.         log_err("FAIL: Error setting the time zone doesn't change the represented time\n");
  307.     else if((hour-8 + 1) != ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status)) /*because it is not in daylight savings time */
  308.         log_err("FAIL: Error setTimeZone doesn't change the represented time correctly with 8 hour offset\n");
  309.     else
  310.         log_verbose("PASS: setTimeZone works fine\n");
  311.         
  312.     /*testing setTimeZone roundtrip */
  313.     log_verbose("\nTesting setTimeZone() roundtrip\n");
  314.     u_uastrcpy(tzID, "GMT");
  315.     ucal_setTimeZone(caldef2, tzID, 3, &status);
  316.     if(U_FAILURE(status)){
  317.         log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", myErrorName(status));
  318.     }
  319.     if(d2==ucal_getMillis(caldef2, &status))
  320.         log_verbose("PASS: setTimeZone roundtrip test passed\n");
  321.     else
  322.         log_err("FAIL: setTimeZone roundtrip test failed\n");
  323. /*----------------------------*     */
  324.     
  325.     
  326.  
  327.     /*Testing  if setDate works fine  */
  328.     log_verbose("\nTesting the ucal_setDate() function \n");
  329.     u_uastrcpy(temp, "Dec 17, 1971 11:05:28 PM");
  330.     ucal_setDate(caldef,1971, UCAL_DECEMBER, 17, &status);
  331.     if(U_FAILURE(status)){
  332.         log_err("error in setting the calendar date : %s\n", myErrorName(status));
  333.     }
  334.     /*checking if the calendar date is set properly or not  */
  335.     d1=ucal_getMillis(caldef, &status);
  336.     if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
  337.         log_verbose("PASS:setDate works fine\n");
  338.     else
  339.         log_err("FAIL:Error in setDate()\n");
  340.  
  341.     
  342.     /* Testing setDate Extensively with various input values */
  343.     log_verbose("\nTesting ucal_setDate() extensively\n");
  344.     ucal_setDate(caldef, 1999, UCAL_JANUARY, 10, &status);
  345.     verify1("1999  10th day of January  is :", caldef, datdef, 1999, UCAL_JANUARY, 10);
  346.     ucal_setDate(caldef, 1999, UCAL_DECEMBER, 3, &status);
  347.     verify1("1999 3rd day of December  is :", caldef, datdef, 1999, UCAL_DECEMBER, 3);
  348.     ucal_setDate(caldef, 2000, UCAL_MAY, 3, &status);
  349.     verify1("2000 3rd day of May is :", caldef, datdef, 2000, UCAL_MAY, 3);
  350.     ucal_setDate(caldef, 1999, UCAL_AUGUST, 32, &status);
  351.     verify1("1999 32th day of August is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1);
  352.     ucal_setDate(caldef, 1999, UCAL_MARCH, 0, &status); 
  353.     verify1("1999 0th day of March is :", caldef, datdef, 1999, UCAL_FEBRUARY, 28);
  354.     ucal_setDate(caldef, 0, UCAL_MARCH, 12, &status);
  355.     
  356.     /*--------------------*/
  357.  
  358.     /*Testing if setDateTime works fine */
  359.     log_verbose("\nTesting the ucal_setDateTime() function \n");
  360.     u_uastrcpy(temp, "May 3, 1972 4:30:42 PM");
  361.     ucal_setDateTime(caldef,1972, UCAL_MAY, 3, 16, 30, 42, &status);
  362.     if(U_FAILURE(status)){
  363.         log_err("error in setting the calendar date : %s\n", myErrorName(status));
  364.     }
  365.     /*checking  if the calendar date is set properly or not  */
  366.     d1=ucal_getMillis(caldef, &status);
  367.     if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
  368.         log_verbose("PASS: setDateTime works fine\n");
  369.     else
  370.         log_err("FAIL: Error in setDateTime\n");
  371.  
  372.     
  373.     
  374.     /*Testing setDateTime extensively with various input values*/
  375.     log_verbose("\nTesting ucal_setDateTime() function extensively\n");
  376.     ucal_setDateTime(caldef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, &status);
  377.     verify2("1999  10th day of October  at 6:45:30 is :", caldef, datdef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, 0 );
  378.     ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 15, 10, 55, &status);
  379.     verify2("1999 3rd day of March   at 15:10:55 is :", caldef, datdef, 1999, UCAL_MARCH, 3, 3, 10, 55, 1);
  380.     ucal_setDateTime(caldef, 1999, UCAL_MAY, 3, 25, 30, 45, &status);
  381.     verify2("1999 3rd day of May at 25:30:45 is :", caldef, datdef, 1999, UCAL_MAY, 4, 1, 30, 45, 0);
  382.     ucal_setDateTime(caldef, 1999, UCAL_AUGUST, 32, 22, 65, 40, &status);
  383.     verify2("1999 32th day of August at 22:65:40 is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1, 11, 5, 40,1);
  384.     ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, 0, 0, 0,&status);
  385.     verify2("1999 12th day of March at 0:0:0 is :", caldef, datdef, 1999, UCAL_MARCH, 12, 0, 0, 0, 0);
  386.     ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, -10, -10,0, &status);
  387.     verify2("1999 12th day of March is at -10:-10:0 :", caldef, datdef, 1999, UCAL_MARCH, 11, 1, 50, 0, 1);
  388.     
  389.     
  390.     
  391.     /*close caldef and datdef*/
  392.     ucal_close(caldef);
  393.     udat_close(datdef);
  394.     free(tzID);
  395.  
  396. }
  397.  
  398. /*----------------------------------------------------------- */
  399. /**
  400.  * Confirm the functioning of the calendar field related functions.
  401.  */
  402. void TestFieldGetSet()
  403. {
  404.     UCalendar *cal = 0;
  405.     UChar *tzID = 0;
  406.     UDateFormat *datdef = 0;
  407.     UDate d1;
  408.     UErrorCode status=U_ZERO_ERROR;
  409.     log_verbose("\nFetching pointer to UCalendar using the ucal_open()\n");
  410.     tzID=(UChar*)malloc(sizeof(UChar) * 4);
  411.     u_uastrcpy(tzID, "GMT");
  412.     /*open the calendar used */
  413.     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
  414.     if (U_FAILURE(status)) {
  415.         log_err("ucal_open failed: %s\n", myErrorName(status));
  416.         return; 
  417.     }
  418.     datdef=udat_open(UDAT_SHORT,UDAT_SHORT ,NULL,fgGMTID,-1, &status);
  419.     if(U_FAILURE(status))
  420.     {
  421.         log_err("error in creating the dateformat : %s\n", myErrorName(status));
  422.     }
  423.     
  424.     /*Testing ucal_get()*/
  425.     log_verbose("\nTesting the ucal_get() function of Calendar\n");
  426.     ucal_setDateTime(cal, 1999, UCAL_MARCH, 12, 5, 25, 30, &status);
  427.     if(U_FAILURE(status)){
  428.         log_err("error in the setDateTime() : %s\n", myErrorName(status));
  429.     }
  430.     if(ucal_get(cal, UCAL_YEAR, &status)!=1999 || ucal_get(cal, UCAL_MONTH, &status)!=2 || 
  431.         ucal_get(cal, UCAL_DATE, &status)!=12 || ucal_get(cal, UCAL_HOUR, &status)!=5)
  432.         log_err("error in ucal_get()\n");    
  433.     else if(ucal_get(cal, UCAL_DAY_OF_WEEK_IN_MONTH, &status)!=2 || ucal_get(cal, UCAL_DAY_OF_WEEK, &status)!=6
  434.         || ucal_get(cal, UCAL_WEEK_OF_MONTH, &status)!=2 || ucal_get(cal, UCAL_WEEK_OF_YEAR, &status)!= 11)
  435.         log_err("FAIL: error in ucal_get()\n");
  436.     else
  437.         log_verbose("PASS: ucal_get() works fine\n");
  438.  
  439.     /*Testing the ucal_set() , ucal_clear() functions of calendar*/
  440.     log_verbose("\nTesting the set, and clear  field functions of calendar\n");
  441.     ucal_setAttribute(cal, UCAL_LENIENT, 0);
  442.     ucal_clear(cal);
  443.     ucal_set(cal, UCAL_YEAR, 1997);
  444.     ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
  445.     ucal_set(cal, UCAL_DATE, 3);
  446.     verify1("1997 third day of June = ", cal, datdef, 1997, UCAL_JUNE, 3);
  447.     ucal_clear(cal);
  448.     ucal_set(cal, UCAL_YEAR, 1997);
  449.     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  450.     ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
  451.     ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 1);
  452.     verify1("1997 first Tuesday in June = ", cal, datdef, 1997, UCAL_JUNE, 3);
  453.     ucal_clear(cal);
  454.     ucal_set(cal, UCAL_YEAR, 1997);
  455.     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  456.     ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
  457.     ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, - 1);
  458.     verify1("1997 last Tuesday in June = ", cal, datdef,1997,   UCAL_JUNE, 24);
  459.     /*give undesirable input    */
  460.     status = U_ZERO_ERROR;
  461.         ucal_clear(cal);
  462.         ucal_set(cal, UCAL_YEAR, 1997);
  463.         ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  464.         ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
  465.         ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 0);
  466.         d1=ucal_getMillis(cal,&status);
  467.         if (status != U_ILLEGAL_ARGUMENT_ERROR){ 
  468.             log_err("FAIL: No IllegalArgumentError for :");
  469.             log_err("1997 zero-th Tuesday in June \n");
  470.         }
  471.         else 
  472.             log_verbose("PASS: IllegalArgumentError as expected\n");
  473.    
  474.     ucal_clear(cal);
  475.     ucal_set(cal, UCAL_YEAR, 1997);
  476.     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  477.     ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
  478.     ucal_set(cal, UCAL_WEEK_OF_MONTH, 1);
  479.     verify1("1997 Tuesday in week 1 of June = ", cal,datdef, 1997, UCAL_JUNE, 3);
  480.     ucal_clear(cal);
  481.     ucal_set(cal, UCAL_YEAR, 1997);
  482.     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  483.     ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
  484.     ucal_set(cal, UCAL_WEEK_OF_MONTH, 5);
  485.     verify1("1997 Tuesday in week 5 of June = ", cal,datdef, 1997, UCAL_JULY, 1);
  486.     status = U_ZERO_ERROR;
  487.     ucal_clear(cal);
  488.     ucal_set(cal, UCAL_YEAR, 1997);
  489.     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  490.     ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
  491.     ucal_set(cal, UCAL_WEEK_OF_MONTH, 0);
  492.     verify1("1997 Tuesday in week 0 of June = ", cal, datdef , 1997, UCAL_MAY, 27);
  493.     ucal_clear(cal);
  494.     ucal_set(cal, UCAL_YEAR, 1997);
  495.     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  496.     ucal_set(cal, UCAL_WEEK_OF_YEAR, 1);
  497.     verify1("1997 Tuesday in week 1 of year = ", cal, datdef,1996, UCAL_DECEMBER, 31);
  498.     ucal_clear(cal);
  499.     ucal_set(cal, UCAL_YEAR, 1997);
  500.     ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
  501.     ucal_set(cal, UCAL_WEEK_OF_YEAR, 10);
  502.     verify1("1997 Tuesday in week 10 of year = ", cal,datdef, 1997, UCAL_MARCH, 4);
  503.     ucal_clear(cal);
  504.     ucal_set(cal, UCAL_YEAR, 1999);
  505.     ucal_set(cal, UCAL_DAY_OF_YEAR, 1);
  506.     verify1("1999 1st day of the year =", cal, datdef, 1999, UCAL_JANUARY, 1);
  507.     ucal_set(cal, UCAL_MONTH, -3);
  508.     d1=ucal_getMillis(cal,&status);
  509.         if (status != U_ILLEGAL_ARGUMENT_ERROR){ 
  510.             log_err("FAIL: No IllegalArgumentError for :\"1999 -3th month \" ");
  511.         }
  512.         else 
  513.             log_verbose("PASS: IllegalArgumentError as expected\n");
  514.     
  515.     ucal_setAttribute(cal, UCAL_LENIENT, 1);
  516.     
  517.     ucal_set(cal, UCAL_MONTH, -3);
  518.     verify1("1999 -3th month should be", cal, datdef, 1998, UCAL_OCTOBER, 1);
  519.  
  520.  
  521.     /*testing isSet and clearField()*/
  522.     if(!ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
  523.         log_err("FAIL: error in isSet\n");
  524.     else
  525.         log_verbose("PASS: isSet working fine\n");
  526.     ucal_clearField(cal, UCAL_WEEK_OF_YEAR);
  527.     if(ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
  528.         log_err("FAIL: there is an error in clearField or isSet\n");
  529.     else
  530.         log_verbose("PASS :clearField working fine\n");
  531.  
  532.     /*-------------------------------*/
  533.  
  534.     ucal_close(cal);
  535.     udat_close(datdef);
  536.     free(tzID);
  537.     
  538. }
  539.  
  540.  
  541.  
  542. /* ------------------------------------- */
  543. /**
  544.  * Execute adding and rolling in Calendar extensively,
  545.  */
  546. void TestAddRollExtensive()
  547. {    
  548.     UCalendar *cal = 0;
  549.     int32_t i,limit;
  550.     UChar* tzID = 0;
  551.     UCalendarDateFields e;
  552.     int32_t y,m,d,hr,min,sec,ms;
  553.     int32_t maxlimit = 40;
  554.     UErrorCode status = U_ZERO_ERROR;
  555.     y = 1997; m = UCAL_FEBRUARY; d = 1; hr = 1; min = 1; sec = 0; ms = 0;
  556.    
  557.     log_verbose("Testing add and roll extensively\n");
  558.     
  559.     tzID=(UChar*)malloc(sizeof(UChar) * 4);
  560.     u_uastrcpy(tzID, "PST");
  561.     /*open the calendar used */
  562.     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);;
  563.     if (U_FAILURE(status)) {
  564.         log_err("ucal_open() failed : %s\n", myErrorName(status)); 
  565.         return; 
  566.     }
  567.  
  568.     ucal_set(cal, UCAL_YEAR, y);
  569.     ucal_set(cal, UCAL_MONTH, m);
  570.     ucal_set(cal, UCAL_DATE, d);
  571.  
  572.     /* Confirm that adding to various fields works.*/
  573.     log_verbose("\nTesting to confirm that adding to various fields works with ucal_add()\n");
  574.     checkDate(cal, y, m, d);
  575.     ucal_add(cal,UCAL_YEAR, 1, &status);
  576.     if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status)); return; }
  577.     y++;
  578.     checkDate(cal, y, m, d);
  579.     ucal_add(cal,UCAL_MONTH, 12, &status);
  580.     if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
  581.     y+=1;
  582.     checkDate(cal, y, m, d);
  583.     ucal_add(cal,UCAL_DATE, 1, &status);
  584.     if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
  585.     d++;
  586.     checkDate(cal, y, m, d);
  587.     ucal_add(cal,UCAL_DATE, 2, &status);
  588.     if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
  589.     d += 2;
  590.     checkDate(cal, y, m, d);
  591.     ucal_add(cal,UCAL_DATE, 28, &status);
  592.     if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", myErrorName(status) ); return; }
  593.     ++m;
  594.     checkDate(cal, y, m, d);
  595.     ucal_add(cal, -1, 10, &status);
  596.     if(status==U_ILLEGAL_ARGUMENT_ERROR)
  597.         log_verbose("Pass: Illegal argument error as expected\n");
  598.     else{
  599.         log_err("Fail: No, illegal argument error as expected. Got....: %s\n", myErrorName(status));
  600.     }
  601.     status=U_ZERO_ERROR;
  602.     
  603.  
  604.     /*confirm that applying roll to various fields works fine*/
  605.     log_verbose("\nTesting to confirm that ucal_roll() works\n");
  606.     ucal_roll(cal, UCAL_DATE, -1, &status);
  607.     if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
  608.     d -=1;
  609.     checkDate(cal, y, m, d);
  610.     ucal_roll(cal, UCAL_MONTH, -2, &status);
  611.     if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
  612.     m -=2;
  613.     checkDate(cal, y, m, d);
  614.     ucal_roll(cal, UCAL_DATE, 1, &status);
  615.     if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
  616.     d +=1;
  617.     checkDate(cal, y, m, d);
  618.     ucal_roll(cal, UCAL_MONTH, -12, &status);
  619.     if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
  620.     checkDate(cal, y, m, d);
  621.     ucal_roll(cal, UCAL_YEAR, -1, &status);
  622.     if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
  623.     y -=1;
  624.     checkDate(cal, y, m, d);
  625.     ucal_roll(cal, UCAL_DATE, 29, &status);
  626.     if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", myErrorName(status) ); return; }
  627.     d = 2;
  628.     checkDate(cal, y, m, d);
  629.     ucal_roll(cal, -1, 10, &status);
  630.     if(status==U_ILLEGAL_ARGUMENT_ERROR)
  631.         log_verbose("Pass: illegal arguement error as expected\n");
  632.     else{
  633.         log_err("Fail: no illegal argument error got..: %s\n", myErrorName(status));
  634.         return;
  635.     }
  636.     status=U_ZERO_ERROR;
  637.     ucal_setDateTime(cal, 1999, UCAL_FEBRUARY, 28, 10, 30, 45,  &status);
  638.     if(U_FAILURE(status)){
  639.         log_err("error is setting the datetime: %s\n", myErrorName(status));
  640.     }
  641.     ucal_add(cal, UCAL_MONTH, 1, &status);
  642.     checkDate(cal, 1999, UCAL_MARCH, 28);
  643.     ucal_add(cal, UCAL_MILLISECOND, 1000, &status);
  644.     checkDateTime(cal, 1999, UCAL_MARCH, 28, 10, 30, 46, 0, UCAL_MILLISECOND);
  645.  
  646.     ucal_close(cal);
  647. /*--------------- */
  648.     status=U_ZERO_ERROR;
  649.     /* Testing add and roll extensively */
  650.     log_verbose("\nTesting the ucal_add() and ucal_roll() functions extensively\n");
  651.     y = 1997; m = UCAL_FEBRUARY; d = 1; hr = 1; min = 1; sec = 0; ms = 0;
  652.     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
  653.     if (U_FAILURE(status)) {
  654.         log_err("ucal_open failed: %s\n", myErrorName(status));
  655.         return; 
  656.     }
  657.     ucal_set(cal, UCAL_YEAR, y);
  658.     ucal_set(cal, UCAL_MONTH, m);
  659.     ucal_set(cal, UCAL_DATE, d);
  660.     ucal_set(cal, UCAL_HOUR, hr);
  661.     ucal_set(cal, UCAL_MINUTE, min);
  662.     ucal_set(cal, UCAL_SECOND,sec);
  663.     ucal_set(cal, UCAL_MILLISECOND, ms);
  664.     status=U_ZERO_ERROR;
  665.  
  666.     log_verbose("\nTesting UCalendar add...\n");
  667.     for(e = UCAL_YEAR;e < UCAL_FIELD_COUNT; e=(UCalendarDateFields)((int32_t)e + 1)) {
  668.         limit = maxlimit;
  669.         status = U_ZERO_ERROR;
  670.         for (i = 0; i < limit; i++) {
  671.             ucal_add(cal, e, 1, &status);
  672.             if (U_FAILURE(status)) { limit = i; status = U_ZERO_ERROR; }
  673.         }
  674.         for (i = 0; i < limit; i++) {
  675.             ucal_add(cal, e, -1, &status);
  676.             if (U_FAILURE(status)) { 
  677.                 log_err("ucal_add -1 failed: %s\n", myErrorName(status));
  678.                 return; 
  679.             }
  680.         }
  681.         checkDateTime(cal, y, m, d, hr, min, sec, ms, e);
  682.     }
  683.     log_verbose("\nTesting calendar ucal_roll()...\n");
  684.     for(e = UCAL_YEAR;e < UCAL_FIELD_COUNT; e=(UCalendarDateFields)((int32_t)e + 1)) {
  685.         int32_t limit = maxlimit;
  686.         status = U_ZERO_ERROR;
  687.         for (i = 0; i < limit; i++) {
  688.             ucal_roll(cal, e, 1, &status);
  689.             if (U_FAILURE(status)) { limit = i; status = U_ZERO_ERROR; }
  690.         }
  691.         for (i = 0; i < limit; i++) {
  692.             ucal_roll(cal, e, -1, &status);
  693.             if (U_FAILURE(status)) { 
  694.                 log_err("ucal_roll -1 failed: %s\n", myErrorName(status));
  695.                 return; 
  696.             }
  697.         }
  698.         checkDateTime(cal, y, m, d, hr, min, sec, ms, e);
  699.     }
  700.  
  701.     ucal_close(cal);
  702.     free(tzID);
  703. }
  704.  
  705. /*------------------------------------------------------ */
  706. /*Testing the Limits for various Fields of Calendar*/
  707. void TestGetLimits()
  708. {
  709.     UCalendar *cal = 0;
  710.     int32_t min, max, gr_min, le_max, ac_min, ac_max, val;
  711.     UChar* tzID = 0;
  712.     UErrorCode status = U_ZERO_ERROR;
  713.     
  714.     
  715.     tzID=(UChar*)malloc(sizeof(UChar) * 4);
  716.     u_uastrcpy(tzID, "PST");
  717.     /*open the calendar used */
  718.     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);;
  719.     if (U_FAILURE(status)) {
  720.         log_err("ucal_open() for gregorian calendar failed in TestGetLimits: %s\n", myErrorName(status));
  721.         return; 
  722.     }
  723.     
  724.     log_verbose("\nTesting the getLimits function for various fields\n");
  725.     
  726.     
  727.     
  728.     ucal_setDate(cal, 1999, UCAL_MARCH, 5, &status); /* Set the date to be March 5, 1999 */
  729.     val = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
  730.     min = ucal_getLimit(cal, UCAL_DAY_OF_WEEK, UCAL_MINIMUM, &status);
  731.     max = ucal_getLimit(cal, UCAL_DAY_OF_WEEK, UCAL_MAXIMUM, &status);
  732.     if ( (min != UCAL_SUNDAY || max != UCAL_SATURDAY ) && (min > val > max)  && (val != UCAL_FRIDAY)){
  733.            log_err("FAIL: Min/max bad\n");
  734.            log_err("FAIL: Day of week %d out of range\n", val);
  735.            log_err("FAIL: FAIL: Day of week should be SUNDAY Got %d\n", val);
  736.     }
  737.     else
  738.         log_verbose("getLimits successful\n");
  739.  
  740.     val = ucal_get(cal, UCAL_DAY_OF_WEEK_IN_MONTH, &status);
  741.     min = ucal_getLimit(cal, UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_MINIMUM, &status);
  742.     max = ucal_getLimit(cal, UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_MAXIMUM, &status);
  743.     if ( (min != 0 || max != 5 ) && (min > val > max)  && (val != 1)){
  744.            log_err("FAIL: Min/max bad\n");
  745.            log_err("FAIL: Day of week in month %d out of range\n", val);
  746.            log_err("FAIL: FAIL: Day of week in month should be SUNDAY Got %d\n", val);
  747.         
  748.     }
  749.     else
  750.         log_verbose("getLimits successful\n");
  751.     
  752.     min=ucal_getLimit(cal, UCAL_MONTH, UCAL_MINIMUM, &status);
  753.     max=ucal_getLimit(cal, UCAL_MONTH, UCAL_MAXIMUM, &status);
  754.     gr_min=ucal_getLimit(cal, UCAL_MONTH, UCAL_GREATEST_MINIMUM, &status);
  755.     le_max=ucal_getLimit(cal, UCAL_MONTH, UCAL_LEAST_MAXIMUM, &status);
  756.     ac_min=ucal_getLimit(cal, UCAL_MONTH, UCAL_ACTUAL_MINIMUM, &status);
  757.     ac_max=ucal_getLimit(cal, UCAL_MONTH, UCAL_ACTUAL_MAXIMUM, &status);
  758.     if(U_FAILURE(status)){
  759.         log_err("Error in getLimits: %s\n", myErrorName(status));
  760.     }
  761.     if(min!=0 || max!=11 || gr_min!=0 || le_max!=11 || ac_min!=0 || ac_max!=11)
  762.         log_err("There is and error in getLimits in fetching the values\n");
  763.     else
  764.         log_verbose("getLimits successful\n");
  765.  
  766.     ucal_setDateTime(cal, 1999, UCAL_MARCH, 5, 4, 10, 35, &status);
  767.     val=ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
  768.     min=ucal_getLimit(cal, UCAL_HOUR_OF_DAY, UCAL_MINIMUM, &status);
  769.     max=ucal_getLimit(cal, UCAL_HOUR_OF_DAY, UCAL_MAXIMUM, &status);
  770.     gr_min=ucal_getLimit(cal, UCAL_MINUTE, UCAL_GREATEST_MINIMUM, &status);
  771.     le_max=ucal_getLimit(cal, UCAL_MINUTE, UCAL_LEAST_MAXIMUM, &status);
  772.     ac_min=ucal_getLimit(cal, UCAL_MINUTE, UCAL_ACTUAL_MINIMUM, &status);
  773.     ac_max=ucal_getLimit(cal, UCAL_SECOND, UCAL_ACTUAL_MAXIMUM, &status);
  774.     if( (min!=0 || max!= 11 || gr_min!=0 || le_max!=60 || ac_min!=0 || ac_max!=60) &&
  775.         (min>val>max) && val!=4){
  776.                 
  777.         log_err("FAIL: Min/max bad\n");
  778.         log_err("FAIL: Hour of Day %d out of range\n", val);
  779.         log_err("FAIL: HOUR_OF_DAY should be 4 Got %d\n", val);
  780.     }
  781.     else
  782.         log_verbose("getLimits successful\n");    
  783.  
  784.     
  785.  
  786.     ucal_close(cal);
  787.     free(tzID);
  788. }
  789.  
  790.  
  791.  
  792. /* ------------------------------------- */
  793.  
  794. /**
  795.  * Test that the days of the week progress properly when add is called repeatedly
  796.  * for increments of 24 days.
  797.  */
  798. void TestDOWProgression()
  799. {
  800.     int32_t initialDOW, DOW, newDOW, expectedDOW;
  801.     UCalendar *cal = 0;
  802.     UDateFormat *datfor = 0;
  803.     UDate date1;
  804.     int32_t delta=24;
  805.     UErrorCode status = U_ZERO_ERROR;
  806.     UChar* tzID = 0;
  807.     tzID=(UChar*)malloc(sizeof(UChar) * 4);
  808.     u_uastrcpy(tzID, "GMT");
  809.     /*open the calendar used */
  810.     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);;
  811.     if (U_FAILURE(status)) {
  812.         log_err("ucal_open failed: %s\n", myErrorName(status));
  813.         return; 
  814.     }
  815.  
  816.     datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1, &status);
  817.     if(U_FAILURE(status)){
  818.         log_err("error in creating the dateformat : %s\n", myErrorName(status));
  819.     }
  820.     
  821.  
  822.     ucal_setDate(cal, 1999, UCAL_JANUARY, 1, &status);
  823.  
  824.     log_verbose("\nTesting the DOW progression\n");
  825.     
  826.     initialDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
  827.     if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", myErrorName(status) ); return; }
  828.     newDOW = initialDOW;
  829.     do {
  830.         DOW = newDOW;
  831.         log_verbose("DOW = %d...\n", DOW);
  832.         date1=ucal_getMillis(cal, &status);
  833.         if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", myErrorName(status)); return;}
  834.         log_verbose("%s\n", austrdup(myDateFormat(datfor, date1)));
  835.         
  836.         ucal_add(cal,UCAL_DAY_OF_WEEK, delta, &status);
  837.         if (U_FAILURE(status)) { log_err("ucal_add() failed: %s\n", myErrorName(status)); return; }
  838.         
  839.         newDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
  840.         if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", myErrorName(status)); return; }
  841.         expectedDOW = 1 + (DOW + delta - 1) % 7;
  842.         date1=ucal_getMillis(cal, &status);
  843.         if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", myErrorName(status)); return;}
  844.         if (newDOW != expectedDOW) {
  845.             log_err("Day of week should be %d instead of %d on %s", expectedDOW, newDOW, 
  846.                 austrdup(myDateFormat(datfor, date1)) );    
  847.             return; 
  848.         }
  849.     }
  850.     while (newDOW != initialDOW);
  851.     
  852.     ucal_close(cal);
  853.     udat_close(datfor);
  854.     free(tzID);
  855.     
  856. }
  857.  
  858. /* ------------------------------------- */
  859.  
  860. /**
  861.  * Confirm that the offset between local time and GMT behaves as expected.
  862.  */
  863. void TestGMTvsLocal()
  864. {
  865.     log_verbose("\nTesting the offset between the GMT and local time\n");
  866.     testZones(1999, 1, 1, 12, 0, 0);
  867.     testZones(1999, 4, 16, 18, 30, 0);
  868.     testZones(1998, 12, 17, 19, 0, 0);
  869. }
  870.  
  871. /* ------------------------------------- */
  872.  
  873. void testZones(int32_t yr, int32_t mo, int32_t dt, int32_t hr, int32_t mn, int32_t sc)
  874. {
  875.     int32_t offset,utc, expected;
  876.     UCalendar *gmtcal = 0, *cal = 0;
  877.     UDate date1;
  878.     double temp;
  879.     UDateFormat *datfor = 0;
  880.     UErrorCode status = U_ZERO_ERROR;
  881.     UChar* tzID = 0;
  882.     tzID=(UChar*)malloc(sizeof(UChar) * 4);
  883.     u_uastrcpy(tzID, "GMT");
  884.     gmtcal=ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);;
  885.     if (U_FAILURE(status)) {
  886.         log_err("ucal_open failed: %s\n", myErrorName(status)); 
  887.         return; 
  888.     }
  889.     u_uastrcpy(tzID, "PST");
  890.     cal = ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);
  891.     if (U_FAILURE(status)) {
  892.         log_err("ucal_open failed: %s\n", myErrorName(status));
  893.         return; 
  894.     }
  895.     
  896.     datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1, &status);
  897.     if(U_FAILURE(status)){
  898.         log_err("error in creating the dateformat : %s\n", myErrorName(status));
  899.     }
  900.    
  901.     ucal_setDateTime(gmtcal, yr, mo - 1, dt, hr, mn, sc, &status);
  902.     if (U_FAILURE(status)) {
  903.         log_err("ucal_setDateTime failed: %s\n", myErrorName(status));
  904.         return; 
  905.     }
  906.     ucal_set(gmtcal, UCAL_MILLISECOND, 0);
  907.     date1 = ucal_getMillis(gmtcal, &status);
  908.     if (U_FAILURE(status)) { log_err("ucal_getMillis failed: %s\n", myErrorName(status)); return; }
  909.     log_verbose("date = %s\n", austrdup(myDateFormat(datfor, date1)) );
  910.  
  911.     
  912.     ucal_setMillis(cal, date1, &status);
  913.     if (U_FAILURE(status)) { log_err("ucal_setMillis() failed: %s\n", myErrorName(status)); return; }
  914.  
  915.     offset = ucal_get(cal, UCAL_ZONE_OFFSET, &status);
  916.     offset += ucal_get(cal, UCAL_DST_OFFSET, &status);
  917.    
  918.     if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", myErrorName(status)); return; }
  919.     temp=(double)((double)offset / 1000.0 / 60.0 / 60.0);
  920.     /*printf("offset for %s %f hr\n", austrdup(myDateFormat(datfor, date1)), temp);*/
  921.        
  922.     utc = ((ucal_get(cal, UCAL_HOUR_OF_DAY, &status) * 60 +
  923.                     ucal_get(cal, UCAL_MINUTE, &status)) * 60 +
  924.                    ucal_get(cal, UCAL_SECOND, &status)) * 1000 +
  925.                     ucal_get(cal, UCAL_MILLISECOND, &status) - offset;
  926.     if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", myErrorName(status)); return; }
  927.     
  928.     expected = ((hr * 60 + mn) * 60 + sc) * 1000;
  929.     if (utc != expected) {
  930.         temp=(double)(utc - expected)/ 1000 / 60 / 60.0;
  931.         printf("FAIL: Discrepancy of %d  millis = %fhr\n", utc-expected, temp );
  932.     }
  933.     else
  934.         log_verbose("PASS: the offset between local and GMT is correct\n");
  935.     ucal_close(gmtcal);
  936.     ucal_close(cal);
  937.     udat_close(datfor);
  938.     free(tzID);
  939. }
  940.  
  941. /* ------------------------------------- */
  942.  
  943.  
  944.  
  945.  
  946. /* INTERNAL FUNCTIONS USED */
  947. /*------------------------------------------------------------------------------------------- */
  948.  
  949. /* ------------------------------------- */
  950. void checkDateTime(UCalendar* c, 
  951.                         int32_t y, int32_t m, int32_t d, 
  952.                         int32_t hr, int32_t min, int32_t sec, 
  953.                         int32_t ms, UCalendarDateFields field)
  954.  
  955. {
  956.     UErrorCode status = U_ZERO_ERROR;
  957.     if (ucal_get(c, UCAL_YEAR, &status) != y ||
  958.         ucal_get(c, UCAL_MONTH, &status) != m ||
  959.         ucal_get(c, UCAL_DATE, &status) != d ||
  960.         ucal_get(c, UCAL_HOUR, &status) != hr ||
  961.         ucal_get(c, UCAL_MINUTE, &status) != min ||
  962.         ucal_get(c, UCAL_SECOND, &status) != sec ||
  963.         ucal_get(c, UCAL_MILLISECOND, &status) != ms) {
  964.         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",
  965.             (int32_t)field, y, m + 1, d, hr, min, sec, ms, 
  966.                     ucal_get(c, UCAL_YEAR, &status),
  967.                     ucal_get(c, UCAL_MONTH, &status) + 1,
  968.                     ucal_get(c, UCAL_DATE, &status),
  969.                     ucal_get(c, UCAL_HOUR, &status),
  970.                     ucal_get(c, UCAL_MINUTE, &status) + 1,
  971.                     ucal_get(c, UCAL_SECOND, &status),
  972.                     ucal_get(c, UCAL_MILLISECOND, &status) );
  973.  
  974.                     if (U_FAILURE(status)){
  975.                     log_err("ucal_get failed: %s\n", myErrorName(status)); 
  976.                     return; 
  977.                     }
  978.     
  979.      }
  980.     else 
  981.         log_verbose("Confirmed: %d/%d/%d %d:%d:%d:%d\n", y, m + 1, d, hr, min, sec, ms);
  982.         
  983. }
  984.  
  985. /* ------------------------------------- */
  986. void checkDate(UCalendar* c, int32_t y, int32_t m, int32_t d)
  987.  
  988. {
  989.     UErrorCode status = U_ZERO_ERROR;
  990.     if (ucal_get(c,UCAL_YEAR, &status) != y ||
  991.         ucal_get(c, UCAL_MONTH, &status) != m ||
  992.         ucal_get(c, UCAL_DATE, &status) != d) {
  993.         
  994.         log_err("FAILURE: Expected y/m/d of %d/%d/%d  got %d/%d/%d\n", y, m + 1, d, 
  995.                     ucal_get(c, UCAL_YEAR, &status),
  996.                     ucal_get(c, UCAL_MONTH, &status) + 1,
  997.                     ucal_get(c, UCAL_DATE, &status) );
  998.         
  999.         if (U_FAILURE(status)) { 
  1000.             log_err("ucal_get failed: %s\n", myErrorName(status));
  1001.             return; 
  1002.         }
  1003.     }
  1004.     else 
  1005.         log_verbose("Confirmed: %d/%d/%d\n", y, m + 1, d);
  1006.  
  1007.  
  1008. }
  1009.  
  1010. /* ------------------------------------- */
  1011.  
  1012. /* ------------------------------------- */
  1013.  
  1014. void verify1(const char* msg, UCalendar* c, UDateFormat* dat, int32_t year, int32_t month, int32_t day)
  1015. {
  1016.     UDate d1;
  1017.     UErrorCode status = U_ZERO_ERROR;
  1018.     if (ucal_get(c, UCAL_YEAR, &status) == year &&
  1019.         ucal_get(c, UCAL_MONTH, &status) == month &&
  1020.         ucal_get(c, UCAL_DATE, &status) == day) {
  1021.         if (U_FAILURE(status)) { 
  1022.             log_err("FAIL: Calendar::get failed: %s\n", myErrorName(status));
  1023.             return; 
  1024.         }
  1025.         log_verbose("PASS: %s\n", msg);
  1026.         d1=ucal_getMillis(c, &status);
  1027.         if (U_FAILURE(status)) { 
  1028.             log_err("ucal_getMillis failed: %s\n", myErrorName(status));
  1029.             return;
  1030.         }
  1031.     /*log_verbose(austrdup(myDateFormat(dat, d1)) );*/
  1032.     }
  1033.     else {
  1034.         log_err("FAIL: %s\n", msg);
  1035.         d1=ucal_getMillis(c, &status);
  1036.         if (U_FAILURE(status)) { 
  1037.             log_err("ucal_getMillis failed: %s\n", myErrorName(status) );
  1038.             return;
  1039.         }
  1040.         log_err("Got %s  Expected %d/%d/%d \n", austrdup(myDateFormat(dat, d1)), year, month + 1, day );
  1041.         return;
  1042.     }
  1043.  
  1044.         
  1045. }
  1046.  
  1047. /* ------------------------------------ */
  1048. void verify2(const char* msg, UCalendar* c, UDateFormat* dat, int32_t year, int32_t month, int32_t day, 
  1049.                                                                 int32_t hour, int32_t min, int32_t sec, int32_t am_pm)
  1050. {
  1051.     UDate d1;
  1052.     char str[3];
  1053.     UErrorCode status = U_ZERO_ERROR;
  1054.     if (ucal_get(c, UCAL_YEAR, &status) == year &&
  1055.         ucal_get(c, UCAL_MONTH, &status) == month &&
  1056.         ucal_get(c, UCAL_DATE, &status) == day &&
  1057.         ucal_get(c, UCAL_HOUR, &status) == hour &&
  1058.         ucal_get(c, UCAL_MINUTE, &status) == min &&
  1059.         ucal_get(c, UCAL_SECOND, &status) == sec &&
  1060.         ucal_get(c, UCAL_AM_PM, &status) == am_pm ){
  1061.         if (U_FAILURE(status)) { 
  1062.             log_err("FAIL: Calendar::get failed: %s\n", myErrorName(status));
  1063.             return; 
  1064.         }
  1065.         log_verbose("PASS: %s\n", msg); 
  1066.         d1=ucal_getMillis(c, &status);
  1067.         if (U_FAILURE(status)) { 
  1068.             log_err("ucal_getMillis failed: %s\n", myErrorName(status));
  1069.             return;
  1070.         }
  1071.         log_verbose("%s\n" , austrdup(myDateFormat(dat, d1)) );
  1072.     }
  1073.     else {
  1074.         log_err("FAIL: %s\n", msg);
  1075.         d1=ucal_getMillis(c, &status);
  1076.         if (U_FAILURE(status)) { 
  1077.             log_err("ucal_getMillis failed: %s\n", myErrorName(status)); 
  1078.             return;
  1079.         }
  1080.         if(am_pm==0)
  1081.         strcpy(str,"AM");
  1082.         else
  1083.         strcpy(str,"PM");
  1084.         log_err("Got %s Expected %d/%d/%d/ %d:%d:%d  %s\n", austrdup(myDateFormat(dat, d1)), 
  1085.             year, month + 1, day, hour, min, sec,  str);
  1086.         
  1087.         return;
  1088.     }
  1089.  
  1090.         
  1091. }
  1092.  
  1093. /*--------------------------------------------- */
  1094.