From ec800e7407493f65f3f5aee9bc7a657bb25850f1 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Wed, 21 Feb 2024 16:33:41 -0800 Subject: [PATCH] ICU-22633 Return error if era is out of range --- icu4c/source/i18n/buddhcal.cpp | 5 ++++- icu4c/source/i18n/buddhcal.h | 3 ++- icu4c/source/i18n/calendar.cpp | 15 ++++++++++++--- icu4c/source/i18n/chnsecal.cpp | 6 +++++- icu4c/source/i18n/chnsecal.h | 2 +- icu4c/source/i18n/coptccal.cpp | 10 ++++++++-- icu4c/source/i18n/coptccal.h | 2 +- icu4c/source/i18n/ethpccal.cpp | 10 ++++++++-- icu4c/source/i18n/ethpccal.h | 4 ++-- icu4c/source/i18n/gregocal.cpp | 10 ++++++++-- icu4c/source/i18n/hebrwcal.cpp | 14 +++++++++++--- icu4c/source/i18n/hebrwcal.h | 3 ++- icu4c/source/i18n/indiancal.cpp | 5 ++++- icu4c/source/i18n/indiancal.h | 2 +- icu4c/source/i18n/islamcal.cpp | 5 ++++- icu4c/source/i18n/islamcal.h | 2 +- icu4c/source/i18n/japancal.cpp | 10 +++++++--- icu4c/source/i18n/japancal.h | 2 +- icu4c/source/i18n/persncal.cpp | 5 ++++- icu4c/source/i18n/persncal.h | 2 +- icu4c/source/i18n/taiwncal.cpp | 9 ++++++++- icu4c/source/i18n/taiwncal.h | 2 +- icu4c/source/i18n/unicode/calendar.h | 3 ++- icu4c/source/i18n/unicode/gregocal.h | 3 ++- icu4c/source/test/intltest/incaltst.cpp | 12 ++++++++++++ icu4c/source/test/intltest/incaltst.h | 1 + 26 files changed, 113 insertions(+), 34 deletions(-) diff --git a/icu4c/source/i18n/buddhcal.cpp b/icu4c/source/i18n/buddhcal.cpp index dc14af00bf9..0ff48bea982 100644 --- a/icu4c/source/i18n/buddhcal.cpp +++ b/icu4c/source/i18n/buddhcal.cpp @@ -63,8 +63,11 @@ const char *BuddhistCalendar::getType() const return "buddhist"; } -int32_t BuddhistCalendar::handleGetExtendedYear() +int32_t BuddhistCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } // EXTENDED_YEAR in BuddhistCalendar is a Gregorian year. // The default value of EXTENDED_YEAR is 1970 (Buddhist 2513) int32_t year; diff --git a/icu4c/source/i18n/buddhcal.h b/icu4c/source/i18n/buddhcal.h index 01b59341c12..a92c9bb0fc8 100644 --- a/icu4c/source/i18n/buddhcal.h +++ b/icu4c/source/i18n/buddhcal.h @@ -139,10 +139,11 @@ private: * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such * as UCAL_ERA) specific to the calendar system, depending on which set of * fields is newer. + * @param status * @return the extended year * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Subclasses may override this method to compute several fields * specific to each calendar system. diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index b8f14760bdd..03af659042d 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -2929,11 +2929,17 @@ void Calendar::validateField(UCalendarDateFields field, UErrorCode &status) { int32_t y; switch (field) { case UCAL_DAY_OF_MONTH: - y = handleGetExtendedYear(); + y = handleGetExtendedYear(status); + if (U_FAILURE(status)) { + return; + } validateField(field, 1, handleGetMonthLength(y, internalGetMonth()), status); break; case UCAL_DAY_OF_YEAR: - y = handleGetExtendedYear(); + y = handleGetExtendedYear(status); + if (U_FAILURE(status)) { + return; + } validateField(field, 1, handleGetYearLength(y), status); break; case UCAL_DAY_OF_WEEK_IN_MONTH: @@ -3387,7 +3393,10 @@ int32_t Calendar::handleComputeJulianDay(UCalendarDateFields bestField, UErrorCo if (bestField == UCAL_WEEK_OF_YEAR && newerField(UCAL_YEAR_WOY, UCAL_YEAR) == UCAL_YEAR_WOY) { year = internalGet(UCAL_YEAR_WOY); } else { - year = handleGetExtendedYear(); + year = handleGetExtendedYear(status); + if (U_FAILURE(status)) { + return 0; + } } internalSet(UCAL_EXTENDED_YEAR, year); diff --git a/icu4c/source/i18n/chnsecal.cpp b/icu4c/source/i18n/chnsecal.cpp index dfda861485b..17d92ed1a3d 100644 --- a/icu4c/source/i18n/chnsecal.cpp +++ b/icu4c/source/i18n/chnsecal.cpp @@ -222,7 +222,11 @@ int32_t ChineseCalendar::handleGetLimit(UCalendarDateFields field, ELimitType li * field as the continuous year count, depending on which is newer. * @stable ICU 2.8 */ -int32_t ChineseCalendar::handleGetExtendedYear() { +int32_t ChineseCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } + int32_t year; if (newestStamp(UCAL_ERA, UCAL_YEAR, kUnset) <= fStamp[UCAL_EXTENDED_YEAR]) { year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1 diff --git a/icu4c/source/i18n/chnsecal.h b/icu4c/source/i18n/chnsecal.h index 7d4ef952f91..9d7846b3551 100644 --- a/icu4c/source/i18n/chnsecal.h +++ b/icu4c/source/i18n/chnsecal.h @@ -209,7 +209,7 @@ class U_I18N_API ChineseCalendar : public Calendar { virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override; virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const override; virtual int64_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const override; - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override; virtual const UFieldResolutionTable* getFieldResolutionTable() const override; diff --git a/icu4c/source/i18n/coptccal.cpp b/icu4c/source/i18n/coptccal.cpp index df2a77c2d8e..9bb50215006 100644 --- a/icu4c/source/i18n/coptccal.cpp +++ b/icu4c/source/i18n/coptccal.cpp @@ -57,8 +57,11 @@ CopticCalendar::getType() const //------------------------------------------------------------------------- int32_t -CopticCalendar::handleGetExtendedYear() +CopticCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } int32_t eyear; if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { eyear = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1 @@ -67,8 +70,11 @@ CopticCalendar::handleGetExtendedYear() int32_t era = internalGet(UCAL_ERA, CE); if (era == BCE) { eyear = 1 - internalGet(UCAL_YEAR, 1); // Convert to extended year - } else { + } else if (era == CE){ eyear = internalGet(UCAL_YEAR, 1); // Default to year 1 + } else { + status = U_ILLEGAL_ARGUMENT_ERROR; + return 0; } } return eyear; diff --git a/icu4c/source/i18n/coptccal.h b/icu4c/source/i18n/coptccal.h index 396127e8adb..aabb4a5f305 100644 --- a/icu4c/source/i18n/coptccal.h +++ b/icu4c/source/i18n/coptccal.h @@ -177,7 +177,7 @@ protected: * Return the extended year defined by the current fields. * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Compute fields from the JD diff --git a/icu4c/source/i18n/ethpccal.cpp b/icu4c/source/i18n/ethpccal.cpp index 9c2843594d1..6be363d1064 100644 --- a/icu4c/source/i18n/ethpccal.cpp +++ b/icu4c/source/i18n/ethpccal.cpp @@ -56,8 +56,11 @@ EthiopicCalendar::getType() const //------------------------------------------------------------------------- int32_t -EthiopicCalendar::handleGetExtendedYear() +EthiopicCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } // Ethiopic calendar uses EXTENDED_YEAR aligned to // Amelete Hihret year always. if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { @@ -181,8 +184,11 @@ EthiopicAmeteAlemCalendar::getType() const } int32_t -EthiopicAmeteAlemCalendar::handleGetExtendedYear() +EthiopicAmeteAlemCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } // Ethiopic calendar uses EXTENDED_YEAR aligned to // Amelete Hihret year always. if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { diff --git a/icu4c/source/i18n/ethpccal.h b/icu4c/source/i18n/ethpccal.h index 19d9e0efb7e..b6597c1d603 100644 --- a/icu4c/source/i18n/ethpccal.h +++ b/icu4c/source/i18n/ethpccal.h @@ -169,7 +169,7 @@ protected: * 1 AMETE_MIHRET 1 * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Compute fields from the JD @@ -341,7 +341,7 @@ protected: * 1 AMETE_ALEM 5501 * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Compute fields from the JD diff --git a/icu4c/source/i18n/gregocal.cpp b/icu4c/source/i18n/gregocal.cpp index 6b80e7ed42b..9142cb601ee 100644 --- a/icu4c/source/i18n/gregocal.cpp +++ b/icu4c/source/i18n/gregocal.cpp @@ -1158,7 +1158,10 @@ int32_t GregorianCalendar::getActualMaximum(UCalendarDateFields field, UErrorCod } -int32_t GregorianCalendar::handleGetExtendedYear() { +int32_t GregorianCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } // the year to return int32_t year = kEpochYear; @@ -1184,8 +1187,11 @@ int32_t GregorianCalendar::handleGetExtendedYear() { int32_t era = internalGet(UCAL_ERA, AD); if (era == BC) { year = 1 - internalGet(UCAL_YEAR, 1); // Convert to extended year - } else { + } else if (era == AD) { year = internalGet(UCAL_YEAR, kEpochYear); + } else { + status = U_ILLEGAL_ARGUMENT_ERROR; + return 0; } } break; diff --git a/icu4c/source/i18n/hebrwcal.cpp b/icu4c/source/i18n/hebrwcal.cpp index 88ecb827a13..c6698328c48 100644 --- a/icu4c/source/i18n/hebrwcal.cpp +++ b/icu4c/source/i18n/hebrwcal.cpp @@ -546,7 +546,10 @@ int32_t HebrewCalendar::handleGetYearLength(int32_t eyear) const { void HebrewCalendar::validateField(UCalendarDateFields field, UErrorCode &status) { if ((field == UCAL_MONTH || field == UCAL_ORDINAL_MONTH) - && !isLeapYear(handleGetExtendedYear()) && internalGetMonth() == ADAR_1) { + && !isLeapYear(handleGetExtendedYear(status)) && internalGetMonth() == ADAR_1) { + if (U_FAILURE(status)) { + return; + } status = U_ILLEGAL_ARGUMENT_ERROR; return; } @@ -636,7 +639,10 @@ void HebrewCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) /** * @internal */ -int32_t HebrewCalendar::handleGetExtendedYear() { +int32_t HebrewCalendar::handleGetExtendedYear(UErrorCode& status ) { + if (U_FAILURE(status)) { + return 0; + } int32_t year; if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1 @@ -783,7 +789,9 @@ int32_t HebrewCalendar::internalGetMonth() const { int32_t ordinalMonth = internalGet(UCAL_ORDINAL_MONTH); HebrewCalendar *nonConstThis = (HebrewCalendar*)this; // cast away const - int32_t year = nonConstThis->handleGetExtendedYear(); + UErrorCode status = U_ZERO_ERROR; + int32_t year = nonConstThis->handleGetExtendedYear(status); + U_ASSERT(U_SUCCESS(status)); return ordinalMonth + (((!isLeapYear(year)) && (ordinalMonth > ADAR_1)) ? 1: 0); } return Calendar::internalGetMonth(); diff --git a/icu4c/source/i18n/hebrwcal.h b/icu4c/source/i18n/hebrwcal.h index b68e01e1059..afd6d6fb80d 100644 --- a/icu4c/source/i18n/hebrwcal.h +++ b/icu4c/source/i18n/hebrwcal.h @@ -350,10 +350,11 @@ public: * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such * as UCAL_ERA) specific to the calendar system, depending on which set of * fields is newer. + * @param status * @return the extended year * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Return the Julian day number of day before the first day of the * given month in the given extended year. Subclasses should override diff --git a/icu4c/source/i18n/indiancal.cpp b/icu4c/source/i18n/indiancal.cpp index 698e783c04b..e9e2db33190 100644 --- a/icu4c/source/i18n/indiancal.cpp +++ b/icu4c/source/i18n/indiancal.cpp @@ -228,7 +228,10 @@ int64_t IndianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UB // Functions for converting from milliseconds to field values //------------------------------------------------------------------------- -int32_t IndianCalendar::handleGetExtendedYear() { +int32_t IndianCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } int32_t year; if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { diff --git a/icu4c/source/i18n/indiancal.h b/icu4c/source/i18n/indiancal.h index 04ca4dd6f3a..297345d6182 100644 --- a/icu4c/source/i18n/indiancal.h +++ b/icu4c/source/i18n/indiancal.h @@ -234,7 +234,7 @@ public: /** * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Override Calendar to compute several fields specific to the Indian diff --git a/icu4c/source/i18n/islamcal.cpp b/icu4c/source/i18n/islamcal.cpp index cba49848a3f..f71cbdc821f 100644 --- a/icu4c/source/i18n/islamcal.cpp +++ b/icu4c/source/i18n/islamcal.cpp @@ -484,7 +484,10 @@ int64_t IslamicCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, U /** * @draft ICU 2.4 */ -int32_t IslamicCalendar::handleGetExtendedYear() { +int32_t IslamicCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } int32_t year; if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1 diff --git a/icu4c/source/i18n/islamcal.h b/icu4c/source/i18n/islamcal.h index 8bd0bf97c70..196f3454c99 100644 --- a/icu4c/source/i18n/islamcal.h +++ b/icu4c/source/i18n/islamcal.h @@ -280,7 +280,7 @@ class U_I18N_API IslamicCalendar : public Calendar { /** * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Override Calendar to compute several fields specific to the Islamic diff --git a/icu4c/source/i18n/japancal.cpp b/icu4c/source/i18n/japancal.cpp index fc18d6c0eb1..20800714ef7 100644 --- a/icu4c/source/i18n/japancal.cpp +++ b/icu4c/source/i18n/japancal.cpp @@ -191,8 +191,11 @@ int32_t JapaneseCalendar::internalGetEra() const return internalGet(UCAL_ERA, gCurrentEra); } -int32_t JapaneseCalendar::handleGetExtendedYear() +int32_t JapaneseCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } // EXTENDED_YEAR in JapaneseCalendar is a Gregorian year // The default value of EXTENDED_YEAR is 1970 (Showa 45) int32_t year; @@ -201,9 +204,10 @@ int32_t JapaneseCalendar::handleGetExtendedYear() newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) { year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch); } else { - UErrorCode status = U_ZERO_ERROR; int32_t eraStartYear = gJapaneseEraRules->getStartYear(internalGet(UCAL_ERA, gCurrentEra), status); - U_ASSERT(U_SUCCESS(status)); + if (U_FAILURE(status)) { + return 0; + } // extended year is a gregorian year, where 1 = 1AD, 0 = 1BC, -1 = 2BC, etc year = internalGet(UCAL_YEAR, 1) // pin to minimum of year 1 (first year) diff --git a/icu4c/source/i18n/japancal.h b/icu4c/source/i18n/japancal.h index 3ae4900a2cd..dfcfda635af 100644 --- a/icu4c/source/i18n/japancal.h +++ b/icu4c/source/i18n/japancal.h @@ -123,7 +123,7 @@ public: * Japanese calendar case, this is equal to the equivalent extended Gregorian year. * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Return the maximum value that this field could have, given the current date. diff --git a/icu4c/source/i18n/persncal.cpp b/icu4c/source/i18n/persncal.cpp index 8aac2352cbd..722da76b97d 100644 --- a/icu4c/source/i18n/persncal.cpp +++ b/icu4c/source/i18n/persncal.cpp @@ -187,7 +187,10 @@ int64_t PersianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, U // Functions for converting from milliseconds to field values //------------------------------------------------------------------------- -int32_t PersianCalendar::handleGetExtendedYear() { +int32_t PersianCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } int32_t year; if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1 diff --git a/icu4c/source/i18n/persncal.h b/icu4c/source/i18n/persncal.h index 80bebd99b8a..838ece280d4 100644 --- a/icu4c/source/i18n/persncal.h +++ b/icu4c/source/i18n/persncal.h @@ -228,7 +228,7 @@ class PersianCalendar : public Calendar { /** * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Override Calendar to compute several fields specific to the Persian diff --git a/icu4c/source/i18n/taiwncal.cpp b/icu4c/source/i18n/taiwncal.cpp index 48f0b99e18d..424861337b8 100644 --- a/icu4c/source/i18n/taiwncal.cpp +++ b/icu4c/source/i18n/taiwncal.cpp @@ -63,8 +63,12 @@ const char *TaiwanCalendar::getType() const return "roc"; } -int32_t TaiwanCalendar::handleGetExtendedYear() +int32_t TaiwanCalendar::handleGetExtendedYear(UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } + // EXTENDED_YEAR in TaiwanCalendar is a Gregorian year // The default value of EXTENDED_YEAR is 1970 (Minguo 59) int32_t year = kGregorianEpoch; @@ -78,6 +82,9 @@ int32_t TaiwanCalendar::handleGetExtendedYear() year = internalGet(UCAL_YEAR, 1) + kTaiwanEraStart; } else if(era == BEFORE_MINGUO) { year = 1 - internalGet(UCAL_YEAR, 1) + kTaiwanEraStart; + } else { + status = U_ILLEGAL_ARGUMENT_ERROR; + return 0; } } return year; diff --git a/icu4c/source/i18n/taiwncal.h b/icu4c/source/i18n/taiwncal.h index b0a30f91080..c41227e322e 100644 --- a/icu4c/source/i18n/taiwncal.h +++ b/icu4c/source/i18n/taiwncal.h @@ -139,7 +139,7 @@ private: * @return the extended year * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Subclasses may override this method to compute several fields * specific to each calendar system. diff --git a/icu4c/source/i18n/unicode/calendar.h b/icu4c/source/i18n/unicode/calendar.h index 206fd3e1e4f..9edf92c0729 100644 --- a/icu4c/source/i18n/unicode/calendar.h +++ b/icu4c/source/i18n/unicode/calendar.h @@ -1694,10 +1694,11 @@ protected: * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such * as UCAL_ERA) specific to the calendar system, depending on which set of * fields is newer. + * @param status ICU Error Code * @return the extended year * @internal */ - virtual int32_t handleGetExtendedYear() = 0; + virtual int32_t handleGetExtendedYear(UErrorCode& status) = 0; /** * Subclasses may override this. This method calls diff --git a/icu4c/source/i18n/unicode/gregocal.h b/icu4c/source/i18n/unicode/gregocal.h index 64ad5f71f0e..a6d83aa3ff4 100644 --- a/icu4c/source/i18n/unicode/gregocal.h +++ b/icu4c/source/i18n/unicode/gregocal.h @@ -583,10 +583,11 @@ public: * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such * as UCAL_ERA) specific to the calendar system, depending on which set of * fields is newer. + * @param status * @return the extended year * @internal */ - virtual int32_t handleGetExtendedYear() override; + virtual int32_t handleGetExtendedYear(UErrorCode& status) override; /** * Subclasses may override this to convert from week fields diff --git a/icu4c/source/test/intltest/incaltst.cpp b/icu4c/source/test/intltest/incaltst.cpp index 5a682c3156e..812fe4a678b 100644 --- a/icu4c/source/test/intltest/incaltst.cpp +++ b/icu4c/source/test/intltest/incaltst.cpp @@ -106,6 +106,7 @@ void IntlCalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &n TESTCASE_AUTO(TestConsistencyPersian); TESTCASE_AUTO(TestConsistencyJapanese); TESTCASE_AUTO(TestIslamicUmalquraCalendarSlow); + TESTCASE_AUTO(TestJapaneseLargeEra); TESTCASE_AUTO_END; } @@ -1135,6 +1136,17 @@ void IntlCalendarTest::TestIslamicUmalquraCalendarSlow() { status.reset(); } +void IntlCalendarTest::TestJapaneseLargeEra() { + IcuTestErrorCode status(*this, "TestJapaneseLargeEra"); + Locale l("ja@calendar=japanese"); + std::unique_ptr cal( + Calendar::createInstance(l, status)); + cal->clear(); + cal->set(UCAL_ERA, 2139062143); + cal->add(UCAL_YEAR, 1229539657, status); + status.expectErrorAndReset(U_ILLEGAL_ARGUMENT_ERROR); +} + void IntlCalendarTest::simpleTest(const Locale& loc, const UnicodeString& expect, UDate expectDate, UErrorCode& status) { UnicodeString tmp; diff --git a/icu4c/source/test/intltest/incaltst.h b/icu4c/source/test/intltest/incaltst.h index f01d6b16c17..8f8ca430096 100644 --- a/icu4c/source/test/intltest/incaltst.h +++ b/icu4c/source/test/intltest/incaltst.h @@ -61,6 +61,7 @@ public: void TestConsistencyPersian(); void TestConsistencyJapanese(); void TestIslamicUmalquraCalendarSlow(); + void TestJapaneseLargeEra(); protected: // Test a Gregorian-Like calendar