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
This commit is contained in:
Yoshito Umaoka 2014-01-27 21:56:47 +00:00
parent 86ae277276
commit 2c56459ce6
2 changed files with 51 additions and 1 deletions

View file

@ -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<Calendar> cal1(Calendar::createInstance(LOCALE_PAIRS[i], status));
LocalPointer<Calendar> 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

View file

@ -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 */