From 76444a4b71a874b978a3c52e9d0f3cd43fdd83a9 Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Thu, 1 Mar 2012 05:27:43 +0000 Subject: [PATCH] ICU-8716 Fix errors in cintltst and intltest when data is missing X-SVN-Rev: 31552 --- icu4c/source/i18n/smpdtfmt.cpp | 4 +++- icu4c/source/i18n/timezone.cpp | 12 ++++++++++++ icu4c/source/test/cintltst/cdattst.c | 2 +- icu4c/source/test/intltest/tzfmttst.cpp | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 8aed26cb332..ad55de49a90 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -3341,7 +3341,9 @@ SimpleDateFormat::tzFormat() const { if (fTimeZoneFormat == NULL) { UErrorCode status = U_ZERO_ERROR; TimeZoneFormat *tzfmt = TimeZoneFormat::createInstance(fLocale, status); - U_ASSERT(U_SUCCESS(status)); + if (U_FAILURE(status)) { + return NULL; + } const_cast(this)->fTimeZoneFormat = tzfmt; } diff --git a/icu4c/source/i18n/timezone.cpp b/icu4c/source/i18n/timezone.cpp index 0f04b335e97..197dbdde09f 100644 --- a/icu4c/source/i18n/timezone.cpp +++ b/icu4c/source/i18n/timezone.cpp @@ -1246,6 +1246,10 @@ TimeZone::getDisplayName(UBool daylight, EDisplayType style, const Locale& local if (style == GENERIC_LOCATION || style == LONG_GENERIC || style == SHORT_GENERIC) { LocalPointer tzfmt(TimeZoneFormat::createInstance(locale, status)); + if (U_FAILURE(status)) { + result.remove(); + return result; + } // Generic format switch (style) { case GENERIC_LOCATION: @@ -1269,6 +1273,10 @@ TimeZone::getDisplayName(UBool daylight, EDisplayType style, const Locale& local } } else if (style == LONG_GMT || style == SHORT_GMT) { LocalPointer tzfmt(TimeZoneFormat::createInstance(locale, status)); + if (U_FAILURE(status)) { + result.remove(); + return result; + } offset = daylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset(); switch (style) { case LONG_GMT: @@ -1296,6 +1304,10 @@ TimeZone::getDisplayName(UBool daylight, EDisplayType style, const Locale& local U_ASSERT(FALSE); } LocalPointer tznames(TimeZoneNames::createInstance(locale, status)); + if (U_FAILURE(status)) { + result.remove(); + return result; + } UnicodeString canonicalID(ZoneMeta::getCanonicalCLDRID(*this)); tznames->getDisplayName(canonicalID, nameType, date, result); if (result.isEmpty()) { diff --git a/icu4c/source/test/cintltst/cdattst.c b/icu4c/source/test/cintltst/cdattst.c index 56802183cae..9fe124891a8 100644 --- a/icu4c/source/test/cintltst/cdattst.c +++ b/icu4c/source/test/cintltst/cdattst.c @@ -1272,7 +1272,7 @@ static void TestContext(void) { UErrorCode status = U_ZERO_ERROR; UDateFormat* udfmt = udat_open(UDAT_NONE, UDAT_MEDIUM, textContextItemPtr->locale, NULL, 0, NULL, 0, &status); if ( U_FAILURE(status) ) { - log_err("FAIL: udat_open for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); + log_data_err("FAIL: udat_open for locale %s, status %s\n", textContextItemPtr->locale, u_errorName(status) ); } else { UDateTimePatternGenerator* udtpg = udatpg_open(textContextItemPtr->locale, &status); if ( U_FAILURE(status) ) { diff --git a/icu4c/source/test/intltest/tzfmttst.cpp b/icu4c/source/test/intltest/tzfmttst.cpp index 2fbb62ccd37..4ff82ef60c5 100644 --- a/icu4c/source/test/intltest/tzfmttst.cpp +++ b/icu4c/source/test/intltest/tzfmttst.cpp @@ -109,6 +109,10 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) { for (int32_t locidx = 0; locidx < nLocales; locidx++) { UnicodeString localGMTString; SimpleDateFormat gmtFmt(UnicodeString("ZZZZ"), LOCALES[locidx], status); + if (U_FAILURE(status)) { + dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status)); + continue; + } gmtFmt.setTimeZone(*TimeZone::getGMT()); gmtFmt.format(0.0, localGMTString); -- 2.40.0