diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-18 18:48:46 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-02-25 13:45:48 +0300 |
commit | 5e527213a2430bb3018e5eebd909aef294edf9b5 (patch) | |
tree | 94de33c82080b53d9a9e300170f6d221d89078f4 /xsd-tests/cxx/parser/validation/choice | |
parent | 7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff) |
Switch to build2
Diffstat (limited to 'xsd-tests/cxx/parser/validation/choice')
-rw-r--r-- | xsd-tests/cxx/parser/validation/choice/buildfile | 22 | ||||
-rw-r--r-- | xsd-tests/cxx/parser/validation/choice/driver.cxx | 126 | ||||
-rw-r--r-- | xsd-tests/cxx/parser/validation/choice/test.xsd | 24 | ||||
-rw-r--r-- | xsd-tests/cxx/parser/validation/choice/testscript | 179 |
4 files changed, 351 insertions, 0 deletions
diff --git a/xsd-tests/cxx/parser/validation/choice/buildfile b/xsd-tests/cxx/parser/validation/choice/buildfile new file mode 100644 index 0000000..adf0832 --- /dev/null +++ b/xsd-tests/cxx/parser/validation/choice/buildfile @@ -0,0 +1,22 @@ +# file : cxx/parser/validation/choice/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/choice/driver.cxx b/xsd-tests/cxx/parser/validation/choice/driver.cxx new file mode 100644 index 0000000..4a52c5d --- /dev/null +++ b/xsd-tests/cxx/parser/validation/choice/driver.cxx @@ -0,0 +1,126 @@ +// file : cxx/parser/validation/choice/driver.cxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the choice compositor validation. +// + +#include <string> +#include <fstream> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; +using xml_schema::ro_string; + +struct choice_pimpl: choice_pskel +{ + virtual void + pre () + { + cout << "{" << endl; + } + + virtual void + a (string const& v) + { + cout << " a = " << v << endl; + } + + virtual void + b (string const& v) + { + cout << " b = " << v << endl; + } + + virtual void + c (string const& v) + { + cout << " c = " << v << endl; + } + + virtual void + d (string const& v) + { + cout << " d = " << v << endl; + } + + virtual void + _start_any_element (ro_string const& ns, + ro_string const& name, + ro_string const*) + { + cout << " any: " << ns << "#" << name << endl + << " {" << endl; + } + + virtual void + _any_characters (ro_string const& v) + { + cout << " chars = " << v << endl; + } + + virtual void + _end_any_element (ro_string const&, ro_string const&) + { + cout << " }" << endl; + } + + virtual void + post_choice () + { + cout << "}" << endl + << endl; + } +}; + +struct type_pimpl: type_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; + choice_pimpl choice_p; + type_pimpl type_p; + + choice_p.parsers (string_p, string_p, string_p, string_p); + type_p.parsers (choice_p); + + xml_schema::document doc_p (type_p, "test", "root"); + + try + { + ifstream ifs (argv[1]); + type_p.pre (); + doc_p.parse (ifs, argv[1], "", xml_schema::flags::dont_validate); + type_p.post_type (); + } + catch (xml_schema::exception const& e) + { + cout << " " << e << endl + << "}" << endl + << 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/choice/test.xsd b/xsd-tests/cxx/parser/validation/choice/test.xsd new file mode 100644 index 0000000..8132bbb --- /dev/null +++ b/xsd-tests/cxx/parser/validation/choice/test.xsd @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="choice"> + <choice maxOccurs="3"> + <element name="a" type="string"/> + <element name="b" type="string" maxOccurs="unbounded"/> + <sequence> + <element name="c" type="string" minOccurs="0"/> + <element name="d" type="string"/> + </sequence> + <any namespace="other" maxOccurs="unbounded"/> + </choice> + </complexType> + + <complexType name="type"> + <sequence> + <element name="choice" type="t:choice" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd-tests/cxx/parser/validation/choice/testscript b/xsd-tests/cxx/parser/validation/choice/testscript new file mode 100644 index 0000000..c5f5afa --- /dev/null +++ b/xsd-tests/cxx/parser/validation/choice/testscript @@ -0,0 +1,179 @@ +# file : cxx/parser/validation/choice/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:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <choice> + <a>a</a> + + <b>b</b> + </choice> + + <choice> + <c>c</c> + <d>d</d> + + <o:any>any</o:any> + + <a>a</a> + </choice> + + <choice> + <c>c</c> + <d>d</d> + + <d>d</d> + + <a>a</a> + </choice> + + </t:root> + EOI + + $* >>EOO + { + a = a + b = b + } + + { + c = c + d = d + any: other#any + { + chars = any + } + a = a + } + + { + c = c + d = d + d = d + a = a + } + + EOO +} + +: absent1 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- invalid --> + <choice> + </choice> + + </t:root> + EOI + + $* >>EOO + { + :8:12 error: expected element 'a' + } + + EOO +} + +: absent2 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- invalid --> + <choice> + <c>c</c> + <d>d</d> + + <o:any>any</o:any> + + <a>a</a> + <b>b</b> + </choice> + + </t:root> + EOI + + $* >>EOO + { + c = c + d = d + any: other#any + { + chars = any + } + a = a + :14:8 error: unexpected element 'b' + } + + EOO +} + +: absent3 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- invalid --> + <choice> + <c>c</c> + </choice> + + </t:root> + EOI + + $* >>EOO + { + c = c + :9:12 error: expected element 'd' + } + + EOO +} + +: absent4 +: +{ + cat <<EOI >=test.xml; + <t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- invalid --> + <choice> + <x>x</x> + </choice> + + </t:root> + EOI + + $* >>EOO + { + :8:8 error: expected element 'a' instead of 'x' + } + + EOO +} |