1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

report improvement more tests Daniel

* schematron.c: report improvement
* test/schematron/zvon* result/schematron/zvon*: more tests
Daniel
This commit is contained in:
Daniel Veillard 2005-07-31 16:49:51 +00:00
parent 5fe95a8fd9
commit d541c8f8b4
106 changed files with 575 additions and 6 deletions

View File

@ -1,3 +1,8 @@
Sun Jul 31 18:48:55 CEST 2005 Daniel Veillard <daniel@veillard.com>
* schematron.c: report improvement
* test/schematron/zvon* result/schematron/zvon*: more tests
Sun Jul 31 16:02:59 CEST 2005 Daniel Veillard <daniel@veillard.com>
* win32/Makefile.msvc win32/configure.js: applied patch from Rob

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
<BBB aaa="A" bbb="B"/>
</AAA>

View File

@ -0,0 +1,2 @@
Pattern: Attributes present
./test/schematron/zvon11_0.xml validates

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
<BBB bbb="B"/>
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Attributes present
/AAA/BBB line 2: The element must not have an isolated bbb attribute
./test/schematron/zvon11_1.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
<BBB aaa="A"/>
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Attributes present
/AAA/BBB line 2: The element must not have an isolated aaa attribute
./test/schematron/zvon11_2.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
<BBB/>
</AAA>

View File

@ -0,0 +1,2 @@
Pattern: Attributes present
./test/schematron/zvon11_3.xml validates

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
<BBB bbb="C"/>
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Number of characters in an abbreviation
/AAA/BBB line 2: There is not enough letters in the abbreviation
./test/schematron/zvon12_0.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
<BBB bbb="CZ"/>
</AAA>

View File

@ -0,0 +1,2 @@
Pattern: Number of characters in an abbreviation
./test/schematron/zvon12_1.xml validates

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
<BBB bbb="CZCZ"/>
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Number of characters in an abbreviation
/AAA/BBB line 2: There is too much letters in the abbreviation
./test/schematron/zvon12_2.xml fails to validate

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<Total>
<Percent>20</Percent>
<Percent>30</Percent>
<Percent>10</Percent>
<Percent>50</Percent>
</Total>

View File

@ -0,0 +1,3 @@
Pattern: Sum equals 100%.
/Total line 1: The values do not sum to 100%.
./test/schematron/zvon13_0.xml fails to validate

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<Total>
<Percent>20</Percent>
<Percent>10</Percent>
<Percent>50</Percent>
</Total>

View File

@ -0,0 +1,3 @@
Pattern: Sum equals 100%.
/Total line 1: The values do not sum to 100%.
./test/schematron/zvon13_1.xml fails to validate

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<Total>
<Percent>20</Percent>
<Percent>30</Percent>
<Percent>50</Percent>
</Total>

View File

@ -0,0 +1,2 @@
Pattern: Sum equals 100%.
./test/schematron/zvon13_2.xml validates

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<AAA>
<BBB>
<CCC/>
</BBB>
<CCC/>
<DDD>
<CCC/>
<EEE>
<CCC/>
</EEE>
</DDD>
</AAA>

View File

@ -0,0 +1,4 @@
Pattern: a child of selected elements
/AAA/CCC line 5: Element CCC must not be a child of element AAA
/AAA/DDD/EEE/CCC line 9: Element CCC must not be a child of element EEE
./test/schematron/zvon14_0.xml fails to validate

View File

@ -0,0 +1,5 @@
<?xml version="1.0"?>
<AAA name="aaa">
<BBB id="bbb"/>
<CCC color="ccc"/>
</AAA>

View File

@ -0,0 +1,4 @@
Pattern: id is the only permited attribute name
/AAA line 1: Attribute name is forbidden in element AAA
/AAA/CCC line 3: Attribute color is forbidden in element CCC
./test/schematron/zvon15_0.xml fails to validate

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<AAA>
<BBB>
<CCC/>
<CCC/>
</BBB>
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Root test
/AAA line 1: Root element is AAA
./test/schematron/zvon4_0.xml fails to validate

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<XXX>
<BBB>
<CCC/>
<CCC/>
</BBB>
</XXX>

View File

