diff options
Diffstat (limited to 'xsd-tests/cxx/parser/validation/restriction')
4 files changed, 370 insertions, 0 deletions
diff --git a/xsd-tests/cxx/parser/validation/restriction/buildfile b/xsd-tests/cxx/parser/validation/restriction/buildfile new file mode 100644 index 0000000..4c415bf --- /dev/null +++ b/xsd-tests/cxx/parser/validation/restriction/buildfile @@ -0,0 +1,22 @@ +# file : cxx/parser/validation/restriction/buildfile +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +import libs = libxsd%lib{xsd} +import libs += libxerces-c%lib{xerces-c} + +exe{driver}: {hxx cxx}{* -test-pskel} {hxx ixx cxx}{test-pskel} $libs \ + testscript + +<{hxx ixx cxx}{test-pskel}>: xsd{test} $xsd +{{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-parser --std c++11 \ + --generate-inline \ + --skel-file-suffix -pskel \ + --output-dir $out_base \ + --generate-validation \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" diff --git a/xsd-tests/cxx/parser/validation/restriction/driver.cxx b/xsd-tests/cxx/parser/validation/restriction/driver.cxx new file mode 100644 index 0000000..206b9f8 --- /dev/null +++ b/xsd-tests/cxx/parser/validation/restriction/driver.cxx @@ -0,0 +1,107 @@ +// file : cxx/parser/validation/restriction/driver.cxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the restriction compositor validation. +// + +#include <string> +#include <fstream> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct base_a_pimpl: base_a_pskel +{ +}; + +struct restriction_a_pimpl: restriction_a_pskel +{ +}; + +struct extension_b_pimpl: extension_b_pskel +{ +}; + +struct restriction_b_pimpl: restriction_b_pskel +{ +}; + +struct type_b_pimpl: type_b_pskel +{ +}; + +struct type_r_pimpl: type_r_pskel +{ +}; + + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + try + { + xml_schema::string_pimpl string_p; + base_a_pimpl base_a_p; + restriction_a_pimpl restriction_a_p; + extension_b_pimpl extension_b_p; + restriction_b_pimpl restriction_b_p; + type_b_pimpl type_b_p; + type_r_pimpl type_r_p; + + base_a_p.parsers (string_p, string_p, string_p, + string_p, string_p, string_p); + + restriction_a_p.parsers (string_p, string_p, string_p, + string_p, string_p, string_p); + + extension_b_p.parsers (string_p, string_p, string_p, + string_p, string_p); + + restriction_b_p.parsers (string_p, string_p, string_p, + string_p, string_p); + + type_b_p.parsers (base_a_p, extension_b_p); + type_r_p.parsers (restriction_a_p, restriction_b_p); + + xml_schema::document doc_b_p (type_b_p, "test", "root"); + xml_schema::document doc_r_p (type_r_p, "test", "root"); + + { + ifstream ifs (argv[1]); + type_b_p.pre (); + doc_b_p.parse (ifs, argv[1], "", xml_schema::flags::dont_validate); + type_b_p.post_type_b (); + } + + try + { + ifstream ifs (argv[1]); + type_r_p.pre (); + doc_r_p.parse (ifs, argv[1], "", xml_schema::flags::dont_validate); + type_r_p.post_type_r (); + } + catch (xml_schema::exception const& e) + { + cout << e << endl; + } + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/xsd-tests/cxx/parser/validation/restriction/test.xsd b/xsd-tests/cxx/parser/validation/restriction/test.xsd new file mode 100644 index 0000000..158ded5 --- /dev/null +++ b/xsd-tests/cxx/parser/validation/restriction/test.xsd @@ -0,0 +1,82 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- simple case --> + <complexType name="base-a"> + <sequence minOccurs="1" maxOccurs="2"> + <element name="a" type="string" minOccurs="0"/> + <element name="b" type="string"/> + <element name="c" type="string"/> + </sequence> + <attribute name="x" type="string"/> + <attribute name="y" type="string"/> + <attribute name="z" type="string"/> + </complexType> + + <complexType name="restriction-a"> + <complexContent> + <restriction base="t:base-a"> + <sequence minOccurs="1" maxOccurs="1"> + <element name="a" type="string" minOccurs="1"/> + <element name="b" type="string"/> + <element name="c" type="string"/> + </sequence> + <!-- Can be ommited if not changed, e.g., 'x'. --> + <attribute name="y" type="string"/> <!-- But can also be repeated without change. --> + <attribute name="z" type="string" use="required"/> + </restriction> + </complexContent> + </complexType> + + <!-- restriction of an extension --> + <complexType name="base-b"> + <sequence> + <element name="a" type="string" minOccurs="0"/> + </sequence> + <attribute name="x" type="string"/> + </complexType> + + <complexType name="extension-b"> + <complexContent> + <extension base="t:base-b"> + <choice> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string"/> + </choice> + <attribute name="y" type="string"/> + </extension> + </complexContent> + </complexType> + + <complexType name="restriction-b"> + <complexContent> + <restriction base="t:extension-b"> + <sequence> + <sequence> + <element name="a" type="string" minOccurs="1"/> + </sequence> + <choice> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string"/> + </choice> + </sequence> + <attribute name="y" type="string" use="required"/> + </restriction> + </complexContent> + </complexType> + + <complexType name="type-b"> + <choice maxOccurs="unbounded"> + <element name="restriction-a" type="t:base-a"/> + <element name="restriction-b" type="t:extension-b"/> + </choice> + </complexType> + + <complexType name="type-r"> + <choice maxOccurs="unbounded"> + <element name="restriction-a" type="t:restriction-a"/> + <element name="restriction-b" type="t:restriction-b"/> + </choice> + </complexType> + +</schema> diff --git a/xsd-tests/cxx/parser/validation/restriction/testscript b/xsd-tests/cxx/parser/validation/restriction/testscript new file mode 100644 index 0000000..ea5a4e8 --- /dev/null +++ b/xsd-tests/cxx/parser/validation/restriction/testscript @@ -0,0 +1,159 @@ +# file : cxx/parser/validation/all/testscript +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +test.arguments += test.xml + +: valid +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <restriction-a z="z"> + <a>a</a> + <b>b</b> + <c>c</c> + </restriction-a> + + <restriction-a x="x" y="y" z="z"> + <a>a</a> + <b>b</b> + <c>c</c> + </restriction-a> + + <restriction-b y="y"> + <a>a</a> + <b>b</b> + </restriction-b> + + <restriction-b y="y"> + <a>a</a> + <c>c</c> + </restriction-b> + + <restriction-b x="x" y="y"> + <a>a</a> + </restriction-b> + + </t:root> + EOI + + $* +} + +: invalid1 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- valid base but not restriction: a element --> + <restriction-a z="z"> + <b>b</b> + <c>c</c> + </restriction-a> + + </t:root> + EOI + + $* >>EOO + :7:8 error: expected element 'a' instead of 'b' + EOO +} + +: invalid2 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- valid base but not restriction: z attribute --> + <restriction-a> + <a>a</a> + <b>b</b> + <c>c</c> + </restriction-a> + + </t:root> + EOI + + $* >>EOO + :10:19 error: expected attribute 'z' + EOO +} + +: invalid3 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- valid base but not restriction: sequence maxOccurs="1" --> + <restriction-a z="z"> + <a>a</a> + <b>b</b> + <c>c</c> + + <a>a</a> + <b>b</b> + <c>c</c> + </restriction-a> + + </t:root> + EOI + + $* >>EOO + :11:8 error: unexpected element 'a' + EOO +} + +: invalid4 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- valid extension but not restriction: a element --> + <restriction-b y="y"> + <b>b</b> + </restriction-b> + + </t:root> + EOI + + $* >>EOO + :7:8 error: expected element 'a' instead of 'b' + EOO +} + +: invalid5 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- valid extension but not restriction: y attribute --> + <restriction-b> + <a>a</a> + <b>b</b> + </restriction-b> + + </t:root> + EOI + + $* >>EOO + :9:19 error: expected attribute 'y' + EOO +} |