]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/srchtest.cpp
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / test / intltest / srchtest.cpp
index cb95832119bf14ea1bbcfa7d17007b0611149cd5..6899f4bb2587687bdfdab6293fc2808538d2b416 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *****************************************************************************
-* Copyright (C) 2001-2003, International Business Machines orporation and others.  
-* All Rights Reserved.
+* Copyright (C) 2001-2004, International Business Machines orporation  
+* and others. All Rights Reserved.
 ****************************************************************************/
 
 #include "unicode/utypes.h"
@@ -14,6 +14,7 @@
 #include "unicode/ustring.h"
 #include "unicode/schriter.h"
 #include <string.h>
+#include <stdio.h>
 
 // private definitions -----------------------------------------------------
 
@@ -193,33 +194,19 @@ BreakIterator * StringSearchTest::getBreakIterator(const char *breaker)
 
 char * StringSearchTest::toCharString(const UnicodeString &text)
 {
-           UChar  unichars[512];
     static char   result[1024];
-           int    count  = 0;
            int    index  = 0;
+           int    count  = 0;
            int    length = text.length();
 
-    text.extract(0, text.length(), unichars, 0);
-
     for (; count < length; count ++) {
-        UChar ch = unichars[count];
+        UChar ch = text[count];
         if (ch >= 0x20 && ch <= 0x7e) {
             result[index ++] = (char)ch;
         }
         else {
-            char digit[5];
-            int  zerosize;
-            result[index ++] = '\\';
-            result[index ++] = 'u';
-            sprintf(digit, "%x", ch);
-            zerosize = 4 - strlen(digit);
-            while (zerosize != 0) {
-                result[index ++] = '0';
-                zerosize --;
-            }
-            result[index] = 0;
-            strcat(result, digit);
-            index += strlen(digit);
+            sprintf(result+index, "\\u%04x", ch);
+            index += 6; /* \uxxxx */
         }
     }
     result[index] = 0;
@@ -344,7 +331,7 @@ UBool StringSearchTest::assertEqual(const SearchData *search)
     
     Collator      *collator = getCollator(search->collator);
     BreakIterator *breaker  = getBreakIterator(search->breaker);
-    StringSearch  *strsrch
+    StringSearch  *strsrch, *strsrch2;
     UChar          temp[128];
     
 #if UCONFIG_NO_BREAK_ITERATION
@@ -377,6 +364,20 @@ UBool StringSearchTest::assertEqual(const SearchData *search)
         delete strsrch;
         return FALSE;
     }
+
+
+    strsrch2 = strsrch->clone();
+    if( strsrch2 == strsrch || *strsrch2 != *strsrch ||
+        !assertEqualWithStringSearch(strsrch2, search)
+    ) {
+        errln("failure with StringSearch.clone()");
+        collator->setStrength(getECollationStrength(UCOL_TERTIARY));
+        delete strsrch;
+        delete strsrch2;
+        return FALSE;
+    }
+    delete strsrch2;
+
     collator->setStrength(getECollationStrength(UCOL_TERTIARY));
     delete strsrch;
     return TRUE;
@@ -1618,6 +1619,10 @@ void StringSearchTest::TestBreakIteratorCanonical()
         }
         search  = &(BREAKITERATOREXACT[count + 1]);
         breaker = getBreakIterator(search->breaker);
+        if (breaker == NULL) {
+            errln("Error creating BreakIterator");
+            return;
+        }
         breaker->setText(strsrch->getText());
         strsrch->setBreakIterator(breaker, status);
         if (U_FAILURE(status) || strsrch->getBreakIterator() != breaker) {
@@ -2230,7 +2235,7 @@ void StringSearchTest::TestSubclass()
     int i;
     StringCharacterIterator chariter(text);
 
-       search.setText(text, status);
+    search.setText(text, status);
     if (search.getText() != search2.getText()) {
         errln("Error setting text");
     }