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

Integrated xmlRegExecErrInfo and xmlRegExecNextValues from xmlregexp.c to

* xmlschemas.c: Integrated xmlRegExecErrInfo and xmlRegExecNextValues
  from xmlregexp.c to report expected elements on content model errors.
* all_*.err any3_0_0.err choice_*.err list0_0_1.err list0_1_1.err:
  Adapted output of regression tests.
This commit is contained in:
Kasimier T. Buchcik 2005-01-13 12:10:11 +00:00
parent dcd939032f
commit c3af19d1f7
19 changed files with 174 additions and 48 deletions

View File

@ -1,3 +1,10 @@
Thu Jan 13 12:59:25 CET 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c: Integrated xmlRegExecErrInfo and xmlRegExecNextValues
from xmlregexp.c to report expected elements on content model errors.
* all_*.err any3_0_0.err choice_*.err list0_0_1.err list0_1_1.err:
Adapted output of regression tests.
Thu Jan 13 12:24:09 CET 2005 Daniel Veillard <daniel@veillard.com>
* config.h.in configure.in xmlmodule.c: trying to work around

View File

@ -1 +1 @@
./test/schemas/all_3.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s).
./test/schemas/all_3.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s). Expected is 'c'.

View File

@ -1 +1 @@
./test/schemas/all_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s).
./test/schemas/all_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s). Expected is one of 'a', 'b', 'c'.

View File

@ -1 +1 @@
./test/schemas/all_5.xml:1: element a: Schemas validity error : Element 'a': This element is not expected.
./test/schemas/all_5.xml:1: element a: Schemas validity error : Element 'a': This element is not expected. Expected is 'c'.

View File

@ -1 +1 @@
./test/schemas/all_6.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s).
./test/schemas/all_6.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s). Expected is one of 'b', 'c'.

View File

@ -1 +1 @@
./test/schemas/all_7.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s).
./test/schemas/all_7.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s). Expected is 'c'.

View File

@ -1 +1 @@
./test/schemas/all_5.xml:1: element a: Schemas validity error : Element 'a': This element is not expected.
./test/schemas/all_5.xml:1: element a: Schemas validity error : Element 'a': This element is not expected. Expected is 'c'.

View File

@ -1,2 +1 @@
./test/schemas/all_1.xml:1: element c: Schemas validity error : Element 'c': This element is not expected.
./test/schemas/all_1.xml:1: element a: Schemas validity error : Element 'a': This element is not expected.
./test/schemas/all_1.xml:1: element c: Schemas validity error : Element 'c': This element is not expected. Expected is 'a'.

View File

@ -1 +1 @@
./test/schemas/all_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s).
./test/schemas/all_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s). Expected is one of 'a', 'b'.

View File

@ -1,3 +1 @@
./test/schemas/any3_0.xml:12: element bar.A: Schemas validity error : Element 'bar.A': This element is not expected.
./test/schemas/any3_0.xml:13: element bar.B: Schemas validity error : Element 'foo:bar.B': This element is not expected.
./test/schemas/any3_0.xml:14: element bar.C: Schemas validity error : Element 'bar:bar.C': This element is not expected.
./test/schemas/any3_0.xml:12: element bar.A: Schemas validity error : Element 'bar.A': This element is not expected. Expected is one of {##other:http://FOO}*.

View File

@ -1 +1 @@
./test/schemas/choice_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s).
./test/schemas/choice_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s). Expected is one of 'a', 'b'.

View File

@ -1,2 +1 @@
./test/schemas/choice_5.xml:3: element b: Schemas validity error : Element 'b': This element is not expected.
./test/schemas/choice_5.xml:4: element a: Schemas validity error : Element 'a': This element is not expected.

View File

@ -1,3 +1 @@
./test/schemas/choice_6.xml:3: element b: Schemas validity error : Element 'b': This element is not expected.
./test/schemas/choice_6.xml:4: element a: Schemas validity error : Element 'a': This element is not expected.
./test/schemas/choice_6.xml:5: element a: Schemas validity error : Element 'a': This element is not expected.

View File

@ -1,2 +1 @@
./test/schemas/choice_5.xml:3: element b: Schemas validity error : Element 'b': This element is not expected.
./test/schemas/choice_5.xml:4: element a: Schemas validity error : Element 'a': This element is not expected.

View File

