]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/tscoll.cpp
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / tscoll.cpp
index 8aabab53b3d4c384776514cf7c605a7e56168428..8b1c43c523a98b905292a3e652f651f8c002efb1 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2008, International Business Machines Corporation and
+ * Copyright (c) 1997-2014, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
 
 #if !UCONFIG_NO_COLLATION
 
+#include "unicode/localpointer.h"
+#include "unicode/sortkey.h"
 #include "unicode/uchar.h"
 #include "unicode/ustring.h"
 
-#include "dadrcoll.h"
-
 #include "encoll.h"
 #include "frcoll.h"
 #include "decoll.h"
 #include "thcoll.h"
 #include "srchtest.h"
 #include "ssearch.h"
-#include "cntabcol.h"
 #include "lcukocol.h"
 #include "ucaconf.h"
 #include "svccoll.h"
 #include "cmemory.h"
-//#include "rndmcoll.h"
+#include "alphaindextst.h"
 
 // Set to 1 to test offsets in backAndForth()
 #define TEST_OFFSETS 0
 
-#define TESTCLASS(n,classname)        \
-    case n:                           \
-        name = #classname;            \
-        if (exec) {                   \
-            logln(#classname "---");  \
-            logln("");                \
-            classname t;              \
-            callTest(t, par);         \
-        }                             \
-        break
+extern IntlTest *createCollationTest();
 
 void IntlTestCollator::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
 {
@@ -70,33 +60,32 @@ void IntlTestCollator::runIndexedTest( int32_t index, UBool exec, const char* &n
         logln("TestSuite Collator: ");
     }
 
-    switch (index) {
-      TESTCLASS(0, CollationEnglishTest);
-      TESTCLASS(1, CollationFrenchTest);
-      TESTCLASS(2, CollationGermanTest);
-      TESTCLASS(3, CollationSpanishTest);
-      TESTCLASS(4, CollationKanaTest);
-      TESTCLASS(5, CollationTurkishTest);
-      TESTCLASS(6, CollationDummyTest);
-      TESTCLASS(7, G7CollationTest);
-      TESTCLASS(8, CollationMonkeyTest);
-      TESTCLASS(9, CollationAPITest);
-      TESTCLASS(10, CollationRegressionTest);
-      TESTCLASS(11, CollationCurrencyTest);
-      TESTCLASS(12, CollationIteratorTest);
-      TESTCLASS(13, CollationThaiTest);
-      TESTCLASS(14, LotusCollationKoreanTest);
-      TESTCLASS(15, StringSearchTest);
-      TESTCLASS(16, ContractionTableTest);
-      TESTCLASS(17, DataDrivenCollatorTest);
-      TESTCLASS(18, UCAConformanceTest);
-      TESTCLASS(19, CollationServiceTest);
-      TESTCLASS(20, CollationFinnishTest); // removed by weiv - we have changed Finnish collation
-      //TESTCLASS(21, RandomCollatorTest); // See ticket 5747 about reenabling this test.
-      TESTCLASS(21, SSearchTest);
-
-      default: name = ""; break;
-    }
+    TESTCASE_AUTO_BEGIN;
+    TESTCASE_AUTO_CLASS(CollationEnglishTest);
+    TESTCASE_AUTO_CLASS(CollationFrenchTest);
+    TESTCASE_AUTO_CLASS(CollationGermanTest);
+    TESTCASE_AUTO_CLASS(CollationSpanishTest);
+    TESTCASE_AUTO_CLASS(CollationKanaTest);
+    TESTCASE_AUTO_CLASS(CollationTurkishTest);
+    TESTCASE_AUTO_CLASS(CollationDummyTest);
+    TESTCASE_AUTO_CLASS(G7CollationTest);
+    TESTCASE_AUTO_CLASS(CollationMonkeyTest);
+    TESTCASE_AUTO_CLASS(CollationAPITest);
+    TESTCASE_AUTO_CLASS(CollationRegressionTest);
+    TESTCASE_AUTO_CLASS(CollationCurrencyTest);
+    TESTCASE_AUTO_CLASS(CollationIteratorTest);
+    TESTCASE_AUTO_CLASS(CollationThaiTest);
+    TESTCASE_AUTO_CLASS(LotusCollationKoreanTest);
+    TESTCASE_AUTO_CLASS(StringSearchTest);
+    TESTCASE_AUTO_CLASS(UCAConformanceTest);
+    TESTCASE_AUTO_CLASS(CollationServiceTest);
+    TESTCASE_AUTO_CLASS(CollationFinnishTest); // removed by weiv - we have changed Finnish collation
+    TESTCASE_AUTO_CLASS(SSearchTest);
+#if !UCONFIG_NO_NORMALIZATION
+    TESTCASE_AUTO_CLASS(AlphabeticIndexTest);
+#endif
+    TESTCASE_AUTO_CREATE_CLASS(CollationTest);
+    TESTCASE_AUTO_END;
 }
 
 UCollationResult 
@@ -138,7 +127,7 @@ IntlTestCollator::doTestVariant(Collator* col, const UnicodeString &source, cons
 {   
   UErrorCode status = U_ZERO_ERROR;
 
-  UCollator *myCollation = (UCollator *)((RuleBasedCollator *)col)->getUCollator();
+  UCollator *myCollation = col->toUCollator();
 
   Collator::EComparisonResult compareResult = col->compare(source, target);
 
@@ -263,13 +252,12 @@ IntlTestCollator::doTest(Collator* col, const UnicodeString &source, const Unico
     }
 
     UErrorCode status = U_ZERO_ERROR;
-    CollationElementIterator* c = ((RuleBasedCollator *)col)->createCollationElementIterator( source );
+    LocalPointer<CollationElementIterator> c(((RuleBasedCollator *)col)->createCollationElementIterator(source));
     logln("Testing iterating source: "+source);
     backAndForth(*c);
     c->setText(target, status);
     logln("Testing iterating target: "+target);
     backAndForth(*c);
-    delete c;
   }
 }
 
@@ -384,8 +372,10 @@ UnicodeString &IntlTestCollator::prettify(const CollationKey &source, UnicodeStr
 
     for (i = 0; i < byteCount; i += 1)
     {
+        if (i != 0) {
+            target += " ";
+        }
         appendHex(bytes[i], 2, target);
-        target += " ";
     }
 
     target += "]";
@@ -397,7 +387,7 @@ void IntlTestCollator::backAndForth(CollationElementIterator &iter)
 {
     // Run through the iterator forwards and stick it into an array
     int32_t orderLength = 0;
-    Order *orders = getOrders(iter, orderLength);
+    LocalArray<Order> orders(getOrders(iter, orderLength));
     UErrorCode status = U_ZERO_ERROR;
 
     // Now go through it backwards and make sure we get the same values
@@ -409,7 +399,7 @@ void IntlTestCollator::backAndForth(CollationElementIterator &iter)
 
     while ((o = iter.previous(status)) != CollationElementIterator::NULLORDER)
     {
-        int32_t offset = iter.getOffset();
+        /*int32_t offset = */iter.getOffset();
 
         if (index == 0) {
           if(o == 0) {
@@ -434,7 +424,7 @@ void IntlTestCollator::backAndForth(CollationElementIterator &iter)
                     errln("Mismatched order at index %d: 0x%0:8X vs. 0x%0:8X", index,
                     orders[index].order, o);
                 //break;
-                  goto bail;
+                  return;
                 }
             }
         }
@@ -444,7 +434,7 @@ void IntlTestCollator::backAndForth(CollationElementIterator &iter)
           errln("Mismatched offset at index %d: %d vs. %d", index,
             orders[index].offset, offset);
        //break;
-         goto bail;
+         return;
         }
 #endif
 
@@ -483,9 +473,6 @@ void IntlTestCollator::backAndForth(CollationElementIterator &iter)
         }
         errln("");
     }
