]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/itutil.cpp
ICU-551.24.tar.gz
[apple/icu.git] / icuSources / test / intltest / itutil.cpp
index 8557ff92beb9c85a539daa446f1597f8753db636..ce2c5a85d7a4d3ca2d819b9a92209dc7aa67b6f0 100644 (file)
@@ -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<IntlTest> test(createLRUCacheTest());
+                logln("TestSuite SimplePatternFormatterTest---"); logln();
+                LocalPointer<IntlTest> test(createSimplePatternFormatterTest());
                 callTest(*test, par);
             }
             break;
         case 21:
-            name = "SimplePatternFormatterTest";
+            name = "UnifiedCacheTest";
             if (exec) {
-                logln("TestSuite SimplePatternFormatterTest---"); logln();
-                LocalPointer<IntlTest> test(createSimplePatternFormatterTest());
+                logln("TestSuite UnifiedCacheTest---"); logln();
+                LocalPointer<IntlTest> test(createUnifiedCacheTest());
+                callTest(*test, par);
+            }
+            break;
+        case 22:
+            name = "QuantityFormatterTest";
+            if (exec) {
+                logln("TestSuite QuantityFormatterTest---"); logln();
+                LocalPointer<IntlTest> 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<CharString> 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<CharString> 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).