X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/f3c0d7a59d99c2a94c6b8822291f0e42be3773c9..HEAD:/icuSources/test/intltest/tzfmttst.cpp?ds=sidebyside diff --git a/icuSources/test/intltest/tzfmttst.cpp b/icuSources/test/intltest/tzfmttst.cpp index 0c14eec5..40362aac 100644 --- a/icuSources/test/intltest/tzfmttst.cpp +++ b/icuSources/test/intltest/tzfmttst.cpp @@ -21,6 +21,7 @@ #include "unicode/basictz.h" #include "unicode/tzfmt.h" #include "unicode/localpointer.h" +#include "unicode/utf16.h" #include "cstring.h" #include "cstr.h" @@ -83,7 +84,9 @@ TimeZoneFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &name TESTCASE(4, TestFormat); TESTCASE(5, TestFormatTZDBNames); TESTCASE(6, TestFormatCustomZone); - default: name = ""; break; + TESTCASE(7, TestFormatTZDBNamesAllZoneCoverage); + TESTCASE(8, TestAdoptDefaultThreadSafe); + default: name = ""; break; } } @@ -139,7 +142,9 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { Locale("en"), Locale("en_CA"), Locale("fr"), - Locale("zh_Hant") + Locale("zh_Hant"), + Locale("fa"), + Locale("ccp") }; const Locale *LOCALES; @@ -168,7 +173,6 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { gmtFmt.format(0.0, localGMTString); for (int32_t patidx = 0; patidx < UPRV_LENGTHOF(PATTERNS); patidx++) { - SimpleDateFormat *sdf = new SimpleDateFormat((UnicodeString)PATTERNS[patidx], LOCALES[locidx], status); if (U_FAILURE(status)) { dataerrln((UnicodeString)"new SimpleDateFormat failed for pattern " + @@ -299,10 +303,13 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { if (!isOffsetFormat) { // Check if localized GMT format is used as a fallback of name styles int32_t numDigits = 0; - for (int n = 0; n < tzstr.length(); n++) { - if (u_isdigit(tzstr.charAt(n))) { + int32_t idx = 0; + while (idx < tzstr.length()) { + UChar32 cp = tzstr.char32At(idx); + if (u_isdigit(cp)) { numDigits++; } + idx += U16_LENGTH(cp); } isOffsetFormat = (numDigits > 0); } @@ -403,7 +410,7 @@ struct LocaleData { for (int i=0; isetTimeZone(*tz); @@ -710,6 +712,44 @@ void TimeZoneFormatTest::RunTimeRoundTripTests(int32_t threadNumber) { delete tzids; } +void +TimeZoneFormatTest::TestAdoptDefaultThreadSafe(void) { + ThreadPool threads(this, threadCount, &TimeZoneFormatTest::RunAdoptDefaultThreadSafeTests); + threads.start(); // Start all threads. + threads.join(); // Wait for all threads to finish. +} + +static const int32_t kAdoptDefaultIteration = 10; +static const int32_t kCreateDefaultIteration = 5000; +static const int64_t kStartTime = 1557288964845; + +void TimeZoneFormatTest::RunAdoptDefaultThreadSafeTests(int32_t threadNumber) { + UErrorCode status = U_ZERO_ERROR; + if (threadNumber % 2 == 0) { + for (int32_t i = 0; i < kAdoptDefaultIteration; i++) { + std::unique_ptr timezones( + icu::TimeZone::createEnumeration()); + // Fails with missing data. + if (!assertTrue(WHERE, (bool)timezones, false, true)) {return;} + while (const icu::UnicodeString* timezone = timezones->snext(status)) { + status = U_ZERO_ERROR; + icu::TimeZone::adoptDefault(icu::TimeZone::createTimeZone(*timezone)); + } + } + } else { + int32_t rawOffset; + int32_t dstOffset; + int64_t date = kStartTime; + for (int32_t i = 0; i < kCreateDefaultIteration; i++) { + date += 6000 * i; + std::unique_ptr tz(icu::TimeZone::createDefault()); + status = U_ZERO_ERROR; + tz->getOffset(date, TRUE, rawOffset, dstOffset, status); + status = U_ZERO_ERROR; + tz->getOffset(date, FALSE, rawOffset, dstOffset, status); + } + } +} typedef struct { const char* text; @@ -1257,5 +1297,47 @@ TimeZoneFormatTest::TestFormatCustomZone(void) { } } +void +TimeZoneFormatTest::TestFormatTZDBNamesAllZoneCoverage(void) { + UErrorCode status = U_ZERO_ERROR; + LocalPointer tzids(TimeZone::createEnumeration()); + if (tzids.getAlias() == nullptr) { + dataerrln("%s %d tzids is null", __FILE__, __LINE__); + return; + } + const UnicodeString *tzid; + LocalPointer tzdbNames(TimeZoneNames::createTZDBInstance(Locale("en"), status)); + UDate now = Calendar::getNow(); + UnicodeString mzId; + UnicodeString name; + while ((tzid = tzids->snext(status))) { + logln("Zone: " + *tzid); + LocalPointer tz(TimeZone::createTimeZone(*tzid)); + tzdbNames->getMetaZoneID(*tzid, now, mzId); + if (mzId.isBogus()) { + logln((UnicodeString)"Meta zone: "); + } else { + logln((UnicodeString)"Meta zone: " + mzId); + } + + // mzID could be bogus here + tzdbNames->getMetaZoneDisplayName(mzId, UTZNM_SHORT_STANDARD, name); + // name could be bogus here + if (name.isBogus()) { + logln((UnicodeString)"Meta zone short standard name: "); + } + else { + logln((UnicodeString)"Meta zone short standard name: " + name); + } + tzdbNames->getMetaZoneDisplayName(mzId, UTZNM_SHORT_DAYLIGHT, name); + // name could be bogus here + if (name.isBogus()) { + logln((UnicodeString)"Meta zone short daylight name: "); + } + else { + logln((UnicodeString)"Meta zone short daylight name: " + name); + } + } +} #endif /* #if !UCONFIG_NO_FORMATTING */