@ -0,0 +1,3 @@
Pattern: Root test
/XXX line 1: Root element is XXX, not AAA
./test/schematron/zvon4_1.xml fails to validate

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<AAA>
<BBB>
<CCC/>
</BBB>
</AAA>

View File

@ -0,0 +1,7 @@
Pattern: Select empty elements CCC
/AAA/BBB/CCC line 3: Source contains an empty element CCC
/AAA/BBB/CCC line 3: [1]An element CCC does not contain any text
/AAA/BBB/CCC line 3: [2]An element CCC does not contain any text
/AAA/BBB/CCC line 3: [1]An element CCC does not contain any child element
/AAA/BBB/CCC line 3: [2]An element CCC does not contain any child element
./test/schematron/zvon5_0.xml fails to validate

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<AAA>
<BBB>
<CCC>I am CCC element</CCC>
</BBB>
</AAA>

View File

@ -0,0 +1,5 @@
Pattern: Select empty elements CCC
/AAA/BBB/CCC line 3: Source contains an empty element CCC
/AAA/BBB/CCC line 3: [1]An element CCC does not contain any child element
/AAA/BBB/CCC line 3: [2]An element CCC does not contain any child element
./test/schematron/zvon5_1.xml fails to validate

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<AAA>
<BBB>
<CCC>
<DDD/>
</CCC>
</BBB>
</AAA>

View File

@ -0,0 +1,5 @@
Pattern: Select empty elements CCC
/AAA/BBB/CCC line 3: Source contains an empty element CCC
/AAA/BBB/CCC line 3: [1]An element CCC does not contain any text
/AAA/BBB/CCC line 3: [2]An element CCC does not contain any text
./test/schematron/zvon5_2.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
aaa
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Predefined values
/AAA line 1: O.K.
./test/schematron/zvon6_0.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
bbb
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Predefined values
/AAA line 1: O.K.
./test/schematron/zvon6_1.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
ccc
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Predefined values
/AAA line 1: The AAA value is not permitted.
./test/schematron/zvon6_2.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
aaa
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Test integer
/AAA line 1: The AAA value is not an integer.
./test/schematron/zvon7_0.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
12.234
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Test integer
/AAA line 1: The AAA value is not an integer.
./test/schematron/zvon7_1.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
45
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Test integer
/AAA line 1: O.K.
./test/schematron/zvon7_2.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
0
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Test integer
/AAA line 1: O.K.
./test/schematron/zvon7_3.xml fails to validate

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<AAA>
-45
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Test integer
/AAA line 1: O.K.
./test/schematron/zvon7_4.xml fails to validate

View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<XXX>
<BBB/>
<BBB/>
<AAA/>
<BBB/>
<AAA/>
<AAA/>
</XXX>

View File

@ -0,0 +1,3 @@
Pattern: Test count
/XXX line 1: O.K.
./test/schematron/zvon8_0.xml fails to validate

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<XXX>
<BBB/>
<AAA/>
<BBB/>
<AAA/>
<AAA/>
</XXX>

View File

@ -0,0 +1,3 @@
Pattern: Test count
/XXX line 1: Some BBB are missing
./test/schematron/zvon8_1.xml fails to validate

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<XXX>
<BBB/>
<BBB/>
<AAA/>
<BBB/>
<AAA/>
</XXX>

View File

@ -0,0 +1,3 @@
Pattern: Test count
/XXX line 1: Some AAA are missing
./test/schematron/zvon8_2.xml fails to validate

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<AAA>
<CCC/>
<CCC/>
<BBB>
<CCC id="Q1"/>
</BBB>
</AAA>

View File

@ -0,0 +1,2 @@
Pattern: Test attribute
./test/schematron/zvon9_0.xml validates

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<AAA>
<CCC id="Q2"/>
<CCC/>
<BBB>
<CCC id="Q1"/>
</BBB>
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Test attribute
/AAA/CCC[1] line 2: Attribute id is used in wrong context
./test/schematron/zvon9_1.xml fails to validate

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<AAA>
<CCC/>
<CCC/>
<BBB>
<CCC/>
</BBB>
</AAA>

View File

