From 2c56459ce6e366262054b7c472b32146c8fbf63c Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Mon, 27 Jan 2014 21:56:47 +0000 Subject: [PATCH] ICU-10577 Added a test case in ICU4C to check if the calendar factory method uses locale's region to initialize week data. ICU4C library code is working fine, so no changes in the library code. X-SVN-Rev: 35002 --- icu4c/source/test/intltest/caltest.cpp | 49 ++++++++++++++++++++++++++ icu4c/source/test/intltest/caltest.h | 3 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/icu4c/source/test/intltest/caltest.cpp b/icu4c/source/test/intltest/caltest.cpp index 5c30426e9bb..c6849acf7e3 100644 --- a/icu4c/source/test/intltest/caltest.cpp +++ b/icu4c/source/test/intltest/caltest.cpp @@ -305,6 +305,13 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name, TestHebrewMonthValidation(); } break; + case 34: + name = "TestWeekData"; + if(exec) { + logln("TestWeekData---"); logln(""); + TestWeekData(); + } + break; default: name = ""; break; } } @@ -2920,6 +2927,48 @@ void CalendarTest::TestHebrewMonthValidation() { } } +void CalendarTest::TestWeekData() { + // Each line contains two locales using the same set of week rule data. + const char* LOCALE_PAIRS[] = { + "en", "en_US", + "de", "de_DE", + "de_DE", "en_DE", + "en_GB", "und_GB", + "ar_EG", "en_EG", + "ar_SA", "fr_SA", + 0 + }; + + UErrorCode status; + + for (int32_t i = 0; LOCALE_PAIRS[i] != 0; i += 2) { + status = U_ZERO_ERROR; + LocalPointer cal1(Calendar::createInstance(LOCALE_PAIRS[i], status)); + LocalPointer cal2(Calendar::createInstance(LOCALE_PAIRS[i + 1], status)); + TEST_CHECK_STATUS; + + // First day of week + UCalendarDaysOfWeek dow1 = cal1->getFirstDayOfWeek(status); + UCalendarDaysOfWeek dow2 = cal2->getFirstDayOfWeek(status); + TEST_CHECK_STATUS; + TEST_ASSERT(dow1 == dow2); + + // Minimum days in first week + uint8_t minDays1 = cal1->getMinimalDaysInFirstWeek(); + uint8_t minDays2 = cal2->getMinimalDaysInFirstWeek(); + TEST_ASSERT(minDays1 == minDays2); + + // Weekdays and Weekends + for (int32_t d = UCAL_SUNDAY; d <= UCAL_SATURDAY; d++) { + status = U_ZERO_ERROR; + UCalendarWeekdayType wdt1 = cal1->getDayOfWeekType((UCalendarDaysOfWeek)d, status); + UCalendarWeekdayType wdt2 = cal2->getDayOfWeekType((UCalendarDaysOfWeek)d, status); + TEST_CHECK_STATUS; + TEST_ASSERT(wdt1 == wdt2); + } + } +} + #endif /* #if !UCONFIG_NO_FORMATTING */ //eof diff --git a/icu4c/source/test/intltest/caltest.h b/icu4c/source/test/intltest/caltest.h index f00f5f44f40..1c428ef3604 100644 --- a/icu4c/source/test/intltest/caltest.h +++ b/icu4c/source/test/intltest/caltest.h @@ -1,5 +1,5 @@ /*********************************************************************** - * Copyright (c) 1997-2013, International Business Machines Corporation + * Copyright (c) 1997-2014, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -248,6 +248,7 @@ public: // package void setAndTestCalendar(Calendar* cal, int32_t initMonth, int32_t initDay, int32_t initYear, UErrorCode& status); void setAndTestWholeYear(Calendar* cal, int32_t startYear, UErrorCode& status); + void TestWeekData(void); }; #endif /* #if !UCONFIG_NO_FORMATTING */ -- 2.40.0