📄 runsuite.c
字号:
xmlChar *name, *res;
name = getString(tst, "string(@name)");
if (name == NULL)
return;
res = composeDir(base, name);
xmlFree(name);
if (res == NULL) {
return;
}
/* Now process resources and subdir recursively */
test = getNext(tst, "./resource[1]");
if (test != NULL) {
installResources(test, res);
}
test = getNext(tst, "./dir[1]");
while (test != NULL) {
installDirs(test, res);
test = getNext(test, "following-sibling::dir[1]");
}
xmlFree(res);
}
static int
xsdTestCase(xmlNodePtr tst) {
xmlNodePtr test, tmp, cur;
xmlBufferPtr buf;
xmlDocPtr doc = NULL;
xmlRelaxNGParserCtxtPtr pctxt;
xmlRelaxNGValidCtxtPtr ctxt;
xmlRelaxNGPtr rng = NULL;
int ret = 0, mem, memt;
xmlChar *dtd;
resetEntities();
testErrorsSize = 0; testErrors[0] = 0;
tmp = getNext(tst, "./dir[1]");
if (tmp != NULL) {
installDirs(tmp, NULL);
}
tmp = getNext(tst, "./resource[1]");
if (tmp != NULL) {
installResources(tmp, NULL);
}
cur = getNext(tst, "./correct[1]");
if (cur == NULL) {
return(xsdIncorectTestCase(tst));
}
test = getNext(cur, "./*");
if (test == NULL) {
fprintf(stderr, "Failed to find test in correct line %ld\n",
xmlGetLineNo(cur));
return(1);
}
memt = xmlMemUsed();
extraMemoryFromResolver = 0;
/*
* dump the schemas to a buffer, then reparse it and compile the schemas
*/
buf = xmlBufferCreate();
if (buf == NULL) {
fprintf(stderr, "out of memory !\n");
fatalError();
}
xmlNodeDump(buf, test->doc, test, 0, 0);
pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use);
xmlRelaxNGSetParserErrors(pctxt,
(xmlRelaxNGValidityErrorFunc) testErrorHandler,
(xmlRelaxNGValidityWarningFunc) testErrorHandler,
pctxt);
rng = xmlRelaxNGParse(pctxt);
xmlRelaxNGFreeParserCtxt(pctxt);
if (extraMemoryFromResolver)
memt = 0;
if (rng == NULL) {
test_log("Failed to parse RNGtest line %ld\n",
xmlGetLineNo(test));
nb_errors++;
ret = 1;
goto done;
}
/*
* now scan all the siblings of correct to process the <valid> tests
*/
tmp = getNext(cur, "following-sibling::valid[1]");
while (tmp != NULL) {
dtd = xmlGetProp(tmp, BAD_CAST "dtd");
test = getNext(tmp, "./*");
if (test == NULL) {
fprintf(stderr, "Failed to find test in <valid> line %ld\n",
xmlGetLineNo(tmp));
} else {
xmlBufferEmpty(buf);
if (dtd != NULL)
xmlBufferAdd(buf, dtd, -1);
xmlNodeDump(buf, test->doc, test, 0, 0);
/*
* We are ready to run the test
*/
mem = xmlMemUsed();
extraMemoryFromResolver = 0;
doc = xmlReadMemory((const char *)buf->content, buf->use,
"test", NULL, 0);
if (doc == NULL) {
test_log("Failed to parse valid instance line %ld\n",
xmlGetLineNo(tmp));
nb_errors++;
} else {
nb_tests++;
ctxt = xmlRelaxNGNewValidCtxt(rng);
xmlRelaxNGSetValidErrors(ctxt,
(xmlRelaxNGValidityErrorFunc) testErrorHandler,
(xmlRelaxNGValidityWarningFunc) testErrorHandler,
ctxt);
ret = xmlRelaxNGValidateDoc(ctxt, doc);
xmlRelaxNGFreeValidCtxt(ctxt);
if (ret > 0) {
test_log("Failed to validate valid instance line %ld\n",
xmlGetLineNo(tmp));
nb_errors++;
} else if (ret < 0) {
test_log("Internal error validating instance line %ld\n",
xmlGetLineNo(tmp));
nb_errors++;
}
xmlFreeDoc(doc);
}
xmlResetLastError();
if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
test_log("Validation of instance line %ld leaked %d\n",
xmlGetLineNo(tmp), xmlMemUsed() - mem);
xmlMemoryDump();
nb_leaks++;
}
}
if (dtd != NULL)
xmlFree(dtd);
tmp = getNext(tmp, "following-sibling::valid[1]");
}
/*
* now scan all the siblings of correct to process the <invalid> tests
*/
tmp = getNext(cur, "following-sibling::invalid[1]");
while (tmp != NULL) {
test = getNext(tmp, "./*");
if (test == NULL) {
fprintf(stderr, "Failed to find test in <invalid> line %ld\n",
xmlGetLineNo(tmp));
} else {
xmlBufferEmpty(buf);
xmlNodeDump(buf, test->doc, test, 0, 0);
/*
* We are ready to run the test
*/
mem = xmlMemUsed();
extraMemoryFromResolver = 0;
doc = xmlReadMemory((const char *)buf->content, buf->use,
"test", NULL, 0);
if (doc == NULL) {
test_log("Failed to parse valid instance line %ld\n",
xmlGetLineNo(tmp));
nb_errors++;
} else {
nb_tests++;
ctxt = xmlRelaxNGNewValidCtxt(rng);
xmlRelaxNGSetValidErrors(ctxt,
(xmlRelaxNGValidityErrorFunc) testErrorHandler,
(xmlRelaxNGValidityWarningFunc) testErrorHandler,
ctxt);
ret = xmlRelaxNGValidateDoc(ctxt, doc);
xmlRelaxNGFreeValidCtxt(ctxt);
if (ret == 0) {
test_log("Failed to detect invalid instance line %ld\n",
xmlGetLineNo(tmp));
nb_errors++;
} else if (ret < 0) {
test_log("Internal error validating instance line %ld\n",
xmlGetLineNo(tmp));
nb_errors++;
}
xmlFreeDoc(doc);
}
xmlResetLastError();
if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
test_log("Validation of instance line %ld leaked %d\n",
xmlGetLineNo(tmp), xmlMemUsed() - mem);
xmlMemoryDump();
nb_leaks++;
}
}
tmp = getNext(tmp, "following-sibling::invalid[1]");
}
done:
if (buf != NULL)
xmlBufferFree(buf);
if (rng != NULL)
xmlRelaxNGFree(rng);
xmlResetLastError();
if ((memt != xmlMemUsed()) && (memt != 0)) {
test_log("Validation of tests starting line %ld leaked %d\n",
xmlGetLineNo(cur), xmlMemUsed() - memt);
nb_leaks++;
}
return(ret);
}
static int
xsdTestSuite(xmlNodePtr cur) {
if (verbose) {
xmlChar *doc = getString(cur, "string(documentation)");
if (doc != NULL) {
printf("Suite %s\n", doc);
xmlFree(doc);
}
}
cur = getNext(cur, "./testCase[1]");
while (cur != NULL) {
xsdTestCase(cur);
cur = getNext(cur, "following-sibling::testCase[1]");
}
return(0);
}
static int
xsdTest(void) {
xmlDocPtr doc;
xmlNodePtr cur;
const char *filename = "test/xsdtest/xsdtestsuite.xml";
int ret = 0;
doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
return(-1);
}
printf("## XML Schemas datatypes test suite from James Clark\n");
cur = xmlDocGetRootElement(doc);
if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
fprintf(stderr, "Unexpected format %s\n", filename);
ret = -1;
goto done;
}
cur = getNext(cur, "./testSuite[1]");
if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
fprintf(stderr, "Unexpected format %s\n", filename);
ret = -1;
goto done;
}
while (cur != NULL) {
xsdTestSuite(cur);
cur = getNext(cur, "following-sibling::testSuite[1]");
}
done:
if (doc != NULL)
xmlFreeDoc(doc);
return(ret);
}
static int
rngTestSuite(xmlNodePtr cur) {
if (verbose) {
xmlChar *doc = getString(cur, "string(documentation)");
if (doc != NULL) {
printf("Suite %s\n", doc);
xmlFree(doc);
} else {
doc = getString(cur, "string(section)");
if (doc != NULL) {
printf("Section %s\n", doc);
xmlFree(doc);
}
}
}
cur = getNext(cur, "./testSuite[1]");
while (cur != NULL) {
xsdTestSuite(cur);
cur = getNext(cur, "following-sibling::testSuite[1]");
}
return(0);
}
static int
rngTest1(void) {
xmlDocPtr doc;
xmlNodePtr cur;
const char *filename = "test/relaxng/OASIS/spectest.xml";
int ret = 0;
doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
return(-1);
}
printf("## Relax NG test suite from James Clark\n");
cur = xmlDocGetRootElement(doc);
if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
fprintf(stderr, "Unexpected format %s\n", filename);
ret = -1;
goto done;
}
cur = getNext(cur, "./testSuite[1]");
if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
fprintf(stderr, "Unexpected format %s\n", filename);
ret = -1;
goto done;
}
while (cur != NULL) {
rngTestSuite(cur);
cur = getNext(cur, "following-sibling::testSuite[1]");
}
done:
if (doc != NULL)
xmlFreeDoc(doc);
return(ret);
}
static int
rngTest2(void) {
xmlDocPtr doc;
xmlNodePtr cur;
const char *filename = "test/relaxng/testsuite.xml";
int ret = 0;
doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
return(-1);
}
printf("## Relax NG test suite for libxml2\n");
cur = xmlDocGetRootElement(doc);
if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
fprintf(stderr, "Unexpected format %s\n", filename);
ret = -1;
goto done;
}
cur = getNext(cur, "./testSuite[1]");
if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
fprintf(stderr, "Unexpected format %s\n", filename);
ret = -1;
goto done;
}
while (cur != NULL) {
xsdTestSuite(cur);
cur = getNext(cur, "following-sibling::testSuite[1]");
}
done:
if (doc != NULL)
xmlFreeDoc(doc);
return(ret);
}
/************************************************************************
* *
* Schemas test suites from W3C/NIST/MS/Sun *
* *
************************************************************************/
static int
xstcTestInstance(xmlNodePtr cur, xmlSchemaPtr schemas,
const xmlChar *spath, const char *base) {
xmlChar *href = NULL;
xmlChar *path = NULL;
xmlChar *validity = NULL;
xmlSchemaValidCtxtPtr ctxt = NULL;
xmlDocPtr doc = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -