2000-01-15 02:00:06 +00:00
/********************************************************************
* COPYRIGHT :
2015-01-12 15:51:02 +00:00
* Copyright ( c ) 1997 - 2015 , International Business Machines Corporation and
2000-01-15 02:00:06 +00:00
* others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/********************************************************************************
1999-08-16 21:50:52 +00:00
*
* File CDATTST . C
*
* Modification History :
* Name Description
* Madhu Katragadda Creation
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/* C API TEST FOR DATE FORMAT */
1999-12-28 23:57:50 +00:00
# include "unicode/utypes.h"
2002-09-20 17:54:45 +00:00
# if !UCONFIG_NO_FORMATTING
# include "unicode/uloc.h"
1999-12-28 23:57:50 +00:00
# include "unicode/udat.h"
2012-02-21 09:19:57 +00:00
# include "unicode/udatpg.h"
1999-12-28 23:57:50 +00:00
# include "unicode/ucal.h"
# include "unicode/unum.h"
# include "unicode/ustring.h"
2015-03-04 00:11:53 +00:00
# include "unicode/ufieldpositer.h"
1999-08-16 21:50:52 +00:00
# include "cintltst.h"
# include "cdattst.h"
# include "cformtst.h"
2001-05-31 23:42:59 +00:00
# include "cmemory.h"
2004-05-21 20:25:52 +00:00
# include <math.h>
static void TestExtremeDates ( void ) ;
2005-06-30 05:10:59 +00:00
static void TestAllLocales ( void ) ;
2009-02-14 02:29:08 +00:00
static void TestRelativeCrash ( void ) ;
2012-02-21 09:19:57 +00:00
static void TestContext ( void ) ;
2013-01-04 17:16:07 +00:00
static void TestCalendarDateParse ( void ) ;
2015-02-11 22:23:13 +00:00
static void TestParseErrorReturnValue ( void ) ;
2015-03-04 00:11:53 +00:00
static void TestFormatForFields ( void ) ;
2004-05-21 20:25:52 +00:00
# define LEN(a) (sizeof(a) / sizeof(a[0]))
2001-05-31 23:42:59 +00:00
void addDateForTest ( TestNode * * root ) ;
1999-08-16 21:50:52 +00:00
2004-05-21 20:25:52 +00:00
# define TESTCASE(x) addTest(root, &x, "tsformat / cdattst / " #x)
1999-08-16 21:50:52 +00:00
void addDateForTest ( TestNode * * root )
{
2004-05-21 20:25:52 +00:00
TESTCASE ( TestDateFormat ) ;
2009-01-30 10:46:17 +00:00
TESTCASE ( TestRelativeDateFormat ) ;
2004-05-21 20:25:52 +00:00
TESTCASE ( TestSymbols ) ;
TESTCASE ( TestDateFormatCalendar ) ;
TESTCASE ( TestExtremeDates ) ;
2005-06-30 05:10:59 +00:00
TESTCASE ( TestAllLocales ) ;
2009-02-14 02:29:08 +00:00
TESTCASE ( TestRelativeCrash ) ;
2012-02-21 09:19:57 +00:00
TESTCASE ( TestContext ) ;
2013-01-04 17:16:07 +00:00
TESTCASE ( TestCalendarDateParse ) ;
2014-08-01 21:33:16 +00:00
TESTCASE ( TestOverrideNumberFormat ) ;
2015-02-11 22:23:13 +00:00
TESTCASE ( TestParseErrorReturnValue ) ;
2015-03-04 00:11:53 +00:00
TESTCASE ( TestFormatForFields ) ;
1999-08-16 21:50:52 +00:00
}
/* Testing the DateFormat API */
2000-11-21 04:05:39 +00:00
static void TestDateFormat ( )
1999-08-16 21:50:52 +00:00
{
UDateFormat * def , * fr , * it , * de , * def1 , * fr_pat ;
2002-12-10 02:43:30 +00:00
UDateFormat * any ;
1999-08-16 21:50:52 +00:00
UDateFormat * copy ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2000-07-06 23:01:50 +00:00
UChar * result = NULL ;
1999-08-16 21:50:52 +00:00
const UCalendar * cal ;
const UNumberFormat * numformat1 , * numformat2 ;
2014-07-15 20:39:51 +00:00
UNumberFormat * adoptNF ;
2007-08-21 16:57:21 +00:00
UChar temp [ 50 ] ;
1999-08-16 21:50:52 +00:00
int32_t numlocales ;
UDate d1 ;
2002-12-10 02:43:30 +00:00
int i ;
1999-08-16 21:50:52 +00:00
int32_t resultlength ;
int32_t resultlengthneeded ;
int32_t parsepos ;
UDate d = 837039928046.0 ;
double num = - 10456.37 ;
2000-08-14 17:13:09 +00:00
/*const char* str="yyyy.MM.dd G 'at' hh:mm:ss z";
const char t [ ] = " 2/3/76 2:50 AM " ; */
1999-08-16 21:50:52 +00:00
/*Testing udat_open() to open a dateformat */
2003-10-07 21:52:15 +00:00
ctest_setTimeZone ( NULL , & status ) ;
1999-08-16 21:50:52 +00:00
log_verbose ( " \n Testing udat_open() with various parameters \n " ) ;
2001-08-16 00:58:53 +00:00
fr = udat_open ( UDAT_FULL , UDAT_DEFAULT , " fr_FR " , NULL , 0 , NULL , 0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
2009-06-09 21:28:13 +00:00
log_data_err ( " FAIL: error in creating the dateformat using full time style with french locale -> %s (Are you missing data?) \n " ,
1999-08-16 21:50:52 +00:00
myErrorName ( status ) ) ;
2002-01-30 06:16:26 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
2000-06-10 05:10:28 +00:00
/* this is supposed to open default date format, but later on it treats it like it is "en_US"
- very bad if you try to run the tests on machine where default locale is NOT " en_US " */
/* def = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0, &status); */
2001-08-16 00:58:53 +00:00
def = udat_open ( UDAT_SHORT , UDAT_SHORT , " en_US " , NULL , 0 , NULL , 0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: error in creating the dateformat using short date and time style \n %s \n " ,
myErrorName ( status ) ) ;
2002-01-30 06:16:26 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
2001-08-16 00:58:53 +00:00
it = udat_open ( UDAT_DEFAULT , UDAT_MEDIUM , " it_IT " , NULL , 0 , NULL , 0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: error in creating the dateformat using medium date style with italian locale \n %s \n " ,
myErrorName ( status ) ) ;
2002-01-30 06:16:26 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
2001-08-16 00:58:53 +00:00
de = udat_open ( UDAT_LONG , UDAT_LONG , " de_DE " , NULL , 0 , NULL , 0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: error in creating the dateformat using long time and date styles with german locale \n %s \n " ,
myErrorName ( status ) ) ;
2002-01-30 06:16:26 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
/*creating a default dateformat */
2001-08-16 00:58:53 +00:00
def1 = udat_open ( UDAT_SHORT , UDAT_SHORT , NULL , NULL , 0 , NULL , 0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: error in creating the dateformat using short date and time style \n %s \n " ,
myErrorName ( status ) ) ;
2002-01-30 06:16:26 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
/*Testing udat_getAvailable() and udat_countAvailable()*/
log_verbose ( " \n Testing getAvailableLocales and countAvailable() \n " ) ;
numlocales = udat_countAvailable ( ) ;
/* use something sensible w/o hardcoding the count */
if ( numlocales < 0 )
2002-09-17 19:45:50 +00:00
log_data_err ( " FAIL: error in countAvailable \n " ) ;
1999-08-16 21:50:52 +00:00
log_verbose ( " The number of locales for which date/time formatting patterns are available is %d \n " , numlocales ) ;
2002-12-10 02:43:30 +00:00
for ( i = 0 ; i < numlocales ; i + + ) {
UErrorCode subStatus = U_ZERO_ERROR ;
log_verbose ( " Testing open of %s \n " , udat_getAvailable ( i ) ) ;
2006-06-23 16:36:46 +00:00
any = udat_open ( UDAT_SHORT , UDAT_SHORT , udat_getAvailable ( i ) , NULL , 0 , NULL , 0 , & subStatus ) ;
2002-12-10 02:43:30 +00:00
if ( U_FAILURE ( subStatus ) ) {
2006-06-23 16:36:46 +00:00
log_data_err ( " FAIL: date format %s (getAvailable(%d)) is not instantiable: %s \n " , udat_getAvailable ( i ) , i , u_errorName ( subStatus ) ) ;
2002-12-10 02:43:30 +00:00
}
2002-12-12 18:28:22 +00:00
udat_close ( any ) ;
2002-12-10 02:43:30 +00:00
}
1999-08-16 21:50:52 +00:00
/*Testing udat_clone()*/
log_verbose ( " \n Testing the udat_clone() function of date format \n " ) ;
copy = udat_clone ( def , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
log_err ( " Error in creating the clone using udat_clone: %s \n " , myErrorName ( status ) ) ;
}
/*if(def != copy)
2002-03-08 17:04:20 +00:00
log_err ( " Error in udat_clone " ) ; */ /*how should i check for equality???? */
1999-08-16 21:50:52 +00:00
/*Testing udat_format()*/
log_verbose ( " \n Testing the udat_format() function of date format \n " ) ;
2012-08-28 21:56:06 +00:00
u_uastrcpy ( temp , " 7/10/96, 4:05 PM " ) ;
1999-08-16 21:50:52 +00:00
/*format using def */
resultlength = 0 ;
2001-03-08 23:41:16 +00:00
resultlengthneeded = udat_format ( def , d , NULL , resultlength , NULL , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthneeded + 1 ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
result = NULL ;
}
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
2001-03-08 23:41:16 +00:00
udat_format ( def , d , result , resultlength , NULL , & status ) ;
1999-08-16 21:50:52 +00:00
}
2003-06-04 22:02:07 +00:00
if ( U_FAILURE ( status ) | | ! result )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in formatting using udat_format(.....) %s \n " , myErrorName ( status ) ) ;
2003-06-04 22:02:07 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
else
log_verbose ( " PASS: formatting successful \n " ) ;
if ( u_strcmp ( result , temp ) = = 0 )
2009-03-17 01:06:38 +00:00
log_verbose ( " PASS: Date Format for US locale successful using udat_format() \n " ) ;
else {
char xbuf [ 2048 ] ;
char gbuf [ 2048 ] ;
u_austrcpy ( xbuf , temp ) ;
u_austrcpy ( gbuf , result ) ;
log_err ( " FAIL: Date Format for US locale failed using udat_format() - expected %s got %s \n " , xbuf , gbuf ) ;
}
1999-08-16 21:50:52 +00:00
/*format using fr */
2015-08-27 20:23:27 +00:00
u_unescape ( " 10 juil. 1996 \\ u00E0 16:05:28 heure d \\ u2019 \\ u00E9t \\ u00E9 du Pacifique " , temp , 50 ) ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
result = NULL ;
}
1999-08-16 21:50:52 +00:00
result = myDateFormat ( fr , d ) ;
if ( u_strcmp ( result , temp ) = = 0 )
2004-06-02 22:38:57 +00:00
log_verbose ( " PASS: Date Format for french locale successful using udat_format() \n " ) ;
1999-08-16 21:50:52 +00:00
else
2007-06-22 23:57:38 +00:00
log_data_err ( " FAIL: Date Format for french locale failed using udat_format(). \n " ) ;
2004-06-02 22:38:57 +00:00
/*format using it */
2014-09-02 23:18:20 +00:00
u_uastrcpy ( temp , " 10 lug 1996, 16:05:28 " ) ;
1999-08-16 21:50:52 +00:00
2007-07-25 18:46:17 +00:00
{
UChar * fmtted ;
char g [ 100 ] ;
char x [ 100 ] ;
fmtted = myDateFormat ( it , d ) ;
u_austrcpy ( g , fmtted ) ;
u_austrcpy ( x , temp ) ;
if ( u_strcmp ( fmtted , temp ) = = 0 ) {
log_verbose ( " PASS: Date Format for italian locale successful uisng udat_format() - wanted %s, got %s \n " , x , g ) ;
} else {
log_data_err ( " FAIL: Date Format for italian locale failed using udat_format() - wanted %s, got %s \n " , x , g ) ;
}
}
1999-08-16 21:50:52 +00:00
/*Testing parsing using udat_parse()*/
log_verbose ( " \n Testing parsing using udat_parse() \n " ) ;
2012-08-28 21:56:06 +00:00
u_uastrcpy ( temp , " 2/3/76, 2:50 AM " ) ;
1999-08-16 21:50:52 +00:00
parsepos = 0 ;
2004-07-16 16:22:08 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
d1 = udat_parse ( def , temp , u_strlen ( temp ) , & parsepos , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in parsing using udat_parse(.....) %s \n " , myErrorName ( status ) ) ;
}
else
log_verbose ( " PASS: parsing succesful \n " ) ;
/*format it back and check for equality */
if ( u_strcmp ( myDateFormat ( def , d1 ) , temp ) ! = 0 )
log_err ( " FAIL: error in parsing \n " ) ;
2004-07-16 16:22:08 +00:00
/*Testing parsing using udat_parse()*/
log_verbose ( " \n Testing parsing using udat_parse() \n " ) ;
u_uastrcpy ( temp , " 2/Don't parse this part " ) ;
status = U_ZERO_ERROR ;
d1 = udat_parse ( def , temp , u_strlen ( temp ) , NULL , & status ) ;
if ( status ! = U_PARSE_ERROR )
{
log_err ( " FAIL: udat_parse( \" bad string \" ) passed when it should have failed \n " ) ;
}
else
log_verbose ( " PASS: parsing succesful \n " ) ;
1999-08-16 21:50:52 +00:00
/*Testing udat_openPattern() */
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
log_verbose ( " \n Testing the udat_openPattern with a specified pattern \n " ) ;
/*for french locale */
2012-09-19 21:26:41 +00:00
fr_pat = udat_open ( UDAT_PATTERN , UDAT_PATTERN , " fr_FR " , NULL , 0 , temp , u_strlen ( temp ) , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in creating a date format using udat_openPattern \n %s \n " ,
myErrorName ( status ) ) ;
}
else
log_verbose ( " PASS: creating dateformat using udat_openPattern() succesful \n " ) ;
/*Testing applyPattern and toPattern */
log_verbose ( " \n Testing applyPattern and toPattern() \n " ) ;
udat_applyPattern ( def1 , FALSE , temp , u_strlen ( temp ) ) ;
log_verbose ( " Extracting the pattern \n " ) ;
resultlength = 0 ;
resultlengthneeded = udat_toPattern ( def1 , FALSE , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthneeded + 1 ;
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
1999-08-16 21:50:52 +00:00
udat_toPattern ( def1 , FALSE , result , resultlength , & status ) ;
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: error in extracting the pattern from UNumberFormat \n %s \n " ,
myErrorName ( status ) ) ;
}
if ( u_strcmp ( result , temp ) ! = 0 )
log_err ( " FAIL: Error in extracting the pattern \n " ) ;
else
log_verbose ( " PASS: applyPattern and toPattern work fine \n " ) ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
result = NULL ;
}
1999-08-16 21:50:52 +00:00
/*Testing getter and setter functions*/
/*isLenient and setLenient()*/
log_verbose ( " \n Testing the isLenient and setLenient properties \n " ) ;
udat_setLenient ( fr , udat_isLenient ( it ) ) ;
if ( udat_isLenient ( fr ) ! = udat_isLenient ( it ) )
log_err ( " ERROR: setLenient() failed \n " ) ;
else
log_verbose ( " PASS: setLenient() successful \n " ) ;
/*Test get2DigitYearStart set2DigitYearStart */
log_verbose ( " \n Testing the get and set 2DigitYearStart properties \n " ) ;
d1 = udat_get2DigitYearStart ( fr_pat , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
log_err ( " ERROR: udat_get2DigitYearStart failed %s \n " , myErrorName ( status ) ) ;
}
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
udat_set2DigitYearStart ( def1 , d1 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
log_err ( " ERROR: udat_set2DigitYearStart failed %s \n " , myErrorName ( status ) ) ;
}
if ( udat_get2DigitYearStart ( fr_pat , & status ) ! = udat_get2DigitYearStart ( def1 , & status ) )
log_err ( " FAIL: error in set2DigitYearStart \n " ) ;
else
log_verbose ( " PASS: set2DigitYearStart successful \n " ) ;
/*try setting it to another value */
udat_set2DigitYearStart ( de , 2000.0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
log_verbose ( " ERROR: udat_set2DigitYearStart failed %s \n " , myErrorName ( status ) ) ;
}
if ( udat_get2DigitYearStart ( de , & status ) ! = 2000 )
log_err ( " FAIL: error in set2DigitYearStart \n " ) ;
else
log_verbose ( " PASS: set2DigitYearStart successful \n " ) ;
/*Test getNumberFormat() and setNumberFormat() */
log_verbose ( " \n Testing the get and set NumberFormat properties of date format \n " ) ;
numformat1 = udat_getNumberFormat ( fr_pat ) ;
udat_setNumberFormat ( def1 , numformat1 ) ;
numformat2 = udat_getNumberFormat ( def1 ) ;
if ( u_strcmp ( myNumformat ( numformat1 , num ) , myNumformat ( numformat2 , num ) ) ! = 0 )
log_err ( " FAIL: error in setNumberFormat or getNumberFormat() \n " ) ;
else
log_verbose ( " PASS:setNumberFormat and getNumberFormat succesful \n " ) ;
2014-07-15 20:39:51 +00:00
/*Test getNumberFormat() and adoptNumberFormat() */
log_verbose ( " \n Testing the get and adopt NumberFormat properties of date format \n " ) ;
adoptNF = unum_open ( UNUM_DEFAULT , NULL , 0 , NULL , NULL , & status ) ;
udat_adoptNumberFormat ( def1 , adoptNF ) ;
numformat2 = udat_getNumberFormat ( def1 ) ;
if ( u_strcmp ( myNumformat ( adoptNF , num ) , myNumformat ( numformat2 , num ) ) ! = 0 )
log_err ( " FAIL: error in adoptNumberFormat or getNumberFormat() \n " ) ;
else
log_verbose ( " PASS:adoptNumberFormat and getNumberFormat succesful \n " ) ;
2001-03-08 23:41:16 +00:00
1999-08-16 21:50:52 +00:00
/*try setting the number format to another format */
numformat1 = udat_getNumberFormat ( def ) ;
udat_setNumberFormat ( def1 , numformat1 ) ;
numformat2 = udat_getNumberFormat ( def1 ) ;
if ( u_strcmp ( myNumformat ( numformat1 , num ) , myNumformat ( numformat2 , num ) ) ! = 0 )
log_err ( " FAIL: error in setNumberFormat or getNumberFormat() \n " ) ;
else
log_verbose ( " PASS: setNumberFormat and getNumberFormat succesful \n " ) ;
/*Test getCalendar and setCalendar*/
log_verbose ( " \n Testing the udat_getCalendar() and udat_setCalendar() properties \n " ) ;
cal = udat_getCalendar ( fr_pat ) ;
udat_setCalendar ( def1 , cal ) ;
if ( ! ucal_equivalentTo ( udat_getCalendar ( fr_pat ) , udat_getCalendar ( def1 ) ) )
log_err ( " FAIL: Error in setting and getting the calendar \n " ) ;
else
log_verbose ( " PASS: getting and setting calendar successful \n " ) ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
}
1999-08-16 21:50:52 +00:00
/*Closing the UDateForamt */
udat_close ( def ) ;
udat_close ( fr ) ;
udat_close ( it ) ;
udat_close ( de ) ;
udat_close ( def1 ) ;
udat_close ( fr_pat ) ;
2000-07-06 23:01:50 +00:00
udat_close ( copy ) ;
1999-08-16 21:50:52 +00:00
2003-10-07 21:52:15 +00:00
ctest_resetTimeZone ( ) ;
1999-08-16 21:50:52 +00:00
}
2009-01-30 10:46:17 +00:00
/*
Test combined relative date formatting ( relative date + non - relative time ) .
This is a bit tricky since we can ' t have static test data for comparison , the
relative date formatting is relative to the time the tests are run . We generate
the data for comparison dynamically . However , the tests could fail if they are
run right at midnight Pacific time and the call to ucal_getNow ( ) is before midnight
while the calls to udat_format are after midnight or span midnight .
*/
static const UDate dayInterval = 24.0 * 60.0 * 60.0 * 1000.0 ;
static const UChar trdfZone [ ] = { 0x0055 , 0x0053 , 0x002F , 0x0050 , 0x0061 , 0x0063 , 0x0069 , 0x0066 , 0x0069 , 0x0063 , 0 } ; /* US/Pacific */
static const char trdfLocale [ ] = " en_US " ;
2009-04-18 08:11:19 +00:00
static const UChar minutesPatn [ ] = { 0x006D , 0x006D , 0 } ; /* "mm" */
static const UChar monthLongPatn [ ] = { 0x004D , 0x004D , 0x004D , 0x004D , 0 } ; /* "MMMM" */
static const UChar monthMediumPatn [ ] = { 0x004D , 0x004D , 0x004D , 0 } ; /* "MMM" */
static const UChar monthShortPatn [ ] = { 0x004D , 0 } ; /* "M" */
2009-01-30 10:46:17 +00:00
static const UDateFormatStyle dateStylesList [ ] = { UDAT_FULL , UDAT_LONG , UDAT_MEDIUM , UDAT_SHORT , UDAT_NONE } ;
2009-04-18 08:11:19 +00:00
static const UChar * monthPatnsList [ ] = { monthLongPatn , monthLongPatn , monthMediumPatn , monthShortPatn , NULL } ;
static const UChar newTimePatn [ ] = { 0x0048 , 0x0048 , 0x002C , 0x006D , 0x006D , 0 } ; /* "HH,mm" */
2009-01-30 10:46:17 +00:00
static const UChar minutesStr [ ] = { 0x0034 , 0x0039 , 0 } ; /* "49", minutes string to search for in output */
enum { kDateOrTimeOutMax = 96 , kDateAndTimeOutMax = 192 } ;
2012-10-15 23:32:31 +00:00
static const UDate minutesTolerance = 2 * 60.0 * 1000.0 ;
static const UDate daysTolerance = 2 * 24.0 * 60.0 * 60.0 * 1000.0 ;
2009-01-30 10:46:17 +00:00
static void TestRelativeDateFormat ( )
{
UDate today = 0.0 ;
const UDateFormatStyle * stylePtr ;
2009-04-18 08:11:19 +00:00
const UChar * * monthPtnPtr ;
2009-01-30 10:46:17 +00:00
UErrorCode status = U_ZERO_ERROR ;
UCalendar * ucal = ucal_open ( trdfZone , - 1 , trdfLocale , UCAL_GREGORIAN , & status ) ;
if ( U_SUCCESS ( status ) ) {
int32_t year , month , day ;
ucal_setMillis ( ucal , ucal_getNow ( ) , & status ) ;
year = ucal_get ( ucal , UCAL_YEAR , & status ) ;
month = ucal_get ( ucal , UCAL_MONTH , & status ) ;
day = ucal_get ( ucal , UCAL_DATE , & status ) ;
ucal_setDateTime ( ucal , year , month , day , 18 , 49 , 0 , & status ) ; /* set to today at 18:49:00 */
today = ucal_getMillis ( ucal , & status ) ;
ucal_close ( ucal ) ;
}
if ( U_FAILURE ( status ) | | today = = 0.0 ) {
2010-02-24 16:17:03 +00:00
log_data_err ( " Generate UDate for a specified time today fails, error %s - (Are you missing data?) \n " , myErrorName ( status ) ) ;
2009-01-30 10:46:17 +00:00
return ;
}
2009-04-18 08:11:19 +00:00
for ( stylePtr = dateStylesList , monthPtnPtr = monthPatnsList ; * stylePtr ! = UDAT_NONE ; + + stylePtr , + + monthPtnPtr ) {
2009-01-30 10:46:17 +00:00
UDateFormat * fmtRelDateTime ;
UDateFormat * fmtRelDate ;
UDateFormat * fmtTime ;
int32_t dayOffset , limit ;
UFieldPosition fp ;
2012-10-15 23:32:31 +00:00
UChar strDateTime [ kDateAndTimeOutMax ] ;
UChar strDate [ kDateOrTimeOutMax ] ;
UChar strTime [ kDateOrTimeOutMax ] ;
UChar * strPtr ;
2009-04-18 08:11:19 +00:00
int32_t dtpatLen ;
2009-01-30 10:46:17 +00:00
fmtRelDateTime = udat_open ( UDAT_SHORT , * stylePtr | UDAT_RELATIVE , trdfLocale , trdfZone , - 1 , NULL , 0 , & status ) ;
if ( U_FAILURE ( status ) ) {
2009-06-09 21:28:13 +00:00
log_data_err ( " udat_open timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s (Are you missing data?) \n " , * stylePtr , myErrorName ( status ) ) ;
2009-01-30 10:46:17 +00:00
continue ;
}
fmtRelDate = udat_open ( UDAT_NONE , * stylePtr | UDAT_RELATIVE , trdfLocale , trdfZone , - 1 , NULL , 0 , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " udat_open timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
udat_close ( fmtRelDateTime ) ;
continue ;
}
fmtTime = udat_open ( UDAT_SHORT , UDAT_NONE , trdfLocale , trdfZone , - 1 , NULL , 0 , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " udat_open timeStyle SHORT dateStyle NONE fails, error %s \n " , myErrorName ( status ) ) ;
udat_close ( fmtRelDateTime ) ;
udat_close ( fmtRelDate ) ;
continue ;
}
2009-04-18 08:11:19 +00:00
dtpatLen = udat_toPatternRelativeDate ( fmtRelDateTime , strDate , kDateAndTimeOutMax , & status ) ;
if ( U_FAILURE ( status ) ) {
2012-10-15 23:32:31 +00:00
log_err ( " udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
2009-04-18 08:11:19 +00:00
} else if ( u_strstr ( strDate , * monthPtnPtr ) = = NULL | | dtpatLen ! = u_strlen ( strDate ) ) {
2012-10-15 23:32:31 +00:00
log_err ( " udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) date pattern incorrect \n " , * stylePtr ) ;
2009-04-18 08:11:19 +00:00
}
dtpatLen = udat_toPatternRelativeTime ( fmtRelDateTime , strTime , kDateAndTimeOutMax , & status ) ;
if ( U_FAILURE ( status ) ) {
2012-10-15 23:32:31 +00:00
log_err ( " udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
2009-04-18 08:11:19 +00:00
} else if ( u_strstr ( strTime , minutesPatn ) = = NULL | | dtpatLen ! = u_strlen ( strTime ) ) {
2012-10-15 23:32:31 +00:00
log_err ( " udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) time pattern incorrect \n " , * stylePtr ) ;
2009-04-18 08:11:19 +00:00
}
dtpatLen = udat_toPattern ( fmtRelDateTime , FALSE , strDateTime , kDateAndTimeOutMax , & status ) ;
if ( U_FAILURE ( status ) ) {
2012-10-15 23:32:31 +00:00
log_err ( " udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
2009-04-18 08:11:19 +00:00
} else if ( u_strstr ( strDateTime , strDate ) = = NULL | | u_strstr ( strDateTime , strTime ) = = NULL | | dtpatLen ! = u_strlen ( strDateTime ) ) {
2012-10-15 23:32:31 +00:00
log_err ( " udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) dateTime pattern incorrect \n " , * stylePtr ) ;
2009-04-18 08:11:19 +00:00
}
udat_applyPatternRelative ( fmtRelDateTime , strDate , u_strlen ( strDate ) , newTimePatn , u_strlen ( newTimePatn ) , & status ) ;
if ( U_FAILURE ( status ) ) {
2012-10-15 23:32:31 +00:00
log_err ( " udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
2009-04-18 08:11:19 +00:00
} else {
2012-10-15 23:32:31 +00:00
udat_toPattern ( fmtRelDateTime , FALSE , strDateTime , kDateAndTimeOutMax , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
} else if ( u_strstr ( strDateTime , newTimePatn ) = = NULL ) {
log_err ( " udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) didn't update time pattern \n " , * stylePtr ) ;
}
2009-04-18 08:11:19 +00:00
}
udat_applyPatternRelative ( fmtRelDateTime , strDate , u_strlen ( strDate ) , strTime , u_strlen ( strTime ) , & status ) ; /* restore original */
2009-01-30 10:46:17 +00:00
fp . field = UDAT_MINUTE_FIELD ;
for ( dayOffset = - 2 , limit = 2 ; dayOffset < = limit ; + + dayOffset ) {
UDate dateToUse = today + ( float ) dayOffset * dayInterval ;
2009-04-18 08:11:19 +00:00
udat_format ( fmtRelDateTime , dateToUse , strDateTime , kDateAndTimeOutMax , & fp , & status ) ;
2009-01-30 10:46:17 +00:00
if ( U_FAILURE ( status ) ) {
log_err ( " udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
} else {
2012-10-15 23:32:31 +00:00
int32_t parsePos = 0 ;
UDate dateResult = udat_parse ( fmtRelDateTime , strDateTime , - 1 , & parsePos , & status ) ;
UDate dateDiff = ( dateResult > = dateToUse ) ? dateResult - dateToUse : dateToUse - dateResult ;
if ( U_FAILURE ( status ) | | dateDiff > minutesTolerance ) {
log_err ( " udat_parse timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s, expect approx %.1f, got %.1f, parsePos %d \n " ,
* stylePtr , myErrorName ( status ) , dateToUse , dateResult , parsePos ) ;
status = U_ZERO_ERROR ;
}
2009-04-18 08:11:19 +00:00
udat_format ( fmtRelDate , dateToUse , strDate , kDateOrTimeOutMax , NULL , & status ) ;
2009-01-30 10:46:17 +00:00
if ( U_FAILURE ( status ) ) {
log_err ( " udat_format timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s \n " , * stylePtr , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
2009-04-18 08:11:19 +00:00
} else if ( u_strstr ( strDateTime , strDate ) = = NULL ) {
2009-01-30 10:46:17 +00:00
log_err ( " relative date string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) \n " , * stylePtr ) ;
2012-10-15 23:32:31 +00:00
} else {
parsePos = 0 ;
dateResult = udat_parse ( fmtRelDate , strDate , - 1 , & parsePos , & status ) ;
dateDiff = ( dateResult > = dateToUse ) ? dateResult - dateToUse : dateToUse - dateResult ;
if ( U_FAILURE ( status ) | | dateDiff > daysTolerance ) {
log_err ( " udat_parse timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s, expect approx %.1f, got %.1f, parsePos %d \n " ,
* stylePtr , myErrorName ( status ) , dateToUse , dateResult , parsePos ) ;
status = U_ZERO_ERROR ;
}
2009-01-30 10:46:17 +00:00
}
udat_format ( fmtTime , dateToUse , strTime , kDateOrTimeOutMax , NULL , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " udat_format timeStyle SHORT dateStyle NONE fails, error %s \n " , myErrorName ( status ) ) ;
status = U_ZERO_ERROR ;
2009-04-18 08:11:19 +00:00
} else if ( u_strstr ( strDateTime , strTime ) = = NULL ) {
2009-01-30 10:46:17 +00:00
log_err ( " time string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) \n " , * stylePtr ) ;
}
2009-04-18 08:11:19 +00:00
strPtr = u_strstr ( strDateTime , minutesStr ) ;
2009-01-30 10:46:17 +00:00
if ( strPtr ! = NULL ) {
2009-04-18 08:11:19 +00:00
int32_t beginIndex = strPtr - strDateTime ;
2009-01-30 10:46:17 +00:00
if ( fp . beginIndex ! = beginIndex ) {
log_err ( " UFieldPosition beginIndex %d, expected %d, in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) \n " , fp . beginIndex , beginIndex , * stylePtr ) ;
}
} else {
log_err ( " minutes string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) \n " , * stylePtr ) ;
}
}
}
udat_close ( fmtRelDateTime ) ;
udat_close ( fmtRelDate ) ;
udat_close ( fmtTime ) ;
}
}
1999-08-16 21:50:52 +00:00
/*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/
2000-11-21 04:05:39 +00:00
static void TestSymbols ( )
1999-08-16 21:50:52 +00:00
{
2014-09-08 04:52:23 +00:00
UDateFormat * def , * fr , * zhChiCal ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2000-08-14 17:13:09 +00:00
UChar * value = NULL ;
2000-07-06 23:01:50 +00:00
UChar * result = NULL ;
1999-08-16 21:50:52 +00:00
int32_t resultlength ;
int32_t resultlengthout ;
UChar * pattern ;
/*creating a dateformat with french locale */
log_verbose ( " \n creating a date format with french locale \n " ) ;
2001-08-16 00:58:53 +00:00
fr = udat_open ( UDAT_FULL , UDAT_DEFAULT , " fr_FR " , NULL , 0 , NULL , 0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
2009-06-09 21:28:13 +00:00
log_data_err ( " error in creating the dateformat using full time style with french locale -> %s (Are you missing data?) \n " ,
1999-08-16 21:50:52 +00:00
myErrorName ( status ) ) ;
2002-01-30 06:16:26 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
/*creating a default dateformat */
log_verbose ( " \n creating a date format with default locale \n " ) ;
2000-06-10 05:10:28 +00:00
/* this is supposed to open default date format, but later on it treats it like it is "en_US"
- very bad if you try to run the tests on machine where default locale is NOT " en_US " */
/* def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL, NULL, 0, &status); */
2001-08-16 00:58:53 +00:00
def = udat_open ( UDAT_DEFAULT , UDAT_DEFAULT , " en_US " , NULL , 0 , NULL , 0 , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " error in creating the dateformat using short date and time style \n %s \n " ,
myErrorName ( status ) ) ;
2002-01-30 06:16:26 +00:00
return ;
1999-08-16 21:50:52 +00:00
}
2014-09-08 04:52:23 +00:00
/*creating a dateformat with zh locale */
log_verbose ( " \n creating a date format with zh locale for chinese calendar \n " ) ;
zhChiCal = udat_open ( UDAT_NONE , UDAT_FULL , " zh@calendar=chinese " , NULL , 0 , NULL , 0 , & status ) ;
if ( U_FAILURE ( status ) )
{
log_data_err ( " error in creating the dateformat using full date, no time, locale zh@calendar=chinese -> %s (Are you missing data?) \n " ,
myErrorName ( status ) ) ;
return ;
}
1999-08-16 21:50:52 +00:00
/*Testing countSymbols, getSymbols and setSymbols*/
log_verbose ( " \n Testing countSymbols \n " ) ;
/*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 */
2002-01-30 06:16:26 +00:00
if ( udat_countSymbols ( def , UDAT_ERAS ) ! = 2 | | udat_countSymbols ( def , UDAT_MONTHS ) ! = 12 | |
udat_countSymbols ( def , UDAT_SHORT_MONTHS ) ! = 12 | | udat_countSymbols ( def , UDAT_WEEKDAYS ) ! = 8 | |
1999-08-16 21:50:52 +00:00
udat_countSymbols ( def , UDAT_SHORT_WEEKDAYS ) ! = 8 | | udat_countSymbols ( def , UDAT_AM_PMS ) ! = 2 | |
2006-07-12 23:21:02 +00:00
udat_countSymbols ( def , UDAT_QUARTERS ) ! = 4 | | udat_countSymbols ( def , UDAT_SHORT_QUARTERS ) ! = 4 | |
2014-09-08 04:52:23 +00:00
udat_countSymbols ( def , UDAT_LOCALIZED_CHARS ) ! = 1 | | udat_countSymbols ( def , UDAT_SHORTER_WEEKDAYS ) ! = 8 | |
udat_countSymbols ( zhChiCal , UDAT_CYCLIC_YEARS_NARROW ) ! = 60 | | udat_countSymbols ( zhChiCal , UDAT_ZODIAC_NAMES_NARROW ) ! = 12 )
2002-01-30 06:16:26 +00:00
{
log_err ( " FAIL: error in udat_countSymbols \n " ) ;
}
1999-08-16 21:50:52 +00:00
else
log_verbose ( " PASS: udat_countSymbols() successful \n " ) ;
/*testing getSymbols*/
log_verbose ( " \n Testing getSymbols \n " ) ;
2002-07-29 21:04:18 +00:00
pattern = ( UChar * ) malloc ( sizeof ( UChar ) * 10 ) ;
1999-08-16 21:50:52 +00:00
u_uastrcpy ( pattern , " jeudi " ) ;
resultlength = 0 ;
resultlengthout = udat_getSymbols ( fr , UDAT_WEEKDAYS , 5 , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
result = NULL ;
}
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
1999-08-16 21:50:52 +00:00
udat_getSymbols ( fr , UDAT_WEEKDAYS , 5 , result , resultlength , & status ) ;
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in udat_getSymbols().... %s \n " , myErrorName ( status ) ) ;
}
else
log_verbose ( " PASS: getSymbols succesful \n " ) ;
if ( u_strcmp ( result , pattern ) = = 0 )
log_verbose ( " PASS: getSymbols retrieved the right value \n " ) ;
else
2002-09-17 19:45:50 +00:00
log_data_err ( " FAIL: getSymbols retrieved the wrong value \n " ) ;
1999-08-16 21:50:52 +00:00
/*run series of tests to test getsymbols regressively*/
log_verbose ( " \n Testing getSymbols() regressively \n " ) ;
VerifygetSymbols ( fr , UDAT_WEEKDAYS , 1 , " dimanche " ) ;
VerifygetSymbols ( def , UDAT_WEEKDAYS , 1 , " Sunday " ) ;
VerifygetSymbols ( fr , UDAT_SHORT_WEEKDAYS , 7 , " sam. " ) ;
2013-01-14 22:23:44 +00:00
VerifygetSymbols ( fr , UDAT_SHORTER_WEEKDAYS , 7 , " sa " ) ;
1999-08-16 21:50:52 +00:00
VerifygetSymbols ( def , UDAT_SHORT_WEEKDAYS , 7 , " Sat " ) ;
VerifygetSymbols ( def , UDAT_MONTHS , 11 , " December " ) ;
VerifygetSymbols ( def , UDAT_MONTHS , 0 , " January " ) ;
1999-11-04 17:59:14 +00:00
VerifygetSymbols ( fr , UDAT_ERAS , 0 , " av. J.-C. " ) ;
1999-08-16 21:50:52 +00:00
VerifygetSymbols ( def , UDAT_AM_PMS , 0 , " AM " ) ;
VerifygetSymbols ( def , UDAT_AM_PMS , 1 , " PM " ) ;
VerifygetSymbols ( fr , UDAT_SHORT_MONTHS , 0 , " janv. " ) ;
VerifygetSymbols ( def , UDAT_SHORT_MONTHS , 11 , " Dec " ) ;
2006-07-12 23:21:02 +00:00
VerifygetSymbols ( fr , UDAT_QUARTERS , 0 , " 1er trimestre " ) ;
VerifygetSymbols ( def , UDAT_QUARTERS , 3 , " 4th quarter " ) ;
VerifygetSymbols ( fr , UDAT_SHORT_QUARTERS , 1 , " T2 " ) ;
VerifygetSymbols ( def , UDAT_SHORT_QUARTERS , 2 , " Q3 " ) ;
2014-09-08 04:52:23 +00:00
VerifygetSymbols ( zhChiCal , UDAT_CYCLIC_YEARS_ABBREVIATED , 0 , " \\ u7532 \\ u5B50 " ) ;
VerifygetSymbols ( zhChiCal , UDAT_CYCLIC_YEARS_NARROW , 59 , " \\ u7678 \\ u4EA5 " ) ;
VerifygetSymbols ( zhChiCal , UDAT_ZODIAC_NAMES_ABBREVIATED , 0 , " \\ u9F20 " ) ;
VerifygetSymbols ( zhChiCal , UDAT_ZODIAC_NAMES_WIDE , 11 , " \\ u732A " ) ;
2015-09-07 22:39:49 +00:00
# if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
2014-12-19 07:19:41 +00:00
VerifygetSymbols ( def , UDAT_LOCALIZED_CHARS , 0 , " GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr: " ) ;
2015-09-07 22:39:49 +00:00
# else
VerifygetSymbols ( def , UDAT_LOCALIZED_CHARS , 0 , " GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr " ) ;
# endif
1999-08-16 21:50:52 +00:00
2001-05-31 23:42:59 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2001-05-31 23:42:59 +00:00
result = NULL ;
}
2002-07-29 21:04:18 +00:00
free ( pattern ) ;
1999-08-16 21:50:52 +00:00
log_verbose ( " \n Testing setSymbols \n " ) ;
/*applying the pattern so that setSymbolss works */
resultlength = 0 ;
resultlengthout = udat_toPattern ( fr , FALSE , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2002-07-29 21:04:18 +00:00
pattern = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
1999-08-16 21:50:52 +00:00
udat_toPattern ( fr , FALSE , pattern , resultlength , & status ) ;
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: error in extracting the pattern from UNumberFormat \n %s \n " ,
myErrorName ( status ) ) ;
}
udat_applyPattern ( def , FALSE , pattern , u_strlen ( pattern ) ) ;
resultlength = 0 ;
resultlengthout = udat_toPattern ( def , FALSE , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
result = NULL ;
}
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
1999-08-16 21:50:52 +00:00
udat_toPattern ( fr , FALSE , result , resultlength , & status ) ;
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: error in extracting the pattern from UNumberFormat \n %s \n " ,
myErrorName ( status ) ) ;
}
if ( u_strcmp ( result , pattern ) = = 0 )
log_verbose ( " Pattern applied properly \n " ) ;
else
log_err ( " pattern could not be applied properly \n " ) ;
2002-07-29 21:04:18 +00:00
free ( pattern ) ;
1999-08-16 21:50:52 +00:00
/*testing set symbols */
resultlength = 0 ;
resultlengthout = udat_getSymbols ( fr , UDAT_MONTHS , 11 , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR ) {
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
result = NULL ;
}
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
1999-08-16 21:50:52 +00:00
udat_getSymbols ( fr , UDAT_MONTHS , 11 , result , resultlength , & status ) ;
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
log_err ( " FAIL: error in getSymbols() %s \n " , myErrorName ( status ) ) ;
resultlength = resultlengthout + 1 ;
udat_setSymbols ( def , UDAT_MONTHS , 11 , result , resultlength , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in udat_setSymbols() : %s \n " , myErrorName ( status ) ) ;
}
else
log_verbose ( " PASS: SetSymbols successful \n " ) ;
resultlength = 0 ;
resultlengthout = udat_getSymbols ( def , UDAT_MONTHS , 11 , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR ) {
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2002-07-29 21:04:18 +00:00
value = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
1999-08-16 21:50:52 +00:00
udat_getSymbols ( def , UDAT_MONTHS , 11 , value , resultlength , & status ) ;
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
log_err ( " FAIL: error in retrieving the value using getSymbols i.e roundtrip \n " ) ;
if ( u_strcmp ( result , value ) ! = 0 )
2002-09-17 19:45:50 +00:00
log_data_err ( " FAIL: Error in settting and getting symbols \n " ) ;
1999-08-16 21:50:52 +00:00
else
log_verbose ( " PASS: setSymbols successful \n " ) ;
/*run series of tests to test setSymbols regressively*/
log_verbose ( " \n Testing setSymbols regressively \n " ) ;
VerifysetSymbols ( def , UDAT_ERAS , 0 , " BeforeChrist " ) ;
2006-08-07 16:32:50 +00:00
VerifysetSymbols ( def , UDAT_ERA_NAMES , 1 , " AnnoDomini " ) ;
VerifysetSymbols ( def , UDAT_WEEKDAYS , 1 , " Sundayweek " ) ;
1999-08-16 21:50:52 +00:00
VerifysetSymbols ( def , UDAT_SHORT_WEEKDAYS , 7 , " Satweek " ) ;
2006-08-07 16:32:50 +00:00
VerifysetSymbols ( def , UDAT_NARROW_WEEKDAYS , 4 , " M " ) ;
VerifysetSymbols ( def , UDAT_STANDALONE_WEEKDAYS , 1 , " Sonntagweek " ) ;
VerifysetSymbols ( def , UDAT_STANDALONE_SHORT_WEEKDAYS , 7 , " Sams " ) ;
VerifysetSymbols ( def , UDAT_STANDALONE_NARROW_WEEKDAYS , 4 , " V " ) ;
1999-08-16 21:50:52 +00:00
VerifysetSymbols ( fr , UDAT_MONTHS , 11 , " december " ) ;
VerifysetSymbols ( fr , UDAT_SHORT_MONTHS , 0 , " Jan " ) ;
2006-08-07 16:32:50 +00:00
VerifysetSymbols ( fr , UDAT_NARROW_MONTHS , 1 , " R " ) ;
VerifysetSymbols ( fr , UDAT_STANDALONE_MONTHS , 11 , " dezember " ) ;
VerifysetSymbols ( fr , UDAT_STANDALONE_SHORT_MONTHS , 7 , " Aug " ) ;
VerifysetSymbols ( fr , UDAT_STANDALONE_NARROW_MONTHS , 2 , " M " ) ;
2006-08-08 22:00:10 +00:00
VerifysetSymbols ( fr , UDAT_QUARTERS , 0 , " 1. Quart " ) ;
VerifysetSymbols ( fr , UDAT_SHORT_QUARTERS , 1 , " QQ2 " ) ;
VerifysetSymbols ( fr , UDAT_STANDALONE_QUARTERS , 2 , " 3rd Quar. " ) ;
VerifysetSymbols ( fr , UDAT_STANDALONE_SHORT_QUARTERS , 3 , " 4QQ " ) ;
2014-09-08 04:52:23 +00:00
VerifysetSymbols ( zhChiCal , UDAT_CYCLIC_YEARS_ABBREVIATED , 1 , " yi-chou " ) ;
VerifysetSymbols ( zhChiCal , UDAT_ZODIAC_NAMES_ABBREVIATED , 1 , " Ox " ) ;
1999-08-16 21:50:52 +00:00
/*run series of tests to test get and setSymbols regressively*/
log_verbose ( " \n Testing get and set symbols regressively \n " ) ;
VerifygetsetSymbols ( fr , def , UDAT_WEEKDAYS , 1 ) ;
VerifygetsetSymbols ( fr , def , UDAT_WEEKDAYS , 7 ) ;
VerifygetsetSymbols ( fr , def , UDAT_SHORT_WEEKDAYS , 1 ) ;
VerifygetsetSymbols ( fr , def , UDAT_SHORT_WEEKDAYS , 7 ) ;
VerifygetsetSymbols ( fr , def , UDAT_MONTHS , 0 ) ;
VerifygetsetSymbols ( fr , def , UDAT_SHORT_MONTHS , 0 ) ;
VerifygetsetSymbols ( fr , def , UDAT_ERAS , 1 ) ;
VerifygetsetSymbols ( fr , def , UDAT_LOCALIZED_CHARS , 0 ) ;
VerifygetsetSymbols ( fr , def , UDAT_AM_PMS , 1 ) ;
/*closing*/
udat_close ( fr ) ;
udat_close ( def ) ;
2014-09-08 04:52:23 +00:00
udat_close ( zhChiCal ) ;
2000-07-06 23:01:50 +00:00
if ( result ! = NULL ) {
2002-07-29 21:04:18 +00:00
free ( result ) ;
2000-07-06 23:01:50 +00:00
result = NULL ;
}
2002-07-29 21:04:18 +00:00
free ( value ) ;
1999-08-16 21:50:52 +00:00
}
2002-03-06 20:42:32 +00:00
/**
* Test DateFormat ( Calendar ) API
*/
2002-03-29 19:47:34 +00:00
static void TestDateFormatCalendar ( ) {
2002-03-06 20:42:32 +00:00
UDateFormat * date = 0 , * time = 0 , * full = 0 ;
UCalendar * cal = 0 ;
UChar buf [ 256 ] ;
char cbuf [ 256 ] ;
int32_t pos ;
UDate when ;
UErrorCode ec = U_ZERO_ERROR ;
2014-11-25 04:34:58 +00:00
UChar buf1 [ 256 ] ;
int32_t len1 ;
const char * expected ;
UChar uExpected [ 32 ] ;
2002-03-06 20:42:32 +00:00
2003-10-07 21:52:15 +00:00
ctest_setTimeZone ( NULL , & ec ) ;
2002-03-08 17:04:20 +00:00
/* Create a formatter for date fields. */
2002-03-06 20:42:32 +00:00
date = udat_open ( UDAT_NONE , UDAT_SHORT , " en_US " , NULL , 0 , NULL , 0 , & ec ) ;
if ( U_FAILURE ( ec ) ) {
2009-06-09 21:28:13 +00:00
log_data_err ( " FAIL: udat_open(NONE, SHORT, en_US) failed with %s (Are you missing data?) \n " ,
2002-03-06 20:42:32 +00:00
u_errorName ( ec ) ) ;
goto FAIL ;
}
2002-03-08 17:04:20 +00:00
/* Create a formatter for time fields. */
2002-03-06 20:42:32 +00:00
time = udat_open ( UDAT_SHORT , UDAT_NONE , " en_US " , NULL , 0 , NULL , 0 , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: udat_open(SHORT, NONE, en_US) failed with %s \n " ,
u_errorName ( ec ) ) ;
goto FAIL ;
}
2002-03-08 17:04:20 +00:00
/* Create a full format for output */
2002-03-06 20:42:32 +00:00
full = udat_open ( UDAT_FULL , UDAT_FULL , " en_US " , NULL , 0 , NULL , 0 , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: udat_open(FULL, FULL, en_US) failed with %s \n " ,
u_errorName ( ec ) ) ;
goto FAIL ;
}
2002-03-08 17:04:20 +00:00
/* Create a calendar */
2002-03-06 20:42:32 +00:00
cal = ucal_open ( NULL , 0 , " en_US " , UCAL_GREGORIAN , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: ucal_open(en_US) failed with %s \n " ,
u_errorName ( ec ) ) ;
goto FAIL ;
}
2002-03-08 17:04:20 +00:00
/* Parse the date */
2002-03-06 20:42:32 +00:00
ucal_clear ( cal ) ;
u_uastrcpy ( buf , " 4/5/2001 " ) ;
pos = 0 ;
udat_parseCalendar ( date , cal , buf , - 1 , & pos , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: udat_parseCalendar(4/5/2001) failed at %d with %s \n " ,
pos , u_errorName ( ec ) ) ;
goto FAIL ;
}
2014-11-25 04:34:58 +00:00
/* Check if formatCalendar matches the original date */
len1 = udat_formatCalendar ( date , cal , buf1 , UPRV_LENGTHOF ( buf1 ) , NULL , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: udat_formatCalendar(4/5/2001) failed with %s \n " ,
u_errorName ( ec ) ) ;
goto FAIL ;
}
expected = " 4/5/01 " ;
u_uastrcpy ( uExpected , expected ) ;
if ( u_strlen ( uExpected ) ! = len1 | | u_strncmp ( uExpected , buf1 , len1 ) ! = 0 ) {
log_err ( " FAIL: udat_formatCalendar(4/5/2001), expected: %s " , expected ) ;
}
2002-03-08 17:04:20 +00:00
/* Parse the time */
2002-03-06 20:42:32 +00:00
u_uastrcpy ( buf , " 5:45 PM " ) ;
pos = 0 ;
udat_parseCalendar ( time , cal , buf , - 1 , & pos , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: udat_parseCalendar(17:45) failed at %d with %s \n " ,
pos , u_errorName ( ec ) ) ;
goto FAIL ;
}
2014-11-25 04:34:58 +00:00
/* Check if formatCalendar matches the original time */
len1 = udat_formatCalendar ( time , cal , buf1 , UPRV_LENGTHOF ( buf1 ) , NULL , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: udat_formatCalendar(17:45) failed with %s \n " ,
u_errorName ( ec ) ) ;
goto FAIL ;
}
expected = " 5:45 PM " ;
u_uastrcpy ( uExpected , expected ) ;
if ( u_strlen ( uExpected ) ! = len1 | | u_strncmp ( uExpected , buf1 , len1 ) ! = 0 ) {
log_err ( " FAIL: udat_formatCalendar(17:45), expected: %s " , expected ) ;
}
2002-03-08 17:04:20 +00:00
/* Check result */
2002-03-06 20:42:32 +00:00
when = ucal_getMillis ( cal , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: ucal_getMillis() failed with %s \n " , u_errorName ( ec ) ) ;
goto FAIL ;
}
udat_format ( full , when , buf , sizeof ( buf ) , NULL , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: udat_format() failed with %s \n " , u_errorName ( ec ) ) ;
goto FAIL ;
}
u_austrcpy ( cbuf , buf ) ;
2002-04-11 23:42:17 +00:00
/* Thursday, April 5, 2001 5:45:00 PM PDT 986517900000 */
if ( when = = 986517900000.0 ) {
2002-04-09 23:24:42 +00:00
log_verbose ( " Ok: Parsed result: %s \n " , cbuf ) ;
} else {
2003-10-07 21:52:15 +00:00
log_err ( " FAIL: Parsed result: %s, exp 4/5/2001 5:45 PM \n " , cbuf ) ;
2002-04-09 23:24:42 +00:00
}
2002-03-06 20:42:32 +00:00
FAIL :
udat_close ( date ) ;
udat_close ( time ) ;
udat_close ( full ) ;
ucal_close ( cal ) ;
2003-10-07 21:52:15 +00:00
ctest_resetTimeZone ( ) ;
2002-03-06 20:42:32 +00:00
}
2013-01-04 17:16:07 +00:00
/**
2013-09-12 01:27:29 +00:00
* Test parsing two digit year against " YY " vs . " YYYY " patterns
2013-01-04 17:16:07 +00:00
*/
static void TestCalendarDateParse ( ) {
2013-09-12 01:27:29 +00:00
int32_t result ;
UErrorCode ec = U_ZERO_ERROR ;
2013-01-04 17:16:07 +00:00
UDateFormat * simpleDateFormat = 0 ;
2013-09-12 01:27:29 +00:00
int32_t parsePos = 0 ;
int32_t twoDigitCenturyStart = 75 ;
int32_t currentTwoDigitYear = 0 ;
int32_t startCentury = 0 ;
2013-01-04 17:16:07 +00:00
UCalendar * tempCal = 0 ;
UCalendar * calendar = 0 ;
2013-01-05 23:43:54 +00:00
U_STRING_DECL ( pattern , " yyyy " , 4 ) ;
U_STRING_DECL ( pattern2 , " yy " , 2 ) ;
U_STRING_DECL ( text , " 75 " , 2 ) ;
U_STRING_INIT ( pattern , " yyyy " , 4 ) ;
U_STRING_INIT ( pattern2 , " yy " , 2 ) ;
U_STRING_INIT ( text , " 75 " , 2 ) ;
2013-01-04 17:16:07 +00:00
simpleDateFormat = udat_open ( UDAT_FULL , UDAT_FULL , " en-GB " , 0 , 0 , 0 , 0 , & ec ) ;
2013-01-29 01:51:53 +00:00
if ( U_FAILURE ( ec ) ) {
log_data_err ( " udat_open(UDAT_FULL, UDAT_FULL, \" en-GB \" , 0, 0, 0, 0, &ec) failed: %s - (Are you missing data?) \n " , u_errorName ( ec ) ) ;
return ;
}
2013-01-04 17:16:07 +00:00
udat_applyPattern ( simpleDateFormat , 0 , pattern , u_strlen ( pattern ) ) ;
udat_setLenient ( simpleDateFormat , 0 ) ;
currentTwoDigitYear = getCurrentYear ( ) % 100 ;
startCentury = getCurrentYear ( ) - currentTwoDigitYear ;
if ( twoDigitCenturyStart > currentTwoDigitYear ) {
2013-09-12 01:27:29 +00:00
startCentury - = 100 ;
2013-01-04 17:16:07 +00:00
}
2013-09-12 01:27:29 +00:00
tempCal = ucal_open ( NULL , - 1 , NULL , UCAL_GREGORIAN , & ec ) ;
ucal_setMillis ( tempCal , 0 , & ec ) ;
ucal_setDateTime ( tempCal , startCentury + twoDigitCenturyStart , UCAL_JANUARY , 1 , 0 , 0 , 0 , & ec ) ;
udat_set2DigitYearStart ( simpleDateFormat , ucal_getMillis ( tempCal , & ec ) , & ec ) ;
2013-01-04 17:16:07 +00:00
2013-09-12 01:27:29 +00:00
calendar = ucal_open ( NULL , - 1 , NULL , UCAL_GREGORIAN , & ec ) ;
ucal_setMillis ( calendar , 0 , & ec ) ;
ucal_setDateTime ( calendar , twoDigitCenturyStart , UCAL_JANUARY , 1 , 0 , 0 , 0 , & ec ) ;
2013-01-04 17:16:07 +00:00
2013-09-12 01:27:29 +00:00
udat_parseCalendar ( simpleDateFormat , calendar , text , u_strlen ( text ) , & parsePos , & ec ) ;
2013-01-04 17:16:07 +00:00
/* Check result */
result = ucal_get ( calendar , UCAL_YEAR , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: ucal_get(UCAL_YEAR) failed with %s \n " , u_errorName ( ec ) ) ;
goto FAIL ;
}
if ( result ! = 75 ) {
log_err ( " FAIL: parsed incorrect year: %d \n " , result ) ;
goto FAIL ;
}
parsePos = 0 ;
udat_applyPattern ( simpleDateFormat , 0 , pattern2 , u_strlen ( pattern2 ) ) ;
2013-09-12 01:27:29 +00:00
udat_parseCalendar ( simpleDateFormat , calendar , text , u_strlen ( text ) , & parsePos , & ec ) ;
2013-01-04 17:16:07 +00:00
/* Check result */
result = ucal_get ( calendar , UCAL_YEAR , & ec ) ;
if ( U_FAILURE ( ec ) ) {
log_err ( " FAIL: ucal_get(UCAL_YEAR) failed with %s \n " , u_errorName ( ec ) ) ;
goto FAIL ;
}
if ( result ! = 1975 ) {
log_err ( " FAIL: parsed incorrect year: %d \n " , result ) ;
goto FAIL ;
}
FAIL :
udat_close ( simpleDateFormat ) ;
udat_close ( tempCal ) ;
udat_close ( calendar ) ;
}
1999-08-16 21:50:52 +00:00
/*INTERNAL FUNCTIONS USED*/
2013-01-04 17:16:07 +00:00
static int getCurrentYear ( ) {
static int currentYear = 0 ;
if ( currentYear = = 0 ) {
UErrorCode status = U_ZERO_ERROR ;
UCalendar * cal = ucal_open ( NULL , - 1 , NULL , UCAL_GREGORIAN , & status ) ;
if ( ! U_FAILURE ( status ) ) {
/* Get the current year from the default UCalendar */
currentYear = ucal_get ( cal , UCAL_YEAR , & status ) ;
ucal_close ( cal ) ;
}
}
return currentYear ;
}
2009-02-14 02:29:08 +00:00
/* N.B.: use idx instead of index to avoid 'shadow' warnings in strict mode. */
static void VerifygetSymbols ( UDateFormat * datfor , UDateFormatSymbolType type , int32_t idx , const char * expected )
1999-08-16 21:50:52 +00:00
{
2000-08-14 17:13:09 +00:00
UChar * pattern = NULL ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2000-08-14 17:13:09 +00:00
UChar * result = NULL ;
1999-08-16 21:50:52 +00:00
int32_t resultlength , resultlengthout ;
2014-09-08 04:52:23 +00:00
int32_t patternSize = strlen ( expected ) + 1 ;
1999-08-16 21:50:52 +00:00
2014-09-08 04:52:23 +00:00
pattern = ( UChar * ) malloc ( sizeof ( UChar ) * patternSize ) ;
u_unescape ( expected , pattern , patternSize ) ;
1999-08-16 21:50:52 +00:00
resultlength = 0 ;
2009-02-14 02:29:08 +00:00
resultlengthout = udat_getSymbols ( datfor , type , idx , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
2009-02-14 02:29:08 +00:00
udat_getSymbols ( datfor , type , idx , result , resultlength , & status ) ;
1999-08-16 21:50:52 +00:00
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in udat_getSymbols()... %s \n " , myErrorName ( status ) ) ;
return ;
}
if ( u_strcmp ( result , pattern ) = = 0 )
log_verbose ( " PASS: getSymbols retrieved the right value \n " ) ;
else {
2014-09-08 04:52:23 +00:00
log_data_err ( " FAIL: getSymbols retrieved the wrong value \n Expected %s Got %s \n " , expected ,
aescstrdup ( result , - 1 ) ) ;
1999-08-16 21:50:52 +00:00
}
2002-07-29 21:04:18 +00:00
free ( result ) ;
free ( pattern ) ;
1999-08-16 21:50:52 +00:00
}
2009-02-14 02:29:08 +00:00
static void VerifysetSymbols ( UDateFormat * datfor , UDateFormatSymbolType type , int32_t idx , const char * expected )
1999-08-16 21:50:52 +00:00
{
2000-08-14 17:13:09 +00:00
UChar * result = NULL ;
UChar * value = NULL ;
1999-08-16 21:50:52 +00:00
int32_t resultlength , resultlengthout ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
2014-09-08 04:52:23 +00:00
int32_t valueLen , valueSize = strlen ( expected ) + 1 ;
1999-08-16 21:50:52 +00:00
2014-09-08 04:52:23 +00:00
value = ( UChar * ) malloc ( sizeof ( UChar ) * valueSize ) ;
valueLen = u_unescape ( expected , value , valueSize ) ;
udat_setSymbols ( datfor , type , idx , value , valueLen , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in udat_setSymbols() %s \n " , myErrorName ( status ) ) ;
return ;
}
resultlength = 0 ;
2009-02-14 02:29:08 +00:00
resultlengthout = udat_getSymbols ( datfor , type , idx , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR ) {
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
2009-02-14 02:29:08 +00:00
udat_getSymbols ( datfor , type , idx , result , resultlength , & status ) ;
1999-08-16 21:50:52 +00:00
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
log_err ( " FAIL: error in retrieving the value using getSymbols after setting it previously \n %s \n " ,
myErrorName ( status ) ) ;
return ;
}
if ( u_strcmp ( result , value ) ! = 0 ) {
2014-09-08 04:52:23 +00:00
log_err ( " FAIL:Error in setting and then getting symbols \n Expected %s Got %s \n " , expected ,
aescstrdup ( result , - 1 ) ) ;
1999-08-16 21:50:52 +00:00
}
else
log_verbose ( " PASS: setSymbols successful \n " ) ;
2002-07-29 21:04:18 +00:00
free ( value ) ;
free ( result ) ;
1999-08-16 21:50:52 +00:00
}
2009-02-14 02:29:08 +00:00
static void VerifygetsetSymbols ( UDateFormat * from , UDateFormat * to , UDateFormatSymbolType type , int32_t idx )
1999-08-16 21:50:52 +00:00
{
2000-08-14 17:13:09 +00:00
UChar * result = NULL ;
UChar * value = NULL ;
1999-08-16 21:50:52 +00:00
int32_t resultlength , resultlengthout ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = 0 ;
2009-02-14 02:29:08 +00:00
resultlengthout = udat_getSymbols ( from , type , idx , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR ) {
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2002-07-29 21:04:18 +00:00
result = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
2009-02-14 02:29:08 +00:00
udat_getSymbols ( from , type , idx , result , resultlength , & status ) ;
1999-08-16 21:50:52 +00:00
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
log_err ( " FAIL: error in getSymbols() %s \n " , myErrorName ( status ) ) ;
return ;
}
resultlength = resultlengthout + 1 ;
2009-02-14 02:29:08 +00:00
udat_setSymbols ( to , type , idx , result , resultlength , & status ) ;
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in udat_setSymbols() : %s \n " , myErrorName ( status ) ) ;
return ;
}
resultlength = 0 ;
2009-02-14 02:29:08 +00:00
resultlengthout = udat_getSymbols ( to , type , idx , NULL , resultlength , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR ) {
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthout + 1 ;
2002-07-29 21:04:18 +00:00
value = ( UChar * ) malloc ( sizeof ( UChar ) * resultlength ) ;
2009-02-14 02:29:08 +00:00
udat_getSymbols ( to , type , idx , value , resultlength , & status ) ;
1999-08-16 21:50:52 +00:00
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) ) {
1999-08-16 21:50:52 +00:00
log_err ( " FAIL: error in retrieving the value using getSymbols i.e roundtrip \n %s \n " ,
myErrorName ( status ) ) ;
return ;
}
if ( u_strcmp ( result , value ) ! = 0 ) {
2002-09-17 19:45:50 +00:00
log_data_err ( " FAIL:Error in setting and then getting symbols \n Expected %s Got %s \n " , austrdup ( result ) ,
1999-08-16 21:50:52 +00:00
austrdup ( value ) ) ;
}
else
log_verbose ( " PASS: setSymbols successful \n " ) ;
2002-07-29 21:04:18 +00:00
free ( value ) ;
free ( result ) ;
1999-08-16 21:50:52 +00:00
}
2000-11-21 04:05:39 +00:00
static UChar * myNumformat ( const UNumberFormat * numfor , double d )
1999-08-16 21:50:52 +00:00
{
2000-08-14 17:13:09 +00:00
UChar * result2 = NULL ;
1999-08-16 21:50:52 +00:00
int32_t resultlength , resultlengthneeded ;
1999-10-07 00:07:53 +00:00
UErrorCode status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = 0 ;
2001-03-08 23:41:16 +00:00
resultlengthneeded = unum_formatDouble ( numfor , d , NULL , resultlength , NULL , & status ) ;
1999-10-07 00:07:53 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR )
1999-08-16 21:50:52 +00:00
{
1999-10-07 00:07:53 +00:00
status = U_ZERO_ERROR ;
1999-08-16 21:50:52 +00:00
resultlength = resultlengthneeded + 1 ;
2000-07-06 23:01:50 +00:00
/*result2=(UChar*)malloc(sizeof(UChar) * resultlength);*/ /* this leaks */
result2 = ( UChar * ) ctst_malloc ( sizeof ( UChar ) * resultlength ) ; /*this won't*/
2001-03-08 23:41:16 +00:00
unum_formatDouble ( numfor , d , result2 , resultlength , NULL , & status ) ;
1999-08-16 21:50:52 +00:00
}
1999-10-18 22:48:32 +00:00
if ( U_FAILURE ( status ) )
1999-08-16 21:50:52 +00:00
{
log_err ( " FAIL: Error in formatting using unum_format(.....) %s \n " , myErrorName ( status ) ) ;
return 0 ;
}
return result2 ;
}
2002-09-20 17:54:45 +00:00
2004-05-21 20:25:52 +00:00
/**
* The search depth for TestExtremeDates . The total number of
* dates that will be tested is ( 2 ^ EXTREME_DATES_DEPTH ) - 1.
*/
# define EXTREME_DATES_DEPTH 8
/**
* Support for TestExtremeDates ( below ) .
*
* Test a single date to see whether udat_format handles it properly .
*/
static UBool _aux1ExtremeDates ( UDateFormat * fmt , UDate date ,
UChar * buf , int32_t buflen , char * cbuf ,
UErrorCode * ec ) {
int32_t len = udat_format ( fmt , date , buf , buflen , 0 , ec ) ;
if ( ! assertSuccess ( " udat_format " , ec ) ) return FALSE ;
u_austrncpy ( cbuf , buf , buflen ) ;
if ( len < 4 ) {
log_err ( " FAIL: udat_format(%g) => \" %s \" \n " , date , cbuf ) ;
} else {
log_verbose ( " udat_format(%g) => \" %s \" \n " , date , cbuf ) ;
}
return TRUE ;
}
/**
* Support for TestExtremeDates ( below ) .
*
* Recursively test between ' small ' and ' large ' , up to the depth
* limit specified by EXTREME_DATES_DEPTH .
*/
static UBool _aux2ExtremeDates ( UDateFormat * fmt , UDate small , UDate large ,
UChar * buf , int32_t buflen , char * cbuf ,
int32_t count ,
UErrorCode * ec ) {
/* Logarithmic midpoint; see below */
UDate mid = ( UDate ) exp ( ( log ( small ) + log ( large ) ) / 2 ) ;
if ( count = = EXTREME_DATES_DEPTH ) {
return TRUE ;
}
return
_aux1ExtremeDates ( fmt , mid , buf , buflen , cbuf , ec ) & &
_aux2ExtremeDates ( fmt , small , mid , buf , buflen , cbuf , count + 1 , ec ) & &
_aux2ExtremeDates ( fmt , mid , large , buf , buflen , cbuf , count + 1 , ec ) ;
}
/**
* http : //www.jtcsv.com/cgibin/icu-bugs?findid=3659
*
* For certain large dates , udat_format crashes on MacOS . This test
* attempts to reproduce this problem by doing a recursive logarithmic *
* binary search of a predefined interval ( from ' small ' to ' large ' ) .
*
* The limit of the search is given by EXTREME_DATES_DEPTH , above .
*
* * The search has to be logarithmic , not linear . A linear search of the
* range 0. .10 ^ 30 , for example , will find 0.5 * 10 ^ 30 , then 0.25 * 10 ^ 30 and
* 0.75 * 10 ^ 30 , etc . A logarithmic search will find 10 ^ 15 , then 10 ^ 7.5
* and 10 ^ 22.5 , etc .
*/
static void TestExtremeDates ( ) {
UDateFormat * fmt ;
UErrorCode ec ;
UChar buf [ 256 ] ;
char cbuf [ 256 ] ;
const double small = 1000 ; /* 1 sec */
const double large = 1e+30 ; /* well beyond usable UDate range */
/* There is no need to test larger values from 1e+30 to 1e+300;
the failures occur around 1e+27 , and never above 1e+30 . */
ec = U_ZERO_ERROR ;
fmt = udat_open ( UDAT_LONG , UDAT_LONG , " en_US " ,
0 , 0 , 0 , 0 , & ec ) ;
2009-06-09 21:28:13 +00:00
if ( U_FAILURE ( ec ) ) {
log_data_err ( " FAIL: udat_open (%s) (Are you missing data?) \n " , u_errorName ( ec ) ) ;
return ;
}
2004-05-21 20:25:52 +00:00
_aux2ExtremeDates ( fmt , small , large , buf , LEN ( buf ) , cbuf , 0 , & ec ) ;
udat_close ( fmt ) ;
}
2005-06-30 05:10:59 +00:00
static void TestAllLocales ( void ) {
int32_t idx , dateIdx , timeIdx , localeCount ;
static const UDateFormatStyle style [ ] = {
UDAT_FULL , UDAT_LONG , UDAT_MEDIUM , UDAT_SHORT
} ;
localeCount = uloc_countAvailable ( ) ;
for ( idx = 0 ; idx < localeCount ; idx + + ) {
for ( dateIdx = 0 ; dateIdx < ( int32_t ) ( sizeof ( style ) / sizeof ( style [ 0 ] ) ) ; dateIdx + + ) {
for ( timeIdx = 0 ; timeIdx < ( int32_t ) ( sizeof ( style ) / sizeof ( style [ 0 ] ) ) ; timeIdx + + ) {
UErrorCode status = U_ZERO_ERROR ;
udat_close ( udat_open ( style [ dateIdx ] , style [ timeIdx ] ,
uloc_getAvailable ( idx ) , NULL , 0 , NULL , 0 , & status ) ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " FAIL: udat_open(%s) failed with (%s) dateIdx=%d, timeIdx=%d \n " ,
uloc_getAvailable ( idx ) , u_errorName ( status ) , dateIdx , timeIdx ) ;
}
}
}
}
}
2009-02-14 02:29:08 +00:00
static void TestRelativeCrash ( void ) {
static const UChar tzName [ ] = { 0x0055 , 0x0053 , 0x002F , 0x0050 , 0x0061 , 0x0063 , 0x0069 , 0x0066 , 0x0069 , 0x0063 , 0 } ;
static const UDate aDate = - 631152000000.0 ;
UErrorCode status = U_ZERO_ERROR ;
UErrorCode expectStatus = U_ILLEGAL_ARGUMENT_ERROR ;
UDateFormat icudf ;
icudf = udat_open ( UDAT_NONE , UDAT_SHORT_RELATIVE , " en " , tzName , - 1 , NULL , 0 , & status ) ;
if ( U_SUCCESS ( status ) ) {
const char * what = " ??? " ;
{
UErrorCode subStatus = U_ZERO_ERROR ;
what = " udat_set2DigitYearStart " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
udat_set2DigitYearStart ( icudf , aDate , & subStatus ) ;
if ( subStatus = = expectStatus ) {
log_verbose ( " Success: did not crash on %s, but got %s. \n " , what , u_errorName ( subStatus ) ) ;
} else {
log_err ( " FAIL: didn't crash on %s, but got success %s instead of %s. \n " , what , u_errorName ( subStatus ) , u_errorName ( expectStatus ) ) ;
}
}
{
/* clone works polymorphically. try it anyways */
UErrorCode subStatus = U_ZERO_ERROR ;
UDateFormat * oth ;
what = " clone " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
oth = udat_clone ( icudf , & subStatus ) ;
if ( subStatus = = U_ZERO_ERROR ) {
log_verbose ( " Success: did not crash on %s, but got %s. \n " , what , u_errorName ( subStatus ) ) ;
udat_close ( oth ) ; /* ? */
} else {
log_err ( " FAIL: didn't crash on %s, but got %s instead of %s. \n " , what , u_errorName ( subStatus ) , u_errorName ( expectStatus ) ) ;
}
}
{
UErrorCode subStatus = U_ZERO_ERROR ;
what = " udat_get2DigitYearStart " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
udat_get2DigitYearStart ( icudf , & subStatus ) ;
if ( subStatus = = expectStatus ) {
log_verbose ( " Success: did not crash on %s, but got %s. \n " , what , u_errorName ( subStatus ) ) ;
} else {
log_err ( " FAIL: didn't crash on %s, but got success %s instead of %s. \n " , what , u_errorName ( subStatus ) , u_errorName ( expectStatus ) ) ;
}
}
{
2009-04-18 08:11:19 +00:00
/* Now udat_toPattern works for relative date formatters, unless localized is TRUE */
2009-02-14 02:29:08 +00:00
UErrorCode subStatus = U_ZERO_ERROR ;
what = " udat_toPattern " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
2009-04-18 08:11:19 +00:00
udat_toPattern ( icudf , TRUE , NULL , 0 , & subStatus ) ;
2009-02-14 02:29:08 +00:00
if ( subStatus = = expectStatus ) {
log_verbose ( " Success: did not crash on %s, but got %s. \n " , what , u_errorName ( subStatus ) ) ;
} else {
log_err ( " FAIL: didn't crash on %s, but got success %s instead of %s. \n " , what , u_errorName ( subStatus ) , u_errorName ( expectStatus ) ) ;
}
}
{
UErrorCode subStatus = U_ZERO_ERROR ;
what = " udat_applyPattern " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
udat_applyPattern ( icudf , FALSE , tzName , - 1 ) ;
subStatus = U_ILLEGAL_ARGUMENT_ERROR ; /* what it should be, if this took an errorcode. */
if ( subStatus = = expectStatus ) {
log_verbose ( " Success: did not crash on %s, but got %s. \n " , what , u_errorName ( subStatus ) ) ;
} else {
log_err ( " FAIL: didn't crash on %s, but got success %s instead of %s. \n " , what , u_errorName ( subStatus ) , u_errorName ( expectStatus ) ) ;
}
}
{
2012-10-15 23:32:31 +00:00
UChar erabuf [ 32 ] ;
2009-02-14 02:29:08 +00:00
UErrorCode subStatus = U_ZERO_ERROR ;
what = " udat_getSymbols " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
2011-05-02 23:14:32 +00:00
udat_getSymbols ( icudf , UDAT_ERAS , 0 , erabuf , sizeof ( erabuf ) / sizeof ( erabuf [ 0 ] ) , & subStatus ) ;
if ( subStatus = = U_ZERO_ERROR ) {
log_verbose ( " Success: %s returned %s. \n " , what , u_errorName ( subStatus ) ) ;
2009-02-14 02:29:08 +00:00
} else {
2011-05-02 23:14:32 +00:00
log_err ( " FAIL: didn't crash on %s, but got %s instead of U_ZERO_ERROR. \n " , what , u_errorName ( subStatus ) ) ;
2010-05-13 03:35:54 +00:00
}
}
{
UErrorCode subStatus = U_ZERO_ERROR ;
UChar symbolValue = 0x0041 ;
what = " udat_setSymbols " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
udat_setSymbols ( icudf , UDAT_ERAS , 0 , & symbolValue , 1 , & subStatus ) ; /* bogus values */
if ( subStatus = = expectStatus ) {
log_verbose ( " Success: did not crash on %s, but got %s. \n " , what , u_errorName ( subStatus ) ) ;
} else {
log_err ( " FAIL: didn't crash on %s, but got success %s instead of %s. \n " , what , u_errorName ( subStatus ) , u_errorName ( expectStatus ) ) ;
2009-02-14 02:29:08 +00:00
}
}
{
UErrorCode subStatus = U_ZERO_ERROR ;
what = " udat_countSymbols " ;
log_verbose ( " Trying %s on a relative date.. \n " , what ) ;
udat_countSymbols ( icudf , UDAT_ERAS ) ;
subStatus = U_ILLEGAL_ARGUMENT_ERROR ; /* should have an errorcode. */
if ( subStatus = = expectStatus ) {
log_verbose ( " Success: did not crash on %s, but got %s. \n " , what , u_errorName ( subStatus ) ) ;
} else {
log_err ( " FAIL: didn't crash on %s, but got success %s instead of %s. \n " , what , u_errorName ( subStatus ) , u_errorName ( expectStatus ) ) ;
}
}
udat_close ( icudf ) ;
} else {
2009-06-09 21:28:13 +00:00
log_data_err ( " FAIL: err calling udat_open() ->%s (Are you missing data?) \n " , u_errorName ( status ) ) ;
2009-02-14 02:29:08 +00:00
}
}
2012-02-21 09:19:57 +00:00
static const UChar skeleton_yMMMM [ ] = { 0x79 , 0x4D , 0x4D , 0x4D , 0x4D , 0 } ; /* "yMMMM"; fr maps to "MMMM y", cs maps to "LLLL y" */
static const UChar july2008_frDefault [ ] = { 0x6A , 0x75 , 0x69 , 0x6C , 0x6C , 0x65 , 0x74 , 0x20 , 0x32 , 0x30 , 0x30 , 0x38 , 0 } ; /* "juillet 2008" */
static const UChar july2008_frTitle [ ] = { 0x4A , 0x75 , 0x69 , 0x6C , 0x6C , 0x65 , 0x74 , 0x20 , 0x32 , 0x30 , 0x30 , 0x38 , 0 } ; /* "Juillet 2008" sentence-begin, standalone */
static const UChar july2008_csDefault [ ] = { 0x10D , 0x65 , 0x72 , 0x76 , 0x65 , 0x6E , 0x65 , 0x63 , 0x20 , 0x32 , 0x30 , 0x30 , 0x38 , 0 } ; /* "c(hacek)ervenec 2008" */
static const UChar july2008_csTitle [ ] = { 0x10C , 0x65 , 0x72 , 0x76 , 0x65 , 0x6E , 0x65 , 0x63 , 0x20 , 0x32 , 0x30 , 0x30 , 0x38 , 0 } ; /* "C(hacek)ervenec 2008" sentence-begin, uiListOrMenu */
typedef struct {
const char * locale ;
const UChar * skeleton ;
2012-10-08 16:52:35 +00:00
UDisplayContext capitalizationContext ;
2012-02-21 09:19:57 +00:00
const UChar * expectedFormat ;
} TestContextItem ;
static const TestContextItem textContextItems [ ] = {
2012-10-08 16:52:35 +00:00
{ " fr " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_NONE , july2008_frDefault } ,
2012-03-02 17:59:56 +00:00
# if !UCONFIG_NO_BREAK_ITERATION
2012-10-08 16:52:35 +00:00
{ " fr " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , july2008_frDefault } ,
{ " fr " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , july2008_frTitle } ,
{ " fr " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , july2008_frDefault } ,
{ " fr " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , july2008_frTitle } ,
2012-03-02 17:59:56 +00:00
# endif
2012-10-08 16:52:35 +00:00
{ " cs " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_NONE , july2008_csDefault } ,
2012-03-02 17:59:56 +00:00
# if !UCONFIG_NO_BREAK_ITERATION
2012-10-08 16:52:35 +00:00
{ " cs " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , july2008_csDefault } ,
{ " cs " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , july2008_csTitle } ,
{ " cs " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , july2008_csTitle } ,
{ " cs " , skeleton_yMMMM , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , july2008_csDefault } ,
2012-03-02 17:59:56 +00:00
# endif
2012-10-08 16:52:35 +00:00
{ NULL , NULL , ( UDisplayContext ) 0 , NULL }
2012-02-21 09:19:57 +00:00
} ;
2013-12-09 06:20:23 +00:00
static const UChar today_enDefault [ ] = { 0x74 , 0x6F , 0x64 , 0x61 , 0x79 , 0 } ; /* "today" */
static const UChar today_enTitle [ ] = { 0x54 , 0x6F , 0x64 , 0x61 , 0x79 , 0 } ; /* "Today" sentence-begin, uiListOrMenu, standalone */
static const UChar yesterday_enDefault [ ] = { 0x79 , 0x65 , 0x73 , 0x74 , 0x65 , 0x72 , 0x64 , 0x61 , 0x79 , 0 } ; /* "yesterday" */
static const UChar yesterday_enTitle [ ] = { 0x59 , 0x65 , 0x73 , 0x74 , 0x65 , 0x72 , 0x64 , 0x61 , 0x79 , 0 } ; /* "Yesterday" sentence-begin, uiListOrMenu, standalone */
static const UChar today_nbDefault [ ] = { 0x69 , 0x20 , 0x64 , 0x61 , 0x67 , 0 } ; /* "i dag" */
static const UChar today_nbTitle [ ] = { 0x49 , 0x20 , 0x64 , 0x61 , 0x67 , 0 } ; /* "I dag" sentence-begin, standalone */
2014-01-21 20:58:03 +00:00
static const UChar yesterday_nbDefault [ ] = { 0x69 , 0x20 , 0x67 , 0xE5 , 0x72 , 0 } ;
static const UChar yesterday_nbTitle [ ] = { 0x49 , 0x20 , 0x67 , 0xE5 , 0x72 , 0 } ;
2013-12-09 06:20:23 +00:00
typedef struct {
const char * locale ;
UDisplayContext capitalizationContext ;
const UChar * expectedFormatToday ;
const UChar * expectedFormatYesterday ;
} TestRelativeContextItem ;
static const TestRelativeContextItem textContextRelativeItems [ ] = {
{ " en " , UDISPCTX_CAPITALIZATION_NONE , today_enDefault , yesterday_enDefault } ,
# if !UCONFIG_NO_BREAK_ITERATION
{ " en " , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , today_enDefault , yesterday_enDefault } ,
{ " en " , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , today_enTitle , yesterday_enTitle } ,
{ " en " , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , today_enTitle , yesterday_enTitle } ,
{ " en " , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , today_enTitle , yesterday_enTitle } ,
# endif
{ " nb " , UDISPCTX_CAPITALIZATION_NONE , today_nbDefault , yesterday_nbDefault } ,
# if !UCONFIG_NO_BREAK_ITERATION
{ " nb " , UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE , today_nbDefault , yesterday_nbDefault } ,
{ " nb " , UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE , today_nbTitle , yesterday_nbTitle } ,
{ " nb " , UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU , today_nbDefault , yesterday_nbDefault } ,
{ " nb " , UDISPCTX_CAPITALIZATION_FOR_STANDALONE , today_nbTitle , yesterday_nbTitle } ,
# endif
{ NULL , ( UDisplayContext ) 0 , NULL , NULL }
} ;
static const UChar zoneGMT [ ] = { 0x47 , 0x4D , 0x54 , 0 } ; /* "GMT" */
static const UDate july022008 = 1215000000000.0 ;
2012-02-21 09:19:57 +00:00
enum { kUbufMax = 64 , kBbufMax = 3 * kUbufMax } ;
static void TestContext ( void ) {
2013-12-09 06:20:23 +00:00
const TestContextItem * textContextItemPtr ;
const TestRelativeContextItem * textRelContextItemPtr ;
for ( textContextItemPtr = textContextItems ; textContextItemPtr - > locale ! = NULL ; + + textContextItemPtr ) {
2012-02-21 09:19:57 +00:00
UErrorCode status = U_ZERO_ERROR ;
2013-12-09 06:20:23 +00:00
UDateTimePatternGenerator * udtpg = udatpg_open ( textContextItemPtr - > locale , & status ) ;
if ( U_SUCCESS ( status ) ) {
UChar ubuf [ kUbufMax ] ;
int32_t len = udatpg_getBestPattern ( udtpg , textContextItemPtr - > skeleton , - 1 , ubuf , kUbufMax , & status ) ;
if ( U_SUCCESS ( status ) ) {
UDateFormat * udfmt = udat_open ( UDAT_PATTERN , UDAT_PATTERN , textContextItemPtr - > locale , zoneGMT , - 1 , ubuf , len , & status ) ;
if ( U_SUCCESS ( status ) ) {
2012-10-08 16:52:35 +00:00
udat_setContext ( udfmt , textContextItemPtr - > capitalizationContext , & status ) ;
2013-12-09 06:20:23 +00:00
if ( U_SUCCESS ( status ) ) {
2012-10-08 16:52:35 +00:00
UDisplayContext getContext ;
2012-02-21 09:19:57 +00:00
len = udat_format ( udfmt , july022008 , ubuf , kUbufMax , NULL , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " FAIL: udat_format for locale %s, capitalizationContext %d, status %s \n " ,
textContextItemPtr - > locale , ( int ) textContextItemPtr - > capitalizationContext , u_errorName ( status ) ) ;
status = U_ZERO_ERROR ;
} else if ( u_strncmp ( ubuf , textContextItemPtr - > expectedFormat , kUbufMax ) ! = 0 ) {
char bbuf1 [ kBbufMax ] ;
char bbuf2 [ kBbufMax ] ;
log_err ( " FAIL: udat_format for locale %s, capitalizationContext %d, expected %s, got %s \n " ,
textContextItemPtr - > locale , ( int ) textContextItemPtr - > capitalizationContext ,
u_austrncpy ( bbuf1 , textContextItemPtr - > expectedFormat , kUbufMax ) , u_austrncpy ( bbuf2 , ubuf , kUbufMax ) ) ;
}
2012-10-08 16:52:35 +00:00
getContext = udat_getContext ( udfmt , UDISPCTX_TYPE_CAPITALIZATION , & status ) ;
2012-02-21 09:19:57 +00:00
if ( U_FAILURE ( status ) ) {
2012-10-08 16:52:35 +00:00
log_err ( " FAIL: udat_getContext for locale %s, capitalizationContext %d, status %s \n " ,
2012-02-21 09:19:57 +00:00
textContextItemPtr - > locale , ( int ) textContextItemPtr - > capitalizationContext , u_errorName ( status ) ) ;
2012-10-08 16:52:35 +00:00
} else if ( getContext ! = textContextItemPtr - > capitalizationContext ) {
log_err ( " FAIL: udat_getContext for locale %s, capitalizationContext %d, got context %d \n " ,
textContextItemPtr - > locale , ( int ) textContextItemPtr - > capitalizationContext , ( int ) getContext ) ;
2012-02-21 09:19:57 +00:00
}
2013-12-09 06:20:23 +00:00
} else {
log_err ( " FAIL: udat_setContext for locale %s, capitalizationContext %d, status %s \n " ,
textContextItemPtr - > locale , ( int ) textContextItemPtr - > capitalizationContext , u_errorName ( status ) ) ;
2012-02-21 09:19:57 +00:00
}
2013-12-09 06:20:23 +00:00
udat_close ( udfmt ) ;
} else {
log_data_err ( " FAIL: udat_open for locale %s, status %s \n " , textContextItemPtr - > locale , u_errorName ( status ) ) ;
2012-02-21 09:19:57 +00:00
}
2013-12-09 06:20:23 +00:00
} else {
log_err ( " FAIL: udatpg_getBestPattern for locale %s, status %s \n " , textContextItemPtr - > locale , u_errorName ( status ) ) ;
2012-02-21 09:19:57 +00:00
}
2013-12-09 06:20:23 +00:00
udatpg_close ( udtpg ) ;
} else {
2014-01-22 21:20:24 +00:00
log_data_err ( " FAIL: udatpg_open for locale %s, status %s \n " , textContextItemPtr - > locale , u_errorName ( status ) ) ;
2013-12-09 06:20:23 +00:00
}
}
for ( textRelContextItemPtr = textContextRelativeItems ; textRelContextItemPtr - > locale ! = NULL ; + + textRelContextItemPtr ) {
UErrorCode status = U_ZERO_ERROR ;
UCalendar * ucal = ucal_open ( zoneGMT , - 1 , " root " , UCAL_GREGORIAN , & status ) ;
if ( U_SUCCESS ( status ) ) {
UDateFormat * udfmt = udat_open ( UDAT_NONE , UDAT_LONG_RELATIVE , textRelContextItemPtr - > locale , zoneGMT , - 1 , NULL , 0 , & status ) ;
if ( U_SUCCESS ( status ) ) {
udat_setContext ( udfmt , textRelContextItemPtr - > capitalizationContext , & status ) ;
if ( U_SUCCESS ( status ) ) {
2013-12-09 18:06:56 +00:00
UDate yesterday , today = ucal_getNow ( ) ;
UChar ubuf [ kUbufMax ] ;
char bbuf1 [ kBbufMax ] ;
char bbuf2 [ kBbufMax ] ;
int32_t len = udat_format ( udfmt , today , ubuf , kUbufMax , NULL , & status ) ;
2014-01-10 08:35:00 +00:00
( void ) len ;
2013-12-09 18:06:56 +00:00
if ( U_FAILURE ( status ) ) {
log_err ( " FAIL: udat_format today for locale %s, capitalizationContext %d, status %s \n " ,
textRelContextItemPtr - > locale , ( int ) textRelContextItemPtr - > capitalizationContext , u_errorName ( status ) ) ;
} else if ( u_strncmp ( ubuf , textRelContextItemPtr - > expectedFormatToday , kUbufMax ) ! = 0 ) {
log_err ( " FAIL: udat_format today for locale %s, capitalizationContext %d, expected %s, got %s \n " ,
textRelContextItemPtr - > locale , ( int ) textRelContextItemPtr - > capitalizationContext ,
u_austrncpy ( bbuf1 , textRelContextItemPtr - > expectedFormatToday , kUbufMax ) , u_austrncpy ( bbuf2 , ubuf , kUbufMax ) ) ;
}
status = U_ZERO_ERROR ;
ucal_setMillis ( ucal , today , & status ) ;
ucal_add ( ucal , UCAL_DATE , - 1 , & status ) ;
yesterday = ucal_getMillis ( ucal , & status ) ;
if ( U_SUCCESS ( status ) ) {
len = udat_format ( udfmt , yesterday , ubuf , kUbufMax , NULL , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " FAIL: udat_format yesterday for locale %s, capitalizationContext %d, status %s \n " ,
textRelContextItemPtr - > locale , ( int ) textRelContextItemPtr - > capitalizationContext , u_errorName ( status ) ) ;
} else if ( u_strncmp ( ubuf , textRelContextItemPtr - > expectedFormatYesterday , kUbufMax ) ! = 0 ) {
log_err ( " FAIL: udat_format yesterday for locale %s, capitalizationContext %d, expected %s, got %s \n " ,
textRelContextItemPtr - > locale , ( int ) textRelContextItemPtr - > capitalizationContext ,
u_austrncpy ( bbuf1 , textRelContextItemPtr - > expectedFormatYesterday , kUbufMax ) , u_austrncpy ( bbuf2 , ubuf , kUbufMax ) ) ;
}
}
2013-12-09 06:20:23 +00:00
} else {
log_err ( " FAIL: udat_setContext relative for locale %s, capitalizationContext %d, status %s \n " ,
textRelContextItemPtr - > locale , ( int ) textRelContextItemPtr - > capitalizationContext , u_errorName ( status ) ) ;
}
2013-12-09 18:06:56 +00:00
udat_close ( udfmt ) ;
2013-12-09 06:20:23 +00:00
} else {
log_data_err ( " FAIL: udat_open relative for locale %s, status %s \n " , textRelContextItemPtr - > locale , u_errorName ( status ) ) ;
}
ucal_close ( ucal ) ;
} else {
log_data_err ( " FAIL: ucal_open for locale root, status %s \n " , u_errorName ( status ) ) ;
2012-02-21 09:19:57 +00:00
}
}
}
2014-07-29 18:42:07 +00:00
// overrideNumberFormat[i][0] is to tell which field to set,
// overrideNumberFormat[i][1] is the expected result
static const char * overrideNumberFormat [ ] [ 2 ] = {
{ " " , " \\ u521D \\ u4E03 \\ u521D \\ u4E8C " } ,
{ " d " , " 07 \\ u521D \\ u4E8C " } ,
{ " do " , " 07 \\ u521D \\ u4E8C " } ,
{ " Md " , " \\ u521D \\ u4E03 \\ u521D \\ u4E8C " } ,
{ " MdMMd " , " \\ u521D \\ u4E03 \\ u521D \\ u4E8C " } ,
{ " mixed " , " \\ u521D \\ u4E03 \\ u521D \\ u4E8C " }
} ;
2014-08-01 21:33:16 +00:00
static void TestOverrideNumberFormat ( void ) {
2014-07-29 18:42:07 +00:00
UErrorCode status = U_ZERO_ERROR ;
UChar pattern [ 50 ] ;
2015-01-12 15:51:02 +00:00
UChar expected [ 50 ] ;
UChar fields [ 50 ] ;
2014-07-29 18:42:07 +00:00
char bbuf1 [ kBbufMax ] ;
char bbuf2 [ kBbufMax ] ;
const char * localeString = " zh@numbers=hanidays " ;
UDateFormat * fmt ;
const UNumberFormat * getter_result ;
int32_t i ;
u_uastrcpy ( fields , " d " ) ;
u_uastrcpy ( pattern , " MM d " ) ;
2015-01-12 16:34:01 +00:00
fmt = udat_open ( UDAT_PATTERN , UDAT_PATTERN , " en_US " , zoneGMT , - 1 , pattern , u_strlen ( pattern ) , & status ) ;
2014-09-16 23:46:35 +00:00
if ( ! assertSuccess ( " udat_open() " , & status ) ) {
return ;
}
2014-11-18 00:43:49 +00:00
// loop 5 times to check getter/setter
2014-09-16 23:46:35 +00:00
for ( i = 0 ; i < 5 ; i + + ) {
UNumberFormat * overrideFmt ;
overrideFmt = unum_open ( UNUM_DEFAULT , NULL , 0 , localeString , NULL , & status ) ;
assertSuccess ( " unum_open() " , & status ) ;
2014-07-29 18:42:07 +00:00
udat_adoptNumberFormatForFields ( fmt , fields , overrideFmt , & status ) ;
2014-09-16 23:46:35 +00:00
overrideFmt = NULL ; // no longer valid
2014-07-29 18:42:07 +00:00
assertSuccess ( " udat_setNumberFormatForField() " , & status ) ;
getter_result = udat_getNumberFormatForField ( fmt , ' d ' ) ;
2014-09-16 23:46:35 +00:00
if ( getter_result = = NULL ) {
log_err ( " FAIL: udat_getNumberFormatForField did not return a valid pointer \n " ) ;
}
}
{
UNumberFormat * overrideFmt ;
overrideFmt = unum_open ( UNUM_DEFAULT , NULL , 0 , localeString , NULL , & status ) ;
assertSuccess ( " unum_open() " , & status ) ;
udat_setNumberFormat ( fmt , overrideFmt ) ; // test the same override NF will not crash
2014-09-17 20:31:45 +00:00
unum_close ( overrideFmt ) ;
2014-07-29 18:42:07 +00:00
}
udat_close ( fmt ) ;
2014-12-19 21:03:23 +00:00
for ( i = 0 ; i < UPRV_LENGTHOF ( overrideNumberFormat ) ; i + + ) {
2014-07-29 18:42:07 +00:00
UChar ubuf [ kUbufMax ] ;
2014-08-01 21:33:16 +00:00
UDateFormat * fmt2 ;
UNumberFormat * overrideFmt2 ;
2014-07-29 18:42:07 +00:00
2015-01-12 16:34:01 +00:00
fmt2 = udat_open ( UDAT_PATTERN , UDAT_PATTERN , " en_US " , zoneGMT , - 1 , pattern , u_strlen ( pattern ) , & status ) ;
2014-07-29 18:42:07 +00:00
assertSuccess ( " udat_open() with en_US " , & status ) ;
2014-08-01 21:33:16 +00:00
overrideFmt2 = unum_open ( UNUM_DEFAULT , NULL , 0 , localeString , NULL , & status ) ;
2014-07-29 18:42:07 +00:00
assertSuccess ( " unum_open() in loop " , & status ) ;
u_uastrcpy ( fields , overrideNumberFormat [ i ] [ 0 ] ) ;
2015-01-12 15:51:02 +00:00
u_unescape ( overrideNumberFormat [ i ] [ 1 ] , expected , UPRV_LENGTHOF ( expected ) ) ;
2014-07-29 18:42:07 +00:00
2014-08-01 21:33:16 +00:00
if ( strcmp ( overrideNumberFormat [ i ] [ 0 ] , " " ) = = 0 ) { // use the one w/o field
2015-01-12 15:51:02 +00:00
udat_adoptNumberFormat ( fmt2 , overrideFmt2 ) ;
2014-08-01 21:33:16 +00:00
} else if ( strcmp ( overrideNumberFormat [ i ] [ 0 ] , " mixed " ) = = 0 ) { // set 1 field at first but then full override, both(M & d) should be override
2014-07-29 18:42:07 +00:00
const char * singleLocale = " en@numbers=hebr " ;
UNumberFormat * singleOverrideFmt ;
u_uastrcpy ( fields , " d " ) ;
singleOverrideFmt = unum_open ( UNUM_DEFAULT , NULL , 0 , singleLocale , NULL , & status ) ;
assertSuccess ( " unum_open() in mixed " , & status ) ;
2014-08-01 21:33:16 +00:00
udat_adoptNumberFormatForFields ( fmt2 , fields , singleOverrideFmt , & status ) ;
2014-07-29 18:42:07 +00:00
assertSuccess ( " udat_setNumberFormatForField() in mixed " , & status ) ;
2015-01-12 15:51:02 +00:00
udat_adoptNumberFormat ( fmt2 , overrideFmt2 ) ;
2014-08-01 21:33:16 +00:00
} else if ( strcmp ( overrideNumberFormat [ i ] [ 0 ] , " do " ) = = 0 ) { // o is an invalid field
udat_adoptNumberFormatForFields ( fmt2 , fields , overrideFmt2 , & status ) ;
2014-07-29 18:42:07 +00:00
if ( status = = U_INVALID_FORMAT_ERROR ) {
2014-08-01 21:33:16 +00:00
udat_close ( fmt2 ) ;
2014-07-29 18:42:07 +00:00
status = U_ZERO_ERROR ;
continue ;
}
} else {
2014-08-01 21:33:16 +00:00
udat_adoptNumberFormatForFields ( fmt2 , fields , overrideFmt2 , & status ) ;
2014-07-29 18:42:07 +00:00
assertSuccess ( " udat_setNumberFormatForField() in loop " , & status ) ;
}
2014-08-01 21:33:16 +00:00
udat_format ( fmt2 , july022008 , ubuf , kUbufMax , NULL , & status ) ;
2014-07-29 18:42:07 +00:00
assertSuccess ( " udat_format() july022008 " , & status ) ;
if ( u_strncmp ( ubuf , expected , kUbufMax ) ! = 0 )
log_err ( " fail: udat_format for locale, expected %s, got %s \n " ,
u_austrncpy ( bbuf1 , expected , kUbufMax ) , u_austrncpy ( bbuf2 , ubuf , kUbufMax ) ) ;
2014-08-01 21:33:16 +00:00
udat_close ( fmt2 ) ;
2014-07-29 18:42:07 +00:00
}
}
2015-02-11 22:23:13 +00:00
/*
* Ticket # 11523
* udat_parse and udat_parseCalendar should have the same error code when given the same invalid input .
*/
static void TestParseErrorReturnValue ( void ) {
UErrorCode status = U_ZERO_ERROR ;
UErrorCode expectStatus = U_PARSE_ERROR ;
UDateFormat * df ;
UCalendar * cal ;
df = udat_open ( UDAT_DEFAULT , UDAT_DEFAULT , NULL , NULL , - 1 , NULL , - 1 , & status ) ;
2015-03-11 21:09:25 +00:00
if ( ! assertSuccessCheck ( " udat_open() " , & status , TRUE ) ) {
2015-02-11 22:23:13 +00:00
return ;
}
cal = ucal_open ( NULL , 0 , " en_US " , UCAL_GREGORIAN , & status ) ;
if ( ! assertSuccess ( " ucal_open() " , & status ) ) {
return ;
}
udat_parse ( df , NULL , - 1 , NULL , & status ) ;
if ( status ! = expectStatus ) {
log_err ( " %s should have been returned by udat_parse when given an invalid input, instead got - %s \n " , u_errorName ( expectStatus ) , u_errorName ( status ) ) ;
}
status = U_ZERO_ERROR ;
udat_parseCalendar ( df , cal , NULL , - 1 , NULL , & status ) ;
if ( status ! = expectStatus ) {
log_err ( " %s should have been returned by udat_parseCalendar when given an invalid input, instead got - %s \n " , u_errorName ( expectStatus ) , u_errorName ( status ) ) ;
}
ucal_close ( cal ) ;
udat_close ( df ) ;
}
2015-03-04 00:11:53 +00:00
/*
* Ticket # 11553
* Test new udat_formatForFields , udat_formatCalendarForFields ( and UFieldPositionIterator )
*/
static const char localeForFields [ ] = " en_US " ;
/* zoneGMT[]defined above */
static const UDate date2015Feb25 = 1424841000000.0 ; /* Wednesday, February 25, 2015 at 5:10:00 AM GMT */
typedef struct {
int32_t field ;
int32_t beginPos ;
int32_t endPos ;
} FieldsData ;
static const FieldsData expectedFields [ ] = {
{ UDAT_DAY_OF_WEEK_FIELD /* 9*/ , 0 , 9 } ,
{ UDAT_MONTH_FIELD /* 2*/ , 11 , 19 } ,
{ UDAT_DATE_FIELD /* 3*/ , 20 , 22 } ,
{ UDAT_YEAR_FIELD /* 1*/ , 24 , 28 } ,
{ UDAT_HOUR1_FIELD /*15*/ , 32 , 33 } ,
2015-09-07 22:39:49 +00:00
# if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
2015-03-04 00:11:53 +00:00
{ UDAT_TIME_SEPARATOR_FIELD /*35*/ , 33 , 34 } ,
2015-09-07 22:39:49 +00:00
# endif
2015-03-04 00:11:53 +00:00
{ UDAT_MINUTE_FIELD /* 6*/ , 34 , 36 } ,
2015-09-07 22:39:49 +00:00
# if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
2015-03-04 00:11:53 +00:00
{ UDAT_TIME_SEPARATOR_FIELD /*35*/ , 36 , 37 } ,
2015-09-07 22:39:49 +00:00
# endif
2015-03-04 00:11:53 +00:00
{ UDAT_SECOND_FIELD /* 7*/ , 37 , 39 } ,
{ UDAT_AM_PM_FIELD /*14*/ , 40 , 42 } ,
{ UDAT_TIMEZONE_FIELD /*17*/ , 43 , 46 } ,
{ - 1 , - 1 , - 1 } ,
} ;
enum { kUBufFieldsLen = 128 , kBBufFieldsLen = 256 } ;
static void TestFormatForFields ( void ) {
UErrorCode status = U_ZERO_ERROR ;
UFieldPositionIterator * fpositer = ufieldpositer_open ( & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " ufieldpositer_open fails, status %s \n " , u_errorName ( status ) ) ;
} else {
UDateFormat * udfmt = udat_open ( UDAT_LONG , UDAT_FULL , localeForFields , zoneGMT , - 1 , NULL , 0 , & status ) ;
UCalendar * ucal = ucal_open ( zoneGMT , - 1 , localeForFields , UCAL_DEFAULT , & status ) ;
if ( U_FAILURE ( status ) ) {
log_data_err ( " udat_open or ucal_open fails for locale %s, status %s (Are you missing data?) \n " , localeForFields , u_errorName ( status ) ) ;
} else {
int32_t ulen , field , beginPos , endPos ;
UChar ubuf [ kUBufFieldsLen ] ;
const FieldsData * fptr ;
status = U_ZERO_ERROR ;
ulen = udat_formatForFields ( udfmt , date2015Feb25 , ubuf , kUBufFieldsLen , fpositer , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " udat_formatForFields fails, status %s \n " , u_errorName ( status ) ) ;
} else {
for ( fptr = expectedFields ; ; fptr + + ) {
field = ufieldpositer_next ( fpositer , & beginPos , & endPos ) ;
if ( field ! = fptr - > field | | ( field > = 0 & & ( beginPos ! = fptr - > beginPos | | endPos ! = fptr - > endPos ) ) ) {
if ( fptr - > field > = 0 ) {
log_err ( " udat_formatForFields as \" %s \" ; expect field %d range %d-%d, get field %d range %d-%d \n " ,
aescstrdup ( ubuf , ulen ) , fptr - > field , fptr - > beginPos , fptr - > endPos , field , beginPos , endPos ) ;
} else {
log_err ( " udat_formatForFields as \" %s \" ; expect field < 0, get field %d range %d-%d \n " ,
aescstrdup ( ubuf , ulen ) , field , beginPos , endPos ) ;
}
break ;
}
if ( field < 0 ) {
break ;
}
}
}
ucal_setMillis ( ucal , date2015Feb25 , & status ) ;
status = U_ZERO_ERROR ;
ulen = udat_formatCalendarForFields ( udfmt , ucal , ubuf , kUBufFieldsLen , fpositer , & status ) ;
if ( U_FAILURE ( status ) ) {
log_err ( " udat_formatCalendarForFields fails, status %s \n " , u_errorName ( status ) ) ;
} else {
for ( fptr = expectedFields ; ; fptr + + ) {
field = ufieldpositer_next ( fpositer , & beginPos , & endPos ) ;
if ( field ! = fptr - > field | | ( field > = 0 & & ( beginPos ! = fptr - > beginPos | | endPos ! = fptr - > endPos ) ) ) {
if ( fptr - > field > = 0 ) {
log_err ( " udat_formatFudat_formatCalendarForFieldsorFields as \" %s \" ; expect field %d range %d-%d, get field %d range %d-%d \n " ,
aescstrdup ( ubuf , ulen ) , fptr - > field , fptr - > beginPos , fptr - > endPos , field , beginPos , endPos ) ;
} else {
log_err ( " udat_formatCalendarForFields as \" %s \" ; expect field < 0, get field %d range %d-%d \n " ,
aescstrdup ( ubuf , ulen ) , field , beginPos , endPos ) ;
}
break ;
}
if ( field < 0 ) {
break ;
}
}
}
ucal_close ( ucal ) ;
udat_close ( udfmt ) ;
}
ufieldpositer_close ( fpositer ) ;
}
}
2002-09-20 17:54:45 +00:00
# endif /* #if !UCONFIG_NO_FORMATTING */