]> granicus.if.org Git - icu/commitdiff
ICU-8716 Fix errors in cintltst and intltest when data is missing
authorMichael Ow <mow@svn.icu-project.org>
Thu, 1 Mar 2012 05:27:43 +0000 (05:27 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Thu, 1 Mar 2012 05:27:43 +0000 (05:27 +0000)
X-SVN-Rev: 31552

icu4c/source/i18n/smpdtfmt.cpp
icu4c/source/i18n/timezone.cpp
icu4c/source/test/cintltst/cdattst.c
icu4c/source/test/intltest/tzfmttst.cpp

index 8aed26cb332dce8223cee6522b40847e398d69ed..ad55de49a90b8ce2ba3769f279d57b37406aecc1 100644 (file)
@@ -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<SimpleDateFormat *>(this)->fTimeZoneFormat = tzfmt;
             }
index 0f04b335e97325ba47450897dcd81b50f45926e6..197dbdde09fe2bdb1e6419e352474415f7239afd 100644 (file)
@@ -1246,6 +1246,10 @@ TimeZone::getDisplayName(UBool daylight, EDisplayType style, const Locale& local
 
     if (style == GENERIC_LOCATION || style == LONG_GENERIC || style == SHORT_GENERIC) {
         LocalPointer<TimeZoneFormat> 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<TimeZoneFormat> 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<TimeZoneNames> 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()) {
index 56802183cae75489877e09ab7ef785ed6af265c6..9fe124891a8b9e59d457295b4c95d2ffe9328215 100644 (file)
@@ -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) ) {
index 2fbb62ccd37545ce8dfa817d7b36ce27b8cb9234..4ff82ef60c5f052434c02f34861a62ab5ee603ef 100644 (file)
@@ -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);