X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/57a6839dcb3bba09e8228b822b290604668416fe..b331163bffd790ced0e88b73f44f86d49ccc48a5:/icuSources/test/intltest/itutil.cpp diff --git a/icuSources/test/intltest/itutil.cpp b/icuSources/test/intltest/itutil.cpp index 8557ff92..ce2c5a85 100644 --- a/icuSources/test/intltest/itutil.cpp +++ b/icuSources/test/intltest/itutil.cpp @@ -12,6 +12,7 @@ #include "unicode/utypes.h" #include "unicode/errorcode.h" #include "unicode/localpointer.h" +#include "charstr.h" #include "itutil.h" #include "strtest.h" #include "loctest.h" @@ -33,8 +34,9 @@ extern IntlTest *createBytesTrieTest(); static IntlTest *createLocalPointerTest(); extern IntlTest *createUCharsTrieTest(); static IntlTest *createEnumSetTest(); -extern IntlTest *createLRUCacheTest(); extern IntlTest *createSimplePatternFormatterTest(); +extern IntlTest *createUnifiedCacheTest(); +extern IntlTest *createQuantityFormatterTest(); #define CASE(id, test) case id: \ name = #test; \ @@ -98,18 +100,26 @@ void IntlTestUtilities::runIndexedTest( int32_t index, UBool exec, const char* & } break; case 20: - name = "LRUCacheTest"; + name = "SimplePatternFormatterTest"; if (exec) { - logln("TestSuite LRUCacheTest---"); logln(); - LocalPointer test(createLRUCacheTest()); + logln("TestSuite SimplePatternFormatterTest---"); logln(); + LocalPointer test(createSimplePatternFormatterTest()); callTest(*test, par); } break; case 21: - name = "SimplePatternFormatterTest"; + name = "UnifiedCacheTest"; if (exec) { - logln("TestSuite SimplePatternFormatterTest---"); logln(); - LocalPointer test(createSimplePatternFormatterTest()); + logln("TestSuite UnifiedCacheTest---"); logln(); + LocalPointer test(createUnifiedCacheTest()); + callTest(*test, par); + } + break; + case 22: + name = "QuantityFormatterTest"; + if (exec) { + logln("TestSuite QuantityFormatterTest---"); logln(); + LocalPointer test(createQuantityFormatterTest()); callTest(*test, par); } break; @@ -253,15 +263,12 @@ void LocalPointerTest::runIndexedTest(int32_t index, UBool exec, const char *&na if(exec) { logln("TestSuite LocalPointerTest: "); } - switch (index) { - TESTCASE(0, TestLocalPointer); - TESTCASE(1, TestLocalArray); - TESTCASE(2, TestLocalXyzPointer); - TESTCASE(3, TestLocalXyzPointerNull); - default: - name=""; - break; // needed to end the loop - } + TESTCASE_AUTO_BEGIN; + TESTCASE_AUTO(TestLocalPointer); + TESTCASE_AUTO(TestLocalArray); + TESTCASE_AUTO(TestLocalXyzPointer); + TESTCASE_AUTO(TestLocalXyzPointerNull); + TESTCASE_AUTO_END; } // Exercise every LocalPointer and LocalPointerBase method. @@ -292,6 +299,43 @@ void LocalPointerTest::TestLocalPointer() { if(s->length()!=0) { errln("LocalPointer adoptInstead(empty) failure"); } + + // LocalPointer(p, errorCode) sets U_MEMORY_ALLOCATION_ERROR if p==NULL. + UErrorCode errorCode = U_ZERO_ERROR; + LocalPointer cs(new CharString("some chars", errorCode), errorCode); + if(cs.isNull() && U_SUCCESS(errorCode)) { + errln("LocalPointer(p, errorCode) failure"); + return; + } + errorCode = U_ZERO_ERROR; + cs.adoptInsteadAndCheckErrorCode(new CharString("different chars", errorCode), errorCode); + if(cs.isNull() && U_SUCCESS(errorCode)) { + errln("adoptInsteadAndCheckErrorCode(p, errorCode) failure"); + return; + } + // Incoming failure: Keep the current object and delete the input object. + errorCode = U_ILLEGAL_ARGUMENT_ERROR; + cs.adoptInsteadAndCheckErrorCode(new CharString("unused", errorCode), errorCode); + if(cs.isValid() && strcmp(cs->data(), "different chars") != 0) { + errln("adoptInsteadAndCheckErrorCode(p, U_FAILURE) did not retain the old object"); + return; + } + errorCode = U_ZERO_ERROR; + cs.adoptInsteadAndCheckErrorCode(NULL, errorCode); + if(errorCode != U_MEMORY_ALLOCATION_ERROR) { + errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR"); + return; + } + if(cs.isValid()) { + errln("adoptInsteadAndCheckErrorCode(NULL, errorCode) kept the object"); + return; + } + errorCode = U_ZERO_ERROR; + LocalPointer null(NULL, errorCode); + if(errorCode != U_MEMORY_ALLOCATION_ERROR) { + errln("LocalPointer(NULL, errorCode) did not set U_MEMORY_ALLOCATION_ERROR"); + return; + } } // Exercise every LocalArray method (but not LocalPointerBase).