From d3c17fa8bc95f7e994a5677f38faea76423055f9 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Wed, 21 Aug 2002 00:16:30 +0000 Subject: [PATCH] ICU-2131 Stop using the LocaleProxy deprecated code hack X-SVN-Rev: 9746 --- icu4c/source/test/intltest/apicoll.cpp | 26 +- icu4c/source/test/intltest/calregts.cpp | 2178 +++++++++++------------ icu4c/source/test/intltest/caltest.cpp | 12 +- icu4c/source/test/intltest/dcfmapts.cpp | 4 +- icu4c/source/test/intltest/dtfmapts.cpp | 6 +- icu4c/source/test/intltest/encoll.cpp | 2 +- icu4c/source/test/intltest/itrbnfrt.cpp | 8 +- icu4c/source/test/intltest/ittxtbd.cpp | 4 +- icu4c/source/test/intltest/loctest.cpp | 2 +- icu4c/source/test/intltest/nmfmapts.cpp | 8 +- icu4c/source/test/intltest/numrgts.cpp | 26 +- icu4c/source/test/intltest/rbbiapts.cpp | 2 +- icu4c/source/test/intltest/regcoll.cpp | 4 +- icu4c/source/test/intltest/sdtfmtts.cpp | 6 +- icu4c/source/test/intltest/srchtest.cpp | 8 +- icu4c/source/test/intltest/tmsgfmt.cpp | 4 +- icu4c/source/test/intltest/transapi.cpp | 2 +- icu4c/source/test/intltest/transtst.cpp | 4 +- icu4c/source/test/intltest/tsdtfmsy.cpp | 4 +- icu4c/source/test/intltest/tsmthred.cpp | 4 +- icu4c/source/test/intltest/tzregts.cpp | 2 +- icu4c/source/test/intltest/tztest.cpp | 12 +- 22 files changed, 1164 insertions(+), 1164 deletions(-) diff --git a/icu4c/source/test/intltest/apicoll.cpp b/icu4c/source/test/intltest/apicoll.cpp index e4fc7cbb2d..8fb68e8298 100644 --- a/icu4c/source/test/intltest/apicoll.cpp +++ b/icu4c/source/test/intltest/apicoll.cpp @@ -98,7 +98,7 @@ CollationAPITest::TestProperty(/* char* par */) logln("The property tests begin : "); logln("Test ctors : "); - col = Collator::createInstance(Locale::ENGLISH, success); + col = Collator::createInstance(Locale::getEnglish(), success); if (U_FAILURE(success)) { @@ -173,7 +173,7 @@ CollationAPITest::TestProperty(/* char* par */) doAssert(rcol->getRules().length() != 0, "da_DK rules does not have length 0"); delete rcol; - col = Collator::createInstance(Locale::FRENCH, success); + col = Collator::createInstance(Locale::getFrench(), success); if (U_FAILURE(success)) { errln("Creating French collation failed."); @@ -438,7 +438,7 @@ CollationAPITest::TestHashCode(/* char* par */) logln("hashCode tests begin."); UErrorCode success = U_ZERO_ERROR; Collator *col1 = 0; - col1 = Collator::createInstance(Locale::ENGLISH, success); + col1 = Collator::createInstance(Locale::getEnglish(), success); if (U_FAILURE(success)) { errln("Default collation creation failed."); @@ -455,7 +455,7 @@ CollationAPITest::TestHashCode(/* char* par */) } Collator *col3 = 0; - col3 = Collator::createInstance(Locale::ENGLISH, success); + col3 = Collator::createInstance(Locale::getEnglish(), success); if (U_FAILURE(success)) { errln("2nd default collation creation failed."); @@ -497,7 +497,7 @@ CollationAPITest::TestCollationKey(/* char* par */) logln("testing CollationKey begins..."); Collator *col = 0; UErrorCode success=U_ZERO_ERROR; - col = Collator::createInstance(Locale::ENGLISH, success); + col = Collator::createInstance(Locale::getEnglish(), success); col->setStrength(Collator::TERTIARY); if (U_FAILURE(success)) { @@ -619,7 +619,7 @@ CollationAPITest::TestElemIter(/* char* par */) logln("testing sortkey begins..."); Collator *col = 0; UErrorCode success = U_ZERO_ERROR; - col = Collator::createInstance(Locale::ENGLISH, success); + col = Collator::createInstance(Locale::getEnglish(), success); if (U_FAILURE(success)) { errln("Default collation creation failed."); @@ -776,7 +776,7 @@ CollationAPITest::TestElemIter(/* char* par */) //test error values success=U_UNSUPPORTED_ERROR; Collator *colerror=NULL; - colerror=Collator::createInstance(Locale::ENGLISH, success); + colerror=Collator::createInstance(Locale::getEnglish(), success); if (colerror != 0 || success == U_ZERO_ERROR){ errln("Error: createInstance(UErrorCode != U_ZERO_ERROR) should just return and not create an instance\n"); } @@ -831,7 +831,7 @@ CollationAPITest::TestOperators(/* char* par */) doAssert((*col1 == *col2), "Collator objects not equal after assignment (operator=)"); success = U_ZERO_ERROR; - Collator *col3 = Collator::createInstance(Locale::ENGLISH, success); + Collator *col3 = Collator::createInstance(Locale::getEnglish(), success); if (U_FAILURE(success)) { errln("Default collation creation failed."); return; @@ -893,7 +893,7 @@ void CollationAPITest::TestDuplicate(/* char* par */) { UErrorCode status = U_ZERO_ERROR; - Collator *col1 = Collator::createInstance(Locale::ENGLISH, status); + Collator *col1 = Collator::createInstance(Locale::getEnglish(), status); if (U_FAILURE(status)) { logln("Default collator creation failed."); return; @@ -916,7 +916,7 @@ CollationAPITest::TestCompare(/* char* par */) logln("The compare tests begin : "); Collator *col = 0; UErrorCode success = U_ZERO_ERROR; - col = Collator::createInstance(Locale::ENGLISH, success); + col = Collator::createInstance(Locale::getEnglish(), success); if (U_FAILURE(success)) { errln("Default collation creation failed."); return; @@ -968,7 +968,7 @@ void CollationAPITest::TestSortKey() - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ - Collator *col = Collator::createInstance(Locale::ENGLISH, status); + Collator *col = Collator::createInstance(Locale::getEnglish(), status); if (U_FAILURE(status)) { errln("ERROR: Default collation creation failed.: %s\n", u_errorName(status)); return; @@ -1271,8 +1271,8 @@ void CollationAPITest::TestDisplayName() errln("Failure getting the correct name for locale en_US"); } - coll->getDisplayName(Locale::SIMPLIFIED_CHINESE, result); - Locale::SIMPLIFIED_CHINESE.getDisplayName(name); + coll->getDisplayName(Locale::getSimplifiedChinese(), result); + Locale::getSimplifiedChinese().getDisplayName(name); if (result.compare(name)) { errln("Failure getting the correct name for locale zh_SG"); } diff --git a/icu4c/source/test/intltest/calregts.cpp b/icu4c/source/test/intltest/calregts.cpp index 7fd31f633e..e141930ad1 100644 --- a/icu4c/source/test/intltest/calregts.cpp +++ b/icu4c/source/test/intltest/calregts.cpp @@ -213,1135 +213,1135 @@ CalendarRegressionTest::test4031502() uprv_free(ids); } - /** - * @bug 4035301 - */ - void CalendarRegressionTest::test4035301() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *c = new GregorianCalendar(98, 8, 7,status); - GregorianCalendar *d = new GregorianCalendar(98, 8, 7,status); - if (c->after(*d,status) || - c->after(*c,status) || - c->before(*d,status) || - c->before(*c,status) || - *c != *c || - *c != *d) - errln("Fail"); - delete c; - delete d; - } - - /** - * @bug 4040996 - */ - void CalendarRegressionTest::test4040996() - { - int32_t count = 0; - const UnicodeString **ids = TimeZone::createAvailableIDs(-8 * 60 * 60 * 1000, count); - SimpleTimeZone *pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *ids[0]); - UErrorCode status = U_ZERO_ERROR; - pdt->setStartRule(Calendar::APRIL, 1, Calendar::SUNDAY, 2 * 60 * 60 * 1000, status); - pdt->setEndRule(Calendar::OCTOBER, -1, Calendar::SUNDAY, 2 * 60 * 60 * 1000, status); - Calendar *calendar = new GregorianCalendar(pdt, status); - - calendar->set(Calendar::MONTH,3); - calendar->set(Calendar::DAY_OF_MONTH,18); - calendar->set(Calendar::SECOND, 30); - - logln(UnicodeString("MONTH: ") + calendar->get(Calendar::MONTH, status)); - logln(UnicodeString("DAY_OF_MONTH: ") + - calendar->get(Calendar::DAY_OF_MONTH, status)); - logln(UnicodeString("MINUTE: ") + calendar->get(Calendar::MINUTE, status)); - logln(UnicodeString("SECOND: ") + calendar->get(Calendar::SECOND, status)); - - calendar->add(Calendar::SECOND,6, status); - //This will print out todays date for MONTH and DAY_OF_MONTH - //instead of the date it was set to. - //This happens when adding MILLISECOND or MINUTE also - logln(UnicodeString("MONTH: ") + calendar->get(Calendar::MONTH, status)); - logln(UnicodeString("DAY_OF_MONTH: ") + - calendar->get(Calendar::DAY_OF_MONTH, status)); - logln(UnicodeString("MINUTE: ") + calendar->get(Calendar::MINUTE, status)); - logln(UnicodeString("SECOND: ") + calendar->get(Calendar::SECOND, status)); - if (calendar->get(Calendar::MONTH, status) != 3 || - calendar->get(Calendar::DAY_OF_MONTH, status) != 18 || - calendar->get(Calendar::SECOND, status) != 36) - errln(UnicodeString("Fail: Calendar::add misbehaves")); - - delete calendar; - uprv_free(ids); - // delete ids; // TODO: BAD API - } - - /** - * @bug 4051765 - */ - void CalendarRegressionTest::test4051765() - { - UErrorCode status = U_ZERO_ERROR; - Calendar *cal = Calendar::createInstance(status); - cal->setLenient(FALSE); - cal->set(Calendar::DAY_OF_WEEK, 0); - //try { - cal->getTime(status); - if( ! U_FAILURE(status)) - errln("Fail: DAY_OF_WEEK 0 should be disallowed"); - /*} - catch (IllegalArgumentException e) { - return; - }*/ - - delete cal; - } - - /* User error - no bug here - void CalendarRegressionTest::test4059524() { - // Create calendar for April 10, 1997 - GregorianCalendar calendar = new GregorianCalendar(status); - // print out a bunch of interesting things - logln("ERA: " + Calendar::get(Calendar::ERA)); - logln("YEAR: " + Calendar::get(Calendar::YEAR)); - logln("MONTH: " + Calendar::get(Calendar::MONTH)); - logln("WEEK_OF_YEAR: " + - Calendar::get(Calendar::WEEK_OF_YEAR)); - logln("WEEK_OF_MONTH: " + - Calendar::get(Calendar::WEEK_OF_MONTH)); - logln("DATE: " + Calendar::get(Calendar::DATE)); - logln("DAY_OF_MONTH: " + - Calendar::get(Calendar::DAY_OF_MONTH)); - logln("DAY_OF_YEAR: " + Calendar::get(Calendar::DAY_OF_YEAR)); - logln("DAY_OF_WEEK: " + Calendar::get(Calendar::DAY_OF_WEEK)); - logln("DAY_OF_WEEK_IN_MONTH: " + - Calendar::get(Calendar::DAY_OF_WEEK_IN_MONTH)); - logln("AM_PM: " + Calendar::get(Calendar::AM_PM)); - logln("HOUR: " + Calendar::get(Calendar::HOUR)); - logln("HOUR_OF_DAY: " + Calendar::get(Calendar::HOUR_OF_DAY)); - logln("MINUTE: " + Calendar::get(Calendar::MINUTE)); - logln("SECOND: " + Calendar::get(Calendar::SECOND)); - logln("MILLISECOND: " + Calendar::get(Calendar::MILLISECOND)); - logln("ZONE_OFFSET: " - + (Calendar::get(Calendar::ZONE_OFFSET)/(60*60*1000))); - logln("DST_OFFSET: " - + (Calendar::get(Calendar::DST_OFFSET)/(60*60*1000))); - calendar = new GregorianCalendar(1997,3,10); - Calendar::getTime(); - logln("April 10, 1997"); - logln("ERA: " + Calendar::get(Calendar::ERA)); - logln("YEAR: " + Calendar::get(Calendar::YEAR)); - logln("MONTH: " + Calendar::get(Calendar::MONTH)); - logln("WEEK_OF_YEAR: " + - Calendar::get(Calendar::WEEK_OF_YEAR)); - logln("WEEK_OF_MONTH: " + - Calendar::get(Calendar::WEEK_OF_MONTH)); - logln("DATE: " + Calendar::get(Calendar::DATE)); - logln("DAY_OF_MONTH: " + - Calendar::get(Calendar::DAY_OF_MONTH)); - logln("DAY_OF_YEAR: " + Calendar::get(Calendar::DAY_OF_YEAR)); - logln("DAY_OF_WEEK: " + Calendar::get(Calendar::DAY_OF_WEEK)); - logln("DAY_OF_WEEK_IN_MONTH: " + Calendar::get(Calendar::DAY_OF_WEEK_IN_MONTH)); - logln("AM_PM: " + Calendar::get(Calendar::AM_PM)); - logln("HOUR: " + Calendar::get(Calendar::HOUR)); - logln("HOUR_OF_DAY: " + Calendar::get(Calendar::HOUR_OF_DAY)); - logln("MINUTE: " + Calendar::get(Calendar::MINUTE)); - logln("SECOND: " + Calendar::get(Calendar::SECOND)); - logln("MILLISECOND: " + Calendar::get(Calendar::MILLISECOND)); - logln("ZONE_OFFSET: " - + (Calendar::get(Calendar::ZONE_OFFSET)/(60*60*1000))); // in hours - logln("DST_OFFSET: " - + (Calendar::get(Calendar::DST_OFFSET)/(60*60*1000))); // in hours - } - */ - - /** - * @bug 4059654 - */ - void CalendarRegressionTest::test4059654() { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *gc = new GregorianCalendar(status); - - gc->set(1997, 3, 1, 15, 16, 17); // April 1, 1997 - - gc->set(Calendar::HOUR, 0); - gc->set(Calendar::AM_PM, Calendar::AM); - gc->set(Calendar::MINUTE, 0); - gc->set(Calendar::SECOND, 0); - gc->set(Calendar::MILLISECOND, 0); - - UDate cd = gc->getTime(status); - GregorianCalendar *exp = new GregorianCalendar(97, 3, 1, 0, 0, 0, status); - if (cd != exp->getTime(status)) - errln(UnicodeString("Fail: Calendar::set broken. Got ") + cd + " Want " + exp->getTime(status)); - - delete gc; - delete exp; - } - - /** - * @bug 4061476 - */ - void CalendarRegressionTest::test4061476() - { - UErrorCode status = U_ZERO_ERROR; - SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("ddMMMyy"), Locale::UK,status); - Calendar *cal = Calendar::createInstance(TimeZone::createTimeZone("GMT"), - Locale::UK,status); - fmt->adoptCalendar(cal); - // try { - UDate date = fmt->parse("29MAY97", status); - failure(status, "fmt->parse"); - cal->setTime(date, status); - failure(status, "cal->setTime"); - // } - //catch (Exception e) {;} - cal->set(Calendar::HOUR_OF_DAY, 13); - logln(UnicodeString("Hour: ")+cal->get(Calendar::HOUR_OF_DAY, status)); - cal->add(Calendar::HOUR_OF_DAY, 6,status); - logln(UnicodeString("Hour: ")+cal->get(Calendar::HOUR_OF_DAY, status)); - if (cal->get(Calendar::HOUR_OF_DAY, status) != 19) - errln(UnicodeString("Fail: Want 19 Got ") + cal->get(Calendar::HOUR_OF_DAY, status)); - - delete fmt; - } - - /** - * @bug 4070502 - */ - void CalendarRegressionTest::test4070502() - { - UErrorCode status = U_ZERO_ERROR; - UDate d = getAssociatedDate(makeDate(1998,0,30), status); - Calendar *cal = new GregorianCalendar(status); - cal->setTime(d,status); - if (cal->get(Calendar::DAY_OF_WEEK,status) == Calendar::SATURDAY || - cal->get(Calendar::DAY_OF_WEEK,status) == Calendar::SUNDAY) - errln(UnicodeString("Fail: Want weekday Got ") + d); - - delete cal; - } - - /** - * Get the associated date starting from a specified date - * NOTE: the unnecessary "getTime()'s" below are a work-around for a - * bug in jdk 1.1.3 (and probably earlier versions also) - *

- * @param date The date to start from - */ - UDate - CalendarRegressionTest::getAssociatedDate(UDate d, UErrorCode& status) - { - GregorianCalendar *cal = new GregorianCalendar(status); - cal->setTime(d,status); - //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH - // cal.getTime(); // <--- REMOVE THIS TO SEE BUG - for (;;) { - int32_t wd = cal->get(Calendar::DAY_OF_WEEK, status); - if (wd == Calendar::SATURDAY || wd == Calendar::SUNDAY) { - cal->add(Calendar::DATE, 1, status); - // cal.getTime(); - } - else - break; - } - - UDate dd = cal->getTime(status); - delete cal; - return dd; - } - - /** - * @bug 4071197 - */ - void CalendarRegressionTest::test4071197() - { - dowTest(FALSE); - dowTest(TRUE); - } - - void CalendarRegressionTest::dowTest(UBool lenient) - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal = new GregorianCalendar(status); - cal->set(1997, Calendar::AUGUST, 12); // Wednesday - // cal.getTime(); // Force update - cal->setLenient(lenient); - cal->set(1996, Calendar::DECEMBER, 1); // Set the date to be December 1, 1996 - int32_t dow = cal->get(Calendar::DAY_OF_WEEK, status); - int32_t min = cal->getMinimum(Calendar::DAY_OF_WEEK); - int32_t max = cal->getMaximum(Calendar::DAY_OF_WEEK); - //logln(cal.getTime().toString()); - if (min != Calendar::SUNDAY || max != Calendar::SATURDAY) - errln("FAIL: Min/max bad"); - if (dow < min || dow > max) - errln(UnicodeString("FAIL: Day of week ") + dow + " out of range"); - if (dow != Calendar::SUNDAY) - errln("FAIL: Day of week should be SUNDAY Got " + dow); - - delete cal; - } - - /** - * @bug 4071385 - */ - void CalendarRegressionTest::test4071385() - { - UErrorCode status = U_ZERO_ERROR; - Calendar *cal = Calendar::createInstance(status); - cal->setTime(makeDate(1998, Calendar::JUNE, 24),status); - cal->set(Calendar::MONTH, Calendar::NOVEMBER); // change a field - //logln(cal.getTime().toString()); - if (cal->getTime(status) != makeDate(1998, Calendar::NOVEMBER, 24)) - errln("Fail"); - - delete cal; - } - - /** - * @bug 4073929 - */ - void CalendarRegressionTest::test4073929() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *foo1 = new GregorianCalendar(1997, 8, 27,status); - foo1->add(Calendar::DAY_OF_MONTH, + 1, status); - int32_t testyear = foo1->get(Calendar::YEAR, status); - int32_t testmonth = foo1->get(Calendar::MONTH, status); - int32_t testday = foo1->get(Calendar::DAY_OF_MONTH, status); - if (testyear != 1997 || - testmonth != 8 || - testday != 28) - errln("Fail: Calendar not initialized"); - - delete foo1; - } - - /** - * @bug 4083167 - */ - void CalendarRegressionTest::test4083167() - { - UErrorCode status = U_ZERO_ERROR; - TimeZone *saveZone = TimeZone::createDefault(); - //try { - TimeZone *newZone = TimeZone::createTimeZone("UTC"); - TimeZone::setDefault(*newZone); - UDate firstDate = Calendar::getNow(); - Calendar *cal = new GregorianCalendar(status); - cal->setTime(firstDate,status); - int32_t hr = cal->get(Calendar::HOUR_OF_DAY, status); - int32_t min = cal->get(Calendar::MINUTE, status); - int32_t sec = cal->get(Calendar::SECOND, status); - int32_t msec = cal->get(Calendar::MILLISECOND, status); - double firstMillisInDay = hr * 3600000 + min * 60000 + sec * 1000 + msec; - - //logln("Current time: " + firstDate.toString()); - - for (int32_t validity=0; validity<30; validity++) { - UDate lastDate = firstDate + validity*1000*24*60*60.0; - cal->setTime(lastDate, status); - hr = cal->get(Calendar::HOUR_OF_DAY, status); - min = cal->get(Calendar::MINUTE, status); - sec = cal->get(Calendar::SECOND, status); - msec = cal->get(Calendar::MILLISECOND, status); - double millisInDay = hr * 3600000.0 + min * 60000.0 + sec * 1000.0 + msec; - if (firstMillisInDay != millisInDay) - errln(UnicodeString("Day has shifted ") + lastDate); - } - //} - //finally { - TimeZone::setDefault(*saveZone); - //} - - delete saveZone; - delete newZone; - delete cal; - } - - /** - * @bug 4086724 - */ - void CalendarRegressionTest::test4086724() - { - UErrorCode status = U_ZERO_ERROR; - SimpleDateFormat *date; - TimeZone *saveZone = TimeZone::createDefault(); - Locale saveLocale = Locale::getDefault(); - //try { - Locale::setDefault(Locale::UK,status); - TimeZone *newZone = TimeZone::createTimeZone("GMT"); - TimeZone::setDefault(*newZone); - date = new SimpleDateFormat(UnicodeString("dd MMM yyy (zzzz) 'is in week' ww"),status); - Calendar *cal = Calendar::createInstance(status); - cal->set(1997,Calendar::SEPTEMBER,30); - UDate now = cal->getTime(status); - UnicodeString temp; - FieldPosition pos(FieldPosition::DONT_CARE); - logln(date->format(now, temp, pos)); - cal->set(1997,Calendar::JANUARY,1); - now=cal->getTime(status); - logln(date->format(now,temp, pos)); - cal->set(1997,Calendar::JANUARY,8); - now=cal->getTime(status); - logln(date->format(now,temp, pos)); - cal->set(1996,Calendar::DECEMBER,31); - now=cal->getTime(status); - logln(date->format(now,temp, pos)); - //} - //finally { - Locale::setDefault(saveLocale,status); - TimeZone::setDefault(*saveZone); - //} - logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***"); - - delete newZone; - delete cal; - delete date; - delete saveZone; +/** + * @bug 4035301 + */ +void CalendarRegressionTest::test4035301() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *c = new GregorianCalendar(98, 8, 7,status); + GregorianCalendar *d = new GregorianCalendar(98, 8, 7,status); + if (c->after(*d,status) || + c->after(*c,status) || + c->before(*d,status) || + c->before(*c,status) || + *c != *c || + *c != *d) + errln("Fail"); + delete c; + delete d; } - /** - * @bug 4092362 - */ - void CalendarRegressionTest::test4092362() { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status); - /*cal1.set( Calendar::YEAR, 1997 ); - cal1.set( Calendar::MONTH, 10 ); - cal1.set( Calendar::DATE, 11 ); - cal1.set( Calendar::HOUR, 10 ); - cal1.set( Calendar::MINUTE, 20 ); - cal1.set( Calendar::SECOND, 40 ); */ +/** + * @bug 4040996 + */ +void CalendarRegressionTest::test4040996() +{ + int32_t count = 0; + const UnicodeString **ids = TimeZone::createAvailableIDs(-8 * 60 * 60 * 1000, count); + SimpleTimeZone *pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *ids[0]); + UErrorCode status = U_ZERO_ERROR; + pdt->setStartRule(Calendar::APRIL, 1, Calendar::SUNDAY, 2 * 60 * 60 * 1000, status); + pdt->setEndRule(Calendar::OCTOBER, -1, Calendar::SUNDAY, 2 * 60 * 60 * 1000, status); + Calendar *calendar = new GregorianCalendar(pdt, status); - logln( UnicodeString(" Cal1 = ") + cal1->getTime(status) ); - logln( UnicodeString(" Cal1 time in ms = ") + cal1->get(Calendar::MILLISECOND,status) ); - for( int32_t k = 0; k < 100 ; k++ ); + calendar->set(Calendar::MONTH,3); + calendar->set(Calendar::DAY_OF_MONTH,18); + calendar->set(Calendar::SECOND, 30); - GregorianCalendar *cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status); - /*cal2.set( Calendar::YEAR, 1997 ); - cal2.set( Calendar::MONTH, 10 ); - cal2.set( Calendar::DATE, 11 ); - cal2.set( Calendar::HOUR, 10 ); - cal2.set( Calendar::MINUTE, 20 ); - cal2.set( Calendar::SECOND, 40 ); */ + logln(UnicodeString("MONTH: ") + calendar->get(Calendar::MONTH, status)); + logln(UnicodeString("DAY_OF_MONTH: ") + + calendar->get(Calendar::DAY_OF_MONTH, status)); + logln(UnicodeString("MINUTE: ") + calendar->get(Calendar::MINUTE, status)); + logln(UnicodeString("SECOND: ") + calendar->get(Calendar::SECOND, status)); - logln( UnicodeString(" Cal2 = ") + cal2->getTime(status) ); - logln( UnicodeString(" Cal2 time in ms = ") + cal2->get(Calendar::MILLISECOND,status) ); - if( *cal1 != *cal2 ) - errln("Fail: Milliseconds randomized"); + calendar->add(Calendar::SECOND,6, status); + //This will print out todays date for MONTH and DAY_OF_MONTH + //instead of the date it was set to. + //This happens when adding MILLISECOND or MINUTE also + logln(UnicodeString("MONTH: ") + calendar->get(Calendar::MONTH, status)); + logln(UnicodeString("DAY_OF_MONTH: ") + + calendar->get(Calendar::DAY_OF_MONTH, status)); + logln(UnicodeString("MINUTE: ") + calendar->get(Calendar::MINUTE, status)); + logln(UnicodeString("SECOND: ") + calendar->get(Calendar::SECOND, status)); + if (calendar->get(Calendar::MONTH, status) != 3 || + calendar->get(Calendar::DAY_OF_MONTH, status) != 18 || + calendar->get(Calendar::SECOND, status) != 36) + errln(UnicodeString("Fail: Calendar::add misbehaves")); + + delete calendar; + uprv_free(ids); + // delete ids; // TODO: BAD API +} + +/** + * @bug 4051765 + */ +void CalendarRegressionTest::test4051765() +{ + UErrorCode status = U_ZERO_ERROR; + Calendar *cal = Calendar::createInstance(status); + cal->setLenient(FALSE); + cal->set(Calendar::DAY_OF_WEEK, 0); + //try { + cal->getTime(status); + if( ! U_FAILURE(status)) + errln("Fail: DAY_OF_WEEK 0 should be disallowed"); + /*} + catch (IllegalArgumentException e) { + return; + }*/ + + delete cal; +} + +/* User error - no bug here +void CalendarRegressionTest::test4059524() { + // Create calendar for April 10, 1997 + GregorianCalendar calendar = new GregorianCalendar(status); + // print out a bunch of interesting things + logln("ERA: " + Calendar::get(Calendar::ERA)); + logln("YEAR: " + Calendar::get(Calendar::YEAR)); + logln("MONTH: " + Calendar::get(Calendar::MONTH)); + logln("WEEK_OF_YEAR: " + + Calendar::get(Calendar::WEEK_OF_YEAR)); + logln("WEEK_OF_MONTH: " + + Calendar::get(Calendar::WEEK_OF_MONTH)); + logln("DATE: " + Calendar::get(Calendar::DATE)); + logln("DAY_OF_MONTH: " + + Calendar::get(Calendar::DAY_OF_MONTH)); + logln("DAY_OF_YEAR: " + Calendar::get(Calendar::DAY_OF_YEAR)); + logln("DAY_OF_WEEK: " + Calendar::get(Calendar::DAY_OF_WEEK)); + logln("DAY_OF_WEEK_IN_MONTH: " + + Calendar::get(Calendar::DAY_OF_WEEK_IN_MONTH)); + logln("AM_PM: " + Calendar::get(Calendar::AM_PM)); + logln("HOUR: " + Calendar::get(Calendar::HOUR)); + logln("HOUR_OF_DAY: " + Calendar::get(Calendar::HOUR_OF_DAY)); + logln("MINUTE: " + Calendar::get(Calendar::MINUTE)); + logln("SECOND: " + Calendar::get(Calendar::SECOND)); + logln("MILLISECOND: " + Calendar::get(Calendar::MILLISECOND)); + logln("ZONE_OFFSET: " + + (Calendar::get(Calendar::ZONE_OFFSET)/(60*60*1000))); + logln("DST_OFFSET: " + + (Calendar::get(Calendar::DST_OFFSET)/(60*60*1000))); + calendar = new GregorianCalendar(1997,3,10); + Calendar::getTime(); + logln("April 10, 1997"); + logln("ERA: " + Calendar::get(Calendar::ERA)); + logln("YEAR: " + Calendar::get(Calendar::YEAR)); + logln("MONTH: " + Calendar::get(Calendar::MONTH)); + logln("WEEK_OF_YEAR: " + + Calendar::get(Calendar::WEEK_OF_YEAR)); + logln("WEEK_OF_MONTH: " + + Calendar::get(Calendar::WEEK_OF_MONTH)); + logln("DATE: " + Calendar::get(Calendar::DATE)); + logln("DAY_OF_MONTH: " + + Calendar::get(Calendar::DAY_OF_MONTH)); + logln("DAY_OF_YEAR: " + Calendar::get(Calendar::DAY_OF_YEAR)); + logln("DAY_OF_WEEK: " + Calendar::get(Calendar::DAY_OF_WEEK)); + logln("DAY_OF_WEEK_IN_MONTH: " + Calendar::get(Calendar::DAY_OF_WEEK_IN_MONTH)); + logln("AM_PM: " + Calendar::get(Calendar::AM_PM)); + logln("HOUR: " + Calendar::get(Calendar::HOUR)); + logln("HOUR_OF_DAY: " + Calendar::get(Calendar::HOUR_OF_DAY)); + logln("MINUTE: " + Calendar::get(Calendar::MINUTE)); + logln("SECOND: " + Calendar::get(Calendar::SECOND)); + logln("MILLISECOND: " + Calendar::get(Calendar::MILLISECOND)); + logln("ZONE_OFFSET: " + + (Calendar::get(Calendar::ZONE_OFFSET)/(60*60*1000))); // in hours + logln("DST_OFFSET: " + + (Calendar::get(Calendar::DST_OFFSET)/(60*60*1000))); // in hours +} +*/ + +/** + * @bug 4059654 + */ +void CalendarRegressionTest::test4059654() { + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *gc = new GregorianCalendar(status); - delete cal1; - delete cal2; - } + gc->set(1997, 3, 1, 15, 16, 17); // April 1, 1997 - /** - * @bug 4095407 - */ - void CalendarRegressionTest::test4095407() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *a = new GregorianCalendar(1997,Calendar::NOVEMBER, 13,status); - int32_t dow = a->get(Calendar::DAY_OF_WEEK, status); - if (dow != Calendar::THURSDAY) - errln("Fail: Want THURSDAY Got " + dow); - - delete a; - } + gc->set(Calendar::HOUR, 0); + gc->set(Calendar::AM_PM, Calendar::AM); + gc->set(Calendar::MINUTE, 0); + gc->set(Calendar::SECOND, 0); + gc->set(Calendar::MILLISECOND, 0); - /** - * @bug 4096231 - */ - void CalendarRegressionTest::test4096231() - { - UErrorCode status = U_ZERO_ERROR; - TimeZone *GMT = TimeZone::createTimeZone("GMT"); - TimeZone *PST = TimeZone::createTimeZone("PST"); - int32_t sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997; - - Calendar *cal1 = new GregorianCalendar(*PST,status); - cal1->setTime(880698639000.0,status); - // Issue 1: Changing the timezone doesn't change the - // represented time. The old API, pre 1.2.2a requires - // setTime to be called in order to update the time fields after the time - // zone has been set. - int32_t h1,h2; - logln(UnicodeString("PST 1 is: ") + (h1=cal1->get(Calendar::HOUR_OF_DAY, status))); - cal1->setTimeZone(*GMT); - logln(UnicodeString("GMT 2 is: ") + (h2=cal1->get(Calendar::HOUR_OF_DAY, status))); - if ((*GMT != *PST) && (h1 == h2)) - errln("Fail: Hour same in different zones"); + UDate cd = gc->getTime(status); + GregorianCalendar *exp = new GregorianCalendar(97, 3, 1, 0, 0, 0, status); + if (cd != exp->getTime(status)) + errln(UnicodeString("Fail: Calendar::set broken. Got ") + cd + " Want " + exp->getTime(status)); - Calendar *cal2 = new GregorianCalendar(*GMT,status); - Calendar *cal3 = new GregorianCalendar(*PST,status); + delete gc; + delete exp; +} - cal2->set(cal1->get(Calendar::YEAR,status), - cal1->get(Calendar::MONTH,status), - cal1->get(Calendar::DAY_OF_MONTH,status), - cal1->get(Calendar::HOUR_OF_DAY,status), - cal1->get(Calendar::MINUTE,status), - cal1->get(Calendar::SECOND,status)); +/** + * @bug 4061476 + */ +void CalendarRegressionTest::test4061476() +{ + UErrorCode status = U_ZERO_ERROR; + SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("ddMMMyy"), Locale::getUK(),status); + Calendar *cal = Calendar::createInstance(TimeZone::createTimeZone("GMT"), + Locale::getUK(),status); + fmt->adoptCalendar(cal); + // try { + UDate date = fmt->parse("29MAY97", status); + failure(status, "fmt->parse"); + cal->setTime(date, status); + failure(status, "cal->setTime"); + // } + //catch (Exception e) {;} + cal->set(Calendar::HOUR_OF_DAY, 13); + logln(UnicodeString("Hour: ")+cal->get(Calendar::HOUR_OF_DAY, status)); + cal->add(Calendar::HOUR_OF_DAY, 6,status); + logln(UnicodeString("Hour: ")+cal->get(Calendar::HOUR_OF_DAY, status)); + if (cal->get(Calendar::HOUR_OF_DAY, status) != 19) + errln(UnicodeString("Fail: Want 19 Got ") + cal->get(Calendar::HOUR_OF_DAY, status)); - double t1,t2,t3,t4; - logln(UnicodeString("RGMT 1 is: ") + (t1=cal2->getTime(status))); - cal3->set(year, month, day, hr, min, sec); - logln(UnicodeString("RPST 1 is: ") + (t2=cal3->getTime(status))); - cal3->setTimeZone(*GMT); - logln(UnicodeString("RGMT 2 is: ") + (t3=cal3->getTime(status))); - cal3->set(cal1->get(Calendar::YEAR,status), - cal1->get(Calendar::MONTH,status), - cal1->get(Calendar::DAY_OF_MONTH,status), - cal1->get(Calendar::HOUR_OF_DAY,status), - cal1->get(Calendar::MINUTE,status), - cal1->get(Calendar::SECOND,status)); - // Issue 2: Calendar continues to use the timezone in its - // constructor for set() conversions, regardless - // of calls to setTimeZone() - logln(UnicodeString("RGMT 3 is: ") + (t4=cal3->getTime(status))); - if (t1 == t2 || - t1 != t4 || - t2 != t3) - errln("Fail: Calendar zone behavior faulty"); - - delete cal1; - delete cal2; - delete cal3; - delete GMT; - delete PST; - } + delete fmt; +} - /** - * @bug 4096539 - */ - void CalendarRegressionTest::test4096539() - { - UErrorCode status = U_ZERO_ERROR; - int32_t y [] = {31,28,31,30,31,30,31,31,30,31,30,31}; +/** + * @bug 4070502 + */ +void CalendarRegressionTest::test4070502() +{ + UErrorCode status = U_ZERO_ERROR; + UDate d = getAssociatedDate(makeDate(1998,0,30), status); + Calendar *cal = new GregorianCalendar(status); + cal->setTime(d,status); + if (cal->get(Calendar::DAY_OF_WEEK,status) == Calendar::SATURDAY || + cal->get(Calendar::DAY_OF_WEEK,status) == Calendar::SUNDAY) + errln(UnicodeString("Fail: Want weekday Got ") + d); - for (int32_t x=0;x<12;x++) { - GregorianCalendar *gc = new - GregorianCalendar(1997,x,y[x], status); - int32_t m1,m2; - log(UnicodeString("") + (m1=gc->get(Calendar::MONTH,status)+1)+UnicodeString("/")+ - gc->get(Calendar::DATE,status)+"/"+gc->get(Calendar::YEAR,status)+ - " + 1mo = "); + delete cal; +} - gc->add(Calendar::MONTH, 1,status); - logln(UnicodeString("") + (m2=gc->get(Calendar::MONTH,status)+1)+UnicodeString("/")+ - gc->get(Calendar::DATE,status)+"/"+gc->get(Calendar::YEAR,status) - ); - int32_t m = (m1 % 12) + 1; - if (m2 != m) - errln(UnicodeString("Fail: Want ") + m + " Got " + m2); - delete gc; +/** + * Get the associated date starting from a specified date + * NOTE: the unnecessary "getTime()'s" below are a work-around for a + * bug in jdk 1.1.3 (and probably earlier versions also) + *

+ * @param date The date to start from + */ +UDate +CalendarRegressionTest::getAssociatedDate(UDate d, UErrorCode& status) +{ + GregorianCalendar *cal = new GregorianCalendar(status); + cal->setTime(d,status); + //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH + // cal.getTime(); // <--- REMOVE THIS TO SEE BUG + for (;;) { + int32_t wd = cal->get(Calendar::DAY_OF_WEEK, status); + if (wd == Calendar::SATURDAY || wd == Calendar::SUNDAY) { + cal->add(Calendar::DATE, 1, status); + // cal.getTime(); } + else + break; + } + + UDate dd = cal->getTime(status); + delete cal; + return dd; +} + +/** + * @bug 4071197 + */ +void CalendarRegressionTest::test4071197() +{ + dowTest(FALSE); + dowTest(TRUE); +} + +void CalendarRegressionTest::dowTest(UBool lenient) +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *cal = new GregorianCalendar(status); + cal->set(1997, Calendar::AUGUST, 12); // Wednesday + // cal.getTime(); // Force update + cal->setLenient(lenient); + cal->set(1996, Calendar::DECEMBER, 1); // Set the date to be December 1, 1996 + int32_t dow = cal->get(Calendar::DAY_OF_WEEK, status); + int32_t min = cal->getMinimum(Calendar::DAY_OF_WEEK); + int32_t max = cal->getMaximum(Calendar::DAY_OF_WEEK); + //logln(cal.getTime().toString()); + if (min != Calendar::SUNDAY || max != Calendar::SATURDAY) + errln("FAIL: Min/max bad"); + if (dow < min || dow > max) + errln(UnicodeString("FAIL: Day of week ") + dow + " out of range"); + if (dow != Calendar::SUNDAY) + errln("FAIL: Day of week should be SUNDAY Got " + dow); + + delete cal; +} + +/** + * @bug 4071385 + */ +void CalendarRegressionTest::test4071385() +{ + UErrorCode status = U_ZERO_ERROR; + Calendar *cal = Calendar::createInstance(status); + cal->setTime(makeDate(1998, Calendar::JUNE, 24),status); + cal->set(Calendar::MONTH, Calendar::NOVEMBER); // change a field + //logln(cal.getTime().toString()); + if (cal->getTime(status) != makeDate(1998, Calendar::NOVEMBER, 24)) + errln("Fail"); + + delete cal; +} + +/** + * @bug 4073929 + */ +void CalendarRegressionTest::test4073929() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *foo1 = new GregorianCalendar(1997, 8, 27,status); + foo1->add(Calendar::DAY_OF_MONTH, + 1, status); + int32_t testyear = foo1->get(Calendar::YEAR, status); + int32_t testmonth = foo1->get(Calendar::MONTH, status); + int32_t testday = foo1->get(Calendar::DAY_OF_MONTH, status); + if (testyear != 1997 || + testmonth != 8 || + testday != 28) + errln("Fail: Calendar not initialized"); + + delete foo1; +} + +/** + * @bug 4083167 + */ +void CalendarRegressionTest::test4083167() +{ + UErrorCode status = U_ZERO_ERROR; + TimeZone *saveZone = TimeZone::createDefault(); + //try { + TimeZone *newZone = TimeZone::createTimeZone("UTC"); + TimeZone::setDefault(*newZone); + UDate firstDate = Calendar::getNow(); + Calendar *cal = new GregorianCalendar(status); + cal->setTime(firstDate,status); + int32_t hr = cal->get(Calendar::HOUR_OF_DAY, status); + int32_t min = cal->get(Calendar::MINUTE, status); + int32_t sec = cal->get(Calendar::SECOND, status); + int32_t msec = cal->get(Calendar::MILLISECOND, status); + double firstMillisInDay = hr * 3600000 + min * 60000 + sec * 1000 + msec; - } + //logln("Current time: " + firstDate.toString()); - /** - * @bug 4100311 - */ - void CalendarRegressionTest::test41003112() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status); - cal->set(Calendar::YEAR, 1997); - cal->set(Calendar::DAY_OF_YEAR, 1); - //UDate d = cal->getTime(status); // Should be Jan 1 - //logln(d.toString()); - if (cal->get(Calendar::DAY_OF_YEAR, status) != 1) - errln("Fail: DAY_OF_YEAR not set"); - delete cal; - } + for (int32_t validity=0; validity<30; validity++) { + UDate lastDate = firstDate + validity*1000*24*60*60.0; + cal->setTime(lastDate, status); + hr = cal->get(Calendar::HOUR_OF_DAY, status); + min = cal->get(Calendar::MINUTE, status); + sec = cal->get(Calendar::SECOND, status); + msec = cal->get(Calendar::MILLISECOND, status); + double millisInDay = hr * 3600000.0 + min * 60000.0 + sec * 1000.0 + msec; + if (firstMillisInDay != millisInDay) + errln(UnicodeString("Day has shifted ") + lastDate); + } + //} + //finally { + TimeZone::setDefault(*saveZone); + //} - /** - * @bug 4103271 - */ - void CalendarRegressionTest::test4103271() - { - UErrorCode status = U_ZERO_ERROR; - SimpleDateFormat sdf(status); - int32_t numYears=40, startYear=1997, numDays=15; - UnicodeString output, testDesc, str, str2; - GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status); - testCal->clear(); - sdf.adoptCalendar(testCal); - sdf.applyPattern("EEE dd MMM yyyy 'WOY'ww'-'YYYY 'DOY'DDD"); - UBool fail = FALSE; - for (int32_t firstDay=1; firstDay<=2; firstDay++) { - for (int32_t minDays=1; minDays<=7; minDays++) { - testCal->setMinimalDaysInFirstWeek((uint8_t)minDays); - testCal->setFirstDayOfWeek((Calendar::EDaysOfWeek)firstDay); - testDesc = (UnicodeString("Test") + firstDay + minDays); - logln(testDesc + " => 1st day of week=" + - firstDay + - ", minimum days in first week=" + - minDays); - for (int32_t j=startYear; j<=startYear+numYears; j++) { - testCal->set(j,11,25); - for(int32_t i=0; iadd(Calendar::DATE,1,status); - UnicodeString calWOY; - int32_t actWOY = testCal->get(Calendar::WEEK_OF_YEAR,status); - if (actWOY < 1 || actWOY > 53) { - UDate d = testCal->getTime(status); - //calWOY = String.valueOf(actWOY); - UnicodeString temp; - FieldPosition pos(FieldPosition::DONT_CARE); - output = testDesc + " - " + sdf.format(d,temp,pos) + "\t"; - output = output + "\t" + actWOY; - logln(output); - fail = TRUE; - } - } + delete saveZone; + delete newZone; + delete cal; +} + +/** + * @bug 4086724 + */ +void CalendarRegressionTest::test4086724() +{ + UErrorCode status = U_ZERO_ERROR; + SimpleDateFormat *date; + TimeZone *saveZone = TimeZone::createDefault(); + Locale saveLocale = Locale::getDefault(); + //try { + Locale::setDefault(Locale::getUK(),status); + TimeZone *newZone = TimeZone::createTimeZone("GMT"); + TimeZone::setDefault(*newZone); + date = new SimpleDateFormat(UnicodeString("dd MMM yyy (zzzz) 'is in week' ww"),status); + Calendar *cal = Calendar::createInstance(status); + cal->set(1997,Calendar::SEPTEMBER,30); + UDate now = cal->getTime(status); + UnicodeString temp; + FieldPosition pos(FieldPosition::DONT_CARE); + logln(date->format(now, temp, pos)); + cal->set(1997,Calendar::JANUARY,1); + now=cal->getTime(status); + logln(date->format(now,temp, pos)); + cal->set(1997,Calendar::JANUARY,8); + now=cal->getTime(status); + logln(date->format(now,temp, pos)); + cal->set(1996,Calendar::DECEMBER,31); + now=cal->getTime(status); + logln(date->format(now,temp, pos)); + //} + //finally { + Locale::setDefault(saveLocale,status); + TimeZone::setDefault(*saveZone); + //} + logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***"); + +delete newZone; +delete cal; +delete date; +delete saveZone; +} + +/** + * @bug 4092362 + */ +void CalendarRegressionTest::test4092362() { + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status); + /*cal1.set( Calendar::YEAR, 1997 ); + cal1.set( Calendar::MONTH, 10 ); + cal1.set( Calendar::DATE, 11 ); + cal1.set( Calendar::HOUR, 10 ); + cal1.set( Calendar::MINUTE, 20 ); + cal1.set( Calendar::SECOND, 40 ); */ + + logln( UnicodeString(" Cal1 = ") + cal1->getTime(status) ); + logln( UnicodeString(" Cal1 time in ms = ") + cal1->get(Calendar::MILLISECOND,status) ); + for( int32_t k = 0; k < 100 ; k++ ); + + GregorianCalendar *cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40,status); + /*cal2.set( Calendar::YEAR, 1997 ); + cal2.set( Calendar::MONTH, 10 ); + cal2.set( Calendar::DATE, 11 ); + cal2.set( Calendar::HOUR, 10 ); + cal2.set( Calendar::MINUTE, 20 ); + cal2.set( Calendar::SECOND, 40 ); */ + + logln( UnicodeString(" Cal2 = ") + cal2->getTime(status) ); + logln( UnicodeString(" Cal2 time in ms = ") + cal2->get(Calendar::MILLISECOND,status) ); + if( *cal1 != *cal2 ) + errln("Fail: Milliseconds randomized"); + + delete cal1; + delete cal2; +} + +/** + * @bug 4095407 + */ +void CalendarRegressionTest::test4095407() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *a = new GregorianCalendar(1997,Calendar::NOVEMBER, 13,status); + int32_t dow = a->get(Calendar::DAY_OF_WEEK, status); + if (dow != Calendar::THURSDAY) + errln("Fail: Want THURSDAY Got " + dow); + + delete a; +} + +/** + * @bug 4096231 + */ +void CalendarRegressionTest::test4096231() +{ + UErrorCode status = U_ZERO_ERROR; + TimeZone *GMT = TimeZone::createTimeZone("GMT"); + TimeZone *PST = TimeZone::createTimeZone("PST"); + int32_t sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997; + + Calendar *cal1 = new GregorianCalendar(*PST,status); + cal1->setTime(880698639000.0,status); + // Issue 1: Changing the timezone doesn't change the + // represented time. The old API, pre 1.2.2a requires + // setTime to be called in order to update the time fields after the time + // zone has been set. + int32_t h1,h2; + logln(UnicodeString("PST 1 is: ") + (h1=cal1->get(Calendar::HOUR_OF_DAY, status))); + cal1->setTimeZone(*GMT); + logln(UnicodeString("GMT 2 is: ") + (h2=cal1->get(Calendar::HOUR_OF_DAY, status))); + if ((*GMT != *PST) && (h1 == h2)) + errln("Fail: Hour same in different zones"); + + Calendar *cal2 = new GregorianCalendar(*GMT,status); + Calendar *cal3 = new GregorianCalendar(*PST,status); + + cal2->set(cal1->get(Calendar::YEAR,status), + cal1->get(Calendar::MONTH,status), + cal1->get(Calendar::DAY_OF_MONTH,status), + cal1->get(Calendar::HOUR_OF_DAY,status), + cal1->get(Calendar::MINUTE,status), + cal1->get(Calendar::SECOND,status)); + + double t1,t2,t3,t4; + logln(UnicodeString("RGMT 1 is: ") + (t1=cal2->getTime(status))); + cal3->set(year, month, day, hr, min, sec); + logln(UnicodeString("RPST 1 is: ") + (t2=cal3->getTime(status))); + cal3->setTimeZone(*GMT); + logln(UnicodeString("RGMT 2 is: ") + (t3=cal3->getTime(status))); + cal3->set(cal1->get(Calendar::YEAR,status), + cal1->get(Calendar::MONTH,status), + cal1->get(Calendar::DAY_OF_MONTH,status), + cal1->get(Calendar::HOUR_OF_DAY,status), + cal1->get(Calendar::MINUTE,status), + cal1->get(Calendar::SECOND,status)); + // Issue 2: Calendar continues to use the timezone in its + // constructor for set() conversions, regardless + // of calls to setTimeZone() + logln(UnicodeString("RGMT 3 is: ") + (t4=cal3->getTime(status))); + if (t1 == t2 || + t1 != t4 || + t2 != t3) + errln("Fail: Calendar zone behavior faulty"); + + delete cal1; + delete cal2; + delete cal3; + delete GMT; + delete PST; +} + +/** + * @bug 4096539 + */ +void CalendarRegressionTest::test4096539() +{ + UErrorCode status = U_ZERO_ERROR; + int32_t y [] = {31,28,31,30,31,30,31,31,30,31,30,31}; + + for (int32_t x=0;x<12;x++) { + GregorianCalendar *gc = new + GregorianCalendar(1997,x,y[x], status); + int32_t m1,m2; + log(UnicodeString("") + (m1=gc->get(Calendar::MONTH,status)+1)+UnicodeString("/")+ + gc->get(Calendar::DATE,status)+"/"+gc->get(Calendar::YEAR,status)+ + " + 1mo = "); + + gc->add(Calendar::MONTH, 1,status); + logln(UnicodeString("") + (m2=gc->get(Calendar::MONTH,status)+1)+UnicodeString("/")+ + gc->get(Calendar::DATE,status)+"/"+gc->get(Calendar::YEAR,status) + ); + int32_t m = (m1 % 12) + 1; + if (m2 != m) + errln(UnicodeString("Fail: Want ") + m + " Got " + m2); + delete gc; + } + +} + +/** + * @bug 4100311 + */ +void CalendarRegressionTest::test41003112() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *cal = (GregorianCalendar*)Calendar::createInstance(status); + cal->set(Calendar::YEAR, 1997); + cal->set(Calendar::DAY_OF_YEAR, 1); + //UDate d = cal->getTime(status); // Should be Jan 1 + //logln(d.toString()); + if (cal->get(Calendar::DAY_OF_YEAR, status) != 1) + errln("Fail: DAY_OF_YEAR not set"); + delete cal; +} + +/** + * @bug 4103271 + */ +void CalendarRegressionTest::test4103271() +{ + UErrorCode status = U_ZERO_ERROR; + SimpleDateFormat sdf(status); + int32_t numYears=40, startYear=1997, numDays=15; + UnicodeString output, testDesc, str, str2; + GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status); + testCal->clear(); + sdf.adoptCalendar(testCal); + sdf.applyPattern("EEE dd MMM yyyy 'WOY'ww'-'YYYY 'DOY'DDD"); + UBool fail = FALSE; + for (int32_t firstDay=1; firstDay<=2; firstDay++) { + for (int32_t minDays=1; minDays<=7; minDays++) { + testCal->setMinimalDaysInFirstWeek((uint8_t)minDays); + testCal->setFirstDayOfWeek((Calendar::EDaysOfWeek)firstDay); + testDesc = (UnicodeString("Test") + firstDay + minDays); + logln(testDesc + " => 1st day of week=" + + firstDay + + ", minimum days in first week=" + + minDays); + for (int32_t j=startYear; j<=startYear+numYears; j++) { + testCal->set(j,11,25); + for(int32_t i=0; iadd(Calendar::DATE,1,status); + UnicodeString calWOY; + int32_t actWOY = testCal->get(Calendar::WEEK_OF_YEAR,status); + if (actWOY < 1 || actWOY > 53) { + UDate d = testCal->getTime(status); + //calWOY = String.valueOf(actWOY); + UnicodeString temp; + FieldPosition pos(FieldPosition::DONT_CARE); + output = testDesc + " - " + sdf.format(d,temp,pos) + "\t"; + output = output + "\t" + actWOY; + logln(output); + fail = TRUE; + } } } } - - int32_t DATA [] = { - 3, 52, 52, 52, 52, 52, 52, 52, - 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, - 4, 52, 52, 52, 52, 52, 52, 52, - 53, 53, 53, 53, 53, 53, 53, - 1, 1, 1, 1, 1, 1, 1, - }; - testCal->setFirstDayOfWeek(Calendar::SUNDAY); - for (int32_t j=0; j<44; j+=22) { - logln(UnicodeString("Minimal days in first week = ") + DATA[j] + - " Week starts on Sunday"); - testCal->setMinimalDaysInFirstWeek((uint8_t)DATA[j]); - testCal->set(1997, Calendar::DECEMBER, 21); - for (int32_t i=0; i<21; ++i) { - int32_t woy = testCal->get(Calendar::WEEK_OF_YEAR,status); - str.remove(); - log(UnicodeString("") + sdf.format(testCal->getTime(status), str) + - UnicodeString(" ") + woy); - if (woy != DATA[j + 1 + i]) { - log(" ERROR"); - fail = TRUE; - } - logln(""); - - // Now compute the time from the fields, and make sure we - // get the same answer back. This is a round-trip test. - UDate save = testCal->getTime(status); - testCal->clear(); - testCal->set(Calendar::YEAR_WOY, DATA[j+1+i] < 25 ? 1998 : 1997); - testCal->set(Calendar::WEEK_OF_YEAR, DATA[j+1+i]); - testCal->set(Calendar::DAY_OF_WEEK, (i%7) + Calendar::SUNDAY); - if (testCal->getTime(status) != save) { - str.remove(); - logln(UnicodeString(" Parse failed: ") + - sdf.format(testCal->getTime(status), str)); - fail= TRUE; - } - - testCal->setTime(save,status); - testCal->add(Calendar::DAY_OF_MONTH, 1,status); - } - } - - // Test field disambiguation with a few special hard-coded cases. - // This shouldn't fail if the above cases aren't failing. - int32_t DISAM_int [] = { - // y y_woy woy dow - 1997, 1998, 1, Calendar::SUNDAY, - (1998), (1998), (2), (Calendar::SATURDAY), - (1998), (1998), (53), (Calendar::THURSDAY), - (1999), (1998), (53), (Calendar::FRIDAY) - }; - - UDate DISAM_date [] = { - makeDate(1997, Calendar::DECEMBER, 28), - makeDate(1998, Calendar::JANUARY, 10), - makeDate(1998, Calendar::DECEMBER, 31), - makeDate(1999, Calendar::JANUARY, 1) - }; - - testCal->setMinimalDaysInFirstWeek(3); - testCal->setFirstDayOfWeek(Calendar::SUNDAY); - int32_t i = 0; - - /* Enable this code to display various WOY values - testCal->clear(); - for (i=25; i<38; ++i) { - testCal->set(1996, Calendar::DECEMBER, i); - UDate got = testCal->getTime(status); - str.remove(); - logln(UnicodeString("") + sdf.format(got, str)); - } - for (i=25; i<38; ++i) { - testCal->set(1997, Calendar::DECEMBER, i); - UDate got = testCal->getTime(status); - str.remove(); - logln(UnicodeString("") + sdf.format(got, str)); - } - for (i=25; i<38; ++i) { - testCal->set(1998, Calendar::DECEMBER, i); - UDate got = testCal->getTime(status); - str.remove(); - logln(UnicodeString("") + sdf.format(got, str)); - } - */ - - for (i=0; i < 16; i += 4) { - int32_t y = DISAM_int[i]; - int32_t ywoy = DISAM_int[i+1]; - int32_t woy = DISAM_int[i+2]; - int32_t dow = DISAM_int[i+3]; - UDate exp = DISAM_date[i/4]; - testCal->clear(); - testCal->set(Calendar::YEAR, y); - testCal->set(Calendar::WEEK_OF_YEAR, woy); - testCal->set(Calendar::DAY_OF_WEEK, dow); - UDate got = testCal->getTime(status); - str.remove(); - str2.remove(); - log(UnicodeString("Y") + y + "-W" + woy + - "-DOW" + dow + " expect:" + sdf.format(exp, str) + - " got:" + sdf.format(got, str2)); - if (got != exp) { - log(" FAIL"); - fail = TRUE; - } - logln(""); - - testCal->clear(); - testCal->set(Calendar::YEAR_WOY, ywoy); - testCal->set(Calendar::WEEK_OF_YEAR, woy); - testCal->set(Calendar::DAY_OF_WEEK, dow); - got = testCal->getTime(status); - str.remove(); - str2.remove(); - log(UnicodeString("YWOY") + ywoy + "-W" + woy + - "-DOW" + dow + " expect:" + sdf.format(exp, str) + - " got:" + sdf.format(got, str2)); - if (got != exp) { - log(" FAIL"); - fail = TRUE; - } - logln(""); - } - - // Now try adding and rolling - UDate ADDROLL_date [] = { - makeDate(1998, Calendar::DECEMBER, 25), makeDate(1999, Calendar::JANUARY, 1), - makeDate(1997, Calendar::DECEMBER, 28), makeDate(1998, Calendar::JANUARY, 4), - makeDate(1998, Calendar::DECEMBER, 27), makeDate(1997, Calendar::DECEMBER, 28), - makeDate(1999, Calendar::JANUARY, 2), makeDate(1998, Calendar::JANUARY, 3), - }; - - int32_t ADDROLL_int []= { - (1), - (1), - (1), - (1) - }; - - - UBool ADDROLL_bool [] = { - TRUE,//ADD, - TRUE, - FALSE, - FALSE - }; - - testCal->setMinimalDaysInFirstWeek(3); - testCal->setFirstDayOfWeek(Calendar::SUNDAY); - for (i=0; i<8; i += 2) { - int32_t amount = ADDROLL_int[i/2]; - UDate before = ADDROLL_date[i]; - UDate after = ADDROLL_date[i+1]; - - testCal->setTime(before,status); - if (ADDROLL_bool[i/2]) - testCal->add(Calendar::WEEK_OF_YEAR, amount,status); - else - testCal->roll(Calendar::WEEK_OF_YEAR, amount,status); - UDate got = testCal->getTime(status); - str.remove(); - str2.remove(); - log((ADDROLL_bool[i/2]? UnicodeString("add(WOY,"):UnicodeString("roll(WOY,")) + - amount + ") " + sdf.format(before, str) + " => " + - sdf.format(got, str2)); - if (after != got) { - str.remove(); - logln(UnicodeString(" exp:") + sdf.format(after, str) + " FAIL"); - fail = TRUE; - } - else logln(" ok"); - - testCal->setTime(after,status); - if (ADDROLL_bool[i/2]) - testCal->add(Calendar::WEEK_OF_YEAR, -amount,status); - else - testCal->roll(Calendar::WEEK_OF_YEAR, -amount,status); - got = testCal->getTime(status); - str.remove(); - str2.remove(); - log((ADDROLL_bool[i/2]?UnicodeString("add(WOY,"):UnicodeString("roll(WOY,")) + - (-amount) + ") " + sdf.format(after, str) + " => " + - sdf.format(got, str2)); - if (before != got) { - str.remove(); - logln(UnicodeString(" exp:") + sdf.format(before, str) + " FAIL"); - fail = TRUE; - } - else logln(" ok"); - } - - if (fail) - errln("Fail: Week of year misbehaving"); } - /** - * @bug 4106136 - */ - void CalendarRegressionTest::test4106136() - { - UErrorCode status = U_ZERO_ERROR; - Locale saveLocale = Locale::getDefault(); - //try { - Locale locales [] = { Locale::getChinese(), Locale::getChina() }; - for (int32_t i=0; i<2; ++i) { - Locale::setDefault(locales[i], status); - failure(status, "Locale::setDefault"); - int32_t count1, count2, count3; - Calendar::getAvailableLocales(count1); - DateFormat::getAvailableLocales(count2); - NumberFormat::getAvailableLocales(count3); - int32_t n [] = { - count1, count2, count3 - }; - for (int32_t j=0; j<3; ++j) { - UnicodeString temp; - if (n[j] == 0) - errln(UnicodeString("Fail: No locales for ") + locales[i].getName()); - } - } - //} - //finally { - Locale::setDefault(saveLocale,status); - //} - } - - /** - * @bug 4108764 - */ - void CalendarRegressionTest::test4108764() - { - UErrorCode status = U_ZERO_ERROR; - UDate d00 = makeDate(1997, Calendar::MARCH, 15, 12, 00, 00); - UDate d01 = makeDate(1997, Calendar::MARCH, 15, 12, 00, 56); - UDate d10 = makeDate(1997, Calendar::MARCH, 15, 12, 34, 00); - UDate d11 = makeDate(1997, Calendar::MARCH, 15, 12, 34, 56); - UDate epoch = makeDate(1970, Calendar::JANUARY, 1); - - Calendar *cal = Calendar::createInstance(status); - cal->setTime(d11,status); - - cal->clear( Calendar::MINUTE ); - logln(UnicodeString("") + cal->getTime(status)); - if (cal->getTime(status) != d01) - errln("Fail: clear(MINUTE) broken"); - - cal->set( Calendar::SECOND, 0 ); - logln(UnicodeString("") + cal->getTime(status)); - if (cal->getTime(status) != d00) - errln("Fail: set(SECOND, 0) broken"); - - cal->setTime(d11,status); - cal->set( Calendar::SECOND, 0 ); - logln(UnicodeString("") + cal->getTime(status)); - if (cal->getTime(status) != d10) - errln("Fail: set(SECOND, 0) broken #2"); - - cal->clear( Calendar::MINUTE ); - logln(UnicodeString("") + cal->getTime(status)); - if (cal->getTime(status) != d00) - errln("Fail: clear(MINUTE) broken #2"); - - cal->clear(); - logln(UnicodeString("") + cal->getTime(status)); - if (cal->getTime(status) != epoch) - errln(UnicodeString("Fail: clear() broken Want ") + epoch); - - delete cal; - } - - /** - * @bug 4114578 - */ - void CalendarRegressionTest::test4114578() - { - UErrorCode status = U_ZERO_ERROR; - int32_t ONE_HOUR = 60*60*1000; - Calendar *cal = Calendar::createInstance(status); - cal->adoptTimeZone(TimeZone::createTimeZone("PST")); - UDate onset = makeDate(1998, Calendar::APRIL, 5, 1, 0) + ONE_HOUR; - UDate cease = makeDate(1998, Calendar::OCTOBER, 25, 0, 0) + 2*ONE_HOUR; - - UBool fail = FALSE; - - const int32_t ADD = 1; - const int32_t ROLL = 2; - - double DATA []= { - // Start Action Amt Expected_change - onset - ONE_HOUR, ADD, 1, ONE_HOUR, - onset, ADD, -1, -ONE_HOUR, - onset - ONE_HOUR, ROLL, 1, ONE_HOUR, - onset, ROLL, -1, -ONE_HOUR, - cease - ONE_HOUR, ADD, 1, ONE_HOUR, - cease, ADD, -1, -ONE_HOUR, - cease - ONE_HOUR, ROLL, 1, ONE_HOUR, - cease, ROLL, -1, -ONE_HOUR, - }; - - for (int32_t i=0; i<32; i+=4) { - UDate date = DATA[i]; - int32_t amt = (int32_t) DATA[i+2]; - double expectedChange = DATA[i+3]; - - log(UnicodeString("") + date); - cal->setTime(date,status); - - switch ((int32_t) DATA[i+1]) { - case ADD: - log(UnicodeString(" add (HOUR,") + (amt<0?"":"+")+amt + ")= "); - cal->add(Calendar::HOUR, amt,status); - break; - case ROLL: - log(UnicodeString(" roll(HOUR,") + (amt<0?"":"+")+amt + ")= "); - cal->roll(Calendar::HOUR, amt,status); - break; - } - - log(UnicodeString("") + cal->getTime(status)); - - double change = cal->getTime(status) - date; - if (change != expectedChange) { + int32_t DATA [] = { + 3, 52, 52, 52, 52, 52, 52, 52, + 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, + 4, 52, 52, 52, 52, 52, 52, 52, + 53, 53, 53, 53, 53, 53, 53, + 1, 1, 1, 1, 1, 1, 1, + }; + testCal->setFirstDayOfWeek(Calendar::SUNDAY); + for (int32_t j=0; j<44; j+=22) { + logln(UnicodeString("Minimal days in first week = ") + DATA[j] + + " Week starts on Sunday"); + testCal->setMinimalDaysInFirstWeek((uint8_t)DATA[j]); + testCal->set(1997, Calendar::DECEMBER, 21); + for (int32_t i=0; i<21; ++i) { + int32_t woy = testCal->get(Calendar::WEEK_OF_YEAR,status); + str.remove(); + log(UnicodeString("") + sdf.format(testCal->getTime(status), str) + + UnicodeString(" ") + woy); + if (woy != DATA[j + 1 + i]) { + log(" ERROR"); fail = TRUE; - logln(" FAIL"); } - else logln(" OK"); + logln(""); + + // Now compute the time from the fields, and make sure we + // get the same answer back. This is a round-trip test. + UDate save = testCal->getTime(status); + testCal->clear(); + testCal->set(Calendar::YEAR_WOY, DATA[j+1+i] < 25 ? 1998 : 1997); + testCal->set(Calendar::WEEK_OF_YEAR, DATA[j+1+i]); + testCal->set(Calendar::DAY_OF_WEEK, (i%7) + Calendar::SUNDAY); + if (testCal->getTime(status) != save) { + str.remove(); + logln(UnicodeString(" Parse failed: ") + + sdf.format(testCal->getTime(status), str)); + fail= TRUE; + } + + testCal->setTime(save,status); + testCal->add(Calendar::DAY_OF_MONTH, 1,status); } - - if (fail) errln("Fail: roll/add misbehaves around DST onset/cease"); - - delete cal; } - /** - * @bug 4118384 - * Make sure maximum for HOUR field is 11, not 12. - */ - void CalendarRegressionTest::test4118384() - { - UErrorCode status = U_ZERO_ERROR; - Calendar *cal = Calendar::createInstance(status); - if (cal->getMaximum(Calendar::HOUR) != 11 || - cal->getLeastMaximum(Calendar::HOUR) != 11 || - cal->getActualMaximum(Calendar::HOUR,status) != 11) - errln("Fail: maximum of HOUR field should be 11"); - - delete cal; - } + // Test field disambiguation with a few special hard-coded cases. + // This shouldn't fail if the above cases aren't failing. + int32_t DISAM_int [] = { + // y y_woy woy dow + 1997, 1998, 1, Calendar::SUNDAY, + (1998), (1998), (2), (Calendar::SATURDAY), + (1998), (1998), (53), (Calendar::THURSDAY), + (1999), (1998), (53), (Calendar::FRIDAY) + }; - /** - * @bug 4125881 - * Check isLeapYear for BC years. - */ - void CalendarRegressionTest::test4125881() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status); - DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status); - cal->clear(); - for (int32_t y=-20; y<=10; ++y) { - cal->set(Calendar::ERA, y < 1 ? GregorianCalendar::BC : GregorianCalendar::AD); - cal->set(Calendar::YEAR, y < 1 ? 1 - y : y); - UnicodeString temp; - logln(UnicodeString("") + y + UnicodeString(" = ") + fmt->format(cal->getTime(status), temp) + " " + - cal->isLeapYear(y)); - if (cal->isLeapYear(y) != ((y+40)%4 == 0)) - errln("Leap years broken"); + UDate DISAM_date [] = { + makeDate(1997, Calendar::DECEMBER, 28), + makeDate(1998, Calendar::JANUARY, 10), + makeDate(1998, Calendar::DECEMBER, 31), + makeDate(1999, Calendar::JANUARY, 1) + }; + + testCal->setMinimalDaysInFirstWeek(3); + testCal->setFirstDayOfWeek(Calendar::SUNDAY); + int32_t i = 0; + + /* Enable this code to display various WOY values + testCal->clear(); + for (i=25; i<38; ++i) { + testCal->set(1996, Calendar::DECEMBER, i); + UDate got = testCal->getTime(status); + str.remove(); + logln(UnicodeString("") + sdf.format(got, str)); + } + for (i=25; i<38; ++i) { + testCal->set(1997, Calendar::DECEMBER, i); + UDate got = testCal->getTime(status); + str.remove(); + logln(UnicodeString("") + sdf.format(got, str)); + } + for (i=25; i<38; ++i) { + testCal->set(1998, Calendar::DECEMBER, i); + UDate got = testCal->getTime(status); + str.remove(); + logln(UnicodeString("") + sdf.format(got, str)); + } + */ + + for (i=0; i < 16; i += 4) { + int32_t y = DISAM_int[i]; + int32_t ywoy = DISAM_int[i+1]; + int32_t woy = DISAM_int[i+2]; + int32_t dow = DISAM_int[i+3]; + UDate exp = DISAM_date[i/4]; + testCal->clear(); + testCal->set(Calendar::YEAR, y); + testCal->set(Calendar::WEEK_OF_YEAR, woy); + testCal->set(Calendar::DAY_OF_WEEK, dow); + UDate got = testCal->getTime(status); + str.remove(); + str2.remove(); + log(UnicodeString("Y") + y + "-W" + woy + + "-DOW" + dow + " expect:" + sdf.format(exp, str) + + " got:" + sdf.format(got, str2)); + if (got != exp) { + log(" FAIL"); + fail = TRUE; } - - delete cal; - delete fmt; - } + logln(""); - /** - * @bug 4125892 - * Prove that GregorianCalendar is proleptic (it used to cut off - * at 45 BC, and not have leap years before then). - */ - void CalendarRegressionTest::test4125892() { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status); - DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status); - cal->clear(); - cal->set(Calendar::ERA, GregorianCalendar::BC); - cal->set(Calendar::YEAR, 81); // 81 BC is a leap year (proleptically) - cal->set(Calendar::MONTH, Calendar::FEBRUARY); - cal->set(Calendar::DATE, 28); - cal->add(Calendar::DATE, 1,status); - if(U_FAILURE(status)) - errln("add(DATE,1) failed"); - if (cal->get(Calendar::DATE,status) != 29 || - !cal->isLeapYear(-80)) // -80 == 81 BC - errln("Calendar not proleptic"); - - delete cal; - delete fmt; - } - - /** - * @bug 4141665 - * GregorianCalendar::equals() ignores cutover date - */ - void CalendarRegressionTest::test4141665() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *cal = new GregorianCalendar(status); - GregorianCalendar *cal2 = (GregorianCalendar*)cal->clone(); - UDate cut = cal->getGregorianChange(); - UDate cut2 = cut + 100*24*60*60*1000.0; // 100 days later - if (*cal != *cal2) { - errln("Cloned GregorianCalendars not equal"); + testCal->clear(); + testCal->set(Calendar::YEAR_WOY, ywoy); + testCal->set(Calendar::WEEK_OF_YEAR, woy); + testCal->set(Calendar::DAY_OF_WEEK, dow); + got = testCal->getTime(status); + str.remove(); + str2.remove(); + log(UnicodeString("YWOY") + ywoy + "-W" + woy + + "-DOW" + dow + " expect:" + sdf.format(exp, str) + + " got:" + sdf.format(got, str2)); + if (got != exp) { + log(" FAIL"); + fail = TRUE; } - cal2->setGregorianChange(cut2,status); - if ( *cal == *cal2) { - errln("GregorianCalendar::equals() ignores cutover"); + logln(""); + } + + // Now try adding and rolling + UDate ADDROLL_date [] = { + makeDate(1998, Calendar::DECEMBER, 25), makeDate(1999, Calendar::JANUARY, 1), + makeDate(1997, Calendar::DECEMBER, 28), makeDate(1998, Calendar::JANUARY, 4), + makeDate(1998, Calendar::DECEMBER, 27), makeDate(1997, Calendar::DECEMBER, 28), + makeDate(1999, Calendar::JANUARY, 2), makeDate(1998, Calendar::JANUARY, 3), + }; + + int32_t ADDROLL_int []= { + (1), + (1), + (1), + (1) + }; + + + UBool ADDROLL_bool [] = { + TRUE,//ADD, + TRUE, + FALSE, + FALSE + }; + + testCal->setMinimalDaysInFirstWeek(3); + testCal->setFirstDayOfWeek(Calendar::SUNDAY); + for (i=0; i<8; i += 2) { + int32_t amount = ADDROLL_int[i/2]; + UDate before = ADDROLL_date[i]; + UDate after = ADDROLL_date[i+1]; + + testCal->setTime(before,status); + if (ADDROLL_bool[i/2]) + testCal->add(Calendar::WEEK_OF_YEAR, amount,status); + else + testCal->roll(Calendar::WEEK_OF_YEAR, amount,status); + UDate got = testCal->getTime(status); + str.remove(); + str2.remove(); + log((ADDROLL_bool[i/2]? UnicodeString("add(WOY,"):UnicodeString("roll(WOY,")) + + amount + ") " + sdf.format(before, str) + " => " + + sdf.format(got, str2)); + if (after != got) { + str.remove(); + logln(UnicodeString(" exp:") + sdf.format(after, str) + " FAIL"); + fail = TRUE; } - - delete cal; - delete cal2; - } - - /** - * @bug 4142933 - * Bug states that ArrayIndexOutOfBoundsException is thrown by GregorianCalendar::roll() - * when IllegalArgumentException should be. - */ - void CalendarRegressionTest::test4142933() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *calendar = new GregorianCalendar(status); - //try { - calendar->roll((Calendar::EDateFields)-1, TRUE, status); - if(U_SUCCESS(status)) - errln("Test failed, no exception thrown"); - //} - //catch (IllegalArgumentException e) { - // OK: Do nothing - // logln("Test passed"); - //} - //catch (Exception e) { - //errln("Test failed. Unexpected exception is thrown: " + e); - //e.printStackTrace(); - //} - - delete calendar; - } + else logln(" ok"); - /** - * @bug 4145158 - * GregorianCalendar handling of Dates Long.MIN_VALUE and Long.MAX_VALUE is - * confusing; unless the time zone has a raw offset of zero, one or the - * other of these will wrap. We've modified the test given in the bug - * report to therefore only check the behavior of a calendar with a zero raw - * offset zone. - */ - void CalendarRegressionTest::test4145158() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *calendar = new GregorianCalendar(status); - - calendar->adoptTimeZone(TimeZone::createTimeZone("GMT")); - - calendar->setTime(makeDate(INT32_MIN),status); - int32_t year1 = calendar->get(Calendar::YEAR,status); - int32_t era1 = calendar->get(Calendar::ERA,status); - - calendar->setTime(makeDate(INT32_MAX),status); - int32_t year2 = calendar->get(Calendar::YEAR,status); - int32_t era2 = calendar->get(Calendar::ERA,status); - - if (year1 == year2 && era1 == era2) { - errln("Fail: Long.MIN_VALUE or Long.MAX_VALUE wrapping around"); + testCal->setTime(after,status); + if (ADDROLL_bool[i/2]) + testCal->add(Calendar::WEEK_OF_YEAR, -amount,status); + else + testCal->roll(Calendar::WEEK_OF_YEAR, -amount,status); + got = testCal->getTime(status); + str.remove(); + str2.remove(); + log((ADDROLL_bool[i/2]?UnicodeString("add(WOY,"):UnicodeString("roll(WOY,")) + + (-amount) + ") " + sdf.format(after, str) + " => " + + sdf.format(got, str2)); + if (before != got) { + str.remove(); + logln(UnicodeString(" exp:") + sdf.format(before, str) + " FAIL"); + fail = TRUE; } - - delete calendar; + else logln(" ok"); } - /** - * @bug 4145983 - * Maximum value for YEAR field wrong. - */ - // {sfb} this is not directly applicable in C++, since all - // possible doubles are not representable by our Calendar. - // In Java, all longs are representable. - // We can determine limits programmatically - // Using DBL_MAX is a bit of a hack, since for large doubles - // Calendar gets squirrely and doesn't behave in any sort - // of linear fashion (ie years jump around, up/down, etc) for a - // small change in millis. - void CalendarRegressionTest::test4145983() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *calendar = new GregorianCalendar(status); - calendar->adoptTimeZone(TimeZone::createTimeZone("GMT")); - UDate DATES [] = { LATEST_SUPPORTED_MILLIS, EARLIEST_SUPPORTED_MILLIS }; + if (fail) + errln("Fail: Week of year misbehaving"); +} + +/** + * @bug 4106136 + */ +void CalendarRegressionTest::test4106136() +{ + UErrorCode status = U_ZERO_ERROR; + Locale saveLocale = Locale::getDefault(); + //try { + Locale locales [] = { Locale::getChinese(), Locale::getChina() }; for (int32_t i=0; i<2; ++i) { - calendar->setTime(DATES[i], status); - int32_t year = calendar->get(Calendar::YEAR,status); - int32_t maxYear = calendar->getMaximum(Calendar::YEAR); - if (year > maxYear) { - errln(UnicodeString("Failed for ")+DATES[i]+" ms: year=" + - year + ", maxYear=" + maxYear); + Locale::setDefault(locales[i], status); + failure(status, "Locale::setDefault"); + int32_t count1, count2, count3; + Calendar::getAvailableLocales(count1); + DateFormat::getAvailableLocales(count2); + NumberFormat::getAvailableLocales(count3); + int32_t n [] = { + count1, count2, count3 + }; + for (int32_t j=0; j<3; ++j) { + UnicodeString temp; + if (n[j] == 0) + errln(UnicodeString("Fail: No locales for ") + locales[i].getName()); } } + //} + //finally { + Locale::setDefault(saveLocale,status); + //} +} + +/** + * @bug 4108764 + */ +void CalendarRegressionTest::test4108764() +{ + UErrorCode status = U_ZERO_ERROR; + UDate d00 = makeDate(1997, Calendar::MARCH, 15, 12, 00, 00); + UDate d01 = makeDate(1997, Calendar::MARCH, 15, 12, 00, 56); + UDate d10 = makeDate(1997, Calendar::MARCH, 15, 12, 34, 00); + UDate d11 = makeDate(1997, Calendar::MARCH, 15, 12, 34, 56); + UDate epoch = makeDate(1970, Calendar::JANUARY, 1); + + Calendar *cal = Calendar::createInstance(status); + cal->setTime(d11,status); + + cal->clear( Calendar::MINUTE ); + logln(UnicodeString("") + cal->getTime(status)); + if (cal->getTime(status) != d01) + errln("Fail: clear(MINUTE) broken"); + + cal->set( Calendar::SECOND, 0 ); + logln(UnicodeString("") + cal->getTime(status)); + if (cal->getTime(status) != d00) + errln("Fail: set(SECOND, 0) broken"); + + cal->setTime(d11,status); + cal->set( Calendar::SECOND, 0 ); + logln(UnicodeString("") + cal->getTime(status)); + if (cal->getTime(status) != d10) + errln("Fail: set(SECOND, 0) broken #2"); + + cal->clear( Calendar::MINUTE ); + logln(UnicodeString("") + cal->getTime(status)); + if (cal->getTime(status) != d00) + errln("Fail: clear(MINUTE) broken #2"); + + cal->clear(); + logln(UnicodeString("") + cal->getTime(status)); + if (cal->getTime(status) != epoch) + errln(UnicodeString("Fail: clear() broken Want ") + epoch); + + delete cal; +} + +/** + * @bug 4114578 + */ +void CalendarRegressionTest::test4114578() +{ + UErrorCode status = U_ZERO_ERROR; + int32_t ONE_HOUR = 60*60*1000; + Calendar *cal = Calendar::createInstance(status); + cal->adoptTimeZone(TimeZone::createTimeZone("PST")); + UDate onset = makeDate(1998, Calendar::APRIL, 5, 1, 0) + ONE_HOUR; + UDate cease = makeDate(1998, Calendar::OCTOBER, 25, 0, 0) + 2*ONE_HOUR; + + UBool fail = FALSE; - delete calendar; + const int32_t ADD = 1; + const int32_t ROLL = 2; + + double DATA []= { + // Start Action Amt Expected_change + onset - ONE_HOUR, ADD, 1, ONE_HOUR, + onset, ADD, -1, -ONE_HOUR, + onset - ONE_HOUR, ROLL, 1, ONE_HOUR, + onset, ROLL, -1, -ONE_HOUR, + cease - ONE_HOUR, ADD, 1, ONE_HOUR, + cease, ADD, -1, -ONE_HOUR, + cease - ONE_HOUR, ROLL, 1, ONE_HOUR, + cease, ROLL, -1, -ONE_HOUR, + }; + + for (int32_t i=0; i<32; i+=4) { + UDate date = DATA[i]; + int32_t amt = (int32_t) DATA[i+2]; + double expectedChange = DATA[i+3]; + + log(UnicodeString("") + date); + cal->setTime(date,status); + + switch ((int32_t) DATA[i+1]) { + case ADD: + log(UnicodeString(" add (HOUR,") + (amt<0?"":"+")+amt + ")= "); + cal->add(Calendar::HOUR, amt,status); + break; + case ROLL: + log(UnicodeString(" roll(HOUR,") + (amt<0?"":"+")+amt + ")= "); + cal->roll(Calendar::HOUR, amt,status); + break; + } + + log(UnicodeString("") + cal->getTime(status)); + + double change = cal->getTime(status) - date; + if (change != expectedChange) { + fail = TRUE; + logln(" FAIL"); + } + else logln(" OK"); } - /** - * @bug 4147269 - * This is a bug in the validation code of GregorianCalendar:: As reported, - * the bug seems worse than it really is, due to a bug in the way the bug - * report test was written. In reality the bug is restricted to the DAY_OF_YEAR - * field. - liu 6/29/98 - */ - void CalendarRegressionTest::test4147269() - { - UErrorCode status = U_ZERO_ERROR; - GregorianCalendar *calendar = new GregorianCalendar(status); - calendar->setLenient(FALSE); - UDate date = makeDate(1996, Calendar::JANUARY, 3); // Arbitrary date - for (int32_t field = 0; field < Calendar::FIELD_COUNT; field++) { - calendar->setTime(date,status); - // Note: In the bug report, getActualMaximum() was called instead - // of getMaximum() -- this was an error. The validation code doesn't - // use getActualMaximum(), since that's too costly. - int32_t max = calendar->getMaximum((Calendar::EDateFields)field); - int32_t value = max+1; - calendar->set((Calendar::EDateFields)field, value); - //try { - calendar->getTime(status); // Force time computation - // We expect an exception to be thrown. If we fall through - // to the next line, then we have a bug. - if(U_SUCCESS(status)) - errln(UnicodeString("Test failed with field ") + FIELD_NAME[field] + - ", date before: " + date + - ", date after: " + calendar->getTime(status) + - ", value: " + value + " (max = " + max +")"); - //} catch (IllegalArgumentException e) {} - } - - delete calendar; + if (fail) errln("Fail: roll/add misbehaves around DST onset/cease"); + + delete cal; +} + +/** + * @bug 4118384 + * Make sure maximum for HOUR field is 11, not 12. + */ +void CalendarRegressionTest::test4118384() +{ + UErrorCode status = U_ZERO_ERROR; + Calendar *cal = Calendar::createInstance(status); + if (cal->getMaximum(Calendar::HOUR) != 11 || + cal->getLeastMaximum(Calendar::HOUR) != 11 || + cal->getActualMaximum(Calendar::HOUR,status) != 11) + errln("Fail: maximum of HOUR field should be 11"); + + delete cal; +} + +/** + * @bug 4125881 + * Check isLeapYear for BC years. + */ +void CalendarRegressionTest::test4125881() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status); + DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status); + cal->clear(); + for (int32_t y=-20; y<=10; ++y) { + cal->set(Calendar::ERA, y < 1 ? GregorianCalendar::BC : GregorianCalendar::AD); + cal->set(Calendar::YEAR, y < 1 ? 1 - y : y); + UnicodeString temp; + logln(UnicodeString("") + y + UnicodeString(" = ") + fmt->format(cal->getTime(status), temp) + " " + + cal->isLeapYear(y)); + if (cal->isLeapYear(y) != ((y+40)%4 == 0)) + errln("Leap years broken"); } + delete cal; + delete fmt; +} + +/** + * @bug 4125892 + * Prove that GregorianCalendar is proleptic (it used to cut off + * at 45 BC, and not have leap years before then). + */ +void CalendarRegressionTest::test4125892() { + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *cal = (GregorianCalendar*) Calendar::createInstance(status); + DateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"),status); + cal->clear(); + cal->set(Calendar::ERA, GregorianCalendar::BC); + cal->set(Calendar::YEAR, 81); // 81 BC is a leap year (proleptically) + cal->set(Calendar::MONTH, Calendar::FEBRUARY); + cal->set(Calendar::DATE, 28); + cal->add(Calendar::DATE, 1,status); + if(U_FAILURE(status)) + errln("add(DATE,1) failed"); + if (cal->get(Calendar::DATE,status) != 29 || + !cal->isLeapYear(-80)) // -80 == 81 BC + errln("Calendar not proleptic"); + + delete cal; + delete fmt; +} + +/** + * @bug 4141665 + * GregorianCalendar::equals() ignores cutover date + */ +void CalendarRegressionTest::test4141665() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *cal = new GregorianCalendar(status); + GregorianCalendar *cal2 = (GregorianCalendar*)cal->clone(); + UDate cut = cal->getGregorianChange(); + UDate cut2 = cut + 100*24*60*60*1000.0; // 100 days later + if (*cal != *cal2) { + errln("Cloned GregorianCalendars not equal"); + } + cal2->setGregorianChange(cut2,status); + if ( *cal == *cal2) { + errln("GregorianCalendar::equals() ignores cutover"); + } + + delete cal; + delete cal2; +} + +/** + * @bug 4142933 + * Bug states that ArrayIndexOutOfBoundsException is thrown by GregorianCalendar::roll() + * when IllegalArgumentException should be. + */ +void CalendarRegressionTest::test4142933() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *calendar = new GregorianCalendar(status); + //try { + calendar->roll((Calendar::EDateFields)-1, TRUE, status); + if(U_SUCCESS(status)) + errln("Test failed, no exception thrown"); + //} + //catch (IllegalArgumentException e) { + // OK: Do nothing + // logln("Test passed"); + //} + //catch (Exception e) { + //errln("Test failed. Unexpected exception is thrown: " + e); + //e.printStackTrace(); + //} + + delete calendar; +} + +/** + * @bug 4145158 + * GregorianCalendar handling of Dates Long.MIN_VALUE and Long.MAX_VALUE is + * confusing; unless the time zone has a raw offset of zero, one or the + * other of these will wrap. We've modified the test given in the bug + * report to therefore only check the behavior of a calendar with a zero raw + * offset zone. + */ +void CalendarRegressionTest::test4145158() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *calendar = new GregorianCalendar(status); + + calendar->adoptTimeZone(TimeZone::createTimeZone("GMT")); + + calendar->setTime(makeDate(INT32_MIN),status); + int32_t year1 = calendar->get(Calendar::YEAR,status); + int32_t era1 = calendar->get(Calendar::ERA,status); + + calendar->setTime(makeDate(INT32_MAX),status); + int32_t year2 = calendar->get(Calendar::YEAR,status); + int32_t era2 = calendar->get(Calendar::ERA,status); + + if (year1 == year2 && era1 == era2) { + errln("Fail: Long.MIN_VALUE or Long.MAX_VALUE wrapping around"); + } + + delete calendar; +} + +/** + * @bug 4145983 + * Maximum value for YEAR field wrong. + */ +// {sfb} this is not directly applicable in C++, since all +// possible doubles are not representable by our Calendar. +// In Java, all longs are representable. +// We can determine limits programmatically +// Using DBL_MAX is a bit of a hack, since for large doubles +// Calendar gets squirrely and doesn't behave in any sort +// of linear fashion (ie years jump around, up/down, etc) for a +// small change in millis. +void CalendarRegressionTest::test4145983() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *calendar = new GregorianCalendar(status); + calendar->adoptTimeZone(TimeZone::createTimeZone("GMT")); + UDate DATES [] = { LATEST_SUPPORTED_MILLIS, EARLIEST_SUPPORTED_MILLIS }; + for (int32_t i=0; i<2; ++i) { + calendar->setTime(DATES[i], status); + int32_t year = calendar->get(Calendar::YEAR,status); + int32_t maxYear = calendar->getMaximum(Calendar::YEAR); + if (year > maxYear) { + errln(UnicodeString("Failed for ")+DATES[i]+" ms: year=" + + year + ", maxYear=" + maxYear); + } + } + + delete calendar; +} + +/** + * @bug 4147269 + * This is a bug in the validation code of GregorianCalendar:: As reported, + * the bug seems worse than it really is, due to a bug in the way the bug + * report test was written. In reality the bug is restricted to the DAY_OF_YEAR + * field. - liu 6/29/98 + */ +void CalendarRegressionTest::test4147269() +{ + UErrorCode status = U_ZERO_ERROR; + GregorianCalendar *calendar = new GregorianCalendar(status); + calendar->setLenient(FALSE); + UDate date = makeDate(1996, Calendar::JANUARY, 3); // Arbitrary date + for (int32_t field = 0; field < Calendar::FIELD_COUNT; field++) { + calendar->setTime(date,status); + // Note: In the bug report, getActualMaximum() was called instead + // of getMaximum() -- this was an error. The validation code doesn't + // use getActualMaximum(), since that's too costly. + int32_t max = calendar->getMaximum((Calendar::EDateFields)field); + int32_t value = max+1; + calendar->set((Calendar::EDateFields)field, value); + //try { + calendar->getTime(status); // Force time computation + // We expect an exception to be thrown. If we fall through + // to the next line, then we have a bug. + if(U_SUCCESS(status)) + errln(UnicodeString("Test failed with field ") + FIELD_NAME[field] + + ", date before: " + date + + ", date after: " + calendar->getTime(status) + + ", value: " + value + " (max = " + max +")"); + //} catch (IllegalArgumentException e) {} + } + + delete calendar; +} + /** * @bug 4149677 * Reported bug is that a GregorianCalendar with a cutover of Date(Long.MAX_VALUE) @@ -1524,7 +1524,7 @@ CalendarRegressionTest::Test4166109() UErrorCode status = U_ZERO_ERROR; Calendar::EDateFields field = Calendar::WEEK_OF_MONTH; - GregorianCalendar *calendar = new GregorianCalendar(Locale::US, status); + GregorianCalendar *calendar = new GregorianCalendar(Locale::getUS(), status); if(U_FAILURE(status)) { errln("Couldn't create calendar"); return; @@ -1568,7 +1568,7 @@ CalendarRegressionTest::Test4167060() UErrorCode status = U_ZERO_ERROR; Calendar::EDateFields field = Calendar::YEAR; DateFormat *format = new SimpleDateFormat(UnicodeString("EEE MMM dd HH:mm:ss zzz yyyy G"), - Locale::US, status); + Locale::getUS(), status); if(U_FAILURE(status)) { errln("Couldn't create SimpleDateFormat"); return; @@ -1658,7 +1658,7 @@ void CalendarRegressionTest::Test4197699() { cal.setFirstDayOfWeek(Calendar::MONDAY); cal.setMinimalDaysInFirstWeek(4); SimpleDateFormat fmt("E dd MMM yyyy 'DOY='D 'WOY='w", - Locale::US, status); + Locale::getUS(), status); fmt.setCalendar(cal); if (U_FAILURE(status)) { errln("Couldn't initialize test"); @@ -1721,7 +1721,7 @@ void CalendarRegressionTest::TestJ81() { UnicodeString temp, temp2, temp3; int32_t i; GregorianCalendar cal(TimeZone::createTimeZone("GMT"), status); - SimpleDateFormat fmt("HH:mm 'w'w 'd'D E d MMM yyyy", Locale::US, 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"); return; @@ -1925,7 +1925,7 @@ void CalendarRegressionTest::TestJ438(void) { 1999, Calendar::JUNE, 4, 1964, Calendar::SEPTEMBER, 7, }; int32_t DATA_length = (int32_t)(sizeof(DATA)/sizeof(DATA[0])); - Calendar* pcal = Calendar::createInstance(Locale::US, ec); + Calendar* pcal = Calendar::createInstance(Locale::getUS(), ec); Calendar& cal = *pcal; int32_t i; SimpleDateFormat fmt(UnicodeString("MMM dd yyyy",""), ec); diff --git a/icu4c/source/test/intltest/caltest.cpp b/icu4c/source/test/intltest/caltest.cpp index 8cf6778bba..5ac27bf110 100644 --- a/icu4c/source/test/intltest/caltest.cpp +++ b/icu4c/source/test/intltest/caltest.cpp @@ -326,11 +326,11 @@ CalendarTest::TestGenericAPI() } } - cal = Calendar::createInstance(TimeZone::createDefault(), Locale::ENGLISH, status); + cal = Calendar::createInstance(TimeZone::createDefault(), Locale::getEnglish(), status); if (failure(status, "Calendar::createInstance")) return; delete cal; - cal = Calendar::createInstance(*zone, Locale::ENGLISH, status); + cal = Calendar::createInstance(*zone, Locale::getEnglish(), status); if (failure(status, "Calendar::createInstance")) return; delete cal; @@ -338,14 +338,14 @@ CalendarTest::TestGenericAPI() if (failure(status, "new GregorianCalendar")) return; delete gc; - gc = new GregorianCalendar(Locale::ENGLISH, status); + gc = new GregorianCalendar(Locale::getEnglish(), status); if (failure(status, "new GregorianCalendar")) return; delete gc; - gc = new GregorianCalendar(Locale::ENGLISH, status); + gc = new GregorianCalendar(Locale::getEnglish(), status); delete gc; - gc = new GregorianCalendar(*zone, Locale::ENGLISH, status); + gc = new GregorianCalendar(*zone, Locale::getEnglish(), status); if (failure(status, "new GregorianCalendar")) return; delete gc; @@ -362,7 +362,7 @@ CalendarTest::TestGenericAPI() if (gc->getTime(status) != date(98, 10, 14, 21, 43, 55) || U_FAILURE(status)) errln("FAIL: new GregorianCalendar(ymdhms) failed"); - GregorianCalendar gc2(Locale::ENGLISH, status); + GregorianCalendar gc2(Locale::getEnglish(), status); if (failure(status, "new GregorianCalendar")) return; gc2 = *gc; if (gc2 != *gc || !(gc2 == *gc)) errln("FAIL: GregorianCalendar assignment/operator==/operator!= failed"); diff --git a/icu4c/source/test/intltest/dcfmapts.cpp b/icu4c/source/test/intltest/dcfmapts.cpp index 08f9681cbe..ef6d66fae2 100644 --- a/icu4c/source/test/intltest/dcfmapts.cpp +++ b/icu4c/source/test/intltest/dcfmapts.cpp @@ -22,7 +22,7 @@ void IntlTestDecimalFormatAPI::runIndexedTest( int32_t index, UBool exec, const if (exec) { logln((UnicodeString)"DecimalFormat API test---"); logln((UnicodeString)""); UErrorCode status = U_ZERO_ERROR; - Locale::setDefault(Locale::ENGLISH, status); + Locale::setDefault(Locale::getEnglish(), status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Could not set default locale, test may not give correct results"); } @@ -65,7 +65,7 @@ void IntlTestDecimalFormatAPI::testAPI(/*char *par*/) } status = U_ZERO_ERROR; - DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::FRENCH, status); + DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::getFrench(), status); if(U_FAILURE(status)) { errln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (French)"); } diff --git a/icu4c/source/test/intltest/dtfmapts.cpp b/icu4c/source/test/intltest/dtfmapts.cpp index 9274ae06e0..be4ea2cbdf 100644 --- a/icu4c/source/test/intltest/dtfmapts.cpp +++ b/icu4c/source/test/intltest/dtfmapts.cpp @@ -27,7 +27,7 @@ void IntlTestDateFormatAPI::runIndexedTest( int32_t index, UBool exec, const cha if (exec) { logln("DateFormat API test---"); logln(""); UErrorCode status = U_ZERO_ERROR; - Locale::setDefault(Locale::ENGLISH, status); + Locale::setDefault(Locale::getEnglish(), status); if(U_FAILURE(status)) { errln("ERROR: Could not set default locale, test may not give correct results"); } @@ -94,8 +94,8 @@ void IntlTestDateFormatAPI::testAPI(/* char* par */) logln("Testing DateFormat constructors"); DateFormat *def = DateFormat::createInstance(); - DateFormat *fr = DateFormat::createTimeInstance(DateFormat::FULL, Locale::FRENCH); - DateFormat *it = DateFormat::createDateInstance(DateFormat::MEDIUM, Locale::ITALIAN); + DateFormat *fr = DateFormat::createTimeInstance(DateFormat::FULL, Locale::getFrench()); + DateFormat *it = DateFormat::createDateInstance(DateFormat::MEDIUM, Locale::getItalian()); DateFormat *de = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::LONG, Locale::getGerman()); // ======= Test equality diff --git a/icu4c/source/test/intltest/encoll.cpp b/icu4c/source/test/intltest/encoll.cpp index 67f4fbfce9..c21c1fb78c 100644 --- a/icu4c/source/test/intltest/encoll.cpp +++ b/icu4c/source/test/intltest/encoll.cpp @@ -15,7 +15,7 @@ CollationEnglishTest::CollationEnglishTest() : myCollation(0) { UErrorCode status = U_ZERO_ERROR; - myCollation = Collator::createInstance(Locale::ENGLISH, status); + myCollation = Collator::createInstance(Locale::getEnglish(), status); } CollationEnglishTest::~CollationEnglishTest() diff --git a/icu4c/source/test/intltest/itrbnfrt.cpp b/icu4c/source/test/intltest/itrbnfrt.cpp index d18bbcfcc0..180eeb28fe 100644 --- a/icu4c/source/test/intltest/itrbnfrt.cpp +++ b/icu4c/source/test/intltest/itrbnfrt.cpp @@ -57,7 +57,7 @@ RbnfRoundTripTest::TestEnglishSpelloutRT() { UErrorCode status = U_ZERO_ERROR; RuleBasedNumberFormat* formatter - = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::US, status); + = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getUS(), status); if (U_FAILURE(status)) { errln("failed to construct formatter"); @@ -75,7 +75,7 @@ RbnfRoundTripTest::TestDurationsRT() { UErrorCode status = U_ZERO_ERROR; RuleBasedNumberFormat* formatter - = new RuleBasedNumberFormat(URBNF_DURATION, Locale::US, status); + = new RuleBasedNumberFormat(URBNF_DURATION, Locale::getUS(), status); if (U_FAILURE(status)) { errln("failed to construct formatter"); @@ -147,7 +147,7 @@ RbnfRoundTripTest::TestItalianSpelloutRT() { UErrorCode status = U_ZERO_ERROR; RuleBasedNumberFormat* formatter - = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::ITALIAN, status); + = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getItalian(), status); if (U_FAILURE(status)) { errln("failed to construct formatter"); @@ -219,7 +219,7 @@ RbnfRoundTripTest::TestJapaneseSpelloutRT() { UErrorCode status = U_ZERO_ERROR; RuleBasedNumberFormat* formatter - = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::JAPAN, status); + = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getJapan(), status); if (U_FAILURE(status)) { errln("failed to construct formatter"); diff --git a/icu4c/source/test/intltest/ittxtbd.cpp b/icu4c/source/test/intltest/ittxtbd.cpp index caf590b897..ca9f82bb8a 100644 --- a/icu4c/source/test/intltest/ittxtbd.cpp +++ b/icu4c/source/test/intltest/ittxtbd.cpp @@ -672,7 +672,7 @@ void IntlTestTextBoundary::TestLineIteration() void IntlTestTextBoundary::TestLineInvariants() { UErrorCode status = U_ZERO_ERROR; - BreakIterator *e = BreakIterator::createLineInstance(Locale::US, status); + BreakIterator *e = BreakIterator::createLineInstance(Locale::getUS(), status); if (U_FAILURE(status)) { errln("Failed to create the BreakIterator for default locale in TestLineInvariants.\n"); @@ -1035,7 +1035,7 @@ void IntlTestTextBoundary::TestJapaneseLineBreak() // ":;\\u309b\\u309c\\u3005\\u309d\\u309e\\u30fd\\u30fe\\u2019\\u201d\\u00b0\\u2032\\u2033\\u2034" ":;\\u309b\\u309c\\u3005\\u309d\\u309e\\u30fd\\u00b0\\u2032\\u2033\\u2034" "\\u2030\\u2031\\u2103\\u2109\\u00a2\\u0300\\u0301\\u0302"); - BreakIterator *iter = BreakIterator::createLineInstance(Locale::JAPAN, status); + BreakIterator *iter = BreakIterator::createLineInstance(Locale::getJapan(), status); int32_t i; if (U_FAILURE(status)) diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 1437329b44..4179f5fcdd 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -1051,7 +1051,7 @@ LocaleTest::TestSimpleDisplayNames() for (int32_t i = 0; i < 6; i++) { UnicodeString test; Locale l(languageCodes[i], "", ""); - l.getDisplayLanguage(Locale::US, test); + l.getDisplayLanguage(Locale::getUS(), test); if (test != languageNames[i]) errln("Got wrong display name for " + UnicodeString(languageCodes[i]) + ": Expected \"" + languageNames[i] + "\", got \"" + test + "\"."); diff --git a/icu4c/source/test/intltest/nmfmapts.cpp b/icu4c/source/test/intltest/nmfmapts.cpp index 974ac49585..9759c0f1f1 100644 --- a/icu4c/source/test/intltest/nmfmapts.cpp +++ b/icu4c/source/test/intltest/nmfmapts.cpp @@ -23,7 +23,7 @@ void IntlTestNumberFormatAPI::runIndexedTest( int32_t index, UBool exec, const c if (exec) { logln("NumberFormat API test---"); logln(""); UErrorCode status = U_ZERO_ERROR; - Locale::setDefault(Locale::ENGLISH, status); + Locale::setDefault(Locale::getEnglish(), status); if(U_FAILURE(status)) { errln("ERROR: Could not set default locale, test may not give correct results"); } @@ -53,7 +53,7 @@ void IntlTestNumberFormatAPI::testAPI(/* char* par */) } status = U_ZERO_ERROR; - NumberFormat *fr = NumberFormat::createInstance(Locale::FRENCH, status); + NumberFormat *fr = NumberFormat::createInstance(Locale::getFrench(), status); if(U_FAILURE(status)) { errln("ERROR: Could not create NumberFormat (French)"); } @@ -64,7 +64,7 @@ void IntlTestNumberFormatAPI::testAPI(/* char* par */) } status = U_ZERO_ERROR; - NumberFormat *cur_fr = NumberFormat::createCurrencyInstance(Locale::FRENCH, status); + NumberFormat *cur_fr = NumberFormat::createCurrencyInstance(Locale::getFrench(), status); if(U_FAILURE(status)) { errln("ERROR: Could not create NumberFormat (currency, French)"); } @@ -75,7 +75,7 @@ void IntlTestNumberFormatAPI::testAPI(/* char* par */) } status = U_ZERO_ERROR; - NumberFormat *per_fr = NumberFormat::createPercentInstance(Locale::FRENCH, status); + NumberFormat *per_fr = NumberFormat::createPercentInstance(Locale::getFrench(), status); if(U_FAILURE(status)) { errln("ERROR: Could not create NumberFormat (percent, French)"); } diff --git a/icu4c/source/test/intltest/numrgts.cpp b/icu4c/source/test/intltest/numrgts.cpp index 5485e05fe2..c9b66d3d1f 100644 --- a/icu4c/source/test/intltest/numrgts.cpp +++ b/icu4c/source/test/intltest/numrgts.cpp @@ -274,7 +274,7 @@ NumberFormatRegressionTest::assignFloatValue(float returnfloat) { logln(UnicodeString(" VALUE ") + returnfloat); UErrorCode status = U_ZERO_ERROR; - NumberFormat *nfcommon = NumberFormat::createCurrencyInstance(Locale::US, status); + NumberFormat *nfcommon = NumberFormat::createCurrencyInstance(Locale::getUS(), status); failure(status, "NumberFormat::createCurrencyInstance"); nfcommon->setGroupingUsed(FALSE); @@ -1178,7 +1178,7 @@ void NumberFormatRegressionTest::Test4062486(void) void NumberFormatRegressionTest::Test4108738(void) { UErrorCode status = U_ZERO_ERROR; - DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::US, status); + DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::getUS(), status); failure(status, "new DecimalFormatSymbols"); DecimalFormat *df = new DecimalFormat("#,##0.###", syms, status); failure(status, "new DecimalFormat"); @@ -1584,7 +1584,7 @@ void NumberFormatRegressionTest::Test4134300(void) { void NumberFormatRegressionTest::Test4140009(void) { UErrorCode status = U_ZERO_ERROR; - DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::ENGLISH, status); + DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::getEnglish(), status); failure(status, "new DecimalFormatSymbols"); DecimalFormat *f = new DecimalFormat(UnicodeString(""), syms, status); failure(status, "new DecimalFormat"); @@ -1728,7 +1728,7 @@ void NumberFormatRegressionTest::Test4147706(void) UErrorCode status = U_ZERO_ERROR; DecimalFormat *df = new DecimalFormat("#,##0.0##", status); failure(status, "new DecimalFormat"); - DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::ENGLISH, status); + DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale::getEnglish(), status); failure(status, "new DecimalFormatSymbols"); UnicodeString f1; UnicodeString f2, temp; @@ -1855,7 +1855,7 @@ static double _u_abs(double a) { return a<0?-a:a; } */ void NumberFormatRegressionTest::Test4167494(void) { UErrorCode status = U_ZERO_ERROR; - NumberFormat *fmt = NumberFormat::createInstance(Locale::US, status); + NumberFormat *fmt = NumberFormat::createInstance(Locale::getUS(), status); failure(status, "NumberFormat::createInstance"); double a = DBL_MAX * 0.99; // DBL_MAX itself overflows to +Inf @@ -1888,7 +1888,7 @@ void NumberFormatRegressionTest::Test4167494(void) { */ void NumberFormatRegressionTest::Test4170798(void) { UErrorCode status = U_ZERO_ERROR; - NumberFormat *nf = NumberFormat::createInstance(Locale::US, status); + NumberFormat *nf = NumberFormat::createInstance(Locale::getUS(), status); failure(status, "NumberFormat::createInstance"); if(nf->getDynamicClassID() != DecimalFormat::getStaticClassID()) { errln("DecimalFormat needed to continue"); @@ -1956,7 +1956,7 @@ void NumberFormatRegressionTest::Test4179818(void) { 0.9999, }; UErrorCode status = U_ZERO_ERROR; - DecimalFormatSymbols sym(Locale::US, status); + DecimalFormatSymbols sym(Locale::getUS(), status); failure(status, "Construct DecimalFormatSymbols"); DecimalFormat fmt("#", sym, status); failure(status, "Construct DecimalFormat"); @@ -1987,7 +1987,7 @@ void NumberFormatRegressionTest::Test4179818(void) { */ void NumberFormatRegressionTest::Test4212072(void) { UErrorCode status = U_ZERO_ERROR; - DecimalFormatSymbols sym(Locale::US, status); + DecimalFormatSymbols sym(Locale::getUS(), status); /* failure(status, "DecimalFormatSymbols ct"); DecimalFormat fmt(UnicodeString("#"), sym, status); @@ -2152,7 +2152,7 @@ void NumberFormatRegressionTest::Test4212072(void) { */ void NumberFormatRegressionTest::Test4216742(void) { UErrorCode status = U_ZERO_ERROR; - DecimalFormat *fmt = (DecimalFormat*) NumberFormat::createInstance(Locale::US, status); + DecimalFormat *fmt = (DecimalFormat*) NumberFormat::createInstance(Locale::getUS(), status); failure(status, "createInstance"); int32_t DATA[] = { INT32_MIN, INT32_MAX, -100000000, 100000000 }; int DATA_length = (int)(sizeof(DATA) / sizeof(DATA[0])); @@ -2191,7 +2191,7 @@ void NumberFormatRegressionTest::Test4217661(void) { const char* S[] = { "0", "1", "0.01", "1.01" }; int D_length = (int)(sizeof(D) / sizeof(D[0])); UErrorCode status = U_ZERO_ERROR; - NumberFormat *fmt = NumberFormat::createInstance(Locale::US, status); + NumberFormat *fmt = NumberFormat::createInstance(Locale::getUS(), status); failure(status, "createInstance"); fmt->setMaximumFractionDigits(2); for (int i=0; isetMinimumFractionDigits(1); nf->setMaximumFractionDigits(1); @@ -2231,7 +2231,7 @@ void NumberFormatRegressionTest::Test4161100(void) { */ void NumberFormatRegressionTest::Test4243011(void) { UErrorCode status = U_ZERO_ERROR; - DecimalFormatSymbols sym(Locale::US, status); + DecimalFormatSymbols sym(Locale::getUS(), status); failure(status, "DecimalFormatSymbols ct"); DecimalFormat fmt(UnicodeString("0."), sym, status); failure(status, "DecimalFormat ct"); @@ -2261,7 +2261,7 @@ void NumberFormatRegressionTest::Test4243011(void) { */ void NumberFormatRegressionTest::Test4243108(void) { UErrorCode status = U_ZERO_ERROR; - DecimalFormatSymbols sym(Locale::US, status); + DecimalFormatSymbols sym(Locale::getUS(), status); failure(status, "DecimalFormatSymbols ct"); DecimalFormat fmt(UnicodeString("#.#"), sym, status); failure(status, "DecimalFormat ct"); diff --git a/icu4c/source/test/intltest/rbbiapts.cpp b/icu4c/source/test/intltest/rbbiapts.cpp index ed868a589d..b9920ed516 100644 --- a/icu4c/source/test/intltest/rbbiapts.cpp +++ b/icu4c/source/test/intltest/rbbiapts.cpp @@ -67,7 +67,7 @@ void RBBIAPITest::TestCloneEquals() // source and dest iterator produce the same next() after assignment. // deleting one doesn't disable the other. logln("Testing assignment"); - RuleBasedBreakIterator *bix = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::ENGLISH, status); + RuleBasedBreakIterator *bix = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status); if(U_FAILURE(status)){ errln((UnicodeString)"FAIL : in construction"); return; diff --git a/icu4c/source/test/intltest/regcoll.cpp b/icu4c/source/test/intltest/regcoll.cpp index 313a73759c..db08945de3 100644 --- a/icu4c/source/test/intltest/regcoll.cpp +++ b/icu4c/source/test/intltest/regcoll.cpp @@ -17,7 +17,7 @@ CollationRegressionTest::CollationRegressionTest() { UErrorCode status = U_ZERO_ERROR; - en_us = (RuleBasedCollator *)Collator::createInstance(Locale::US, status); + en_us = (RuleBasedCollator *)Collator::createInstance(Locale::getUS(), status); } CollationRegressionTest::~CollationRegressionTest() @@ -790,7 +790,7 @@ void CollationRegressionTest::Test4124632(/* char* par */) UErrorCode status = U_ZERO_ERROR; Collator *coll = NULL; - coll = Collator::createInstance(Locale::JAPAN, status); + coll = Collator::createInstance(Locale::getJapan(), status); if (coll == NULL || U_FAILURE(status)) { diff --git a/icu4c/source/test/intltest/sdtfmtts.cpp b/icu4c/source/test/intltest/sdtfmtts.cpp index 12636a2c5d..d030e96dc9 100644 --- a/icu4c/source/test/intltest/sdtfmtts.cpp +++ b/icu4c/source/test/intltest/sdtfmtts.cpp @@ -23,7 +23,7 @@ void IntlTestSimpleDateFormatAPI::runIndexedTest( int32_t index, UBool exec, con if (exec) { logln("SimpleDateFormat API test---"); logln(""); UErrorCode status = U_ZERO_ERROR; - Locale::setDefault(Locale::ENGLISH, status); + Locale::setDefault(Locale::getEnglish(), status); if(U_FAILURE(status)) { errln("ERROR: Could not set default locale, test may not give correct results"); } @@ -59,13 +59,13 @@ void IntlTestSimpleDateFormatAPI::testAPI(/*char *par*/) } status = U_ZERO_ERROR; - SimpleDateFormat pat_fr(pattern, Locale::FRENCH, status); + SimpleDateFormat pat_fr(pattern, Locale::getFrench(), status); if(U_FAILURE(status)) { errln("ERROR: Could not create SimpleDateFormat (pattern French)"); } status = U_ZERO_ERROR; - DateFormatSymbols *symbols = new DateFormatSymbols(Locale::FRENCH, status); + DateFormatSymbols *symbols = new DateFormatSymbols(Locale::getFrench(), status); if(U_FAILURE(status)) { errln("ERROR: Could not create DateFormatSymbols (French)"); } diff --git a/icu4c/source/test/intltest/srchtest.cpp b/icu4c/source/test/intltest/srchtest.cpp index eb009e4270..688898a5c2 100644 --- a/icu4c/source/test/intltest/srchtest.cpp +++ b/icu4c/source/test/intltest/srchtest.cpp @@ -51,9 +51,9 @@ StringSearchTest::StringSearchTest() m_es_ = new RuleBasedCollator(rules, status); m_en_wordbreaker_ = BreakIterator::createWordInstance( - Locale::ENGLISH, status); + Locale::getEnglish(), status); m_en_characterbreaker_ = BreakIterator::createCharacterInstance( - Locale::ENGLISH, status); + Locale::getEnglish(), status); } StringSearchTest::~StringSearchTest() @@ -503,14 +503,14 @@ void StringSearchTest::TestOpenClose() delete result; status = U_ZERO_ERROR; - result = new StringSearch(pattern, text, Locale::ENGLISH, NULL, status); + result = new StringSearch(pattern, text, Locale::getEnglish(), NULL, status); if (U_FAILURE(status) || result == NULL) { errln("Error: NULL break iterator is valid for opening search"); } delete result; status = U_ZERO_ERROR; - result = new StringSearch(pattern, chariter, Locale::ENGLISH, NULL, status); + result = new StringSearch(pattern, chariter, Locale::getEnglish(), NULL, status); if (U_FAILURE(status)) { errln("Error: NULL break iterator is valid for opening search"); } diff --git a/icu4c/source/test/intltest/tmsgfmt.cpp b/icu4c/source/test/intltest/tmsgfmt.cpp index 4888fff9ee..84476696a4 100644 --- a/icu4c/source/test/intltest/tmsgfmt.cpp +++ b/icu4c/source/test/intltest/tmsgfmt.cpp @@ -629,14 +629,14 @@ void TestMessageFormat::testSetLocale() msg.setLocale(Locale::getEnglish()); UBool getLocale_ok = TRUE; - if (msg.getLocale() != Locale::ENGLISH) { + if (msg.getLocale() != Locale::getEnglish()) { errln("*** MSG getLocal err."); getLocale_ok = FALSE; } msg.setLocale(Locale::getGerman()); - if (msg.getLocale() != Locale::GERMAN) { + if (msg.getLocale() != Locale::getGerman()) { errln("*** MSG getLocal err."); getLocale_ok = FALSE; } diff --git a/icu4c/source/test/intltest/transapi.cpp b/icu4c/source/test/intltest/transapi.cpp index 2461023624..adc71e6ed1 100644 --- a/icu4c/source/test/intltest/transapi.cpp +++ b/icu4c/source/test/intltest/transapi.cpp @@ -238,7 +238,7 @@ void TransliteratorAPITest::TestGetDisplayName() { message="Display name for ID:" + t->getID(); // doTest(message, name, dispNames[i+1]); //!!! This will obviously fail for any locale other than english and its children!!! name=""; - t->getDisplayName(t->getID(), Locale::US, name); + t->getDisplayName(t->getID(), Locale::getUS(), name); message.remove(); message.append("Display name for on english locale ID:"); message.append(t->getID()); diff --git a/icu4c/source/test/intltest/transtst.cpp b/icu4c/source/test/intltest/transtst.cpp index 301bb4cf1d..02b7eb0e1e 100644 --- a/icu4c/source/test/intltest/transtst.cpp +++ b/icu4c/source/test/intltest/transtst.cpp @@ -3178,10 +3178,10 @@ void TransliteratorTest::TestSpecialCases(void) { Normalizer::normalize(source, UNORM_NFKC, 0, target, ec); } else if (0==id.caseCompare("Lower", U_FOLD_CASE_DEFAULT)) { target = source; - target.toLower(Locale::US); + target.toLower(Locale::getUS()); } else if (0==id.caseCompare("Upper", U_FOLD_CASE_DEFAULT)) { target = source; - target.toUpper(Locale::US); + target.toUpper(Locale::getUS()); } if (U_FAILURE(ec)) { errln((UnicodeString)"FAIL: Internal error normalizing " + source); diff --git a/icu4c/source/test/intltest/tsdtfmsy.cpp b/icu4c/source/test/intltest/tsdtfmsy.cpp index a35ff47027..4cbec469e8 100644 --- a/icu4c/source/test/intltest/tsdtfmsy.cpp +++ b/icu4c/source/test/intltest/tsdtfmsy.cpp @@ -63,13 +63,13 @@ void IntlTestDateFormatSymbols::testSymbols(/* char *par */) { UErrorCode status = U_ZERO_ERROR; - DateFormatSymbols fr(Locale::FRENCH, status); + DateFormatSymbols fr(Locale::getFrench(), status); if(U_FAILURE(status)) { errln("ERROR: Couldn't create French DateFormatSymbols"); } status = U_ZERO_ERROR; - DateFormatSymbols en(Locale::ENGLISH, status); + DateFormatSymbols en(Locale::getEnglish(), status); if(U_FAILURE(status)) { errln("ERROR: Couldn't create English DateFormatSymbols"); } diff --git a/icu4c/source/test/intltest/tsmthred.cpp b/icu4c/source/test/intltest/tsmthred.cpp index 4d130032e0..73bfe7dd2e 100644 --- a/icu4c/source/test/intltest/tsmthred.cpp +++ b/icu4c/source/test/intltest/tsmthred.cpp @@ -673,7 +673,7 @@ public: int32_t iteration; UErrorCode status = U_ZERO_ERROR; - NumberFormat *formatter = NumberFormat::createInstance(Locale::ENGLISH,status); + NumberFormat *formatter = NumberFormat::createInstance(Locale::getEnglish(),status); if(U_FAILURE(status)) { @@ -681,7 +681,7 @@ public: return; } - NumberFormat *percentFormatter = NumberFormat::createPercentInstance(Locale::FRENCH,status); + NumberFormat *percentFormatter = NumberFormat::createPercentInstance(Locale::getFrench(),status); if(U_FAILURE(status)) { diff --git a/icu4c/source/test/intltest/tzregts.cpp b/icu4c/source/test/intltest/tzregts.cpp index dcdc02286b..6297421d91 100644 --- a/icu4c/source/test/intltest/tzregts.cpp +++ b/icu4c/source/test/intltest/tzregts.cpp @@ -785,7 +785,7 @@ void TimeZoneRegressionTest::Test4162593() { UErrorCode status = U_ZERO_ERROR; - SimpleDateFormat *fmt = new SimpleDateFormat("z", Locale::US, status); + SimpleDateFormat *fmt = new SimpleDateFormat("z", Locale::getUS(), status); const int32_t ONE_HOUR = 60*60*1000; SimpleTimeZone *asuncion = new SimpleTimeZone(-4*ONE_HOUR, "America/Asuncion" /*PY%sT*/, diff --git a/icu4c/source/test/intltest/tztest.cpp b/icu4c/source/test/intltest/tztest.cpp index 995a366489..f09c1f349b 100644 --- a/icu4c/source/test/intltest/tztest.cpp +++ b/icu4c/source/test/intltest/tztest.cpp @@ -733,7 +733,7 @@ TimeZoneTest::TestDisplayName() int32_t i; TimeZone *zone = TimeZone::createTimeZone("PST"); UnicodeString name; - zone->getDisplayName(Locale::ENGLISH, name); + zone->getDisplayName(Locale::getEnglish(), name); logln("PST->" + name); if (name.compare("Pacific Standard Time") != 0) errln("Fail: Expected \"Pacific Standard Time\" but got " + name); @@ -762,7 +762,7 @@ TimeZoneTest::TestDisplayName() name.remove(); name = zone->getDisplayName(kData[i].useDst, kData[i].style, - Locale::ENGLISH, name); + Locale::getEnglish(), name); if (name.compare(kData[i].expect) != 0) errln("Fail: Expected " + UnicodeString(kData[i].expect) + "; got " + name); logln("PST [with options]->" + name); @@ -782,14 +782,14 @@ TimeZoneTest::TestDisplayName() errln("Some sort of error..." + UnicodeString(u_errorName(status))); // REVISIT } name.remove(); - name = zone2->getDisplayName(Locale::ENGLISH,name); + name = zone2->getDisplayName(Locale::getEnglish(),name); logln("Modified PST->" + name); if (name.compare("Pacific Standard Time") != 0) errln("Fail: Expected \"Pacific Standard Time\""); // Make sure we get the default display format for Locales // with no display name data. - Locale zh_CN = Locale::SIMPLIFIED_CHINESE; + Locale zh_CN = Locale::getSimplifiedChinese(); name.remove(); name = zone->getDisplayName(zh_CN,name); //***************************************************************** @@ -803,7 +803,7 @@ TimeZoneTest::TestDisplayName() // Now be smart -- check to see if zh resource is even present. // If not, we expect the en fallback behavior. ResourceBundle enRB(u_getDataDirectory(), - Locale::ENGLISH, status); + Locale::getEnglish(), status); if(U_FAILURE(status)) errln("Couldn't get ResourceBundle for en"); @@ -835,7 +835,7 @@ TimeZoneTest::TestDisplayName() delete zone2; zone2 = new SimpleTimeZone(90*60*1000, "xyzzy"); name.remove(); - name = zone2->getDisplayName(Locale::ENGLISH,name); + name = zone2->getDisplayName(Locale::getEnglish(),name); logln("GMT+90min->" + name); if (name.compare("GMT+01:30") && name.compare("GMT+1:30") &&