[libxml2] Fix schemas and relaxng tests



commit 48f191e7d7f0a4bb7bc9fa687e011ea3c5374200
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Mon Apr 4 03:12:49 2022 +0200

    Fix schemas and relaxng tests
    
    Run all tests in runtest.c with warnings. This is required to match the
    schema validation output from xmllint and doesn't seem to cause any
    problems.
    
    Fix the .xml file pattern.
    
    Check parser errors. Print xmllint message if Relax-NG schema can't be
    parsed.

 runtest.c | 64 ++++++++++++++++++++++++++-------------------------------------
 1 file changed, 26 insertions(+), 38 deletions(-)
---
diff --git a/runtest.c b/runtest.c
index c51d8d5e..31bb5c6c 100644
--- a/runtest.c
+++ b/runtest.c
@@ -531,7 +531,6 @@ testStructuredErrorHandler(void *ctx  ATTRIBUTE_UNUSED, xmlErrorPtr err) {
 
 static void
 initializeLibxml2(void) {
-    xmlGetWarningsDefaultValue = 0;
     xmlPedanticParserDefault(0);
 
     xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
@@ -2100,10 +2099,8 @@ errParseTest(const char *filename, const char *result, const char *err,
     } else
 #endif
     {
-       xmlGetWarningsDefaultValue = 1;
        doc = xmlReadFile(filename, NULL, options);
     }
-    xmlGetWarningsDefaultValue = 0;
     if (result) {
        if (doc == NULL) {
            base = "";
@@ -2166,11 +2163,9 @@ fdParseTest(const char *filename, const char *result, const char *err,
     } else
 #endif
     {
-       xmlGetWarningsDefaultValue = 1;
        doc = xmlReadFd(fd, filename, NULL, options);
     }
     close(fd);
-    xmlGetWarningsDefaultValue = 0;
     if (result) {
        if (doc == NULL) {
            base = "";
@@ -2283,7 +2278,6 @@ streamProcessTest(const char *filename, const char *result, const char *err,
        }
     }
 #endif
-    xmlGetWarningsDefaultValue = 1;
     ret = xmlTextReaderRead(reader);
     while (ret == 1) {
        if ((t != NULL) && (rng == NULL))
@@ -2300,7 +2294,6 @@ streamProcessTest(const char *filename, const char *result, const char *err,
            testErrorHandler(NULL, "%s validates\n", filename);
        }
     }
-    xmlGetWarningsDefaultValue = 0;
     if (t != NULL) {
         fclose(t);
        ret = compareFiles(temp, result);
@@ -3072,7 +3065,6 @@ static int
 schemasOneTest(const char *sch,
                const char *filename,
                const char *result,
-              const char *err,
               int options,
               xmlSchemaPtr schemas) {
     xmlDocPtr doc;
@@ -3124,13 +3116,6 @@ schemasOneTest(const char *sch,
         free(temp);
     }
 
-    if ((validResult != 0) && (err != NULL)) {
-       if (compareFileMem(err, testErrors, testErrorsSize)) {
-           fprintf(stderr, "Error for %s on %s failed\n", filename, sch);
-           ret = 1;
-       }
-    }
-
     xmlSchemaFreeValidCtxt(ctxt);
     xmlFreeDoc(doc);
     return(ret);
@@ -3157,6 +3142,7 @@ schemasTest(const char *filename,
     xmlSchemaParserCtxtPtr ctxt;
     xmlSchemaPtr schemas;
     int res = 0, len, ret;
+    int parseErrorsSize;
     char pattern[500];
     char prefix[500];
     char result[500];
@@ -3170,6 +3156,7 @@ schemasTest(const char *filename,
     xmlSchemaSetParserErrors(ctxt, testErrorHandler, testErrorHandler, ctxt);
     schemas = xmlSchemaParse(ctxt);
     xmlSchemaFreeParserCtxt(ctxt);
+    parseErrorsSize = testErrorsSize;
 
     /*
      * most of the mess is about the output filenames generated by the Makefile
@@ -3189,7 +3176,7 @@ schemasTest(const char *filename,
     memcpy(prefix, base, len);
     prefix[len] = 0;
 
-    if (snprintf(pattern, 499, "./test/schemas/%s_?.xml", prefix) >= 499)
+    if (snprintf(pattern, 499, "./test/schemas/%s_*.xml", prefix) >= 499)
         pattern[499] = 0;
 
     if (base[len] == '_') {
@@ -3201,8 +3188,8 @@ schemasTest(const char *filename,
     globbuf.gl_offs = 0;
     glob(pattern, GLOB_DOOFFS, NULL, &globbuf);
     for (i = 0;i < globbuf.gl_pathc;i++) {
-        testErrorsSize = 0;
-       testErrors[0] = 0;
+        testErrorsSize = parseErrorsSize;
+        testErrors[parseErrorsSize] = 0;
         instance = globbuf.gl_pathv[i];
        base2 = baseFilename(instance);
        len = strlen(base2);
@@ -3220,14 +3207,17 @@ schemasTest(const char *filename,
            fprintf(stderr, "don't know how to process %s\n", instance);
            continue;
        }
-       if (schemas == NULL) {
-       } else {
+       if (schemas != NULL) {
            nb_tests++;
-           ret = schemasOneTest(filename, instance, result, err,
-                                options, schemas);
+           ret = schemasOneTest(filename, instance, result, options, schemas);
            if (ret != 0)
                res = ret;
        }
+        if (compareFileMem(err, testErrors, testErrorsSize)) {
+            fprintf(stderr, "Error for %s on %s failed\n", instance,
+                    filename);
+            res = 1;
+        }
     }
     globfree(&globbuf);
     xmlSchemaFree(schemas);
@@ -3244,7 +3234,6 @@ static int
 rngOneTest(const char *sch,
                const char *filename,
                const char *result,
-              const char *err,
               int options,
               xmlRelaxNGPtr schemas) {
     xmlDocPtr doc;
@@ -3296,15 +3285,6 @@ rngOneTest(const char *sch,
         free(temp);
     }
 
-    if (err != NULL) {
-       if (compareFileMem(err, testErrors, testErrorsSize)) {
-           fprintf(stderr, "Error for %s on %s failed\n", filename, sch);
-           ret = 1;
-           printf("%s", testErrors);
-       }
-    }
-
-
     xmlRelaxNGFreeValidCtxt(ctxt);
     xmlFreeDoc(doc);
     return(ret);
@@ -3330,6 +3310,7 @@ rngTest(const char *filename,
     xmlRelaxNGParserCtxtPtr ctxt;
     xmlRelaxNGPtr schemas;
     int res = 0, len, ret = 0;
+    int parseErrorsSize;
     char pattern[500];
     char prefix[500];
     char result[500];
@@ -3343,6 +3324,10 @@ rngTest(const char *filename,
     xmlRelaxNGSetParserErrors(ctxt, testErrorHandler, testErrorHandler, ctxt);
     schemas = xmlRelaxNGParse(ctxt);
     xmlRelaxNGFreeParserCtxt(ctxt);
+    if (schemas == NULL)
+        testErrorHandler(NULL, "Relax-NG schema %s failed to compile\n",
+                         filename);
+    parseErrorsSize = testErrorsSize;
 
     /*
      * most of the mess is about the output filenames generated by the Makefile
@@ -3362,8 +3347,8 @@ rngTest(const char *filename,
     globbuf.gl_offs = 0;
     glob(pattern, GLOB_DOOFFS, NULL, &globbuf);
     for (i = 0;i < globbuf.gl_pathc;i++) {
-        testErrorsSize = 0;
-       testErrors[0] = 0;
+        testErrorsSize = parseErrorsSize;
+        testErrors[parseErrorsSize] = 0;
         instance = globbuf.gl_pathv[i];
        base2 = baseFilename(instance);
        len = strlen(base2);
@@ -3381,14 +3366,17 @@ rngTest(const char *filename,
            fprintf(stderr, "don't know how to process %s\n", instance);
            continue;
        }
-       if (schemas == NULL) {
-       } else {
+       if (schemas != NULL) {
            nb_tests++;
-           res = rngOneTest(filename, instance, result, err,
-                                options, schemas);
+           res = rngOneTest(filename, instance, result, options, schemas);
            if (res != 0)
                ret = res;
        }
+        if (compareFileMem(err, testErrors, testErrorsSize)) {
+            fprintf(stderr, "Error for %s on %s failed\n", instance,
+                    filename);
+            res = 1;
+        }
     }
     globfree(&globbuf);
     xmlRelaxNGFree(schemas);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]