X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..2be6500137966bba13903b24204a44804f9e133a:/icuSources/test/intltest/calregts.cpp?ds=sidebyside diff --git a/icuSources/test/intltest/calregts.cpp b/icuSources/test/intltest/calregts.cpp index 14595641..36564b12 100644 --- a/icuSources/test/intltest/calregts.cpp +++ b/icuSources/test/intltest/calregts.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2006, International Business Machines Corporation + * Copyright (c) 1997-2012, International Business Machines Corporation * and others. All Rights Reserved. ********************************************************************/ @@ -16,6 +16,7 @@ #include "unicode/strenum.h" #include "cmemory.h" #include "caltest.h" +#include "unicode/localpointer.h" #include @@ -81,6 +82,12 @@ CalendarRegressionTest::runIndexedTest( int32_t index, UBool exec, const char* & CASE(42,TestWeekShift); CASE(43,TestTimeZoneTransitionAdd); CASE(44,TestDeprecates); + CASE(45,TestT5555); + CASE(46,TestT6745); + CASE(47,TestT8057); + CASE(48,TestT8596); + CASE(49,Test9019); + CASE(50,TestT9452); default: name = ""; break; } } @@ -111,7 +118,7 @@ UBool CalendarRegressionTest::failure(UErrorCode status, const char* msg) { if(U_FAILURE(status)) { - errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status)); + errcheckln(status, UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status)); return TRUE; } @@ -127,7 +134,7 @@ CalendarRegressionTest::test4100311() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; return; } @@ -150,7 +157,7 @@ CalendarRegressionTest::test4074758() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal = new GregorianCalendar(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; return; } @@ -173,7 +180,7 @@ CalendarRegressionTest::test4028518() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal1 = new GregorianCalendar(status) ; if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal1; return; } @@ -190,6 +197,37 @@ CalendarRegressionTest::test4028518() delete cal2; } + +void +CalendarRegressionTest::Test9019() +{ + UErrorCode status = U_ZERO_ERROR; + LocalPointer cal1(new GregorianCalendar(status)); + LocalPointer cal2(new GregorianCalendar(status)); + cal1->set(UCAL_HOUR, 1); + cal2->set(UCAL_HOUR,2); + cal1->clear(); + cal2->clear(); + if(U_FAILURE(status)) { + dataerrln("Error creating Calendar: %s", u_errorName(status)); + return; + } + failure(status, "new GregorianCalendar"); + cal1->set(2011,UCAL_MAY,06); + cal2->set(2012,UCAL_JANUARY,06); + printdate(cal1.getAlias(), "cal1: ") ; + cal1->setLenient(FALSE); + cal1->add(UCAL_MONTH,8,status); + failure(status, "->add(UCAL_MONTH,8)"); + printdate(cal1.getAlias(), "cal1 (lenient) after adding 8 months:") ; + printdate(cal2.getAlias(), "cal2 (expected date):") ; + + if(!cal1->equals(*cal2,status)) { + errln("Error: cal1 != cal2.\n"); + } + failure(status, "equals"); +} + void CalendarRegressionTest::printdate(GregorianCalendar *cal, const char *string) { @@ -214,11 +252,19 @@ CalendarRegressionTest::test4031502() // require the host zone to be set; it can be set in Java. UErrorCode status = U_ZERO_ERROR; StringEnumeration* ids = TimeZone::createEnumeration(); + if (ids == NULL) { + dataerrln("Unable to create TimeZone Enumeration."); + return; + } UBool bad = FALSE; TimeZone* tz =TimeZone::createTimeZone("Asia/Riyadh87"); failure(status, "new TimeZone"); GregorianCalendar *cl = new GregorianCalendar(tz, status); - failure(status, "new GregorianCalendar"); + if (U_FAILURE(status)) { + dataerrln("Fail new GregorianCalendar: %s", u_errorName(status)); + delete tz; + return; + } cl->clear(); cl->set(1900, 15, 5, 5, 8, 13); cl->get(UCAL_HOUR, status); @@ -262,7 +308,7 @@ void CalendarRegressionTest::test4035301() c->before(*c,status) || *c != *c || *c != *d) - errln("Fail"); + dataerrln("Fail"); delete c; delete d; } @@ -274,13 +320,20 @@ void CalendarRegressionTest::test4040996() { int32_t count = 0; StringEnumeration* ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000); + if (ids == NULL) { + dataerrln("Unable to create TimeZone enumeration."); + return; + } UErrorCode status = U_ZERO_ERROR; count = ids->count(status); SimpleTimeZone *pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *ids->snext(status)); pdt->setStartRule(UCAL_APRIL, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status); pdt->setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status); Calendar *calendar = new GregorianCalendar(pdt, status); - + if (U_FAILURE(status)) { + dataerrln("Fail new GregorianCalendar: %s", u_errorName(status)); + return; + } calendar->set(UCAL_MONTH,3); calendar->set(UCAL_DATE,18); calendar->set(UCAL_SECOND, 30); @@ -318,7 +371,7 @@ void CalendarRegressionTest::test4051765() UErrorCode status = U_ZERO_ERROR; Calendar *cal = Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; return; } @@ -401,7 +454,7 @@ void CalendarRegressionTest::test4059654() { UErrorCode status = U_ZERO_ERROR; GregorianCalendar *gc = new GregorianCalendar(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete gc; return; } @@ -433,7 +486,7 @@ void CalendarRegressionTest::test4061476() Calendar *cal = Calendar::createInstance(TimeZone::createTimeZone("GMT"), Locale::getUK(),status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; delete fmt; return; @@ -463,8 +516,8 @@ void CalendarRegressionTest::test4070502() { UErrorCode status = U_ZERO_ERROR; Calendar *cal = new GregorianCalendar(status); - if(status == U_USING_FALLBACK_WARNING) { - errln("Error creating Calendar: %s", u_errorName(status)); + if(status == U_USING_FALLBACK_WARNING || U_FAILURE(status)) { + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; return; } @@ -520,7 +573,7 @@ void CalendarRegressionTest::dowTest(UBool lenient) UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal = new GregorianCalendar(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; return; } @@ -537,7 +590,7 @@ void CalendarRegressionTest::dowTest(UBool lenient) if (dow < min || dow > max) errln("FAIL: Day of week %d out of range [%d,%d]\n", dow, min, max); if (dow != UCAL_SUNDAY) - errln("FAIL: Day of week should be SUNDAY Got " + dow); + errln(UnicodeString("FAIL: Day of week should be SUNDAY Got ") + dow); if(U_FAILURE(status)) { errln("Error checking Calendar: %s", u_errorName(status)); @@ -577,7 +630,7 @@ void CalendarRegressionTest::test4071385() UErrorCode status = U_ZERO_ERROR; Calendar *cal = Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; return; } @@ -598,7 +651,7 @@ void CalendarRegressionTest::test4073929() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *foo1 = new GregorianCalendar(1997, 8, 27,status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete foo1; return; } @@ -654,7 +707,7 @@ void CalendarRegressionTest::test4083167() UDate firstDate = Calendar::getNow(); Calendar *cal = new GregorianCalendar(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; return; } @@ -704,7 +757,7 @@ void CalendarRegressionTest::test4086724() date = new SimpleDateFormat(UnicodeString("dd MMM yyy (zzzz) 'is in week' ww"),status); Calendar *cal = Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating Calendar: %s", u_errorName(status)); + dataerrln("Error creating Calendar: %s", u_errorName(status)); delete cal; delete newZone; delete date; @@ -743,6 +796,11 @@ delete saveZone; void CalendarRegressionTest::test4092362() { UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status); + if (U_FAILURE(status)) { + dataerrln("Fail new GregorianCalendar: %s", u_errorName(status)); + delete cal1; + return; + } /*cal1.set( Calendar::YEAR, 1997 ); cal1.set( Calendar::MONTH, 10 ); cal1.set( Calendar::DATE, 11 ); @@ -752,7 +810,8 @@ void CalendarRegressionTest::test4092362() { logln( UnicodeString(" Cal1 = ") + cal1->getTime(status) ); logln( UnicodeString(" Cal1 time in ms = ") + cal1->get(UCAL_MILLISECOND,status) ); - for( int32_t k = 0; k < 100 ; k++ ); + for (int32_t k = 0; k < 100 ; k++) + ; GregorianCalendar *cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status); /*cal2.set( Calendar::YEAR, 1997 ); @@ -778,9 +837,14 @@ void CalendarRegressionTest::test4095407() { UErrorCode status = U_ZERO_ERROR; GregorianCalendar *a = new GregorianCalendar(1997,UCAL_NOVEMBER, 13,status); + if (U_FAILURE(status)) { + dataerrln("Fail new GregorianCalendar: %s", u_errorName(status)); + delete a; + return; + } int32_t dow = a->get(UCAL_DAY_OF_WEEK, status); if (dow != UCAL_THURSDAY) - errln("Fail: Want THURSDAY Got " + dow); + errln(UnicodeString("Fail: Want THURSDAY Got ") + dow); delete a; } @@ -796,6 +860,13 @@ void CalendarRegressionTest::test4096231() int32_t sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997; Calendar *cal1 = new GregorianCalendar(*PST,status); + if (U_FAILURE(status)) { + dataerrln("Failure new GregorianCalendar: %s", u_errorName(status)); + delete GMT; + delete PST; + delete cal1; + return; + } cal1->setTime(880698639000.0,status); // Issue 1: Changing the timezone doesn't change the // represented time. The old API, pre 1.2.2a requires @@ -810,6 +881,8 @@ void CalendarRegressionTest::test4096231() Calendar *cal2 = new GregorianCalendar(*GMT,status); Calendar *cal3 = new GregorianCalendar(*PST,status); + cal2->set(UCAL_MILLISECOND, 0); + cal3->set(UCAL_MILLISECOND, 0); cal2->set(cal1->get(UCAL_YEAR,status), cal1->get(UCAL_MONTH,status), @@ -857,6 +930,11 @@ void CalendarRegressionTest::test4096539() for (int32_t x=0;x<12;x++) { GregorianCalendar *gc = new GregorianCalendar(1997,x,y[x], status); + if (U_FAILURE(status)) { + dataerrln("Fail new GregorianCalendar: %s", u_errorName(status)); + delete gc; + return; + } int32_t m1,m2; log(UnicodeString("") + (m1=gc->get(UCAL_MONTH,status)+1)+UnicodeString("/")+ gc->get(UCAL_DATE,status)+"/"+gc->get(UCAL_YEAR,status)+ @@ -882,7 +960,7 @@ void CalendarRegressionTest::test41003112() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating calendar: %s", u_errorName(status)); + dataerrln("Error creating calendar: %s", u_errorName(status)); delete cal; return; } @@ -906,7 +984,7 @@ void CalendarRegressionTest::test4103271() UnicodeString output, testDesc, str, str2; GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating calendar: %s", u_errorName(status)); + dataerrln("Error creating calendar: %s", u_errorName(status)); delete testCal; return; } @@ -1167,7 +1245,7 @@ void CalendarRegressionTest::test4106136() for (int32_t j=0; j<3; ++j) { UnicodeString temp; if (n[j] == 0) - errln(UnicodeString("Fail: No locales for ") + locales[i].getName()); + dataerrln(UnicodeString("Fail: No locales for ") + locales[i].getName()); } } //} @@ -1184,7 +1262,7 @@ void CalendarRegressionTest::test4108764() UErrorCode status = U_ZERO_ERROR; Calendar *cal = Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete cal; return; } @@ -1231,10 +1309,10 @@ void CalendarRegressionTest::test4108764() void CalendarRegressionTest::test4114578() { UErrorCode status = U_ZERO_ERROR; - int32_t ONE_HOUR = 60*60*1000; + double ONE_HOUR = 60*60*1000; Calendar *cal = Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete cal; return; } @@ -1302,7 +1380,7 @@ void CalendarRegressionTest::test4118384() UErrorCode status = U_ZERO_ERROR; Calendar *cal = Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete cal; return; } @@ -1360,12 +1438,16 @@ void CalendarRegressionTest::test4125881() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete cal; return; } DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status); - if(!assertSuccess("trying to construct", status))return; + if(U_FAILURE(status)) { + dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status)); + delete cal; + return; + } cal->clear(); for (int32_t y=-20; y<=10; ++y) { cal->set(UCAL_ERA, y < 1 ? GregorianCalendar::BC : GregorianCalendar::AD); @@ -1390,12 +1472,16 @@ void CalendarRegressionTest::test4125892() { UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete cal; return; } DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status); - if(!assertSuccess("trying to construct", status))return; + if(U_FAILURE(status)) { + dataerrln("Error creating SimpleDateFormat - %s", u_errorName(status)); + delete cal; + return; + } cal->clear(); cal->set(UCAL_ERA, GregorianCalendar::BC); cal->set(UCAL_YEAR, 81); // 81 BC is a leap year (proleptically) @@ -1421,7 +1507,7 @@ void CalendarRegressionTest::test4141665() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *cal = new GregorianCalendar(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete cal; return; } @@ -1450,7 +1536,7 @@ void CalendarRegressionTest::test4142933() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *calendar = new GregorianCalendar(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete calendar; return; } @@ -1484,7 +1570,7 @@ void CalendarRegressionTest::test4145158() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *calendar = new GregorianCalendar(status); if(status == U_USING_FALLBACK_WARNING || U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete calendar; return; } @@ -1523,7 +1609,7 @@ void CalendarRegressionTest::test4145983() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *calendar = new GregorianCalendar(status); if(U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete calendar; return; } @@ -1554,7 +1640,7 @@ void CalendarRegressionTest::test4147269() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *calendar = new GregorianCalendar(status); if(status == U_USING_FALLBACK_WARNING || U_FAILURE(status)) { - errln("Error creating calendar %s", u_errorName(status)); + dataerrln("Error creating calendar %s", u_errorName(status)); delete calendar; return; } @@ -1608,7 +1694,7 @@ CalendarRegressionTest::Test4149677() for (int32_t i=0; i < 3; ++i) { GregorianCalendar *calendar = new GregorianCalendar(zones[i], status); if(U_FAILURE(status)) { - errln("Couldnt' create calendar."); + dataerrln("Couldnt' create calendar.: %s", u_errorName(status)); return; } @@ -1636,7 +1722,7 @@ CalendarRegressionTest::Test4149677() UnicodeString temp; errln("test failed with zone " + zones[i]->getID(temp)); errln(" cutover date is Date(Long.MAX_VALUE)"); - errln(" isLeapYear(100) returns: " + is100Leap); + errln(UnicodeString(" isLeapYear(100) returns: ") + is100Leap); } delete calendar; } @@ -1660,7 +1746,7 @@ CalendarRegressionTest::Test4162587() GregorianCalendar *cal = new GregorianCalendar(tz, status); if(U_FAILURE(status)) { - errln("Couldn't create calendar"); + dataerrln("Couldn't create calendar.: %s", u_errorName(status)); return; } UDate d0, dPlus, dMinus; @@ -1712,7 +1798,7 @@ CalendarRegressionTest::Test4165343() UErrorCode status = U_ZERO_ERROR; GregorianCalendar *calendar = new GregorianCalendar(1996, UCAL_FEBRUARY, 29, status); if(U_FAILURE(status)) { - errln("Couldn't create calendar"); + dataerrln("Couldn't create calendar.: %s", u_errorName(status)); return; } UDate start = calendar->getTime(status); @@ -1767,7 +1853,7 @@ CalendarRegressionTest::Test4166109() GregorianCalendar *calendar = new GregorianCalendar(Locale::getUS(), status); if(U_FAILURE(status)) { - errln("Couldn't create calendar"); + dataerrln("Couldn't create calendar.: %s", u_errorName(status)); return; } calendar->set(1998, UCAL_MARCH, 1); @@ -1811,7 +1897,7 @@ CalendarRegressionTest::Test4167060() DateFormat *format = new SimpleDateFormat(UnicodeString("EEE MMM dd HH:mm:ss zzz yyyy G"), Locale::getUS(), status); if(U_FAILURE(status)) { - errln("Couldn't create SimpleDateFormat"); + dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status)); return; } @@ -1902,7 +1988,7 @@ void CalendarRegressionTest::Test4197699() { Locale::getUS(), status); fmt.setCalendar(cal); if (U_FAILURE(status)) { - errln("Couldn't initialize test"); + dataerrln("Couldn't initialize test - %s", u_errorName(status)); return; } @@ -1964,7 +2050,7 @@ void CalendarRegressionTest::TestJ81() { GregorianCalendar cal(TimeZone::createTimeZone("GMT"), Locale::getUS(), status); SimpleDateFormat fmt("HH:mm 'w'w 'd'D E d MMM yyyy", Locale::getUS(), status); if (U_FAILURE(status)) { - errln("Error: Cannot create calendar or format"); + dataerrln("Error: Cannot create calendar or format - %s", u_errorName(status)); return; } fmt.setCalendar(cal); @@ -2180,7 +2266,7 @@ void CalendarRegressionTest::TestJ438(void) { int32_t DATA_length = (int32_t)(sizeof(DATA)/sizeof(DATA[0])); Calendar* pcal = Calendar::createInstance(Locale::getUS(), ec); if(U_FAILURE(ec)) { - errln("Error creating calendar %s", u_errorName(ec)); + dataerrln("Error creating calendar %s", u_errorName(ec)); delete pcal; return; } @@ -2189,7 +2275,7 @@ void CalendarRegressionTest::TestJ438(void) { SimpleDateFormat fmt(UnicodeString("MMM dd yyyy",""), ec); fmt.setCalendar(cal); UnicodeString s, t, u; - if (!failure(ec, "setup")) { + if (U_SUCCESS(ec)) { for (i=0; iset(2007, UCAL_FEBRUARY, 21); + + // Advance three years + cal->add(UCAL_MONTH, 36, ec); + + // Set to last Wednesday of the month + cal->set(UCAL_DAY_OF_WEEK_IN_MONTH, -1); + + cal->getTime(ec); + + int32_t yy, mm, dd, ee; + + yy = cal->get(UCAL_YEAR, ec); + mm = cal->get(UCAL_MONTH, ec); + dd = cal->get(UCAL_DATE, ec); + ee = cal->get(UCAL_DAY_OF_WEEK, ec); + + // Should be set to Wednesday, February 24, 2010 + if (U_FAILURE(ec) || yy != 2010 || mm != UCAL_FEBRUARY || dd != 24 || ee != UCAL_WEDNESDAY) { + errln("FAIL: got date %4d/%02d/%02d, expected 210/02/24: ", yy, mm + 1, dd); + } + delete cal; +} + +typedef struct { + int32_t startYear; + int32_t startMonth; // 0-based + int32_t startDay; // 1-based + UCalendarDateFields fieldToChange; + int32_t fieldDelta; + int32_t endYear; + int32_t endMonth; // 0-based + int32_t endDay; // 1-based +} CoptEthCalTestItem; + +// year 1724 in coptic calendar = +// year 2000 in ethiopic calendar (276 more than coptic) = +// year 7500 in ethiopic-amete-alem calendar (5776 more than coptic) +// (2007-2008 in gregorian calendar depending on month) +static const CoptEthCalTestItem coptEthCalTestItems[] = { + { 1724, 12, 1, UCAL_MONTH, +1, 1725, 0, 1 }, + { 1724, 12, 1, UCAL_MONTH, +9, 1725, 8, 1 }, + { 1723, 12, 2, UCAL_MONTH, +1, 1724, 0, 2 }, // 1723 is a leap year + { 1723, 12, 2, UCAL_MONTH, +9, 1724, 8, 2 }, + { 1725, 0, 1, UCAL_MONTH, -1, 1724, 12, 1 }, + { 1725, 0, 1, UCAL_MONTH, -6, 1724, 7, 1 }, + { 1724, 12, 1, UCAL_DATE, +8, 1725, 0, 4 }, + { 1723, 12, 1, UCAL_DATE, +8, 1724, 0, 3 }, // 1723 is a leap year + { 1724, 0, 1, UCAL_DATE, -1, 1723, 12, 6 }, // 1723 is a leap year + { 0, 0, 0, (UCalendarDateFields)0, 0, 0, 0, 0 } // terminator +}; + +typedef struct { + const char * locale; + int32_t yearOffset; +} CoptEthCalLocale; + +static const CoptEthCalLocale copEthCalLocales[] = { + { "en@calendar=coptic", 0 }, + { "en@calendar=ethiopic", 276 }, + { NULL, 0 } // terminator +}; + +void CalendarRegressionTest::TestT6745() +{ + const CoptEthCalLocale * testLocalePtr; + for ( testLocalePtr = copEthCalLocales; testLocalePtr->locale != NULL; ++testLocalePtr) { + UErrorCode status = U_ZERO_ERROR; + Calendar *cal = Calendar::createInstance(Locale(testLocalePtr->locale), status); + if ( U_FAILURE(status) ) { + dataerrln((UnicodeString)"FAIL: Calendar::createInstance, locale " + testLocalePtr->locale + ", status " + u_errorName(status)); + continue; + } + const CoptEthCalTestItem * testItemPtr; + for (testItemPtr = coptEthCalTestItems; testItemPtr->fieldDelta != 0; ++testItemPtr) { + status = U_ZERO_ERROR; + cal->set( testItemPtr->startYear + testLocalePtr->yearOffset, testItemPtr->startMonth, testItemPtr->startDay, 9, 0 ); + cal->add( testItemPtr->fieldToChange, testItemPtr->fieldDelta, status ); + if ( U_FAILURE(status) ) { + errln((UnicodeString)"FAIL: Calendar::add, locale " + testLocalePtr->locale + ", field/delta " + + testItemPtr->fieldToChange + "/" + testItemPtr->fieldDelta + ", status " + u_errorName(status)); + continue; + } + int32_t endYear = testItemPtr->endYear + testLocalePtr->yearOffset; + int32_t year = cal->get(UCAL_YEAR, status); + int32_t month = cal->get(UCAL_MONTH, status); + int32_t day = cal->get(UCAL_DATE, status); + if ( U_FAILURE(status) || year != endYear || month != testItemPtr->endMonth || day != testItemPtr->endDay ) { + errln((UnicodeString)"ERROR: Calendar::add, locale " + testLocalePtr->locale + ", field/delta " + + testItemPtr->fieldToChange + "/" + testItemPtr->fieldDelta + ", status " + u_errorName(status) + + ", expected " + endYear + "/" + testItemPtr->endMonth + "/" + testItemPtr->endDay + + ", got " + year + "/" + month + "/" + day ); + } + } + delete cal; + } +} + /** * Test behavior of fieldDifference around leap years. Also test a large * field difference to check binary search. @@ -2278,7 +2476,7 @@ void CalendarRegressionTest::TestLeapFieldDifference() { UErrorCode ec = U_ZERO_ERROR; Calendar* cal = Calendar::createInstance(ec); if (cal == NULL || U_FAILURE(ec)) { - errln("FAIL: Calendar::createInstance()"); + dataerrln("FAIL: Calendar::createInstance(): %s", u_errorName(ec)); delete cal; return; } @@ -2351,7 +2549,7 @@ void CalendarRegressionTest::TestMalaysianInstance() { UErrorCode ec = U_ZERO_ERROR; Calendar* cal = Calendar::createInstance(loc, ec); if (U_FAILURE(ec)) { - errln("FAIL: Can't construct calendar for ms_MY"); + dataerrln("FAIL: Can't construct calendar for ms_MY: %s", u_errorName(ec)); } delete cal; } @@ -2365,6 +2563,10 @@ void CalendarRegressionTest::TestWeekShift() { UErrorCode ec = U_ZERO_ERROR; GregorianCalendar cal(TimeZone::createTimeZone("America/Los_Angeles"), Locale("en", "US"), ec); + if (U_FAILURE(ec)) { + dataerrln("Fail GregorianCalendar: %s", u_errorName(ec)); + return; + } cal.setTime(UDate(997257600000.0), ec); // Wed Aug 08 01:00:00 PDT 2001 // In pass one, change the first day of week so that the weeks // shift in August 2001. In pass two, change the minimal days @@ -2442,7 +2644,7 @@ void CalendarRegressionTest::TestTimeZoneTransitionAdd() { StringEnumeration *tz = TimeZone::createEnumeration(); if (tz == NULL) { - errln("FAIL: TimeZone::createEnumeration"); + dataerrln("FAIL: TimeZone::createEnumeration"); return; } @@ -2491,7 +2693,7 @@ void CalendarRegressionTest::TestTimeZoneTransitionAdd() { } if (U_FAILURE(ec)) { - errln("FAIL: %s", u_errorName(ec)); + dataerrln("FAIL: %s", u_errorName(ec)); } delete tz; @@ -2529,7 +2731,7 @@ void CalendarRegressionTest::TestDeprecates(void) Calendar *c2 = Calendar::createInstance("ja_JP_TRADITIONAL",status); if(!c1 || !c2 || U_FAILURE(status)) { - errln("Couldn't create calendars for roll of HOUR"); + dataerrln("Couldn't create calendars for roll of HOUR: %s", u_errorName(status)); return; } @@ -2615,7 +2817,130 @@ void CalendarRegressionTest::TestDeprecates(void) delete c1; delete c2; + } +void CalendarRegressionTest::TestT8057(void) { + // Set the calendar to the last day in a leap year + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status); + if(U_FAILURE(status)) { + errln("Error creating Calendar: %s", u_errorName(status)); + delete cal; + return; + } + cal->setLenient(FALSE); + cal->clear(); + cal->set(2008, UCAL_DECEMBER, 31); + + // Force calculating then fields once. + UDate t = cal->getTime(status); + if(U_FAILURE(status)) { + errln("Error while calculating the date"); + delete cal; + return; + } + + UDate expected = 1262246400000.0; // 2009-12-31 00:00 PST + + cal->add(UCAL_YEAR, 1, status); + t = cal->getTime(status); + if (U_SUCCESS(status)) { + if (t != expected) { + dataerrln((UnicodeString)"FAIL: wrong date after add: expected=" + expected + " returned=" + t); + } + } else { + errln("FAIL: error while adding one year"); + } + + delete cal; +} + +// Test case for ticket#8596. +// Setting an year followed by getActualMaximum(Calendar.WEEK_OF_YEAR) +// may result wrong maximum week. +void CalendarRegressionTest::TestT8596(void) { + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *gc = new GregorianCalendar(*TimeZone::getGMT(), status); + + if (U_FAILURE(status)) { + dataerrln("Error creating Calendar: %s", u_errorName(status)); + delete gc; + return; + } + + gc->setFirstDayOfWeek(UCAL_MONDAY); + gc->setMinimalDaysInFirstWeek(4); + + // Force the calender to resolve the fields once. + // The maximum week number in 2011 is 52. + gc->set(UCAL_YEAR, 2011); + gc->get(UCAL_YEAR, status); + + // Set a date in year 2009, but not calling get to resolve + // the calendar's internal field yet. + gc->set(2009, UCAL_JULY, 1); + + // Then call getActuamMaximum for week of year. + // #8596 was caused by conflict between year set + // above and internal work calendar field resolution. + int32_t maxWeeks = gc->getActualMaximum(UCAL_WEEK_OF_YEAR, status); + + if (U_FAILURE(status)) { + errln("Error calendar calculation: %s", u_errorName(status)); + delete gc; + return; + } + + if (maxWeeks != 53) { + errln((UnicodeString)"FAIL: Max week in 2009 in ISO calendar is 53, but got " + maxWeeks); + } + + delete gc; +} + +// Test case for ticket 9452 +// Calendar addition fall onto the missing date - 2011-12-30 in Samoa +void CalendarRegressionTest::TestT9452(void) { + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar cal(TimeZone::createTimeZone("Pacific/Apia"), status); + failure(status, "initializing GregorianCalendar"); + + SimpleDateFormat sdf(UnicodeString("y-MM-dd'T'HH:mm:ssZZZZZ"), status); + failure(status, "initializing SimpleDateFormat"); + sdf.setCalendar(cal); + + UnicodeString dstr; + + // Set date to 2011-12-29 00:00 + cal.clear(); + cal.set(2011, UCAL_DECEMBER, 29, 0, 0, 0); + + UDate d = cal.getTime(status); + if (!failure(status, "getTime for initial date")) { + sdf.format(d, dstr); + logln(UnicodeString("Initial date: ") + dstr); + + // Add 1 day + cal.add(UCAL_DATE, 1, status); + failure(status, "add 1 day"); + d = cal.getTime(status); + failure(status, "getTime after +1 day"); + dstr.remove(); + sdf.format(d, dstr); + logln(UnicodeString("+1 day: ") + dstr); + assertEquals("Add 1 day", UnicodeString("2011-12-31T00:00:00+14:00"), dstr); + + // Subtract 1 day + cal.add(UCAL_DATE, -1, status); + failure(status, "subtract 1 day"); + d = cal.getTime(status); + failure(status, "getTime after -1 day"); + dstr.remove(); + sdf.format(d, dstr); + logln(UnicodeString("-1 day: ") + dstr); + assertEquals("Subtract 1 day", UnicodeString("2011-12-29T00:00:00-10:00"), dstr); + } +} #endif /* #if !UCONFIG_NO_FORMATTING */