X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/51004dcb01e06fef634b61be77ed73dd61cb6db9..b801cf366c7671a99bdcef84d1e9c0ec64b36723:/icuSources/test/intltest/itutil.cpp diff --git a/icuSources/test/intltest/itutil.cpp b/icuSources/test/intltest/itutil.cpp index 2f726101..ce2c5a85 100644 --- a/icuSources/test/intltest/itutil.cpp +++ b/icuSources/test/intltest/itutil.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2012, International Business Machines Corporation and + * Copyright (c) 1997-2014, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -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,6 +34,9 @@ extern IntlTest *createBytesTrieTest(); static IntlTest *createLocalPointerTest(); extern IntlTest *createUCharsTrieTest(); static IntlTest *createEnumSetTest(); +extern IntlTest *createSimplePatternFormatterTest(); +extern IntlTest *createUnifiedCacheTest(); +extern IntlTest *createQuantityFormatterTest(); #define CASE(id, test) case id: \ name = #test; \ @@ -95,6 +99,30 @@ void IntlTestUtilities::runIndexedTest( int32_t index, UBool exec, const char* & callTest(*test, par); } break; + case 20: + name = "SimplePatternFormatterTest"; + if (exec) { + logln("TestSuite SimplePatternFormatterTest---"); logln(); + LocalPointer test(createSimplePatternFormatterTest()); + callTest(*test, par); + } + break; + case 21: + name = "UnifiedCacheTest"; + if (exec) { + 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; default: name = ""; break; //needed to end loop } } @@ -235,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. @@ -274,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).