From ea3f398c3905b0c1e57eb0cc897ccc5bccd95d67 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 26 Jan 2003 19:45:18 +0000 Subject: [PATCH] more work on Relax-NG augmented/updated the regression tests Daniel * relaxng.c: more work on Relax-NG * test/relaxng/* result/relaxng/*: augmented/updated the regression tests Daniel --- ChangeLog | 6 +++ relaxng.c | 94 ++++++++++++++++++++++++++++++++--- result/relaxng/tutor3_2_1.err | 2 +- result/relaxng/tutor3_5_2.err | 2 +- result/relaxng/tutor5_1_1.err | 4 +- result/relaxng/tutor5_2_1.err | 8 +-- result/relaxng/tutor5_3_1.err | 2 +- result/relaxng/tutor6_1_3 | 2 +- result/relaxng/tutor6_1_3.err | 2 +- result/relaxng/tutor6_1_4 | 1 + result/relaxng/tutor6_1_4.err | 4 ++ result/relaxng/tutor6_1_5 | 1 + result/relaxng/tutor6_1_5.err | 4 ++ result/relaxng/tutor6_2_1 | 1 + result/relaxng/tutor6_2_1.err | 4 ++ result/relaxng/tutor6_2_2 | 1 + result/relaxng/tutor6_2_2.err | 4 ++ result/relaxng/tutor6_2_3 | 1 + result/relaxng/tutor6_2_3.err | 4 ++ result/relaxng/tutor6_2_4 | 2 + result/relaxng/tutor6_2_4.err | 5 ++ result/relaxng/tutor6_3_1 | 2 + result/relaxng/tutor6_3_1.err | 5 ++ test/relaxng/tutor6_1_4.xml | 1 + test/relaxng/tutor6_1_5.xml | 2 + test/relaxng/tutor6_2_1.xml | 5 ++ test/relaxng/tutor6_2_2.xml | 5 ++ test/relaxng/tutor6_2_3.xml | 5 ++ test/relaxng/tutor6_2_4.xml | 5 ++ test/relaxng/tutor6_3_1.xml | 1 + 30 files changed, 166 insertions(+), 19 deletions(-) create mode 100644 result/relaxng/tutor6_1_4 create mode 100644 result/relaxng/tutor6_1_4.err create mode 100644 result/relaxng/tutor6_1_5 create mode 100644 result/relaxng/tutor6_1_5.err create mode 100644 result/relaxng/tutor6_2_1 create mode 100644 result/relaxng/tutor6_2_1.err create mode 100644 result/relaxng/tutor6_2_2 create mode 100644 result/relaxng/tutor6_2_2.err create mode 100644 result/relaxng/tutor6_2_3 create mode 100644 result/relaxng/tutor6_2_3.err create mode 100644 result/relaxng/tutor6_2_4 create mode 100644 result/relaxng/tutor6_2_4.err create mode 100644 result/relaxng/tutor6_3_1 create mode 100644 result/relaxng/tutor6_3_1.err create mode 100644 test/relaxng/tutor6_1_4.xml create mode 100644 test/relaxng/tutor6_1_5.xml create mode 100644 test/relaxng/tutor6_2_1.xml create mode 100644 test/relaxng/tutor6_2_2.xml create mode 100644 test/relaxng/tutor6_2_3.xml create mode 100644 test/relaxng/tutor6_2_4.xml create mode 100644 test/relaxng/tutor6_3_1.xml diff --git a/ChangeLog b/ChangeLog index bbe98d7c..9974d093 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Jan 26 20:38:43 CET 2003 Daniel Veillard + + * relaxng.c: more work on Relax-NG + * test/relaxng/* result/relaxng/*: augmented/updated the + regression tests + Sun Jan 26 01:49:58 CET 2003 Daniel Veillard * relaxng.c: more work on Relax-NG diff --git a/relaxng.c b/relaxng.c index 2391f72f..a104d8eb 100644 --- a/relaxng.c +++ b/relaxng.c @@ -653,6 +653,8 @@ xmlRelaxNGErrorContext(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGPtr schema, * Type library hooks * * * ************************************************************************/ +static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt, + const xmlChar *str); /** * xmlRelaxNGSchemaTypeHave: @@ -767,8 +769,31 @@ xmlRelaxNGDefaultTypeCompare(void *data ATTRIBUTE_UNUSED, const xmlChar *type ATTRIBUTE_UNUSED, const xmlChar *value1 ATTRIBUTE_UNUSED, const xmlChar *value2 ATTRIBUTE_UNUSED) { - TODO - return(1); + int ret = -1; + + if (xmlStrEqual(type, BAD_CAST "string")) { + ret = xmlStrEqual(value1, value2); + } else if (xmlStrEqual(type, BAD_CAST "token")) { + if (!xmlStrEqual(value1, value2)) { + xmlChar *nval, *nvalue; + + /* + * TODO: trivial optimizations are possible by + * computing at compile-time + */ + nval = xmlRelaxNGNormalize(NULL, value1); + nvalue = xmlRelaxNGNormalize(NULL, value2); + + if ((nval == NULL) || (nvalue == NULL) || + (!xmlStrEqual(nval, nvalue))) + ret = -1; + if (nval != NULL) + xmlFree(nval); + if (nvalue != NULL) + xmlFree(nvalue); + } + } + return(ret); } static int xmlRelaxNGTypeInitialized = 0; @@ -2656,8 +2681,13 @@ xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt, const xmlChar *str) { ret = (xmlChar *) xmlMalloc((len + 1) * sizeof(xmlChar)); if (ret == NULL) { - VALID_CTXT(); - VALID_ERROR("xmlRelaxNGNormalize: out of memory\n"); + if (ctxt != NULL) { + VALID_CTXT(); + VALID_ERROR("xmlRelaxNGNormalize: out of memory\n"); + } else { + xmlGenericError(xmlGenericErrorContext, + "xmlRelaxNGNormalize: out of memory\n"); + } return(NULL); } p = ret; @@ -2756,7 +2786,24 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, case XML_RELAXNG_VALUE: { if (!xmlStrEqual(value, define->value)) { if (define->name != NULL) { - TODO /* value validation w.r.t. the type */ + xmlRelaxNGTypeLibraryPtr lib; + + lib = (xmlRelaxNGTypeLibraryPtr) define->data; + if ((lib != NULL) && (lib->comp != NULL)) + ret = lib->comp(lib->data, define->name, value, + define->value); + else + ret = -1; + if (ret < 0) { + VALID_CTXT(); + VALID_ERROR("Internal: failed to compare type %s\n", + define->name); + return(-1); + } else if (ret == 1) { + ret = 0; + } else { + ret = -1; + } } else { xmlChar *nval, *nvalue; @@ -2767,7 +2814,8 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, nval = xmlRelaxNGNormalize(ctxt, define->value); nvalue = xmlRelaxNGNormalize(ctxt, value); - if (!xmlStrEqual(nval, nvalue)) + if ((nval == NULL) || (nvalue == NULL) || + (!xmlStrEqual(nval, nvalue))) ret = -1; if (nval != NULL) xmlFree(nval); @@ -3036,7 +3084,7 @@ xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt, for (i = 0;i < state->nbAttrs;i++) { if (state->attrs[i] != NULL) { VALID_CTXT(); - VALID_ERROR("Extra attribute %s for element %s\n", + VALID_ERROR("Invalid attribute %s for element %s\n", state->attrs[i]->name, node->name); ret = -1; } @@ -3169,7 +3217,37 @@ xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt, xmlFree(content); break; } - case XML_RELAXNG_VALUE: + case XML_RELAXNG_VALUE: { + xmlChar *content; + xmlChar *oldvalue; + + content = xmlNodeGetContent(node); + oldvalue = ctxt->state->value; + ctxt->state->value = content; + ret = xmlRelaxNGValidateValue(ctxt, define); + ctxt->state->value = oldvalue; + if (ret == -1) { + VALID_CTXT(); + VALID_ERROR("internal error validating %s\n", define->name); + } else if (ret == 0) { + ctxt->state->seq = node->next; + } + /* + * TODO cover the problems with + *

1234

+ * TODO detect full element coverage at compilation time. + */ + if ((node != NULL) && (node->next != NULL)) { + VALID_CTXT(); + VALID_ERROR("The data does not cover the full element %s\n", + node->parent->name); + ret = -1; + } + if (content != NULL) + xmlFree(content); + break; + } + TODO break; } diff --git a/result/relaxng/tutor3_2_1.err b/result/relaxng/tutor3_2_1.err index 48ac0c4a..6904d3bc 100644 --- a/result/relaxng/tutor3_2_1.err +++ b/result/relaxng/tutor3_2_1.err @@ -1,3 +1,3 @@ -error detected at relaxng.c:2982 error detected at relaxng.c:3030 +error detected at relaxng.c:3078 xmlRelaxNGValidateDefinition(): validated card : -1 diff --git a/result/relaxng/tutor3_5_2.err b/result/relaxng/tutor3_5_2.err index 9c72d176..cb3157b4 100644 --- a/result/relaxng/tutor3_5_2.err +++ b/result/relaxng/tutor3_5_2.err @@ -1,5 +1,5 @@ xmlRelaxNGValidateAttribute(name): -1 xmlRelaxNGValidateDefinition(): validated email : 0 xmlRelaxNGValidateDefinition(): validated card : -1 -error detected at relaxng.c:3030 +error detected at relaxng.c:3078 xmlRelaxNGValidateDefinition(): validated addressBook : -1 diff --git a/result/relaxng/tutor5_1_1.err b/result/relaxng/tutor5_1_1.err index e9fa2d92..fa62fe3e 100644 --- a/result/relaxng/tutor5_1_1.err +++ b/result/relaxng/tutor5_1_1.err @@ -1,3 +1,3 @@ -Unimplemented block at relaxng.c:670 -Unimplemented block at relaxng.c:689 +Unimplemented block at relaxng.c:672 +Unimplemented block at relaxng.c:691 xmlRelaxNGValidateDefinition(): validated number : 0 diff --git a/result/relaxng/tutor5_2_1.err b/result/relaxng/tutor5_2_1.err index ac9beb0e..b56a85ac 100644 --- a/result/relaxng/tutor5_2_1.err +++ b/result/relaxng/tutor5_2_1.err @@ -1,7 +1,7 @@ -Unimplemented block at relaxng.c:670 -Unimplemented block at relaxng.c:670 -Unimplemented block at relaxng.c:689 +Unimplemented block at relaxng.c:672 +Unimplemented block at relaxng.c:672 +Unimplemented block at relaxng.c:691 xmlRelaxNGValidateDefinition(): validated x : 0 -Unimplemented block at relaxng.c:689 +Unimplemented block at relaxng.c:691 xmlRelaxNGValidateDefinition(): validated y : 0 xmlRelaxNGValidateDefinition(): validated point : 0 diff --git a/result/relaxng/tutor5_3_1.err b/result/relaxng/tutor5_3_1.err index 5f30338e..b4edac2c 100644 --- a/result/relaxng/tutor5_3_1.err +++ b/result/relaxng/tutor5_3_1.err @@ -1,3 +1,3 @@ -error detected at relaxng.c:3163 +error detected at relaxng.c:3211 xmlRelaxNGValidateDefinition(): validated note : 0 xmlRelaxNGValidateDefinition(): validated bad : -1 diff --git a/result/relaxng/tutor6_1_3 b/result/relaxng/tutor6_1_3 index 2dea6749..56aa11c4 100644 --- a/result/relaxng/tutor6_1_3 +++ b/result/relaxng/tutor6_1_3 @@ -1,2 +1,2 @@ -Extra attribute preferredFormat for element card +Invalid attribute preferredFormat for element card ./test/relaxng/tutor6_1_3.xml validation generated an internal error diff --git a/result/relaxng/tutor6_1_3.err b/result/relaxng/tutor6_1_3.err index 68f183fd..a0bb286b 100644 --- a/result/relaxng/tutor6_1_3.err +++ b/result/relaxng/tutor6_1_3.err @@ -1,5 +1,5 @@ xmlRelaxNGValidateAttribute(preferredFormat): -1 xmlRelaxNGValidateAttribute(email): 0 xmlRelaxNGValidateAttribute(name): 0 -error detected at relaxng.c:3038 +error detected at relaxng.c:3086 xmlRelaxNGValidateDefinition(): validated card : -1 diff --git a/result/relaxng/tutor6_1_4 b/result/relaxng/tutor6_1_4 new file mode 100644 index 00000000..d9b2291e --- /dev/null +++ b/result/relaxng/tutor6_1_4 @@ -0,0 +1 @@ +./test/relaxng/tutor6_1_4.xml validates diff --git a/result/relaxng/tutor6_1_4.err b/result/relaxng/tutor6_1_4.err new file mode 100644 index 00000000..6e456218 --- /dev/null +++ b/result/relaxng/tutor6_1_4.err @@ -0,0 +1,4 @@ +xmlRelaxNGValidateAttribute(preferredFormat): 0 +xmlRelaxNGValidateAttribute(email): 0 +xmlRelaxNGValidateAttribute(name): 0 +xmlRelaxNGValidateDefinition(): validated card : 0 diff --git a/result/relaxng/tutor6_1_5 b/result/relaxng/tutor6_1_5 new file mode 100644 index 00000000..f601d7eb --- /dev/null +++ b/result/relaxng/tutor6_1_5 @@ -0,0 +1 @@ +./test/relaxng/tutor6_1_5.xml validates diff --git a/result/relaxng/tutor6_1_5.err b/result/relaxng/tutor6_1_5.err new file mode 100644 index 00000000..6e456218 --- /dev/null +++ b/result/relaxng/tutor6_1_5.err @@ -0,0 +1,4 @@ +xmlRelaxNGValidateAttribute(preferredFormat): 0 +xmlRelaxNGValidateAttribute(email): 0 +xmlRelaxNGValidateAttribute(name): 0 +xmlRelaxNGValidateDefinition(): validated card : 0 diff --git a/result/relaxng/tutor6_2_1 b/result/relaxng/tutor6_2_1 new file mode 100644 index 00000000..d07807be --- /dev/null +++ b/result/relaxng/tutor6_2_1 @@ -0,0 +1 @@ +./test/relaxng/tutor6_2_1.xml validates diff --git a/result/relaxng/tutor6_2_1.err b/result/relaxng/tutor6_2_1.err new file mode 100644 index 00000000..fab4d8dc --- /dev/null +++ b/result/relaxng/tutor6_2_1.err @@ -0,0 +1,4 @@ +xmlRelaxNGValidateDefinition(): validated name : 0 +xmlRelaxNGValidateDefinition(): validated email : 0 +xmlRelaxNGValidateDefinition(): validated preferredFormat : 0 +xmlRelaxNGValidateDefinition(): validated card : 0 diff --git a/result/relaxng/tutor6_2_2 b/result/relaxng/tutor6_2_2 new file mode 100644 index 00000000..df100759 --- /dev/null +++ b/result/relaxng/tutor6_2_2 @@ -0,0 +1 @@ +./test/relaxng/tutor6_2_2.xml validates diff --git a/result/relaxng/tutor6_2_2.err b/result/relaxng/tutor6_2_2.err new file mode 100644 index 00000000..fab4d8dc --- /dev/null +++ b/result/relaxng/tutor6_2_2.err @@ -0,0 +1,4 @@ +xmlRelaxNGValidateDefinition(): validated name : 0 +xmlRelaxNGValidateDefinition(): validated email : 0 +xmlRelaxNGValidateDefinition(): validated preferredFormat : 0 +xmlRelaxNGValidateDefinition(): validated card : 0 diff --git a/result/relaxng/tutor6_2_3 b/result/relaxng/tutor6_2_3 new file mode 100644 index 00000000..17602d31 --- /dev/null +++ b/result/relaxng/tutor6_2_3 @@ -0,0 +1 @@ +./test/relaxng/tutor6_2_3.xml validates diff --git a/result/relaxng/tutor6_2_3.err b/result/relaxng/tutor6_2_3.err new file mode 100644 index 00000000..fab4d8dc --- /dev/null +++ b/result/relaxng/tutor6_2_3.err @@ -0,0 +1,4 @@ +xmlRelaxNGValidateDefinition(): validated name : 0 +xmlRelaxNGValidateDefinition(): validated email : 0 +xmlRelaxNGValidateDefinition(): validated preferredFormat : 0 +xmlRelaxNGValidateDefinition(): validated card : 0 diff --git a/result/relaxng/tutor6_2_4 b/result/relaxng/tutor6_2_4 new file mode 100644 index 00000000..4d52fa11 --- /dev/null +++ b/result/relaxng/tutor6_2_4 @@ -0,0 +1,2 @@ +Extra content for element preferredFormat +./test/relaxng/tutor6_2_4.xml validation generated an internal error diff --git a/result/relaxng/tutor6_2_4.err b/result/relaxng/tutor6_2_4.err new file mode 100644 index 00000000..2f65d346 --- /dev/null +++ b/result/relaxng/tutor6_2_4.err @@ -0,0 +1,5 @@ +xmlRelaxNGValidateDefinition(): validated name : 0 +xmlRelaxNGValidateDefinition(): validated email : 0 +error detected at relaxng.c:3078 +xmlRelaxNGValidateDefinition(): validated preferredFormat : -1 +xmlRelaxNGValidateDefinition(): validated card : -1 diff --git a/result/relaxng/tutor6_3_1 b/result/relaxng/tutor6_3_1 new file mode 100644 index 00000000..8a9225c6 --- /dev/null +++ b/result/relaxng/tutor6_3_1 @@ -0,0 +1,2 @@ +Invalid attribute preferredFormat for element card +./test/relaxng/tutor6_3_1.xml validation generated an internal error diff --git a/result/relaxng/tutor6_3_1.err b/result/relaxng/tutor6_3_1.err new file mode 100644 index 00000000..a0bb286b --- /dev/null +++ b/result/relaxng/tutor6_3_1.err @@ -0,0 +1,5 @@ +xmlRelaxNGValidateAttribute(preferredFormat): -1 +xmlRelaxNGValidateAttribute(email): 0 +xmlRelaxNGValidateAttribute(name): 0 +error detected at relaxng.c:3086 +xmlRelaxNGValidateDefinition(): validated card : -1 diff --git a/test/relaxng/tutor6_1_4.xml b/test/relaxng/tutor6_1_4.xml new file mode 100644 index 00000000..0ad64dd5 --- /dev/null +++ b/test/relaxng/tutor6_1_4.xml @@ -0,0 +1 @@ + diff --git a/test/relaxng/tutor6_1_5.xml b/test/relaxng/tutor6_1_5.xml new file mode 100644 index 00000000..c5d22bd2 --- /dev/null +++ b/test/relaxng/tutor6_1_5.xml @@ -0,0 +1,2 @@ + + diff --git a/test/relaxng/tutor6_2_1.xml b/test/relaxng/tutor6_2_1.xml new file mode 100644 index 00000000..5064bf23 --- /dev/null +++ b/test/relaxng/tutor6_2_1.xml @@ -0,0 +1,5 @@ + + John Smith + js@example.com + text + diff --git a/test/relaxng/tutor6_2_2.xml b/test/relaxng/tutor6_2_2.xml new file mode 100644 index 00000000..57da2e88 --- /dev/null +++ b/test/relaxng/tutor6_2_2.xml @@ -0,0 +1,5 @@ + + John Smith + js@example.com + html + diff --git a/test/relaxng/tutor6_2_3.xml b/test/relaxng/tutor6_2_3.xml new file mode 100644 index 00000000..acca979d --- /dev/null +++ b/test/relaxng/tutor6_2_3.xml @@ -0,0 +1,5 @@ + + John Smith + js@example.com + html + diff --git a/test/relaxng/tutor6_2_4.xml b/test/relaxng/tutor6_2_4.xml new file mode 100644 index 00000000..c3f723b2 --- /dev/null +++ b/test/relaxng/tutor6_2_4.xml @@ -0,0 +1,5 @@ + + John Smith + js@example.com + error + diff --git a/test/relaxng/tutor6_3_1.xml b/test/relaxng/tutor6_3_1.xml new file mode 100644 index 00000000..0ad64dd5 --- /dev/null +++ b/test/relaxng/tutor6_3_1.xml @@ -0,0 +1 @@ +