1 /********************************************************************
3 * Copyright (c) 1997-2009, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Madhu Katragadda Creation
13 *********************************************************************************
16 /* C API TEST FOR DATE FORMAT */
18 #include "unicode/utypes.h"
20 #if !UCONFIG_NO_FORMATTING
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"
34 static void TestExtremeDates(void);
35 static void TestAllLocales(void);
36 static void TestRelativeCrash(void);
38 #define LEN(a) (sizeof(a)/sizeof(a[0]))
40 void addDateForTest(TestNode
** root
);
42 #define TESTCASE(x) addTest(root, &x, "tsformat/cdattst/" #x)
44 void addDateForTest(TestNode
** root
)
46 TESTCASE(TestDateFormat
);
47 TESTCASE(TestRelativeDateFormat
);
48 TESTCASE(TestSymbols
);
49 TESTCASE(TestDateFormatCalendar
);
50 TESTCASE(TestExtremeDates
);
51 TESTCASE(TestAllLocales
);
52 TESTCASE(TestRelativeCrash
);
54 /* Testing the DateFormat API */
55 static void TestDateFormat()
57 UDateFormat
*def
, *fr
, *it
, *de
, *def1
, *fr_pat
;
60 UErrorCode status
= U_ZERO_ERROR
;
63 const UNumberFormat
*numformat1
, *numformat2
;
69 int32_t resultlengthneeded
;
71 UDate d
= 837039928046.0;
72 double num
= -10456.37;
73 /*const char* str="yyyy.MM.dd G 'at' hh:mm:ss z";
74 const char t[]="2/3/76 2:50 AM";*/
75 /*Testing udat_open() to open a dateformat */
77 ctest_setTimeZone(NULL
, &status
);
79 log_verbose("\nTesting udat_open() with various parameters\n");
80 fr
= udat_open(UDAT_FULL
, UDAT_DEFAULT
, "fr_FR", NULL
,0, NULL
, 0,&status
);
83 log_err("FAIL: error in creating the dateformat using full time style with french locale\n %s\n",
84 myErrorName(status
) );
87 /* this is supposed to open default date format, but later on it treats it like it is "en_US"
88 - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
89 /* def = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0, &status); */
90 def
= udat_open(UDAT_SHORT
, UDAT_SHORT
, "en_US", NULL
, 0,NULL
, 0, &status
);
93 log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n",
94 myErrorName(status
) );
97 it
= udat_open(UDAT_DEFAULT
, UDAT_MEDIUM
, "it_IT", NULL
, 0, NULL
, 0,&status
);
100 log_err("FAIL: error in creating the dateformat using medium date style with italian locale\n %s\n",
101 myErrorName(status
) );
104 de
= udat_open(UDAT_LONG
, UDAT_LONG
, "de_DE", NULL
, 0, NULL
, 0,&status
);
105 if(U_FAILURE(status
))
107 log_err("FAIL: error in creating the dateformat using long time and date styles with german locale\n %s\n",
108 myErrorName(status
));
111 /*creating a default dateformat */
112 def1
= udat_open(UDAT_SHORT
, UDAT_SHORT
, NULL
, NULL
, 0,NULL
, 0, &status
);
113 if(U_FAILURE(status
))
115 log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n",
116 myErrorName(status
) );
121 /*Testing udat_getAvailable() and udat_countAvailable()*/
122 log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
123 numlocales
=udat_countAvailable();
124 /* use something sensible w/o hardcoding the count */
126 log_data_err("FAIL: error in countAvailable\n");
127 log_verbose("The number of locales for which date/time formatting patterns are available is %d\n", numlocales
);
129 for(i
=0;i
<numlocales
;i
++) {
130 UErrorCode subStatus
= U_ZERO_ERROR
;
131 log_verbose("Testing open of %s\n", udat_getAvailable(i
));
132 any
= udat_open(UDAT_SHORT
, UDAT_SHORT
, udat_getAvailable(i
), NULL
,0, NULL
, 0, &subStatus
);
133 if(U_FAILURE(subStatus
)) {
134 log_data_err("FAIL: date format %s (getAvailable(%d)) is not instantiable: %s\n", udat_getAvailable(i
), i
, u_errorName(subStatus
));
139 /*Testing udat_clone()*/
140 log_verbose("\nTesting the udat_clone() function of date format\n");
141 copy
=udat_clone(def
, &status
);
142 if(U_FAILURE(status
)){
143 log_err("Error in creating the clone using udat_clone: %s\n", myErrorName(status
) );
146 log_err("Error in udat_clone");*/ /*how should i check for equality???? */
148 /*Testing udat_format()*/
149 log_verbose("\nTesting the udat_format() function of date format\n");
150 u_uastrcpy(temp
, "7/10/96 4:05 PM");
151 /*format using def */
153 resultlengthneeded
=udat_format(def
, d
, NULL
, resultlength
, NULL
, &status
);
154 if(status
==U_BUFFER_OVERFLOW_ERROR
)
157 resultlength
=resultlengthneeded
+1;
162 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
163 udat_format(def
, d
, result
, resultlength
, NULL
, &status
);
165 if(U_FAILURE(status
) || !result
)
167 log_err("FAIL: Error in formatting using udat_format(.....) %s\n", myErrorName(status
) );
171 log_verbose("PASS: formatting successful\n");
172 if(u_strcmp(result
, temp
)==0)
173 log_verbose("PASS: Date Format for US locale successful using udat_format()\n");
175 log_err("FAIL: Date Format for US locale failed using udat_format()\n");
178 u_unescape("10 juil. 1996 16:05:28 \\u00C9tats-Unis (Los Angeles)", temp
, 50);
183 result
=myDateFormat(fr
, d
);
184 if(u_strcmp(result
, temp
)==0)
185 log_verbose("PASS: Date Format for french locale successful using udat_format()\n");
187 log_data_err("FAIL: Date Format for french locale failed using udat_format().\n" );
190 u_uastrcpy(temp
, "10/lug/1996 16.05.28");
197 fmtted
= myDateFormat(it
,d
);
198 u_austrcpy(g
, fmtted
);
200 if(u_strcmp(fmtted
, temp
)==0) {
201 log_verbose("PASS: Date Format for italian locale successful uisng udat_format() - wanted %s, got %s\n", x
, g
);
203 log_data_err("FAIL: Date Format for italian locale failed using udat_format() - wanted %s, got %s\n", x
, g
);
207 /*Testing parsing using udat_parse()*/
208 log_verbose("\nTesting parsing using udat_parse()\n");
209 u_uastrcpy(temp
,"2/3/76 2:50 AM");
213 d1
=udat_parse(def
, temp
, u_strlen(temp
), &parsepos
, &status
);
214 if(U_FAILURE(status
))
216 log_err("FAIL: Error in parsing using udat_parse(.....) %s\n", myErrorName(status
) );
219 log_verbose("PASS: parsing succesful\n");
220 /*format it back and check for equality */
223 if(u_strcmp(myDateFormat(def
, d1
),temp
)!=0)
224 log_err("FAIL: error in parsing\n");
226 /*Testing parsing using udat_parse()*/
227 log_verbose("\nTesting parsing using udat_parse()\n");
228 u_uastrcpy(temp
,"2/Don't parse this part");
231 d1
=udat_parse(def
, temp
, u_strlen(temp
), NULL
, &status
);
232 if(status
!= U_PARSE_ERROR
)
234 log_err("FAIL: udat_parse(\"bad string\") passed when it should have failed\n");
237 log_verbose("PASS: parsing succesful\n");
241 /*Testing udat_openPattern() */
243 log_verbose("\nTesting the udat_openPattern with a specified pattern\n");
244 /*for french locale */
245 fr_pat
=udat_open(UDAT_IGNORE
, UDAT_IGNORE
,"fr_FR",NULL
,0,temp
, u_strlen(temp
), &status
);
246 if(U_FAILURE(status
))
248 log_err("FAIL: Error in creating a date format using udat_openPattern \n %s\n",
249 myErrorName(status
) );
252 log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n");
255 /*Testing applyPattern and toPattern */
256 log_verbose("\nTesting applyPattern and toPattern()\n");
257 udat_applyPattern(def1
, FALSE
, temp
, u_strlen(temp
));
258 log_verbose("Extracting the pattern\n");
261 resultlengthneeded
=udat_toPattern(def1
, FALSE
, NULL
, resultlength
, &status
);
262 if(status
==U_BUFFER_OVERFLOW_ERROR
)
265 resultlength
=resultlengthneeded
+ 1;
266 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
267 udat_toPattern(def1
, FALSE
, result
, resultlength
, &status
);
269 if(U_FAILURE(status
))
271 log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n",
272 myErrorName(status
) );
274 if(u_strcmp(result
, temp
)!=0)
275 log_err("FAIL: Error in extracting the pattern\n");
277 log_verbose("PASS: applyPattern and toPattern work fine\n");
285 /*Testing getter and setter functions*/
286 /*isLenient and setLenient()*/
287 log_verbose("\nTesting the isLenient and setLenient properties\n");
288 udat_setLenient(fr
, udat_isLenient(it
));
289 if(udat_isLenient(fr
) != udat_isLenient(it
))
290 log_err("ERROR: setLenient() failed\n");
292 log_verbose("PASS: setLenient() successful\n");
295 /*Test get2DigitYearStart set2DigitYearStart */
296 log_verbose("\nTesting the get and set 2DigitYearStart properties\n");
297 d1
= udat_get2DigitYearStart(fr_pat
,&status
);
298 if(U_FAILURE(status
)) {
299 log_err("ERROR: udat_get2DigitYearStart failed %s\n", myErrorName(status
) );
301 status
= U_ZERO_ERROR
;
302 udat_set2DigitYearStart(def1
,d1
, &status
);
303 if(U_FAILURE(status
)) {
304 log_err("ERROR: udat_set2DigitYearStart failed %s\n", myErrorName(status
) );
306 if(udat_get2DigitYearStart(fr_pat
, &status
) != udat_get2DigitYearStart(def1
, &status
))
307 log_err("FAIL: error in set2DigitYearStart\n");
309 log_verbose("PASS: set2DigitYearStart successful\n");
310 /*try setting it to another value */
311 udat_set2DigitYearStart(de
, 2000.0, &status
);
312 if(U_FAILURE(status
)){
313 log_verbose("ERROR: udat_set2DigitYearStart failed %s\n", myErrorName(status
) );
315 if(udat_get2DigitYearStart(de
, &status
) != 2000)
316 log_err("FAIL: error in set2DigitYearStart\n");
318 log_verbose("PASS: set2DigitYearStart successful\n");
322 /*Test getNumberFormat() and setNumberFormat() */
323 log_verbose("\nTesting the get and set NumberFormat properties of date format\n");
324 numformat1
=udat_getNumberFormat(fr_pat
);
325 udat_setNumberFormat(def1
, numformat1
);
326 numformat2
=udat_getNumberFormat(def1
);
327 if(u_strcmp(myNumformat(numformat1
, num
), myNumformat(numformat2
, num
)) !=0)
328 log_err("FAIL: error in setNumberFormat or getNumberFormat()\n");
330 log_verbose("PASS:setNumberFormat and getNumberFormat succesful\n");
332 /*try setting the number format to another format */
333 numformat1
=udat_getNumberFormat(def
);
334 udat_setNumberFormat(def1
, numformat1
);
335 numformat2
=udat_getNumberFormat(def1
);
336 if(u_strcmp(myNumformat(numformat1
, num
), myNumformat(numformat2
, num
)) !=0)
337 log_err("FAIL: error in setNumberFormat or getNumberFormat()\n");
339 log_verbose("PASS: setNumberFormat and getNumberFormat succesful\n");
343 /*Test getCalendar and setCalendar*/
344 log_verbose("\nTesting the udat_getCalendar() and udat_setCalendar() properties\n");
345 cal
=udat_getCalendar(fr_pat
);
348 udat_setCalendar(def1
, cal
);
349 if(!ucal_equivalentTo(udat_getCalendar(fr_pat
), udat_getCalendar(def1
)))
350 log_err("FAIL: Error in setting and getting the calendar\n");
352 log_verbose("PASS: getting and setting calendar successful\n");
358 /*Closing the UDateForamt */
367 ctest_resetTimeZone();
371 Test combined relative date formatting (relative date + non-relative time).
372 This is a bit tricky since we can't have static test data for comparison, the
373 relative date formatting is relative to the time the tests are run. We generate
374 the data for comparison dynamically. However, the tests could fail if they are
375 run right at midnight Pacific time and the call to ucal_getNow() is before midnight
376 while the calls to udat_format are after midnight or span midnight.
378 static const UDate dayInterval
= 24.0*60.0*60.0*1000.0;
379 static const UChar trdfZone
[] = { 0x0055, 0x0053, 0x002F, 0x0050, 0x0061, 0x0063, 0x0069, 0x0066, 0x0069, 0x0063, 0 }; /* US/Pacific */
380 static const char trdfLocale
[] = "en_US";
381 static const UChar minutesPatn
[] = { 0x006D, 0x006D, 0 }; /* "mm" */
382 static const UChar monthLongPatn
[] = { 0x004D, 0x004D, 0x004D, 0x004D, 0 }; /* "MMMM" */
383 static const UChar monthMediumPatn
[] = { 0x004D, 0x004D, 0x004D, 0 }; /* "MMM" */
384 static const UChar monthShortPatn
[] = { 0x004D, 0 }; /* "M" */
385 static const UDateFormatStyle dateStylesList
[] = { UDAT_FULL
, UDAT_LONG
, UDAT_MEDIUM
, UDAT_SHORT
, UDAT_NONE
};
386 static const UChar
*monthPatnsList
[] = { monthLongPatn
, monthLongPatn
, monthMediumPatn
, monthShortPatn
, NULL
};
387 static const UChar newTimePatn
[] = { 0x0048, 0x0048, 0x002C, 0x006D, 0x006D, 0 }; /* "HH,mm" */
388 static const UChar minutesStr
[] = { 0x0034, 0x0039, 0 }; /* "49", minutes string to search for in output */
389 enum { kDateOrTimeOutMax
= 96, kDateAndTimeOutMax
= 192 };
391 static void TestRelativeDateFormat()
394 const UDateFormatStyle
* stylePtr
;
395 const UChar
** monthPtnPtr
;
396 UErrorCode status
= U_ZERO_ERROR
;
397 UCalendar
* ucal
= ucal_open(trdfZone
, -1, trdfLocale
, UCAL_GREGORIAN
, &status
);
398 if ( U_SUCCESS(status
) ) {
399 int32_t year
, month
, day
;
400 ucal_setMillis(ucal
, ucal_getNow(), &status
);
401 year
= ucal_get(ucal
, UCAL_YEAR
, &status
);
402 month
= ucal_get(ucal
, UCAL_MONTH
, &status
);
403 day
= ucal_get(ucal
, UCAL_DATE
, &status
);
404 ucal_setDateTime(ucal
, year
, month
, day
, 18, 49, 0, &status
); /* set to today at 18:49:00 */
405 today
= ucal_getMillis(ucal
, &status
);
408 if ( U_FAILURE(status
) || today
== 0.0 ) {
409 log_err("Generate UDate for a specified time today fails, error %s\n", myErrorName(status
) );
412 for (stylePtr
= dateStylesList
, monthPtnPtr
= monthPatnsList
; *stylePtr
!= UDAT_NONE
; ++stylePtr
, ++monthPtnPtr
) {
413 UDateFormat
* fmtRelDateTime
;
414 UDateFormat
* fmtRelDate
;
415 UDateFormat
* fmtTime
;
416 int32_t dayOffset
, limit
;
418 UChar strDateTime
[kDateAndTimeOutMax
];
419 UChar strDate
[kDateOrTimeOutMax
];
420 UChar strTime
[kDateOrTimeOutMax
];
424 fmtRelDateTime
= udat_open(UDAT_SHORT
, *stylePtr
| UDAT_RELATIVE
, trdfLocale
, trdfZone
, -1, NULL
, 0, &status
);
425 if ( U_FAILURE(status
) ) {
426 log_err("udat_open timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
429 fmtRelDate
= udat_open(UDAT_NONE
, *stylePtr
| UDAT_RELATIVE
, trdfLocale
, trdfZone
, -1, NULL
, 0, &status
);
430 if ( U_FAILURE(status
) ) {
431 log_err("udat_open timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
432 udat_close(fmtRelDateTime
);
435 fmtTime
= udat_open(UDAT_SHORT
, UDAT_NONE
, trdfLocale
, trdfZone
, -1, NULL
, 0, &status
);
436 if ( U_FAILURE(status
) ) {
437 log_err("udat_open timeStyle SHORT dateStyle NONE fails, error %s\n", myErrorName(status
) );
438 udat_close(fmtRelDateTime
);
439 udat_close(fmtRelDate
);
443 dtpatLen
= udat_toPatternRelativeDate(fmtRelDateTime
, strDate
, kDateAndTimeOutMax
, &status
);
444 if ( U_FAILURE(status
) ) {
445 log_err("udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
446 status
= U_ZERO_ERROR
;
447 } else if ( u_strstr(strDate
, *monthPtnPtr
) == NULL
|| dtpatLen
!= u_strlen(strDate
) ) {
448 log_err("udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) date pattern incorrect\n", *stylePtr
);
450 dtpatLen
= udat_toPatternRelativeTime(fmtRelDateTime
, strTime
, kDateAndTimeOutMax
, &status
);
451 if ( U_FAILURE(status
) ) {
452 log_err("udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
453 status
= U_ZERO_ERROR
;
454 } else if ( u_strstr(strTime
, minutesPatn
) == NULL
|| dtpatLen
!= u_strlen(strTime
) ) {
455 log_err("udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) time pattern incorrect\n", *stylePtr
);
457 dtpatLen
= udat_toPattern(fmtRelDateTime
, FALSE
, strDateTime
, kDateAndTimeOutMax
, &status
);
458 if ( U_FAILURE(status
) ) {
459 log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
460 status
= U_ZERO_ERROR
;
461 } else if ( u_strstr(strDateTime
, strDate
) == NULL
|| u_strstr(strDateTime
, strTime
) == NULL
|| dtpatLen
!= u_strlen(strDateTime
) ) {
462 log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) dateTime pattern incorrect\n", *stylePtr
);
464 udat_applyPatternRelative(fmtRelDateTime
, strDate
, u_strlen(strDate
), newTimePatn
, u_strlen(newTimePatn
), &status
);
465 if ( U_FAILURE(status
) ) {
466 log_err("udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
467 status
= U_ZERO_ERROR
;
469 udat_toPattern(fmtRelDateTime
, FALSE
, strDateTime
, kDateAndTimeOutMax
, &status
);
470 if ( U_FAILURE(status
) ) {
471 log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
472 status
= U_ZERO_ERROR
;
473 } else if ( u_strstr(strDateTime
, newTimePatn
) == NULL
) {
474 log_err("udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) didn't update time pattern\n", *stylePtr
);
477 udat_applyPatternRelative(fmtRelDateTime
, strDate
, u_strlen(strDate
), strTime
, u_strlen(strTime
), &status
); /* restore original */
479 fp
.field
= UDAT_MINUTE_FIELD
;
480 for (dayOffset
= -2, limit
= 2; dayOffset
<= limit
; ++dayOffset
) {
481 UDate dateToUse
= today
+ (float)dayOffset
*dayInterval
;
483 udat_format(fmtRelDateTime
, dateToUse
, strDateTime
, kDateAndTimeOutMax
, &fp
, &status
);
484 if ( U_FAILURE(status
) ) {
485 log_err("udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
486 status
= U_ZERO_ERROR
;
488 udat_format(fmtRelDate
, dateToUse
, strDate
, kDateOrTimeOutMax
, NULL
, &status
);
489 if ( U_FAILURE(status
) ) {
490 log_err("udat_format timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr
, myErrorName(status
) );
491 status
= U_ZERO_ERROR
;
492 } else if ( u_strstr(strDateTime
, strDate
) == NULL
) {
493 log_err("relative date string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr
);
496 udat_format(fmtTime
, dateToUse
, strTime
, kDateOrTimeOutMax
, NULL
, &status
);
497 if ( U_FAILURE(status
) ) {
498 log_err("udat_format timeStyle SHORT dateStyle NONE fails, error %s\n", myErrorName(status
) );
499 status
= U_ZERO_ERROR
;
500 } else if ( u_strstr(strDateTime
, strTime
) == NULL
) {
501 log_err("time string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr
);
504 strPtr
= u_strstr(strDateTime
, minutesStr
);
505 if ( strPtr
!= NULL
) {
506 int32_t beginIndex
= strPtr
- strDateTime
;
507 if ( fp
.beginIndex
!= beginIndex
) {
508 log_err("UFieldPosition beginIndex %d, expected %d, in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", fp
.beginIndex
, beginIndex
, *stylePtr
);
511 log_err("minutes string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr
);
516 udat_close(fmtRelDateTime
);
517 udat_close(fmtRelDate
);
522 /*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/
523 static void TestSymbols()
525 UDateFormat
*def
, *fr
;
526 UErrorCode status
= U_ZERO_ERROR
;
528 UChar
*result
= NULL
;
529 int32_t resultlength
;
530 int32_t resultlengthout
;
534 /*creating a dateformat with french locale */
535 log_verbose("\ncreating a date format with french locale\n");
536 fr
= udat_open(UDAT_FULL
, UDAT_DEFAULT
, "fr_FR", NULL
, 0, NULL
, 0, &status
);
537 if(U_FAILURE(status
))
539 log_err("error in creating the dateformat using full time style with french locale\n %s\n",
540 myErrorName(status
) );
543 /*creating a default dateformat */
544 log_verbose("\ncreating a date format with default locale\n");
545 /* this is supposed to open default date format, but later on it treats it like it is "en_US"
546 - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
547 /* def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, &status); */
548 def
= udat_open(UDAT_DEFAULT
,UDAT_DEFAULT
,"en_US", NULL
, 0, NULL
, 0, &status
);
549 if(U_FAILURE(status
))
551 log_err("error in creating the dateformat using short date and time style\n %s\n",
552 myErrorName(status
) );
557 /*Testing countSymbols, getSymbols and setSymbols*/
558 log_verbose("\nTesting countSymbols\n");
559 /*since the month names has the last string empty and week names are 1 based 1.e first string in the weeknames array is empty */
560 if(udat_countSymbols(def
, UDAT_ERAS
)!=2 || udat_countSymbols(def
, UDAT_MONTHS
)!=12 ||
561 udat_countSymbols(def
, UDAT_SHORT_MONTHS
)!=12 || udat_countSymbols(def
, UDAT_WEEKDAYS
)!=8 ||
562 udat_countSymbols(def
, UDAT_SHORT_WEEKDAYS
)!=8 || udat_countSymbols(def
, UDAT_AM_PMS
)!=2 ||
563 udat_countSymbols(def
, UDAT_QUARTERS
) != 4 || udat_countSymbols(def
, UDAT_SHORT_QUARTERS
) != 4 ||
564 udat_countSymbols(def
, UDAT_LOCALIZED_CHARS
)!=1)
566 log_err("FAIL: error in udat_countSymbols\n");
569 log_verbose("PASS: udat_countSymbols() successful\n");
571 /*testing getSymbols*/
572 log_verbose("\nTesting getSymbols\n");
573 pattern
=(UChar
*)malloc(sizeof(UChar
) * 10);
574 u_uastrcpy(pattern
, "jeudi");
576 resultlengthout
=udat_getSymbols(fr
, UDAT_WEEKDAYS
, 5 , NULL
, resultlength
, &status
);
577 if(status
==U_BUFFER_OVERFLOW_ERROR
)
580 resultlength
=resultlengthout
+1;
585 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
586 udat_getSymbols(fr
, UDAT_WEEKDAYS
, 5, result
, resultlength
, &status
);
589 if(U_FAILURE(status
))
591 log_err("FAIL: Error in udat_getSymbols().... %s\n", myErrorName(status
) );
594 log_verbose("PASS: getSymbols succesful\n");
596 if(u_strcmp(result
, pattern
)==0)
597 log_verbose("PASS: getSymbols retrieved the right value\n");
599 log_data_err("FAIL: getSymbols retrieved the wrong value\n");
601 /*run series of tests to test getsymbols regressively*/
602 log_verbose("\nTesting getSymbols() regressively\n");
603 VerifygetSymbols(fr
, UDAT_WEEKDAYS
, 1, "dimanche");
604 VerifygetSymbols(def
, UDAT_WEEKDAYS
, 1, "Sunday");
605 VerifygetSymbols(fr
, UDAT_SHORT_WEEKDAYS
, 7, "sam.");
606 VerifygetSymbols(def
, UDAT_SHORT_WEEKDAYS
, 7, "Sat");
607 VerifygetSymbols(def
, UDAT_MONTHS
, 11, "December");
608 VerifygetSymbols(def
, UDAT_MONTHS
, 0, "January");
609 VerifygetSymbols(fr
, UDAT_ERAS
, 0, "av. J.-C.");
610 VerifygetSymbols(def
, UDAT_AM_PMS
, 0, "AM");
611 VerifygetSymbols(def
, UDAT_AM_PMS
, 1, "PM");
612 VerifygetSymbols(fr
, UDAT_SHORT_MONTHS
, 0, "janv.");
613 VerifygetSymbols(def
, UDAT_SHORT_MONTHS
, 11, "Dec");
614 VerifygetSymbols(fr
, UDAT_QUARTERS
, 0, "1er trimestre");
615 VerifygetSymbols(def
, UDAT_QUARTERS
, 3, "4th quarter");
616 VerifygetSymbols(fr
, UDAT_SHORT_QUARTERS
, 1, "T2");
617 VerifygetSymbols(def
, UDAT_SHORT_QUARTERS
, 2, "Q3");
618 VerifygetSymbols(def
,UDAT_LOCALIZED_CHARS
, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqV");
627 log_verbose("\nTesting setSymbols\n");
628 /*applying the pattern so that setSymbolss works */
630 resultlengthout
=udat_toPattern(fr
, FALSE
, NULL
, resultlength
, &status
);
631 if(status
==U_BUFFER_OVERFLOW_ERROR
)
634 resultlength
=resultlengthout
+ 1;
635 pattern
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
636 udat_toPattern(fr
, FALSE
, pattern
, resultlength
, &status
);
638 if(U_FAILURE(status
))
640 log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n",
641 myErrorName(status
) );
644 udat_applyPattern(def
, FALSE
, pattern
, u_strlen(pattern
));
646 resultlengthout
=udat_toPattern(def
, FALSE
, NULL
, resultlength
,&status
);
647 if(status
==U_BUFFER_OVERFLOW_ERROR
)
650 resultlength
=resultlengthout
+ 1;
655 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
656 udat_toPattern(fr
, FALSE
,result
, resultlength
, &status
);
658 if(U_FAILURE(status
))
660 log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n",
661 myErrorName(status
) );
663 if(u_strcmp(result
, pattern
)==0)
664 log_verbose("Pattern applied properly\n");
666 log_err("pattern could not be applied properly\n");
669 /*testing set symbols */
671 resultlengthout
=udat_getSymbols(fr
, UDAT_MONTHS
, 11 , NULL
, resultlength
, &status
);
672 if(status
==U_BUFFER_OVERFLOW_ERROR
){
674 resultlength
=resultlengthout
+1;
679 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
680 udat_getSymbols(fr
, UDAT_MONTHS
, 11, result
, resultlength
, &status
);
683 if(U_FAILURE(status
))
684 log_err("FAIL: error in getSymbols() %s\n", myErrorName(status
) );
685 resultlength
=resultlengthout
+1;
687 udat_setSymbols(def
, UDAT_MONTHS
, 11, result
, resultlength
, &status
);
688 if(U_FAILURE(status
))
690 log_err("FAIL: Error in udat_setSymbols() : %s\n", myErrorName(status
) );
693 log_verbose("PASS: SetSymbols successful\n");
696 resultlengthout
=udat_getSymbols(def
, UDAT_MONTHS
, 11, NULL
, resultlength
, &status
);
697 if(status
==U_BUFFER_OVERFLOW_ERROR
){
699 resultlength
=resultlengthout
+1;
700 value
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
701 udat_getSymbols(def
, UDAT_MONTHS
, 11, value
, resultlength
, &status
);
703 if(U_FAILURE(status
))
704 log_err("FAIL: error in retrieving the value using getSymbols i.e roundtrip\n");
706 if(u_strcmp(result
, value
)!=0)
707 log_data_err("FAIL: Error in settting and getting symbols\n");
709 log_verbose("PASS: setSymbols successful\n");
712 /*run series of tests to test setSymbols regressively*/
713 log_verbose("\nTesting setSymbols regressively\n");
714 VerifysetSymbols(def
, UDAT_ERAS
, 0, "BeforeChrist");
715 VerifysetSymbols(def
, UDAT_ERA_NAMES
, 1, "AnnoDomini");
716 VerifysetSymbols(def
, UDAT_WEEKDAYS
, 1, "Sundayweek");
717 VerifysetSymbols(def
, UDAT_SHORT_WEEKDAYS
, 7, "Satweek");
718 VerifysetSymbols(def
, UDAT_NARROW_WEEKDAYS
, 4, "M");
719 VerifysetSymbols(def
, UDAT_STANDALONE_WEEKDAYS
, 1, "Sonntagweek");
720 VerifysetSymbols(def
, UDAT_STANDALONE_SHORT_WEEKDAYS
, 7, "Sams");
721 VerifysetSymbols(def
, UDAT_STANDALONE_NARROW_WEEKDAYS
, 4, "V");
722 VerifysetSymbols(fr
, UDAT_MONTHS
, 11, "december");
723 VerifysetSymbols(fr
, UDAT_SHORT_MONTHS
, 0, "Jan");
724 VerifysetSymbols(fr
, UDAT_NARROW_MONTHS
, 1, "R");
725 VerifysetSymbols(fr
, UDAT_STANDALONE_MONTHS
, 11, "dezember");
726 VerifysetSymbols(fr
, UDAT_STANDALONE_SHORT_MONTHS
, 7, "Aug");
727 VerifysetSymbols(fr
, UDAT_STANDALONE_NARROW_MONTHS
, 2, "M");
728 VerifysetSymbols(fr
, UDAT_QUARTERS
, 0, "1. Quart");
729 VerifysetSymbols(fr
, UDAT_SHORT_QUARTERS
, 1, "QQ2");
730 VerifysetSymbols(fr
, UDAT_STANDALONE_QUARTERS
, 2, "3rd Quar.");
731 VerifysetSymbols(fr
, UDAT_STANDALONE_SHORT_QUARTERS
, 3, "4QQ");
734 /*run series of tests to test get and setSymbols regressively*/
735 log_verbose("\nTesting get and set symbols regressively\n");
736 VerifygetsetSymbols(fr
, def
, UDAT_WEEKDAYS
, 1);
737 VerifygetsetSymbols(fr
, def
, UDAT_WEEKDAYS
, 7);
738 VerifygetsetSymbols(fr
, def
, UDAT_SHORT_WEEKDAYS
, 1);
739 VerifygetsetSymbols(fr
, def
, UDAT_SHORT_WEEKDAYS
, 7);
740 VerifygetsetSymbols(fr
, def
, UDAT_MONTHS
, 0);
741 VerifygetsetSymbols(fr
, def
, UDAT_SHORT_MONTHS
, 0);
742 VerifygetsetSymbols(fr
, def
, UDAT_ERAS
,1);
743 VerifygetsetSymbols(fr
, def
, UDAT_LOCALIZED_CHARS
, 0);
744 VerifygetsetSymbols(fr
, def
, UDAT_AM_PMS
, 1);
760 * Test DateFormat(Calendar) API
762 static void TestDateFormatCalendar() {
763 UDateFormat
*date
=0, *time
=0, *full
=0;
769 UErrorCode ec
= U_ZERO_ERROR
;
771 ctest_setTimeZone(NULL
, &ec
);
773 /* Create a formatter for date fields. */
774 date
= udat_open(UDAT_NONE
, UDAT_SHORT
, "en_US", NULL
, 0, NULL
, 0, &ec
);
776 log_err("FAIL: udat_open(NONE, SHORT, en_US) failed with %s\n",
781 /* Create a formatter for time fields. */
782 time
= udat_open(UDAT_SHORT
, UDAT_NONE
, "en_US", NULL
, 0, NULL
, 0, &ec
);
784 log_err("FAIL: udat_open(SHORT, NONE, en_US) failed with %s\n",
789 /* Create a full format for output */
790 full
= udat_open(UDAT_FULL
, UDAT_FULL
, "en_US", NULL
, 0, NULL
, 0, &ec
);
792 log_err("FAIL: udat_open(FULL, FULL, en_US) failed with %s\n",
797 /* Create a calendar */
798 cal
= ucal_open(NULL
, 0, "en_US", UCAL_GREGORIAN
, &ec
);
800 log_err("FAIL: ucal_open(en_US) failed with %s\n",
807 u_uastrcpy(buf
, "4/5/2001");
809 udat_parseCalendar(date
, cal
, buf
, -1, &pos
, &ec
);
811 log_err("FAIL: udat_parseCalendar(4/5/2001) failed at %d with %s\n",
812 pos
, u_errorName(ec
));
817 u_uastrcpy(buf
, "5:45 PM");
819 udat_parseCalendar(time
, cal
, buf
, -1, &pos
, &ec
);
821 log_err("FAIL: udat_parseCalendar(17:45) failed at %d with %s\n",
822 pos
, u_errorName(ec
));
827 when
= ucal_getMillis(cal
, &ec
);
829 log_err("FAIL: ucal_getMillis() failed with %s\n", u_errorName(ec
));
832 udat_format(full
, when
, buf
, sizeof(buf
), NULL
, &ec
);
834 log_err("FAIL: udat_format() failed with %s\n", u_errorName(ec
));
837 u_austrcpy(cbuf
, buf
);
838 /* Thursday, April 5, 2001 5:45:00 PM PDT 986517900000 */
839 if (when
== 986517900000.0) {
840 log_verbose("Ok: Parsed result: %s\n", cbuf
);
842 log_err("FAIL: Parsed result: %s, exp 4/5/2001 5:45 PM\n", cbuf
);
851 ctest_resetTimeZone();
854 /*INTERNAL FUNCTIONS USED*/
855 static void VerifygetSymbols(UDateFormat
* datfor
, UDateFormatSymbolType type
, int32_t index
, const char* expected
)
858 UErrorCode status
= U_ZERO_ERROR
;
860 int32_t resultlength
, resultlengthout
;
863 pattern
=(UChar
*)malloc(sizeof(UChar
) * (strlen(expected
)+1));
864 u_uastrcpy(pattern
, expected
);
866 resultlengthout
=udat_getSymbols(datfor
, type
, index
, NULL
, resultlength
, &status
);
867 if(status
==U_BUFFER_OVERFLOW_ERROR
)
870 resultlength
=resultlengthout
+1;
871 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
872 udat_getSymbols(datfor
, type
, index
, result
, resultlength
, &status
);
875 if(U_FAILURE(status
))
877 log_err("FAIL: Error in udat_getSymbols()... %s\n", myErrorName(status
) );
880 if(u_strcmp(result
, pattern
)==0)
881 log_verbose("PASS: getSymbols retrieved the right value\n");
883 log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s Got %s\n", austrdup(pattern
),
890 static void VerifysetSymbols(UDateFormat
* datfor
, UDateFormatSymbolType type
, int32_t index
, const char* expected
)
894 int32_t resultlength
, resultlengthout
;
895 UErrorCode status
= U_ZERO_ERROR
;
897 value
=(UChar
*)malloc(sizeof(UChar
) * (strlen(expected
) + 1));
898 u_uastrcpy(value
, expected
);
899 udat_setSymbols(datfor
, type
, index
, value
, u_strlen(value
), &status
);
900 if(U_FAILURE(status
))
902 log_err("FAIL: Error in udat_setSymbols() %s\n", myErrorName(status
) );
907 resultlengthout
=udat_getSymbols(datfor
, type
, index
, NULL
, resultlength
, &status
);
908 if(status
==U_BUFFER_OVERFLOW_ERROR
){
910 resultlength
=resultlengthout
+1;
911 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
912 udat_getSymbols(datfor
, type
, index
, result
, resultlength
, &status
);
914 if(U_FAILURE(status
)){
915 log_err("FAIL: error in retrieving the value using getSymbols after setting it previously\n %s\n",
916 myErrorName(status
) );
920 if(u_strcmp(result
, value
)!=0){
921 log_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", austrdup(value
),
925 log_verbose("PASS: setSymbols successful\n");
932 static void VerifygetsetSymbols(UDateFormat
* from
, UDateFormat
* to
, UDateFormatSymbolType type
, int32_t index
)
936 int32_t resultlength
, resultlengthout
;
937 UErrorCode status
= U_ZERO_ERROR
;
940 resultlengthout
=udat_getSymbols(from
, type
, index
, NULL
, resultlength
, &status
);
941 if(status
==U_BUFFER_OVERFLOW_ERROR
){
943 resultlength
=resultlengthout
+1;
944 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
945 udat_getSymbols(from
, type
, index
, result
, resultlength
, &status
);
947 if(U_FAILURE(status
)){
948 log_err("FAIL: error in getSymbols() %s\n", myErrorName(status
) );
952 resultlength
=resultlengthout
+1;
953 udat_setSymbols(to
, type
, index
, result
, resultlength
, &status
);
954 if(U_FAILURE(status
))
956 log_err("FAIL: Error in udat_setSymbols() : %s\n", myErrorName(status
) );
961 resultlengthout
=udat_getSymbols(to
, type
, index
, NULL
, resultlength
, &status
);
962 if(status
==U_BUFFER_OVERFLOW_ERROR
){
964 resultlength
=resultlengthout
+1;
965 value
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
966 udat_getSymbols(to
, type
, index
, value
, resultlength
, &status
);
968 if(U_FAILURE(status
)){
969 log_err("FAIL: error in retrieving the value using getSymbols i.e roundtrip\n %s\n",
970 myErrorName(status
) );
974 if(u_strcmp(result
, value
)!=0){
975 log_data_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", austrdup(result
),
979 log_verbose("PASS: setSymbols successful\n");
986 static UChar
* myNumformat(const UNumberFormat
* numfor
, double d
)
989 int32_t resultlength
, resultlengthneeded
;
990 UErrorCode status
= U_ZERO_ERROR
;
993 resultlengthneeded
=unum_formatDouble(numfor
, d
, NULL
, resultlength
, NULL
, &status
);
994 if(status
==U_BUFFER_OVERFLOW_ERROR
)
997 resultlength
=resultlengthneeded
+1;
998 /*result2=(UChar*)malloc(sizeof(UChar) * resultlength);*/ /* this leaks */
999 result2
=(UChar
*)ctst_malloc(sizeof(UChar
) * resultlength
); /*this won't*/
1000 unum_formatDouble(numfor
, d
, result2
, resultlength
, NULL
, &status
);
1002 if(U_FAILURE(status
))
1004 log_err("FAIL: Error in formatting using unum_format(.....) %s\n", myErrorName(status
) );
1012 * The search depth for TestExtremeDates. The total number of
1013 * dates that will be tested is (2^EXTREME_DATES_DEPTH) - 1.
1015 #define EXTREME_DATES_DEPTH 8
1018 * Support for TestExtremeDates (below).
1020 * Test a single date to see whether udat_format handles it properly.
1022 static UBool
_aux1ExtremeDates(UDateFormat
* fmt
, UDate date
,
1023 UChar
* buf
, int32_t buflen
, char* cbuf
,
1025 int32_t len
= udat_format(fmt
, date
, buf
, buflen
, 0, ec
);
1026 if (!assertSuccess("udat_format", ec
)) return FALSE
;
1027 u_austrncpy(cbuf
, buf
, buflen
);
1029 log_err("FAIL: udat_format(%g) => \"%s\"\n", date
, cbuf
);
1031 log_verbose("udat_format(%g) => \"%s\"\n", date
, cbuf
);
1037 * Support for TestExtremeDates (below).
1039 * Recursively test between 'small' and 'large', up to the depth
1040 * limit specified by EXTREME_DATES_DEPTH.
1042 static UBool
_aux2ExtremeDates(UDateFormat
* fmt
, UDate small
, UDate large
,
1043 UChar
* buf
, int32_t buflen
, char* cbuf
,
1046 /* Logarithmic midpoint; see below */
1047 UDate mid
= (UDate
) exp((log(small
) + log(large
)) / 2);
1048 if (count
== EXTREME_DATES_DEPTH
) {
1052 _aux1ExtremeDates(fmt
, mid
, buf
, buflen
, cbuf
, ec
) &&
1053 _aux2ExtremeDates(fmt
, small
, mid
, buf
, buflen
, cbuf
, count
+1, ec
) &&
1054 _aux2ExtremeDates(fmt
, mid
, large
, buf
, buflen
, cbuf
, count
+1, ec
);
1058 * http://www.jtcsv.com/cgibin/icu-bugs?findid=3659
1060 * For certain large dates, udat_format crashes on MacOS. This test
1061 * attempts to reproduce this problem by doing a recursive logarithmic*
1062 * binary search of a predefined interval (from 'small' to 'large').
1064 * The limit of the search is given by EXTREME_DATES_DEPTH, above.
1066 * *The search has to be logarithmic, not linear. A linear search of the
1067 * range 0..10^30, for example, will find 0.5*10^30, then 0.25*10^30 and
1068 * 0.75*10^30, etc. A logarithmic search will find 10^15, then 10^7.5
1071 static void TestExtremeDates() {
1076 const double small
= 1000; /* 1 sec */
1077 const double large
= 1e+30; /* well beyond usable UDate range */
1079 /* There is no need to test larger values from 1e+30 to 1e+300;
1080 the failures occur around 1e+27, and never above 1e+30. */
1083 fmt
= udat_open(UDAT_LONG
, UDAT_LONG
, "en_US",
1085 if (!assertSuccess("udat_open", &ec
)) return;
1087 _aux2ExtremeDates(fmt
, small
, large
, buf
, LEN(buf
), cbuf
, 0, &ec
);
1092 static void TestAllLocales(void) {
1093 int32_t idx
, dateIdx
, timeIdx
, localeCount
;
1094 static const UDateFormatStyle style
[] = {
1095 UDAT_FULL
, UDAT_LONG
, UDAT_MEDIUM
, UDAT_SHORT
1097 localeCount
= uloc_countAvailable();
1098 for (idx
= 0; idx
< localeCount
; idx
++) {
1099 for (dateIdx
= 0; dateIdx
< (int32_t)(sizeof(style
)/sizeof(style
[0])); dateIdx
++) {
1100 for (timeIdx
= 0; timeIdx
< (int32_t)(sizeof(style
)/sizeof(style
[0])); timeIdx
++) {
1101 UErrorCode status
= U_ZERO_ERROR
;
1102 udat_close(udat_open(style
[dateIdx
], style
[timeIdx
],
1103 uloc_getAvailable(idx
), NULL
, 0, NULL
, 0, &status
));
1104 if (U_FAILURE(status
)) {
1105 log_err("FAIL: udat_open(%s) failed with (%s) dateIdx=%d, timeIdx=%d\n",
1106 uloc_getAvailable(idx
), u_errorName(status
), dateIdx
, timeIdx
);
1113 static void TestRelativeCrash(void) {
1114 static const UChar tzName
[] = { 0x0055, 0x0053, 0x002F, 0x0050, 0x0061, 0x0063, 0x0069, 0x0066, 0x0069, 0x0063, 0 };
1115 static const UDate aDate
= -631152000000.0;
1117 UErrorCode status
= U_ZERO_ERROR
;
1118 UErrorCode expectStatus
= U_ILLEGAL_ARGUMENT_ERROR
;
1121 icudf
= udat_open(UDAT_NONE
, UDAT_SHORT_RELATIVE
, "en", tzName
, -1, NULL
, 0, &status
);
1122 if ( U_SUCCESS(status
) ) {
1123 const char *what
= "???";
1125 UErrorCode subStatus
= U_ZERO_ERROR
;
1126 what
= "udat_set2DigitYearStart";
1127 log_verbose("Trying %s on a relative date..\n", what
);
1128 udat_set2DigitYearStart(icudf
, aDate
, &subStatus
);
1129 if(subStatus
== expectStatus
) {
1130 log_verbose("Success: did not crash on %s, but got %s.\n", what
, u_errorName(subStatus
));
1132 log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what
, u_errorName(subStatus
), u_errorName(expectStatus
));
1136 /* clone works polymorphically. try it anyways */
1137 UErrorCode subStatus
= U_ZERO_ERROR
;
1140 log_verbose("Trying %s on a relative date..\n", what
);
1141 oth
= udat_clone(icudf
, &subStatus
);
1142 if(subStatus
== U_ZERO_ERROR
) {
1143 log_verbose("Success: did not crash on %s, but got %s.\n", what
, u_errorName(subStatus
));
1144 udat_close(oth
); /* ? */
1146 log_err("FAIL: didn't crash on %s, but got %s instead of %s. \n", what
, u_errorName(subStatus
), u_errorName(expectStatus
));
1150 UErrorCode subStatus
= U_ZERO_ERROR
;
1151 what
= "udat_get2DigitYearStart";
1152 log_verbose("Trying %s on a relative date..\n", what
);
1153 udat_get2DigitYearStart(icudf
, &subStatus
);
1154 if(subStatus
== expectStatus
) {
1155 log_verbose("Success: did not crash on %s, but got %s.\n", what
, u_errorName(subStatus
));
1157 log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what
, u_errorName(subStatus
), u_errorName(expectStatus
));
1161 /* Now udat_toPattern works for relative date formatters, unless localized is TRUE */
1162 UErrorCode subStatus
= U_ZERO_ERROR
;
1163 what
= "udat_toPattern";
1164 log_verbose("Trying %s on a relative date..\n", what
);
1165 udat_toPattern(icudf
, TRUE
,NULL
,0, &subStatus
);
1166 if(subStatus
== expectStatus
) {
1167 log_verbose("Success: did not crash on %s, but got %s.\n", what
, u_errorName(subStatus
));
1169 log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what
, u_errorName(subStatus
), u_errorName(expectStatus
));
1173 UErrorCode subStatus
= U_ZERO_ERROR
;
1174 what
= "udat_applyPattern";
1175 log_verbose("Trying %s on a relative date..\n", what
);
1176 udat_applyPattern(icudf
, FALSE
,tzName
,-1);
1177 subStatus
= U_ILLEGAL_ARGUMENT_ERROR
; /* what it should be, if this took an errorcode. */
1178 if(subStatus
== expectStatus
) {
1179 log_verbose("Success: did not crash on %s, but got %s.\n", what
, u_errorName(subStatus
));
1181 log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what
, u_errorName(subStatus
), u_errorName(expectStatus
));
1185 UErrorCode subStatus
= U_ZERO_ERROR
;
1186 what
= "udat_getSymbols";
1187 log_verbose("Trying %s on a relative date..\n", what
);
1188 udat_getSymbols(icudf
, UDAT_ERAS
,0,NULL
,0, &subStatus
); /* bogus values */
1189 if(subStatus
== expectStatus
) {
1190 log_verbose("Success: did not crash on %s, but got %s.\n", what
, u_errorName(subStatus
));
1192 log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what
, u_errorName(subStatus
), u_errorName(expectStatus
));
1196 UErrorCode subStatus
= U_ZERO_ERROR
;
1197 what
= "udat_countSymbols";
1198 log_verbose("Trying %s on a relative date..\n", what
);
1199 udat_countSymbols(icudf
, UDAT_ERAS
);
1200 subStatus
= U_ILLEGAL_ARGUMENT_ERROR
; /* should have an errorcode. */
1201 if(subStatus
== expectStatus
) {
1202 log_verbose("Success: did not crash on %s, but got %s.\n", what
, u_errorName(subStatus
));
1204 log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what
, u_errorName(subStatus
), u_errorName(expectStatus
));
1210 log_err("FAIL: err %s\n", u_errorName(status
));
1214 #endif /* #if !UCONFIG_NO_FORMATTING */