X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b331163bffd790ced0e88b73f44f86d49ccc48a5..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/test/cintltst/cdattst.c?ds=sidebyside diff --git a/icuSources/test/cintltst/cdattst.c b/icuSources/test/cintltst/cdattst.c index 54f2c528..8187de71 100644 --- a/icuSources/test/cintltst/cdattst.c +++ b/icuSources/test/cintltst/cdattst.c @@ -1,6 +1,6 @@ /******************************************************************** - * COPYRIGHT: - * Copyright (c) 1997-2015, International Business Machines Corporation and + * COPYRIGHT: + * Copyright (c) 1997-2016, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -8,7 +8,7 @@ * File CDATTST.C * * Modification History: -* Name Description +* Name Description * Madhu Katragadda Creation ********************************************************************************* */ @@ -41,12 +41,12 @@ static void TestContext(void); static void TestCalendarDateParse(void); static void TestParseErrorReturnValue(void); static void TestFormatForFields(void); +static void TestStandardPatterns(void); static void TestApplyPatnOverridesTimeSep(void); +static void Test12HrFormats(void); static void TestTimeUnitFormat(void); /* Apple-specific */ static void TestRemapPatternWithOpts(void); /* Apple-specific */ -#define LEN(a) (sizeof(a)/sizeof(a[0])) - void addDateForTest(TestNode** root); #define TESTCASE(x) addTest(root, &x, "tsformat/cdattst/" #x) @@ -65,7 +65,9 @@ void addDateForTest(TestNode** root) TESTCASE(TestOverrideNumberFormat); TESTCASE(TestParseErrorReturnValue); TESTCASE(TestFormatForFields); + TESTCASE(TestStandardPatterns); TESTCASE(TestApplyPatnOverridesTimeSep); + TESTCASE(Test12HrFormats); TESTCASE(TestTimeUnitFormat); /* Apple-specific */ TESTCASE(TestRemapPatternWithOpts); /* Apple-specific */ } @@ -99,24 +101,24 @@ static void TestDateFormat() fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL,0, NULL, 0,&status); if(U_FAILURE(status)) { - log_data_err("FAIL: error in creating the dateformat using full time style with french locale -> %s (Are you missing data?)\n", + log_data_err("FAIL: error in creating the dateformat using full time style with french locale -> %s (Are you missing data?)\n", myErrorName(status) ); return; } - /* this is supposed to open default date format, but later on it treats it like it is "en_US" + /* 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); */ def = udat_open(UDAT_SHORT, UDAT_SHORT, "en_US", NULL, 0,NULL, 0, &status); if(U_FAILURE(status)) { - log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", + log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", myErrorName(status) ); return; } it = udat_open(UDAT_DEFAULT, UDAT_MEDIUM, "it_IT", NULL, 0, NULL, 0,&status); if(U_FAILURE(status)) { - log_err("FAIL: error in creating the dateformat using medium date style with italian locale\n %s\n", + log_err("FAIL: error in creating the dateformat using medium date style with italian locale\n %s\n", myErrorName(status) ); return; } @@ -131,20 +133,20 @@ static void TestDateFormat() def1 = udat_open(UDAT_SHORT, UDAT_SHORT, NULL, NULL, 0,NULL, 0, &status); if(U_FAILURE(status)) { - log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", + log_err("FAIL: error in creating the dateformat using short date and time style\n %s\n", myErrorName(status) ); return; } - /*Testing udat_getAvailable() and udat_countAvailable()*/ + /*Testing udat_getAvailable() and udat_countAvailable()*/ log_verbose("\nTesting getAvailableLocales and countAvailable()\n"); numlocales=udat_countAvailable(); /* use something sensible w/o hardcoding the count */ if(numlocales < 0) log_data_err("FAIL: error in countAvailable\n"); log_verbose("The number of locales for which date/time formatting patterns are available is %d\n", numlocales); - + for(i=0;i %s (Are you missing data?)\n", + log_data_err("error in creating the dateformat using full time style with french locale -> %s (Are you missing data?)\n", myErrorName(status) ); return; } /*creating a default dateformat */ log_verbose("\ncreating a date format with default locale\n"); - /* this is supposed to open default date format, but later on it treats it like it is "en_US" + /* 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); */ def = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US", NULL, 0, NULL, 0, &status); if(U_FAILURE(status)) { - log_err("error in creating the dateformat using short date and time style\n %s\n", + log_err("error in creating the dateformat using short date and time style\n %s\n", myErrorName(status) ); return; } @@ -612,16 +614,16 @@ static void TestSymbols() 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", + 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; } - - + + /*Testing countSymbols, getSymbols and setSymbols*/ log_verbose("\nTesting 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 */ - if(udat_countSymbols(def, UDAT_ERAS)!=2 || udat_countSymbols(def, UDAT_MONTHS)!=12 || + 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 || udat_countSymbols(def, UDAT_SHORT_WEEKDAYS)!=8 || udat_countSymbols(def, UDAT_AM_PMS)!=2 || udat_countSymbols(def, UDAT_QUARTERS) != 4 || udat_countSymbols(def, UDAT_SHORT_QUARTERS) != 4 || @@ -649,7 +651,7 @@ static void TestSymbols() } result=(UChar*)malloc(sizeof(UChar) * resultlength); udat_getSymbols(fr, UDAT_WEEKDAYS, 5, result, resultlength, &status); - + } if(U_FAILURE(status)) { @@ -685,15 +687,19 @@ static void TestSymbols() 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"); - VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr:"); +#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR + VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB:"); +#else + VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB"); +#endif if(result != NULL) { free(result); result = NULL; } -free(pattern); - +free(pattern); + log_verbose("\nTesting setSymbols\n"); /*applying the pattern so that setSymbolss works */ resultlength=0; @@ -707,10 +713,10 @@ free(pattern); } if(U_FAILURE(status)) { - log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n", + 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); @@ -727,7 +733,7 @@ free(pattern); } if(U_FAILURE(status)) { - log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n", + log_err("FAIL: error in extracting the pattern from UNumberFormat\n %s\n", myErrorName(status) ); } if(u_strcmp(result, pattern)==0) @@ -748,12 +754,12 @@ free(pattern); } result=(UChar*)malloc(sizeof(UChar) * resultlength); udat_getSymbols(fr, UDAT_MONTHS, 11, result, resultlength, &status); - + } if(U_FAILURE(status)) log_err("FAIL: error in getSymbols() %s\n", myErrorName(status) ); resultlength=resultlengthout+1; - + udat_setSymbols(def, UDAT_MONTHS, 11, result, resultlength, &status); if(U_FAILURE(status)) { @@ -761,7 +767,7 @@ free(pattern); } else log_verbose("PASS: SetSymbols successful\n"); - + resultlength=0; resultlengthout=udat_getSymbols(def, UDAT_MONTHS, 11, NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ @@ -772,13 +778,13 @@ free(pattern); } if(U_FAILURE(status)) log_err("FAIL: error in retrieving the value using getSymbols i.e roundtrip\n"); - + if(u_strcmp(result, value)!=0) log_data_err("FAIL: Error in settting and getting symbols\n"); else log_verbose("PASS: setSymbols successful\n"); - - + + /*run series of tests to test setSymbols regressively*/ log_verbose("\nTesting setSymbols regressively\n"); VerifysetSymbols(def, UDAT_ERAS, 0, "BeforeChrist"); @@ -817,7 +823,7 @@ free(pattern); /*closing*/ - + udat_close(fr); udat_close(def); udat_close(zhChiCal); @@ -826,7 +832,7 @@ free(pattern); result = NULL; } free(value); - + } /** @@ -850,7 +856,7 @@ static void TestDateFormatCalendar() { /* Create a formatter for date fields. */ date = udat_open(UDAT_NONE, UDAT_SHORT, "en_US", NULL, 0, NULL, 0, &ec); if (U_FAILURE(ec)) { - log_data_err("FAIL: udat_open(NONE, SHORT, en_US) failed with %s (Are you missing data?)\n", + log_data_err("FAIL: udat_open(NONE, SHORT, en_US) failed with %s (Are you missing data?)\n", u_errorName(ec)); goto FAIL; } @@ -858,7 +864,7 @@ static void TestDateFormatCalendar() { /* Create a formatter for time fields. */ 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", + log_err("FAIL: udat_open(SHORT, NONE, en_US) failed with %s\n", u_errorName(ec)); goto FAIL; } @@ -866,7 +872,7 @@ static void TestDateFormatCalendar() { /* Create a full format for output */ 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", + log_err("FAIL: udat_open(FULL, FULL, en_US) failed with %s\n", u_errorName(ec)); goto FAIL; } @@ -874,7 +880,7 @@ static void TestDateFormatCalendar() { /* Create a calendar */ 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", + log_err("FAIL: ucal_open(en_US) failed with %s\n", u_errorName(ec)); goto FAIL; } @@ -945,7 +951,7 @@ static void TestDateFormatCalendar() { log_err("FAIL: Parsed result: %s, exp 4/5/2001 5:45 PM\n", cbuf); } - FAIL: + FAIL: udat_close(date); udat_close(time); udat_close(full); @@ -1062,7 +1068,7 @@ static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in UChar *result=NULL; int32_t resultlength, resultlengthout; int32_t patternSize = strlen(expected) + 1; - + pattern=(UChar*)malloc(sizeof(UChar) * patternSize); u_unescape(expected, pattern, patternSize); resultlength=0; @@ -1073,7 +1079,7 @@ static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in resultlength=resultlengthout+1; result=(UChar*)malloc(sizeof(UChar) * resultlength); udat_getSymbols(datfor, type, idx, result, resultlength, &status); - + } if(U_FAILURE(status)) { @@ -1083,7 +1089,7 @@ static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in if(u_strcmp(result, pattern)==0) log_verbose("PASS: getSymbols retrieved the right value\n"); else{ - log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s Got %s\n", expected, + log_data_err("FAIL: getSymbols retrieved the wrong value\n Expected %s Got %s\n", expected, aescstrdup(result,-1) ); } free(result); @@ -1116,11 +1122,11 @@ static void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in udat_getSymbols(datfor, type, idx, result, resultlength, &status); } if(U_FAILURE(status)){ - log_err("FAIL: error in retrieving the value using getSymbols after setting it previously\n %s\n", + 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){ log_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", expected, aescstrdup(result,-1) ); @@ -1139,7 +1145,7 @@ static void VerifygetsetSymbols(UDateFormat* from, UDateFormat* to, UDateFormatS UChar *value=NULL; int32_t resultlength, resultlengthout; UErrorCode status = U_ZERO_ERROR; - + resultlength=0; resultlengthout=udat_getSymbols(from, type, idx , NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ @@ -1152,7 +1158,7 @@ static void VerifygetsetSymbols(UDateFormat* from, UDateFormat* to, UDateFormatS log_err("FAIL: error in getSymbols() %s\n", myErrorName(status) ); return; } - + resultlength=resultlengthout+1; udat_setSymbols(to, type, idx, result, resultlength, &status); if(U_FAILURE(status)) @@ -1170,11 +1176,11 @@ static void VerifygetsetSymbols(UDateFormat* from, UDateFormat* to, UDateFormatS udat_getSymbols(to, type, idx, value, resultlength, &status); } if(U_FAILURE(status)){ - log_err("FAIL: error in retrieving the value using getSymbols i.e roundtrip\n %s\n", + 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){ log_data_err("FAIL:Error in setting and then getting symbols\n Expected %s Got %s\n", austrdup(result), austrdup(value) ); @@ -1192,7 +1198,7 @@ static UChar* myNumformat(const UNumberFormat* numfor, double d) UChar *result2=NULL; int32_t resultlength, resultlengthneeded; UErrorCode status = U_ZERO_ERROR; - + resultlength=0; resultlengthneeded=unum_formatDouble(numfor, d, NULL, resultlength, NULL, &status); if(status==U_BUFFER_OVERFLOW_ERROR) @@ -1208,7 +1214,7 @@ static UChar* myNumformat(const UNumberFormat* numfor, double d) log_err("FAIL: Error in formatting using unum_format(.....) %s\n", myErrorName(status) ); return 0; } - + return result2; } @@ -1282,7 +1288,7 @@ static void TestExtremeDates() { /* 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); @@ -1291,7 +1297,7 @@ static void TestExtremeDates() { return; } - _aux2ExtremeDates(fmt, small, large, buf, LEN(buf), cbuf, 0, &ec); + _aux2ExtremeDates(fmt, small, large, buf, UPRV_LENGTHOF(buf), cbuf, 0, &ec); udat_close(fmt); } @@ -1303,8 +1309,8 @@ static void TestAllLocales(void) { }; 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++) { + for (dateIdx = 0; dateIdx < UPRV_LENGTHOF(style); dateIdx++) { + for (timeIdx = 0; timeIdx < UPRV_LENGTHOF(style); timeIdx++) { UErrorCode status = U_ZERO_ERROR; udat_close(udat_open(style[dateIdx], style[timeIdx], uloc_getAvailable(idx), NULL, 0, NULL, 0, &status)); @@ -1332,12 +1338,12 @@ static void TestRelativeCrash(void) { UErrorCode subStatus = U_ZERO_ERROR; what = "udat_set2DigitYearStart"; log_verbose("Trying %s on a relative date..\n", what); - udat_set2DigitYearStart(icudf, aDate, &subStatus); + 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 */ @@ -1351,54 +1357,54 @@ static void TestRelativeCrash(void) { 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); + 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)); - } + } } { /* Now udat_toPattern works for relative date formatters, unless localized is TRUE */ UErrorCode subStatus = U_ZERO_ERROR; what = "udat_toPattern"; log_verbose("Trying %s on a relative date..\n", what); - udat_toPattern(icudf, TRUE,NULL,0, &subStatus); + udat_toPattern(icudf, TRUE,NULL,0, &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)); - } + } } { UErrorCode subStatus = U_ZERO_ERROR; what = "udat_applyPattern"; log_verbose("Trying %s on a relative date..\n", what); - udat_applyPattern(icudf, FALSE,tzName,-1); + 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)); - } + } } { UChar erabuf[32]; UErrorCode subStatus = U_ZERO_ERROR; what = "udat_getSymbols"; log_verbose("Trying %s on a relative date..\n", what); - udat_getSymbols(icudf, UDAT_ERAS,0,erabuf,sizeof(erabuf)/sizeof(erabuf[0]), &subStatus); + udat_getSymbols(icudf, UDAT_ERAS,0,erabuf,UPRV_LENGTHOF(erabuf), &subStatus); if(subStatus == U_ZERO_ERROR) { log_verbose("Success: %s returned %s.\n", what, u_errorName(subStatus)); } else { log_err("FAIL: didn't crash on %s, but got %s instead of U_ZERO_ERROR.\n", what, u_errorName(subStatus)); - } + } } { UErrorCode subStatus = U_ZERO_ERROR; @@ -1410,21 +1416,21 @@ static void TestRelativeCrash(void) { 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_countSymbols"; log_verbose("Trying %s on a relative date..\n", what); - udat_countSymbols(icudf, UDAT_ERAS); + 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 { log_data_err("FAIL: err calling udat_open() ->%s (Are you missing data?)\n", u_errorName(status)); @@ -1604,9 +1610,9 @@ static void TestContext(void) { } -// overrideNumberFormat[i][0] is to tell which field to set, +// overrideNumberFormat[i][0] is to tell which field to set, // overrideNumberFormat[i][1] is the expected result -static const char * overrideNumberFormat[][2] = { +static const char * overrideNumberFormat[][2] = { {"", "\\u521D\\u4E03 \\u521D\\u4E8C"}, {"d", "07 \\u521D\\u4E8C"}, {"do", "07 \\u521D\\u4E8C"}, @@ -1657,7 +1663,7 @@ static void TestOverrideNumberFormat(void) { unum_close(overrideFmt); } udat_close(fmt); - + for (i=0; ilocale != NULL; itemPtr++) { + UErrorCode status = U_ZERO_ERROR; + UDateFormat* udfmt = udat_open(itemPtr->timeStyle, itemPtr->dateStyle, itemPtr->locale, zoneGMT, -1, NULL, 0, &status); + if ( U_FAILURE(status) ) { + log_err("udat_open(%d, %d, \"%s\",...) fails, status %s\n", + (int)itemPtr->timeStyle, (int)itemPtr->dateStyle, itemPtr->locale, u_errorName(status)); + } else { + UChar uget[kUbufStdMax]; + int32_t ugetlen = udat_format(udfmt, date2015Feb25, uget, kUbufStdMax, NULL, &status); + if ( U_FAILURE(status) ) { + log_err("udat_format for (%d, %d, \"%s\",...) fails, status %s\n", + (int)itemPtr->timeStyle, (int)itemPtr->dateStyle, itemPtr->locale, u_errorName(status)); + } else { + UChar uexpect[kUbufStdMax]; + int32_t uexpectlen = u_unescape(itemPtr->expect, uexpect, kUbufStdMax); + if (ugetlen != uexpectlen || u_strncmp(uget, uexpect, uexpectlen) != 0) { + char bexpect[kBbufStdMax]; + char bget[kBbufStdMax]; + u_austrcpy(bexpect, uexpect); + u_austrcpy(bget, uget); + log_err("udat_format for (%d, %d, \"%s\",...):\n expect %s\n get %s\n", + (int)itemPtr->timeStyle, (int)itemPtr->dateStyle, itemPtr->locale, bexpect, bget); + } + } + udat_close(udfmt); + } + } +} + /* defined above static const UChar zoneGMT[] = { 0x47,0x4D,0x54,0 }; // "GMT" static const UDate date2015Feb25 = 1424841000000.0; // Wednesday, February 25, 2015 at 5:10:00 AM GMT @@ -1894,6 +1957,122 @@ static void TestApplyPatnOverridesTimeSep(void) { } +#define UDATE_SECOND (1000.0) +#define UDATE_MINUTE (60.0*UDATE_SECOND) +#define UDATE_HOUR (60.0*UDATE_MINUTE) + +static const double dayOffsets[] = { + 0.0, /* 00:00:00 */ + UDATE_SECOND, /* 00:00:01 */ + UDATE_MINUTE, /* 00:01:00 */ + UDATE_HOUR, /* 01:00:00 */ + 11.0*UDATE_HOUR + 59.0*UDATE_MINUTE, /* 11:59:00 */ + 12.0*UDATE_HOUR, /* 12:00:00 */ + 12.0*UDATE_HOUR + UDATE_SECOND, /* 12:00:01 */ + 12.0*UDATE_HOUR + UDATE_MINUTE, /* 12:01:00 */ + 13.0*UDATE_HOUR, /* 13:00:00 */ + 23.0*UDATE_HOUR + 59.0*UDATE_MINUTE, /* 23:59:00 */ +}; +enum { kNumDayOffsets = UPRV_LENGTHOF(dayOffsets) }; + +static const char* ja12HrFmt_hm[kNumDayOffsets] = { /* aK:mm */ + "\\u5348\\u524D0:00", /* "午前0:00" */ + "\\u5348\\u524D0:00", + "\\u5348\\u524D0:01", + "\\u5348\\u524D1:00", + "\\u5348\\u524D11:59", + "\\u5348\\u5F8C0:00", /* "午後0:00" */ + "\\u5348\\u5F8C0:00", + "\\u5348\\u5F8C0:01", /* "午後0:01" */ + "\\u5348\\u5F8C1:00", + "\\u5348\\u5F8C11:59", +}; + +static const char* ja12HrFmt_h[kNumDayOffsets] = { /* aK時 */ + "\\u5348\\u524D0\\u6642", /* "午前0時" */ + "\\u5348\\u524D0\\u6642", + "\\u5348\\u524D0\\u6642", + "\\u5348\\u524D1\\u6642", + "\\u5348\\u524D11\\u6642", + "\\u5348\\u5F8C0\\u6642", /* "午後0時" */ + "\\u5348\\u5F8C0\\u6642", + "\\u5348\\u5F8C0\\u6642", /* "午後0時" */ + "\\u5348\\u5F8C1\\u6642", + "\\u5348\\u5F8C11\\u6642", +}; +typedef struct { + const char* locale; + const char* skeleton; + const char ** expected; +} Test12HrFmtItem; + +static const Test12HrFmtItem test12HrFmtItems[] = { + { "ja", "hm", ja12HrFmt_hm }, + { "ja", "h", ja12HrFmt_h }, + { NULL, NULL, NULL } /* terminator */ +}; + +enum { kUBufMax = 128, }; +static void Test12HrFormats(void) { + const Test12HrFmtItem* itemPtr; + for (itemPtr = test12HrFmtItems; itemPtr->locale != NULL; itemPtr++) { + UErrorCode status = U_ZERO_ERROR; + UCalendar* ucal = ucal_open(NULL, 0, itemPtr->locale, UCAL_DEFAULT, &status); + if ( U_FAILURE(status) ) { + log_data_err("ucal_open fails for locale %s: status %s (Are you missing data?)\n", itemPtr->locale, u_errorName(status)); + } else { + ucal_clear(ucal); + ucal_setDateTime(ucal, 2016, UCAL_JANUARY, 1, 0, 0, 0, &status); + UDate baseDate = ucal_getMillis(ucal, &status); + if ( U_FAILURE(status) ) { + log_err("ucal_setDateTime or ucal_getMillis fails for locale %s: status %s\n", itemPtr->locale, u_errorName(status)); + } else { + UDateTimePatternGenerator* udatpg = udatpg_open(itemPtr->locale, &status); + if ( U_FAILURE(status) ) { + log_data_err("udatpg_open fails for locale %s: status %s (Are you missing data?)\n", itemPtr->locale, u_errorName(status)); + } else { + UChar ubuf1[kUbufMax], ubuf2[kUbufMax]; + int32_t ulen1 = u_unescape(itemPtr->skeleton, ubuf1, kUbufMax); + int32_t ulen2 = udatpg_getBestPattern(udatpg, ubuf1, ulen1, ubuf2, kUbufMax, &status); + if ( U_FAILURE(status) ) { + log_err("udatpg_getBestPattern fails for locale %s, skeleton %s: status %s\n", + itemPtr->locale, itemPtr->skeleton, u_errorName(status)); + } else { + UDateFormat* udat = udat_open(UDAT_PATTERN, UDAT_PATTERN, itemPtr->locale, NULL, 0, ubuf2, ulen2, &status); + if ( U_FAILURE(status) ) { + log_data_err("udat_open fails for locale %s, skeleton %s: status %s (Are you missing data?)\n", + itemPtr->locale, itemPtr->skeleton, u_errorName(status)); + } else { + int32_t iDayOffset; + for (iDayOffset = 0; iDayOffset < kNumDayOffsets; iDayOffset++) { + status = U_ZERO_ERROR; + ulen1 = udat_format(udat, baseDate + dayOffsets[iDayOffset], ubuf1, kUbufMax, NULL, &status); + if ( U_FAILURE(status) ) { + log_err("udat_format fails for locale %s, skeleton %s, iDayOffset %d: status %s\n", + itemPtr->locale, itemPtr->skeleton, iDayOffset, u_errorName(status)); + } else { + ulen2 = u_unescape(itemPtr->expected[iDayOffset], ubuf2, kUbufMax); + if (ulen1 != ulen2 || u_strncmp(ubuf1, ubuf2, ulen2) != 0) { + char bbuf1[kBbufMax], bbuf2[kBbufMax]; + u_austrncpy(bbuf1, ubuf1, ulen1); + u_austrncpy(bbuf2, ubuf2, ulen2); + log_err("udat_format fails for locale %s, skeleton %s, iDayOffset %d:\n expect %s\n get %s\n", + itemPtr->locale, itemPtr->skeleton, iDayOffset, bbuf2, bbuf1); + } + } + + } + udat_close(udat); + } + } + udatpg_close(udatpg); + } + } + ucal_close(ucal); + } + } +} + /* *** */ typedef struct { @@ -1926,6 +2105,7 @@ static const ListPatternItem listPatternItems[] = { { "en", UATIMEUNITSTYLE_NARROW, UATIMEUNITLISTPAT_END_PIECE, "{0} {1}" }, { "en", UATIMEUNITSTYLE_NARROW, UATIMEUNITLISTPAT_MIDDLE_PIECE, "{0} {1}" }, { "en", UATIMEUNITSTYLE_NARROW, UATIMEUNITLISTPAT_START_PIECE, "{0} {1}" }, + { "en", UATIMEUNITSTYLE_SHORTER, UATIMEUNITLISTPAT_TWO_ONLY, "{0} {1}" }, { "fr", UATIMEUNITSTYLE_FULL, UATIMEUNITLISTPAT_TWO_ONLY, "{0} et {1}" }, { "fr", UATIMEUNITSTYLE_FULL, UATIMEUNITLISTPAT_END_PIECE, "{0} et {1}" }, { "fr", UATIMEUNITSTYLE_FULL, UATIMEUNITLISTPAT_MIDDLE_PIECE, "{0}, {1}" }, @@ -1934,6 +2114,7 @@ static const ListPatternItem listPatternItems[] = { { "fr", UATIMEUNITSTYLE_NARROW, UATIMEUNITLISTPAT_END_PIECE, "{0} {1}" }, { "fr", UATIMEUNITSTYLE_NARROW, UATIMEUNITLISTPAT_MIDDLE_PIECE, "{0} {1}" }, { "fr", UATIMEUNITSTYLE_NARROW, UATIMEUNITLISTPAT_START_PIECE, "{0} {1}" }, + { "fr", UATIMEUNITSTYLE_SHORTER, UATIMEUNITLISTPAT_TWO_ONLY, "{0} {1}" }, { NULL, 0, 0, NULL } };