summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2023-04-30 21:26:55 +0200
committerNick Wellnhofer <wellnhofer@aevum.de>2023-04-30 21:45:39 +0200
commit4f49017e37c489397ebc6995fab0fe56a339bd9f (patch)
treec516b9566ea73c638cd9cf07e57db7cdcfc40780
parentd88763ccadc32bb004b0fbd3f618ba0fff7eb3f1 (diff)
downloadlibxml2-4f49017e37c489397ebc6995fab0fe56a339bd9f.tar.gz
tests: Test streaming schema validation
-rw-r--r--runtest.c108
1 files changed, 63 insertions, 45 deletions
diff --git a/runtest.c b/runtest.c
index ecac702a..d1eced93 100644
--- a/runtest.c
+++ b/runtest.c
@@ -3400,59 +3400,81 @@ static int
schemasOneTest(const char *sch,
const char *filename,
const char *result,
+ const char *err,
int options,
xmlSchemaPtr schemas) {
- xmlDocPtr doc;
- xmlSchemaValidCtxtPtr ctxt;
int ret = 0;
- int validResult = 0;
+ int i;
char *temp;
- FILE *schemasOutput;
-
- doc = xmlReadFile(filename, NULL, options);
- if (doc == NULL) {
- fprintf(stderr, "failed to parse instance %s for %s\n", filename, sch);
- return(-1);
- }
+ int parseErrorsSize = testErrorsSize;
temp = resultFilename(result, temp_directory, ".res");
if (temp == NULL) {
fprintf(stderr, "Out of memory\n");
fatalError();
- }
- schemasOutput = fopen(temp, "wb");
- if (schemasOutput == NULL) {
- fprintf(stderr, "failed to open output file %s\n", temp);
- xmlFreeDoc(doc);
- free(temp);
- return(-1);
+ return(-1);
}
- ctxt = xmlSchemaNewValidCtxt(schemas);
- xmlSchemaSetValidErrors(ctxt, testErrorHandler, testErrorHandler, ctxt);
- validResult = xmlSchemaValidateDoc(ctxt, doc);
- if (validResult == 0) {
- fprintf(schemasOutput, "%s validates\n", filename);
- } else if (validResult > 0) {
- fprintf(schemasOutput, "%s fails to validate\n", filename);
- } else {
- fprintf(schemasOutput, "%s validation generated an internal error\n",
- filename);
- }
- fclose(schemasOutput);
- if (result) {
- if (compareFiles(temp, result)) {
- fprintf(stderr, "Result for %s on %s failed\n", filename, sch);
- ret = 1;
- }
- }
- if (temp != NULL) {
+ /*
+ * Test both memory and streaming validation.
+ */
+ for (i = 0; i < 2; i++) {
+ xmlSchemaValidCtxtPtr ctxt;
+ int validResult = 0;
+ FILE *schemasOutput;
+
+ testErrorsSize = parseErrorsSize;
+ testErrors[parseErrorsSize] = 0;
+
+ ctxt = xmlSchemaNewValidCtxt(schemas);
+ xmlSchemaSetValidErrors(ctxt, testErrorHandler, testErrorHandler, ctxt);
+
+ schemasOutput = fopen(temp, "wb");
+ if (schemasOutput == NULL) {
+ fprintf(stderr, "failed to open output file %s\n", temp);
+ free(temp);
+ return(-1);
+ }
+
+ if (i == 0) {
+ xmlDocPtr doc;
+
+ doc = xmlReadFile(filename, NULL, options);
+ if (doc == NULL) {
+ fprintf(stderr, "failed to parse instance %s for %s\n", filename, sch);
+ return(-1);
+ }
+ validResult = xmlSchemaValidateDoc(ctxt, doc);
+ xmlFreeDoc(doc);
+ } else {
+ validResult = xmlSchemaValidateFile(ctxt, filename, options);
+ }
+
+ if (validResult == 0) {
+ fprintf(schemasOutput, "%s validates\n", filename);
+ } else if (validResult > 0) {
+ fprintf(schemasOutput, "%s fails to validate\n", filename);
+ } else {
+ fprintf(schemasOutput, "%s validation generated an internal error\n",
+ filename);
+ }
+ fclose(schemasOutput);
+ if (result) {
+ if (compareFiles(temp, result)) {
+ fprintf(stderr, "Result for %s on %s failed\n", filename, sch);
+ ret = 1;
+ }
+ }
+ if (compareFileMem(err, testErrors, testErrorsSize)) {
+ fprintf(stderr, "Error for %s on %s failed\n", filename, sch);
+ ret = 1;
+ }
+
unlink(temp);
- free(temp);
+ xmlSchemaFreeValidCtxt(ctxt);
}
- xmlSchemaFreeValidCtxt(ctxt);
- xmlFreeDoc(doc);
+ free(temp);
return(ret);
}
/**
@@ -3544,15 +3566,11 @@ schemasTest(const char *filename,
}
if (schemas != NULL) {
nb_tests++;
- ret = schemasOneTest(filename, instance, result, options, schemas);
+ ret = schemasOneTest(filename, instance, result, err,
+ 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);