1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-28 00:21:53 +03:00

Work on the W3C/NIST regression tests for XInclude, improved the script,

* check-xinclude-test-suite.py xinclude.c: Work on the W3C/NIST
  regression tests for XInclude, improved the script, improving
  XInclude error reporting mechanism
Daniel
This commit is contained in:
Daniel Veillard
2003-02-11 18:03:05 +00:00
parent e9751d9516
commit d581b7edd4
3 changed files with 111 additions and 20 deletions

View File

@ -1,3 +1,9 @@
Tue Feb 11 19:01:02 CET 2003 Daniel Veillard <daniel@veillard.com>
* check-xinclude-test-suite.py xinclude.c: Work on the W3C/NIST
regression tests for XInclude, improved the script, improving
XInclude error reporting mechanism
Mon Feb 10 17:19:14 CET 2003 Daniel Veillard <daniel@veillard.com> Mon Feb 10 17:19:14 CET 2003 Daniel Veillard <daniel@veillard.com>
* NEWS doc/* configure.in: preparing release 2.5.3 * NEWS doc/* configure.in: preparing release 2.5.3

View File

@ -14,11 +14,16 @@ LOG="check-xinclude-test-suite.log"
log = open(LOG, "w") log = open(LOG, "w")
test_nr = 0
test_succeed = 0
test_failed = 0
test_error = 0
# #
# Error and warning handlers # Error and warning handlers
# #
error_nr = 0 error_nr = 0
error_msg = '' error_msg = ''
def errorHandler(ctx, str): def errorHandler(ctx, str):
global error_nr global error_nr
global error_msg global error_msg
@ -44,10 +49,6 @@ def testXInclude(filename, id):
print "testXInclude(%s, %s)" % (filename, id) print "testXInclude(%s, %s)" % (filename, id)
return 1 return 1
test_nr = 0
test_succeed = 0
test_failed = 0
test_error = 0
def runTest(test, basedir): def runTest(test, basedir):
global test_nr global test_nr
global test_failed global test_failed
@ -56,6 +57,7 @@ def runTest(test, basedir):
global error_msg global error_msg
global log global log
fatal_error = 0
uri = test.prop('href') uri = test.prop('href')
id = test.prop('id') id = test.prop('id')
if uri == None: if uri == None:
@ -72,26 +74,76 @@ def runTest(test, basedir):
print "Test %s missing: base %s uri %s" % (URI, basedir, uri) print "Test %s missing: base %s uri %s" % (URI, basedir, uri)
return -1 return -1
# output = output = test.xpathEval('string(output)')
expected = None
if output == 'No output file.':
output = None
if output == '':
output = None
if output != None:
if basedir != None:
output = basedir + "/" + output
if os.access(output, os.R_OK) == 0:
print "Result for %s missing: %s" % (id, output)
output = None
else:
try:
f = open(output)
expected = f.read()
except:
print "Result for %s unreadable: %s" % (id, output)
description = test.xpathEval('string(description)')
if string.find(description, 'fatal error') != -1:
fatal_error = 1
try:
# print "testing %s" % (URI)
doc = libxml2.parseFile(URI)
except:
doc = None
if doc != None:
res = doc.xincludeProcess()
if expected != None and fatal_error != 0:
result = doc.serialize()
if result != expected:
print "Result for %s differs" % (id)
doc.freeDoc()
else:
print "Failed to parse %s" % (URI)
res = -1
test_nr = test_nr + 1 test_nr = test_nr + 1
if res > 0: if fatal_error == 0 and output != None:
test_succeed = test_succeed + 1 if res > 0:
elif res == 0: test_succeed = test_succeed + 1
test_failed = test_failed + 1 elif res == 0:
elif res < 0: test_failed = test_failed + 1
test_error = test_error + 1 print "Test %s: no substitution done ???" % (id)
elif res < 0:
test_error = test_error + 1
print "Test %s: failed valid XInclude processing" % (id)
else:
if res > 0:
test_error = test_error + 1
print "Test %s: failed to detect invalid XInclude processing" % (id)
elif res == 0:
test_failed = test_failed + 1
print "Test %s: Invalid but no substitution done" % (id)
elif res < 0:
test_succeed = test_succeed + 1
# Log the ontext # Log the ontext
if res != 1: if res != 1:
log.write("Test ID %s\n" % (id))
log.write(" File: %s\n" % (URI)) log.write(" File: %s\n" % (URI))
content = string.strip(test.content) content = string.strip(test.content)
while content[-1] == '\n': while content[-1] == '\n':
content = content[0:-1] content = content[0:-1]
if extra != None: log.write(" %s:%s\n\n" % (type, content))
log.write(" %s:%s:%s\n" % (type, extra, content))
else:
log.write(" %s:%s\n\n" % (type, content))
if error_msg != '': if error_msg != '':
log.write(" ----\n%s ----\n" % (error_msg)) log.write(" ----\n%s ----\n" % (error_msg))
error_msg = '' error_msg = ''
@ -134,11 +186,6 @@ start = time.time()
case = testsuite.children case = testsuite.children
while case != None: while case != None:
global test_nr
global test_succeed
global test_failed
global test_error
if case.name == 'testcases': if case.name == 'testcases':
old_test_nr = test_nr old_test_nr = test_nr
old_test_succeed = test_succeed old_test_succeed = test_succeed

View File

@ -83,6 +83,8 @@ struct _xmlXIncludeCtxt {
int txtMax; /* size of unparsed documents tab */ int txtMax; /* size of unparsed documents tab */
xmlNodePtr *txtTab; /* array of unparsed text nodes */ xmlNodePtr *txtTab; /* array of unparsed text nodes */
xmlURL *txturlTab; /* array of unparsed txtuments URLs */ xmlURL *txturlTab; /* array of unparsed txtuments URLs */
int nbErrors; /* the number of errors detected */
}; };
static int static int
@ -152,6 +154,7 @@ xmlXIncludeNewRef(xmlXIncludeCtxtPtr ctxt, const xmlChar *URI,
if (ctxt->incTab == NULL) { if (ctxt->incTab == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"malloc failed !\n"); "malloc failed !\n");
ctxt->nbErrors++;
xmlXIncludeFreeRef(ret); xmlXIncludeFreeRef(ret);
return(NULL); return(NULL);
} }
@ -197,6 +200,7 @@ xmlXIncludeNewContext(xmlDocPtr doc) {
ret->incBase = 0; ret->incBase = 0;
ret->incMax = 0; ret->incMax = 0;
ret->incTab = NULL; ret->incTab = NULL;
ret->nbErrors = 0;
return(ret); return(ret);
} }
@ -268,6 +272,7 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
href = xmlGetProp(cur, XINCLUDE_HREF); href = xmlGetProp(cur, XINCLUDE_HREF);
if (href == NULL) { if (href == NULL) {
xmlGenericError(xmlGenericErrorContext, "XInclude: no href\n"); xmlGenericError(xmlGenericErrorContext, "XInclude: no href\n");
ctxt->nbErrors++;
return(-1); return(-1);
} }
} }
@ -284,6 +289,7 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value %s for %s\n", "XInclude: invalid value %s for %s\n",
parse, XINCLUDE_PARSE); parse, XINCLUDE_PARSE);
ctxt->nbErrors++;
if (href != NULL) if (href != NULL)
xmlFree(href); xmlFree(href);
if (parse != NULL) if (parse != NULL)
@ -323,6 +329,7 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
xmlFree(base); xmlFree(base);
if (URI == NULL) { if (URI == NULL) {
xmlGenericError(xmlGenericErrorContext, "XInclude: failed build URL\n"); xmlGenericError(xmlGenericErrorContext, "XInclude: failed build URL\n");
ctxt->nbErrors++;
return(-1); return(-1);
} }
@ -333,6 +340,7 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
if (uri == NULL) { if (uri == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", URI); "XInclude: invalid value URI %s\n", URI);
ctxt->nbErrors++;
return(-1); return(-1);
} }
if (uri->fragment != NULL) { if (uri->fragment != NULL) {
@ -345,6 +353,7 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
if (URL == NULL) { if (URL == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", URI); "XInclude: invalid value URI %s\n", URI);
ctxt->nbErrors++;
if (fragment != NULL) if (fragment != NULL)
xmlFree(fragment); xmlFree(fragment);
return(-1); return(-1);
@ -395,6 +404,7 @@ xmlXIncludeRecurseDoc(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc,
if (newctxt->incTab == NULL) { if (newctxt->incTab == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"malloc failed !\n"); "malloc failed !\n");
ctxt->nbErrors++;
xmlFree(newctxt); xmlFree(newctxt);
return; return;
} }
@ -440,6 +450,7 @@ xmlXIncludeAddTxt(xmlXIncludeCtxtPtr ctxt, xmlNodePtr txt, const xmlURL url) {
if (ctxt->txtTab == NULL) { if (ctxt->txtTab == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"malloc failed !\n"); "malloc failed !\n");
ctxt->nbErrors++;
return; return;
} }
ctxt->txturlTab = (xmlURL *) xmlMalloc(ctxt->txtMax * ctxt->txturlTab = (xmlURL *) xmlMalloc(ctxt->txtMax *
@ -447,6 +458,7 @@ xmlXIncludeAddTxt(xmlXIncludeCtxtPtr ctxt, xmlNodePtr txt, const xmlURL url) {
if (ctxt->txturlTab == NULL) { if (ctxt->txturlTab == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"malloc failed !\n"); "malloc failed !\n");
ctxt->nbErrors++;
return; return;
} }
} }
@ -457,6 +469,7 @@ xmlXIncludeAddTxt(xmlXIncludeCtxtPtr ctxt, xmlNodePtr txt, const xmlURL url) {
if (ctxt->txtTab == NULL) { if (ctxt->txtTab == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"realloc failed !\n"); "realloc failed !\n");
ctxt->nbErrors++;
return; return;
} }
ctxt->txturlTab = (xmlURL *) xmlRealloc(ctxt->txturlTab, ctxt->txturlTab = (xmlURL *) xmlRealloc(ctxt->txturlTab,
@ -464,6 +477,7 @@ xmlXIncludeAddTxt(xmlXIncludeCtxtPtr ctxt, xmlNodePtr txt, const xmlURL url) {
if (ctxt->txturlTab == NULL) { if (ctxt->txturlTab == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"realloc failed !\n"); "realloc failed !\n");
ctxt->nbErrors++;
return; return;
} }
} }
@ -945,6 +959,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (uri == NULL) { if (uri == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url); "XInclude: invalid value URI %s\n", url);
ctxt->nbErrors++;
return(-1); return(-1);
} }
if (uri->fragment != NULL) { if (uri->fragment != NULL) {
@ -956,6 +971,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (URL == NULL) { if (URL == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url); "XInclude: invalid value URI %s\n", url);
ctxt->nbErrors++;
if (fragment != NULL) if (fragment != NULL)
xmlFree(fragment); xmlFree(fragment);
return(-1); return(-1);
@ -1051,6 +1067,7 @@ loaded:
if (xptrctxt == NULL) { if (xptrctxt == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: could create XPointer context\n"); "XInclude: could create XPointer context\n");
ctxt->nbErrors++;
xmlFree(URL); xmlFree(URL);
xmlFree(fragment); xmlFree(fragment);
return(-1); return(-1);
@ -1060,6 +1077,7 @@ loaded:
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer evaluation failed: #%s\n", "XInclude: XPointer evaluation failed: #%s\n",
fragment); fragment);
ctxt->nbErrors++;
xmlXPathFreeContext(xptrctxt); xmlXPathFreeContext(xptrctxt);
xmlFree(URL); xmlFree(URL);
xmlFree(fragment); xmlFree(fragment);
@ -1076,6 +1094,7 @@ loaded:
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer is not a range: #%s\n", "XInclude: XPointer is not a range: #%s\n",
fragment); fragment);
ctxt->nbErrors++;
xmlXPathFreeContext(xptrctxt); xmlXPathFreeContext(xptrctxt);
xmlFree(URL); xmlFree(URL);
xmlFree(fragment); xmlFree(fragment);
@ -1108,12 +1127,14 @@ loaded:
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer selects an attribute: #%s\n", "XInclude: XPointer selects an attribute: #%s\n",
fragment); fragment);
ctxt->nbErrors++;
set->nodeTab[i] = NULL; set->nodeTab[i] = NULL;
continue; continue;
case XML_NAMESPACE_DECL: case XML_NAMESPACE_DECL:
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer selects a namespace: #%s\n", "XInclude: XPointer selects a namespace: #%s\n",
fragment); fragment);
ctxt->nbErrors++;
set->nodeTab[i] = NULL; set->nodeTab[i] = NULL;
continue; continue;
case XML_DOCUMENT_TYPE_NODE: case XML_DOCUMENT_TYPE_NODE:
@ -1128,6 +1149,7 @@ loaded:
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: XPointer selects unexpected nodes: #%s\n", "XInclude: XPointer selects unexpected nodes: #%s\n",
fragment); fragment);
ctxt->nbErrors++;
set->nodeTab[i] = NULL; set->nodeTab[i] = NULL;
set->nodeTab[i] = NULL; set->nodeTab[i] = NULL;
continue; /* for */ continue; /* for */
@ -1193,12 +1215,14 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (uri == NULL) { if (uri == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url); "XInclude: invalid value URI %s\n", url);
ctxt->nbErrors++;
return(-1); return(-1);
} }
if (uri->fragment != NULL) { if (uri->fragment != NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: fragment identifier forbidden for text: %s\n", "XInclude: fragment identifier forbidden for text: %s\n",
uri->fragment); uri->fragment);
ctxt->nbErrors++;
xmlFreeURI(uri); xmlFreeURI(uri);
return(-1); return(-1);
} }
@ -1207,6 +1231,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (URL == NULL) { if (URL == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", url); "XInclude: invalid value URI %s\n", url);
ctxt->nbErrors++;
return(-1); return(-1);
} }
@ -1217,6 +1242,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (URL[0] == 0) { if (URL[0] == 0) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: text serialization of document not available\n"); "XInclude: text serialization of document not available\n");
ctxt->nbErrors++;
xmlFree(URL); xmlFree(URL);
return(-1); return(-1);
} }
@ -1247,6 +1273,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (enc == XML_CHAR_ENCODING_ERROR) { if (enc == XML_CHAR_ENCODING_ERROR) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: encoding %s not supported\n", encoding); "XInclude: encoding %s not supported\n", encoding);
ctxt->nbErrors++;
xmlFree(encoding); xmlFree(encoding);
xmlFree(URL); xmlFree(URL);
return(-1); return(-1);
@ -1281,6 +1308,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
if (!IS_CHAR(cur)) { if (!IS_CHAR(cur)) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: %s contains invalid char %d\n", URL, cur); "XInclude: %s contains invalid char %d\n", URL, cur);
ctxt->nbErrors++;
} else { } else {
xmlNodeAddContentLen(node, &content[i], l); xmlNodeAddContentLen(node, &content[i], l);
} }
@ -1437,6 +1465,7 @@ xmlXIncludePreloadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
xmlFree(base); xmlFree(base);
if (URI == NULL) { if (URI == NULL) {
xmlGenericError(xmlGenericErrorContext, "XInclude: failed build URL\n"); xmlGenericError(xmlGenericErrorContext, "XInclude: failed build URL\n");
ctxt->nbErrors++;
return(-1); return(-1);
} }
@ -1447,6 +1476,7 @@ xmlXIncludePreloadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
if (uri == NULL) { if (uri == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", URI); "XInclude: invalid value URI %s\n", URI);
ctxt->nbErrors++;
xmlFree(URI); xmlFree(URI);
return(-1); return(-1);
} }
@ -1459,6 +1489,7 @@ xmlXIncludePreloadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
if (URL == NULL) { if (URL == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value URI %s\n", URI); "XInclude: invalid value URI %s\n", URI);
ctxt->nbErrors++;
if (fragment != NULL) if (fragment != NULL)
xmlFree(fragment); xmlFree(fragment);
xmlFree(URI); xmlFree(URI);
@ -1517,6 +1548,7 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
href = xmlGetProp(cur, XINCLUDE_HREF); href = xmlGetProp(cur, XINCLUDE_HREF);
if (href == NULL) { if (href == NULL) {
xmlGenericError(xmlGenericErrorContext, "XInclude: no href\n"); xmlGenericError(xmlGenericErrorContext, "XInclude: no href\n");
ctxt->nbErrors++;
return(-1); return(-1);
} }
} }
@ -1533,6 +1565,7 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: invalid value %s for %s\n", "XInclude: invalid value %s for %s\n",
parse, XINCLUDE_PARSE); parse, XINCLUDE_PARSE);
ctxt->nbErrors++;
if (href != NULL) if (href != NULL)
xmlFree(href); xmlFree(href);
if (parse != NULL) if (parse != NULL)
@ -1566,6 +1599,7 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
} }
if (URI == NULL) { if (URI == NULL) {
xmlGenericError(xmlGenericErrorContext, "XInclude: failed build URL\n"); xmlGenericError(xmlGenericErrorContext, "XInclude: failed build URL\n");
ctxt->nbErrors++;
if (parse != NULL) if (parse != NULL)
xmlFree(parse); xmlFree(parse);
if (href != NULL) if (href != NULL)
@ -1615,6 +1649,7 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: could not load %s, and no fallback was found\n", "XInclude: could not load %s, and no fallback was found\n",
URI); URI);
ctxt->nbErrors++;
} }
/* /*
@ -1661,6 +1696,7 @@ xmlXIncludeIncludeNode(xmlXIncludeCtxtPtr ctxt, int nr) {
if (end == NULL) { if (end == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"XInclude: failed to build node\n"); "XInclude: failed to build node\n");
ctxt->nbErrors++;
return(-1); return(-1);
} }
end->type = XML_XINCLUDE_END; end->type = XML_XINCLUDE_END;
@ -1791,6 +1827,8 @@ xmlXIncludeProcess(xmlDocPtr doc) {
if (ctxt == NULL) if (ctxt == NULL)
return(-1); return(-1);
ret = xmlXIncludeDoProcess(ctxt, doc); ret = xmlXIncludeDoProcess(ctxt, doc);
if ((ret >= 0) && (ctxt->nbErrors > 0))
ret = -1;
xmlXIncludeFreeContext(ctxt); xmlXIncludeFreeContext(ctxt);
return(ret); return(ret);