]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/ucaconf.cpp
ICU-461.12.tar.gz
[apple/icu.git] / icuSources / test / intltest / ucaconf.cpp
index bc85d90c854099e2b09c24088c6964c15a111cdc..8c492c17edaefb89b4b769ecab1075fc6fc0ff88 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 2002-2008, International Business Machines Corporation and
+ * Copyright (c) 2002-2010, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
@@ -31,7 +31,7 @@ status(U_ZERO_ERROR)
 
     const char *srcDir = IntlTest::getSourceTestData(status);
     if (U_FAILURE(status)) {
-        dataerrln("[DATA] Could not open test data %s", u_errorName(status));
+        dataerrln("Could not open test data %s", u_errorName(status));
         return;
     }
     uprv_strcpy(testDataPath, srcDir);
@@ -136,7 +136,7 @@ void UCAConformanceTest::openTestFile(const char *type)
 
             if (testFile == 0) {
                 *(buffer+bufLen) = 0;
-                dataerrln("[DATA] Could not open any of the conformance test files, tried opening base %s\n", buffer);
+                dataerrln("Could not open any of the conformance test files, tried opening base %s\n", buffer);
                 return;        
             } else {
                 infoln(
@@ -158,10 +158,14 @@ void UCAConformanceTest::testConformance(UCollator *coll)
     int32_t line = 0;
 
     UChar b1[1024], b2[1024];
-    char lineB[1024];
     UChar *buffer = b1, *oldB = NULL;
+
+    char lineB1[1024], lineB2[1024];
+    char *lineB = lineB1, *oldLineB = lineB2;
+
     uint8_t sk1[1024], sk2[1024];
     uint8_t *oldSk = NULL, *newSk = sk1;
+
     int32_t resLen = 0, oldLen = 0;
     int32_t buflen = 0, oldBlen = 0;
     uint32_t first = 0;
@@ -170,6 +174,8 @@ void UCAConformanceTest::testConformance(UCollator *coll)
 
 
     while (fgets(lineB, 1024, testFile) != NULL) {
+        // remove trailing whitespace
+        u_rtrim(lineB);
         offset = 0;
 
         line++;
@@ -177,6 +183,11 @@ void UCAConformanceTest::testConformance(UCollator *coll)
             continue;
         }
         offset = u_parseString(lineB, buffer, 1024, &first, &status);
+        if(U_FAILURE(status)) {
+            errln("Error parsing line %ld (%s): %s\n",
+                  (long)line, u_errorName(status), lineB);
+            status = U_ZERO_ERROR;
+        }
         buflen = offset;
         buffer[offset++] = 0;
 
@@ -195,34 +206,51 @@ void UCAConformanceTest::testConformance(UCollator *coll)
 
             if(((res&0x80000000) != (cmpres&0x80000000)) || (res == 0 && cmpres != 0) || (res != 0 && cmpres == 0)) {
                 errln("Difference between ucol_strcoll and sortkey compare on line %i", line);
-                logln("Data line %s", lineB);
+                errln("  Previous data line %s", oldLineB);
+                errln("  Current data line  %s", lineB);
             }
 
             if(res > 0) {
                 errln("Line %i is not greater or equal than previous line", line);
-                logln("Data line %s", lineB);
+                errln("  Previous data line %s", oldLineB);
+                errln("  Current data line  %s", lineB);
                 prettify(CollationKey(oldSk, oldLen), oldS);
                 prettify(CollationKey(newSk, resLen), newS);
-                logln("Keys: "+oldS+" and "+newS);
+                errln("  Previous key: "+oldS);
+                errln("  Current key:  "+newS);
             } else if(res == 0) { /* equal */
                 res = u_strcmpCodePointOrder(oldB, buffer);
                 if (res == 0) {
                     errln("Probable error in test file on line %i (comparing identical strings)", line);
-                    logln("Data line %s", lineB);
-                } else if (res > 0) {
-                    errln("Sortkeys are identical, but code point comapare gives >0 on line %i", line);
-                    logln("Data line %s", lineB);
+                    errln("  Data line %s", lineB);
+                }
+                /*
+                 * UCA 6.0 test files can have lines that compare == if they are
+                 * different strings but canonically equivalent.
+                else if (res > 0) {
+                    errln("Sortkeys are identical, but code point compare gives >0 on line %i", line);
+                    errln("  Previous data line %s", oldLineB);
+                    errln("  Current data line  %s", lineB);
                 }
+                 */
             }
         }
 
+        // swap buffers
+        oldLineB = lineB;
+        oldB = buffer;
         oldSk = newSk;
+        if(lineB == lineB1) {
+            lineB = lineB2;
+            buffer = b2;
+            newSk = sk2;
+        } else {
+            lineB = lineB1;
+            buffer = b1;
+            newSk = sk1;
+        }
         oldLen = resLen;
-
-        newSk = (newSk == sk1)?sk2:sk1;
-        oldB = buffer;
         oldBlen = buflen;
-        buffer = (buffer == b1)?b2:b1;
     }
 }