From 3261e6d7039d64d9ccb8a606ba8d6a385482e05e Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Tue, 7 Dec 2010 23:46:13 +0000 Subject: [PATCH] ICU-7089 Add test for Calendar class time stamp recalculation in ICU4C X-SVN-Rev: 29164 --- icu4c/source/i18n/calendar.cpp | 4 +-- icu4c/source/test/intltest/caltest.cpp | 42 ++++++++++++++++++++++++++ icu4c/source/test/intltest/caltest.h | 7 ++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index 183db4065e0..e2d896a8b67 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -138,8 +138,8 @@ U_CFUNC void ucal_dump(UCalendar* cal) { #endif -/* Max value for stamp allowable */ -#define STAMP_MAX INT32_MAX +/* Max value for stamp allowable before recalculation */ +#define STAMP_MAX 10000 static const char * const gCalTypes[] = { "gregorian", diff --git a/icu4c/source/test/intltest/caltest.cpp b/icu4c/source/test/intltest/caltest.cpp index bac34354a0b..b418fc736d6 100644 --- a/icu4c/source/test/intltest/caltest.cpp +++ b/icu4c/source/test/intltest/caltest.cpp @@ -229,6 +229,13 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name, Test1624(); } break; + case 25: + name = "TestTimeStamp"; + if(exec) { + logln("TestTimeStamp---"); logln(""); + TestTimeStamp(); + } + break; default: name = ""; break; } } @@ -2158,6 +2165,41 @@ void CalendarTest::Test1624() { return; } +void CalendarTest::TestTimeStamp() { + UErrorCode status = U_ZERO_ERROR; + UDate start, time; + Calendar *cal; + + // Create a new Gregorian Calendar. + cal = Calendar::createInstance("en_US@calender=gregorian", status); + if (U_FAILURE(status)) { + dataerrln("Error creating Gregorian calendar."); + return; + } + + for (int i = 0; i < 20000; i++) { + // Set the Gregorian Calendar to a specific date for testing. + cal->set(2009, UCAL_JULY, 3, 0, 49, 46); + + time = cal->getTime(status); + if (U_FAILURE(status)) { + errln("Error calling getTime()"); + break; + } + + if (i == 0) { + start = time; + } else { + if (start != time) { + errln("start and time not equal."); + break; + } + } + } + + delete cal; +} + #endif /* #if !UCONFIG_NO_FORMATTING */ //eof diff --git a/icu4c/source/test/intltest/caltest.h b/icu4c/source/test/intltest/caltest.h index c8b51f15f7e..f998f0b84db 100644 --- a/icu4c/source/test/intltest/caltest.h +++ b/icu4c/source/test/intltest/caltest.h @@ -1,5 +1,5 @@ /*********************************************************************** - * Copyright (c) 1997-2009, International Business Machines Corporation + * Copyright (c) 1997-2010, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -219,6 +219,11 @@ public: // package void Test6703(void); void Test3785(void); void Test1624(void); + + /** + * Test the time stamp array recalculation during heavy Calendar usage + */ + void TestTimeStamp(void); }; #endif /* #if !UCONFIG_NO_FORMATTING */