Commit de0e498b authored by Daniel Veillard's avatar Daniel Veillard

expanded test found and fixed the leak exposed by Microsoft regtests

* runsuite.c: expanded test
* xmlregexp.c: found and fixed the leak exposed by Microsoft regtests
Daniel
parent 3fe1e8a1
Sun Jul 3 16:34:47 CEST 2005 Daniel Veillard <daniel@veillard.com>
* runsuite.c: expanded test
* xmlregexp.c: found and fixed the leak exposed by Microsoft regtests
Sat Jul 2 23:38:24 CEST 2005 Daniel Veillard <daniel@veillard.com> Sat Jul 2 23:38:24 CEST 2005 Daniel Veillard <daniel@veillard.com>
* runsuite.c: a bit of progresses on xstc * runsuite.c: a bit of progresses on xstc
......
...@@ -254,7 +254,7 @@ getString(xmlNodePtr cur, const char *xpath) { ...@@ -254,7 +254,7 @@ getString(xmlNodePtr cur, const char *xpath) {
************************************************************************/ ************************************************************************/
static int static int
xsdIncorectTestCase(xmlNodePtr cur) { xsdIncorectTestCase(int verbose, xmlNodePtr cur) {
xmlNodePtr test; xmlNodePtr test;
xmlBufferPtr buf; xmlBufferPtr buf;
xmlRelaxNGParserCtxtPtr pctxt; xmlRelaxNGParserCtxtPtr pctxt;
...@@ -292,8 +292,10 @@ xsdIncorectTestCase(xmlNodePtr cur) { ...@@ -292,8 +292,10 @@ xsdIncorectTestCase(xmlNodePtr cur) {
rng = xmlRelaxNGParse(pctxt); rng = xmlRelaxNGParse(pctxt);
xmlRelaxNGFreeParserCtxt(pctxt); xmlRelaxNGFreeParserCtxt(pctxt);
if (rng != NULL) { if (rng != NULL) {
fprintf(stderr, "Failed to detect incorect RNG line %ld\n", if (verbose) {
xmlGetLineNo(test)); fprintf(stderr, "Failed to detect incorect RNG line %ld\n",
xmlGetLineNo(test));
}
ret = 1; ret = 1;
goto done; goto done;
} }
...@@ -373,7 +375,7 @@ installDirs(xmlNodePtr tst, const xmlChar *base) { ...@@ -373,7 +375,7 @@ installDirs(xmlNodePtr tst, const xmlChar *base) {
} }
static int static int
xsdTestCase(xmlNodePtr tst) { xsdTestCase(int verbose, xmlNodePtr tst) {
xmlNodePtr test, tmp, cur; xmlNodePtr test, tmp, cur;
xmlBufferPtr buf; xmlBufferPtr buf;
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
...@@ -396,7 +398,7 @@ xsdTestCase(xmlNodePtr tst) { ...@@ -396,7 +398,7 @@ xsdTestCase(xmlNodePtr tst) {
cur = getNext(tst, "./correct[1]"); cur = getNext(tst, "./correct[1]");
if (cur == NULL) { if (cur == NULL) {
return(xsdIncorectTestCase(tst)); return(xsdIncorectTestCase(verbose, tst));
} }
test = getNext(cur, "./*"); test = getNext(cur, "./*");
...@@ -473,9 +475,11 @@ xsdTestCase(xmlNodePtr tst) { ...@@ -473,9 +475,11 @@ xsdTestCase(xmlNodePtr tst) {
ret = xmlRelaxNGValidateDoc(ctxt, doc); ret = xmlRelaxNGValidateDoc(ctxt, doc);
xmlRelaxNGFreeValidCtxt(ctxt); xmlRelaxNGFreeValidCtxt(ctxt);
if (ret > 0) { if (ret > 0) {
fprintf(stderr, if (verbose) {
"Failed to validate valid instance line %ld\n", fprintf(stderr,
xmlGetLineNo(tmp)); "Failed to validate valid instance line %ld\n",
xmlGetLineNo(tmp));
}
nb_errors++; nb_errors++;
} else if (ret < 0) { } else if (ret < 0) {
fprintf(stderr, fprintf(stderr,
...@@ -533,9 +537,11 @@ xsdTestCase(xmlNodePtr tst) { ...@@ -533,9 +537,11 @@ xsdTestCase(xmlNodePtr tst) {
ret = xmlRelaxNGValidateDoc(ctxt, doc); ret = xmlRelaxNGValidateDoc(ctxt, doc);
xmlRelaxNGFreeValidCtxt(ctxt); xmlRelaxNGFreeValidCtxt(ctxt);
if (ret == 0) { if (ret == 0) {
fprintf(stderr, if (verbose) {
"Failed to detect invalid instance line %ld\n", fprintf(stderr,
xmlGetLineNo(tmp)); "Failed to detect invalid instance line %ld\n",
xmlGetLineNo(tmp));
}
nb_errors++; nb_errors++;
} else if (ret < 0) { } else if (ret < 0) {
fprintf(stderr, fprintf(stderr,
...@@ -582,7 +588,7 @@ xsdTestSuite(int verbose, xmlNodePtr cur) { ...@@ -582,7 +588,7 @@ xsdTestSuite(int verbose, xmlNodePtr cur) {
} }
cur = getNext(cur, "./testCase[1]"); cur = getNext(cur, "./testCase[1]");
while (cur != NULL) { while (cur != NULL) {
xsdTestCase(cur); xsdTestCase(verbose, cur);
cur = getNext(cur, "following-sibling::testCase[1]"); cur = getNext(cur, "following-sibling::testCase[1]");
} }
...@@ -735,13 +741,19 @@ done: ...@@ -735,13 +741,19 @@ done:
************************************************************************/ ************************************************************************/
static int static int
xstcTestInstance(int verbose, xmlNodePtr cur, xmlSchemaPtr schemas) { xstcTestInstance(int verbose, xmlNodePtr cur, xmlSchemaPtr schemas,
const xmlChar *spath, const xmlChar *base) {
xmlChar *href = NULL; xmlChar *href = NULL;
xmlChar *path = NULL; xmlChar *path = NULL;
int ret = 0; xmlChar *validity = NULL;
xmlSchemaValidCtxtPtr ctxt = NULL;
xmlDocPtr doc = NULL;
int ret = 0, mem;
xmlResetLastError();
mem = xmlMemUsed();
href = getString(cur, href = getString(cur,
"string(ts:schemaTest/ts:schemaDocument/@xlink:href)"); "string(ts:instanceDocument/@xlink:href)");
if ((href == NULL) || (href[0] == 0)) { if ((href == NULL) || (href[0] == 0)) {
if (verbose) if (verbose)
fprintf(stderr, fprintf(stderr,
...@@ -750,7 +762,7 @@ xstcTestInstance(int verbose, xmlNodePtr cur, xmlSchemaPtr schemas) { ...@@ -750,7 +762,7 @@ xstcTestInstance(int verbose, xmlNodePtr cur, xmlSchemaPtr schemas) {
ret = -1; ret = -1;
goto done; goto done;
} }
path = xmlBuildURI(href, BAD_CAST "./xstc/Tests/"); path = xmlBuildURI(href, BAD_CAST base);
if (path == NULL) { if (path == NULL) {
fprintf(stderr, fprintf(stderr,
"Failed to build path to schemas testGroup line %ld : %s\n", "Failed to build path to schemas testGroup line %ld : %s\n",
...@@ -758,30 +770,88 @@ xstcTestInstance(int verbose, xmlNodePtr cur, xmlSchemaPtr schemas) { ...@@ -758,30 +770,88 @@ xstcTestInstance(int verbose, xmlNodePtr cur, xmlSchemaPtr schemas) {
ret = -1; ret = -1;
goto done; goto done;
} }
if (checkTestFile(path) <= 0) { if (checkTestFile((const char *) path) <= 0) {
fprintf(stderr, fprintf(stderr,
"schemas for testGroup line %ld is missing: %s\n", "schemas for testGroup line %ld is missing: %s\n",
xmlGetLineNo(cur), path); xmlGetLineNo(cur), path);
ret = -1; ret = -1;
goto done; goto done;
} }
validity = getString(cur,
"string(ts:expected/@validity)");
if (validity == NULL) {
fprintf(stderr, "instanceDocument line %ld misses expected validity\n",
xmlGetLineNo(cur));
ret = -1;
goto done;
}
nb_tests++; nb_tests++;
doc = xmlReadFile((const char *) path, NULL, XML_PARSE_NOENT);
if (doc == NULL) {
fprintf(stderr, "instance %s fails to parse\n", path);
ret = -1;
nb_errors++;
goto done;
}
ctxt = xmlSchemaNewValidCtxt(schemas);
xmlSchemaSetValidErrors(ctxt,
(xmlSchemaValidityErrorFunc) testErrorHandler,
(xmlSchemaValidityWarningFunc) testErrorHandler,
ctxt);
ret = xmlSchemaValidateDoc(ctxt, doc);
if (xmlStrEqual(validity, BAD_CAST "valid")) {
if (ret != 0) {
if (verbose)
fprintf(stderr,
"valid instance %s failed to validate against %s\n",
path, spath);
nb_errors++;
}
} else if (xmlStrEqual(validity, BAD_CAST "invalid")) {
if (ret == 0) {
if (verbose)
fprintf(stderr,
"Failed to detect invalid instance %s against %s\n",
path, spath);
nb_errors++;
}
} else {
fprintf(stderr,
"instanceDocument line %ld has unexpected validity value%s\n",
xmlGetLineNo(cur), validity);
ret = -1;
goto done;
}
done: done:
if (href != NULL) xmlFree(href); if (href != NULL) xmlFree(href);
if (path != NULL) xmlFree(path); if (path != NULL) xmlFree(path);
if (validity != NULL) xmlFree(validity);
if (ctxt != NULL) xmlSchemaFreeValidCtxt(ctxt);
if (doc != NULL) xmlFreeDoc(doc);
xmlResetLastError();
if (mem != xmlMemUsed()) {
fprintf(stderr, "Validation of tests starting line %ld leaked %d\n",
xmlGetLineNo(cur), xmlMemUsed() - mem);
nb_leaks++;
}
return(ret); return(ret);
} }
static int static int
xstcTestGroup(int verbose, xmlNodePtr cur) { xstcTestGroup(int verbose, xmlNodePtr cur, const char *base) {
xmlChar *href = NULL; xmlChar *href = NULL;
xmlChar *path = NULL; xmlChar *path = NULL;
xmlChar *validity = NULL; xmlChar *validity = NULL;
xmlSchemaPtr schemas = NULL; xmlSchemaPtr schemas = NULL;
xmlSchemaParserCtxtPtr ctxt; xmlSchemaParserCtxtPtr ctxt;
xmlNodePtr instance; xmlNodePtr instance;
int ret = 0; int ret = 0, mem;
xmlResetLastError();
mem = xmlMemUsed();
href = getString(cur, href = getString(cur,
"string(ts:schemaTest/ts:schemaDocument/@xlink:href)"); "string(ts:schemaTest/ts:schemaDocument/@xlink:href)");
if ((href == NULL) || (href[0] == 0)) { if ((href == NULL) || (href[0] == 0)) {
...@@ -792,7 +862,7 @@ xstcTestGroup(int verbose, xmlNodePtr cur) { ...@@ -792,7 +862,7 @@ xstcTestGroup(int verbose, xmlNodePtr cur) {
ret = -1; ret = -1;
goto done; goto done;
} }
path = xmlBuildURI(href, BAD_CAST "./xstc/Tests/"); path = xmlBuildURI(href, BAD_CAST base);
if (path == NULL) { if (path == NULL) {
fprintf(stderr, fprintf(stderr,
"Failed to build path to schemas testGroup line %ld : %s\n", "Failed to build path to schemas testGroup line %ld : %s\n",
...@@ -800,7 +870,7 @@ xstcTestGroup(int verbose, xmlNodePtr cur) { ...@@ -800,7 +870,7 @@ xstcTestGroup(int verbose, xmlNodePtr cur) {
ret = -1; ret = -1;
goto done; goto done;
} }
if (checkTestFile(path) <= 0) { if (checkTestFile((const char *) path) <= 0) {
fprintf(stderr, fprintf(stderr,
"schemas for testGroup line %ld is missing: %s\n", "schemas for testGroup line %ld is missing: %s\n",
xmlGetLineNo(cur), path); xmlGetLineNo(cur), path);
...@@ -816,7 +886,7 @@ xstcTestGroup(int verbose, xmlNodePtr cur) { ...@@ -816,7 +886,7 @@ xstcTestGroup(int verbose, xmlNodePtr cur) {
goto done; goto done;
} }
if (xmlStrEqual(validity, BAD_CAST "valid")) { if (xmlStrEqual(validity, BAD_CAST "valid")) {
ctxt = xmlSchemaNewParserCtxt(path); ctxt = xmlSchemaNewParserCtxt((const char *) path);
xmlSchemaSetParserErrors(ctxt, xmlSchemaSetParserErrors(ctxt,
(xmlSchemaValidityErrorFunc) testErrorHandler, (xmlSchemaValidityErrorFunc) testErrorHandler,
(xmlSchemaValidityWarningFunc) testErrorHandler, (xmlSchemaValidityWarningFunc) testErrorHandler,
...@@ -834,12 +904,12 @@ xstcTestGroup(int verbose, xmlNodePtr cur) { ...@@ -834,12 +904,12 @@ xstcTestGroup(int verbose, xmlNodePtr cur) {
nb_tests++; nb_tests++;
} }
while (instance != NULL) { while (instance != NULL) {
xstcTestInstance(verbose, instance, schemas); xstcTestInstance(verbose, instance, schemas, path, base);
instance = getNext(instance, instance = getNext(instance,
"following-sibling::ts:instanceTest[1]"); "following-sibling::ts:instanceTest[1]");
} }
} else if (xmlStrEqual(validity, BAD_CAST "invalid")) { } else if (xmlStrEqual(validity, BAD_CAST "invalid")) {
ctxt = xmlSchemaNewParserCtxt(path); ctxt = xmlSchemaNewParserCtxt((const char *) path);
xmlSchemaSetParserErrors(ctxt, xmlSchemaSetParserErrors(ctxt,
(xmlSchemaValidityErrorFunc) testErrorHandler, (xmlSchemaValidityErrorFunc) testErrorHandler,
(xmlSchemaValidityWarningFunc) testErrorHandler, (xmlSchemaValidityWarningFunc) testErrorHandler,
...@@ -866,11 +936,17 @@ done: ...@@ -866,11 +936,17 @@ done:
if (path != NULL) xmlFree(path); if (path != NULL) xmlFree(path);
if (validity != NULL) xmlFree(validity); if (validity != NULL) xmlFree(validity);
if (schemas != NULL) xmlSchemaFree(schemas); if (schemas != NULL) xmlSchemaFree(schemas);
xmlResetLastError();
if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
fprintf(stderr, "Processing test line %ld leaked %d\n",
xmlGetLineNo(cur), xmlMemUsed() - mem);
nb_leaks++;
}
return(ret); return(ret);
} }
static int static int
xstcMetadata(int verbose, const char *metadata) { xstcMetadata(int verbose, const char *metadata, const char *base) {
xmlDocPtr doc; xmlDocPtr doc;
xmlNodePtr cur; xmlNodePtr cur;
xmlChar *contributor; xmlChar *contributor;
...@@ -907,7 +983,7 @@ xstcMetadata(int verbose, const char *metadata) { ...@@ -907,7 +983,7 @@ xstcMetadata(int verbose, const char *metadata) {
goto done; goto done;
} }
while (cur != NULL) { while (cur != NULL) {
xstcTestGroup(verbose, cur); xstcTestGroup(verbose, cur, base);
cur = getNext(cur, "following-sibling::ts:testGroup[1]"); cur = getNext(cur, "following-sibling::ts:testGroup[1]");
} }
...@@ -916,15 +992,6 @@ done: ...@@ -916,15 +992,6 @@ done:
return(ret); return(ret);
} }
static int
xstcTests(int verbose) {
int ret;
ret = xstcMetadata(verbose,
"xstc/Tests/Metadata/MSXMLSchema1-0-20020116.testSet");
return(ret);
}
/************************************************************************ /************************************************************************
* * * *
* The driver for the tests * * The driver for the tests *
...@@ -979,7 +1046,35 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { ...@@ -979,7 +1046,35 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
old_errors = nb_errors; old_errors = nb_errors;
old_tests = nb_tests; old_tests = nb_tests;
old_leaks = nb_leaks; old_leaks = nb_leaks;
res = xstcTests(verbose); res = xstcMetadata(verbose,
"xstc/Tests/Metadata/NISTXMLSchemaDatatypes.testSet",
"xstc/Tests/Metadata/");
if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
printf("Ran %d tests, no errors\n", nb_tests - old_tests);
else
printf("Ran %d tests, %d errors, %d leaks\n",
nb_tests - old_tests,
nb_errors - old_errors,
nb_leaks - old_leaks);
old_errors = nb_errors;
old_tests = nb_tests;
old_leaks = nb_leaks;
res = xstcMetadata(verbose,
"xstc/Tests/Metadata/SunXMLSchema1-0-20020116.testSet",
"xstc/");
if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
printf("Ran %d tests, no errors\n", nb_tests - old_tests);
else
printf("Ran %d tests, %d errors, %d leaks\n",
nb_tests - old_tests,
nb_errors - old_errors,
nb_leaks - old_leaks);
old_errors = nb_errors;
old_tests = nb_tests;
old_leaks = nb_leaks;
res = xstcMetadata(verbose,
"xstc/Tests/Metadata/MSXMLSchema1-0-20020116.testSet",
"xstc/Tests/");
if ((nb_errors == old_errors) && (nb_leaks == old_leaks)) if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
printf("Ran %d tests, no errors\n", nb_tests - old_tests); printf("Ran %d tests, no errors\n", nb_tests - old_tests);
else else
......
...@@ -749,7 +749,9 @@ xmlRegFreeAtom(xmlRegAtomPtr atom) { ...@@ -749,7 +749,9 @@ xmlRegFreeAtom(xmlRegAtomPtr atom) {
xmlRegFreeRange(atom->ranges[i]); xmlRegFreeRange(atom->ranges[i]);
if (atom->ranges != NULL) if (atom->ranges != NULL)
xmlFree(atom->ranges); xmlFree(atom->ranges);
if (atom->type == XML_REGEXP_STRING) if ((atom->type == XML_REGEXP_STRING) && (atom->valuep != NULL))
xmlFree(atom->valuep);
if ((atom->type == XML_REGEXP_BLOCK_NAME) && (atom->valuep != NULL))
xmlFree(atom->valuep); xmlFree(atom->valuep);
xmlFree(atom); xmlFree(atom);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment