mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-24 21:33:51 +03:00
tests: Test streaming schema validation
This commit is contained in:
parent
d88763ccad
commit
4f49017e37
108
runtest.c
108
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);
|
||||
|
Loading…
Reference in New Issue
Block a user