rolled back to 2.9.2 because 2.9.4 doesn't work with XML validator
[platform/upstream/libxml2.git] / runtest.c
index bb74d2a..02fe09a 100644 (file)
--- a/runtest.c
+++ b/runtest.c
  */
 #ifdef O_BINARY
 #define RD_FLAGS       O_RDONLY | O_BINARY
-#define WR_FLAGS       O_WRONLY | O_CREAT | O_TRUNC | O_BINARY
 #else
-#define RD_FLAGS       O_RDONLY
-#define WR_FLAGS       O_WRONLY | O_CREAT | O_TRUNC
+#define        RD_FLAGS        O_RDONLY
 #endif
 
 typedef int (*functest) (const char *filename, const char *result,
@@ -102,7 +100,6 @@ struct testDesc {
     int     options;  /* parser options for the test */
 };
 
-static int update_results = 0;
 static int checkTestFile(const char *filename);
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
@@ -607,34 +604,12 @@ static int checkTestFile(const char *filename) {
     return(1);
 }
 
-static int compareFiles(const char *r1 /* temp */, const char *r2 /* result */) {
+static int compareFiles(const char *r1, const char *r2) {
     int res1, res2;
     int fd1, fd2;
     char bytes1[4096];
     char bytes2[4096];
 
-    if (update_results) {
-        fd1 = open(r1, RD_FLAGS);
-        if (fd1 < 0)
-            return(-1);
-        fd2 = open(r2, WR_FLAGS, 0644);
-        if (fd2 < 0) {
-            close(fd1);
-            return(-1);
-        }
-        do {
-            res1 = read(fd1, bytes1, 4096);
-            if (res1 <= 0)
-                break;
-            res2 = write(fd2, bytes1, res1);
-            if (res2 <= 0 || res2 != res1)
-                break;
-        } while (1);
-        close(fd2);
-        close(fd1);
-        return(res1 != 0);
-    }
-
     fd1 = open(r1, RD_FLAGS);
     if (fd1 < 0)
         return(-1);
@@ -671,31 +646,13 @@ static int compareFileMem(const char *filename, const char *mem, int size) {
     int idx = 0;
     struct stat info;
 
-    if (update_results) {
-        fd = open(filename, WR_FLAGS, 0644);
-        if (fd < 0) {
-           fprintf(stderr, "failed to open %s for writing", filename);
-            return(-1);
-       }
-        res = write(fd, mem, size);
-        close(fd);
-        return(res != size);
-    }
-
-    if (stat(filename, &info) < 0) {
-        fprintf(stderr, "failed to stat %s\n", filename);
+    if (stat(filename, &info) < 0)
        return(-1);
-    }
-    if (info.st_size != size) {
-        fprintf(stderr, "file %s is %ld bytes, result is %d bytes\n",
-               filename, info.st_size, size);
+    if (info.st_size != size)
         return(-1);
-    }
     fd = open(filename, RD_FLAGS);
-    if (fd < 0) {
-       fprintf(stderr, "failed to open %s for reading", filename);
+    if (fd < 0)
         return(-1);
-    }
     while (idx < size) {
         res = read(fd, bytes, 4096);
        if (res <= 0)
@@ -714,9 +671,6 @@ static int compareFileMem(const char *filename, const char *mem, int size) {
        idx += res;
     }
     close(fd);
-    if (idx != size) {
-       fprintf(stderr,"Compare error index %d, size %d\n", idx, size);
-    }
     return(idx != size);
 }
 
@@ -1873,7 +1827,7 @@ pushParseTest(const char *filename, const char *result,
     ctxt = xmlCreatePushParserCtxt(NULL, NULL, base + cur, 4, filename);
     xmlCtxtUseOptions(ctxt, options);
     cur += 4;
-    do {
+    while (cur < size) {
         if (cur + 1024 >= size) {
 #ifdef LIBXML_HTML_ENABLED
            if (options & XML_PARSE_HTML)
@@ -1891,7 +1845,7 @@ pushParseTest(const char *filename, const char *result,
            xmlParseChunk(ctxt, base + cur, 1024, 0);
            cur += 1024;
        }
-    } while (cur < size);
+    }
     doc = ctxt->myDoc;
 #ifdef LIBXML_HTML_ENABLED
     if (options & XML_PARSE_HTML)
@@ -1917,7 +1871,7 @@ pushParseTest(const char *filename, const char *result,
     if ((base == NULL) || (res != 0)) {
        if (base != NULL)
            xmlFree((char *)base);
-        fprintf(stderr, "Result for %s failed in %s\n", filename, result);
+        fprintf(stderr, "Result for %s failed\n", filename);
        return(-1);
     }
     xmlFree((char *)base);
@@ -1972,7 +1926,7 @@ memParseTest(const char *filename, const char *result,
     if ((base == NULL) || (res != 0)) {
        if (base != NULL)
            xmlFree((char *)base);
-        fprintf(stderr, "Result for %s failed in %s\n", filename, result);
+        fprintf(stderr, "Result for %s failed\n", filename);
        return(-1);
     }
     xmlFree((char *)base);
@@ -2083,16 +2037,16 @@ errParseTest(const char *filename, const char *result, const char *err,
            xmlDocDumpMemory(doc, (xmlChar **) &base, &size);
        }
        res = compareFileMem(result, base, size);
-       if (res != 0) {
-           fprintf(stderr, "Result for %s failed in %s\n", filename, result);
-           return(-1);
-       }
     }
     if (doc != NULL) {
        if (base != NULL)
            xmlFree((char *)base);
        xmlFreeDoc(doc);
     }
+    if (res != 0) {
+        fprintf(stderr, "Result for %s failed\n", filename);
+       return(-1);
+    }
     if (err != NULL) {
        res = compareFileMem(err, testErrors, testErrorsSize);
        if (res != 0) {
@@ -2205,7 +2159,7 @@ streamProcessTest(const char *filename, const char *result, const char *err,
             free(temp);
         }
        if (ret) {
-           fprintf(stderr, "Result for %s failed in %s\n", filename, result);
+           fprintf(stderr, "Result for %s failed\n", filename);
            return(-1);
        }
     }
@@ -2408,7 +2362,7 @@ xpathCommonTest(const char *filename, const char *result,
     if (result != NULL) {
        ret = compareFiles(temp, result);
        if (ret) {
-           fprintf(stderr, "Result for %s failed in %s\n", filename, result);
+           fprintf(stderr, "Result for %s failed\n", filename);
        }
     }
 
@@ -2579,7 +2533,7 @@ xmlidDocTest(const char *filename,
     if (result != NULL) {
        ret = compareFiles(temp, result);
        if (ret) {
-           fprintf(stderr, "Result for %s failed in %s\n", filename, result);
+           fprintf(stderr, "Result for %s failed\n", filename);
            res = 1;
        }
     }
@@ -2707,7 +2661,7 @@ uriCommonTest(const char *filename,
     if (result != NULL) {
        ret = compareFiles(temp, result);
        if (ret) {
-           fprintf(stderr, "Result for %s failed in %s\n", filename, result);
+           fprintf(stderr, "Result for %s failed\n", filename);
            res = 1;
        }
     }
@@ -3476,11 +3430,11 @@ patternTest(const char *filename,
     result[499] = 0;
     memcpy(xml + len, ".xml", 5);
 
-    if (!checkTestFile(xml) && !update_results) {
+    if (!checkTestFile(xml)) {
        fprintf(stderr, "Missing xml file %s\n", xml);
        return(-1);
     }
-    if (!checkTestFile(result) && !update_results) {
+    if (!checkTestFile(result)) {
        fprintf(stderr, "Missing result file %s\n", result);
        return(-1);
     }
@@ -3579,7 +3533,7 @@ patternTest(const char *filename,
 
     ret = compareFiles(temp, result);
     if (ret) {
-       fprintf(stderr, "Result for %s failed in %s\n", filename, result);
+       fprintf(stderr, "Result for %s failed\n", filename);
        ret = 1;
     }
     if (temp != NULL) {
@@ -3851,7 +3805,7 @@ c14nCommonTest(const char *filename, int with_comments, int mode,
     prefix[len] = 0;
 
     snprintf(buf, 499, "result/c14n/%s/%s", subdir,prefix);
-    if (!checkTestFile(buf) && !update_results) {
+    if (!checkTestFile(buf)) {
         fprintf(stderr, "Missing result file %s", buf);
        return(-1);
     }
@@ -4400,9 +4354,9 @@ launchTests(testDescPtr tst) {
            } else {
                error = NULL;
            }
-           if ((result) &&(!checkTestFile(result)) && !update_results) {
+           if ((result) &&(!checkTestFile(result))) {
                fprintf(stderr, "Missing result file %s\n", result);
-           } else if ((error) &&(!checkTestFile(error)) && !update_results) {
+           } else if ((error) &&(!checkTestFile(error))) {
                fprintf(stderr, "Missing error file %s\n", error);
            } else {
                mem = xmlMemUsed();
@@ -4486,8 +4440,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
     for (a = 1; a < argc;a++) {
         if (!strcmp(argv[a], "-v"))
            verbose = 1;
-        else if (!strcmp(argv[a], "-u"))
-           update_results = 1;
         else if (!strcmp(argv[a], "-quiet"))
            tests_quiet = 1;
        else {