@ -1,3 +1 @@
./test/schemas/choice_6.xml:3: element b: Schemas validity error : Element 'b': This element is not expected.
./test/schemas/choice_6.xml:4: element a: Schemas validity error : Element 'a': This element is not expected.
./test/schemas/choice_6.xml:5: element a: Schemas validity error : Element 'a': This element is not expected.

View File

@ -1 +1 @@
./test/schemas/choice_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s).
./test/schemas/choice_4.xml:1: element doc: Schemas validity error : Element 'doc': Missing child element(s). Expected is one of 'a', 'b'.

View File

@ -1 +1 @@
./test/schemas/list0_1.xml:1: element test: Schemas validity error : Element 'test': Missing child element(s).
./test/schemas/list0_1.xml:1: element test: Schemas validity error : Element 'test': Missing child element(s). Expected is 'string'.

View File

@ -1 +1 @@
./test/schemas/list0_1.xml:1: element test: Schemas validity error : Element 'test': Missing child element(s).
./test/schemas/list0_1.xml:1: element test: Schemas validity error : Element 'test': Missing child element(s). Expected is 'string'.

View File

@ -1078,13 +1078,124 @@ xmlSchemaVComplexTypeErr(xmlSchemaValidCtxtPtr ctxt,
msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0));
msg = xmlStrcat(msg, BAD_CAST "]");
}
msg = xmlStrcat(msg, BAD_CAST ": %s.\n");
xmlSchemaVErr(ctxt, node, error, (const char *) msg,
msg = xmlStrcat(msg, BAD_CAST ": %s.\n");
xmlSchemaVErr(ctxt, node, error, (const char *) msg,
(const xmlChar *) message, NULL);
FREE_AND_NULL(str)
xmlFree(msg);
}
/**
* xmlSchemaVComplexTypeElemErr:
* @ctxt: the schema validation context
* @error: the error code
* @node: the node containing the validated value
* @type: the complex type used for validation
* @message: the error message
*
* Reports a complex type validation error.
*/
static void
xmlSchemaVComplexTypeElemErr(xmlSchemaValidCtxtPtr ctxt,
xmlParserErrors error,
xmlNodePtr node,
xmlSchemaTypePtr type,
const char *message,
int nbval,
int nbneg,
xmlChar **values)
{
xmlChar *str = NULL, *msg = NULL;
xmlChar *localName, *nsName;
const xmlChar *cur, *end;
int i;
xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0);
/* Specify the complex type only if it is global. */
if ((type != NULL) && (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) {
msg = xmlStrcat(msg, BAD_CAST " [");
msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0));
msg = xmlStrcat(msg, BAD_CAST "]");
FREE_AND_NULL(str)
}
msg = xmlStrcat(msg, BAD_CAST ": ");
msg = xmlStrcat(msg, (const xmlChar *) message);
/*
* Note that is does not make sense to report that we have a
* wildcard here, since the wildcard might be unfolded into
* multiple transitions.
*/
if (nbval + nbneg > 0) {
if (nbval + nbneg > 1) {
str = xmlStrdup(BAD_CAST ". Expected is one of ");
} else
str = xmlStrdup(BAD_CAST ". Expected is ");
nsName = NULL;
for (i = 0; i < nbval + nbneg; i++) {
cur = values[i];
/*
* Get the local name.
*/
localName = NULL;
end = cur;
if (*end == '*') {
localName = xmlStrdup(BAD_CAST "*");
*end++;
} else {
while ((*end != 0) && (*end != '|'))
end++;
localName = xmlStrcat(localName, BAD_CAST "'");
localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
localName = xmlStrcat(localName, BAD_CAST "'");
}
if (*end != 0) {
*end++;
/*
* Skip "*|*" if they come with negated expressions, since
* they represent the same negated wildcard.
*/
if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
/*
* Get the namespace name.
*/
cur = end;
if (*end == '*') {
nsName = xmlStrdup(BAD_CAST "{*}");
} else {
while (*end != 0)
end++;
if (i >= nbval)
nsName = xmlStrdup(BAD_CAST "{##other:");
else
nsName = xmlStrdup(BAD_CAST "{");
nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
nsName = xmlStrcat(nsName, BAD_CAST "}");
}
str = xmlStrcat(str, BAD_CAST nsName);
FREE_AND_NULL(nsName)
} else {
FREE_AND_NULL(localName);
continue;
}
}
str = xmlStrcat(str, BAD_CAST localName);
FREE_AND_NULL(localName);
if (i < nbval + nbneg -1)
str = xmlStrcat(str, BAD_CAST ", ");
}
msg = xmlStrcat(msg, BAD_CAST str);
FREE_AND_NULL(str)
}
msg = xmlStrcat(msg, BAD_CAST ".\n");
xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL);
xmlFree(msg);
}
/**
* xmlSchemaPMissingAttrErr:
* @ctxt: the schema validation context
@ -8552,7 +8663,7 @@ xmlSchemaBuildAContentModel(xmlSchemaTypePtr type,
oldstate = ctxt->state;
counter = xmlAutomataNewCounter(ctxt->am,
particle->minOccurs - 1, UNBOUNDED);
ctxt->state =
ctxt->state =
xmlAutomataNewTransition2(ctxt->am,
ctxt->state, NULL,
elemDecl->name,
@ -14710,8 +14821,6 @@ xmlSchemaValidateSimpleTypeValue(xmlSchemaValidCtxtPtr ctxt,
* in the ·lexical space· of {item type definition}
*/
if (value == NULL)
value = BAD_CAST "";
tmpType = xmlSchemaGetListSimpleTypeItemType(type);
cur = value;
do {
@ -15849,6 +15958,8 @@ xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt,
case XML_SCHEMA_CONTENT_ELEMENTS:
{
xmlRegExecCtxtPtr oldregexp = NULL;
xmlChar *values[10];
int terminal, nbval = 10, nbneg;
/*
* Content model check initialization.
@ -15877,8 +15988,10 @@ xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt,
/*
* URGENT TODO: Could we anchor an error report
* here to notify of invalid elements?
* TODO: Perhaps it would be better to report
* only the first erroneous element and then break.
*/
#ifdef DEBUG_AUTOMATA
#ifdef DEBUG_AUTOMATA
if (ret < 0)
xmlGenericError(xmlGenericErrorContext,
" --> %s Error\n", child->name);
@ -15887,11 +16000,19 @@ xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt,
" --> %s\n", child->name);
#endif
if (ret < 0) {
xmlSchemaVComplexTypeErr(ctxt,
xmlRegExecErrInfo(ctxt->regexp, NULL, &nbval, &nbneg,
&values[0], &terminal);
xmlSchemaVComplexTypeElemErr(ctxt,
XML_SCHEMAV_ELEMENT_CONTENT,
child, NULL/* type */,
"This element is not expected");
"This element is not expected",
nbval, nbneg, values);
ret = 1;
/*
* Note that this will skip further validation of the
* content.
*/
break;
}
} else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) &&
/*
@ -15922,29 +16043,36 @@ xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt,
* Content model check finalization.
*/
if (type->contModel != NULL) {
if (ret != 1) {
ret = xmlRegExecPushString(ctxt->regexp, NULL, NULL);
if (ret == 0) {
xmlRegExecNextValues(ctxt->regexp, &nbval, &nbneg,
&values[0], &terminal);
if (nbval + nbneg != 0) {
/*
* If a next value still exists, I does not have to
* mean that there's an element missing, since it
* might be an optional element. So double check it.
*/
ret = xmlRegExecPushString(ctxt->regexp,
NULL, NULL);
if (ret <= 0) {
ret = 1;
xmlSchemaVComplexTypeElemErr(ctxt,
XML_SCHEMAV_ELEMENT_CONTENT,
elem, type, "Missing child element(s)",
nbval, nbneg, values);
} else
ret = 0;
#ifdef DEBUG_AUTOMATA
xmlGenericError(xmlGenericErrorContext,
"====> %s : %d\n", elem->name, ret);
xmlGenericError(xmlGenericErrorContext,
"====> %s : %d\n", elem->name, ret);
#endif
if (ret == 0) {
/* TODO: Hmm, can this one really happen? */
xmlSchemaVComplexTypeErr(ctxt,
XML_SCHEMAV_ELEMENT_CONTENT,
elem, type, "Missing child element(s)");
} else if (ret < 0) {
xmlSchemaVComplexTypeErr(ctxt,
XML_SCHEMAV_ELEMENT_CONTENT,
elem, type, "Missing child element(s)");
}
#ifdef DEBUG_CONTENT
} else {
if (ret == 0)
xmlGenericError(xmlGenericErrorContext,
"Element %s content check succeeded\n",
elem->name);
#endif
}
}
xmlRegFreeExecCtxt(ctxt->regexp);
ctxt->regexp = oldregexp;
@ -16071,8 +16199,8 @@ xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt,
}
}
if (value != NULL)
xmlFree(value);
xmlFree(value);
}
break;
default: