ICU-9191 copy locale in cloned calendars

X-SVN-Rev: 31603
This commit is contained in:
Steven R. Loomis 2012-03-08 19:29:24 +00:00
parent e150cb8c78
commit 849b2da11d
3 changed files with 32 additions and 0 deletions

View file

@ -783,6 +783,8 @@ Calendar::operator=(const Calendar &right)
fWeekendCease = right.fWeekendCease;
fWeekendCeaseMillis = right.fWeekendCeaseMillis;
fNextStamp = right.fNextStamp;
uprv_strcpy(validLocale, right.validLocale);
uprv_strcpy(actualLocale, right.actualLocale);
}
return *this;

View file

@ -18,9 +18,15 @@
#include "unicode/udat.h"
#include "unicode/ustring.h"
#include "cstring.h"
#include "unicode/localpointer.h"
#define mkcstr(U) u_austrcpy(calloc(8, u_strlen(U) + 1), U)
#define TEST_CHECK_STATUS {if (U_FAILURE(status)) {errln("%s:%d: Test failure. status=%s", \
__FILE__, __LINE__, u_errorName(status)); return;}}
#define TEST_ASSERT(expr) {if ((expr)==FALSE) {errln("%s:%d: Test failure \n", __FILE__, __LINE__);};}
// *****************************************************************************
// class CalendarTest
// *****************************************************************************
@ -265,6 +271,13 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
TestSkippedWallTime();
}
break;
case 30:
name = "TestCloneLocale";
if(exec) {
logln("TestCloneLocale---"); logln("");
TestCloneLocale();
}
break;
default: name = ""; break;
}
}
@ -2649,6 +2662,21 @@ void CalendarTest::TestSkippedWallTime(void) {
}
}
void CalendarTest::TestCloneLocale(void) {
UErrorCode status = U_ZERO_ERROR;
LocalPointer<Calendar> cal(Calendar::createInstance(TimeZone::getGMT()->clone(),
Locale::createFromName("en"), status));
TEST_CHECK_STATUS;
Locale l0 = cal->getLocale(ULOC_VALID_LOCALE, status);
TEST_CHECK_STATUS;
LocalPointer<Calendar> cal2(cal->clone());
Locale l = cal2->getLocale(ULOC_VALID_LOCALE, status);
if(l0!=l) {
errln("Error: cloned locale %s != original locale %s, status %s\n", l0.getName(), l.getName(), u_errorName(status));
}
TEST_CHECK_STATUS;
}
#endif /* #if !UCONFIG_NO_FORMATTING */
//eof

View file

@ -235,6 +235,8 @@ public: // package
void TestAmbiguousWallTimeAPIs(void);
void TestRepeatedWallTime(void);
void TestSkippedWallTime(void);
void TestCloneLocale(void);
};
#endif /* #if !UCONFIG_NO_FORMATTING */