@ -0,0 +1,3 @@
Pattern: Test attribute
/AAA/BBB/CCC line 5: Attribute id is missing
./test/schematron/zvon9_2.xml fails to validate

View File

@ -1224,6 +1224,29 @@ exit:
* *
************************************************************************/
static xmlNodePtr
xmlSchematronGetNode(xmlSchematronValidCtxtPtr ctxt,
xmlNodePtr cur, const xmlChar *xpath) {
xmlNodePtr node = NULL;
xmlXPathObjectPtr ret;
if ((ctxt == NULL) || (cur == NULL) || (xpath == NULL))
return(NULL);
ctxt->xctxt->doc = cur->doc;
ctxt->xctxt->node = cur;
ret = xmlXPathEval(xpath, ctxt->xctxt);
if (ret == NULL)
return(NULL);
if ((ret->type == XPATH_NODESET) &&
(ret->nodesetval != NULL) && (ret->nodesetval->nodeNr > 0))
node = ret->nodesetval->nodeTab[0];
xmlXPathFreeObject(ret);
return(node);
}
/**
* xmlSchematronReportOutput:
* @ctxt: the validation context
@ -1255,7 +1278,7 @@ static xmlChar *
xmlSchematronFormatReport(xmlSchematronValidCtxtPtr ctxt,
xmlNodePtr test, xmlNodePtr cur) {
xmlChar *ret = NULL;
xmlNodePtr child;
xmlNodePtr child, node;
if ((test == NULL) || (cur == NULL))
return(ret);
@ -1266,12 +1289,24 @@ xmlSchematronFormatReport(xmlSchematronValidCtxtPtr ctxt,
(child->type == XML_CDATA_SECTION_NODE))
ret = xmlStrcat(ret, child->content);
else if (IS_SCHEMATRON(child, "name")) {
if ((cur->ns == NULL) || (cur->ns->prefix == NULL))
ret = xmlStrcat(ret, cur->name);
xmlChar *path;
path = xmlGetNoNsProp(child, BAD_CAST "path");
node = cur;
if (path != NULL) {
node = xmlSchematronGetNode(ctxt, cur, path);
if (node == NULL)
node = cur;
xmlFree(path);
}
if ((node->ns == NULL) || (node->ns->prefix == NULL))
ret = xmlStrcat(ret, node->name);
else {
ret = xmlStrcat(ret, cur->ns->prefix);
ret = xmlStrcat(ret, node->ns->prefix);
ret = xmlStrcat(ret, BAD_CAST ":");
ret = xmlStrcat(ret, cur->name);
ret = xmlStrcat(ret, node->name);
}
} else {
child = child->next;
@ -1358,7 +1393,7 @@ xmlSchematronReportSuccess(xmlSchematronValidCtxtPtr ctxt,
} else {
snprintf(msg, 999, "%s line %ld: %s\n", (const char *) path,
line, (const char *) report);
xmlFree(report);
xmlFree((char *) report);
}
xmlSchematronReportOutput(ctxt, cur, &msg[0]);
if ((path != NULL) && (path != (xmlChar *) cur->name))

View File

@ -0,0 +1,8 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Attributes present">
<rule context="BBB">
<assert test="not(@aaa) or (@aaa and @bbb)">The element must not have an isolated aaa attribute</assert>
<assert test="not(@bbb) or (@aaa and @bbb)">The element must not have an isolated bbb attribute</assert>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,3 @@
<AAA>
<BBB aaa="A" bbb="B"/>
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
<BBB bbb="B"/>
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
<BBB aaa="A"/>
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
<BBB/>
</AAA>

View File

@ -0,0 +1,8 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Number of characters in an abbreviation">
<rule context="BBB">
<report test="string-length(@bbb) &lt; 2">There is not enough letters in the abbreviation</report>
<report test="string-length(@bbb) > 3">There is too much letters in the abbreviation</report>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,3 @@
<AAA>
<BBB bbb="C"/>
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
<BBB bbb="CZ"/>
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
<BBB bbb="CZCZ"/>
</AAA>

View File

@ -0,0 +1,7 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Sum equals 100%.">
<rule context="Total">
<assert test="sum(//Percent) = 100">The values do not sum to 100%. </assert>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,6 @@
<Total>
<Percent>20</Percent>
<Percent>30</Percent>
<Percent>10</Percent>
<Percent>50</Percent>
</Total>

View File

@ -0,0 +1,5 @@
<Total>
<Percent>20</Percent>
<Percent>10</Percent>
<Percent>50</Percent>
</Total>

View File

@ -0,0 +1,5 @@
<Total>
<Percent>20</Percent>
<Percent>30</Percent>
<Percent>50</Percent>
</Total>

View File

@ -0,0 +1,10 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="a child of selected elements">
<rule context="CCC">
<assert test="parent::*[name()='BBB' or name()='DDD']">Element CCC must not be a child of element
<name path="parent::*"/>
</assert>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,12 @@
<AAA>
<BBB>
<CCC/>
</BBB>
<CCC/>
<DDD>
<CCC/>
<EEE>
<CCC/>
</EEE>
</DDD>
</AAA>

View File

@ -0,0 +1,11 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="id is the only permited attribute name">
<rule context="*">
<report test="@*[not(name()='id')]">Attribute
<name path="@*[not(name()='id')]"/> is forbidden in element
<name/>
</report>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,4 @@
<AAA name="aaa">
<BBB id="bbb"/>
<CCC color="ccc"/>
</AAA>

10
test/schematron/zvon4.sct Normal file
View File

@ -0,0 +1,10 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Root test">
<rule context="/*">
<assert test="name()='AAA'">Root element is
<name/>, not AAA
</assert>
<report test="name()='AAA'">Root element is AAA</report>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,6 @@
<AAA>
<BBB>
<CCC/>
<CCC/>
</BBB>
</AAA>

View File

@ -0,0 +1,6 @@
<XXX>
<BBB>
<CCC/>
<CCC/>
</BBB>
</XXX>

12
test/schematron/zvon5.sct Normal file
View File

@ -0,0 +1,12 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Select empty elements CCC">
<rule context="CCC">
<assert test="normalize-space(.) and *">Source contains an empty element CCC </assert>
<report test="normalize-space(.) = ''">[1]An element CCC does not contain any text</report>
<assert test="normalize-space(.)">[2]An element CCC does not contain any text</assert>
<report test="not(*)">[1]An element CCC does not contain any child element</report>
<assert test="*">[2]An element CCC does not contain any child element</assert>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,5 @@
<AAA>
<BBB>
<CCC/>
</BBB>
</AAA>

View File

@ -0,0 +1,5 @@
<AAA>
<BBB>
<CCC>I am CCC element</CCC>
</BBB>
</AAA>

View File

@ -0,0 +1,7 @@
<AAA>
<BBB>
<CCC>
<DDD/>
</CCC>
</BBB>
</AAA>

View File

@ -0,0 +1,8 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Predefined values">
<rule context="AAA">
<report test="normalize-space(.) = 'aaa' or normalize-space(.) = 'bbb'">O.K.</report>
<assert test="normalize-space(.) = 'aaa' or normalize-space(.) = 'bbb'">The AAA value is not permitted.</assert>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,3 @@
<AAA>
aaa
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
bbb
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
ccc
</AAA>

View File

@ -0,0 +1,9 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Test integer">
<rule context="AAA">
<report test="floor(.) = number(.)">O.K.</report>
<assert test="floor(.) = number(.)">The AAA value is not an integer.</assert>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,3 @@
<AAA>
aaa
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
12.234
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
45
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
0
</AAA>

View File

@ -0,0 +1,3 @@
<AAA>
-45
</AAA>

10
test/schematron/zvon8.sct Normal file
View File

@ -0,0 +1,10 @@
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Test count">
<rule context="/*">
<report test="count(//BBB) = count(//AAA)">O.K.</report>
<assert test="count(//BBB) &lt;= count(//AAA)">Some AAA are missing</assert>
<report test="count(//BBB) &lt; count(//AAA)">Some BBB are missing</report>
</rule>
</pattern>
</schema>

View File

@ -0,0 +1,8 @@
<XXX>
<BBB/>
<BBB/>
<AAA/>
<BBB/>
<AAA/>
<AAA/>
</XXX>

Some files were not shown because too many files have changed in this diff Show More