-
-bail:
-    delete[] orders;
 }
 
 
@@ -497,7 +484,7 @@ IntlTestCollator::Order *IntlTestCollator::getOrders(CollationElementIterator &i
 {
     int32_t maxSize = 100;
     int32_t size = 0;
-    Order *orders = new Order[maxSize];
+    LocalArray<Order> orders(new Order[maxSize]);
     UErrorCode status = U_ZERO_ERROR;
     int32_t offset = iter.getOffset();
 
@@ -509,9 +496,8 @@ IntlTestCollator::Order *IntlTestCollator::getOrders(CollationElementIterator &i
             maxSize *= 2;
             Order *temp = new Order[maxSize];
 
-            uprv_memcpy(temp, orders, size * sizeof(Order));
-            delete[] orders;
-            orders = temp;
+            uprv_memcpy(temp, orders.getAlias(), size * sizeof(Order));
+            orders.adoptInstead(temp);
         }
 
         orders[size].order  = order;
@@ -520,18 +506,21 @@ IntlTestCollator::Order *IntlTestCollator::getOrders(CollationElementIterator &i
         offset = iter.getOffset();
         size += 1;
     }
+    if (U_FAILURE(status)) {
+        errln("CollationElementIterator.next() failed - %s",
+              u_errorName(status));
+    }
 
     if (maxSize > size)
     {
         Order *temp = new Order[size];
 
-        uprv_memcpy(temp, orders, size * sizeof(Order));
-        delete[] orders;
-        orders = temp;
+        uprv_memcpy(temp, orders.getAlias(), size * sizeof(Order));
+        orders.adoptInstead(temp);
     }
 
     orderLength = size;
-    return orders;
+    return orders.orphan();
 }
 
 #endif /* #if !UCONFIG_NO_COLLATION */