From c740a17f453f1b5de647c394362aa85c64c3003b Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 31 Jul 2005 12:17:24 +0000 Subject: [PATCH] fixing the loop bug, fixing schematron text error rendering started * schematron.c xmllint.c: fixing the loop bug, fixing schematron text error rendering * Makefile.am result/schematron/* test/schematron/zvon1*.sct: started integrating within "make tests" Daniel --- ChangeLog | 7 ++ Makefile.am | 31 +++++++- result/schematron/zvon1_0 | 4 + result/schematron/zvon1_0.err | 8 ++ result/schematron/zvon1_1 | 4 + result/schematron/zvon1_1.err | 8 ++ schematron.c | 89 ++++++++++++++++++---- test/schematron/{zvon1_0.sct => zvon1.sct} | 0 xmllint.c | 6 +- 9 files changed, 139 insertions(+), 18 deletions(-) create mode 100644 result/schematron/zvon1_0 create mode 100644 result/schematron/zvon1_0.err create mode 100644 result/schematron/zvon1_1 create mode 100644 result/schematron/zvon1_1.err rename test/schematron/{zvon1_0.sct => zvon1.sct} (100%) diff --git a/ChangeLog b/ChangeLog index f7e550a3..49d59d6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Jul 31 14:15:31 CEST 2005 Daniel Veillard + + * schematron.c xmllint.c: fixing the loop bug, fixing schematron + text error rendering + * Makefile.am result/schematron/* test/schematron/zvon1*.sct: + started integrating within "make tests" + Sat Jul 30 17:26:58 EDT 2005 Daniel Veillard * test/schematron/*: a few first tests from Zvon unfortunately diff --git a/Makefile.am b/Makefile.am index ef043cbb..6600f689 100644 --- a/Makefile.am +++ b/Makefile.am @@ -159,7 +159,7 @@ check-local: all tests testall : tests SVGtests SAXtests -tests: XMLtests XMLenttests NStests IDtests Errtests APItests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@ @TEST_VALID@ URItests @TEST_PATTERN@ @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ @TEST_MODULES@ +tests: XMLtests XMLenttests NStests IDtests Errtests APItests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@ @TEST_VALID@ URItests @TEST_PATTERN@ @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_SCHEMATRON@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ @TEST_MODULES@ @(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; \ $(MAKE) MAKEFLAGS+=--silent tests ; fi) @(cd doc/examples ; $(MAKE) MAKEFLAGS+=--silent tests) @@ -1007,6 +1007,35 @@ Relaxtests: xmllint$(EXEEXT) fi ; fi ; \ done; done) +Schematrontests: xmllint$(EXEEXT) + @(echo > .memdump) + @echo "## Schematron regression tests" + -@(for i in $(srcdir)/test/schematron/*.sct ; do \ + name=`basename $$i | sed 's+\.sct++'`; \ + for j in $(srcdir)/test/schematron/"$$name"_*.xml ; do \ + if [ -f $$j ] ; then \ + xno=`basename $$j | sed 's+.*_\(.*\).xml+\1+'`; \ + if [ ! -f $(srcdir)/result/schematron/"$$name"_"$$xno" ]; \ + then \ + echo New test file "$$name"_"$$xno" ; \ + $(CHECKER) $(top_builddir)/xmllint$(EXEEXT) --schematron $$i $$j \ + > $(srcdir)/result/schematron/"$$name"_"$$xno" \ + 2> $(srcdir)/result/schematron/"$$name"_"$$xno".err; \ + grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\ + else \ + log=`$(CHECKER) $(top_builddir)/xmllint$(EXEEXT) --schematron $$i $$j \ + > res.$$name 2> err.$$name;\ + grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0";\ + diff $(srcdir)/result/schematron/"$$name"_"$$xno" \ + res.$$name;\ + diff $(srcdir)/result/schematron/"$$name"_"$$xno".err \ + err.$$name | grep -v "error detected at";\ + grep Unimplemented err.$$name`; \ + if [ -n "$$log" ] ; then echo "$$name"_"$$xno" result ; echo $$log ; fi ; \ + rm res.$$name err.$$name ; \ + fi ; fi ; \ + done; done) + RelaxNGPythonTests: @(if [ -x $(PYTHON) ] ; then \ PYTHONPATH=$(top_builddir)/python:$(top_builddir)/python/.libs:$$PYTHONPATH ; \ diff --git a/result/schematron/zvon1_0 b/result/schematron/zvon1_0 new file mode 100644 index 00000000..9aae4b1e --- /dev/null +++ b/result/schematron/zvon1_0 @@ -0,0 +1,4 @@ + + + + diff --git a/result/schematron/zvon1_0.err b/result/schematron/zvon1_0.err new file mode 100644 index 00000000..0d421844 --- /dev/null +++ b/result/schematron/zvon1_0.err @@ -0,0 +1,8 @@ +Pattern: Print both cases +/AAA line 1: BBB element is present. +/AAA line 1: AAA misses attribute name. +Pattern: Print positive result only +/AAA line 1: BBB element is present. +Pattern: Print negative result only +/AAA line 1: AAA misses attribute name. +./test/schematron/zvon1_0.xml fails to validate diff --git a/result/schematron/zvon1_1 b/result/schematron/zvon1_1 new file mode 100644 index 00000000..0a06953a --- /dev/null +++ b/result/schematron/zvon1_1 @@ -0,0 +1,4 @@ + + + + diff --git a/result/schematron/zvon1_1.err b/result/schematron/zvon1_1.err new file mode 100644 index 00000000..70ee87a7 --- /dev/null +++ b/result/schematron/zvon1_1.err @@ -0,0 +1,8 @@ +Pattern: Print both cases +/AAA line 1: BBB element is missing. +/AAA line 1: AAA misses attribute name. +Pattern: Print positive result only +Pattern: Print negative result only +/AAA line 1: BBB element is missing. +/AAA line 1: AAA misses attribute name. +./test/schematron/zvon1_1.xml fails to validate diff --git a/schematron.c b/schematron.c index 832ff416..312dfc5e 100644 --- a/schematron.c +++ b/schematron.c @@ -332,8 +332,16 @@ xmlSchematronAddTest(xmlSchematronParserCtxtPtr ctxt, ret->test = test; ret->comp = comp; ret->report = report; - ret->next = rule->tests; - rule->tests = ret; + ret->next = NULL; + if (rule->tests == NULL) { + rule->tests = ret; + } else { + xmlSchematronTestPtr prev = rule->tests; + + while (prev->next != NULL) + prev = prev->next; + prev->next = ret; + } return (ret); } @@ -406,10 +414,26 @@ xmlSchematronAddRule(xmlSchematronParserCtxtPtr ctxt, xmlSchematronPtr schema, ret->context = context; ret->pattern = pattern; ret->report = report; - ret->next = schema->rules; - schema->rules = ret; - ret->patnext = pat->rules; - pat->rules = ret; + ret->next = NULL; + if (schema->rules == NULL) { + schema->rules = ret; + } else { + xmlSchematronRulePtr prev = schema->rules; + + while (prev->next != NULL) + prev = prev->next; + prev->next = ret; + } + ret->patnext = NULL; + if (pat->rules == NULL) { + pat->rules = ret; + } else { + xmlSchematronRulePtr prev = pat->rules; + + while (prev->patnext != NULL) + prev = prev->patnext; + prev->patnext = ret; + } return (ret); } @@ -465,8 +489,16 @@ xmlSchematronAddPattern(xmlSchematronParserCtxtPtr ctxt, } memset(ret, 0, sizeof(xmlSchematronPattern)); ret->name = name; - ret->next = schema->patterns; - schema->patterns = ret; + ret->next = NULL; + if (schema->patterns == NULL) { + schema->patterns = ret; + } else { + xmlSchematronPatternPtr prev = schema->patterns; + + while (prev->next != NULL) + prev = prev->next; + prev->next = ret; + } return (ret); } @@ -1197,7 +1229,7 @@ exit: static void xmlSchematronReportOutput(xmlSchematronValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlNodePtr cur ATTRIBUTE_UNUSED, - const char *msg ATTRIBUTE_UNUSED) { + const char *msg) { /* TODO */ fprintf(stderr, "%s", msg); } @@ -1220,8 +1252,7 @@ xmlSchematronReportSuccess(xmlSchematronValidCtxtPtr ctxt, /* if quiet and not SVRL report only failures */ if ((ctxt->flags & XML_SCHEMATRON_OUT_QUIET) && ((ctxt->flags & XML_SCHEMATRON_OUT_XML) == 0) && - (((test->type == XML_SCHEMATRON_REPORT) & (!success)) || - ((test->type == XML_SCHEMATRON_ASSERT) & (success)))) + (test->type == XML_SCHEMATRON_REPORT)) return; if (ctxt->flags & XML_SCHEMATRON_OUT_XML) { TODO @@ -1253,6 +1284,33 @@ xmlSchematronReportSuccess(xmlSchematronValidCtxtPtr ctxt, } } +/** + * xmlSchematronReportPattern: + * @ctxt: the validation context + * @pattern: the current pattern + * + * called from the validation engine when starting to check a pattern + */ +static void +xmlSchematronReportPattern(xmlSchematronValidCtxtPtr ctxt, + xmlSchematronPatternPtr pattern) { + if ((ctxt == NULL) || (pattern == NULL)) + return; + if (ctxt->flags & XML_SCHEMATRON_OUT_QUIET) + return; + if (ctxt->flags & XML_SCHEMATRON_OUT_XML) { + TODO + } else { + char msg[1000]; + + if (pattern->name == NULL) + return; + snprintf(msg, 999, "Pattern: %s\n", (const char *) pattern->name); + xmlSchematronReportOutput(ctxt, NULL, &msg[0]); + } +} + + /************************************************************************ * * * Validation against a Schematrontron * @@ -1274,9 +1332,7 @@ xmlSchematronNewValidCtxt(xmlSchematronPtr schema, int options) int i; xmlSchematronValidCtxtPtr ret; - ret = - (xmlSchematronValidCtxtPtr) - xmlMalloc(sizeof(xmlSchematronValidCtxt)); + ret = (xmlSchematronValidCtxtPtr) xmlMalloc(sizeof(xmlSchematronValidCtxt)); if (ret == NULL) { xmlSchematronVErrMemory(NULL, "allocating validation context", NULL); @@ -1432,7 +1488,6 @@ xmlSchematronValidateDoc(xmlSchematronValidCtxtPtr ctxt, xmlDocPtr instance) xmlSchematronPatternPtr pattern; xmlSchematronRulePtr rule; xmlSchematronTestPtr test; - int matched; if ((ctxt == NULL) || (ctxt->schema == NULL) || (ctxt->schema->rules == NULL) || (instance == NULL)) @@ -1473,7 +1528,8 @@ xmlSchematronValidateDoc(xmlSchematronValidCtxtPtr ctxt, xmlDocPtr instance) pattern = ctxt->schema->patterns; while (pattern != NULL) { - matched = 0; + xmlSchematronReportPattern(ctxt, pattern); + /* * TODO convert the pattern rule to a direct XPath and * compute directly instead of using the pattern matching @@ -1496,6 +1552,7 @@ xmlSchematronValidateDoc(xmlSchematronValidCtxtPtr ctxt, xmlDocPtr instance) cur = xmlSchematronNextNode(cur); } + pattern = pattern->next; } } return(ctxt->nberrors); diff --git a/test/schematron/zvon1_0.sct b/test/schematron/zvon1.sct similarity index 100% rename from test/schematron/zvon1_0.sct rename to test/schematron/zvon1.sct diff --git a/xmllint.c b/xmllint.c index b4c7b733..ca94c6cb 100644 --- a/xmllint.c +++ b/xmllint.c @@ -2591,7 +2591,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { if (wxschematron != NULL) { xmlSchematronValidCtxtPtr ctxt; int ret; - int flag = XML_SCHEMATRON_OUT_TEXT; + int flag; if ((timing) && (!repeat)) { startTimer(); @@ -2599,6 +2599,10 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { if (debug) flag = XML_SCHEMATRON_OUT_XML; + else + flag = XML_SCHEMATRON_OUT_TEXT; + if (noout) + flag |= XML_SCHEMATRON_OUT_QUIET; ctxt = xmlSchematronNewValidCtxt(wxschematron, flag); #if 0 xmlSchematronSetValidErrors(ctxt,