X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/4f1e1a09ce4daed860e35d359ce2fceccb0764e8..HEAD:/icuSources/test/cintltst/cdattst.c diff --git a/icuSources/test/cintltst/cdattst.c b/icuSources/test/cintltst/cdattst.c index ca4ae88d..8189b459 100644 --- a/icuSources/test/cintltst/cdattst.c +++ b/icuSources/test/cintltst/cdattst.c @@ -21,6 +21,7 @@ #if !UCONFIG_NO_FORMATTING +#include "unicode/uchar.h" #include "unicode/uloc.h" #include "unicode/udat.h" #include "unicode/udatpg.h" @@ -37,7 +38,15 @@ #endif #include +#include // for sprintf +#define ADD_ALLOC_TEST 0 +#define WRITE_HOUR_MISMATCH_ERRS 0 +#define WRITE_COUNTRY_FALLBACK_RESULTS 0 + +#if ADD_ALLOC_TEST +static void TestPerf(void); +#endif static void TestExtremeDates(void); static void TestAllLocales(void); static void TestRelativeCrash(void); @@ -45,13 +54,24 @@ static void TestContext(void); static void TestCalendarDateParse(void); static void TestParseErrorReturnValue(void); static void TestFormatForFields(void); +static void TestForceGannenNumbering(void); static void TestStandardPatterns(void); static void TestApplyPatnOverridesTimeSep(void); static void Test12HrFormats(void); +static void Test12HrPatterns(void); #if !U_PLATFORM_HAS_WIN32_API static void TestTimeUnitFormat(void); /* Apple-specific */ +static void TestTimeUnitFormatWithNumStyle(void); /* Apple-specific */ #endif +static void TestMapPatternCharToFields(void); /* Apple */ static void TestRemapPatternWithOpts(void); /* Apple-specific */ +#if WRITE_HOUR_MISMATCH_ERRS +static void WriteHourMismatchErrs(void); /* 52980140*/ +#endif +#if WRITE_COUNTRY_FALLBACK_RESULTS +static void WriteCountryFallbackResults(void); /* Apple */ +#endif +static void TestCountryFallback(void); /* Apple */ void addDateForTest(TestNode** root); @@ -59,6 +79,9 @@ void addDateForTest(TestNode** root); void addDateForTest(TestNode** root) { +#if ADD_ALLOC_TEST + TESTCASE(TestPerf); +#endif TESTCASE(TestDateFormat); TESTCASE(TestRelativeDateFormat); TESTCASE(TestSymbols); @@ -71,14 +94,26 @@ void addDateForTest(TestNode** root) TESTCASE(TestOverrideNumberFormat); TESTCASE(TestParseErrorReturnValue); TESTCASE(TestFormatForFields); + TESTCASE(TestForceGannenNumbering); TESTCASE(TestStandardPatterns); TESTCASE(TestApplyPatnOverridesTimeSep); TESTCASE(Test12HrFormats); + TESTCASE(Test12HrPatterns); #if !U_PLATFORM_HAS_WIN32_API TESTCASE(TestTimeUnitFormat); /* Apple-specific */ + TESTCASE(TestTimeUnitFormatWithNumStyle); /* Apple-specific */ #endif + TESTCASE(TestMapPatternCharToFields); /* Apple */ TESTCASE(TestRemapPatternWithOpts); /* Apple-specific */ +#if WRITE_HOUR_MISMATCH_ERRS + TESTCASE(WriteHourMismatchErrs); /* 52980140 */ +#endif +#if WRITE_COUNTRY_FALLBACK_RESULTS + TESTCASE(WriteCountryFallbackResults); /* Apple */ +#endif + TESTCASE(TestCountryFallback); /* Apple */ } + /* Testing the DateFormat API */ static void TestDateFormat() { @@ -568,7 +603,7 @@ static void TestRelativeDateFormat() strPtr = u_strstr(strDateTime, minutesStr); if ( strPtr != NULL ) { - int32_t beginIndex = strPtr - strDateTime; + int32_t beginIndex = (int32_t)(strPtr - strDateTime); 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 ); } @@ -587,7 +622,7 @@ static void TestRelativeDateFormat() /*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/ static void TestSymbols() { - UDateFormat *def, *fr, *zhChiCal; + UDateFormat *def, *fr, *zhChiCal, *esMX; UErrorCode status = U_ZERO_ERROR; UChar *value=NULL; UChar *result = NULL; @@ -626,6 +661,15 @@ static void TestSymbols() myErrorName(status) ); return; } + /*creating a dateformat with es_MX locale */ + log_verbose("\ncreating a date format with es_MX locale\n"); + esMX = udat_open(UDAT_SHORT, UDAT_NONE, "es_MX", NULL, 0, NULL, 0, &status); + if(U_FAILURE(status)) + { + log_data_err("error in creating the dateformat using no date, short time, locale es_MX -> %s (Are you missing data?)\n", + myErrorName(status) ); + return; + } /*Testing countSymbols, getSymbols and setSymbols*/ @@ -695,6 +739,8 @@ 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(esMX, UDAT_AM_PMS, 0, "a.m."); // see + VerifygetSymbols(esMX, UDAT_AM_PMS, 1, "p.m."); // see #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR VerifygetSymbols(def,UDAT_LOCALIZED_CHARS, 0, "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB:"); #else @@ -835,6 +881,7 @@ free(pattern); udat_close(fr); udat_close(def); udat_close(zhChiCal); + udat_close(esMX); if(result != NULL) { free(result); result = NULL; @@ -1075,7 +1122,7 @@ static void VerifygetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in UErrorCode status = U_ZERO_ERROR; UChar *result=NULL; int32_t resultlength, resultlengthout; - int32_t patternSize = strlen(expected) + 1; + int32_t patternSize = (int32_t)strlen(expected) + 1; pattern=(UChar*)malloc(sizeof(UChar) * patternSize); u_unescape(expected, pattern, patternSize); @@ -1110,7 +1157,7 @@ static void VerifysetSymbols(UDateFormat* datfor, UDateFormatSymbolType type, in UChar *value=NULL; int32_t resultlength, resultlengthout; UErrorCode status = U_ZERO_ERROR; - int32_t valueLen, valueSize = strlen(expected) + 1; + int32_t valueLen, valueSize = (int32_t)strlen(expected) + 1; value=(UChar*)malloc(sizeof(UChar) * valueSize); valueLen = u_unescape(expected, value, valueSize); @@ -1598,7 +1645,6 @@ static void TestContext(void) { log_data_err("FAIL: udatpg_open for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); } } - for (textRelContextItemPtr = textContextRelativeItems; textRelContextItemPtr->locale != NULL; ++textRelContextItemPtr) { UErrorCode status = U_ZERO_ERROR; UCalendar* ucal = ucal_open(zoneGMT, -1, "root", UCAL_GREGORIAN, &status); @@ -1713,6 +1759,7 @@ static void TestOverrideNumberFormat(void) { // loop 5 times to check getter/setter for (i = 0; i < 5; i++){ + status = U_ZERO_ERROR; UNumberFormat* overrideFmt; overrideFmt = unum_open(UNUM_DEFAULT, NULL, 0, localeString, NULL, &status); assertSuccess("unum_open()", &status); @@ -1726,15 +1773,19 @@ static void TestOverrideNumberFormat(void) { } } { + status = U_ZERO_ERROR; 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 + if (U_SUCCESS(status)) { + udat_setNumberFormat(fmt, overrideFmt); // test the same override NF will not crash + } unum_close(overrideFmt); } udat_close(fmt); for (i=0; i; currently no specific locales for these + { "en_AZ", UDAT_MEDIUM, UDAT_SHORT, "25 Feb 2015 at 05:10" }, // en uses h, AZ Azerbaijanvpref cycle H + { "fr_US", UDAT_NONE, UDAT_SHORT, "5:10 AM" }, // fr uses H, US pref cycle h + { "rkt", UDAT_NONE, UDAT_SHORT, "5:10 AM" }, // rkt (no locale) => rkt_Beng_BD, BD pref cycle h unlike root H + // Add tests for Apple + { "ur_PK", UDAT_MEDIUM, UDAT_SHORT, "25 \\u0641\\u0631\\u0648\\u060C 2015 5:10 \\u0642.\\u062F." }, + { "ur_IN", UDAT_MEDIUM, UDAT_SHORT, "\\u06F2\\u06F5 \\u0641\\u0631\\u0648\\u060C \\u06F2\\u06F0\\u06F1\\u06F5 \\u06F5:\\u06F1\\u06F0 \\u0642.\\u062F." }, + { "ur_Arab", UDAT_MEDIUM, UDAT_SHORT, "25 \\u0641\\u0631\\u0648\\u060C 2015 5:10 \\u0642.\\u062F." }, + { "ur_Aran", UDAT_MEDIUM, UDAT_SHORT, "25 \\u0641\\u0631\\u0648\\u060C 2015 5:10 \\u0642.\\u062F." }, + { "ur_Arab_PK", UDAT_MEDIUM, UDAT_SHORT, "25 \\u0641\\u0631\\u0648\\u060C 2015 5:10 \\u0642.\\u062F." }, + { "ur_Aran_PK", UDAT_MEDIUM, UDAT_SHORT, "25 \\u0641\\u0631\\u0648\\u060C 2015 5:10 \\u0642.\\u062F." }, + { "ur_Arab_IN", UDAT_MEDIUM, UDAT_SHORT, "\\u06F2\\u06F5 \\u0641\\u0631\\u0648\\u060C \\u06F2\\u06F0\\u06F1\\u06F5 \\u06F5:\\u06F1\\u06F0 \\u0642.\\u062F." }, + { "ur_Aran_IN", UDAT_MEDIUM, UDAT_SHORT, "\\u06F2\\u06F5 \\u0641\\u0631\\u0648\\u060C \\u06F2\\u06F0\\u06F1\\u06F5 \\u06F5:\\u06F1\\u06F0 \\u0642.\\u062F." }, + // Add tests for Apple + { "zh@calendar=buddhist", UDAT_NONE, UDAT_MEDIUM, "\\u4E0A\\u53485:10:00" }, + { "zh@calendar=buddhist", UDAT_NONE, UDAT_SHORT, "\\u4E0A\\u53485:10" }, + { "zh_Hant@calendar=buddhist", UDAT_NONE, UDAT_MEDIUM, "\\u4E0A\\u53485:10:00" }, + { "zh_Hant@calendar=buddhist", UDAT_NONE, UDAT_SHORT, "\\u4E0A\\u53485:10" }, + // Add tests for Apple + { "pl", UDAT_FULL, UDAT_SHORT, "\\u015Broda, 25 lutego 2015 o 05:10" }, + { "pl", UDAT_LONG, UDAT_SHORT, "25 lutego 2015 o 05:10" }, + { "pl", UDAT_MEDIUM, UDAT_SHORT, "25.02.2015 o 05:10" }, + { "pl", UDAT_SHORT, UDAT_SHORT, "25.02.2015, 05:10" }, + // Add tests for Apple + { "iu_Latn_CA", UDAT_LONG, UDAT_SHORT, "2015 M02 25 5:10 AM" }, + { "iu_CA", UDAT_LONG, UDAT_SHORT, "\\u1555\\u155d\\u1557\\u140a\\u14d5 25, 2015 5:10 am" }, + { "nv", UDAT_LONG, UDAT_SHORT, "February 25, 2015 at 5:10 AM" }, { NULL, (UDateFormatStyle)0, (UDateFormatStyle)0, NULL } /* terminator */ }; @@ -2157,8 +2276,92 @@ static void Test12HrFormats(void) { } } +static const UChar* skeletons12Hr[] = { + u"h", + u"j", + u"hm", + u"jm", + u"hms", + u"jms", + u"hmz", + u"jmz", + u"Ehmm", + u"Ejmm", + NULL +}; + +static const UChar* patterns12Hr_zh_buddhist[] = { + u"ah时", + u"ah时", + u"ah:mm", + u"ah:mm", + u"ah:mm:ss", + u"ah:mm:ss", + u"z ah:mm", + u"z ah:mm", + u"EEE ah:mm", + u"EEE ah:mm", + NULL +}; + +static const UChar* patterns12Hr_zhHant_buddhist[] = { + u"ah時", + u"ah時", + u"ah:mm", + u"ah:mm", + u"ah:mm:ss", + u"ah:mm:ss", + u"z ah:mm", // as in gregorian/generic standard, gregorian availableFormats + u"z ah:mm", + u"EEE ah:mm", + u"EEE ah:mm", + NULL +}; + +typedef struct { + const char* locale; + const UChar** skeletons; + const UChar** patterns; +} Test12HrPatItem; + +static const Test12HrPatItem test12HrPatItems[] = { + { "zh@calendar=buddhist", skeletons12Hr, patterns12Hr_zh_buddhist }, + { "zh_Hant@calendar=buddhist", skeletons12Hr, patterns12Hr_zhHant_buddhist }, + { NULL, NULL, NULL } /* terminator */ +}; + +static void Test12HrPatterns(void) { // Apple + const Test12HrPatItem* itemPtr; + for (itemPtr = test12HrPatItems; itemPtr->locale != NULL; itemPtr++) { + UErrorCode status = U_ZERO_ERROR; + 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 { + const UChar** skeletonsPtr = itemPtr->skeletons; + const UChar** patternsPtr = itemPtr->patterns; + const UChar* skeleton; + const UChar* expPatn; + while ((skeleton = *skeletonsPtr++) != NULL && (expPatn = *patternsPtr++) != NULL) { + UChar getPatn[kUbufMax]; + char bSkel[kBbufMax]; + u_austrcpy(bSkel, skeleton); + int32_t getLen = udatpg_getBestPattern(udatpg, skeleton, -1, getPatn, kUbufMax, &status); + if ( U_FAILURE(status) ) { + log_err("udatpg_getBestPattern fails for locale %s, skeleton %s: status %s\n", itemPtr->locale, bSkel, u_errorName(status)); + } else if (u_strcmp(getPatn,expPatn) != 0) { + char bExpPatn[kBbufMax], bGetPatn[kBbufMax]; + u_austrcpy(bExpPatn, expPatn); + u_austrcpy(bGetPatn, getPatn); + log_err("udatpg_getBestPattern error for locale %s, skeleton %s: expected %s, got %s\n", itemPtr->locale, bSkel, bExpPatn, bGetPatn); + } + } + udatpg_close(udatpg); + } + } +} + #if !U_PLATFORM_HAS_WIN32_API -/* *** */ typedef struct { const char* locale; @@ -2242,8 +2445,99 @@ static void TestTimeUnitFormat(void) { /* Apple-specific */ } } + +typedef struct { + const char* locale; + UNumberFormatStyle numStyle; + UATimeUnitStyle width; + UATimeUnitField field; + double value; + const UChar* expect; +} TimeUnitWithNumStyleItem; +static const TimeUnitWithNumStyleItem tuNumStyleItems[] = { + { "en_US", UNUM_PATTERN_DECIMAL/*0*/, UATIMEUNITSTYLE_FULL/*0*/, UATIMEUNITFIELD_SECOND/*6*/, 0.0, u"0 seconds" }, + { "en_US", UNUM_DECIMAL, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0 seconds" }, + { "en_US", UNUM_CURRENCY, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"$0.00 seconds" }, + { "en_US", UNUM_PERCENT, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0% seconds" }, + { "en_US", UNUM_SCIENTIFIC/*4*/, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0E0 seconds" }, + { "en_US", UNUM_SPELLOUT/*5*/, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"zero seconds" }, // uses RuleBasedNumberFormat, got U_UNSUPPORTED_ERROR + { "en_US", UNUM_ORDINAL, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0th seconds" }, // uses RuleBasedNumberFormat, got U_UNSUPPORTED_ERROR + { "en_US", UNUM_DURATION, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0 sec. seconds" }, // uses RuleBasedNumberFormat, got U_UNSUPPORTED_ERROR + { "en_US", UNUM_NUMBERING_SYSTEM/*8*/, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"௦ seconds" }, // uses RuleBasedNumberFormat, got U_UNSUPPORTED_ERROR + // skip UNUM_PATTERN_RULEBASED/*9*/ // uses RuleBasedNumberFormat + // { "en_US", UNUM_CURRENCY_ISO/*10*/, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"USD 0.00 seconds" }, // currently produces u"USD 0.0 seconds0" + { "en_US", UNUM_CURRENCY_PLURAL, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0.00 US dollars seconds" }, + { "en_US", UNUM_CURRENCY_ACCOUNTING, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"$0.00 seconds" }, + { "en_US", UNUM_CASH_CURRENCY, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"$0.00 seconds" }, + { "en_US", UNUM_DECIMAL_COMPACT_SHORT, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0 seconds" }, + { "en_US", UNUM_DECIMAL_COMPACT_LONG, UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"0 seconds" }, + { "en_US", UNUM_CURRENCY_STANDARD/*16*/,UATIMEUNITSTYLE_FULL, UATIMEUNITFIELD_SECOND, 0.0, u"$0.00 seconds" }, + { NULL, 0, 0, 0, 0.0, NULL } +}; + +enum { kBBufMax = 196 }; + +static void TestTimeUnitFormatWithNumStyle(void) { /* Apple-specific */ + const TimeUnitWithNumStyleItem* itemPtr; + for (itemPtr = tuNumStyleItems; itemPtr->locale != NULL; itemPtr++) { + UErrorCode status = U_ZERO_ERROR; + UNumberFormat *numFormat = unum_open(itemPtr->numStyle, NULL, 0, itemPtr->locale, NULL, &status); + if ( U_FAILURE(status) ) { + log_data_err("unum_open for locale %s, style %d: status %s\n", itemPtr->locale, itemPtr->numStyle, u_errorName(status)); + } else { + UATimeUnitFormat *tuFormat = uatmufmt_openWithNumberFormat(itemPtr->locale, itemPtr->width, numFormat, &status); + if ( U_FAILURE(status) ) { + log_data_err("uatmufmt_openWithNumberFormat for locale %s, numStyle %d, width %d: status %s\n", itemPtr->locale, itemPtr->numStyle, itemPtr->width, u_errorName(status)); + } else { + UChar ubuf[kUBufMax] = {0}; + int32_t ulen = uatmufmt_format(tuFormat, itemPtr->value, itemPtr->field, ubuf, kUBufMax, &status); + if ( U_FAILURE(status) ) { + log_err("uatmufmt_format for locale %s, numStyle %d, width %d, field %d: status %s\n", itemPtr->locale, itemPtr->numStyle, itemPtr->width, itemPtr->field, u_errorName(status)); + } else if (u_strcmp(ubuf, itemPtr->expect) != 0) { + char bbufExp[kBBufMax]; + char bbufGet[kBBufMax]; + u_strToUTF8(bbufExp, kBBufMax, NULL, itemPtr->expect, -1, &status); + u_strToUTF8(bbufGet, kBBufMax, NULL, ubuf, ulen, &status); + log_err("uatmufmt_format for locale %s, numStyle %d, width %d, field %d:\n expect %s\n get %s\n", itemPtr->locale, itemPtr->numStyle, itemPtr->width, itemPtr->field, bbufExp, bbufGet); + } + uatmufmt_close(tuFormat); + } + } + } +} + #endif +typedef struct { + UChar patternChar; + UDateFormatField dateField; + UCalendarDateFields calField; +} PatternCharToFieldsItem; + +static const PatternCharToFieldsItem patCharToFieldsItems[] = { + { u'G', UDAT_ERA_FIELD, UCAL_ERA }, + { u'y', UDAT_YEAR_FIELD, UCAL_YEAR }, + { u'Y', UDAT_YEAR_WOY_FIELD, UCAL_YEAR_WOY }, + { u'Q', UDAT_QUARTER_FIELD, UCAL_MONTH }, + { u'H', UDAT_HOUR_OF_DAY0_FIELD, UCAL_HOUR_OF_DAY }, + { u'r', UDAT_RELATED_YEAR_FIELD, UCAL_EXTENDED_YEAR }, + { u'B', UDAT_FLEXIBLE_DAY_PERIOD_FIELD, UCAL_FIELD_COUNT }, + { u'$', UDAT_FIELD_COUNT, UCAL_FIELD_COUNT }, + { (UChar)0, (UDateFormatField)0, (UCalendarDateFields)0 } // terminator +}; + +static void TestMapPatternCharToFields(void){ /* Apple */ + const PatternCharToFieldsItem* itemPtr; + for ( itemPtr=patCharToFieldsItems; itemPtr->patternChar!=(UChar)0; itemPtr++) { + UDateFormatField dateField = udat_patternCharToDateFormatField(itemPtr->patternChar); + UCalendarDateFields calField = udat_toCalendarDateField(dateField); + if (dateField != itemPtr->dateField || calField != itemPtr->calField) { + log_err("for pattern char 0x%04X, expect dateField %d and got %d, expect calField %d and got %d\n", + itemPtr->patternChar, itemPtr->dateField, dateField, itemPtr->calField, calField); + } + } +} + typedef enum RemapTesttype { REMAP_TESTTYPE_FULL = UDAT_FULL, // 0 REMAP_TESTTYPE_LONG = UDAT_LONG, // 1 @@ -2829,6 +3123,321 @@ static const char * remapResults_en_IL[] = { NULL }; +static const char * remapResults_es_PR_japanese[] = { // rdar://52461062 + "h:mm:ss a zzzz", // full + "HH:mm:ss zzzz", // force24 + "h:mm:ss a zzzz", // force12 + "h:mm:ss a z", // long + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + "h:mm:ss a", // medium + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "h:mm a", // short + "HH:mm", // force24 + "h:mm a", // force12 + "EEEE, d 'de' MMMM 'de' y G, h:mm:ss a z", // long_df + "EEEE, d 'de' MMMM 'de' y G, HH:mm:ss z", // force24 + "EEEE, d 'de' MMMM 'de' y G, h:mm:ss a z", // force12 + "MM/dd/yy GGGGG h:mm a", // short_ds + "MM/dd/yy GGGGG HH:mm", // force24 + "MM/dd/yy GGGGG h:mm a", // force12 + + "h:mm:ss a", // jmmss + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "h:mm:ss a", // jjmmss + "HH:mm:ss", // force24 + "HH:mm:ss", // force24 | match hour field length + "h:mm:ss a", // force12 + "hh:mm:ss a", // force12 | match hour field length + "hh:mm", // Jmm + "HH:mm", // force24 + "hh:mm", // force12 + "h:mm:ss a v", // jmsv + "HH:mm:ss v", // force24 + "h:mm:ss a v", // force12 + "h:mm:ss a z", // jmsz + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + + "h:mm:ss a", // "h:mm:ss" + "HH:mm:ss", // + "a'xx'h:mm:ss d MMM y", // "a'xx'h:mm:ss d MMM y" + "HH:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' h:mm:ss a 'hrs'" + "EEE, d MMM y 'aha' HH:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' a'xx'h:mm:ss", // "EEE, d MMM y 'aha' a'xx'h:mm:ss" + "EEE, d MMM y 'aha' HH:mm:ss", // + "yyMMddhhmmss", // "yyMMddhhmmss" + "yyMMddHHmmss", // + + "h:mm:ss a", // "H:mm:ss" + "H:mm:ss", // + "h:mm:ss a d MMM y", // "H:mm:ss d MMM y" + "H:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' H:mm:ss 'hrs'" + "EEE, d MMM y 'aha' H:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' h'h'mm'm'ss a", // "EEE, d MMM y 'aha' H'h'mm'm'ss" + "EEE, d MMM y 'aha' H'h'mm'm'ss", // + + "uuuu-MM-dd h:mm:ss a '+0000'", // + + NULL +}; + +static const char * remapResults_en_IN[] = { // rdar://56309604 + "h:mm:ss a zzzz", // full + "HH:mm:ss zzzz", // force24 + "h:mm:ss a zzzz", // force12 + "h:mm:ss a z", // long + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + "h:mm:ss a", // medium + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "h:mm a", // short + "HH:mm", // force24 + "h:mm a", // force12 + "EEEE, d MMMM y 'at' h:mm:ss a z", // long_df + "EEEE, d MMMM y 'at' HH:mm:ss z", // force24 + "EEEE, d MMMM y 'at' h:mm:ss a z", // force12 + "dd/MM/yy, h:mm a", // short_ds + "dd/MM/yy, HH:mm", // force24 + "dd/MM/yy, h:mm a", // force12 + + "h:mm:ss a", // jmmss + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "h:mm:ss a", // jjmmss + "HH:mm:ss", // force24 + "HH:mm:ss", // force24 | match hour field length + "h:mm:ss a", // force12 + "hh:mm:ss a", // force12 | match hour field length + "hh:mm", // Jmm + "HH:mm", // force24 + "hh:mm", // force12 + "h:mm:ss a v", // jmsv + "HH:mm:ss v", // force24 + "h:mm:ss a v", // force12 + "h:mm:ss a z", // jmsz + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + + "h:mm:ss a", // "h:mm:ss" + "HH:mm:ss", // + "a'xx'h:mm:ss d MMM y", // "a'xx'h:mm:ss d MMM y" + "HH:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' h:mm:ss a 'hrs'" + "EEE, d MMM y 'aha' HH:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' a'xx'h:mm:ss", // "EEE, d MMM y 'aha' a'xx'h:mm:ss" + "EEE, d MMM y 'aha' HH:mm:ss", // + "yyMMddhhmmss", // "yyMMddhhmmss" + "yyMMddHHmmss", // + + "h:mm:ss a", // "H:mm:ss" + "H:mm:ss", // + "h:mm:ss a d MMM y", // "H:mm:ss d MMM y" + "H:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' H:mm:ss 'hrs'" + "EEE, d MMM y 'aha' H:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' h'h'mm'm'ss a", // "EEE, d MMM y 'aha' H'h'mm'm'ss" + "EEE, d MMM y 'aha' H'h'mm'm'ss", // + + "uuuu-MM-dd h:mm:ss a '+0000'", // + + NULL +}; + +static const char * remapResults_en_IN_japanese[] = { // rdar://56309604 + "h:mm:ss a zzzz", // full + "HH:mm:ss zzzz", // force24 + "h:mm:ss a zzzz", // force12 + "h:mm:ss a z", // long + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + "h:mm:ss a", // medium + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "h:mm a", // short + "HH:mm", // force24 + "h:mm a", // force12 + "EEEE, d MMMM y G 'at' h:mm:ss a z", // long_df + "EEEE, d MMMM y G 'at' HH:mm:ss z", // force24 + "EEEE, d MMMM y G 'at' h:mm:ss a z", // force12 + "dd/MM/y GGGGG, h:mm a", // short_ds + "dd/MM/y GGGGG, HH:mm", // force24 + "dd/MM/y GGGGG, h:mm a", // force12 + + "h:mm:ss a", // jmmss + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "h:mm:ss a", // jjmmss + "HH:mm:ss", // force24 + "HH:mm:ss", // force24 | match hour field length + "h:mm:ss a", // force12 + "hh:mm:ss a", // force12 | match hour field length + "hh:mm", // Jmm + "HH:mm", // force24 + "hh:mm", // force12 + "h:mm:ss a v", // jmsv + "HH:mm:ss v", // force24 + "h:mm:ss a v", // force12 + "h:mm:ss a z", // jmsz + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + + "h:mm:ss a", // "h:mm:ss" + "HH:mm:ss", // + "a'xx'h:mm:ss d MMM y", // "a'xx'h:mm:ss d MMM y" + "HH:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' h:mm:ss a 'hrs'" + "EEE, d MMM y 'aha' HH:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' a'xx'h:mm:ss", // "EEE, d MMM y 'aha' a'xx'h:mm:ss" + "EEE, d MMM y 'aha' HH:mm:ss", // + "yyMMddhhmmss", // "yyMMddhhmmss" + "yyMMddHHmmss", // + + "h:mm:ss a", // "H:mm:ss" + "H:mm:ss", // + "h:mm:ss a d MMM y", // "H:mm:ss d MMM y" + "H:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' H:mm:ss 'hrs'" + "EEE, d MMM y 'aha' H:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' h'h'mm'm'ss a", // "EEE, d MMM y 'aha' H'h'mm'm'ss" + "EEE, d MMM y 'aha' H'h'mm'm'ss", // + + "uuuu-MM-dd h:mm:ss a '+0000'", // + + NULL +}; + +static const char * remapResults_en_BE[] = { // rdar://56309604 + "HH:mm:ss zzzz", // full + "HH:mm:ss zzzz", // force24 + "h:mm:ss a zzzz", // force12 + "HH:mm:ss z", // long + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + "HH:mm:ss", // medium + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "HH:mm", // short + "HH:mm", // force24 + "h:mm a", // force12 + "EEEE, d MMMM y 'at' HH:mm:ss z", // long_df + "EEEE, d MMMM y 'at' HH:mm:ss z", // force24 + "EEEE, d MMMM y 'at' h:mm:ss a z", // force12 + "dd/MM/y, HH:mm", // short_ds + "dd/MM/y, HH:mm", // force24 + "dd/MM/y, h:mm a", // force12 + + "HH:mm:ss", // jmmss + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "HH:mm:ss", // jjmmss + "HH:mm:ss", // force24 + "HH:mm:ss", // force24 | match hour field length + "h:mm:ss a", // force12 + "hh:mm:ss a", // force12 | match hour field length + "HH:mm", // Jmm + "HH:mm", // force24 + "hh:mm", // force12 + "HH:mm:ss v", // jmsv + "HH:mm:ss v", // force24 + "h:mm:ss a v", // force12 + "HH:mm:ss z", // jmsz + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + + "h:mm:ss a", // "h:mm:ss" force12 + "HH:mm:ss", // force24 + "a'xx'h:mm:ss d MMM y", // "a'xx'h:mm:ss d MMM y" force12 + "HH:mm:ss d MMM y", // force24 + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' h:mm:ss a 'hrs'" force12 + "EEE, d MMM y 'aha' HH:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' a'xx'h:mm:ss", // "EEE, d MMM y 'aha' a'xx'h:mm:ss" + "EEE, d MMM y 'aha' HH:mm:ss", // + "yyMMddhhmmss", // "yyMMddhhmmss" force12 + "yyMMddHHmmss", // + + "h:mm:ss a", // "H:mm:ss" + "H:mm:ss", // + "h:mm:ss a d MMM y", // "H:mm:ss d MMM y" + "H:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' H:mm:ss 'hrs'" + "EEE, d MMM y 'aha' H:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' h'h'mm'm'ss a", // "EEE, d MMM y 'aha' H'h'mm'm'ss" + "EEE, d MMM y 'aha' H'h'mm'm'ss", // + + "uuuu-MM-dd h:mm:ss a '+0000'", // + + NULL +}; + +static const char * remapResults_en_BE_japanese[] = { // rdar://56309604 + "HH:mm:ss zzzz", // full + "HH:mm:ss zzzz", // force24 + "h:mm:ss a zzzz", // force12 + "HH:mm:ss z", // long + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + "HH:mm:ss", // medium + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "HH:mm", // short + "HH:mm", // force24 + "h:mm a", // force12 + "EEEE, d MMMM y G 'at' HH:mm:ss z", // long_df + "EEEE, d MMMM y G 'at' HH:mm:ss z", // force24 + "EEEE, d MMMM y G 'at' h:mm:ss a z", // force12 + "dd/MM/y GGGGG, HH:mm", // short_ds + "dd/MM/y GGGGG, HH:mm", // force24 + "dd/MM/y GGGGG, h:mm a", // force12 + + "HH:mm:ss", // jmmss + "HH:mm:ss", // force24 + "h:mm:ss a", // force12 + "HH:mm:ss", // jjmmss + "HH:mm:ss", // force24 + "HH:mm:ss", // force24 | match hour field length + "h:mm:ss a", // force12 + "hh:mm:ss a", // force12 | match hour field length + "HH:mm", // Jmm + "HH:mm", // force24 + "hh:mm", // force12 + "HH:mm:ss v", // jmsv + "HH:mm:ss v", // force24 + "h:mm:ss a v", // force12 + "HH:mm:ss z", // jmsz + "HH:mm:ss z", // force24 + "h:mm:ss a z", // force12 + + "h:mm:ss a", // "h:mm:ss" force12 + "HH:mm:ss", // force24 + "a'xx'h:mm:ss d MMM y", // "a'xx'h:mm:ss d MMM y" force12 + "HH:mm:ss d MMM y", // force24 + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' h:mm:ss a 'hrs'" force12 + "EEE, d MMM y 'aha' HH:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' a'xx'h:mm:ss", // "EEE, d MMM y 'aha' a'xx'h:mm:ss" + "EEE, d MMM y 'aha' HH:mm:ss", // + "yyMMddhhmmss", // "yyMMddhhmmss" force12 + "yyMMddHHmmss", // + + "h:mm:ss a", // "H:mm:ss" + "H:mm:ss", // + "h:mm:ss a d MMM y", // "H:mm:ss d MMM y" + "H:mm:ss d MMM y", // + "EEE, d MMM y 'aha' h:mm:ss a 'hrs'", // "EEE, d MMM y 'aha' H:mm:ss 'hrs'" + "EEE, d MMM y 'aha' H:mm:ss 'hrs'", // + "EEE, d MMM y 'aha' h'h'mm'm'ss a", // "EEE, d MMM y 'aha' H'h'mm'm'ss" + "EEE, d MMM y 'aha' H'h'mm'm'ss", // + + "uuuu-MM-dd h:mm:ss a '+0000'", // + + NULL +}; + typedef struct { const char * locale; const char ** resultsPtr; @@ -2843,6 +3452,11 @@ static const RemapPatternLocaleResults remapLocResults[] = { { "hi", remapResults_hi }, { "ar", remapResults_ar }, { "en_IL", remapResults_en_IL }, + { "es_PR@calendar=japanese", remapResults_es_PR_japanese }, + { "en_IN", remapResults_en_IN }, + { "en_IN@calendar=japanese", remapResults_en_IN_japanese }, + { "en_BE", remapResults_en_BE }, + { "en_BE@calendar=japanese", remapResults_en_BE_japanese }, { NULL, NULL } }; @@ -2911,4 +3525,483 @@ static void TestRemapPatternWithOpts(void) { /* Apple-specific */ } } +#if ADD_ALLOC_TEST +#include +#include +static const UChar* tzName = u"US/Pacific"; +static const UDate udatToUse = 1290714600000.0; // Thurs, Nov. 25, 2010 11:50:00 AM PT +static const UChar* dateStrEST = u"Thursday, November 25, 2010 at 11:50:00 AM EST"; +enum { kUCharsOutMax = 128, kBytesOutMax = 256, kRepeatCount = 100, SLEEPSECS = 6 }; + +static void TestPerf(void) { + UDateFormat *udatfmt; + UErrorCode status = U_ZERO_ERROR; + printf("\n# TestPerf start; sleeping %d seconds to check heap.\n", SLEEPSECS); sleep(SLEEPSECS); + udatfmt = udat_open(UDAT_FULL, UDAT_FULL, "en_US", tzName, -1, NULL, 0, &status); + if ( U_SUCCESS(status) ) { + UChar outUChars[kUCharsOutMax]; + int32_t count, datlen, datlen2, parsePos; + UDate dateParsed, dateParsed2; + + datlen = udat_format(udatfmt, udatToUse, outUChars, kUCharsOutMax, NULL, &status); + printf("# TestPerf after first open & format, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS); + + for (count = kRepeatCount; count-- > 0;) { + status = U_ZERO_ERROR; + datlen2 = udat_format(udatfmt, udatToUse, outUChars, kUCharsOutMax, NULL, &status); + if ( U_FAILURE(status) || datlen2 != datlen ) { + printf("# TestPerf udat_format unexpected result.\n"); + break; + } + } + printf("# TestPerf after many more format, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS); + + udat_setLenient(udatfmt, TRUE); + status = U_ZERO_ERROR; + parsePos = 0; + dateParsed = udat_parse(udatfmt, dateStrEST, -1, &parsePos, &status); + printf("# TestPerf after first parse lenient diff style/zone, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS); + + for (count = kRepeatCount; count-- > 0;) { + status = U_ZERO_ERROR; + parsePos = 0; + dateParsed2 = udat_parse(udatfmt, dateStrEST, -1, &parsePos, &status); + if ( U_FAILURE(status) || dateParsed2 != dateParsed ) { + printf("# TestPerf udat_parse unexpected result.\n"); + break; + } + } + printf("# TestPerf after many more parse, status %d; sleeping %d seconds to check heap.\n", status, SLEEPSECS); sleep(SLEEPSECS); + + udat_close(udatfmt); + printf("# TestPerf after udat_close; sleeping %d seconds to check heap.\n", SLEEPSECS); sleep(SLEEPSECS); + } +} +#endif /* #if ADD_ALLOC_TEST */ + +#if WRITE_HOUR_MISMATCH_ERRS +// WriteHourMismatchErrs stuff 52980140 +#include +#include +#include + +static const char* langs[] = { + "ar", "ca", "cs", "da", "de", "el", "en", "es", "fi", "fr", "he", + "hi", "hr", "hu", "id", "it", "ja", "ko", "ms", "nb", "nl", "pl", + "pt", "ro", "ru", "sk", "sv", "th", "tr", "uk", "vi", "zh" }; // handle "yue" separately +enum { kNlangs = sizeof(langs)/sizeof(langs[0]) }; + +static const char* cals[] = { + "buddhist", + "chinese", + "coptic", + "ethiopic", + "gregorian", + "hebrew", + "indian", + "islamic-umalqura", + "islamic", + "japanese", + "persian", + NULL +}; + +enum { kLBufMax = 63 }; + +static int compKeys(const void* keyval, const void* baseval) { + const char* keystr = (const char*)keyval; + const char* basestr = *(const char**)baseval; + return strcmp(keystr,basestr); +} + +static UBool useLocale(const char* locale) { + if (strncmp(locale, "yue", 3) == 0) { + return TRUE; + } + if (locale[2]==0 || locale[2]=='_') { + char lang[3] = {0,0,0}; + strncpy(lang,locale,2); + if (bsearch(&lang, langs, kNlangs, sizeof(char*), compKeys) != NULL) { + return TRUE; + } + } + return FALSE; +} + +static UBool patIsBad(const UChar* ubuf) { + return (u_strchr(ubuf,0x251C)!=NULL || u_strchr(ubuf,0x2524)!=NULL || u_strstr(ubuf,u": ")!=NULL); +} + + +static void WriteHourMismatchErrs(void) { /* Apple-specific */ + int32_t iloc, nloc = uloc_countAvailable(); + int32_t errcnt = 0; + printf("# uloc_countAvailable: %d\n", nloc); + for (iloc = 0; iloc < nloc; iloc++) { + const char* locale = uloc_getAvailable(iloc); + if (useLocale(locale)) { + const char** calsPtr = cals; + const char* cal; + while ((cal = *calsPtr++) != NULL) { + char fullLocale[kLBufMax+1]; + UErrorCode status = U_ZERO_ERROR; + strncpy(fullLocale, locale, kLBufMax); + fullLocale[kLBufMax] = 0; + uloc_setKeywordValue("calendar", cal, fullLocale, kLBufMax, &status); + if ( U_SUCCESS(status) ) { + fullLocale[kLBufMax] = 0; + UDateFormat* udat = udat_open(UDAT_SHORT, UDAT_NONE, fullLocale, NULL, 0, NULL, 0, &status); + UDateTimePatternGenerator* udatpg = udatpg_open(fullLocale, &status); + if ( U_FAILURE(status) ) { + printf("# udat_open/udatpg_open for locale %s: %s\n", fullLocale, u_errorName(status)); + } else { + UChar ubufs[kUBufMax]; + UChar ubufp[kUBufMax]; + char bbufs[kBBufMax]; + char bbufpj[kBBufMax]; + char bbufpH[kBBufMax]; + char bbufph[kBBufMax]; + int32_t ulen; + int8_t errors[4] = {0,0,0,0}; + + status = U_ZERO_ERROR; + ulen = udat_toPattern(udat, FALSE, ubufs, kUBufMax, &status); + u_strToUTF8(bbufs, kBBufMax, NULL, ubufs, ulen, &status); + if ( U_FAILURE(status) ) { + printf("# udat_toPattern for locale %s: %s\n", fullLocale, u_errorName(status)); + strcpy(bbufs, "****"); + errors[0] = 3; + } else if (patIsBad(ubufs)) { + errors[0] = 2; + } + + status = U_ZERO_ERROR; + ulen = udatpg_getBestPattern(udatpg, u"jmm", 3, ubufp, kUBufMax, &status); + u_strToUTF8(bbufpj, kBBufMax, NULL, ubufp, ulen, &status); + if ( U_FAILURE(status) ) { + printf("# udatpg_getBestPat jmm for locale %s: %s\n", fullLocale, u_errorName(status)); + strcpy(bbufpj, "****"); + errors[1] = 3; + } else if (patIsBad(ubufp)) { + errors[1] = 2; + } else if (errors[0] == 0 && u_strcmp(ubufp,ubufs) != 0) { + errors[0] = 1; + } + + status = U_ZERO_ERROR; + ulen = udatpg_getBestPattern(udatpg, u"Hmm", 3, ubufp, kUBufMax, &status); + u_strToUTF8(bbufpH, kBBufMax, NULL, ubufp, ulen, &status); + if ( U_FAILURE(status) ) { + printf("# udatpg_getBestPat Hmm for locale %s: %s\n", fullLocale, u_errorName(status)); + strcpy(bbufpH, "****"); + errors[2] = 3; + } else if (patIsBad(ubufp)) { + errors[2] = 2; + } + + status = U_ZERO_ERROR; + ulen = udatpg_getBestPattern(udatpg, u"hmm", 3, ubufp, kUBufMax, &status); + u_strToUTF8(bbufph, kBBufMax, NULL, ubufp, ulen, &status); + if ( U_FAILURE(status) ) { + printf("# udatpg_getBestPat hmm for locale %s: %s\n", fullLocale, u_errorName(status)); + strcpy(bbufph, "****"); + errors[3] = 3; + } else if (patIsBad(ubufp)) { + errors[3] = 2; + } + + if ( errors[0] || errors[1] || errors[2] || errors[3]) { + printf("%-36s\tshr-%d %-8s\tjmm-%d %-18s\tHmm-%d %-18s\thmm-%d %-18s\n", fullLocale, + errors[0], bbufs, errors[1], bbufpj, errors[2], bbufpH, errors[3], bbufph); + errcnt++; + } + + udatpg_close(udatpg); + udat_close(udat); + } + } + } + } + } + printf("# total err lines: %d\n", errcnt); +} +#endif /* #if WRITE_HOUR_MISMATCH_ERRS */ + +#if WRITE_COUNTRY_FALLBACK_RESULTS +// A utility program for printing out the results of our formatting code for vetting. The list of locales +// below is the top 100 non-default-language locales from internal statistics on system locales. +static void WriteCountryFallbackResults(void) { /* Apple */ + char* systemLanguages[] = { + "en", + "zh-Hans", + "zh-Hant", + "ja", + "es", + "fr", + "de", + "ru", + "pt", + "it", + "ko", + "tr", + "nl", + "ar", + "th", + "sv", + "da", + "vi", + "nb", + "pl", + "fi", + "id", + "he", + "el", + "ro", + "hu", + "cs", + "ca", + "sk", + "uk", + "hr", + "ms", + "hi", + }; + char* styleNames[] = { + "full", + "long", + "medium", + "short" + }; + + UErrorCode err = U_ZERO_ERROR; + UCalendar* cal = ucal_open(NULL, -1, "en_US", UCAL_GREGORIAN, &err); + ucal_setDateTime(cal, 2017, UCAL_DECEMBER, 24, 20, 35, 15, &err); + assertSuccess("Error creating test calendar", &err); + const char* const* countries = uloc_getISOCountries(); + + printf("locale\tstyle\tafter\n"); + for (int32_t i = 0; i < (sizeof(systemLanguages) / sizeof(char*)); i++) { + const char* language = systemLanguages[i]; + char errorMessage[200]; + err = U_ZERO_ERROR; + + char locale[50]; +// UChar defaultResults[4][200]; + + uloc_addLikelySubtags(language, locale, 50, &err); +// uloc_minimizeSubtags(locale, locale, 50, &err); + if (U_FAILURE(err)) { + continue; + } +// for (UDateFormatStyle style = UDAT_FULL; style <= UDAT_SHORT; ++style) { +// err = U_ZERO_ERROR; +// UDateFormat* df = udat_open(/*style*/UDAT_NONE, style, locale, NULL, 0, NULL, 0, &err); +// UChar formattedDate[200]; +// +// udat_formatCalendar(df, cal, formattedDate, 200, NULL, &err); +// assertSuccess("Error formatting date", &err); +// +// printf("%s\t%s\t%s\t%s\n", locale, "D", styleNames[style], austrdup(formattedDate)); +// u_strcpy(defaultResults[style], formattedDate); +// +// udat_close(df); +// } + + for (int32_t j = 0; countries[j] != NULL; j++) { + sprintf(locale, "%s_%s", language, countries[j]); + +// UBool hasResourceBundle = FALSE; +// UResourceBundle* bundle = ures_open(NULL, locale, &err); +// hasResourceBundle = err != U_USING_FALLBACK_WARNING; +// ures_close(bundle); + + for (UDateFormatStyle style = UDAT_FULL; style <= UDAT_SHORT; ++style) { + err = U_ZERO_ERROR; + UDateFormat* df = udat_open(/*style*/UDAT_NONE, style, locale, NULL, 0, NULL, 0, &err); + UChar formattedDate[200]; + + udat_formatCalendar(df, cal, formattedDate, 200, NULL, &err); + assertSuccess("Error formatting date", &err); + +// if (u_strcmp(defaultResults[style], formattedDate) != 0) { + printf("%s\t%s\t%s\n", locale, styleNames[style], austrdup(formattedDate)); +// } + + udat_close(df); + } + } + } + ucal_close(cal); +} +#endif /*WRITE_COUNTRY_FALLBACK_RESULTS*/ + +UBool stringsEqualWithoutBidiMarks(const UChar* s1, const UChar* s2) { + while (*s1 != u'\0' || *s2 != u'\0') { + if (*s1 == *s2) { + ++s1; + ++s2; + } else if (*s1 == u'\u200f') { + ++s1; + } else if (*s2 == u'\u200f') { + ++s2; + } else { + return FALSE; + } + } + return TRUE; +} + +static void TestCountryFallback(void) { /* Apple */ + // The columns in the table below are as follows: + // 1: The test locale ID. The locale for which we're testing the date formats. + // 2: Long date locale. The full and long date formats for the test locale should match this locale. + // 3: Medium date locale. The medium date format for the test locale should match this locale. If this starts with + // a *, compare against the SHORT date format from this locale (without the *, of course) + // 4: Short date locale. The short date format for the test locale should match this locale. + char* testData[] = { + // The following locales were previously handled by adding resource bundles. If the short or medium date formats + // in the resources don't match what the algorithmic solution would produce, that's called out in the comments. + // If the full or long formats are different, or there's no fallback resource we can match, the whole line + // is commented out. + "en_AD", "en_150", "ca_AD", "ca_AD", + "en_AR", "en_001", "es_AR", "en_001", // short date pattern for es_AR is different? +// "en_BR", "en_001", "en_001", "en_001", // short date pattern is different from both pt_BR and en_001 + "en_CL", "en_001", "es_CL", "es_CL", + "en_CN", "en", "en", "zh_CN", +// "en_CO", "en_001", "*es_CO", "es_CO", // medium date pattern is wrong? +// "en_DE", "de_DE", "de_DE", "de_DE", // medium date pattern is wrong? + "en_ER", "en_001", "en_001", "en_001", // short date pattern for ti_ER is different? + "en_ES", "en_150", "en_150", "es_ES", + "en_GH", "en_001", "en_001", "en_001", // short date pattern for ak_GH is different? + "en_GR", "en_150", "el_GR", "el_GR", + "en_HK", "en_001", "en_001", "zh_HK", + "en_IS", "en_150", "en_150", "is_IS", + "en_IT", "en_150", "en_150", "it_IT", + "en_JP", "en", "en", "ja_JP", +// "en_KR", "en", "en", "ko_KR", // short date pattern is different? + "en_LU", "en_150", "fr_LU", "fr_LU", + "en_ME", "en_150", "sr_ME", "sr_ME", + "en_MO", "en_001", "en_001", "en_001", // short and medium date patterns for zh_MO are different? +// "en_MT", "en_150", "en_150", "mt_MT", // several patterns are different from both en_150 and mt_MT + "en_MX", "en_001", "es_MX", "es_MX", + "en_MY", "en_001", "en_001", "en_001", // short date pattern for ms_MY is different? + "en_NL", "en_150", "en_150", "en_150", // short date pattern for nl_NL is different? + "en_PH", "en", "fil_PH", "fil_PH", + "en_RO", "en_150", "en_150", "ro_RO", + "en_RS", "en_150", "sr_RS", "sr_RS", +// "en_TR", "en_150", "en_150", "tr_TR", // long date pattern for en_150 is different + "en_TW", "en", "en", "zh_TW", +// "en_ZW", "en_001", "en_001", "sn_ZW", // all date patterns are different from en_001 and sn_ZW + "es_US", "es_419", "en_US", "en_US", + + // The following locales are specifically mentioned in Radars (some of these have resource bundles too): + "fr_US", "fr", "fr", "en_US", // rdar://problem/54886964 +// "en_TH", "en_001", "en_001", "en_001", // rdar://problem/29299919 (the en_TH resource has era fields, even in Gregorian calendar, and they're in a different place than for the Buddhist calendar) +// "en_BG", "en_150", "en_150", "en_150", // rdar://problem/29299919 (all date patterns for bg_BG have "'г'." at the end, short date pattern also doesn't match en_150) + "fr_BG", "fr", "fr", "fr", // rdar://64135398 + "en_LI", "en_150", "de_LI", "de_LI", // rdar://problem/29299919 + "en_MC", "en_150", "fr_MC", "fr_MC", // rdar://problem/29299919 + "en_MD", "en_150", "ro_MD", "ro_MD", // rdar://problem/29299919 + "en_VA", "en_150", "it_VA", "it_VA", // rdar://problem/29299919 + "fr_GB", "fr", "fr", "en_GB", // rdar://problem/36020946 + "fr_CN", "fr", "fr", "zh_CN", // rdar://problem/50083902 + "es_IE", "es", "es", "en_IE", // rdar://problem/58733843 + "de_US", "de", "*en_US", "en_US", // rdar://problem/31169349 (I think we no longer address this Radar...) +// "en_CZ", "en_150", "cs_CZ", "cs_CZ", // rdar://problem/57625632 (Long date format doesn't match en_150) + + // Special for en_SA, date formats should match those for en_001, other items match en + "en_SA", "en_001@calendar=islamic-umalqura", "en_001@calendar=islamic-umalqura", "en_001@calendar=islamic-umalqura", + + // Tests for situations where the default calendar and/or numbering system is different depending on whether you + // fall back by language or by country: + "ar_US", "ar", "ar", "ar", + "ar_DE", "ar", "ar", "ar", // rdar://67971515 + "ar_FR", "ar", "ar", "ar", // rdar://67971515 + "en_EG", "en_001", "en_001", "en_001", // rdar://69523017 + + // Tests for situations where the original locale ID specifies a script: + // this one doesn't fall back to ar_SA because even the "short" date format in arSA is non-numeric + "sr_Cyrl_SA", "sr_Cyrl@calendar=islamic-umalqura", "sr_Cyrl@calendar=islamic-umalqura", "sr_Cyrl@calendar=islamic-umalqura", + "ru_Cyrl_BA", "ru_Cyrl", "bs_Cyrl_BA", "bs_Cyrl_BA", + + // And these are just a few additional arbitrary combinations: + "ja_US", "ja", "*en_US", "en_US", + "fr_DE", "fr", "de_DE", "de_DE", + "de_FR", "de", "*fr_FR", "fr_FR", + "es_TW", "es", "es", "zh_TW", + "en_BH", "en_001", "en_001", "en_001", + // Test to make sure that nothing goes wrong if language and country fallback both lead to the same resource + // (This won't happen for any "real" locales, because ICU has resources for all of them, but we can fake it with + // a nonexistent country code such as QQ.) + "en_QQ", "en", "en", "en" + }; + + for (int32_t i = 0; i < (sizeof(testData) / sizeof(char*)); i += 4) { + const char* testLocale = testData[i]; + const char* longDateLocale = testData[i + 1]; + const char* mediumDateLocale = testData[i + 2]; + const char* shortDateLocale = testData[i + 3]; + char errorMessage[200]; + UErrorCode err = U_ZERO_ERROR; + + // Check that the date formatting patterns for the test locale are the same as those for the fallback locale. + for (UDateFormatStyle style = UDAT_FULL; style <= UDAT_SHORT; ++style) { + err = U_ZERO_ERROR; + UDateFormat* testFormatter = udat_open(UDAT_NONE, style, testLocale, NULL, 0, NULL, 0, &err); + const char* comparisonLocale = longDateLocale; + if (style == UDAT_MEDIUM) { + comparisonLocale = mediumDateLocale; + } else if (style == UDAT_SHORT) { + comparisonLocale = shortDateLocale; + } + UDateFormat* comparisonFormatter = NULL; + if (comparisonLocale[0] == '*') { + // if the comparison locale starts with a *, strip off the * and retrieve the SHORT date format + // from that locale regardless of what style we're actually on (should only happen when + // style is UDAT_MEDIUM) + comparisonFormatter = udat_open(UDAT_NONE, UDAT_SHORT, &(comparisonLocale[1]), NULL, 0, NULL, 0, &err); + } else { + comparisonFormatter = udat_open(UDAT_NONE, style, comparisonLocale, NULL, 0, NULL, 0, &err); + } + + sprintf(errorMessage, "Error creating formatters for %s and %s", testLocale, comparisonLocale); + if (assertSuccess(errorMessage, &err)) { + UChar testPattern[100]; + UChar comparisonPattern[100]; + + udat_toPattern(testFormatter, FALSE, testPattern, 100, &err); + udat_toPattern(comparisonFormatter, FALSE, comparisonPattern, 100, &err); + + if (assertSuccess("Error getting date format patterns", &err)) { + sprintf(errorMessage, "In %s, formatting pattern for style %d doesn't match: expected %s, got %s", testLocale, style, austrdup(comparisonPattern), austrdup(testPattern)); + assertTrue(errorMessage, stringsEqualWithoutBidiMarks(comparisonPattern, testPattern)); + } + + const UNumberFormat* testNF = udat_getNumberFormat(testFormatter); + const UNumberFormat* comparisonNF = udat_getNumberFormat(comparisonFormatter); + UChar testZeroDigit[5]; + UChar comparisonZeroDigit[5]; + unum_getSymbol(testNF, UNUM_ZERO_DIGIT_SYMBOL, testZeroDigit, 5, &err); + unum_getSymbol(comparisonNF, UNUM_ZERO_DIGIT_SYMBOL, comparisonZeroDigit, 5, &err); + + if (assertSuccess("Error getting zero digits", &err)) { + sprintf(errorMessage, "In %s, zero digits for style %d don't match: ", testLocale, style); + assertUEquals(errorMessage, comparisonZeroDigit, testZeroDigit); + } + } + udat_close(testFormatter); + udat_close(comparisonFormatter); + } + + // The TestCountryFallback test for number formatting also checks to make sure that we still fall back by + // language for certain number formatting symbols. The time and date+time patterns should continue to fall back + // by language, but we don't test that here for two reasons: a) There's no way to explicitly get the date+time + // pattern by itself, and b) even though time patterns technically fall back by language, there's extra logic + // to synthesize a time pattern in cases where there's no resource bundle for the requested locale and the + // requested country has a different time cycle than the default country for the requested language. + // Accounting for both of these would require changing this test to compare the results against hard-coded + // pattern strings, which I don't want to do yet. --rtg 4/30/20 + // (NOTE: I might need to change the comment above when I fix rdar://problem/62242807) + } +} #endif /* #if !UCONFIG_NO_FORMATTING */