| OLD | NEW |
| (Empty) |
| 1 /******************************************************************** | |
| 2 * COPYRIGHT: | |
| 3 * Copyright (c) 1997-2014, International Business Machines Corporation and | |
| 4 * others. All Rights Reserved. | |
| 5 ********************************************************************/ | |
| 6 /*******************************************************************************
* | |
| 7 * | |
| 8 * File CDTRGTST.C | |
| 9 * | |
| 10 * Madhu Katragadda Ported for C API | |
| 11 * Modification History: | |
| 12 * Date Name Description | |
| 13 * 07/15/99 helena Ported to HPUX 10/11 CC. | |
| 14 ********************************************************************************
* | |
| 15 */ | |
| 16 /* REGRESSION TEST FOR DATE FORMAT */ | |
| 17 | |
| 18 #include "unicode/utypes.h" | |
| 19 | |
| 20 #if !UCONFIG_NO_FORMATTING | |
| 21 | |
| 22 #include "unicode/uloc.h" | |
| 23 #include "unicode/udat.h" | |
| 24 #include "unicode/ucal.h" | |
| 25 #include "unicode/unum.h" | |
| 26 #include "unicode/ustring.h" | |
| 27 #include "cintltst.h" | |
| 28 #include "cdtrgtst.h" | |
| 29 #include "cmemory.h" | |
| 30 | |
| 31 void addDateForRgrTest(TestNode** root); | |
| 32 | |
| 33 void addDateForRgrTest(TestNode** root) | |
| 34 { | |
| 35 addTest(root, &Test4029195, "tsformat/cdtrgtst/Test4029195"); | |
| 36 addTest(root, &Test4056591, "tsformat/cdtrgtst/Test4056591"); | |
| 37 addTest(root, &Test4059917, "tsformat/cdtrgtst/Test4059917"); | |
| 38 addTest(root, &Test4060212, "tsformat/cdtrgtst/Test4060212"); | |
| 39 addTest(root, &Test4061287, "tsformat/cdtrgtst/Test4061287"); | |
| 40 addTest(root, &Test4073003, "tsformat/cdtrgtst/Test4073003"); | |
| 41 addTest(root, &Test4162071, "tsformat/cdtrgtst/Test4162071"); | |
| 42 addTest(root, &Test714, "tsformat/cdtrgtst/Test714"); | |
| 43 addTest(root, &Test_GEec, "tsformat/cdtrgtst/Test_GEec"); /* tests for for
mat chars GEec, jitterbugs 5726 6072 6585 */ | |
| 44 } | |
| 45 | |
| 46 /** | |
| 47 * @bug 4029195 | |
| 48 */ | |
| 49 void Test4029195() | |
| 50 { | |
| 51 int32_t resultlength, resultlengthneeded; | |
| 52 UChar *fmdt, *todayS, *rt; | |
| 53 UChar *pat=NULL; | |
| 54 UChar *temp; | |
| 55 UDate today, d1; | |
| 56 UDateFormat *df; | |
| 57 int32_t parsepos; | |
| 58 UErrorCode status = U_ZERO_ERROR; | |
| 59 | |
| 60 log_verbose("Testing date format and parse function in regression test\n"); | |
| 61 today = ucal_getNow(); | |
| 62 | |
| 63 df = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US", NULL, 0, NULL, 0, &status
); | |
| 64 if(U_FAILURE(status)) | |
| 65 { | |
| 66 log_data_err("FAIL: error in creating the dateformat using default date
and time style : %s (Are you missing data?)\n", myErrorName(status)); | |
| 67 return; | |
| 68 } | |
| 69 resultlength=0; | |
| 70 resultlengthneeded=udat_toPattern(df, TRUE, NULL, resultlength, &status); | |
| 71 if(status==U_BUFFER_OVERFLOW_ERROR) | |
| 72 { | |
| 73 status=U_ZERO_ERROR; | |
| 74 resultlength=resultlengthneeded + 1; | |
| 75 pat=(UChar*)malloc(sizeof(UChar) * resultlength); | |
| 76 udat_toPattern(df, TRUE, pat, resultlength, &status); | |
| 77 } | |
| 78 | |
| 79 log_verbose("pattern: %s\n", austrdup(pat)); | |
| 80 | |
| 81 | |
| 82 fmdt = myFormatit(df, today); | |
| 83 if(fmdt) { | |
| 84 log_verbose("today: %s\n", austrdup(fmdt)); | |
| 85 } else { | |
| 86 log_data_err("ERROR: couldn't format, exitting test"); | |
| 87 return; | |
| 88 } | |
| 89 | |
| 90 temp=(UChar*)malloc(sizeof(UChar) * 10); | |
| 91 u_uastrcpy(temp, "M yyyy dd"); | |
| 92 udat_applyPattern(df, TRUE, temp, u_strlen(temp)); | |
| 93 | |
| 94 todayS =myFormatit(df, today); | |
| 95 log_verbose("After the pattern is applied\n today: %s\n", austrdup(todayS) )
; | |
| 96 parsepos=0; | |
| 97 d1=udat_parse(df, todayS, u_strlen(todayS), &parsepos, &status); | |
| 98 if(U_FAILURE(status)) | |
| 99 { | |
| 100 log_err("FAIL: Error in parsing using udat_parse(.....): %s\n", myErrorN
ame(status)); | |
| 101 } | |
| 102 | |
| 103 rt =myFormatit(df, d1); | |
| 104 log_verbose("today: %s\n", austrdup(rt) ); | |
| 105 | |
| 106 log_verbose("round trip: %s\n", austrdup(rt) ); | |
| 107 | |
| 108 if(u_strcmp(rt, todayS)!=0) { | |
| 109 log_err("Fail: Want %s Got %s\n", austrdup(todayS), austrdup(rt) ); | |
| 110 } | |
| 111 else | |
| 112 log_verbose("Pass: parse and format working fine\n"); | |
| 113 udat_close(df); | |
| 114 free(temp); | |
| 115 if(pat != NULL) { | |
| 116 free(pat); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 | |
| 121 /** | |
| 122 * @bug 4056591 | |
| 123 * Verify the function of the [s|g]et2DigitYearStart() API. | |
| 124 */ | |
| 125 void Test4056591() | |
| 126 { | |
| 127 int i; | |
| 128 UCalendar *cal; | |
| 129 UDateFormat *def; | |
| 130 UDate start,exp,got; | |
| 131 UChar s[10]; | |
| 132 UChar *gotdate, *expdate; | |
| 133 UChar pat[10]; | |
| 134 UDate d[4]; | |
| 135 UErrorCode status = U_ZERO_ERROR; | |
| 136 const char* strings[] = { | |
| 137 "091225", | |
| 138 "091224", | |
| 139 "611226", | |
| 140 "991227" | |
| 141 }; | |
| 142 | |
| 143 log_verbose("Testing s[get] 2 digit year start regressively\n"); | |
| 144 cal=ucal_open(NULL, 0, "en_US", UCAL_GREGORIAN, &status); | |
| 145 if(U_FAILURE(status)){ | |
| 146 log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n
", myErrorName(status)); | |
| 147 return; | |
| 148 } | |
| 149 ucal_setDateTime(cal, 1809, UCAL_DECEMBER, 25, 17, 40, 30, &status); | |
| 150 d[0]=ucal_getMillis(cal, &status); | |
| 151 if(U_FAILURE(status)){ | |
| 152 log_err("Error: failure in get millis: %s\n", myErrorName(status)); | |
| 153 } | |
| 154 ucal_setDateTime(cal, 1909, UCAL_DECEMBER, 24, 17, 40, 30, &status); | |
| 155 d[1]=ucal_getMillis(cal, &status); | |
| 156 ucal_setDateTime(cal, 1861, UCAL_DECEMBER, 26, 17, 40, 30, &status); | |
| 157 d[2]=ucal_getMillis(cal, &status); | |
| 158 ucal_setDateTime(cal, 1999, UCAL_DECEMBER, 27, 17, 40, 30, &status); | |
| 159 d[3]=ucal_getMillis(cal, &status); | |
| 160 | |
| 161 | |
| 162 u_uastrcpy(pat, "yyMMdd"); | |
| 163 def = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL, NULL, 0, pat, u_strlen(pat),
&status); | |
| 164 if(U_FAILURE(status)) | |
| 165 { | |
| 166 log_data_err("FAIL: error in creating the dateformat using u_openPattern
(): %s - (Are you missing data?)\n", myErrorName(status)); | |
| 167 return; | |
| 168 } | |
| 169 start = 1800; | |
| 170 udat_set2DigitYearStart(def, start, &status); | |
| 171 if(U_FAILURE(status)) | |
| 172 log_err("ERROR: in setTwoDigitStartDate: %s\n", myErrorName(status)); | |
| 173 if( (udat_get2DigitYearStart(def, &status) != start)) | |
| 174 log_err("ERROR: get2DigitYearStart broken\n"); | |
| 175 | |
| 176 | |
| 177 for(i = 0; i < 4; ++i) { | |
| 178 u_uastrcpy(s, strings[i]); | |
| 179 exp = d[i]; | |
| 180 got = udat_parse(def, s, u_strlen(s), 0, &status); | |
| 181 gotdate=myFormatit(def, got); | |
| 182 expdate=myFormatit(def, exp); | |
| 183 | |
| 184 if (gotdate == NULL || expdate == NULL) { | |
| 185 log_err("myFormatit failed!\n"); | |
| 186 } | |
| 187 else if(u_strcmp(gotdate, expdate) !=0){ | |
| 188 log_err("set2DigitYearStart broken for %s \n got: %s, expected: %s\
n", austrdup(s), | |
| 189 austrdup(gotdate), austrdup(expdate) ); | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 udat_close(def); | |
| 194 ucal_close(cal); | |
| 195 } | |
| 196 | |
| 197 | |
| 198 /** | |
| 199 * SimpleDateFormat does not properly parse date strings without delimiters | |
| 200 * @bug 4059917 | |
| 201 */ | |
| 202 void Test4059917() | |
| 203 { | |
| 204 UDateFormat* def; | |
| 205 UChar *myDate; | |
| 206 UErrorCode status = U_ZERO_ERROR; | |
| 207 UChar pattern[11]; | |
| 208 UChar tzID[4]; | |
| 209 | |
| 210 log_verbose("Testing apply pattern and to pattern regressively\n"); | |
| 211 u_uastrcpy(tzID, "PST"); | |
| 212 u_uastrcpy(pattern, "yyyy/MM/dd"); | |
| 213 log_verbose("%s\n", austrdup(pattern) ); | |
| 214 def = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,tzID,-1,pattern, u_strlen(pat
tern),&status); | |
| 215 if(U_FAILURE(status)) | |
| 216 { | |
| 217 log_data_err("FAIL: error in creating the dateformat using openPattern:
%s - (Are you missing data?)\n", myErrorName(status)); | |
| 218 return; | |
| 219 } | |
| 220 myDate=(UChar*)malloc(sizeof(UChar) * 11); | |
| 221 u_uastrcpy(myDate, "1970/01/12"); | |
| 222 | |
| 223 aux917( def, myDate ); | |
| 224 udat_close(def); | |
| 225 | |
| 226 u_uastrcpy(pattern, "yyyyMMdd"); | |
| 227 def = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,tzID,-1,pattern, u_strlen(pat
tern),&status); | |
| 228 if(U_FAILURE(status)) | |
| 229 { | |
| 230 log_err("FAIL: error in creating the dateformat using openPattern: %s\n"
, myErrorName(status)); | |
| 231 return; | |
| 232 } | |
| 233 u_uastrcpy(myDate, "19700112"); | |
| 234 aux917( def, myDate ); | |
| 235 udat_close(def); | |
| 236 free(myDate); | |
| 237 } | |
| 238 | |
| 239 void aux917( UDateFormat *fmt, UChar* str) | |
| 240 { | |
| 241 int32_t resultlength, resultlengthneeded; | |
| 242 UErrorCode status = U_ZERO_ERROR; | |
| 243 UChar* formatted=NULL; | |
| 244 UChar *pat=NULL; | |
| 245 UDate d1=1000000000.0; | |
| 246 | |
| 247 resultlength=0; | |
| 248 resultlengthneeded=udat_toPattern(fmt, TRUE, NULL, resultlength, &status); | |
| 249 if(status==U_BUFFER_OVERFLOW_ERROR) | |
| 250 { | |
| 251 status=U_ZERO_ERROR; | |
| 252 resultlength=resultlengthneeded + 1; | |
| 253 pat=(UChar*)malloc(sizeof(UChar) * (resultlength)); | |
| 254 udat_toPattern(fmt, TRUE, pat, resultlength, &status); | |
| 255 } | |
| 256 if(U_FAILURE(status)){ | |
| 257 log_err("failure in retrieving the pattern: %s\n", myErrorName(status)); | |
| 258 } | |
| 259 log_verbose("pattern: %s\n", austrdup(pat) ); | |
| 260 | |
| 261 status = U_ZERO_ERROR; | |
| 262 formatted = myFormatit(fmt, d1); | |
| 263 if( u_strcmp(formatted,str)!=0) { | |
| 264 log_err("Fail: Want %s Got: %s\n", austrdup(str), austrdup(formatted) )
; | |
| 265 } | |
| 266 free(pat); | |
| 267 } | |
| 268 | |
| 269 /** | |
| 270 * @bug 4060212 | |
| 271 */ | |
| 272 void Test4060212() | |
| 273 { | |
| 274 int32_t pos; | |
| 275 UCalendar *cal; | |
| 276 UDateFormat *formatter, *fmt; | |
| 277 UErrorCode status = U_ZERO_ERROR; | |
| 278 UDate myDate; | |
| 279 UChar *myString; | |
| 280 UChar dateString[30], pattern[20], tzID[4]; | |
| 281 u_uastrcpy(dateString, "1995-040.05:01:29 -8"); | |
| 282 u_uastrcpy(pattern, "yyyy-DDD.hh:mm:ss z"); | |
| 283 | |
| 284 log_verbose( "dateString= %s Using yyyy-DDD.hh:mm:ss\n", austrdup(dateString
) ); | |
| 285 status = U_ZERO_ERROR; | |
| 286 u_uastrcpy(tzID, "PST"); | |
| 287 | |
| 288 formatter = udat_open(UDAT_PATTERN,UDAT_PATTERN,"en_US",tzID,-1,pattern, u_s
trlen(pattern), &status); | |
| 289 pos=0; | |
| 290 myDate = udat_parse(formatter, dateString, u_strlen(dateString), &pos, &stat
us); | |
| 291 | |
| 292 | |
| 293 fmt = udat_open(UDAT_FULL,UDAT_LONG ,NULL, tzID, -1, NULL, 0, &status); | |
| 294 if(U_FAILURE(status)) | |
| 295 { | |
| 296 log_data_err("FAIL: error in creating the dateformat using default date
and time style: %s - (Are you missing data?)\n", | |
| 297 myErrorName(status) ); | |
| 298 return; | |
| 299 } | |
| 300 myString = myFormatit(fmt, myDate); | |
| 301 (void)myString; /* Suppress set but not used warning. */ | |
| 302 cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status); | |
| 303 if(U_FAILURE(status)){ | |
| 304 log_err("FAIL: error in ucal_open caldef : %s\n", myErrorName(status)); | |
| 305 } | |
| 306 ucal_setMillis(cal, myDate, &status); | |
| 307 if ((ucal_get(cal, UCAL_DAY_OF_YEAR, &status) != 40)){ | |
| 308 log_err("Fail: Got %d Expected 40\n", ucal_get(cal, UCAL_DAY_OF_YEAR, &
status)); | |
| 309 } | |
| 310 | |
| 311 udat_close(formatter); | |
| 312 ucal_close(cal); | |
| 313 udat_close(fmt); | |
| 314 | |
| 315 } | |
| 316 | |
| 317 /** | |
| 318 * @bug 4061287 | |
| 319 */ | |
| 320 void Test4061287() | |
| 321 { | |
| 322 UBool ok; | |
| 323 int32_t pos; | |
| 324 UDateFormat *df; | |
| 325 UErrorCode status = U_ZERO_ERROR; | |
| 326 UDate myDate; | |
| 327 UChar pattern[21], dateString[11]; | |
| 328 | |
| 329 u_uastrcpy(dateString, "35/13/1971"); | |
| 330 u_uastrcpy(pattern, "dd/mm/yyyy"); | |
| 331 status = U_ZERO_ERROR; | |
| 332 log_verbose("Testing parsing by changing the attribute lenient\n"); | |
| 333 df = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,NULL,0,pattern, u_strlen(patte
rn),&status); | |
| 334 if(U_FAILURE(status)){ | |
| 335 log_data_err("ERROR: failure in open pattern of test4061287: %s - (Are y
ou missing data?)\n", myErrorName(status)); | |
| 336 return; | |
| 337 } | |
| 338 | |
| 339 pos=0; | |
| 340 | |
| 341 udat_setLenient(df, FALSE); | |
| 342 ok=udat_isLenient(df); | |
| 343 if(ok==TRUE) | |
| 344 log_err("setLenient nor working\n"); | |
| 345 ok = FALSE; | |
| 346 myDate = udat_parse(df, dateString, u_strlen(dateString), &pos, &status); | |
| 347 (void)myDate; /* Suppress set but not used warning. */ | |
| 348 if(U_FAILURE(status)) | |
| 349 ok = TRUE; | |
| 350 if(ok!=TRUE) | |
| 351 log_err("Fail: Lenient not working: does lenient parsing in spite of set
ting Leninent as FALSE "); | |
| 352 | |
| 353 udat_close(df); | |
| 354 | |
| 355 } | |
| 356 | |
| 357 | |
| 358 | |
| 359 /* The java.text.DateFormat.parse(String) method expects for the | |
| 360 US locale a string formatted according to mm/dd/yy and parses it | |
| 361 correctly. | |
| 362 | |
| 363 When given a string mm/dd/yyyy it only parses up to the first | |
| 364 two y's, typically resulting in a date in the year 1919. | |
| 365 | |
| 366 Please extend the parsing method(s) to handle strings with | |
| 367 four-digit year values (probably also applicable to various | |
| 368 other locales. */ | |
| 369 /** | |
| 370 * @bug 4073003 | |
| 371 */ | |
| 372 void Test4073003() | |
| 373 { | |
| 374 int32_t pos,i; | |
| 375 UDate d,dd; | |
| 376 UChar *datestr; | |
| 377 UChar temp[15]; | |
| 378 UErrorCode status = U_ZERO_ERROR; | |
| 379 UDateFormat *fmt; | |
| 380 UChar *result, *result2; | |
| 381 const char* tests [] = { | |
| 382 "12/25/61", | |
| 383 "12/25/1961", | |
| 384 "4/3/1999", | |
| 385 "4/3/99" | |
| 386 }; | |
| 387 | |
| 388 fmt= udat_open(UDAT_SHORT,UDAT_SHORT ,NULL, NULL, 0, NULL, 0, &status); | |
| 389 if(U_FAILURE(status)) | |
| 390 { | |
| 391 log_data_err("FAIL: error in creating the dateformat using short date an
d time style: %s (Are you missing data?)\n", | |
| 392 myErrorName(status)); | |
| 393 return; | |
| 394 } | |
| 395 u_uastrcpy(temp, "m/D/yy"); | |
| 396 udat_applyPattern(fmt, FALSE, temp, u_strlen(temp)); | |
| 397 | |
| 398 for(i= 0; i < 4; i+=2) { | |
| 399 status=U_ZERO_ERROR; | |
| 400 datestr=(UChar*)malloc(sizeof(UChar) * (strlen(tests[i])+1)); | |
| 401 u_uastrcpy(datestr, tests[i]); | |
| 402 | |
| 403 pos=0; | |
| 404 d = udat_parse(fmt, datestr, u_strlen(datestr), &pos, &status); | |
| 405 if(U_FAILURE(status)){ | |
| 406 log_err("ERROR : in test 4073003: %s\n", myErrorName(status)); | |
| 407 } | |
| 408 | |
| 409 free(datestr); | |
| 410 datestr=(UChar*)malloc(sizeof(UChar) * (strlen(tests[i+1])+1)); | |
| 411 u_uastrcpy(datestr, tests[i+1]); | |
| 412 | |
| 413 pos=0; | |
| 414 status=U_ZERO_ERROR; | |
| 415 dd = udat_parse(fmt, datestr, u_strlen(datestr), &pos, &status); | |
| 416 if(U_FAILURE(status)){ | |
| 417 log_err("ERROR : in test 4073003: %s\n", myErrorName(status)); | |
| 418 } | |
| 419 free(datestr); | |
| 420 | |
| 421 result =myFormatit(fmt, d); | |
| 422 result2 =myFormatit(fmt, dd); | |
| 423 if(!result || !result2) { | |
| 424 log_data_err("Fail: could not format - exitting test\n"); | |
| 425 return; | |
| 426 } | |
| 427 if (u_strcmp(result, result2)!=0){ | |
| 428 log_err("Fail: %s != %s\n", austrdup(result), austrdup(result2) ); | |
| 429 } | |
| 430 else{ | |
| 431 log_verbose("Ok: %s == %s\n", austrdup(result), austrdup(result2) ); | |
| 432 } | |
| 433 | |
| 434 } | |
| 435 udat_close(fmt); | |
| 436 } | |
| 437 | |
| 438 /** | |
| 439 * @bug 4162071 | |
| 440 **/ | |
| 441 void Test4162071() | |
| 442 { | |
| 443 int32_t pos; | |
| 444 UDate x; | |
| 445 UErrorCode status = U_ZERO_ERROR; | |
| 446 UDateFormat *df; | |
| 447 UChar datestr[30]; | |
| 448 UChar format[50]; | |
| 449 u_uastrcpy(datestr, "Thu, 30-Jul-1999 11:51:14 GMT"); | |
| 450 u_uastrcpy(format, "EEE', 'dd-MMM-yyyy HH:mm:ss z"); /* RFC 822/1123 */ | |
| 451 status = U_ZERO_ERROR; | |
| 452 /* Can't hardcode the result to assume the default locale is "en_US". */ | |
| 453 df = udat_open(UDAT_PATTERN,UDAT_PATTERN,"en_US",NULL,0,format, u_strlen(for
mat),&status); | |
| 454 if(U_FAILURE(status)){ | |
| 455 log_data_err("ERROR: couldn't create date format: %s\n", myErrorName(sta
tus)); | |
| 456 return; | |
| 457 } | |
| 458 pos=0; | |
| 459 x = udat_parse(df, datestr, u_strlen(datestr), &pos, &status); | |
| 460 (void)x; /* Suppress set but not used warning. */ | |
| 461 if(U_FAILURE(status)){ | |
| 462 log_data_err("ERROR : parse format %s fails : %s\n", austrdup(format),
myErrorName(status)); | |
| 463 } | |
| 464 else{ | |
| 465 log_verbose("Parse format \"%s \" ok.\n", austrdup(format) ); | |
| 466 } | |
| 467 /*log_verbose("date= %s\n", austrdup(myFormatit(df, x)) );*/ | |
| 468 udat_close(df); | |
| 469 } | |
| 470 | |
| 471 void Test714(void) | |
| 472 { | |
| 473 UDate d=978103543000.0; | |
| 474 UChar temp[20]; | |
| 475 UErrorCode status = U_ZERO_ERROR; | |
| 476 UDateFormat *fmt; | |
| 477 UChar *result; | |
| 478 const char* expect = "7:25:43 AM"; | |
| 479 | |
| 480 ctest_setTimeZone(NULL, &status); | |
| 481 | |
| 482 fmt= udat_open(UDAT_MEDIUM,UDAT_NONE ,"en_US_CA", NULL, -1, NULL, 0, &status
); | |
| 483 if(U_FAILURE(status)) | |
| 484 { | |
| 485 log_data_err("FAIL: error in creating the dateformat using medium time s
tyle and NO date style: %s (Are you missing data?)\n", | |
| 486 myErrorName(status)); | |
| 487 return; | |
| 488 } | |
| 489 result =myFormatit(fmt, d); | |
| 490 if(!result) { | |
| 491 log_data_err("Fail: could not format - exitting test\n"); | |
| 492 return; | |
| 493 } | |
| 494 u_uastrcpy(temp, expect); | |
| 495 if (u_strcmp(result, temp)!=0){ | |
| 496 log_err("Fail: %s != %s\n", austrdup(result), expect); | |
| 497 } | |
| 498 else{ | |
| 499 log_verbose("Ok: %s == %s\n", austrdup(result), expect ); | |
| 500 } | |
| 501 | |
| 502 udat_close(fmt); | |
| 503 | |
| 504 ctest_resetTimeZone(); | |
| 505 } | |
| 506 | |
| 507 enum { DATE_TEXT_MAX_CHARS = 64 }; | |
| 508 static const UChar zonePST[] = { 0x50,0x53,0x54,0 }; /* "PST" */ | |
| 509 static const UDate july022008 = 1215000001979.0; /* 02 July 2008 5:00:01.979 AM
PDT (near ICU 4.0 release date :-) */ | |
| 510 static const double dayMillisec = 8.64e+07; | |
| 511 | |
| 512 static const UChar dMyGGGPattern[] = { 0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79
,0x79,0x79,0x79,0x20,0x47,0x47,0x47,0 }; /* "dd MMM yyyy GGG" */ | |
| 513 static const UChar dMyGGGGGPattern[] = { 0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79
,0x79,0x79,0x79,0x20,0x47,0x47,0x47,0x47,0x47,0 }; /* "dd MMM yyyy GGGGG" */ | |
| 514 static const UChar dMyGGGText[] = { 0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32
,0x30,0x30,0x38,0x20,0x41,0x44,0 }; /* "02 Jul 2008 AD" */ | |
| 515 static const UChar dMyGGGGGText[] = { 0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32
,0x30,0x30,0x38,0x20,0x41,0 }; /* "02 Jul 2008 A" */ | |
| 516 static const UChar edMyPattern[] = { 0x65,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D
,0x20,0x79,0x79,0x79,0x79,0 }; /* "e dd MMM yyyy" */ | |
| 517 static const UChar eedMyPattern[] = { 0x65,0x65,0x20,0x64,0x64,0x20,0x4D,0x4D
,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "ee dd MMM yyyy" */ | |
| 518 static const UChar cdMyPattern[] = { 0x63,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D
,0x20,0x79,0x79,0x79,0x79,0 }; /* "c dd MMM yyyy" */ | |
| 519 static const UChar ccdMyPattern[] = { 0x63,0x63,0x20,0x64,0x64,0x20,0x4D,0x4D
,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "cc dd MMM yyyy" */ | |
| 520 static const UChar edMyText[] = { 0x34,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C
,0x20,0x32,0x30,0x30,0x38,0 }; /* "4 02 Jul 2008" */ | |
| 521 static const UChar eedMyText[] = { 0x30,0x34,0x20,0x30,0x32,0x20,0x4A,0x75
,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "04 02 Jul 2008" */ | |
| 522 static const UChar eeedMyPattern[] = { 0x65,0x65,0x65,0x20,0x64,0x64,0x20,0x4D
,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eee dd MMM yyyy" */ | |
| 523 static const UChar EEEdMyPattern[] = { 0x45,0x45,0x45,0x20,0x64,0x64,0x20,0x4D
,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "EEE dd MMM yyyy" */ | |
| 524 static const UChar EEdMyPattern[] = { 0x45,0x45,0x20,0x64,0x64,0x20,0x4D,0x4D
,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "EE dd MMM yyyy" */ | |
| 525 static const UChar eeedMyText[] = { 0x57,0x65,0x64,0x20,0x30,0x32,0x20,0x4A
,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "Wed 02 Jul 2008" */ | |
| 526 static const UChar eeeedMyPattern[] = { 0x65,0x65,0x65,0x65,0x20,0x64,0x64,0x20
,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eeee dd MMM yyyy" */ | |
| 527 static const UChar eeeedMyText[] = { 0x57,0x65,0x64,0x6E,0x65,0x73,0x64,0x61
,0x79,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "Wedne
sday 02 Jul 2008" */ | |
| 528 static const UChar eeeeedMyPattern[] = { 0x65,0x65,0x65,0x65,0x65,0x20,0x64,0x64
,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eeeee dd MMM yyyy" */ | |
| 529 static const UChar eeeeedMyText[] = { 0x57,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C
,0x20,0x32,0x30,0x30,0x38,0 }; /* "W 02 Jul 2008" */ | |
| 530 static const UChar ewYPattern[] = { 0x65,0x20,0x77,0x77,0x20,0x59,0x59,0x59
,0x59,0 }; /* "e ww YYYY" */ | |
| 531 static const UChar cwYPattern[] = { 0x63,0x20,0x77,0x77,0x20,0x59,0x59,0x59
,0x59,0 }; /* "c ww YYYY" */ | |
| 532 static const UChar ewYText[] = { 0x34,0x20,0x32,0x37,0x20,0x32,0x30,0x30
,0x38,0 }; /* "4 27 2008" */ | |
| 533 static const UChar HHmmssPattern[] = { 0x48,0x48,0x3A,0x6D,0x6D,0x3A,0x73,0x73
,0 }; /* "HH:mm:ss" */ | |
| 534 static const UChar HHmmssText[] = { 0x30,0x35,0x3A,0x30,0x30,0x3A,0x30,0x31
,0 }; /* "05:00:01" */ | |
| 535 static const UChar ssSPattern[] = { 0x73,0x73,0x2E,0x53,0 };
/* "ss.S" */ | |
| 536 static const UChar ssSText[] = { 0x30,0x31,0x2E,0x39,0 };
/* "01.9" */ | |
| 537 static const UChar ssSSPattern[] = { 0x73,0x73,0x2E,0x53,0x53,0 };
/* "ss.SS" */ | |
| 538 static const UChar ssSSText[] = { 0x30,0x31,0x2E,0x39,0x37,0 };
/* "01.97" */ | |
| 539 | |
| 540 typedef struct { | |
| 541 const UChar * pattern; | |
| 542 const UChar * text; | |
| 543 const char * label; | |
| 544 } DatePatternAndText; | |
| 545 static const DatePatternAndText datePatternsAndText[] = { | |
| 546 { dMyGGGPattern, dMyGGGText, "dd MMM yyyy GGG" }, | |
| 547 { dMyGGGGGPattern, dMyGGGGGText, "dd MMM yyyy GGGGG" }, | |
| 548 { edMyPattern, edMyText, "e dd MMM yyyy" }, | |
| 549 { eedMyPattern, eedMyText, "ee dd MMM yyyy" }, | |
| 550 { cdMyPattern, edMyText, "c dd MMM yyyy" }, | |
| 551 { ccdMyPattern, edMyText, "cc dd MMM yyyy" }, | |
| 552 { eeedMyPattern, eeedMyText, "eee dd MMM yyyy" }, | |
| 553 { EEEdMyPattern, eeedMyText, "EEE dd MMM yyyy" }, | |
| 554 { EEdMyPattern, eeedMyText, "EE dd MMM yyyy" }, | |
| 555 { eeeedMyPattern, eeeedMyText, "eeee dd MMM yyyy" }, | |
| 556 { eeeeedMyPattern, eeeeedMyText, "eeeee dd MMM yyyy" }, | |
| 557 { ewYPattern, ewYText, "e ww YYYY" }, | |
| 558 { cwYPattern, ewYText, "c ww YYYY" }, | |
| 559 { HHmmssPattern, HHmmssText, "* HH:mm:ss" }, /* '*' at start mean
s don't check value from parse (won't be july022008) */ | |
| 560 { ssSPattern, ssSText, "* ss.S" }, | |
| 561 { ssSSPattern, ssSSText, "* ss.SS" }, | |
| 562 { NULL, NULL, NULL } | |
| 563 }; | |
| 564 void Test_GEec(void) | |
| 565 { | |
| 566 UErrorCode status = U_ZERO_ERROR; | |
| 567 UDateFormat * dtfmt = udat_open(UDAT_LONG, UDAT_LONG, "en", zonePST, -1, NUL
L, 0, &status); | |
| 568 if ( U_SUCCESS(status) ) { | |
| 569 const DatePatternAndText *patTextPtr; | |
| 570 for (patTextPtr = datePatternsAndText; patTextPtr->pattern != NULL; ++pa
tTextPtr) { | |
| 571 UChar dmyGnText[DATE_TEXT_MAX_CHARS]; | |
| 572 char byteText[3*DATE_TEXT_MAX_CHARS]; | |
| 573 int32_t dmyGnTextLen; | |
| 574 UDate dateResult; | |
| 575 | |
| 576 udat_applyPattern(dtfmt, FALSE, patTextPtr->pattern, -1); | |
| 577 dmyGnTextLen = udat_format(dtfmt, july022008, dmyGnText, DATE_TEXT_M
AX_CHARS, NULL, &status); | |
| 578 (void)dmyGnTextLen; /* Suppress set but not used warning. */ | |
| 579 if ( U_FAILURE(status) ) { | |
| 580 log_err("FAIL: udat_format with %s: %s\n", patTextPtr->label, my
ErrorName(status) ); | |
| 581 status = U_ZERO_ERROR; | |
| 582 } else if ( u_strcmp(dmyGnText, patTextPtr->text) != 0 ) { | |
| 583 log_err("FAIL: udat_format with %s: wrong UChar[] result %s\n",
patTextPtr->label, u_austrcpy(byteText,dmyGnText) ); | |
| 584 } | |
| 585 | |
| 586 dateResult = udat_parse(dtfmt, patTextPtr->text, -1, NULL, &status);
/* no time, dateResult != july022008 by some hours */ | |
| 587 if ( U_FAILURE(status) ) { | |
| 588 log_err("FAIL: udat_parse with %s: %s\n", patTextPtr->label, myE
rrorName(status) ); | |
| 589 status = U_ZERO_ERROR; | |
| 590 } else if ( patTextPtr->label[0] != '*' && july022008 - dateResult >
dayMillisec ) { | |
| 591 log_err("FAIL: udat_parse with %s: wrong UDate result\n", patTex
tPtr->label ); | |
| 592 } | |
| 593 } | |
| 594 udat_close(dtfmt); | |
| 595 } else { | |
| 596 log_data_err("FAIL: udat_open fails: %s (Are you missing data?)\n", myEr
rorName(status)); | |
| 597 } | |
| 598 } | |
| 599 | |
| 600 /*INTERNAL FUNCTION USED */ | |
| 601 | |
| 602 UChar* myFormatit(UDateFormat* datdef, UDate d1) | |
| 603 { | |
| 604 UChar *result1=NULL; | |
| 605 int32_t resultlength, resultlengthneeded; | |
| 606 UErrorCode status = U_ZERO_ERROR; | |
| 607 | |
| 608 resultlength=0; | |
| 609 resultlengthneeded=udat_format(datdef, d1, NULL, resultlength, NULL, &status
); | |
| 610 if(status==U_BUFFER_OVERFLOW_ERROR) | |
| 611 { | |
| 612 status=U_ZERO_ERROR; | |
| 613 resultlength=resultlengthneeded+1; | |
| 614 /*result1=(UChar*)malloc(sizeof(UChar) * resultlength);*/ /*this leaks*/ | |
| 615 result1=(UChar*)ctst_malloc(sizeof(UChar) * resultlength); /*this won't*
/ | |
| 616 udat_format(datdef, d1, result1, resultlength, NULL, &status); | |
| 617 } | |
| 618 if(U_FAILURE(status)) | |
| 619 { | |
| 620 log_err("FAIL: Error in formatting using udat_format(.....): %s\n", myEr
rorName(status)); | |
| 621 return 0; | |
| 622 } | |
| 623 | |
| 624 | |
| 625 return result1; | |
| 626 | |
| 627 } | |
| 628 | |
| 629 #endif /* #if !UCONFIG_NO_FORMATTING */ | |
| 630 | |
| 631 /*eof*/ | |
| OLD | NEW |