ccaltst.c revision 6d5deb12725f146643d443090dfa11b206df528a
1/********************************************************************
2 * Copyright (c) 1997-2009, International Business Machines
3 * Corporation and others. All Rights Reserved.
4 ********************************************************************
5 *
6 * File CCALTST.C
7 *
8 * Modification History:
9 *        Name                     Description
10 *     Madhu Katragadda               Creation
11 ********************************************************************
12 */
13
14/* C API AND FUNCTIONALITY TEST FOR CALENDAR (ucol.h)*/
15
16#include "unicode/utypes.h"
17
18#if !UCONFIG_NO_FORMATTING
19
20#include <stdlib.h>
21#include <string.h>
22
23#include "unicode/uloc.h"
24#include "unicode/ucal.h"
25#include "unicode/udat.h"
26#include "unicode/ustring.h"
27#include "cintltst.h"
28#include "ccaltst.h"
29#include "cformtst.h"
30#include "cstring.h"
31#include "ulist.h"
32
33void TestGregorianChange(void);
34
35void addCalTest(TestNode** root);
36
37void addCalTest(TestNode** root)
38{
39
40    addTest(root, &TestCalendar, "tsformat/ccaltst/TestCalendar");
41    addTest(root, &TestGetSetDateAPI, "tsformat/ccaltst/TestGetSetDateAPI");
42    addTest(root, &TestFieldGetSet, "tsformat/ccaltst/TestFieldGetSet");
43    addTest(root, &TestAddRollExtensive, "tsformat/ccaltst/TestAddRollExtensive");
44    addTest(root, &TestGetLimits, "tsformat/ccaltst/TestGetLimits");
45    addTest(root, &TestDOWProgression, "tsformat/ccaltst/TestDOWProgression");
46    addTest(root, &TestGMTvsLocal, "tsformat/ccaltst/TestGMTvsLocal");
47    addTest(root, &TestGregorianChange, "tsformat/ccaltst/TestGregorianChange");
48    addTest(root, &TestGetKeywordValuesForLocale, "tsformat/ccaltst/TestGetKeywordValuesForLocale");
49}
50
51/* "GMT" */
52static const UChar fgGMTID [] = { 0x0047, 0x004d, 0x0054, 0x0000 };
53
54/* "PST" */
55static const UChar PST[] = {0x50, 0x53, 0x54, 0x00}; /* "PST" */
56
57static const UChar EUROPE_PARIS[] = {0x45, 0x75, 0x72, 0x6F, 0x70, 0x65, 0x2F, 0x50, 0x61, 0x72, 0x69, 0x73, 0x00}; /* "Europe/Paris" */
58
59static const UChar AMERICA_LOS_ANGELES[] = {0x41, 0x6D, 0x65, 0x72, 0x69, 0x63, 0x61, 0x2F,
60    0x4C, 0x6F, 0x73, 0x5F, 0x41, 0x6E, 0x67, 0x65, 0x6C, 0x65, 0x73, 0x00}; /* America/Los_Angeles */
61
62typedef struct {
63    const char *    locale;
64    UCalendarType   calType;
65    const char *    expectedResult;
66} UCalGetTypeTest;
67
68static const UCalGetTypeTest ucalGetTypeTests[] = {
69    { "en_US",                   UCAL_GREGORIAN, "gregorian" },
70    { "ja_JP@calendar=japanese", UCAL_DEFAULT,   "japanese"  },
71    { "th_TH",                   UCAL_GREGORIAN, "gregorian" },
72    { "th_TH",                   UCAL_DEFAULT,   "buddhist"  },
73    { NULL, 0, NULL } /* terminator */
74};
75
76static void TestCalendar()
77{
78    UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0, *calfrclone = 0;
79    UEnumeration* uenum = NULL;
80    int32_t count, count2, i,j;
81    UChar tzID[4];
82    UChar *tzdname = 0;
83    UErrorCode status = U_ZERO_ERROR;
84    UDate now;
85    UDateFormat *datdef = 0;
86    UChar *result = 0;
87    int32_t resultlength, resultlengthneeded;
88    char tempMsgBuf[256];
89    UChar zone1[32], zone2[32];
90    const char *tzver = 0;
91    UChar canonicalID[64];
92    UBool isSystemID = FALSE;
93    const UCalGetTypeTest * ucalGetTypeTestPtr;
94
95#ifdef U_USE_UCAL_OBSOLETE_2_8
96    /*Testing countAvailableTimeZones*/
97    int32_t offset=0;
98    log_verbose("\nTesting ucal_countAvailableTZIDs\n");
99    count=ucal_countAvailableTZIDs(offset);
100    log_verbose("The number of timezone id's present with offset 0 are %d:\n", count);
101    if(count < 5) /* Don't hard code an exact == test here! */
102        log_err("FAIL: error in the ucal_countAvailableTZIDs - got %d expected at least 5 total\n", count);
103
104    /*Testing getAvailableTZIDs*/
105    log_verbose("\nTesting ucal_getAvailableTZIDs");
106    for(i=0;i<count;i++){
107        ucal_getAvailableTZIDs(offset, i, &status);
108        if(U_FAILURE(status)){
109            log_err("FAIL: ucal_getAvailableTZIDs returned %s\n", u_errorName(status));
110        }
111        log_verbose("%s\n", u_austrcpy(tempMsgBuf, ucal_getAvailableTZIDs(offset, i, &status)));
112    }
113    /*get Illegal TZID where index >= count*/
114    ucal_getAvailableTZIDs(offset, i, &status);
115    if(status != U_INDEX_OUTOFBOUNDS_ERROR){
116        log_err("FAIL:for TZID index >= count Expected INDEX_OUTOFBOUNDS_ERROR Got %s\n", u_errorName(status));
117    }
118    status=U_ZERO_ERROR;
119#endif
120
121    /*Test ucal_openTimeZones & ucal_openCountryTimeZones*/
122    for (j=0; j<2; ++j) {
123        const char* api = (j==0) ? "ucal_openTimeZones()" :
124            "ucal_openCountryTimeZones(US)";
125        uenum = (j==0) ? ucal_openTimeZones(&status) :
126            ucal_openCountryTimeZones("US", &status);
127        if (U_FAILURE(status)) {
128            log_err("FAIL: %s failed with %s", api,
129                    u_errorName(status));
130        } else {
131            const char* id;
132            int32_t len;
133            count = uenum_count(uenum, &status);
134            log_verbose("%s returned %d timezone id's:\n", api, count);
135            if (count < 5) { /* Don't hard code an exact == test here! */
136                log_data_err("FAIL: in %s, got %d, expected at least 5 -> %s (Are you missing data?)\n", api, count, u_errorName(status));
137            }
138            uenum_reset(uenum, &status);
139            if (U_FAILURE(status)){
140                log_err("FAIL: uenum_reset for %s returned %s\n",
141                        api, u_errorName(status));
142            }
143            for (i=0; i<count; i++) {
144                id = uenum_next(uenum, &len, &status);
145                if (U_FAILURE(status)){
146                    log_err("FAIL: uenum_next for %s returned %s\n",
147                            api, u_errorName(status));
148                } else {
149                    log_verbose("%s\n", id);
150                }
151            }
152            /* Next one should be NULL */
153            id = uenum_next(uenum, &len, &status);
154            if (id != NULL) {
155                log_err("FAIL: uenum_next for %s returned %s, expected NULL\n",
156                        api, id);
157            }
158        }
159        uenum_close(uenum);
160    }
161
162    /*Test ucal_getDSTSavings*/
163    status = U_ZERO_ERROR;
164    i = ucal_getDSTSavings(fgGMTID, &status);
165    if (U_FAILURE(status)) {
166        log_err("FAIL: ucal_getDSTSavings(GMT) => %s\n",
167                u_errorName(status));
168    } else if (i != 0) {
169        log_data_err("FAIL: ucal_getDSTSavings(GMT) => %d, expect 0 (Are you missing data?)\n", i);
170    }
171    i = ucal_getDSTSavings(PST, &status);
172    if (U_FAILURE(status)) {
173        log_err("FAIL: ucal_getDSTSavings(PST) => %s\n",
174                u_errorName(status));
175    } else if (i != 1*60*60*1000) {
176        log_err("FAIL: ucal_getDSTSavings(PST) => %d, expect %d\n", i, 1*60*60*1000);
177    }
178
179    /*Test ucal_set/getDefaultTimeZone*/
180    status = U_ZERO_ERROR;
181    i = ucal_getDefaultTimeZone(zone1, sizeof(zone1)/sizeof(zone1[0]), &status);
182    if (U_FAILURE(status)) {
183        log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
184                u_errorName(status));
185    } else {
186        ucal_setDefaultTimeZone(EUROPE_PARIS, &status);
187        if (U_FAILURE(status)) {
188            log_err("FAIL: ucal_setDefaultTimeZone(Europe/Paris) => %s\n",
189                    u_errorName(status));
190        } else {
191            i = ucal_getDefaultTimeZone(zone2, sizeof(zone2)/sizeof(zone2[0]), &status);
192            if (U_FAILURE(status)) {
193                log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
194                        u_errorName(status));
195            } else {
196                if (u_strcmp(zone2, EUROPE_PARIS) != 0) {
197                    log_data_err("FAIL: ucal_getDefaultTimeZone() did not return Europe/Paris (Are you missing data?)\n");
198                }
199            }
200        }
201        status = U_ZERO_ERROR;
202        ucal_setDefaultTimeZone(zone1, &status);
203    }
204
205    /*Test ucal_getTZDataVersion*/
206    status = U_ZERO_ERROR;
207    tzver = ucal_getTZDataVersion(&status);
208    if (U_FAILURE(status)) {
209        log_err_status(status, "FAIL: ucal_getTZDataVersion() => %s\n", u_errorName(status));
210    } else if (uprv_strlen(tzver) != 5 /*4 digits + 1 letter*/) {
211        log_err("FAIL: Bad version string was returned by ucal_getTZDataVersion\n");
212    } else {
213        log_verbose("PASS: ucal_getTZDataVersion returned %s\n", tzver);
214    }
215
216    /*Testing ucal_getCanonicalTimeZoneID*/
217    status = U_ZERO_ERROR;
218    resultlength = ucal_getCanonicalTimeZoneID(PST, -1,
219        canonicalID, sizeof(canonicalID)/sizeof(UChar), &isSystemID, &status);
220    if (U_FAILURE(status)) {
221        log_err("FAIL: error in ucal_getCanonicalTimeZoneID : %s\n", u_errorName(status));
222    } else {
223        if (u_strcmp(AMERICA_LOS_ANGELES, canonicalID) != 0) {
224            log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) returned %s : expected - %s (Are you missing data?)\n",
225                PST, canonicalID, AMERICA_LOS_ANGELES);
226        }
227        if (!isSystemID) {
228            log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) set %d to isSystemID (Are you missing data?)\n",
229                PST, isSystemID);
230        }
231    }
232
233    /*Testing the  ucal_open() function*/
234    status = U_ZERO_ERROR;
235    log_verbose("\nTesting the ucal_open()\n");
236    u_uastrcpy(tzID, "PST");
237    caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
238    if(U_FAILURE(status)){
239        log_err("FAIL: error in ucal_open caldef : %s\n", u_errorName(status));
240    }
241
242    caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
243    if(U_FAILURE(status)){
244        log_err("FAIL: error in ucal_open caldef : %s\n", u_errorName(status));
245    }
246    u_strcpy(tzID, fgGMTID);
247    calfr=ucal_open(tzID, u_strlen(tzID), "fr_FR", UCAL_TRADITIONAL, &status);
248    if(U_FAILURE(status)){
249        log_err("FAIL: error in ucal_open calfr : %s\n", u_errorName(status));
250    }
251    calit=ucal_open(tzID, u_strlen(tzID), "it_IT", UCAL_TRADITIONAL, &status);
252    if(U_FAILURE(status))    {
253        log_err("FAIL: error in ucal_open calit : %s\n", u_errorName(status));
254    }
255
256    /*Testing the  clone() function*/
257    calfrclone = ucal_clone(calfr, &status);
258    if(U_FAILURE(status)){
259        log_err("FAIL: error in ucal_clone calfr : %s\n", u_errorName(status));
260    }
261
262    /*Testing udat_getAvailable() and udat_countAvailable()*/
263    log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
264    count=ucal_countAvailable();
265    /* use something sensible w/o hardcoding the count */
266    if(count > 0) {
267        log_verbose("PASS: ucal_countAvailable() works fine\n");
268        log_verbose("The no: of locales for which calendars are avilable are %d\n", count);
269    } else {
270        log_data_err("FAIL: Error in countAvailable()\n");
271    }
272
273    for(i=0;i<count;i++) {
274       log_verbose("%s\n", ucal_getAvailable(i));
275    }
276
277
278    /*Testing the equality between calendar's*/
279    log_verbose("\nTesting ucal_equivalentTo()\n");
280    if(caldef && caldef2 && calfr && calit) {
281      if(ucal_equivalentTo(caldef, caldef2) == FALSE || ucal_equivalentTo(caldef, calfr)== TRUE ||
282        ucal_equivalentTo(caldef, calit)== TRUE || ucal_equivalentTo(calfr, calfrclone) == FALSE) {
283          log_data_err("FAIL: Error. equivalentTo test failed (Are you missing data?)\n");
284      } else {
285          log_verbose("PASS: equivalentTo test passed\n");
286      }
287    }
288
289
290    /*Testing the current time and date using ucal_getnow()*/
291    log_verbose("\nTesting the ucal_getNow function to check if it is fetching tbe current time\n");
292    now=ucal_getNow();
293    /* open the date format and format the date to check the output */
294    datdef=udat_open(UDAT_FULL,UDAT_FULL ,NULL, NULL, 0,NULL,0,&status);
295    if(U_FAILURE(status)){
296        log_data_err("FAIL: error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
297        return;
298    }
299    log_verbose("PASS: The current date and time fetched is %s\n", u_austrcpy(tempMsgBuf, myDateFormat(datdef, now)) );
300
301
302    /*Testing the TimeZoneDisplayName */
303    log_verbose("\nTesting the fetching of time zone display name\n");
304    /*for the US locale */
305    resultlength=0;
306    resultlengthneeded=ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", NULL, resultlength, &status);
307
308    if(status==U_BUFFER_OVERFLOW_ERROR)
309    {
310        status=U_ZERO_ERROR;
311        resultlength=resultlengthneeded+1;
312        result=(UChar*)malloc(sizeof(UChar) * resultlength);
313        ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", result, resultlength, &status);
314    }
315    if(U_FAILURE(status))    {
316        log_err("FAIL: Error in getting the timezone display name : %s\n", u_errorName(status));
317    }
318    else{
319        log_verbose("PASS: getting the time zone display name successful : %s, %d needed \n",
320            u_errorName(status), resultlengthneeded);
321    }
322
323
324#define expectPDT "Pacific Daylight Time"
325
326    tzdname=(UChar*)malloc(sizeof(UChar) * (sizeof(expectPDT)+1));
327    u_uastrcpy(tzdname, expectPDT);
328    if(u_strcmp(tzdname, result)==0){
329        log_verbose("PASS: got the correct time zone display name %s\n", u_austrcpy(tempMsgBuf, result) );
330    }
331    else{
332        log_err("FAIL: got the wrong time zone(DST) display name %s, wanted %s\n", austrdup(result) , expectPDT);
333    }
334
335    ucal_getTimeZoneDisplayName(caldef, UCAL_SHORT_DST, "en_US", result, resultlength, &status);
336    u_uastrcpy(tzdname, "PDT");
337    if(u_strcmp(tzdname, result) != 0){
338        log_err("FAIL: got the wrong time zone(SHORT_DST) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
339    }
340
341    ucal_getTimeZoneDisplayName(caldef, UCAL_STANDARD, "en_US", result, resultlength, &status);
342    u_uastrcpy(tzdname, "Pacific Standard Time");
343    if(u_strcmp(tzdname, result) != 0){
344        log_err("FAIL: got the wrong time zone(STANDARD) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
345    }
346
347    ucal_getTimeZoneDisplayName(caldef, UCAL_SHORT_STANDARD, "en_US", result, resultlength, &status);
348    u_uastrcpy(tzdname, "PST");
349    if(u_strcmp(tzdname, result) != 0){
350        log_err("FAIL: got the wrong time zone(SHORT_STANDARD) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
351    }
352
353
354    /*testing the setAttributes and getAttributes of a UCalendar*/
355    log_verbose("\nTesting the getAttributes and set Attributes\n");
356    count=ucal_getAttribute(calit, UCAL_LENIENT);
357    count2=ucal_getAttribute(calfr, UCAL_LENIENT);
358    ucal_setAttribute(calit, UCAL_LENIENT, 0);
359    ucal_setAttribute(caldef, UCAL_LENIENT, count2);
360    if( ucal_getAttribute(calit, UCAL_LENIENT) !=0 ||
361        ucal_getAttribute(calfr, UCAL_LENIENT)!=ucal_getAttribute(caldef, UCAL_LENIENT) )
362        log_err("FAIL: there is an error in getAttributes or setAttributes\n");
363    else
364        log_verbose("PASS: attribute set and got successfully\n");
365        /*set it back to orginal value */
366    log_verbose("Setting it back to normal\n");
367    ucal_setAttribute(calit, UCAL_LENIENT, count);
368    if(ucal_getAttribute(calit, UCAL_LENIENT)!=count)
369        log_err("FAIL: Error in setting the attribute back to normal\n");
370
371    /*setting the first day of the week to other values  */
372    count=ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK);
373    for (i=1; i<=7; ++i) {
374        ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,i);
375        if (ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK) != i)
376            log_err("FAIL: set/getFirstDayOfWeek failed\n");
377    }
378    /*get bogus Attribute*/
379    count=ucal_getAttribute(calit, (UCalendarAttribute)99); /* BOGUS_ATTRIBUTE */
380    if(count != -1){
381        log_err("FAIL: get/bogus attribute should return -1\n");
382    }
383
384    /*set it back to normal */
385    ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,count);
386    /*setting minimal days of the week to other values */
387    count=ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK);
388    for (i=1; i<=7; ++i) {
389        ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,i);
390        if (ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK) != i)
391            log_err("FAIL: set/getMinimalDaysInFirstWeek failed\n");
392    }
393    /*set it back to normal */
394    ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,count);
395
396
397    /*testing if the UCalendar's timezone is currently in day light saving's time*/
398    log_verbose("\nTesting if the UCalendar is currently in daylight saving's time\n");
399    ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 10, 45, 20, &status);
400    ucal_inDaylightTime(caldef, &status );
401    if(U_FAILURE(status))    {
402        log_err("Error in ucal_inDaylightTime: %s\n", u_errorName(status));
403    }
404    if(!ucal_inDaylightTime(caldef, &status))
405        log_verbose("PASS: It is not in daylight saving's time\n");
406    else
407        log_err("FAIL: It is not in daylight saving's time\n");
408
409    /*closing the UCalendar*/
410    ucal_close(caldef);
411    ucal_close(caldef2);
412    ucal_close(calfr);
413    ucal_close(calit);
414    ucal_close(calfrclone);
415
416    /*testing ucal_getType, and ucal_open with UCAL_GREGORIAN*/
417    for (ucalGetTypeTestPtr = ucalGetTypeTests; ucalGetTypeTestPtr->locale != NULL; ++ucalGetTypeTestPtr) {
418        status = U_ZERO_ERROR;
419        caldef = ucal_open(NULL, 0, ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType, &status);
420        if ( U_SUCCESS(status) ) {
421            const char * calType = ucal_getType(caldef, &status);
422            if ( U_SUCCESS(status) && calType != NULL ) {
423                if ( strcmp( calType, ucalGetTypeTestPtr->expectedResult ) != 0 ) {
424                    log_err("FAIL: ucal_open %s type %d does not return %s calendar\n", ucalGetTypeTestPtr->locale,
425                                                ucalGetTypeTestPtr->calType, ucalGetTypeTestPtr->expectedResult);
426                }
427            } else {
428                log_err("FAIL: ucal_open %s type %d, then ucal_getType fails\n", ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType);
429            }
430            ucal_close(caldef);
431        } else {
432            log_err("FAIL: ucal_open %s type %d fails\n", ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType);
433        }
434    }
435
436    /*closing the UDateFormat used */
437    udat_close(datdef);
438    free(result);
439    free(tzdname);
440}
441
442/*------------------------------------------------------*/
443/*Testing the getMillis, setMillis, setDate and setDateTime functions extensively*/
444
445static void TestGetSetDateAPI()
446{
447    UCalendar *caldef = 0, *caldef2 = 0;
448    UChar tzID[4];
449    UDate d1;
450    int32_t hour;
451    int32_t zoneOffset;
452    UDateFormat *datdef = 0;
453    UErrorCode status=U_ZERO_ERROR;
454    UDate d2= 837039928046.0;
455    UChar temp[30];
456
457    log_verbose("\nOpening the calendars()\n");
458    u_strcpy(tzID, fgGMTID);
459    /*open the calendars used */
460    caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
461    caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
462    /*open the dateformat */
463    /* this is supposed to open default date format, but later on it treats it like it is "en_US"
464       - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
465    /*datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL,fgGMTID,-1, &status);*/
466    datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US",fgGMTID,-1,NULL,0, &status);
467    if(U_FAILURE(status))
468    {
469        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
470        return;
471    }
472
473
474    /*Testing getMillis and setMillis */
475    log_verbose("\nTesting the date and time fetched in millis for a calendar using getMillis\n");
476    d1=ucal_getMillis(caldef, &status);
477    if(U_FAILURE(status)){
478        log_err("Error in getMillis : %s\n", u_errorName(status));
479    }
480
481    /*testing setMillis */
482    log_verbose("\nTesting the set date and time function using setMillis\n");
483    ucal_setMillis(caldef, d2, &status);
484    if(U_FAILURE(status)){
485        log_err("Error in setMillis : %s\n", u_errorName(status));
486    }
487
488    /*testing if the calendar date is set properly or not  */
489    d1=ucal_getMillis(caldef, &status);
490    if(u_strcmp(myDateFormat(datdef, d1), myDateFormat(datdef, d2))!=0)
491        log_err("error in setMillis or getMillis\n");
492    /*-------------------*/
493
494
495
496    ctest_setTimeZone(NULL, &status);
497
498    /*testing ucal_setTimeZone() function*/
499    log_verbose("\nTesting if the function ucal_setTimeZone() works fine\n");
500    ucal_setMillis(caldef2, d2, &status);
501    if(U_FAILURE(status)){
502        log_err("Error in getMillis : %s\n", u_errorName(status));;
503    }
504    hour=ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status);
505
506    u_uastrcpy(tzID, "PST");
507    ucal_setTimeZone(caldef2,tzID, 3, &status);
508    if(U_FAILURE(status)){
509        log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status));
510    }
511    else
512        log_verbose("ucal_setTimeZone worked fine\n");
513    if(hour == ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status))
514        log_err("FAIL: Error setting the time zone doesn't change the represented time\n");
515    else if((hour-8 + 1) != ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status)) /*because it is not in daylight savings time */
516        log_err("FAIL: Error setTimeZone doesn't change the represented time correctly with 8 hour offset\n");
517    else
518        log_verbose("PASS: setTimeZone works fine\n");
519
520    /*testing setTimeZone roundtrip */
521    log_verbose("\nTesting setTimeZone() roundtrip\n");
522    u_strcpy(tzID, fgGMTID);
523    ucal_setTimeZone(caldef2, tzID, 3, &status);
524    if(U_FAILURE(status)){
525        log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status));
526    }
527    if(d2==ucal_getMillis(caldef2, &status))
528        log_verbose("PASS: setTimeZone roundtrip test passed\n");
529    else
530        log_err("FAIL: setTimeZone roundtrip test failed\n");
531
532    zoneOffset = ucal_get(caldef2, UCAL_ZONE_OFFSET, &status);
533    if(U_FAILURE(status)){
534        log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone(): %s\n", u_errorName(status));
535    }
536    else if (zoneOffset != 0) {
537        log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset);
538    }
539
540    ucal_setTimeZone(caldef2, NULL, -1, &status);
541    if(U_FAILURE(status)){
542        log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status));
543    }
544    if(ucal_getMillis(caldef2, &status))
545        log_verbose("PASS: setTimeZone roundtrip test passed\n");
546    else
547        log_err("FAIL: setTimeZone roundtrip test failed\n");
548
549    zoneOffset = ucal_get(caldef2, UCAL_ZONE_OFFSET, &status);
550    if(U_FAILURE(status)){
551        log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone(): %s\n", u_errorName(status));
552    }
553    else if (zoneOffset != -28800000) {
554        log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset);
555    }
556
557    ctest_resetTimeZone();
558
559/*----------------------------*     */
560
561
562
563    /*Testing  if setDate works fine  */
564    log_verbose("\nTesting the ucal_setDate() function \n");
565    u_uastrcpy(temp, "Dec 17, 1971 11:05:28 PM");
566    ucal_setDate(caldef,1971, UCAL_DECEMBER, 17, &status);
567    if(U_FAILURE(status)){
568        log_err("error in setting the calendar date : %s\n", u_errorName(status));
569    }
570    /*checking if the calendar date is set properly or not  */
571    d1=ucal_getMillis(caldef, &status);
572    if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
573        log_verbose("PASS:setDate works fine\n");
574    else
575        log_err("FAIL:Error in setDate()\n");
576
577
578    /* Testing setDate Extensively with various input values */
579    log_verbose("\nTesting ucal_setDate() extensively\n");
580    ucal_setDate(caldef, 1999, UCAL_JANUARY, 10, &status);
581    verify1("1999  10th day of January  is :", caldef, datdef, 1999, UCAL_JANUARY, 10);
582    ucal_setDate(caldef, 1999, UCAL_DECEMBER, 3, &status);
583    verify1("1999 3rd day of December  is :", caldef, datdef, 1999, UCAL_DECEMBER, 3);
584    ucal_setDate(caldef, 2000, UCAL_MAY, 3, &status);
585    verify1("2000 3rd day of May is :", caldef, datdef, 2000, UCAL_MAY, 3);
586    ucal_setDate(caldef, 1999, UCAL_AUGUST, 32, &status);
587    verify1("1999 32th day of August is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1);
588    ucal_setDate(caldef, 1999, UCAL_MARCH, 0, &status);
589    verify1("1999 0th day of March is :", caldef, datdef, 1999, UCAL_FEBRUARY, 28);
590    ucal_setDate(caldef, 0, UCAL_MARCH, 12, &status);
591
592    /*--------------------*/
593
594    /*Testing if setDateTime works fine */
595    log_verbose("\nTesting the ucal_setDateTime() function \n");
596    u_uastrcpy(temp, "May 3, 1972 4:30:42 PM");
597    ucal_setDateTime(caldef,1972, UCAL_MAY, 3, 16, 30, 42, &status);
598    if(U_FAILURE(status)){
599        log_err("error in setting the calendar date : %s\n", u_errorName(status));
600    }
601    /*checking  if the calendar date is set properly or not  */
602    d1=ucal_getMillis(caldef, &status);
603    if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
604        log_verbose("PASS: setDateTime works fine\n");
605    else
606        log_err("FAIL: Error in setDateTime\n");
607
608
609
610    /*Testing setDateTime extensively with various input values*/
611    log_verbose("\nTesting ucal_setDateTime() function extensively\n");
612    ucal_setDateTime(caldef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, &status);
613    verify2("1999  10th day of October  at 6:45:30 is :", caldef, datdef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, 0 );
614    ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 15, 10, 55, &status);
615    verify2("1999 3rd day of March   at 15:10:55 is :", caldef, datdef, 1999, UCAL_MARCH, 3, 3, 10, 55, 1);
616    ucal_setDateTime(caldef, 1999, UCAL_MAY, 3, 25, 30, 45, &status);
617    verify2("1999 3rd day of May at 25:30:45 is :", caldef, datdef, 1999, UCAL_MAY, 4, 1, 30, 45, 0);
618    ucal_setDateTime(caldef, 1999, UCAL_AUGUST, 32, 22, 65, 40, &status);
619    verify2("1999 32th day of August at 22:65:40 is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1, 11, 5, 40,1);
620    ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, 0, 0, 0,&status);
621    verify2("1999 12th day of March at 0:0:0 is :", caldef, datdef, 1999, UCAL_MARCH, 12, 0, 0, 0, 0);
622    ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, -10, -10,0, &status);
623    verify2("1999 12th day of March is at -10:-10:0 :", caldef, datdef, 1999, UCAL_MARCH, 11, 1, 50, 0, 1);
624
625
626
627    /*close caldef and datdef*/
628    ucal_close(caldef);
629    ucal_close(caldef2);
630    udat_close(datdef);
631}
632
633/*----------------------------------------------------------- */
634/**
635 * Confirm the functioning of the calendar field related functions.
636 */
637static void TestFieldGetSet()
638{
639    UCalendar *cal = 0;
640    UChar tzID[4];
641    UDateFormat *datdef = 0;
642    UDate d1;
643    UErrorCode status=U_ZERO_ERROR;
644    log_verbose("\nFetching pointer to UCalendar using the ucal_open()\n");
645    u_strcpy(tzID, fgGMTID);
646    /*open the calendar used */
647    cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
648    if (U_FAILURE(status)) {
649        log_err("ucal_open failed: %s\n", u_errorName(status));
650        return;
651    }
652    datdef=udat_open(UDAT_SHORT,UDAT_SHORT ,NULL,fgGMTID,-1,NULL, 0, &status);
653    if(U_FAILURE(status))
654    {
655        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
656    }
657
658    /*Testing ucal_get()*/
659    log_verbose("\nTesting the ucal_get() function of Calendar\n");
660    ucal_setDateTime(cal, 1999, UCAL_MARCH, 12, 5, 25, 30, &status);
661    if(U_FAILURE(status)){
662        log_data_err("error in the setDateTime() : %s (Are you missing data?)\n", u_errorName(status));
663    }
664    if(ucal_get(cal, UCAL_YEAR, &status)!=1999 || ucal_get(cal, UCAL_MONTH, &status)!=2 ||
665        ucal_get(cal, UCAL_DATE, &status)!=12 || ucal_get(cal, UCAL_HOUR, &status)!=5)
666        log_data_err("error in ucal_get() -> %s (Are you missing data?)\n", u_errorName(status));
667    else if(ucal_get(cal, UCAL_DAY_OF_WEEK_IN_MONTH, &status)!=2 || ucal_get(cal, UCAL_DAY_OF_WEEK, &status)!=6
668        || ucal_get(cal, UCAL_WEEK_OF_MONTH, &status)!=2 || ucal_get(cal, UCAL_WEEK_OF_YEAR, &status)!= 10)
669        log_err("FAIL: error in ucal_get()\n");
670    else
671        log_verbose("PASS: ucal_get() works fine\n");
672
673    /*Testing the ucal_set() , ucal_clear() functions of calendar*/
674    log_verbose("\nTesting the set, and clear  field functions of calendar\n");
675    ucal_setAttribute(cal, UCAL_LENIENT, 0);
676    ucal_clear(cal);
677    ucal_set(cal, UCAL_YEAR, 1997);
678    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
679    ucal_set(cal, UCAL_DATE, 3);
680    verify1("1997 third day of June = ", cal, datdef, 1997, UCAL_JUNE, 3);
681    ucal_clear(cal);
682    ucal_set(cal, UCAL_YEAR, 1997);
683    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
684    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
685    ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 1);
686    verify1("1997 first Tuesday in June = ", cal, datdef, 1997, UCAL_JUNE, 3);
687    ucal_clear(cal);
688    ucal_set(cal, UCAL_YEAR, 1997);
689    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
690    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
691    ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, - 1);
692    verify1("1997 last Tuesday in June = ", cal, datdef,1997,   UCAL_JUNE, 24);
693    /*give undesirable input    */
694    status = U_ZERO_ERROR;
695    ucal_clear(cal);
696    ucal_set(cal, UCAL_YEAR, 1997);
697    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
698    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
699    ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 0);
700    d1 = ucal_getMillis(cal, &status);
701    if (status != U_ILLEGAL_ARGUMENT_ERROR) {
702        log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 zero-th Tuesday in June\n");
703    } else {
704        log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
705    }
706    status = U_ZERO_ERROR;
707    ucal_clear(cal);
708    ucal_set(cal, UCAL_YEAR, 1997);
709    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
710    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
711    ucal_set(cal, UCAL_WEEK_OF_MONTH, 1);
712    verify1("1997 Tuesday in week 1 of June = ", cal,datdef, 1997, UCAL_JUNE, 3);
713    ucal_clear(cal);
714    ucal_set(cal, UCAL_YEAR, 1997);
715    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
716    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
717    ucal_set(cal, UCAL_WEEK_OF_MONTH, 5);
718    verify1("1997 Tuesday in week 5 of June = ", cal,datdef, 1997, UCAL_JULY, 1);
719    status = U_ZERO_ERROR;
720    ucal_clear(cal);
721    ucal_set(cal, UCAL_YEAR, 1997);
722    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
723    ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
724    ucal_set(cal, UCAL_WEEK_OF_MONTH, 0);
725    ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
726    d1 = ucal_getMillis(cal,&status);
727    if (status != U_ILLEGAL_ARGUMENT_ERROR){
728        log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 Tuesday zero-th week in June\n");
729    } else {
730        log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
731    }
732    status = U_ZERO_ERROR;
733    ucal_clear(cal);
734    ucal_set(cal, UCAL_YEAR_WOY, 1997);
735    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
736    ucal_set(cal, UCAL_WEEK_OF_YEAR, 1);
737    verify1("1997 Tuesday in week 1 of year = ", cal, datdef,1996, UCAL_DECEMBER, 31);
738    ucal_clear(cal);
739    ucal_set(cal, UCAL_YEAR, 1997);
740    ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
741    ucal_set(cal, UCAL_WEEK_OF_YEAR, 10);
742    verify1("1997 Tuesday in week 10 of year = ", cal,datdef, 1997, UCAL_MARCH, 4);
743    ucal_clear(cal);
744    ucal_set(cal, UCAL_YEAR, 1999);
745    ucal_set(cal, UCAL_DAY_OF_YEAR, 1);
746    verify1("1999 1st day of the year =", cal, datdef, 1999, UCAL_JANUARY, 1);
747    ucal_set(cal, UCAL_MONTH, -3);
748    d1 = ucal_getMillis(cal,&status);
749    if (status != U_ILLEGAL_ARGUMENT_ERROR){
750        log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1999 -3th month\n");
751    } else {
752        log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
753    }
754
755    ucal_setAttribute(cal, UCAL_LENIENT, 1);
756
757    ucal_set(cal, UCAL_MONTH, -3);
758    verify1("1999 -3th month should be", cal, datdef, 1998, UCAL_OCTOBER, 1);
759
760
761    /*testing isSet and clearField()*/
762    if(!ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
763        log_err("FAIL: error in isSet\n");
764    else
765        log_verbose("PASS: isSet working fine\n");
766    ucal_clearField(cal, UCAL_WEEK_OF_YEAR);
767    if(ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
768        log_err("FAIL: there is an error in clearField or isSet\n");
769    else
770        log_verbose("PASS :clearField working fine\n");
771
772    /*-------------------------------*/
773
774    ucal_close(cal);
775    udat_close(datdef);
776}
777
778
779
780/* ------------------------------------- */
781/**
782 * Execute adding and rolling in Calendar extensively,
783 */
784static void TestAddRollExtensive()
785{
786    UCalendar *cal = 0;
787    int32_t i,limit;
788    UChar tzID[4];
789    UCalendarDateFields e;
790    int32_t y,m,d,hr,min,sec,ms;
791    int32_t maxlimit = 40;
792    UErrorCode status = U_ZERO_ERROR;
793    y = 1997; m = UCAL_FEBRUARY; d = 1; hr = 1; min = 1; sec = 0; ms = 0;
794
795    log_verbose("Testing add and roll extensively\n");
796
797    u_uastrcpy(tzID, "PST");
798    /*open the calendar used */
799    cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);;
800    if (U_FAILURE(status)) {
801        log_err("ucal_open() failed : %s\n", u_errorName(status));
802        return;
803    }
804
805    ucal_set(cal, UCAL_YEAR, y);
806    ucal_set(cal, UCAL_MONTH, m);
807    ucal_set(cal, UCAL_DATE, d);
808    ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
809
810    /* Confirm that adding to various fields works.*/
811    log_verbose("\nTesting to confirm that adding to various fields works with ucal_add()\n");
812    checkDate(cal, y, m, d);
813    ucal_add(cal,UCAL_YEAR, 1, &status);
814    if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status)); return; }
815    y++;
816    checkDate(cal, y, m, d);
817    ucal_add(cal,UCAL_MONTH, 12, &status);
818    if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status) ); return; }
819    y+=1;
820    checkDate(cal, y, m, d);
821    ucal_add(cal,UCAL_DATE, 1, &status);
822    if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status) ); return; }
823    d++;
824    checkDate(cal, y, m, d);
825    ucal_add(cal,UCAL_DATE, 2, &status);
826    if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status) ); return; }
827    d += 2;
828    checkDate(cal, y, m, d);
829    ucal_add(cal,UCAL_DATE, 28, &status);
830    if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status) ); return; }
831    ++m;
832    checkDate(cal, y, m, d);
833    ucal_add(cal, (UCalendarDateFields)-1, 10, &status);
834    if(status==U_ILLEGAL_ARGUMENT_ERROR)
835        log_verbose("Pass: Illegal argument error as expected\n");
836    else{
837        log_err("Fail: No, illegal argument error as expected. Got....: %s\n", u_errorName(status));
838    }
839    status=U_ZERO_ERROR;
840
841
842    /*confirm that applying roll to various fields works fine*/
843    log_verbose("\nTesting to confirm that ucal_roll() works\n");
844    ucal_roll(cal, UCAL_DATE, -1, &status);
845    if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", u_errorName(status) ); return; }
846    d -=1;
847    checkDate(cal, y, m, d);
848    ucal_roll(cal, UCAL_MONTH, -2, &status);
849    if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", u_errorName(status) ); return; }
850    m -=2;
851    checkDate(cal, y, m, d);
852    ucal_roll(cal, UCAL_DATE, 1, &status);
853    if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", u_errorName(status) ); return; }
854    d +=1;
855    checkDate(cal, y, m, d);
856    ucal_roll(cal, UCAL_MONTH, -12, &status);
857    if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", u_errorName(status) ); return; }
858    checkDate(cal, y, m, d);
859    ucal_roll(cal, UCAL_YEAR, -1, &status);
860    if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", u_errorName(status) ); return; }
861    y -=1;
862    checkDate(cal, y, m, d);
863    ucal_roll(cal, UCAL_DATE, 29, &status);
864    if (U_FAILURE(status)) { log_err("ucal_roll failed: %s\n", u_errorName(status) ); return; }
865    d = 2;
866    checkDate(cal, y, m, d);
867    ucal_roll(cal, (UCalendarDateFields)-1, 10, &status);
868    if(status==U_ILLEGAL_ARGUMENT_ERROR)
869        log_verbose("Pass: illegal arguement error as expected\n");
870    else{
871        log_err("Fail: no illegal argument error got..: %s\n", u_errorName(status));
872        return;
873    }
874    status=U_ZERO_ERROR;
875    ucal_clear(cal);
876    ucal_setDateTime(cal, 1999, UCAL_FEBRUARY, 28, 10, 30, 45,  &status);
877    if(U_FAILURE(status)){
878        log_err("error is setting the datetime: %s\n", u_errorName(status));
879    }
880    ucal_add(cal, UCAL_MONTH, 1, &status);
881    checkDate(cal, 1999, UCAL_MARCH, 28);
882    ucal_add(cal, UCAL_MILLISECOND, 1000, &status);
883    checkDateTime(cal, 1999, UCAL_MARCH, 28, 10, 30, 46, 0, UCAL_MILLISECOND);
884
885    ucal_close(cal);
886/*--------------- */
887    status=U_ZERO_ERROR;
888    /* Testing add and roll extensively */
889    log_verbose("\nTesting the ucal_add() and ucal_roll() functions extensively\n");
890    y = 1997; m = UCAL_FEBRUARY; d = 1; hr = 1; min = 1; sec = 0; ms = 0;
891    cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
892    if (U_FAILURE(status)) {
893        log_err("ucal_open failed: %s\n", u_errorName(status));
894        return;
895    }
896    ucal_set(cal, UCAL_YEAR, y);
897    ucal_set(cal, UCAL_MONTH, m);
898    ucal_set(cal, UCAL_DATE, d);
899    ucal_set(cal, UCAL_HOUR, hr);
900    ucal_set(cal, UCAL_MINUTE, min);
901    ucal_set(cal, UCAL_SECOND,sec);
902    ucal_set(cal, UCAL_MILLISECOND, ms);
903    ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
904    status=U_ZERO_ERROR;
905
906    log_verbose("\nTesting UCalendar add...\n");
907    for(e = UCAL_YEAR;e < UCAL_FIELD_COUNT; e=(UCalendarDateFields)((int32_t)e + 1)) {
908        limit = maxlimit;
909        status = U_ZERO_ERROR;
910        for (i = 0; i < limit; i++) {
911            ucal_add(cal, e, 1, &status);
912            if (U_FAILURE(status)) { limit = i; status = U_ZERO_ERROR; }
913        }
914        for (i = 0; i < limit; i++) {
915            ucal_add(cal, e, -1, &status);
916            if (U_FAILURE(status)) {
917                log_err("ucal_add -1 failed: %s\n", u_errorName(status));
918                return;
919            }
920        }
921        checkDateTime(cal, y, m, d, hr, min, sec, ms, e);
922    }
923    log_verbose("\nTesting calendar ucal_roll()...\n");
924    for(e = UCAL_YEAR;e < UCAL_FIELD_COUNT; e=(UCalendarDateFields)((int32_t)e + 1)) {
925        limit = maxlimit;
926        status = U_ZERO_ERROR;
927        for (i = 0; i < limit; i++) {
928            ucal_roll(cal, e, 1, &status);
929            if (U_FAILURE(status)) {
930                limit = i;
931                status = U_ZERO_ERROR;
932            }
933        }
934        for (i = 0; i < limit; i++) {
935            ucal_roll(cal, e, -1, &status);
936            if (U_FAILURE(status)) {
937                log_err("ucal_roll -1 failed: %s\n", u_errorName(status));
938                return;
939            }
940        }
941        checkDateTime(cal, y, m, d, hr, min, sec, ms, e);
942    }
943
944    ucal_close(cal);
945}
946
947/*------------------------------------------------------ */
948/*Testing the Limits for various Fields of Calendar*/
949static void TestGetLimits()
950{
951    UCalendar *cal = 0;
952    int32_t min, max, gr_min, le_max, ac_min, ac_max, val;
953    UChar tzID[4];
954    UErrorCode status = U_ZERO_ERROR;
955
956
957    u_uastrcpy(tzID, "PST");
958    /*open the calendar used */
959    cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);;
960    if (U_FAILURE(status)) {
961        log_err("ucal_open() for gregorian calendar failed in TestGetLimits: %s\n", u_errorName(status));
962        return;
963    }
964
965    log_verbose("\nTesting the getLimits function for various fields\n");
966
967
968
969    ucal_setDate(cal, 1999, UCAL_MARCH, 5, &status); /* Set the date to be March 5, 1999 */
970    val = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
971    min = ucal_getLimit(cal, UCAL_DAY_OF_WEEK, UCAL_MINIMUM, &status);
972    max = ucal_getLimit(cal, UCAL_DAY_OF_WEEK, UCAL_MAXIMUM, &status);
973    if ( (min != UCAL_SUNDAY || max != UCAL_SATURDAY ) && (min > val && val > max)  && (val != UCAL_FRIDAY)){
974           log_err("FAIL: Min/max bad\n");
975           log_err("FAIL: Day of week %d out of range\n", val);
976           log_err("FAIL: FAIL: Day of week should be SUNDAY Got %d\n", val);
977    }
978    else
979        log_verbose("getLimits successful\n");
980
981    val = ucal_get(cal, UCAL_DAY_OF_WEEK_IN_MONTH, &status);
982    min = ucal_getLimit(cal, UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_MINIMUM, &status);
983    max = ucal_getLimit(cal, UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_MAXIMUM, &status);
984    if ( (min != 0 || max != 5 ) && (min > val && val > max)  && (val != 1)){
985           log_err("FAIL: Min/max bad\n");
986           log_err("FAIL: Day of week in month %d out of range\n", val);
987           log_err("FAIL: FAIL: Day of week in month should be SUNDAY Got %d\n", val);
988
989    }
990    else
991        log_verbose("getLimits successful\n");
992
993    min=ucal_getLimit(cal, UCAL_MONTH, UCAL_MINIMUM, &status);
994    max=ucal_getLimit(cal, UCAL_MONTH, UCAL_MAXIMUM, &status);
995    gr_min=ucal_getLimit(cal, UCAL_MONTH, UCAL_GREATEST_MINIMUM, &status);
996    le_max=ucal_getLimit(cal, UCAL_MONTH, UCAL_LEAST_MAXIMUM, &status);
997    ac_min=ucal_getLimit(cal, UCAL_MONTH, UCAL_ACTUAL_MINIMUM, &status);
998    ac_max=ucal_getLimit(cal, UCAL_MONTH, UCAL_ACTUAL_MAXIMUM, &status);
999    if(U_FAILURE(status)){
1000        log_err("Error in getLimits: %s\n", u_errorName(status));
1001    }
1002    if(min!=0 || max!=11 || gr_min!=0 || le_max!=11 || ac_min!=0 || ac_max!=11)
1003        log_err("There is and error in getLimits in fetching the values\n");
1004    else
1005        log_verbose("getLimits successful\n");
1006
1007    ucal_setDateTime(cal, 1999, UCAL_MARCH, 5, 4, 10, 35, &status);
1008    val=ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
1009    min=ucal_getLimit(cal, UCAL_HOUR_OF_DAY, UCAL_MINIMUM, &status);
1010    max=ucal_getLimit(cal, UCAL_HOUR_OF_DAY, UCAL_MAXIMUM, &status);
1011    gr_min=ucal_getLimit(cal, UCAL_MINUTE, UCAL_GREATEST_MINIMUM, &status);
1012    le_max=ucal_getLimit(cal, UCAL_MINUTE, UCAL_LEAST_MAXIMUM, &status);
1013    ac_min=ucal_getLimit(cal, UCAL_MINUTE, UCAL_ACTUAL_MINIMUM, &status);
1014    ac_max=ucal_getLimit(cal, UCAL_SECOND, UCAL_ACTUAL_MAXIMUM, &status);
1015    if( (min!=0 || max!= 11 || gr_min!=0 || le_max!=60 || ac_min!=0 || ac_max!=60) &&
1016        (min>val && val>max) && val!=4){
1017
1018        log_err("FAIL: Min/max bad\n");
1019        log_err("FAIL: Hour of Day %d out of range\n", val);
1020        log_err("FAIL: HOUR_OF_DAY should be 4 Got %d\n", val);
1021    }
1022    else
1023        log_verbose("getLimits successful\n");
1024
1025
1026    /*get BOGUS_LIMIT type*/
1027    val=ucal_getLimit(cal, UCAL_SECOND, (UCalendarLimitType)99, &status);
1028    if(val != -1){
1029        log_err("FAIL: ucal_getLimit() with BOGUS type should return -1\n");
1030    }
1031    status=U_ZERO_ERROR;
1032
1033
1034    ucal_close(cal);
1035}
1036
1037
1038
1039/* ------------------------------------- */
1040
1041/**
1042 * Test that the days of the week progress properly when add is called repeatedly
1043 * for increments of 24 days.
1044 */
1045static void TestDOWProgression()
1046{
1047    int32_t initialDOW, DOW, newDOW, expectedDOW;
1048    UCalendar *cal = 0;
1049    UDateFormat *datfor = 0;
1050    UDate date1;
1051    int32_t delta=24;
1052    UErrorCode status = U_ZERO_ERROR;
1053    UChar tzID[4];
1054    char tempMsgBuf[256];
1055    u_strcpy(tzID, fgGMTID);
1056    /*open the calendar used */
1057    cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);;
1058    if (U_FAILURE(status)) {
1059        log_err("ucal_open failed: %s\n", u_errorName(status));
1060        return;
1061    }
1062
1063    datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1,NULL, 0, &status);
1064    if(U_FAILURE(status)){
1065        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
1066    }
1067
1068
1069    ucal_setDate(cal, 1999, UCAL_JANUARY, 1, &status);
1070
1071    log_verbose("\nTesting the DOW progression\n");
1072
1073    initialDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
1074    if (U_FAILURE(status)) { log_data_err("ucal_get() failed: %s (Are you missing data?)\n", u_errorName(status) ); return; }
1075    newDOW = initialDOW;
1076    do {
1077        DOW = newDOW;
1078        log_verbose("DOW = %d...\n", DOW);
1079        date1=ucal_getMillis(cal, &status);
1080        if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status)); return;}
1081        log_verbose("%s\n", u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)));
1082
1083        ucal_add(cal,UCAL_DAY_OF_WEEK, delta, &status);
1084        if (U_FAILURE(status)) { log_err("ucal_add() failed: %s\n", u_errorName(status)); return; }
1085
1086        newDOW = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
1087        if (U_FAILURE(status)) { log_err("ucal_get() failed: %s\n", u_errorName(status)); return; }
1088        expectedDOW = 1 + (DOW + delta - 1) % 7;
1089        date1=ucal_getMillis(cal, &status);
1090        if(U_FAILURE(status)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status)); return;}
1091        if (newDOW != expectedDOW) {
1092            log_err("Day of week should be %d instead of %d on %s", expectedDOW, newDOW,
1093                u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)) );
1094            return;
1095        }
1096    }
1097    while (newDOW != initialDOW);
1098
1099    ucal_close(cal);
1100    udat_close(datfor);
1101}
1102
1103/* ------------------------------------- */
1104
1105/**
1106 * Confirm that the offset between local time and GMT behaves as expected.
1107 */
1108static void TestGMTvsLocal()
1109{
1110    log_verbose("\nTesting the offset between the GMT and local time\n");
1111    testZones(1999, 1, 1, 12, 0, 0);
1112    testZones(1999, 4, 16, 18, 30, 0);
1113    testZones(1998, 12, 17, 19, 0, 0);
1114}
1115
1116/* ------------------------------------- */
1117
1118static void testZones(int32_t yr, int32_t mo, int32_t dt, int32_t hr, int32_t mn, int32_t sc)
1119{
1120    int32_t offset,utc, expected;
1121    UCalendar *gmtcal = 0, *cal = 0;
1122    UDate date1;
1123    double temp;
1124    UDateFormat *datfor = 0;
1125    UErrorCode status = U_ZERO_ERROR;
1126    UChar tzID[4];
1127    char tempMsgBuf[256];
1128
1129    u_strcpy(tzID, fgGMTID);
1130    gmtcal=ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);;
1131    if (U_FAILURE(status)) {
1132        log_err("ucal_open failed: %s\n", u_errorName(status));
1133        return;
1134    }
1135    u_uastrcpy(tzID, "PST");
1136    cal = ucal_open(tzID, 3, "en_US", UCAL_TRADITIONAL, &status);
1137    if (U_FAILURE(status)) {
1138        log_err("ucal_open failed: %s\n", u_errorName(status));
1139        return;
1140    }
1141
1142    datfor=udat_open(UDAT_MEDIUM,UDAT_MEDIUM ,NULL, fgGMTID,-1,NULL, 0, &status);
1143    if(U_FAILURE(status)){
1144        log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
1145    }
1146
1147    ucal_setDateTime(gmtcal, yr, mo - 1, dt, hr, mn, sc, &status);
1148    if (U_FAILURE(status)) {
1149        log_data_err("ucal_setDateTime failed: %s (Are you missing data?)\n", u_errorName(status));
1150        return;
1151    }
1152    ucal_set(gmtcal, UCAL_MILLISECOND, 0);
1153    date1 = ucal_getMillis(gmtcal, &status);
1154    if (U_FAILURE(status)) {
1155        log_err("ucal_getMillis failed: %s\n", u_errorName(status));
1156        return;
1157    }
1158    log_verbose("date = %s\n", u_austrcpy(tempMsgBuf, myDateFormat(datfor, date1)) );
1159
1160
1161    ucal_setMillis(cal, date1, &status);
1162    if (U_FAILURE(status)) {
1163        log_err("ucal_setMillis() failed: %s\n", u_errorName(status));
1164        return;
1165    }
1166
1167    offset = ucal_get(cal, UCAL_ZONE_OFFSET, &status);
1168    offset += ucal_get(cal, UCAL_DST_OFFSET, &status);
1169
1170    if (U_FAILURE(status)) {
1171        log_err("ucal_get() failed: %s\n", u_errorName(status));
1172        return;
1173    }
1174    temp=(double)((double)offset / 1000.0 / 60.0 / 60.0);
1175    /*printf("offset for %s %f hr\n", austrdup(myDateFormat(datfor, date1)), temp);*/
1176
1177    utc = ((ucal_get(cal, UCAL_HOUR_OF_DAY, &status) * 60 +
1178                    ucal_get(cal, UCAL_MINUTE, &status)) * 60 +
1179                   ucal_get(cal, UCAL_SECOND, &status)) * 1000 +
1180                    ucal_get(cal, UCAL_MILLISECOND, &status) - offset;
1181    if (U_FAILURE(status)) {
1182        log_err("ucal_get() failed: %s\n", u_errorName(status));
1183        return;
1184    }
1185
1186    expected = ((hr * 60 + mn) * 60 + sc) * 1000;
1187    if (utc != expected) {
1188        temp=(double)(utc - expected)/ 1000 / 60 / 60.0;
1189        log_err("FAIL: Discrepancy of %d  millis = %fhr\n", utc-expected, temp );
1190    }
1191    else
1192        log_verbose("PASS: the offset between local and GMT is correct\n");
1193    ucal_close(gmtcal);
1194    ucal_close(cal);
1195    udat_close(datfor);
1196}
1197
1198/* ------------------------------------- */
1199
1200
1201
1202
1203/* INTERNAL FUNCTIONS USED */
1204/*------------------------------------------------------------------------------------------- */
1205
1206/* ------------------------------------- */
1207static void checkDateTime(UCalendar* c,
1208                        int32_t y, int32_t m, int32_t d,
1209                        int32_t hr, int32_t min, int32_t sec,
1210                        int32_t ms, UCalendarDateFields field)
1211
1212{
1213    UErrorCode status = U_ZERO_ERROR;
1214    if (ucal_get(c, UCAL_YEAR, &status) != y ||
1215        ucal_get(c, UCAL_MONTH, &status) != m ||
1216        ucal_get(c, UCAL_DATE, &status) != d ||
1217        ucal_get(c, UCAL_HOUR, &status) != hr ||
1218        ucal_get(c, UCAL_MINUTE, &status) != min ||
1219        ucal_get(c, UCAL_SECOND, &status) != sec ||
1220        ucal_get(c, UCAL_MILLISECOND, &status) != ms) {
1221        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",
1222            (int32_t)field, y, m + 1, d, hr, min, sec, ms,
1223                    ucal_get(c, UCAL_YEAR, &status),
1224                    ucal_get(c, UCAL_MONTH, &status) + 1,
1225                    ucal_get(c, UCAL_DATE, &status),
1226                    ucal_get(c, UCAL_HOUR, &status),
1227                    ucal_get(c, UCAL_MINUTE, &status) + 1,
1228                    ucal_get(c, UCAL_SECOND, &status),
1229                    ucal_get(c, UCAL_MILLISECOND, &status) );
1230
1231                    if (U_FAILURE(status)){
1232                    log_err("ucal_get failed: %s\n", u_errorName(status));
1233                    return;
1234                    }
1235
1236     }
1237    else
1238        log_verbose("Confirmed: %d/%d/%d %d:%d:%d:%d\n", y, m + 1, d, hr, min, sec, ms);
1239
1240}
1241
1242/* ------------------------------------- */
1243static void checkDate(UCalendar* c, int32_t y, int32_t m, int32_t d)
1244{
1245    UErrorCode status = U_ZERO_ERROR;
1246    if (ucal_get(c,UCAL_YEAR, &status) != y ||
1247        ucal_get(c, UCAL_MONTH, &status) != m ||
1248        ucal_get(c, UCAL_DATE, &status) != d) {
1249
1250        log_err("FAILURE: Expected y/m/d of %d/%d/%d  got %d/%d/%d\n", y, m + 1, d,
1251                    ucal_get(c, UCAL_YEAR, &status),
1252                    ucal_get(c, UCAL_MONTH, &status) + 1,
1253                    ucal_get(c, UCAL_DATE, &status) );
1254
1255        if (U_FAILURE(status)) {
1256            log_err("ucal_get failed: %s\n", u_errorName(status));
1257            return;
1258        }
1259    }
1260    else
1261        log_verbose("Confirmed: %d/%d/%d\n", y, m + 1, d);
1262
1263
1264}
1265
1266/* ------------------------------------- */
1267
1268/* ------------------------------------- */
1269
1270static void verify1(const char* msg, UCalendar* c, UDateFormat* dat, int32_t year, int32_t month, int32_t day)
1271{
1272    UDate d1;
1273    UErrorCode status = U_ZERO_ERROR;
1274    if (ucal_get(c, UCAL_YEAR, &status) == year &&
1275        ucal_get(c, UCAL_MONTH, &status) == month &&
1276        ucal_get(c, UCAL_DATE, &status) == day) {
1277        if (U_FAILURE(status)) {
1278            log_err("FAIL: Calendar::get failed: %s\n", u_errorName(status));
1279            return;
1280        }
1281        log_verbose("PASS: %s\n", msg);
1282        d1=ucal_getMillis(c, &status);
1283        if (U_FAILURE(status)) {
1284            log_err("ucal_getMillis failed: %s\n", u_errorName(status));
1285            return;
1286        }
1287    /*log_verbose(austrdup(myDateFormat(dat, d1)) );*/
1288    }
1289    else {
1290        log_err("FAIL: %s\n", msg);
1291        d1=ucal_getMillis(c, &status);
1292        if (U_FAILURE(status)) {
1293            log_err("ucal_getMillis failed: %s\n", u_errorName(status) );
1294            return;
1295        }
1296        log_err("Got %s  Expected %d/%d/%d \n", austrdup(myDateFormat(dat, d1)), year, month + 1, day );
1297        return;
1298    }
1299
1300
1301}
1302
1303/* ------------------------------------ */
1304static void verify2(const char* msg, UCalendar* c, UDateFormat* dat, int32_t year, int32_t month, int32_t day,
1305                                                                     int32_t hour, int32_t min, int32_t sec, int32_t am_pm)
1306{
1307    UDate d1;
1308    UErrorCode status = U_ZERO_ERROR;
1309    char tempMsgBuf[256];
1310
1311    if (ucal_get(c, UCAL_YEAR, &status) == year &&
1312        ucal_get(c, UCAL_MONTH, &status) == month &&
1313        ucal_get(c, UCAL_DATE, &status) == day &&
1314        ucal_get(c, UCAL_HOUR, &status) == hour &&
1315        ucal_get(c, UCAL_MINUTE, &status) == min &&
1316        ucal_get(c, UCAL_SECOND, &status) == sec &&
1317        ucal_get(c, UCAL_AM_PM, &status) == am_pm ){
1318        if (U_FAILURE(status)) {
1319            log_err("FAIL: Calendar::get failed: %s\n", u_errorName(status));
1320            return;
1321        }
1322        log_verbose("PASS: %s\n", msg);
1323        d1=ucal_getMillis(c, &status);
1324        if (U_FAILURE(status)) {
1325            log_err("ucal_getMillis failed: %s\n", u_errorName(status));
1326            return;
1327        }
1328        log_verbose("%s\n" , u_austrcpy(tempMsgBuf, myDateFormat(dat, d1)) );
1329    }
1330    else {
1331        log_err("FAIL: %s\n", msg);
1332        d1=ucal_getMillis(c, &status);
1333        if (U_FAILURE(status)) {
1334            log_err("ucal_getMillis failed: %s\n", u_errorName(status));
1335            return;
1336        }
1337        log_err("Got %s Expected %d/%d/%d/ %d:%d:%d  %s\n", austrdup(myDateFormat(dat, d1)),
1338            year, month + 1, day, hour, min, sec, (am_pm==0) ? "AM": "PM");
1339
1340        return;
1341    }
1342
1343
1344}
1345
1346void TestGregorianChange() {
1347    static const UChar utc[] = { 0x45, 0x74, 0x63, 0x2f, 0x47, 0x4d, 0x54, 0 }; /* "Etc/GMT" */
1348    const int32_t dayMillis = 86400 * INT64_C(1000);    /* 1 day = 86400 seconds */
1349    UCalendar *cal;
1350    UDate date;
1351    UErrorCode errorCode = U_ZERO_ERROR;
1352
1353    /* Test ucal_setGregorianChange() on a Gregorian calendar. */
1354    errorCode = U_ZERO_ERROR;
1355    cal = ucal_open(utc, -1, "", UCAL_GREGORIAN, &errorCode);
1356    if(U_FAILURE(errorCode)) {
1357        log_err("ucal_open(UTC) failed: %s\n", u_errorName(errorCode));
1358        return;
1359    }
1360    ucal_setGregorianChange(cal, -365 * (dayMillis * (UDate)1), &errorCode);
1361    if(U_FAILURE(errorCode)) {
1362        log_err("ucal_setGregorianChange(1969) failed: %s\n", u_errorName(errorCode));
1363    } else {
1364        date = ucal_getGregorianChange(cal, &errorCode);
1365        if(U_FAILURE(errorCode) || date != -365 * (dayMillis * (UDate)1)) {
1366            log_err("ucal_getGregorianChange() failed: %s, date = %f\n", u_errorName(errorCode), date);
1367        }
1368    }
1369    ucal_close(cal);
1370
1371    /* Test ucal_setGregorianChange() on a non-Gregorian calendar where it should fail. */
1372    errorCode = U_ZERO_ERROR;
1373    cal = ucal_open(utc, -1, "th@calendar=buddhist", UCAL_TRADITIONAL, &errorCode);
1374    if(U_FAILURE(errorCode)) {
1375        log_err("ucal_open(UTC, non-Gregorian) failed: %s\n", u_errorName(errorCode));
1376        return;
1377    }
1378    ucal_setGregorianChange(cal, -730 * (dayMillis * (UDate)1), &errorCode);
1379    if(errorCode != U_UNSUPPORTED_ERROR) {
1380        log_err("ucal_setGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
1381                u_errorName(errorCode));
1382    }
1383    errorCode = U_ZERO_ERROR;
1384    date = ucal_getGregorianChange(cal, &errorCode);
1385    if(errorCode != U_UNSUPPORTED_ERROR) {
1386        log_err("ucal_getGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
1387                u_errorName(errorCode));
1388    }
1389    ucal_close(cal);
1390}
1391
1392static void TestGetKeywordValuesForLocale() {
1393#define PREFERRED_SIZE 15
1394#define MAX_NUMBER_OF_KEYWORDS 4
1395    const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = {
1396            { "root",        "gregorian", NULL, NULL, NULL },
1397            { "und",         "gregorian", NULL, NULL, NULL },
1398            { "en_US",       "gregorian", NULL, NULL, NULL },
1399            { "en_029",      "gregorian", NULL, NULL, NULL },
1400            { "th_TH",       "buddhist", "gregorian", NULL, NULL },
1401            { "und_TH",      "buddhist", "gregorian", NULL, NULL },
1402            { "en_TH",       "buddhist", "gregorian", NULL, NULL },
1403            { "he_IL",       "gregorian", "hebrew", "islamic", "islamic-civil" },
1404            { "ar_EG",       "gregorian", "coptic", "islamic", "islamic-civil" },
1405            { "ja",          "gregorian", "japanese", NULL, NULL },
1406            { "ps_Guru_IN",  "gregorian", "indian", NULL, NULL },
1407            { "th@calendar=gregorian", "buddhist", "gregorian", NULL, NULL },
1408            { "en@calendar=islamic",   "gregorian", NULL, NULL, NULL },
1409            { "zh_TW",       "gregorian", "roc", "chinese", NULL },
1410            { "ar_IR",       "gregorian", "persian", "islamic", "islamic-civil" },
1411    };
1412    const int32_t EXPECTED_SIZE[PREFERRED_SIZE] = { 1, 1, 1, 1, 2, 2, 2, 4, 4, 2, 2, 2, 1, 3, 4 };
1413    UErrorCode status = U_ZERO_ERROR;
1414    int32_t i, size, j;
1415    UEnumeration *all, *pref;
1416    const char *loc = NULL;
1417    UBool matchPref, matchAll;
1418    const char *value;
1419    int32_t valueLength;
1420    UList *ALLList = NULL;
1421
1422    UEnumeration *ALL = ucal_getKeywordValuesForLocale("calendar", uloc_getDefault(), FALSE, &status);
1423    if (U_SUCCESS(status)) {
1424        for (i = 0; i < PREFERRED_SIZE; i++) {
1425            pref = NULL;
1426            all = NULL;
1427            loc = PREFERRED[i][0];
1428            pref = ucal_getKeywordValuesForLocale("calendar", loc, TRUE, &status);
1429            matchPref = FALSE;
1430            matchAll = FALSE;
1431
1432            value = NULL;
1433            valueLength = 0;
1434
1435            if (U_SUCCESS(status) && uenum_count(pref, &status) == EXPECTED_SIZE[i]) {
1436                matchPref = TRUE;
1437                for (j = 0; j < EXPECTED_SIZE[i]; j++) {
1438                    if ((value = uenum_next(pref, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
1439                        if (uprv_strcmp(value, PREFERRED[i][j+1]) != 0) {
1440                            matchPref = FALSE;
1441                            break;
1442                        }
1443                    } else {
1444                        matchPref = FALSE;
1445                        log_err("ERROR getting keyword value for locale \"%s\"\n", loc);
1446                        break;
1447                    }
1448                }
1449            }
1450
1451            if (!matchPref) {
1452                log_err("FAIL: Preferred values for locale \"%s\" does not match expected.\n", loc);
1453                break;
1454            }
1455            uenum_close(pref);
1456
1457            all = ucal_getKeywordValuesForLocale("calendar", loc, FALSE, &status);
1458
1459            size = uenum_count(all, &status);
1460
1461            if (U_SUCCESS(status) && size == uenum_count(ALL, &status)) {
1462                matchAll = TRUE;
1463                ALLList = ulist_getListFromEnum(ALL);
1464                for (j = 0; j < size; j++) {
1465                    if ((value = uenum_next(all, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
1466                        if (!ulist_containsString(ALLList, value, uprv_strlen(value))) {
1467                            log_err("Locale %s have %s not in ALL\n", loc, value);
1468                            matchAll = FALSE;
1469                            break;
1470                        }
1471                    } else {
1472                        matchAll = FALSE;
1473                        log_err("ERROR getting \"all\" keyword value for locale \"%s\"\n", loc);
1474                        break;
1475                    }
1476                }
1477            }
1478            if (!matchAll) {
1479                log_err("FAIL: All values for locale \"%s\" does not match expected.\n", loc);
1480            }
1481
1482            uenum_close(all);
1483        }
1484    } else {
1485        log_err_status(status, "Failed to get ALL keyword values for default locale %s: %s.\n", uloc_getDefault(), u_errorName(status));
1486    }
1487    uenum_close(ALL);
1488}
1489
1490#endif /* #if !UCONFIG_NO_FORMATTING */
1491