xref: /aosp_15_r20/external/icu/icu4c/source/test/cintltst/cdtdptst.c (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /********************************************************************
4*0e209d39SAndroid Build Coastguard Worker  * COPYRIGHT:
5*0e209d39SAndroid Build Coastguard Worker  * Copyright (c) 1997-2014, International Business Machines Corporation and
6*0e209d39SAndroid Build Coastguard Worker  * others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker  ********************************************************************/
8*0e209d39SAndroid Build Coastguard Worker /********************************************************************************
9*0e209d39SAndroid Build Coastguard Worker *
10*0e209d39SAndroid Build Coastguard Worker * File CDTDPTST.C
11*0e209d39SAndroid Build Coastguard Worker *
12*0e209d39SAndroid Build Coastguard Worker * Modification History:
13*0e209d39SAndroid Build Coastguard Worker *        Name                     Description
14*0e209d39SAndroid Build Coastguard Worker *     Madhu Katragadda               Creation
15*0e209d39SAndroid Build Coastguard Worker *********************************************************************************
16*0e209d39SAndroid Build Coastguard Worker */
17*0e209d39SAndroid Build Coastguard Worker /* INDEPTH TEST FOR DATE FORMAT */
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
20*0e209d39SAndroid Build Coastguard Worker 
21*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
22*0e209d39SAndroid Build Coastguard Worker 
23*0e209d39SAndroid Build Coastguard Worker #include <stdbool.h>
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker #include "unicode/uloc.h"
26*0e209d39SAndroid Build Coastguard Worker #include "unicode/udat.h"
27*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucal.h"
28*0e209d39SAndroid Build Coastguard Worker #include "unicode/unum.h"
29*0e209d39SAndroid Build Coastguard Worker #include "unicode/ustring.h"
30*0e209d39SAndroid Build Coastguard Worker #include "cintltst.h"
31*0e209d39SAndroid Build Coastguard Worker #include "cdtdptst.h"
32*0e209d39SAndroid Build Coastguard Worker #include "cformtst.h"
33*0e209d39SAndroid Build Coastguard Worker 
34*0e209d39SAndroid Build Coastguard Worker #include "cmemory.h"
35*0e209d39SAndroid Build Coastguard Worker 
36*0e209d39SAndroid Build Coastguard Worker void addDtFrDepTest(TestNode** root);
37*0e209d39SAndroid Build Coastguard Worker 
addDtFrDepTest(TestNode ** root)38*0e209d39SAndroid Build Coastguard Worker void addDtFrDepTest(TestNode** root)
39*0e209d39SAndroid Build Coastguard Worker {
40*0e209d39SAndroid Build Coastguard Worker     addTest(root, &TestTwoDigitYearDSTParse, "tsformat/cdtdptst/TestTwoDigitYearDSTParse");
41*0e209d39SAndroid Build Coastguard Worker     addTest(root, &TestPartialParse994, "tsformat/cdtdptst/TestPartialParse994");
42*0e209d39SAndroid Build Coastguard Worker     addTest(root, &TestRunTogetherPattern985, "tsformat/cdtdptst/TestRunTogetherPattern985");
43*0e209d39SAndroid Build Coastguard Worker     addTest(root, &TestCzechMonths459, "tsformat/cdtdptst/TestCzechMonths459");
44*0e209d39SAndroid Build Coastguard Worker     addTest(root, &TestQuotePattern161, "tsformat/cdtdptst/TestQuotePattern161");
45*0e209d39SAndroid Build Coastguard Worker     addTest(root, &TestBooleanAttributes, "tsformat/cdtdptst/TestBooleanAttributes");
46*0e209d39SAndroid Build Coastguard Worker 
47*0e209d39SAndroid Build Coastguard Worker 
48*0e209d39SAndroid Build Coastguard Worker }
49*0e209d39SAndroid Build Coastguard Worker 
50*0e209d39SAndroid Build Coastguard Worker /**
51*0e209d39SAndroid Build Coastguard Worker  * Test the parsing of 2-digit years.
52*0e209d39SAndroid Build Coastguard Worker  */
TestTwoDigitYearDSTParse(void)53*0e209d39SAndroid Build Coastguard Worker void TestTwoDigitYearDSTParse(void)
54*0e209d39SAndroid Build Coastguard Worker {
55*0e209d39SAndroid Build Coastguard Worker     UDateFormat *fullFmt, *fmt;
56*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
57*0e209d39SAndroid Build Coastguard Worker     UChar *pattern;
58*0e209d39SAndroid Build Coastguard Worker     UDate d;
59*0e209d39SAndroid Build Coastguard Worker     UChar *s;
60*0e209d39SAndroid Build Coastguard Worker     int32_t pos;
61*0e209d39SAndroid Build Coastguard Worker 
62*0e209d39SAndroid Build Coastguard Worker     ctest_setTimeZone(NULL, &status);
63*0e209d39SAndroid Build Coastguard Worker 
64*0e209d39SAndroid Build Coastguard Worker     pattern=(UChar*)malloc(sizeof(UChar) * (strlen("EEE MMM dd HH:mm:ss.SSS zzz yyyy G")+1 ));
65*0e209d39SAndroid Build Coastguard Worker     u_uastrcpy(pattern, "EEE MMM dd HH:mm:ss.SSS zzz yyyy G");
66*0e209d39SAndroid Build Coastguard Worker     fullFmt= udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US",NULL,0,pattern, u_strlen(pattern),&status);
67*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status))    {
68*0e209d39SAndroid Build Coastguard Worker         log_data_err("FAIL: Error in creating a date format using udat_openPattern %s - (Are you missing data?)\n",
69*0e209d39SAndroid Build Coastguard Worker             myErrorName(status) );
70*0e209d39SAndroid Build Coastguard Worker     }
71*0e209d39SAndroid Build Coastguard Worker     else {
72*0e209d39SAndroid Build Coastguard Worker         log_verbose("PASS: creating dateformat using udat_openPattern() successful\n");
73*0e209d39SAndroid Build Coastguard Worker 
74*0e209d39SAndroid Build Coastguard Worker         u_uastrcpy(pattern, "dd-MMM-yy h:mm:ss 'o''clock' a z");
75*0e209d39SAndroid Build Coastguard Worker         fmt= udat_open(UDAT_PATTERN,UDAT_PATTERN,"en_US", NULL, 0,pattern, u_strlen(pattern), &status);
76*0e209d39SAndroid Build Coastguard Worker 
77*0e209d39SAndroid Build Coastguard Worker 
78*0e209d39SAndroid Build Coastguard Worker         s=(UChar*)malloc(sizeof(UChar) * (strlen("03-Apr-04 2:20:47 o'clock AM PST")+1) );
79*0e209d39SAndroid Build Coastguard Worker         u_uastrcpy(s, "03-Apr-04 2:20:47 o'clock AM PST");
80*0e209d39SAndroid Build Coastguard Worker         pos=0;
81*0e209d39SAndroid Build Coastguard Worker         d = udat_parse(fmt, s, u_strlen(s), &pos, &status);
82*0e209d39SAndroid Build Coastguard Worker         if (U_FAILURE(status)) {
83*0e209d39SAndroid Build Coastguard Worker             log_err("FAIL: Could not parse \"%s\"\n", austrdup(s));
84*0e209d39SAndroid Build Coastguard Worker         } else {
85*0e209d39SAndroid Build Coastguard Worker             UCalendar *cal = ucal_open(NULL, 0, uloc_getDefault(), UCAL_TRADITIONAL, &status);
86*0e209d39SAndroid Build Coastguard Worker             if (U_FAILURE(status)) {
87*0e209d39SAndroid Build Coastguard Worker                 log_err_status(status, "FAIL: Could not open calendar: %s\n", u_errorName(status));
88*0e209d39SAndroid Build Coastguard Worker             } else {
89*0e209d39SAndroid Build Coastguard Worker                 int32_t h;
90*0e209d39SAndroid Build Coastguard Worker                 ucal_setMillis(cal, d, &status);
91*0e209d39SAndroid Build Coastguard Worker                 h = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
92*0e209d39SAndroid Build Coastguard Worker                 if (U_FAILURE(status)) {
93*0e209d39SAndroid Build Coastguard Worker                     log_err("FAIL: Some calendar operations failed");
94*0e209d39SAndroid Build Coastguard Worker                 } else if (h != 2) {
95*0e209d39SAndroid Build Coastguard Worker                     log_err("FAIL: Parse of \"%s\" returned HOUR_OF_DAY %d\n",
96*0e209d39SAndroid Build Coastguard Worker                             austrdup(s), h);
97*0e209d39SAndroid Build Coastguard Worker                 }
98*0e209d39SAndroid Build Coastguard Worker                 ucal_close(cal);
99*0e209d39SAndroid Build Coastguard Worker             }
100*0e209d39SAndroid Build Coastguard Worker         }
101*0e209d39SAndroid Build Coastguard Worker 
102*0e209d39SAndroid Build Coastguard Worker         udat_close(fullFmt);
103*0e209d39SAndroid Build Coastguard Worker         udat_close(fmt);
104*0e209d39SAndroid Build Coastguard Worker         free(s);
105*0e209d39SAndroid Build Coastguard Worker     }
106*0e209d39SAndroid Build Coastguard Worker     free(pattern);
107*0e209d39SAndroid Build Coastguard Worker 
108*0e209d39SAndroid Build Coastguard Worker     ctest_resetTimeZone();
109*0e209d39SAndroid Build Coastguard Worker }
110*0e209d39SAndroid Build Coastguard Worker 
111*0e209d39SAndroid Build Coastguard Worker 
112*0e209d39SAndroid Build Coastguard Worker /**
113*0e209d39SAndroid Build Coastguard Worker  * Verify that strings which contain incomplete specifications are parsed
114*0e209d39SAndroid Build Coastguard Worker  * correctly.  In some instances, this means not being parsed at all, and
115*0e209d39SAndroid Build Coastguard Worker  * returning an appropriate error.
116*0e209d39SAndroid Build Coastguard Worker  */
TestPartialParse994(void)117*0e209d39SAndroid Build Coastguard Worker void TestPartialParse994(void)
118*0e209d39SAndroid Build Coastguard Worker {
119*0e209d39SAndroid Build Coastguard Worker     int32_t pos;
120*0e209d39SAndroid Build Coastguard Worker     UDateFormat *f;
121*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
122*0e209d39SAndroid Build Coastguard Worker     UChar *s;
123*0e209d39SAndroid Build Coastguard Worker     UChar *fmtChars;
124*0e209d39SAndroid Build Coastguard Worker     UDate d, null;
125*0e209d39SAndroid Build Coastguard Worker     null=0;
126*0e209d39SAndroid Build Coastguard Worker 
127*0e209d39SAndroid Build Coastguard Worker     /* this is supposed to open default date format, but later on it treats it like it is "en_US"
128*0e209d39SAndroid Build Coastguard Worker        - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
129*0e209d39SAndroid Build Coastguard Worker     /* f = udat_open(UDAT_DEFAULT, UDAT_SHORT, NULL, NULL, 0, &status); */
130*0e209d39SAndroid Build Coastguard Worker     f = udat_open(UDAT_DEFAULT, UDAT_SHORT, "en_US", NULL, 0,  NULL, 0,&status);
131*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)){
132*0e209d39SAndroid Build Coastguard Worker         log_data_err("FAIL: ErrorCode received during test: %s (Are you missing data?)\n", myErrorName(status));
133*0e209d39SAndroid Build Coastguard Worker         return;
134*0e209d39SAndroid Build Coastguard Worker     }
135*0e209d39SAndroid Build Coastguard Worker     s=(UChar*)malloc(sizeof(UChar) * (strlen("01/01/1997 10:11:42 AM")+1) );
136*0e209d39SAndroid Build Coastguard Worker     u_uastrcpy(s, "01/01/1997 10:11:42 AM");
137*0e209d39SAndroid Build Coastguard Worker     pos=0;
138*0e209d39SAndroid Build Coastguard Worker     d = udat_parse(f, s, u_strlen(s), &pos, &status);
139*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)) {
140*0e209d39SAndroid Build Coastguard Worker       log_data_err("FAIL: could not parse - exiting");
141*0e209d39SAndroid Build Coastguard Worker       return;
142*0e209d39SAndroid Build Coastguard Worker     }
143*0e209d39SAndroid Build Coastguard Worker     fmtChars = myDateFormat(f, d);
144*0e209d39SAndroid Build Coastguard Worker     if(fmtChars) {
145*0e209d39SAndroid Build Coastguard Worker       log_verbose("%s\n", fmtChars);
146*0e209d39SAndroid Build Coastguard Worker     } else {
147*0e209d39SAndroid Build Coastguard Worker       log_data_err("FAIL: could not format \n");
148*0e209d39SAndroid Build Coastguard Worker       return;
149*0e209d39SAndroid Build Coastguard Worker     }
150*0e209d39SAndroid Build Coastguard Worker     tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/01 10:11:42", d);
151*0e209d39SAndroid Build Coastguard Worker     tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/01 10:", null);
152*0e209d39SAndroid Build Coastguard Worker     tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/01 10", null);
153*0e209d39SAndroid Build Coastguard Worker     tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/01 ", null);
154*0e209d39SAndroid Build Coastguard Worker     tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/01", null);
155*0e209d39SAndroid Build Coastguard Worker     udat_close(f);
156*0e209d39SAndroid Build Coastguard Worker     free(s);
157*0e209d39SAndroid Build Coastguard Worker }
158*0e209d39SAndroid Build Coastguard Worker 
159*0e209d39SAndroid Build Coastguard Worker 
160*0e209d39SAndroid Build Coastguard Worker 
tryPat994(UDateFormat * format,const char * pattern,const char * s,UDate expected)161*0e209d39SAndroid Build Coastguard Worker void tryPat994(UDateFormat* format, const char* pattern, const char* s, UDate expected)
162*0e209d39SAndroid Build Coastguard Worker {
163*0e209d39SAndroid Build Coastguard Worker     UChar *f;
164*0e209d39SAndroid Build Coastguard Worker     UChar *str, *pat;
165*0e209d39SAndroid Build Coastguard Worker     UDate date;
166*0e209d39SAndroid Build Coastguard Worker     UDate null=0;
167*0e209d39SAndroid Build Coastguard Worker     int32_t pos;
168*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
169*0e209d39SAndroid Build Coastguard Worker     str=(UChar*)malloc(sizeof(UChar) * (strlen(s) + 1) );
170*0e209d39SAndroid Build Coastguard Worker     u_uastrcpy(str, s);
171*0e209d39SAndroid Build Coastguard Worker     pat=(UChar*)malloc(sizeof(UChar) * (strlen(pattern) + 1) );
172*0e209d39SAndroid Build Coastguard Worker     u_uastrcpy(pat, pattern);
173*0e209d39SAndroid Build Coastguard Worker     log_verbose("Pattern : %s ;  String : %s\n", austrdup(pat), austrdup(str));
174*0e209d39SAndroid Build Coastguard Worker     udat_applyPattern(format, false, pat, u_strlen(pat));
175*0e209d39SAndroid Build Coastguard Worker     pos=0;
176*0e209d39SAndroid Build Coastguard Worker     date = udat_parse(format, str, u_strlen(str), &pos, &status);
177*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status) || date == null) {
178*0e209d39SAndroid Build Coastguard Worker         log_verbose("ParseException: : %s\n", myErrorName(status) );
179*0e209d39SAndroid Build Coastguard Worker          if (expected != null)
180*0e209d39SAndroid Build Coastguard Worker              log_err("FAIL: Expected: %s\n", austrdup(myDateFormat(format, expected)) );
181*0e209d39SAndroid Build Coastguard Worker         }
182*0e209d39SAndroid Build Coastguard Worker     else {
183*0e209d39SAndroid Build Coastguard Worker         f=myDateFormat(format, date);
184*0e209d39SAndroid Build Coastguard Worker         log_verbose(" parse( %s ) -> %s\n", austrdup(str), austrdup(f));
185*0e209d39SAndroid Build Coastguard Worker         if (expected == null || date != expected)
186*0e209d39SAndroid Build Coastguard Worker             log_err("FAIL: Expected null for \"%s\"\n", s);
187*0e209d39SAndroid Build Coastguard Worker         if (u_strcmp(f, str) !=0)
188*0e209d39SAndroid Build Coastguard Worker             log_err("FAIL: Expected : %s\n", austrdup(str) );
189*0e209d39SAndroid Build Coastguard Worker     }
190*0e209d39SAndroid Build Coastguard Worker 
191*0e209d39SAndroid Build Coastguard Worker     free(str);
192*0e209d39SAndroid Build Coastguard Worker     free(pat);
193*0e209d39SAndroid Build Coastguard Worker }
194*0e209d39SAndroid Build Coastguard Worker 
195*0e209d39SAndroid Build Coastguard Worker 
196*0e209d39SAndroid Build Coastguard Worker /**
197*0e209d39SAndroid Build Coastguard Worker  * Verify the behavior of patterns in which digits for different fields run together
198*0e209d39SAndroid Build Coastguard Worker  * without intervening separators.
199*0e209d39SAndroid Build Coastguard Worker  */
TestRunTogetherPattern985(void)200*0e209d39SAndroid Build Coastguard Worker void TestRunTogetherPattern985(void)
201*0e209d39SAndroid Build Coastguard Worker {
202*0e209d39SAndroid Build Coastguard Worker     int32_t pos;
203*0e209d39SAndroid Build Coastguard Worker     UChar *pattern=NULL, *now=NULL, *then=NULL;
204*0e209d39SAndroid Build Coastguard Worker     UDateFormat *format;
205*0e209d39SAndroid Build Coastguard Worker     UDate date1, date2;
206*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
207*0e209d39SAndroid Build Coastguard Worker     pattern=(UChar*)malloc(sizeof(UChar) * (strlen("yyyyMMddHHmmssSSS")+1) );
208*0e209d39SAndroid Build Coastguard Worker     u_uastrcpy(pattern, "yyyyMMddHHmmssSSS");
209*0e209d39SAndroid Build Coastguard Worker     format = udat_open(UDAT_PATTERN, UDAT_PATTERN, NULL, NULL, 0,pattern, u_strlen(pattern), &status);
210*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)){
211*0e209d39SAndroid Build Coastguard Worker         log_data_err("FAIL: Error in date format construction with pattern: %s - (Are you missing data?)\n", myErrorName(status));
212*0e209d39SAndroid Build Coastguard Worker         free(pattern);
213*0e209d39SAndroid Build Coastguard Worker         return;
214*0e209d39SAndroid Build Coastguard Worker     }
215*0e209d39SAndroid Build Coastguard Worker     date1 = ucal_getNow();
216*0e209d39SAndroid Build Coastguard Worker     now=myDateFormat(format, date1);
217*0e209d39SAndroid Build Coastguard Worker     log_verbose("%s\n", austrdup(now) );
218*0e209d39SAndroid Build Coastguard Worker     pos = 0;
219*0e209d39SAndroid Build Coastguard Worker     date2 = udat_parse(format, now, u_strlen(now), &pos, &status);
220*0e209d39SAndroid Build Coastguard Worker     if (date2 == 0) log_verbose("Parse stopped at : %d\n", pos);
221*0e209d39SAndroid Build Coastguard Worker     else then=myDateFormat(format, date2);
222*0e209d39SAndroid Build Coastguard Worker     log_verbose("%s\n", austrdup(then) );
223*0e209d39SAndroid Build Coastguard Worker     if (!(date2 == date1)) log_err("FAIL\n");
224*0e209d39SAndroid Build Coastguard Worker 
225*0e209d39SAndroid Build Coastguard Worker     udat_close(format);
226*0e209d39SAndroid Build Coastguard Worker     free(pattern);
227*0e209d39SAndroid Build Coastguard Worker 
228*0e209d39SAndroid Build Coastguard Worker }
229*0e209d39SAndroid Build Coastguard Worker 
230*0e209d39SAndroid Build Coastguard Worker /**
231*0e209d39SAndroid Build Coastguard Worker  * Verify the handling of Czech June and July, which have the unique attribute that
232*0e209d39SAndroid Build Coastguard Worker  * one is a proper prefix substring of the other.
233*0e209d39SAndroid Build Coastguard Worker  */
TestCzechMonths459(void)234*0e209d39SAndroid Build Coastguard Worker void TestCzechMonths459(void)
235*0e209d39SAndroid Build Coastguard Worker {
236*0e209d39SAndroid Build Coastguard Worker     int32_t lneed, pos;
237*0e209d39SAndroid Build Coastguard Worker     UChar *pattern=NULL, *tzID=NULL;
238*0e209d39SAndroid Build Coastguard Worker     UChar *juneStr, *julyStr;
239*0e209d39SAndroid Build Coastguard Worker     UDateFormat *fmt;
240*0e209d39SAndroid Build Coastguard Worker     UCalendar *cal;
241*0e209d39SAndroid Build Coastguard Worker     UDate june, july, d;
242*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
243*0e209d39SAndroid Build Coastguard Worker     UChar *date;
244*0e209d39SAndroid Build Coastguard Worker 
245*0e209d39SAndroid Build Coastguard Worker     ctest_setTimeZone(NULL, &status);
246*0e209d39SAndroid Build Coastguard Worker     fmt = udat_open(UDAT_FULL, UDAT_FULL, "cs", NULL, 0, NULL, 0, &status);
247*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)){
248*0e209d39SAndroid Build Coastguard Worker         log_data_err("Error in constructing the date format -> %s (Are you missing data?)\n", u_errorName(status));
249*0e209d39SAndroid Build Coastguard Worker         ctest_resetTimeZone();
250*0e209d39SAndroid Build Coastguard Worker         return;
251*0e209d39SAndroid Build Coastguard Worker     }
252*0e209d39SAndroid Build Coastguard Worker     lneed=0;
253*0e209d39SAndroid Build Coastguard Worker     lneed=udat_toPattern(fmt, true, NULL, lneed, &status);
254*0e209d39SAndroid Build Coastguard Worker     if(status==U_BUFFER_OVERFLOW_ERROR){
255*0e209d39SAndroid Build Coastguard Worker         status=U_ZERO_ERROR;
256*0e209d39SAndroid Build Coastguard Worker         pattern=(UChar*)malloc(sizeof(UChar) * (lneed+1) );
257*0e209d39SAndroid Build Coastguard Worker         udat_toPattern(fmt, true, pattern, lneed+1, &status);
258*0e209d39SAndroid Build Coastguard Worker     }
259*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)){ log_err("Error in extracting the pattern\n"); }
260*0e209d39SAndroid Build Coastguard Worker     tzID=(UChar*)malloc(sizeof(UChar) * 4);
261*0e209d39SAndroid Build Coastguard Worker     u_uastrcpy(tzID, "GMT");
262*0e209d39SAndroid Build Coastguard Worker     cal=ucal_open(tzID, u_strlen(tzID), "cs", UCAL_GREGORIAN, &status);
263*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)){ log_err("error in ucal_open caldef : %s\n", myErrorName(status));    }
264*0e209d39SAndroid Build Coastguard Worker 
265*0e209d39SAndroid Build Coastguard Worker     ucal_setDate(cal, 1997, UCAL_JUNE, 15, &status);
266*0e209d39SAndroid Build Coastguard Worker     june=ucal_getMillis(cal, &status);
267*0e209d39SAndroid Build Coastguard Worker     ucal_setDate(cal, 1997, UCAL_JULY, 15, &status);
268*0e209d39SAndroid Build Coastguard Worker     july=ucal_getMillis(cal, &status);
269*0e209d39SAndroid Build Coastguard Worker 
270*0e209d39SAndroid Build Coastguard Worker     juneStr = myDateFormat(fmt, june);
271*0e209d39SAndroid Build Coastguard Worker     julyStr = myDateFormat(fmt, july);
272*0e209d39SAndroid Build Coastguard Worker     pos=0;
273*0e209d39SAndroid Build Coastguard Worker     if(juneStr == NULL) {
274*0e209d39SAndroid Build Coastguard Worker       log_data_err("Can't load juneStr. Quitting.\n");
275*0e209d39SAndroid Build Coastguard Worker       return;
276*0e209d39SAndroid Build Coastguard Worker     }
277*0e209d39SAndroid Build Coastguard Worker     d = udat_parse(fmt, juneStr, u_strlen(juneStr), &pos, &status);
278*0e209d39SAndroid Build Coastguard Worker     date = myDateFormat(fmt, d);
279*0e209d39SAndroid Build Coastguard Worker 
280*0e209d39SAndroid Build Coastguard Worker     if(U_SUCCESS(status)){
281*0e209d39SAndroid Build Coastguard Worker         UChar* out1 = myDateFormat(fmt, june);
282*0e209d39SAndroid Build Coastguard Worker         UChar* out2 = myDateFormat(fmt, d);
283*0e209d39SAndroid Build Coastguard Worker         if(u_strcmp(out1, out2) !=0)
284*0e209d39SAndroid Build Coastguard Worker             log_err("Error in handling the czech month june\n");
285*0e209d39SAndroid Build Coastguard Worker         else
286*0e209d39SAndroid Build Coastguard Worker             log_verbose("Pass: Date = %s (czech month June)\n", aescstrdup(date, -1));
287*0e209d39SAndroid Build Coastguard Worker     }else{
288*0e209d39SAndroid Build Coastguard Worker         log_err("udat_parse failed. Error. %s\n",u_errorName(status));
289*0e209d39SAndroid Build Coastguard Worker     }
290*0e209d39SAndroid Build Coastguard Worker     pos=0;
291*0e209d39SAndroid Build Coastguard Worker     d = udat_parse(fmt, julyStr, u_strlen(julyStr), &pos, &status);
292*0e209d39SAndroid Build Coastguard Worker     date = myDateFormat(fmt, d);
293*0e209d39SAndroid Build Coastguard Worker     if(u_strcmp(myDateFormat(fmt, july), myDateFormat(fmt, d) ) !=0)
294*0e209d39SAndroid Build Coastguard Worker         log_err("Error in handling the czech month july\n");
295*0e209d39SAndroid Build Coastguard Worker     else
296*0e209d39SAndroid Build Coastguard Worker         log_verbose("Pass: Date = %s (czech month July)\n", aescstrdup(date, -1));
297*0e209d39SAndroid Build Coastguard Worker 
298*0e209d39SAndroid Build Coastguard Worker     ctest_resetTimeZone();
299*0e209d39SAndroid Build Coastguard Worker     udat_close(fmt);
300*0e209d39SAndroid Build Coastguard Worker     ucal_close(cal);
301*0e209d39SAndroid Build Coastguard Worker     free(pattern);
302*0e209d39SAndroid Build Coastguard Worker     free(tzID);
303*0e209d39SAndroid Build Coastguard Worker }
304*0e209d39SAndroid Build Coastguard Worker 
305*0e209d39SAndroid Build Coastguard Worker /**
306*0e209d39SAndroid Build Coastguard Worker  * Test the handling of single quotes in patterns.
307*0e209d39SAndroid Build Coastguard Worker  */
TestQuotePattern161(void)308*0e209d39SAndroid Build Coastguard Worker void TestQuotePattern161(void)
309*0e209d39SAndroid Build Coastguard Worker {
310*0e209d39SAndroid Build Coastguard Worker     UDateFormat *format = NULL;
311*0e209d39SAndroid Build Coastguard Worker     UCalendar *cal = NULL;
312*0e209d39SAndroid Build Coastguard Worker     UDate currentTime_1;
313*0e209d39SAndroid Build Coastguard Worker     UChar *pattern = NULL;
314*0e209d39SAndroid Build Coastguard Worker     UChar *tzID = NULL;
315*0e209d39SAndroid Build Coastguard Worker     UChar *exp = NULL;
316*0e209d39SAndroid Build Coastguard Worker     UChar *dateString;
317*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
318*0e209d39SAndroid Build Coastguard Worker     const char* expStr = "04/13/1999 at 10:42:28 AM ";
319*0e209d39SAndroid Build Coastguard Worker 
320*0e209d39SAndroid Build Coastguard Worker     ctest_setTimeZone(NULL, &status);
321*0e209d39SAndroid Build Coastguard Worker 
322*0e209d39SAndroid Build Coastguard Worker     pattern=(UChar*)malloc(sizeof(UChar) * (strlen("MM/dd/yyyy 'at' hh:mm:ss a zzz")+1) );
323*0e209d39SAndroid Build Coastguard Worker     u_uastrcpy(pattern, "MM/dd/yyyy 'at' hh:mm:ss a zzz");
324*0e209d39SAndroid Build Coastguard Worker 
325*0e209d39SAndroid Build Coastguard Worker     /* this is supposed to open default date format, but later on it treats it like it is "en_US"
326*0e209d39SAndroid Build Coastguard Worker        - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
327*0e209d39SAndroid Build Coastguard Worker     /* format= udat_openPattern(pattern, u_strlen(pattern), NULL, &status); */
328*0e209d39SAndroid Build Coastguard Worker     format= udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US", NULL, 0,pattern, u_strlen(pattern), &status);
329*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)){
330*0e209d39SAndroid Build Coastguard Worker         log_data_err("error in udat_open: %s - (Are you missing data?)\n", myErrorName(status));
331*0e209d39SAndroid Build Coastguard Worker     } else {
332*0e209d39SAndroid Build Coastguard Worker         tzID=(UChar*)malloc(sizeof(UChar) * 4);
333*0e209d39SAndroid Build Coastguard Worker         u_uastrcpy(tzID, "PST");
334*0e209d39SAndroid Build Coastguard Worker         /* this is supposed to open default date format, but later on it treats it like it is "en_US"
335*0e209d39SAndroid Build Coastguard Worker            - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
336*0e209d39SAndroid Build Coastguard Worker         /* cal=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status); */
337*0e209d39SAndroid Build Coastguard Worker         cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
338*0e209d39SAndroid Build Coastguard Worker         if(U_FAILURE(status)){ log_err("error in ucal_open cal : %s\n", myErrorName(status));    }
339*0e209d39SAndroid Build Coastguard Worker 
340*0e209d39SAndroid Build Coastguard Worker         ucal_setDateTime(cal, 1999, UCAL_APRIL, 13, 10, 42, 28, &status);
341*0e209d39SAndroid Build Coastguard Worker         currentTime_1 = ucal_getMillis(cal, &status);
342*0e209d39SAndroid Build Coastguard Worker 
343*0e209d39SAndroid Build Coastguard Worker         dateString = myDateFormat(format, currentTime_1);
344*0e209d39SAndroid Build Coastguard Worker         exp=(UChar*)malloc(sizeof(UChar) * (strlen(expStr) + 1) );
345*0e209d39SAndroid Build Coastguard Worker         u_uastrcpy(exp, expStr);
346*0e209d39SAndroid Build Coastguard Worker 
347*0e209d39SAndroid Build Coastguard Worker         log_verbose("%s\n", austrdup(dateString) );
348*0e209d39SAndroid Build Coastguard Worker         if(u_strncmp(dateString, exp, (int32_t)strlen(expStr)) !=0) {
349*0e209d39SAndroid Build Coastguard Worker             log_err("Error in formatting a pattern with single quotes\n");
350*0e209d39SAndroid Build Coastguard Worker         }
351*0e209d39SAndroid Build Coastguard Worker     }
352*0e209d39SAndroid Build Coastguard Worker     udat_close(format);
353*0e209d39SAndroid Build Coastguard Worker     ucal_close(cal);
354*0e209d39SAndroid Build Coastguard Worker     free(exp);
355*0e209d39SAndroid Build Coastguard Worker     free(tzID);
356*0e209d39SAndroid Build Coastguard Worker     free(pattern);
357*0e209d39SAndroid Build Coastguard Worker 
358*0e209d39SAndroid Build Coastguard Worker     ctest_resetTimeZone();
359*0e209d39SAndroid Build Coastguard Worker }
360*0e209d39SAndroid Build Coastguard Worker 
361*0e209d39SAndroid Build Coastguard Worker /*
362*0e209d39SAndroid Build Coastguard Worker  * Testing udat_getBooleanAttribute and  unum_setBooleanAttribute() to make sure basic C wrapper functionality is present
363*0e209d39SAndroid Build Coastguard Worker  */
TestBooleanAttributes(void)364*0e209d39SAndroid Build Coastguard Worker void TestBooleanAttributes(void)
365*0e209d39SAndroid Build Coastguard Worker {
366*0e209d39SAndroid Build Coastguard Worker     UDateFormat *en;
367*0e209d39SAndroid Build Coastguard Worker     UErrorCode status=U_ZERO_ERROR;
368*0e209d39SAndroid Build Coastguard Worker     UBool initialState = true;
369*0e209d39SAndroid Build Coastguard Worker     UBool switchedState = false;
370*0e209d39SAndroid Build Coastguard Worker 
371*0e209d39SAndroid Build Coastguard Worker     log_verbose("\ncreating a date format with english locale\n");
372*0e209d39SAndroid Build Coastguard Worker     en = udat_open(UDAT_FULL, UDAT_DEFAULT, "en_US", NULL, 0, NULL, 0, &status);
373*0e209d39SAndroid Build Coastguard Worker     if(U_FAILURE(status)) {
374*0e209d39SAndroid Build Coastguard Worker         log_data_err("error in creating the dateformat -> %s (Are you missing data?)\n",
375*0e209d39SAndroid Build Coastguard Worker             myErrorName(status) );
376*0e209d39SAndroid Build Coastguard Worker         return;
377*0e209d39SAndroid Build Coastguard Worker     }
378*0e209d39SAndroid Build Coastguard Worker 
379*0e209d39SAndroid Build Coastguard Worker 
380*0e209d39SAndroid Build Coastguard Worker     initialState = udat_getBooleanAttribute(en, UDAT_PARSE_ALLOW_NUMERIC, &status);
381*0e209d39SAndroid Build Coastguard Worker     if(initialState != true) switchedState = true;  // if it wasn't the default of true, then flip what we expect
382*0e209d39SAndroid Build Coastguard Worker 
383*0e209d39SAndroid Build Coastguard Worker     udat_setBooleanAttribute(en, UDAT_PARSE_ALLOW_NUMERIC, switchedState, &status);
384*0e209d39SAndroid Build Coastguard Worker     if(switchedState != udat_getBooleanAttribute(en, UDAT_PARSE_ALLOW_NUMERIC, &status)) {
385*0e209d39SAndroid Build Coastguard Worker         log_err("unable to switch states!");
386*0e209d39SAndroid Build Coastguard Worker         return;
387*0e209d39SAndroid Build Coastguard Worker     }
388*0e209d39SAndroid Build Coastguard Worker 
389*0e209d39SAndroid Build Coastguard Worker     udat_close(en);
390*0e209d39SAndroid Build Coastguard Worker }
391*0e209d39SAndroid Build Coastguard Worker 
392*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */
393