-
-
Notifications
You must be signed in to change notification settings - Fork 709
/
ccaltst.c
2894 lines (2622 loc) · 132 KB
/
ccaltst.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http:https://www.unicode.org/copyright.html
/********************************************************************
* Copyright (c) 1997-2016, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************
*
* File CCALTST.C
*
* Modification History:
* Name Description
* Madhu Katragadda Creation
********************************************************************
*/
/* C API AND FUNCTIONALITY TEST FOR CALENDAR (ucol.h)*/
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "unicode/uloc.h"
#include "unicode/ucal.h"
#include "unicode/udat.h"
#include "unicode/ustring.h"
#include "cintltst.h"
#include "ccaltst.h"
#include "cformtst.h"
#include "cmemory.h"
#include "cstring.h"
#include "ulist.h"
void TestGregorianChange(void);
void TestFieldDifference(void);
void TestAddRollEra0AndEraBounds(void);
void TestGetTZTransition(void);
void TestGetWindowsTimeZoneID(void);
void TestGetTimeZoneIDByWindowsID(void);
void TestJpnCalAddSetNextEra(void);
void TestUcalOpenBufferRead(void);
void TestGetTimeZoneOffsetFromLocal(void);
void TestFWWithISO8601(void);
void addCalTest(TestNode** root);
void addCalTest(TestNode** root)
{
addTest(root, &TestCalendar, "tsformat/ccaltst/TestCalendar");
addTest(root, &TestGetSetDateAPI, "tsformat/ccaltst/TestGetSetDateAPI");
addTest(root, &TestFieldGetSet, "tsformat/ccaltst/TestFieldGetSet");
addTest(root, &TestAddRollExtensive, "tsformat/ccaltst/TestAddRollExtensive");
addTest(root, &TestGetLimits, "tsformat/ccaltst/TestGetLimits");
addTest(root, &TestDOWProgression, "tsformat/ccaltst/TestDOWProgression");
addTest(root, &TestGMTvsLocal, "tsformat/ccaltst/TestGMTvsLocal");
addTest(root, &TestGregorianChange, "tsformat/ccaltst/TestGregorianChange");
addTest(root, &TestGetKeywordValuesForLocale, "tsformat/ccaltst/TestGetKeywordValuesForLocale");
addTest(root, &TestWeekend, "tsformat/ccaltst/TestWeekend");
addTest(root, &TestFieldDifference, "tsformat/ccaltst/TestFieldDifference");
addTest(root, &TestAmbiguousWallTime, "tsformat/ccaltst/TestAmbiguousWallTime");
addTest(root, &TestAddRollEra0AndEraBounds, "tsformat/ccaltst/TestAddRollEra0AndEraBounds");
addTest(root, &TestGetTZTransition, "tsformat/ccaltst/TestGetTZTransition");
addTest(root, &TestGetWindowsTimeZoneID, "tsformat/ccaltst/TestGetWindowsTimeZoneID");
addTest(root, &TestGetTimeZoneIDByWindowsID, "tsformat/ccaltst/TestGetTimeZoneIDByWindowsID");
addTest(root, &TestJpnCalAddSetNextEra, "tsformat/ccaltst/TestJpnCalAddSetNextEra");
addTest(root, &TestUcalOpenBufferRead, "tsformat/ccaltst/TestUcalOpenBufferRead");
addTest(root, &TestGetTimeZoneOffsetFromLocal, "tsformat/ccaltst/TestGetTimeZoneOffsetFromLocal");
addTest(root, &TestFWWithISO8601, "tsformat/ccaltst/TestFWWithISO8601");
addTest(root, &TestGetIanaTimeZoneID, "tstformat/ccaltst/TestGetIanaTimeZoneID");
}
/* "GMT" */
static const UChar fgGMTID [] = { 0x0047, 0x004d, 0x0054, 0x0000 };
/* "PST" */
static const UChar PST[] = {0x50, 0x53, 0x54, 0x00}; /* "PST" */
static const UChar EUROPE_PARIS[] = {0x45, 0x75, 0x72, 0x6F, 0x70, 0x65, 0x2F, 0x50, 0x61, 0x72, 0x69, 0x73, 0x00}; /* "Europe/Paris" */
static const UChar AMERICA_LOS_ANGELES[] = {0x41, 0x6D, 0x65, 0x72, 0x69, 0x63, 0x61, 0x2F,
0x4C, 0x6F, 0x73, 0x5F, 0x41, 0x6E, 0x67, 0x65, 0x6C, 0x65, 0x73, 0x00}; /* America/Los_Angeles */
typedef struct {
const char * locale;
UCalendarType calType;
const char * expectedResult;
} UCalGetTypeTest;
static const UCalGetTypeTest ucalGetTypeTests[] = {
{ "en_US", UCAL_GREGORIAN, "gregorian" },
{ "ja_JP@calendar=japanese", UCAL_DEFAULT, "japanese" },
{ "th_TH", UCAL_GREGORIAN, "gregorian" },
{ "th_TH", UCAL_DEFAULT, "buddhist" },
{ "th-TH-u-ca-gregory", UCAL_DEFAULT, "gregorian" },
{ "ja_JP@calendar=japanese", UCAL_GREGORIAN, "gregorian" },
{ "fr_CH", UCAL_DEFAULT, "gregorian" },
{ "fr_SA", UCAL_DEFAULT, "islamic-umalqura" },
{ "fr_CH@rg=sazzzz", UCAL_DEFAULT, "islamic-umalqura" },
{ "fr_CH@rg=sa14", UCAL_DEFAULT, "islamic-umalqura" },
{ "fr_CH@calendar=japanese;rg=sazzzz", UCAL_DEFAULT, "japanese" },
{ "fr_CH@rg=twcyi", UCAL_DEFAULT, "gregorian" }, // test for ICU-22364
{ "fr_CH@rg=ugw", UCAL_DEFAULT, "gregorian" }, // test for ICU-22364
{ "fr_TH@rg=SA", UCAL_DEFAULT, "buddhist" }, /* ignore malformed rg tag */
{ "th@rg=SA", UCAL_DEFAULT, "buddhist" }, /* ignore malformed rg tag */
{ "", UCAL_GREGORIAN, "gregorian" },
{ NULL, UCAL_GREGORIAN, "gregorian" },
{ NULL, 0, NULL } /* terminator */
};
static void TestCalendar()
{
UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0, *calfrclone = 0;
UEnumeration* uenum = NULL;
int32_t count, count2, i,j;
UChar tzID[4];
UChar *tzdname = 0;
UErrorCode status = U_ZERO_ERROR;
UDate now;
UDateFormat *datdef = 0;
UChar *result = 0;
int32_t resultlength, resultlengthneeded;
char tempMsgBuf[1024]; // u_austrcpy() of some formatted dates & times.
char tempMsgBuf2[256]; // u_austrcpy() of some formatted dates & times.
UChar zone1[64], zone2[64];
const char *tzver = 0;
int32_t tzverLen = 0;
UChar canonicalID[64];
UBool isSystemID = false;
const UCalGetTypeTest * ucalGetTypeTestPtr;
#ifdef U_USE_UCAL_OBSOLETE_2_8
/*Testing countAvailableTimeZones*/
int32_t offset=0;
log_verbose("\nTesting ucal_countAvailableTZIDs\n");
count=ucal_countAvailableTZIDs(offset);
log_verbose("The number of timezone id's present with offset 0 are %d:\n", count);
if(count < 5) /* Don't hard code an exact == test here! */
log_err("FAIL: error in the ucal_countAvailableTZIDs - got %d expected at least 5 total\n", count);
/*Testing getAvailableTZIDs*/
log_verbose("\nTesting ucal_getAvailableTZIDs");
for(i=0;i<count;i++){
ucal_getAvailableTZIDs(offset, i, &status);
if(U_FAILURE(status)){
log_err("FAIL: ucal_getAvailableTZIDs returned %s\n", u_errorName(status));
}
log_verbose("%s\n", u_austrcpy(tempMsgBuf, ucal_getAvailableTZIDs(offset, i, &status)));
}
/*get Illegal TZID where index >= count*/
ucal_getAvailableTZIDs(offset, i, &status);
if(status != U_INDEX_OUTOFBOUNDS_ERROR){
log_err("FAIL:for TZID index >= count Expected INDEX_OUTOFBOUNDS_ERROR Got %s\n", u_errorName(status));
}
status=U_ZERO_ERROR;
#endif
/*Test ucal_openTimeZones, ucal_openCountryTimeZones and ucal_openTimeZoneIDEnumeration */
for (j=0; j<6; ++j) {
const char *api = "?";
const int32_t offsetMinus5 = -5*60*60*1000;
switch (j) {
case 0:
api = "ucal_openTimeZones()";
uenum = ucal_openTimeZones(&status);
break;
case 1:
api = "ucal_openCountryTimeZones(US)";
uenum = ucal_openCountryTimeZones("US", &status);
break;
case 2:
api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL)";
uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, &status);
break;
case 3:
api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_CANONICAL_LOCATION, CA, NULL)";
uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION, "CA", NULL, &status);
break;
case 4:
api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_ANY, NULL, -5 hour)";
uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, NULL, &offsetMinus5, &status);
break;
case 5:
api = "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_ANY, US, -5 hour)";
uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, "US", &offsetMinus5, &status);
break;
}
if (U_FAILURE(status)) {
log_err_status(status, "FAIL: %s failed with %s\n", api,
u_errorName(status));
} else {
const char* id;
int32_t len;
count = uenum_count(uenum, &status);
log_verbose("%s returned %d timezone id's:\n", api, count);
if (count < 5) { /* Don't hard code an exact == test here! */
log_data_err("FAIL: in %s, got %d, expected at least 5 -> %s (Are you missing data?)\n", api, count, u_errorName(status));
}
uenum_reset(uenum, &status);
if (U_FAILURE(status)){
log_err("FAIL: uenum_reset for %s returned %s\n",
api, u_errorName(status));
}
for (i=0; i<count; i++) {
id = uenum_next(uenum, &len, &status);
if (U_FAILURE(status)){
log_err("FAIL: uenum_next for %s returned %s\n",
api, u_errorName(status));
} else {
log_verbose("%s\n", id);
}
}
/* Next one should be NULL */
id = uenum_next(uenum, &len, &status);
if (id != NULL) {
log_err("FAIL: uenum_next for %s returned %s, expected NULL\n",
api, id);
}
}
uenum_close(uenum);
}
/*Test ucal_getDSTSavings*/
status = U_ZERO_ERROR;
i = ucal_getDSTSavings(fgGMTID, &status);
if (U_FAILURE(status)) {
log_err("FAIL: ucal_getDSTSavings(GMT) => %s\n",
u_errorName(status));
} else if (i != 0) {
log_data_err("FAIL: ucal_getDSTSavings(GMT) => %d, expect 0 (Are you missing data?)\n", i);
}
i = ucal_getDSTSavings(PST, &status);
if (U_FAILURE(status)) {
log_err("FAIL: ucal_getDSTSavings(PST) => %s\n",
u_errorName(status));
} else if (i != 1*60*60*1000) {
log_err("FAIL: ucal_getDSTSavings(PST) => %d, expect %d\n", i, 1*60*60*1000);
}
/*Test ucal_set/getDefaultTimeZone and ucal_getHostTimeZone */
status = U_ZERO_ERROR;
i = ucal_getDefaultTimeZone(zone1, UPRV_LENGTHOF(zone1), &status);
if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) {
log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
u_errorName(status));
} else {
ucal_setDefaultTimeZone(EUROPE_PARIS, &status);
if (U_FAILURE(status)) {
log_err("FAIL: ucal_setDefaultTimeZone(Europe/Paris) => %s\n",
u_errorName(status));
} else {
i = ucal_getDefaultTimeZone(zone2, UPRV_LENGTHOF(zone2), &status);
if (U_FAILURE(status)) {
log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
u_errorName(status));
} else {
if (u_strcmp(zone2, EUROPE_PARIS) != 0) {
log_data_err("FAIL: ucal_getDefaultTimeZone() did not return Europe/Paris (Are you missing data?)\n");
} else {
// Redetect the host timezone, it should be the same as zone1 even though ICU's default timezone has been changed.
i = ucal_getHostTimeZone(zone2, UPRV_LENGTHOF(zone2), &status);
if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) {
log_err("FAIL: ucal_getHostTimeZone() => %s\n", u_errorName(status));
} else {
if (u_strcmp(zone1, zone2) != 0) {
log_err("FAIL: ucal_getHostTimeZone() should give the same host timezone even if the default changed. (Got '%s', Expected '%s').\n",
u_austrcpy(tempMsgBuf, zone2), u_austrcpy(tempMsgBuf2, zone1));
}
}
}
}
}
status = U_ZERO_ERROR;
ucal_setDefaultTimeZone(zone1, &status);
}
/*Test ucal_getTZDataVersion*/
status = U_ZERO_ERROR;
tzver = ucal_getTZDataVersion(&status);
if (U_FAILURE(status)) {
log_err_status(status, "FAIL: ucal_getTZDataVersion() => %s\n", u_errorName(status));
} else {
tzverLen = uprv_strlen(tzver);
if (tzverLen == 5 || tzverLen == 6 /* 4 digits + 1 or 2 letters */) {
log_verbose("PASS: ucal_getTZDataVersion returned %s\n", tzver);
} else {
log_err("FAIL: Bad version string was returned by ucal_getTZDataVersion\n");
}
}
/*Testing ucal_getCanonicalTimeZoneID*/
status = U_ZERO_ERROR;
resultlength = ucal_getCanonicalTimeZoneID(PST, -1,
canonicalID, UPRV_LENGTHOF(canonicalID), &isSystemID, &status);
if (U_FAILURE(status)) {
log_data_err("FAIL: error in ucal_getCanonicalTimeZoneID : %s\n", u_errorName(status));
} else {
if (u_strcmp(AMERICA_LOS_ANGELES, canonicalID) != 0) {
log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) returned %s : expected - %s (Are you missing data?)\n",
PST, canonicalID, AMERICA_LOS_ANGELES);
}
if (!isSystemID) {
log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) set %d to isSystemID (Are you missing data?)\n",
PST, isSystemID);
}
}
/*Testing the ucal_open() function*/
status = U_ZERO_ERROR;
log_verbose("\nTesting the ucal_open()\n");
u_uastrcpy(tzID, "PST");
caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)){
log_data_err("FAIL: error in ucal_open caldef : %s\n - (Are you missing data?)", u_errorName(status));
}
caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)){
log_data_err("FAIL: error in ucal_open caldef : %s - (Are you missing data?)\n", u_errorName(status));
}
u_strcpy(tzID, fgGMTID);
calfr=ucal_open(tzID, u_strlen(tzID), "fr_FR", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)){
log_data_err("FAIL: error in ucal_open calfr : %s - (Are you missing data?)\n", u_errorName(status));
}
calit=ucal_open(tzID, u_strlen(tzID), "it_IT", UCAL_TRADITIONAL, &status);
if(U_FAILURE(status)) {
log_data_err("FAIL: error in ucal_open calit : %s - (Are you missing data?)\n", u_errorName(status));
}
/*Testing the clone() function*/
calfrclone = ucal_clone(calfr, &status);
if(U_FAILURE(status)){
log_data_err("FAIL: error in ucal_clone calfr : %s - (Are you missing data?)\n", u_errorName(status));
}
/*Testing udat_getAvailable() and udat_countAvailable()*/
log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
count=ucal_countAvailable();
/* use something sensible w/o hardcoding the count */
if(count > 0) {
log_verbose("PASS: ucal_countAvailable() works fine\n");
log_verbose("The no: of locales for which calendars are available are %d\n", count);
} else {
log_data_err("FAIL: Error in countAvailable()\n");
}
for(i=0;i<count;i++) {
log_verbose("%s\n", ucal_getAvailable(i));
}
/*Testing the equality between calendar's*/
log_verbose("\nTesting ucal_equivalentTo()\n");
if(caldef && caldef2 && calfr && calit) {
if(ucal_equivalentTo(caldef, caldef2) == false || ucal_equivalentTo(caldef, calfr)== true ||
ucal_equivalentTo(caldef, calit)== true || ucal_equivalentTo(calfr, calfrclone) == false) {
log_data_err("FAIL: Error. equivalentTo test failed (Are you missing data?)\n");
} else {
log_verbose("PASS: equivalentTo test passed\n");
}
}
/*Testing the current time and date using ucal_getnow()*/
log_verbose("\nTesting the ucal_getNow function to check if it is fetching tbe current time\n");
now=ucal_getNow();
/* open the date format and format the date to check the output */
datdef=udat_open(UDAT_FULL,UDAT_FULL ,NULL, NULL, 0,NULL,0,&status);
if(U_FAILURE(status)){
log_data_err("FAIL: error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
ucal_close(caldef2);
ucal_close(calfr);
ucal_close(calit);
ucal_close(calfrclone);
ucal_close(caldef);
return;
}
log_verbose("PASS: The current date and time fetched is %s\n", u_austrcpy(tempMsgBuf, myDateFormat(datdef, now)) );
/*Testing the TimeZoneDisplayName */
log_verbose("\nTesting the fetching of time zone display name\n");
/*for the US locale */
resultlength=0;
resultlengthneeded=ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", NULL, resultlength, &status);
if(status==U_BUFFER_OVERFLOW_ERROR)
{
status=U_ZERO_ERROR;
resultlength=resultlengthneeded+1;
result=(UChar*)malloc(sizeof(UChar) * resultlength);
ucal_getTimeZoneDisplayName(caldef, UCAL_DST, "en_US", result, resultlength, &status);
}
if(U_FAILURE(status)) {
log_err("FAIL: Error in getting the timezone display name : %s\n", u_errorName(status));
}
else{
log_verbose("PASS: getting the time zone display name successful : %s, %d needed \n",
u_errorName(status), resultlengthneeded);
}
#define expectPDT "Pacific Daylight Time"
tzdname=(UChar*)malloc(sizeof(UChar) * (sizeof(expectPDT)+1));
u_uastrcpy(tzdname, expectPDT);
if(u_strcmp(tzdname, result)==0){
log_verbose("PASS: got the correct time zone display name %s\n", u_austrcpy(tempMsgBuf, result) );
}
else{
log_err("FAIL: got the wrong time zone(DST) display name %s, wanted %s\n", austrdup(result) , expectPDT);
}
ucal_getTimeZoneDisplayName(caldef, UCAL_SHORT_DST, "en_US", result, resultlength, &status);
u_uastrcpy(tzdname, "PDT");
if(u_strcmp(tzdname, result) != 0){
log_err("FAIL: got the wrong time zone(SHORT_DST) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
}
ucal_getTimeZoneDisplayName(caldef, UCAL_STANDARD, "en_US", result, resultlength, &status);
u_uastrcpy(tzdname, "Pacific Standard Time");
if(u_strcmp(tzdname, result) != 0){
log_err("FAIL: got the wrong time zone(STANDARD) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
}
ucal_getTimeZoneDisplayName(caldef, UCAL_SHORT_STANDARD, "en_US", result, resultlength, &status);
u_uastrcpy(tzdname, "PST");
if(u_strcmp(tzdname, result) != 0){
log_err("FAIL: got the wrong time zone(SHORT_STANDARD) display name %s, wanted %s\n", austrdup(result), austrdup(tzdname));
}
/*testing the setAttributes and getAttributes of a UCalendar*/
log_verbose("\nTesting the getAttributes and set Attributes\n");
count=ucal_getAttribute(calit, UCAL_LENIENT);
count2=ucal_getAttribute(calfr, UCAL_LENIENT);
ucal_setAttribute(calit, UCAL_LENIENT, 0);
ucal_setAttribute(caldef, UCAL_LENIENT, count2);
if( ucal_getAttribute(calit, UCAL_LENIENT) !=0 ||
ucal_getAttribute(calfr, UCAL_LENIENT)!=ucal_getAttribute(caldef, UCAL_LENIENT) )
log_err("FAIL: there is an error in getAttributes or setAttributes\n");
else
log_verbose("PASS: attribute set and got successfully\n");
/*set it back to original value */
log_verbose("Setting it back to normal\n");
ucal_setAttribute(calit, UCAL_LENIENT, count);
if(ucal_getAttribute(calit, UCAL_LENIENT)!=count)
log_err("FAIL: Error in setting the attribute back to normal\n");
/*setting the first day of the week to other values */
count=ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK);
for (i=1; i<=7; ++i) {
ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,i);
if (ucal_getAttribute(calit, UCAL_FIRST_DAY_OF_WEEK) != i)
log_err("FAIL: set/getFirstDayOfWeek failed\n");
}
/*get bogus Attribute*/
count=ucal_getAttribute(calit, (UCalendarAttribute)99); /* BOGUS_ATTRIBUTE */
if(count != -1){
log_err("FAIL: get/bogus attribute should return -1\n");
}
/*set it back to normal */
ucal_setAttribute(calit, UCAL_FIRST_DAY_OF_WEEK,count);
/*setting minimal days of the week to other values */
count=ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK);
for (i=1; i<=7; ++i) {
ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,i);
if (ucal_getAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK) != i)
log_err("FAIL: set/getMinimalDaysInFirstWeek failed\n");
}
/*set it back to normal */
ucal_setAttribute(calit, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,count);
/*testing if the UCalendar's timezone is currently in day light saving's time*/
log_verbose("\nTesting if the UCalendar is currently in daylight saving's time\n");
ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 10, 45, 20, &status);
ucal_inDaylightTime(caldef, &status );
if(U_FAILURE(status)) {
log_err("Error in ucal_inDaylightTime: %s\n", u_errorName(status));
}
if(!ucal_inDaylightTime(caldef, &status))
log_verbose("PASS: It is not in daylight saving's time\n");
else
log_err("FAIL: It is not in daylight saving's time\n");
/*closing the UCalendar*/
ucal_close(caldef);
ucal_close(caldef2);
ucal_close(calfr);
ucal_close(calit);
ucal_close(calfrclone);
/*testing ucal_getType, and ucal_open with UCAL_GREGORIAN*/
for (ucalGetTypeTestPtr = ucalGetTypeTests; ucalGetTypeTestPtr->expectedResult != NULL; ++ucalGetTypeTestPtr) {
const char * localeToDisplay = (ucalGetTypeTestPtr->locale != NULL)? ucalGetTypeTestPtr->locale: "<NULL>";
status = U_ZERO_ERROR;
caldef = ucal_open(NULL, 0, ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType, &status);
if ( U_SUCCESS(status) ) {
const char * calType = ucal_getType(caldef, &status);
if ( U_SUCCESS(status) && calType != NULL ) {
if ( uprv_strcmp( calType, ucalGetTypeTestPtr->expectedResult ) != 0 ) {
log_err("FAIL: ucal_open %s type %d does not return %s calendar\n", localeToDisplay,
ucalGetTypeTestPtr->calType, ucalGetTypeTestPtr->expectedResult);
}
} else {
log_err("FAIL: ucal_open %s type %d, then ucal_getType fails\n", localeToDisplay, ucalGetTypeTestPtr->calType);
}
ucal_close(caldef);
} else {
log_err("FAIL: ucal_open %s type %d fails\n", localeToDisplay, ucalGetTypeTestPtr->calType);
}
}
/*closing the UDateFormat used */
udat_close(datdef);
free(result);
free(tzdname);
}
/*------------------------------------------------------*/
/*Testing the getMillis, setMillis, setDate and setDateTime functions extensively*/
static void TestGetSetDateAPI()
{
UCalendar *caldef = 0, *caldef2 = 0, *caldef3 = 0;
UChar tzID[4];
UDate d1;
int32_t hour;
int32_t zoneOffset;
UDateFormat *datdef = 0;
UErrorCode status=U_ZERO_ERROR;
UDate d2= 837039928046.0;
UChar temp[30];
double testMillis;
int32_t dateBit;
UChar id[4];
int32_t idLen;
log_verbose("\nOpening the calendars()\n");
u_strcpy(tzID, fgGMTID);
/*open the calendars used */
caldef=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
caldef2=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
caldef3=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
/*open the dateformat */
/* this is supposed to open default date format, but later on it treats it like it is "en_US"
- very bad if you try to run the tests on machine where default locale is NOT "en_US" */
/*datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL,fgGMTID,-1, &status);*/
datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US",fgGMTID,-1,NULL,0, &status);
if(U_FAILURE(status))
{
log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
ucal_close(caldef);
ucal_close(caldef2);
ucal_close(caldef3);
udat_close(datdef);
return;
}
/*Testing getMillis and setMillis */
log_verbose("\nTesting the date and time fetched in millis for a calendar using getMillis\n");
d1=ucal_getMillis(caldef, &status);
if(U_FAILURE(status)){
log_err("Error in getMillis : %s\n", u_errorName(status));
}
/*testing setMillis */
log_verbose("\nTesting the set date and time function using setMillis\n");
ucal_setMillis(caldef, d2, &status);
if(U_FAILURE(status)){
log_err("Error in setMillis : %s\n", u_errorName(status));
}
/*testing if the calendar date is set properly or not */
d1=ucal_getMillis(caldef, &status);
if(u_strcmp(myDateFormat(datdef, d1), myDateFormat(datdef, d2))!=0)
log_err("error in setMillis or getMillis\n");
/*-------------------*/
/*testing large negative millis*/
/*test a previously failed millis and beyond the lower bounds - ICU trac #9403 */
// -184303902611600000.0 - just beyond lower bounds (#9403 sets U_ILLEGAL_ARGUMENT_ERROR in strict mode)
// -46447814188001000.0 - fixed by #9403
log_verbose("\nTesting very large valid millis & invalid setMillis values (in both strict & lienent modes) detected\n");
testMillis = -46447814188001000.0; // point where floorDivide in handleComputeFields failed as per #9403
log_verbose("using value[%lf]\n", testMillis);
ucal_setAttribute(caldef3, UCAL_LENIENT, 0);
ucal_setMillis(caldef3, testMillis, &status);
if(U_FAILURE(status)){
log_err("Fail: setMillis incorrectly detected invalid value : for millis : %e : returned : %s\n", testMillis, u_errorName(status));
status = U_ZERO_ERROR;
}
log_verbose("\nTesting invalid setMillis values detected\n");
testMillis = -184303902611600000.0;
log_verbose("using value[%lf]\n", testMillis);
ucal_setAttribute(caldef3, UCAL_LENIENT, 1);
ucal_setMillis(caldef3, testMillis, &status);
if(U_FAILURE(status)){
log_err("Fail: setMillis incorrectly detected invalid value : for millis : %e : returned : %s\n", testMillis, u_errorName(status));
status = U_ZERO_ERROR;
} else {
dateBit = ucal_get(caldef2, UCAL_MILLISECOND, &status);
if(testMillis == dateBit)
{
log_err("Fail: error in setMillis, allowed invalid value %e : returns millisecond : %d", testMillis, dateBit);
} else {
log_verbose("Pass: setMillis correctly pinned min, returned : %d", dateBit);
}
}
log_verbose("\nTesting invalid setMillis values detected\n");
testMillis = -184303902611600000.0;
log_verbose("using value[%lf]\n", testMillis);
ucal_setAttribute(caldef3, UCAL_LENIENT, 0);
ucal_setMillis(caldef3, testMillis, &status);
if(U_FAILURE(status)){
log_verbose("Pass: Illegal argument error as expected : for millis : %e : returned : %s\n", testMillis, u_errorName(status));
status = U_ZERO_ERROR;
} else {
dateBit = ucal_get(caldef3, UCAL_DAY_OF_MONTH, &status);
log_err("Fail: error in setMillis, allowed invalid value %e : returns DayOfMonth : %d", testMillis, dateBit);
}
/*-------------------*/
ctest_setTimeZone(NULL, &status);
/*testing ucal_setTimeZone() and ucal_getTimeZoneID function*/
log_verbose("\nTesting if the function ucal_setTimeZone() and ucal_getTimeZoneID work fine\n");
idLen = ucal_getTimeZoneID(caldef2, id, UPRV_LENGTHOF(id), &status);
(void)idLen; /* Suppress set but not used warning. */
if (U_FAILURE(status)) {
log_err("Error in getTimeZoneID : %s\n", u_errorName(status));
} else if (u_strcmp(id, fgGMTID) != 0) {
log_err("FAIL: getTimeZoneID returns a wrong ID: actual=%d, expected=%s\n", austrdup(id), austrdup(fgGMTID));
} else {
log_verbose("PASS: getTimeZoneID works fine\n");
}
ucal_setMillis(caldef2, d2, &status);
if(U_FAILURE(status)){
log_err("Error in getMillis : %s\n", u_errorName(status));
}
hour=ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status);
u_uastrcpy(tzID, "PST");
ucal_setTimeZone(caldef2,tzID, 3, &status);
if(U_FAILURE(status)){
log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status));
}
else
log_verbose("ucal_setTimeZone worked fine\n");
idLen = ucal_getTimeZoneID(caldef2, id, UPRV_LENGTHOF(id), &status);
if (U_FAILURE(status)) {
log_err("Error in getTimeZoneID : %s\n", u_errorName(status));
} else if (u_strcmp(id, tzID) != 0) {
log_err("FAIL: getTimeZoneID returns a wrong ID: actual=%d, expected=%s\n", austrdup(id), austrdup(tzID));
} else {
log_verbose("PASS: getTimeZoneID works fine\n");
}
if(hour == ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status))
log_err("FAIL: Error setting the time zone doesn't change the represented time\n");
else if((hour-8 + 1) != ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status)) /*because it is not in daylight savings time */
log_err("FAIL: Error setTimeZone doesn't change the represented time correctly with 8 hour offset\n");
else
log_verbose("PASS: setTimeZone works fine\n");
/*testing setTimeZone roundtrip */
log_verbose("\nTesting setTimeZone() roundtrip\n");
u_strcpy(tzID, fgGMTID);
ucal_setTimeZone(caldef2, tzID, 3, &status);
if(U_FAILURE(status)){
log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status));
}
if(d2==ucal_getMillis(caldef2, &status))
log_verbose("PASS: setTimeZone roundtrip test passed\n");
else
log_err("FAIL: setTimeZone roundtrip test failed\n");
zoneOffset = ucal_get(caldef2, UCAL_ZONE_OFFSET, &status);
if(U_FAILURE(status)){
log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone(): %s\n", u_errorName(status));
}
else if (zoneOffset != 0) {
log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset);
}
ucal_setTimeZone(caldef2, NULL, -1, &status);
if(U_FAILURE(status)){
log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status));
}
if(ucal_getMillis(caldef2, &status))
log_verbose("PASS: setTimeZone roundtrip test passed\n");
else
log_err("FAIL: setTimeZone roundtrip test failed\n");
zoneOffset = ucal_get(caldef2, UCAL_ZONE_OFFSET, &status);
if(U_FAILURE(status)){
log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone(): %s\n", u_errorName(status));
}
else if (zoneOffset != -28800000) {
log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset);
}
ctest_resetTimeZone();
/*----------------------------* */
/*Testing if setDate works fine */
log_verbose("\nTesting the ucal_setDate() function \n");
u_strcpy(temp, u"Dec 17, 1971, 11:05:28\u202FPM");
ucal_setDate(caldef,1971, UCAL_DECEMBER, 17, &status);
if(U_FAILURE(status)){
log_err("error in setting the calendar date : %s\n", u_errorName(status));
}
/*checking if the calendar date is set properly or not */
d1=ucal_getMillis(caldef, &status);
if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
log_verbose("PASS:setDate works fine\n");
else
log_err("FAIL:Error in setDate()\n");
/* Testing setDate Extensively with various input values */
log_verbose("\nTesting ucal_setDate() extensively\n");
ucal_setDate(caldef, 1999, UCAL_JANUARY, 10, &status);
verify1("1999 10th day of January is :", caldef, datdef, 1999, UCAL_JANUARY, 10);
ucal_setDate(caldef, 1999, UCAL_DECEMBER, 3, &status);
verify1("1999 3rd day of December is :", caldef, datdef, 1999, UCAL_DECEMBER, 3);
ucal_setDate(caldef, 2000, UCAL_MAY, 3, &status);
verify1("2000 3rd day of May is :", caldef, datdef, 2000, UCAL_MAY, 3);
ucal_setDate(caldef, 1999, UCAL_AUGUST, 32, &status);
verify1("1999 32th day of August is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1);
ucal_setDate(caldef, 1999, UCAL_MARCH, 0, &status);
verify1("1999 0th day of March is :", caldef, datdef, 1999, UCAL_FEBRUARY, 28);
ucal_setDate(caldef, 0, UCAL_MARCH, 12, &status);
/*--------------------*/
/*Testing if setDateTime works fine */
log_verbose("\nTesting the ucal_setDateTime() function \n");
u_strcpy(temp, u"May 3, 1972, 4:30:42\u202FPM");
ucal_setDateTime(caldef,1972, UCAL_MAY, 3, 16, 30, 42, &status);
if(U_FAILURE(status)){
log_err("error in setting the calendar date : %s\n", u_errorName(status));
}
/*checking if the calendar date is set properly or not */
d1=ucal_getMillis(caldef, &status);
if(u_strcmp(myDateFormat(datdef, d1), temp)==0)
log_verbose("PASS: setDateTime works fine\n");
else
log_err("FAIL: Error in setDateTime\n");
/*Testing setDateTime extensively with various input values*/
log_verbose("\nTesting ucal_setDateTime() function extensively\n");
ucal_setDateTime(caldef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, &status);
verify2("1999 10th day of October at 6:45:30 is :", caldef, datdef, 1999, UCAL_OCTOBER, 10, 6, 45, 30, 0 );
ucal_setDateTime(caldef, 1999, UCAL_MARCH, 3, 15, 10, 55, &status);
verify2("1999 3rd day of March at 15:10:55 is :", caldef, datdef, 1999, UCAL_MARCH, 3, 3, 10, 55, 1);
ucal_setDateTime(caldef, 1999, UCAL_MAY, 3, 25, 30, 45, &status);
verify2("1999 3rd day of May at 25:30:45 is :", caldef, datdef, 1999, UCAL_MAY, 4, 1, 30, 45, 0);
ucal_setDateTime(caldef, 1999, UCAL_AUGUST, 32, 22, 65, 40, &status);
verify2("1999 32th day of August at 22:65:40 is :", caldef, datdef, 1999, UCAL_SEPTEMBER, 1, 11, 5, 40,1);
ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, 0, 0, 0,&status);
verify2("1999 12th day of March at 0:0:0 is :", caldef, datdef, 1999, UCAL_MARCH, 12, 0, 0, 0, 0);
ucal_setDateTime(caldef, 1999, UCAL_MARCH, 12, -10, -10,0, &status);
verify2("1999 12th day of March is at -10:-10:0 :", caldef, datdef, 1999, UCAL_MARCH, 11, 1, 50, 0, 1);
/*close caldef and datdef*/
ucal_close(caldef);
ucal_close(caldef2);
ucal_close(caldef3);
udat_close(datdef);
}
/*----------------------------------------------------------- */
/**
* Confirm the functioning of the calendar field related functions.
*/
static void TestFieldGetSet()
{
UCalendar *cal = 0;
UChar tzID[4];
UDateFormat *datdef = 0;
UDate d1 = 0;
UErrorCode status=U_ZERO_ERROR;
(void)d1; /* Suppress set but not used warning. */
log_verbose("\nFetching pointer to UCalendar using the ucal_open()\n");
u_strcpy(tzID, fgGMTID);
/*open the calendar used */
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
if (U_FAILURE(status)) {
log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status));
return;
}
datdef=udat_open(UDAT_SHORT,UDAT_SHORT ,NULL,fgGMTID,-1,NULL, 0, &status);
if(U_FAILURE(status))
{
log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
}
/*Testing ucal_get()*/
log_verbose("\nTesting the ucal_get() function of Calendar\n");
ucal_setDateTime(cal, 1999, UCAL_MARCH, 12, 5, 25, 30, &status);
if(U_FAILURE(status)){
log_data_err("error in the setDateTime() : %s (Are you missing data?)\n", u_errorName(status));
}
if(ucal_get(cal, UCAL_YEAR, &status)!=1999 || ucal_get(cal, UCAL_MONTH, &status)!=2 ||
ucal_get(cal, UCAL_DATE, &status)!=12 || ucal_get(cal, UCAL_HOUR, &status)!=5)
log_data_err("error in ucal_get() -> %s (Are you missing data?)\n", u_errorName(status));
else if(ucal_get(cal, UCAL_DAY_OF_WEEK_IN_MONTH, &status)!=2 || ucal_get(cal, UCAL_DAY_OF_WEEK, &status)!=6
|| ucal_get(cal, UCAL_WEEK_OF_MONTH, &status)!=2 || ucal_get(cal, UCAL_WEEK_OF_YEAR, &status)!= 11)
log_err("FAIL: error in ucal_get()\n");
else
log_verbose("PASS: ucal_get() works fine\n");
/*Testing the ucal_set() , ucal_clear() functions of calendar*/
log_verbose("\nTesting the set, and clear field functions of calendar\n");
ucal_setAttribute(cal, UCAL_LENIENT, 0);
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
ucal_set(cal, UCAL_DATE, 3);
verify1("1997 third day of June = ", cal, datdef, 1997, UCAL_JUNE, 3);
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 1);
verify1("1997 first Tuesday in June = ", cal, datdef, 1997, UCAL_JUNE, 3);
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, - 1);
verify1("1997 last Tuesday in June = ", cal, datdef,1997, UCAL_JUNE, 24);
/*give undesirable input */
status = U_ZERO_ERROR;
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, 0);
d1 = ucal_getMillis(cal, &status);
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 zero-th Tuesday in June\n");
} else {
log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
}
status = U_ZERO_ERROR;
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
ucal_set(cal, UCAL_WEEK_OF_MONTH, 1);
verify1("1997 Tuesday in week 1 of June = ", cal,datdef, 1997, UCAL_JUNE, 3);
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
ucal_set(cal, UCAL_WEEK_OF_MONTH, 5);
verify1("1997 Tuesday in week 5 of June = ", cal,datdef, 1997, UCAL_JULY, 1);
status = U_ZERO_ERROR;
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_MONTH, UCAL_JUNE);
ucal_set(cal, UCAL_WEEK_OF_MONTH, 0);
ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
d1 = ucal_getMillis(cal,&status);
if (status != U_ILLEGAL_ARGUMENT_ERROR){
log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 Tuesday zero-th week in June\n");
} else {
log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
}
status = U_ZERO_ERROR;
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR_WOY, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_WEEK_OF_YEAR, 1);
verify1("1997 Tuesday in week 1 of year = ", cal, datdef,1996, UCAL_DECEMBER, 31);
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1997);
ucal_set(cal, UCAL_DAY_OF_WEEK, UCAL_TUESDAY);
ucal_set(cal, UCAL_WEEK_OF_YEAR, 10);
verify1("1997 Tuesday in week 10 of year = ", cal,datdef, 1997, UCAL_MARCH, 4);
ucal_clear(cal);
ucal_set(cal, UCAL_YEAR, 1999);
ucal_set(cal, UCAL_DAY_OF_YEAR, 1);
verify1("1999 1st day of the year =", cal, datdef, 1999, UCAL_JANUARY, 1);
ucal_set(cal, UCAL_MONTH, -3);
d1 = ucal_getMillis(cal,&status);
if (status != U_ILLEGAL_ARGUMENT_ERROR){
log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1999 -3th month\n");
} else {
log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
}
ucal_setAttribute(cal, UCAL_LENIENT, 1);
ucal_set(cal, UCAL_MONTH, -3);
verify1("1999 -3th month should be", cal, datdef, 1998, UCAL_OCTOBER, 1);
/*testing isSet and clearField()*/
if(!ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
log_err("FAIL: error in isSet\n");
else
log_verbose("PASS: isSet working fine\n");
ucal_clearField(cal, UCAL_WEEK_OF_YEAR);
if(ucal_isSet(cal, UCAL_WEEK_OF_YEAR))
log_err("FAIL: there is an error in clearField or isSet\n");
else
log_verbose("PASS :clearField working fine\n");
/*-------------------------------*/
ucal_close(cal);
udat_close(datdef);
}
typedef struct {
const char * zone;
int32_t year;
int32_t month;
int32_t day;
int32_t hour;
} TransitionItem;
static const TransitionItem transitionItems[] = {
{ "America/Caracas", 2007, UCAL_DECEMBER, 8, 10 }, /* day before change in UCAL_ZONE_OFFSET */
{ "US/Pacific", 2011, UCAL_MARCH, 12, 10 }, /* day before change in UCAL_DST_OFFSET */
{ NULL, 0, 0, 0, 0 }
};
/* ------------------------------------- */
/**
* Execute adding and rolling in Calendar extensively,
*/
static void TestAddRollExtensive()
{
const TransitionItem * itemPtr;
UCalendar *cal = 0;
int32_t i,limit;
UChar tzID[32];
UCalendarDateFields e;
int32_t y,m,d,hr,min,sec,ms;
int32_t maxlimit = 40;
UErrorCode status = U_ZERO_ERROR;
y = 1997; m = UCAL_FEBRUARY; d = 1; hr = 1; min = 1; sec = 0; ms = 0;
log_verbose("Testing add and roll extensively\n");
u_uastrcpy(tzID, "PST");
/*open the calendar used */
cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);
if (U_FAILURE(status)) {
log_data_err("ucal_open() failed : %s - (Are you missing data?)\n", u_errorName(status));
return;
}
ucal_set(cal, UCAL_YEAR, y);
ucal_set(cal, UCAL_MONTH, m);
ucal_set(cal, UCAL_DATE, d);
ucal_setAttribute(cal, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,1);
/* Confirm that adding to various fields works.*/
log_verbose("\nTesting to confirm that adding to various fields works with ucal_add()\n");
checkDate(cal, y, m, d);
ucal_add(cal,UCAL_YEAR, 1, &status);
if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status)); return; }
y++;
checkDate(cal, y, m, d);
ucal_add(cal,UCAL_MONTH, 12, &status);
if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status) ); return; }
y+=1;
checkDate(cal, y, m, d);
ucal_add(cal,UCAL_DATE, 1, &status);
if (U_FAILURE(status)) { log_err("ucal_add failed: %s\n", u_errorName(status) ); return; }
d++;
checkDate(cal, y, m, d);
ucal_add(cal,UCAL_DATE, 2, &status);