#include "unicode/basictz.h"
#include "unicode/tzfmt.h"
#include "unicode/localpointer.h"
+#include "unicode/utf16.h"
#include "cstring.h"
#include "cstr.h"
TESTCASE(4, TestFormat);
TESTCASE(5, TestFormatTZDBNames);
TESTCASE(6, TestFormatCustomZone);
- default: name = ""; break;
+ TESTCASE(7, TestFormatTZDBNamesAllZoneCoverage);
+ TESTCASE(8, TestAdoptDefaultThreadSafe);
+ default: name = ""; break;
}
}
Locale("en"),
Locale("en_CA"),
Locale("fr"),
- Locale("zh_Hant")
+ Locale("zh_Hant"),
+ Locale("fa"),
+ Locale("ccp")
};
const Locale *LOCALES;
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 " +
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);
}
for (int i=0; i<UPRV_LENGTHOF(times); i++) {
times[i] = 0;
}
- };
+ }
void resetTestIteration() {
localeIndex = -1;
Locale("ko_KR"), Locale("nb_NO"), Locale("nl_NL"), Locale("nn_NO"), Locale("pl_PL"),
Locale("pt"), Locale("pt_BR"), Locale("pt_PT"), Locale("ru_RU"), Locale("sv_SE"),
Locale("th_TH"), Locale("tr_TR"), Locale("zh"), Locale("zh_Hans"), Locale("zh_Hans_CN"),
- Locale("zh_Hant"), Locale("zh_Hant_TW")
+ Locale("zh_Hant"), Locale("zh_Hant_TW"), Locale("fa"), Locale("ccp")
};
if (bTestAll) {
}
}
- if (*tzid == "Pacific/Apia" && uprv_strcmp(PATTERNS[patidx], "vvvv") == 0
+ if ((*tzid == "Pacific/Apia" || *tzid == "Pacific/Midway" || *tzid == "Pacific/Pago_Pago")
+ && uprv_strcmp(PATTERNS[patidx], "vvvv") == 0
&& logKnownIssue("11052", "Ambiguous zone name - Samoa Time")) {
continue;
}
- // skip some zone/format combinations until we have a metazone for them and/or
- // better fallback zone formatting...
- if ((*tzid == "America/Punta_Arenas" || *tzid == "Antarctica/Palmer") &&
- uprv_strcmp(PATTERNS[patidx], "zzzz") == 0) {
- continue;
- }
BasicTimeZone *tz = (BasicTimeZone*) TimeZone::createTimeZone(*tzid);
sdf->setTimeZone(*tz);
delete tzids;
}
+void
+TimeZoneFormatTest::TestAdoptDefaultThreadSafe(void) {
+ ThreadPool<TimeZoneFormatTest> 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<icu::StringEnumeration> 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<icu::TimeZone> 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;
}
}
+void
+TimeZoneFormatTest::TestFormatTZDBNamesAllZoneCoverage(void) {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<StringEnumeration> tzids(TimeZone::createEnumeration());
+ if (tzids.getAlias() == nullptr) {
+ dataerrln("%s %d tzids is null", __FILE__, __LINE__);
+ return;
+ }
+ const UnicodeString *tzid;
+ LocalPointer<TimeZoneNames> tzdbNames(TimeZoneNames::createTZDBInstance(Locale("en"), status));
+ UDate now = Calendar::getNow();
+ UnicodeString mzId;
+ UnicodeString name;
+ while ((tzid = tzids->snext(status))) {
+ logln("Zone: " + *tzid);
+ LocalPointer<TimeZone> tz(TimeZone::createTimeZone(*tzid));
+ tzdbNames->getMetaZoneID(*tzid, now, mzId);
+ if (mzId.isBogus()) {
+ logln((UnicodeString)"Meta zone: <not available>");
+ } 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: <not available>");
+ }
+ 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: <not available>");
+ }
+ else {
+ logln((UnicodeString)"Meta zone short daylight name: " + name);
+ }
+ }
+}
#endif /* #if !UCONFIG_NO_FORMATTING */