diff options
Diffstat (limited to 'tests/cxx')
323 files changed, 25030 insertions, 0 deletions
diff --git a/tests/cxx/hashmap/driver.cxx b/tests/cxx/hashmap/driver.cxx new file mode 100644 index 0000000..99c773f --- /dev/null +++ b/tests/cxx/hashmap/driver.cxx @@ -0,0 +1,98 @@ +// file : tests/cxx/hashmap/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test xsde::cxx::hashmap type. +// +#include <assert.h> +#include <string.h> + +#include <iostream> + +#include <xsde/cxx/hashmap.hxx> + +using xsde::cxx::hashmap; +using namespace std; + +const char* table[] = +{ + "apple", "1", + "orange", "2", + "peach", "3", + "apricot", "4", + "mango", "5", + "banana", "6", + "pear", "7", + "grapefruit", "8", + "tangerine", "9", +}; + +const size_t table_size = (sizeof (table) / sizeof (const char*)) / 2; + +int +main () +{ + { + hashmap h (1, sizeof (const char*)); + assert (h.size () == 0 && h.empty () && h.max_bucket_size () == 0); + assert (h.begin () == h.end ()); + } + + { + hashmap h (2, sizeof (const char*)); + + const char* v = "bar"; + h.insert ("foo", &v); + assert (h.size () == 1 && !h.empty () && h.max_bucket_size () == 1); + assert (h.begin () != h.end ()); + const void* p = h.find ("foo"); + assert (p != 0 && *static_cast<const char* const*> (p) == v); + } + + { + hashmap h (5, sizeof (const char*)); + + for (size_t i = 0; i < table_size; ++i) + { + const char* v = table[i * 2 + 1]; + h.insert (table[i * 2], &v); + } + + assert (h.size () == table_size); + + for (size_t i = 0; i < table_size; ++i) + { + const char* v = table[i * 2 + 1]; + const void* p = h.find (table[i * 2]); + assert (p != 0 && *static_cast<const char* const*> (p) == v); + } + + // Figure out how many elements are in each bucket. + // + size_t bucket_entries[5] = {0, 0, 0, 0, 0}; + + for (size_t i = 0; i < table_size; ++i) + { + bucket_entries[hashmap::hash (table[i * 2]) % 5]++; + } + + size_t max = 0; + + for (size_t i = 0; i < 5; ++i) + { + if (bucket_entries[i] > max) + max = bucket_entries[i]; + } + + assert (max == h.max_bucket_size ()); + + // Test iteration + // + for (hashmap::const_iterator i = h.begin (); i != h.end (); ++i) + { + const void* p = *i; + cout << "'" << *static_cast<const char* const*> (p) << "'" << endl; + } + } +} diff --git a/tests/cxx/hashmap/makefile b/tests/cxx/hashmap/makefile new file mode 100644 index 0000000..e9b3aca --- /dev/null +++ b/tests/cxx/hashmap/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/hashmap/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hashmap/output b/tests/cxx/hashmap/output new file mode 100644 index 0000000..295e6da --- /dev/null +++ b/tests/cxx/hashmap/output @@ -0,0 +1,9 @@ +'1' +'4' +'2' +'9' +'3' +'8' +'5' +'6' +'7' diff --git a/tests/cxx/hybrid/built-in/driver.cxx b/tests/cxx/hybrid/built-in/driver.cxx new file mode 100644 index 0000000..6204882 --- /dev/null +++ b/tests/cxx/hybrid/built-in/driver.cxx @@ -0,0 +1,56 @@ +// file : tests/cxx/hybrid/built-in/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test built-in types. +// + +#include <iostream> + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/built-in/makefile b/tests/cxx/hybrid/built-in/makefile new file mode 100644 index 0000000..c62315c --- /dev/null +++ b/tests/cxx/hybrid/built-in/makefile @@ -0,0 +1,88 @@ +# file : tests/cxx/hybrid/built-in/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,\ +$(cxx:.cxx=.o) \ +$(xsd:.xsd=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.o)) + +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=.hxx) \ + $(out_base)/$(xsd:.xsd=.cxx) \ + $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.hxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.cxx) \ + $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) \ + $(out_base)/$(xsd:.xsd=-simpl.hxx) \ + $(out_base)/$(xsd:.xsd=-simpl.cxx) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -ubB $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/built-in/output b/tests/cxx/hybrid/built-in/output new file mode 100644 index 0000000..6798590 --- /dev/null +++ b/tests/cxx/hybrid/built-in/output @@ -0,0 +1,5 @@ +<t:root xmlns:t="test"><any></any><any-res x="x"><a>123</a><b>abc</b></any-res><any-simple></any-simple><any-simple-ext x="x"></any-simple-ext><int>123</int><simple-int>456</simple-int><int-base x="x">789</int-base><int-derived x="x" y="y">123</int-derived><bin>YmFzZTY0IGJpbmFyeQ== +</bin><simple-bin>YmFzZTY0IGJpbmFyeQ== +</simple-bin><bin-base x="x">YmFzZTY0IGJpbmFyeQ== +</bin-base><bin-derived x="x" y="y">YmFzZTY0IGJpbmFyeQ== +</bin-derived><string>abc</string><simple-string>def</simple-string><string-base x="x">ghi</string-base><string-derived x="x" y="y">jkl</string-derived></t:root>
\ No newline at end of file diff --git a/tests/cxx/hybrid/built-in/test.xml b/tests/cxx/hybrid/built-in/test.xml new file mode 100644 index 0000000..ae72e80 --- /dev/null +++ b/tests/cxx/hybrid/built-in/test.xml @@ -0,0 +1,24 @@ +<t:root xmlns:t="test" any-simple-attr=""> + + <any></any> + <any-res x="x"><a>123</a><b>abc</b></any-res> + + <any-simple></any-simple> + <any-simple-ext x="x"></any-simple-ext> + + <int>123</int> + <simple-int>456</simple-int> + <int-base x="x">789</int-base> + <int-derived x="x" y="y">123</int-derived> + + <bin>YmFzZTY0IGJpbmFyeQ==</bin> + <simple-bin>YmFzZTY0IGJpbmFyeQ==</simple-bin> + <bin-base x="x">YmFzZTY0IGJpbmFyeQ==</bin-base> + <bin-derived x="x" y="y">YmFzZTY0IGJpbmFyeQ==</bin-derived> + + <string>abc</string> + <simple-string>def</simple-string> + <string-base x="x">ghi</string-base> + <string-derived x="x" y="y">jkl</string-derived> + +</t:root> diff --git a/tests/cxx/hybrid/built-in/test.xsd b/tests/cxx/hybrid/built-in/test.xsd new file mode 100644 index 0000000..1481d4f --- /dev/null +++ b/tests/cxx/hybrid/built-in/test.xsd @@ -0,0 +1,125 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- anyType --> + + <complexType name="any-res"> + <complexContent> + <restriction base="anyType"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="string"/> + </sequence> + <attribute name="x" type="string"/> + </restriction> + </complexContent> + </complexType> + + <!-- anySimpleType --> + + <complexType name="any-simple-ext"> + <simpleContent> + <extension base="anySimpleType"> + <attribute name="x" type="string"/> + </extension> + </simpleContent> + </complexType> + + + <!-- int --> + + <simpleType name="simple-int"> + <restriction base="int"/> + </simpleType> + + <complexType name="int-base"> + <simpleContent> + <extension base="int"> + <attribute name="x" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="int-derived"> + <simpleContent> + <extension base="t:int-base"> + <attribute name="y" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- base64Binary --> + + <simpleType name="simple-bin"> + <restriction base="base64Binary"/> + </simpleType> + + <complexType name="bin-base"> + <simpleContent> + <extension base="base64Binary"> + <attribute name="x" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="bin-derived"> + <simpleContent> + <extension base="t:bin-base"> + <attribute name="y" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- string --> + + <simpleType name="simple-string"> + <restriction base="string"/> + </simpleType> + + <complexType name="string-base"> + <simpleContent> + <extension base="string"> + <attribute name="x" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="string-derived"> + <simpleContent> + <extension base="t:string-base"> + <attribute name="y" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="type"> + <sequence> + + <element name="any" type="anyType"/> + <element name="any-res" type="t:any-res"/> + + <element name="any-simple" type="anySimpleType"/> + <element name="any-simple-ext" type="t:any-simple-ext"/> + + <element name="int" type="int"/> + <element name="simple-int" type="t:simple-int"/> + <element name="int-base" type="t:int-base"/> + <element name="int-derived" type="t:int-derived"/> + + <element name="bin" type="base64Binary"/> + <element name="simple-bin" type="t:simple-bin"/> + <element name="bin-base" type="t:bin-base"/> + <element name="bin-derived" type="t:bin-derived"/> + + <element name="string" type="string"/> + <element name="simple-string" type="t:simple-string"/> + <element name="string-base" type="t:string-base"/> + <element name="string-derived" type="t:string-derived"/> + + </sequence> + <attribute name="any-simple-attr" type="anySimpleType"/> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/hybrid/choice/driver.cxx b/tests/cxx/hybrid/choice/driver.cxx new file mode 100644 index 0000000..0ba13de --- /dev/null +++ b/tests/cxx/hybrid/choice/driver.cxx @@ -0,0 +1,70 @@ +// file : tests/cxx/hybrid/choice/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test choice mapping. +// + +#include <cassert> +#include <iostream> + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + +#ifdef XSDE_STL + { + test1 x; + x.b ("foo"); + test1 y (x); + assert (y.b () == "foo"); + test1 z; + y.a (123); + z = y; + assert (z.a () == 123); + } +#endif + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/choice/makefile b/tests/cxx/hybrid/choice/makefile new file mode 100644 index 0000000..cd256ff --- /dev/null +++ b/tests/cxx/hybrid/choice/makefile @@ -0,0 +1,88 @@ +# file : tests/cxx/hybrid/choice/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,\ +$(cxx:.cxx=.o) \ +$(xsd:.xsd=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.o)) + +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=.hxx) \ + $(out_base)/$(xsd:.xsd=.cxx) \ + $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.hxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.cxx) \ + $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) \ + $(out_base)/$(xsd:.xsd=-simpl.hxx) \ + $(out_base)/$(xsd:.xsd=-simpl.cxx) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -ubB $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/choice/output b/tests/cxx/hybrid/choice/output new file mode 100644 index 0000000..b299e90 --- /dev/null +++ b/tests/cxx/hybrid/choice/output @@ -0,0 +1 @@ +<t:root xmlns:t="test"><test2><a>123</a></test2><test2><b>abc</b><b>def</b></test2><test2><c><a>1.23</a><b>123</b></c></test2><test2><d><a>true</a><a>false</a><b>abc</b></d></test2><test2><e></e></test2><test2><s1>1.23</s1><s2>123</s2></test2><test2><s3>1.23</s3><s4>123</s4></test2><test2><s5>1.23</s5><s6>123</s6><s5>4.56</s5><s6>456</s6></test2><test3><f1>1.23</f1><v1>true</v1><f5>1.23</f5><v5>true</v5></test3><test3><f2>123</f2><v2><a>true</a><a>false</a><b>abc</b></v2><f3>1.23</f3><v3>true</v3><f6>123</f6><f5>1.23</f5><v6><a>true</a><a>false</a><b>abc</b></v6><v5>true</v5></test3><test4><f1>1.23</f1></test4><test4><v1>true</v1></test4><test4><f5>1.23</f5></test4><test4><v5>true</v5></test4><test4><f2>123</f2></test4><test4><v2><a>true</a><a>false</a><b>abc</b></v2></test4><test4><f3>1.23</f3></test4><test4><v3>true</v3></test4><test4><f6>123</f6><f5>1.23</f5></test4><test4><v6><a>true</a><a>false</a><b>abc</b></v6><v5>true</v5></test4><test5a></test5a><test5b><d>true</d></test5b><test5c><d>true</d></test5c><test5d></test5d></t:root>
\ No newline at end of file diff --git a/tests/cxx/hybrid/choice/test.xml b/tests/cxx/hybrid/choice/test.xml new file mode 100644 index 0000000..48f06fd --- /dev/null +++ b/tests/cxx/hybrid/choice/test.xml @@ -0,0 +1,57 @@ +<t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- test 2 --> + + <test2><a>123</a></test2> + + <test2><b>abc</b><b>def</b></test2> + + <test2><c><a>1.23</a><b>123</b></c></test2> + + <test2><d><a>true</a><a>false</a><b>abc</b></d></test2> + + <test2><e/></test2> + + <test2><s1>1.23</s1><s2>123</s2></test2> + <test2><s3>1.23</s3><s4>123</s4></test2> + <test2><s5>1.23</s5><s6>123</s6><s5>4.56</s5><s6>456</s6></test2> + + <!-- test 3 --> + + <test3> + <f1>1.23</f1> + <v1>true</v1> + <f5>1.23</f5> + <v5>true</v5></test3> + + <test3> + <f2>123</f2> + <v2><a>true</a><a>false</a><b>abc</b></v2> + <f3>1.23</f3> + <v3>true</v3> + <f6>123</f6><f5>1.23</f5> + <v6><a>true</a><a>false</a><b>abc</b></v6><v5>true</v5> + </test3> + + <!-- test 4 --> + + <test4><f1>1.23</f1></test4> + <test4><v1>true</v1></test4> + <test4><f5>1.23</f5></test4> + <test4><v5>true</v5></test4> + <test4><f2>123</f2></test4> + <test4><v2><a>true</a><a>false</a><b>abc</b></v2></test4> + <test4><f3>1.23</f3></test4> + <test4><v3>true</v3></test4> + <test4><f6>123</f6><f5>1.23</f5></test4> + <test4><v6><a>true</a><a>false</a><b>abc</b></v6><v5>true</v5></test4> + + <!-- test 5 --> + + <test5a></test5a> + <test5b><d>true</d></test5b> + <test5c><d>true</d></test5c> + <test5d></test5d> + +</t:root> diff --git a/tests/cxx/hybrid/choice/test.xsd b/tests/cxx/hybrid/choice/test.xsd new file mode 100644 index 0000000..9fe5f5c --- /dev/null +++ b/tests/cxx/hybrid/choice/test.xsd @@ -0,0 +1,174 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="fix"> + <sequence> + <element name="a" type="double" minOccurs="0"/> + <element name="b" type="int"/> + </sequence> + </complexType> + + <complexType name="var"> + <sequence> + <element name="a" type="boolean" maxOccurs="unbounded"/> + <element name="b" type="string"/> + </sequence> + </complexType> + + <complexType name="empty"> + <sequence/> + </complexType> + + + <!-- test 1: fixed choice copying/assignment --> + + <complexType name="test1"> + <choice> + <element name="a" type="int"/> + <element name="b" type="string"/> + </choice> + </complexType> + + <!-- test 2: general --> + + <complexType name="test2"> + <choice> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="string" maxOccurs="unbounded"/> + <element name="c" type="t:fix"/> + <element name="d" type="t:var"/> + <element name="e" type="t:empty"/> + <sequence> + <element name="s1" type="double"/> + <element name="s2" type="int"/> + </sequence> + <sequence minOccurs="0"> + <element name="s3" type="double"/> + <element name="s4" type="int"/> + </sequence> + <sequence maxOccurs="unbounded"> + <element name="s5" type="double"/> + <element name="s6" type="int"/> + </sequence> + </choice> + </complexType> + + <!-- test 3: choice cardinalities --> + + <complexType name="test3"> + <sequence> + <choice> + <element name="f1" type="double"/> + <element name="f2" type="int"/> + </choice> + <choice> + <element name="v1" type="boolean"/> + <element name="v2" type="t:var"/> + </choice> + <choice minOccurs="0"> + <element name="f3" type="double"/> + <element name="f4" type="int"/> + </choice> + <choice minOccurs="0"> + <element name="v3" type="boolean"/> + <element name="v4" type="t:var"/> + </choice> + <choice maxOccurs="unbounded"> + <element name="f5" type="double"/> + <element name="f6" type="int"/> + </choice> + <choice maxOccurs="unbounded"> + <element name="v5" type="boolean"/> + <element name="v6" type="t:var"/> + </choice> + </sequence> + </complexType> + + <!-- test 4: nested choice --> + + <complexType name="test4"> + <choice minOccurs="0"> + <choice> + <element name="f1" type="double"/> + <element name="f2" type="int"/> + </choice> + <choice> + <element name="v1" type="boolean"/> + <element name="v2" type="t:var"/> + </choice> + <choice minOccurs="0"> + <element name="f3" type="double"/> + <element name="f4" type="int"/> + </choice> + <choice minOccurs="0"> + <element name="v3" type="boolean"/> + <element name="v4" type="t:var"/> + </choice> + <choice maxOccurs="unbounded"> + <element name="f5" type="double"/> + <element name="f6" type="int"/> + </choice> + <choice maxOccurs="unbounded"> + <element name="v5" type="boolean"/> + <element name="v6" type="t:var"/> + </choice> + </choice> + </complexType> + + <!-- test 5: required choice with optional element--> + + <complexType name="test5a"> + <choice> + <element name="a" type="int"/> + <element name="b" type="double" minOccurs="0"/> + <element name="c" type="boolean"/> + </choice> + </complexType> + + <complexType name="test5b"> + <sequence> + <choice> + <element name="a" type="int"/> + <element name="b" type="double" minOccurs="0"/> + <element name="c" type="boolean"/> + </choice> + <element name="d" type="boolean"/> + </sequence> + </complexType> + + <complexType name="test5c"> + <sequence> + <element name="d" type="boolean"/> + <choice> + <element name="a" type="int"/> + <element name="b" type="double" minOccurs="0"/> + <element name="c" type="boolean"/> + </choice> + </sequence> + </complexType> + + <complexType name="test5d"> + <choice> + <choice> + <element name="a" type="int"/> + <element name="b" type="double" minOccurs="0"/> + </choice> + <element name="c" type="boolean"/> + </choice> + </complexType> + + <complexType name="type"> + <sequence> + <element name="test2" type="t:test2" maxOccurs="unbounded"/> + <element name="test3" type="t:test3" maxOccurs="unbounded"/> + <element name="test4" type="t:test4" maxOccurs="unbounded"/> + <element name="test5a" type="t:test5a" maxOccurs="unbounded"/> + <element name="test5b" type="t:test5b" maxOccurs="unbounded"/> + <element name="test5c" type="t:test5c" maxOccurs="unbounded"/> + <element name="test5d" type="t:test5d" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/hybrid/compositor/includee.xsd b/tests/cxx/hybrid/compositor/includee.xsd new file mode 100644 index 0000000..1def761 --- /dev/null +++ b/tests/cxx/hybrid/compositor/includee.xsd @@ -0,0 +1,14 @@ +<?xml version="1.0" ?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:t="test" + targetNamespace="test"> + + <complexType name="member"> + <choice> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </choice> + </complexType> + +</schema> diff --git a/tests/cxx/hybrid/compositor/includer.xsd b/tests/cxx/hybrid/compositor/includer.xsd new file mode 100644 index 0000000..fc730e4 --- /dev/null +++ b/tests/cxx/hybrid/compositor/includer.xsd @@ -0,0 +1,14 @@ +<?xml version="1.0" ?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:T="test" + targetNamespace="test"> + + <include schemaLocation="includee.xsd"/> + + <complexType name="container"> + <choice> + <element name="a" type="T:member" maxOccurs="unbounded"/> + </choice> + </complexType> + +</schema> diff --git a/tests/cxx/hybrid/compositor/test.xsd b/tests/cxx/hybrid/compositor/test.xsd new file mode 100644 index 0000000..3d1b1ce --- /dev/null +++ b/tests/cxx/hybrid/compositor/test.xsd @@ -0,0 +1,186 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- all --> + + <complexType name="all-1"> + <all> + <element name="a" type="int"/> + <element name="b" type="string"/> + </all> + </complexType> + + <complexType name="all-2"> + <all minOccurs="0"> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="string" minOccurs="0"/> + </all> + </complexType> + + <!-- sequence --> + + <complexType name="sequence-1"> + <sequence> + <element name="a" type="int"/> + <sequence> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </sequence> + </sequence> + </complexType> + + <complexType name="sequence-2"> + <sequence minOccurs="0"> + <element name="a" type="int"/> + <sequence minOccurs="0"> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </sequence> + </sequence> + </complexType> + + <complexType name="sequence-3"> + <sequence maxOccurs="unbounded"> + <element name="a" type="int"/> + <sequence minOccurs="0" maxOccurs="unbounded"> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </sequence> + </sequence> + </complexType> + + <complexType name="sequence-4"> + <sequence> + <element name="a" type="int"/> + <choice> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </choice> + </sequence> + </complexType> + + <complexType name="sequence-5"> + <sequence> + <element name="a" type="int"/> + <choice minOccurs="0"> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </choice> + </sequence> + </complexType> + + <complexType name="sequence-6"> + <sequence> + <element name="a" type="int"/> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </choice> + </sequence> + </complexType> + + <complexType name="sequence-7"> + <sequence> + <element name="a" type="int"/> + <choice> + <element name="b" type="string"/> + <sequence> + <element name="c" type="boolean"/> + <element name="d" type="float"/> + </sequence> + </choice> + </sequence> + </complexType> + + <complexType name="sequence-8"> + <sequence> + <element name="a" type="int"/> + <choice> + <element name="b" type="string"/> + <sequence minOccurs="0"> + <element name="c" type="boolean"/> + <element name="d" type="float"/> + </sequence> + </choice> + </sequence> + </complexType> + + <complexType name="sequence-9"> + <sequence> + <element name="a" type="int"/> + <choice> + <element name="b" type="string"/> + <sequence minOccurs="0" maxOccurs="unbounded"> + <element name="c" type="boolean"/> + <element name="d" type="float"/> + </sequence> + </choice> + </sequence> + </complexType> + + + <complexType name="sequence-10"> + <sequence> + <element name="a" type="int"/> + <sequence minOccurs="0"> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </sequence> + <sequence maxOccurs="unbounded"> + <element name="d" type="string"/> + <element name="e" type="boolean"/> + </sequence> + </sequence> + </complexType> + + <!-- choice --> + + <complexType name="choice-1"> + <choice> + <element name="a" type="int"/> + <choice> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + <element name="d" type="string" minOccurs="0"/> + <element name="e" type="boolean" minOccurs="0"/> + <element name="f" type="string" maxOccurs="unbounded"/> + <element name="g" type="boolean" maxOccurs="unbounded"/> + </choice> + </choice> + </complexType> + + <complexType name="choice-2"> + <choice minOccurs="0"> + <element name="a" type="int"/> + <choice minOccurs="0"> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </choice> + </choice> + </complexType> + + <complexType name="choice-3"> + <choice maxOccurs="unbounded"> + <element name="a" type="int"/> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </choice> + </choice> + </complexType> + + <complexType name="choice-4"> + <sequence> + <element name="a" type="int"/> + <choice> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + </choice> + <choice> + <element name="d" type="string"/> + <element name="e" type="boolean"/> + </choice> + </sequence> + </complexType> + +</schema> diff --git a/tests/cxx/hybrid/compositor/tmp.xsd b/tests/cxx/hybrid/compositor/tmp.xsd new file mode 100644 index 0000000..fc3a4bd --- /dev/null +++ b/tests/cxx/hybrid/compositor/tmp.xsd @@ -0,0 +1,87 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="fixed"> + <sequence> + <element name="a" type="boolean" minOccurs="0"/> + <element name="b" type="int"/> + </sequence> + </complexType> + + <complexType name="fix-ext"> + <complexContent> + <extension base="t:fixed"> + <sequence> + <element name="c" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="var-ext"> + <complexContent> + <extension base="t:fixed"> + <sequence> + <element name="c" type="string"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="var-ext2"> + <complexContent> + <extension base="t:var-ext"> + <sequence> + <element name="d" type="string"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="sequence-1"> + <choice maxOccurs="unbounded"> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="string" maxOccurs="unbounded"/> + <element name="c" type="boolean"/> + <sequence maxOccurs="unbounded"> + <element name="d" type="string"/> + <element name="e" type="boolean"/> + </sequence> + </choice> + </complexType> + + <complexType name="sequence-1a"> + <choice> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + <sequence minOccurs="1"> + <element name="d" type="string"/> + <element name="e" type="boolean"/> + </sequence> + </choice> + </complexType> + + <complexType name="sequence-2"> + <sequence maxOccurs="10"> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="string"/> + <element name="c" type="boolean"/> + <sequence maxOccurs="20"> + <element name="d" type="string"/> + <element name="e" type="boolean"/> + </sequence> + </sequence> + </complexType> + + <complexType name="sequence-3"> + <sequence maxOccurs="unbounded"> + <element name="a" type="int" minOccurs="0"/> + <sequence maxOccurs="unbounded"> + <element name="b" type="string" maxOccurs="unbounded"/> + <element name="c" type="boolean"/> + </sequence> + </sequence> + </complexType> + +</schema> diff --git a/tests/cxx/hybrid/file-per-type/a.xsd b/tests/cxx/hybrid/file-per-type/a.xsd new file mode 100644 index 0000000..9abe165 --- /dev/null +++ b/tests/cxx/hybrid/file-per-type/a.xsd @@ -0,0 +1,14 @@ +<?xml version="1.0" ?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <include schemaLocation="b.xsd"/> + + <complexType name="base"> + <sequence> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="boolean"/> + <element name="c" type="t:derived" minOccurs="0"/> + </sequence> + </complexType> + +</schema> diff --git a/tests/cxx/hybrid/file-per-type/b.xsd b/tests/cxx/hybrid/file-per-type/b.xsd new file mode 100644 index 0000000..f10ad4c --- /dev/null +++ b/tests/cxx/hybrid/file-per-type/b.xsd @@ -0,0 +1,16 @@ +<?xml version="1.0" ?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <include schemaLocation="a.xsd"/> + + <complexType name="derived"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="d" type="double"/> + </sequence> + </extension> + </complexContent> + </complexType> + +</schema> diff --git a/tests/cxx/hybrid/file-per-type/test.xsd b/tests/cxx/hybrid/file-per-type/test.xsd new file mode 100644 index 0000000..ebb2f23 --- /dev/null +++ b/tests/cxx/hybrid/file-per-type/test.xsd @@ -0,0 +1,9 @@ +<?xml version="1.0" ?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <include schemaLocation="a.xsd"/> + <include schemaLocation="b.xsd"/> + + <element name="root" type="t:derived"/> + +</schema> diff --git a/tests/cxx/hybrid/list/driver.cxx b/tests/cxx/hybrid/list/driver.cxx new file mode 100644 index 0000000..5d6b20e --- /dev/null +++ b/tests/cxx/hybrid/list/driver.cxx @@ -0,0 +1,56 @@ +// file : tests/cxx/hybrid/list/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test list mapping. +// + +#include <iostream> + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/list/makefile b/tests/cxx/hybrid/list/makefile new file mode 100644 index 0000000..5d70a97 --- /dev/null +++ b/tests/cxx/hybrid/list/makefile @@ -0,0 +1,88 @@ +# file : tests/cxx/hybrid/list/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,\ +$(cxx:.cxx=.o) \ +$(xsd:.xsd=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.o)) + +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=.hxx) \ + $(out_base)/$(xsd:.xsd=.cxx) \ + $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.hxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.cxx) \ + $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) \ + $(out_base)/$(xsd:.xsd=-simpl.hxx) \ + $(out_base)/$(xsd:.xsd=-simpl.cxx) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -ubB $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/list/output b/tests/cxx/hybrid/list/output new file mode 100644 index 0000000..6c1ac43 --- /dev/null +++ b/tests/cxx/hybrid/list/output @@ -0,0 +1 @@ +<t:root xmlns:t="test"><int-list>123 456 789</int-list><qname-list>one t:two three</qname-list><string-list>abc def ghi</string-list><string-list-lang lang="fr">abc def ghi</string-list-lang></t:root>
\ No newline at end of file diff --git a/tests/cxx/hybrid/list/test.xml b/tests/cxx/hybrid/list/test.xml new file mode 100644 index 0000000..2451a4b --- /dev/null +++ b/tests/cxx/hybrid/list/test.xml @@ -0,0 +1,8 @@ +<t:root xmlns:t="test"> + + <int-list>123 456 789</int-list> + <qname-list>one t:two three</qname-list> + <string-list>abc def ghi</string-list> + <string-list-lang lang="fr">abc def ghi</string-list-lang> + +</t:root> diff --git a/tests/cxx/hybrid/list/test.xsd b/tests/cxx/hybrid/list/test.xsd new file mode 100644 index 0000000..d864b12 --- /dev/null +++ b/tests/cxx/hybrid/list/test.xsd @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="int-list"> + <list itemType="int"/> + </simpleType> + + <simpleType name="qname-list"> + <list itemType="QName"/> + </simpleType> + + <simpleType name="string-list"> + <list itemType="string"/> + </simpleType> + + <complexType name="string-list-lang"> + <simpleContent> + <extension base="t:string-list"> + <attribute name="lang" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="int-list" type="t:int-list"/> + <element name="qname-list" type="t:qname-list"/> + <element name="string-list" type="t:string-list"/> + <element name="string-list-lang" type="t:string-list-lang"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/hybrid/makefile b/tests/cxx/hybrid/makefile new file mode 100644 index 0000000..3351241 --- /dev/null +++ b/tests/cxx/hybrid/makefile @@ -0,0 +1,29 @@ +# file : tests/cxx/hybrid/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +tests := sequences + +ifeq ($(xsde_iostream),y) +tests += built-in list test-template union + +ifeq ($(xsde_parser_validation),y) +tests += choice +endif + +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/hybrid/reorder/test.xsd b/tests/cxx/hybrid/reorder/test.xsd new file mode 100644 index 0000000..1b610cc --- /dev/null +++ b/tests/cxx/hybrid/reorder/test.xsd @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="container"> + <sequence> + <element name="c" type="t:member"/> + <element name="d" type="t:member" minOccurs="0"/> + </sequence> + </complexType> + + <complexType name="member"> + <sequence> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="boolean"/> + </sequence> + </complexType> + + <simpleType name="list"> + <list itemType="t:item"/> + </simpleType> + + <simpleType name="item"> + <restriction base="int"/> + </simpleType> + +</schema> diff --git a/tests/cxx/hybrid/sequences/driver.cxx b/tests/cxx/hybrid/sequences/driver.cxx new file mode 100644 index 0000000..3d6c702 --- /dev/null +++ b/tests/cxx/hybrid/sequences/driver.cxx @@ -0,0 +1,442 @@ +// file : tests/cxx/hybrid/sequences/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test sequence templates. +// +#include <string> +#include <cassert> + +#include <xsde/cxx/config.hxx> + +#ifndef XSDE_STL +#include <xsde/cxx/strdupx.hxx> +#endif + +#include <xsde/cxx/hybrid/sequence.hxx> + +using std::string; +using namespace xsde::cxx::hybrid; + +void data_destructor (void* p, size_t) +{ + delete static_cast<string*> (p); +} + +void data_destructor_pos (void* p, size_t i) +{ + switch (i) + { + case 0: + { + delete static_cast<string*> (p); + break; + } + case 1: + { + delete static_cast<int*> (p); + break; + } + } +} + +int +main () +{ + // + // pod_seq + // + typedef pod_seq<int> pod; + + { + pod s; + s.push_back (111); + assert (s.size () == 1 && s[0] == 111); + s.pop_back (); + assert (s.size () == 0); + } + + { + pod s; + s.push_back (111); + s.erase (s.begin ()); + assert (s.size () == 0); + + s.push_back (111); + s.push_back (222); + s.push_back (333); + s.erase (s.begin ()); + assert (s.size () == 2 && s[0] == 222 && s[1] == 333); + + s.push_back (444); + s.erase (s.begin () + 1); + assert (s.size () == 2 && s[0] == 222 && s[1] == 444); + + s.push_back (555); + s.erase (s.begin () + 2); + assert (s.size () == 2 && s[0] == 222 && s[1] == 444); + } + + { + pod s; + s.reserve (2); + s.push_back (111); + s.push_back (222); + s.push_back (333); + assert (s.size () == 3 && s[0] == 111 && s[1] == 222 && s[2] == 333); + } + + { + pod s; + s.insert (s.begin (), 111); + assert (s.size () == 1 && s[0] == 111); + s.push_back (222); + s.push_back (333); + + s.insert (s.begin (), 444); + assert (s[0] == 444); + + s.insert (s.begin () + 1, 555); + assert (s[1] == 555); + + s.insert (s.end (), 666); + assert (s[5] == 666); + + assert (s[0] == 444 && s[1] == 555 && s[2] == 111 && + s[3] == 222 && s[4] == 333 && s[5] == 666); + } + + { + pod s; + s.reserve (2); + s.push_back (111); + s.push_back (222); + s.insert (s.begin () + 1, 333); + assert (s[0] == 111 && s[1] == 333 && s[2] == 222); + } + + // + // fix_seq + // + typedef fix_seq<string> fix; + + { + fix s; + s.push_back ("aaa"); + assert (s.size () == 1 && s[0] == "aaa"); + s.pop_back (); + assert (s.size () == 0); + } + + { + fix s; + s.push_back ("aaa"); + s.erase (s.begin ()); + assert (s.size () == 0); + + s.push_back ("aaa"); + s.push_back ("bbb"); + s.push_back ("ccc"); + s.erase (s.begin ()); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ccc"); + + s.push_back ("ddd"); + s.erase (s.begin () + 1); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ddd"); + + s.push_back ("eee"); + s.erase (s.begin () + 2); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ddd"); + } + + { + fix s; + s.reserve (2); + s.push_back ("aaa"); + s.push_back ("bbb"); + s.push_back ("ccc"); + assert (s.size () == 3 && s[0] == "aaa" && + s[1] == "bbb" && s[2] == "ccc"); + } + + { + fix s; + s.insert (s.begin (), "aaa"); + assert (s.size () == 1 && s[0] == "aaa"); + s.push_back ("bbb"); + s.push_back ("ccc"); + + s.insert (s.begin (), "ddd"); + assert (s[0] == "ddd"); + + s.insert (s.begin () + 1, "eee"); + assert (s[1] == "eee"); + + s.insert (s.end (), "fff"); + assert (s[5] == "fff"); + + assert (s[0] == "ddd" && s[1] == "eee" && s[2] == "aaa" && + s[3] == "bbb" && s[4] == "ccc" && s[5] == "fff"); + } + + { + fix s; + s.reserve (2); + s.push_back ("aaa"); + s.push_back ("bbb"); + s.insert (s.begin () + 1, "ccc"); + assert (s[0] == "aaa" && s[1] == "ccc" && s[2] == "bbb"); + } + + // + // var_seq + // + typedef var_seq<string> var; + + { + var s; + s.push_back (new string ("aaa")); + assert (s.size () == 1 && s[0] == "aaa"); + s.pop_back (); + assert (s.size () == 0); + } + + { + var s; + s.push_back (new string ("aaa")); + s.erase (s.begin ()); + assert (s.size () == 0); + + s.push_back (new string ("aaa")); + s.push_back (new string ("bbb")); + s.push_back (new string ("ccc")); + s.erase (s.begin ()); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ccc"); + + s.push_back (new string ("ddd")); + s.erase (s.begin () + 1); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ddd"); + + s.push_back (new string ("eee")); + s.erase (s.begin () + 2); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ddd"); + } + + { + var s; + s.reserve (2); + s.push_back (new string ("aaa")); + s.push_back (new string ("bbb")); + s.push_back (new string ("ccc")); + assert (s.size () == 3 && s[0] == "aaa" && + s[1] == "bbb" && s[2] == "ccc"); + } + + { + var s; + s.insert (s.begin (), new string ("aaa")); + assert (s.size () == 1 && s[0] == "aaa"); + s.push_back (new string ("bbb")); + s.push_back (new string ("ccc")); + + s.insert (s.begin (), new string ("ddd")); + assert (s[0] == "ddd"); + + s.insert (s.begin () + 1, new string ("eee")); + assert (s[1] == "eee"); + + s.insert (s.end (), new string ("fff")); + assert (s[5] == "fff"); + + assert (s[0] == "ddd" && s[1] == "eee" && s[2] == "aaa" && + s[3] == "bbb" && s[4] == "ccc" && s[5] == "fff"); + } + + { + var s; + s.reserve (2); + s.push_back (new string ("aaa")); + s.push_back (new string ("bbb")); + s.insert (s.begin () + 1, new string ("ccc")); + assert (s[0] == "aaa" && s[1] == "ccc" && s[2] == "bbb"); + } + + // + // str_seq + // + typedef str_seq str; + +#ifndef XSDE_STL + using xsde::cxx::strdupx; + + { + str s; + s.push_back (strdupx ("aaa")); + assert (s.size () == 1 && s[0] == string ("aaa")); + s.pop_back (); + assert (s.size () == 0); + } + + { + str s; + s.push_back_copy ("aaa"); + s.erase (s.begin ()); + assert (s.size () == 0); + + s.push_back_copy ("aaa"); + s.push_back_copy ("bbb"); + s.push_back_copy ("ccc"); + s.erase (s.begin ()); + assert (s.size () == 2 && + s[0] == string ("bbb") && s[1] == string ("ccc")); + + s.push_back_copy ("ddd"); + s.erase (s.begin () + 1); + assert (s.size () == 2 && + s[0] == string ("bbb") && s[1] == string ("ddd")); + + s.push_back_copy ("eee"); + s.erase (s.begin () + 2); + assert (s.size () == 2 && + s[0] == string ("bbb") && s[1] == string ("ddd")); + } + + { + str s; + s.reserve (2); + s.push_back_copy ("aaa"); + s.push_back_copy ("bbb"); + s.push_back_copy ("ccc"); + assert (s.size () == 3 && + s[0] == string ("aaa") && + s[1] == string ("bbb") && + s[2] == string ("ccc")); + } + + { + str s; + s.insert (s.begin (), strdupx ("aaa")); + assert (s.size () == 1 && s[0] == string ("aaa")); + s.push_back_copy ("bbb"); + s.push_back_copy ("ccc"); + + s.insert (s.begin (), strdupx ("ddd")); + assert (s[0] == string ("ddd")); + + s.insert (s.begin () + 1, strdupx ("eee")); + assert (s[1] == string ("eee")); + + s.insert (s.end (), strdupx ("fff")); + assert (s[5] == string ("fff")); + + assert (s[0] == string ("ddd") && s[1] == string ("eee") && + s[2] == string ("aaa") && s[3] == string ("bbb") && + s[4] == string ("ccc") && s[5] == string ("fff")); + } + + { + str s; + s.reserve (2); + s.push_back_copy ("aaa"); + s.push_back_copy ("bbb"); + s.insert (s.begin () + 1, strdupx ("ccc")); + assert (s[0] == string ("aaa") && + s[1] == string ("ccc") && + s[2] == string ("bbb")); + } + +#else + + { + str s; + s.push_back ("aaa"); + assert (s.size () == 1 && s[0] == "aaa"); + s.pop_back (); + assert (s.size () == 0); + } + + { + str s; + s.push_back ("aaa"); + s.erase (s.begin ()); + assert (s.size () == 0); + + s.push_back ("aaa"); + s.push_back ("bbb"); + s.push_back ("ccc"); + s.erase (s.begin ()); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ccc"); + + s.push_back ("ddd"); + s.erase (s.begin () + 1); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ddd"); + + s.push_back ("eee"); + s.erase (s.begin () + 2); + assert (s.size () == 2 && s[0] == "bbb" && s[1] == "ddd"); + } + + { + str s; + s.reserve (2); + s.push_back ("aaa"); + s.push_back ("bbb"); + s.push_back ("ccc"); + assert (s.size () == 3 && + s[0] == "aaa" && s[1] == "bbb" && s[2] == "ccc"); + } + + { + str s; + s.insert (s.begin (), "aaa"); + assert (s.size () == 1 && s[0] == "aaa"); + s.push_back ("bbb"); + s.push_back ("ccc"); + + s.insert (s.begin (), "ddd"); + assert (s[0] == "ddd"); + + s.insert (s.begin () + 1, "eee"); + assert (s[1] == "eee"); + + s.insert (s.end (), "fff"); + assert (s[5] == "fff"); + + assert (s[0] == "ddd" && s[1] == "eee" && s[2] == "aaa" && + s[3] == "bbb" && s[4] == "ccc" && s[5] == "fff"); + } + + { + str s; + s.reserve (2); + s.push_back ("aaa"); + s.push_back ("bbb"); + s.insert (s.begin () + 1, "ccc"); + assert (s[0] == "aaa" && s[1] == "ccc" && s[2] == "bbb"); + } +#endif + + // + // data_seq + // + typedef data_seq data; + + { + data s; + s.destructor (&data_destructor); + s.push_back (new string ("aaa")); + s.push_back (new string ("bbb")); + assert (*static_cast<string*> (s[0]) == "aaa" && + *static_cast<string*> (s[1]) == "bbb"); + } + + { + data s; + s.destructor (&data_destructor_pos); + s.push_back (new string ("aaa")); + s.push_back (new int (5)); + assert (*static_cast<string*> (s[0]) == "aaa" && + *static_cast<int*> (s[1]) == 5); + } +} diff --git a/tests/cxx/hybrid/sequences/makefile b/tests/cxx/hybrid/sequences/makefile new file mode 100644 index 0000000..41f5941 --- /dev/null +++ b/tests/cxx/hybrid/sequences/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/hybrid/sequences/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/size/test.xsd b/tests/cxx/hybrid/size/test.xsd new file mode 100644 index 0000000..e8e265d --- /dev/null +++ b/tests/cxx/hybrid/size/test.xsd @@ -0,0 +1,136 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- fixed --> + + <complexType name="fixed-base"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="t:fixed-all" minOccurs="0"/> + </sequence> + <attribute name="x" type="double" use="required"/> + </complexType> + + <complexType name="fixed-derived"> + <complexContent> + <extension base="t:fixed-base"> + <sequence> + <element name="c" type="float"/> + </sequence> + <attribute name="y" type="boolean"/> + </extension> + </complexContent> + </complexType> + + <complexType name="fixed-all"> + <all> + <element name="a" type="int"/> + <element name="b" type="time" minOccurs="0"/> + </all> + <attribute name="x" type="double"/> + </complexType> + + <!-- variable --> + + <complexType name="var-el-string"> + <all> + <element name="b" type="string"/> + </all> + <attribute name="x" type="double"/> + </complexType> + + <complexType name="var-at-string"> + <all> + <element name="b" type="int"/> + </all> + <attribute name="x" type="string"/> + </complexType> + + <complexType name="var-seq1"> + <sequence> + <element name="b" type="int" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <complexType name="var-seq2"> + <sequence maxOccurs="2"> + <element name="a" type="int"/> + <element name="b" type="int"/> + </sequence> + </complexType> + + <complexType name="var-choice"> + <choice> + <element name="a" type="int"/> + <element name="b" type="boolean"/> + </choice> + </complexType> + + <complexType name="var-var-mem"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="t:var-seq1"/> + </sequence> + </complexType> + + <complexType name="var-var-base"> + <complexContent> + <extension base="t:var-var-mem"> + <sequence> + <element name="c" type="float"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="var-fwd1"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="t:var-fwd2"/> + </sequence> + </complexType> + + <complexType name="var-fwd2"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="string"/> + </sequence> + </complexType> + + + <complexType name="var-mem-rec1"> + <sequence> + <element name="a" type="t:var-mem-rec2"/> + </sequence> + </complexType> + + <complexType name="var-mem-rec2"> + <sequence> + <element name="a" type="t:var-mem-rec1" minOccurs="0"/> + </sequence> + </complexType> + + + <complexType name="var-base-rec1"> + <sequence> + <element name="a" type="t:var-base-rec3"/> + </sequence> + </complexType> + + <complexType name="var-base-rec2"> + <complexContent> + <extension base="t:var-base-rec1"> + <sequence> + <element name="c" type="float"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="var-base-rec3"> + <sequence> + <element name="a" type="t:var-base-rec2" minOccurs="0"/> + </sequence> + </complexType> + +</schema> diff --git a/tests/cxx/hybrid/test-template/driver.cxx b/tests/cxx/hybrid/test-template/driver.cxx new file mode 100644 index 0000000..c482a0c --- /dev/null +++ b/tests/cxx/hybrid/test-template/driver.cxx @@ -0,0 +1,56 @@ +// file : tests/cxx/hybrid/test-template/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Insert test description here. +// + +#include <iostream> + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/test-template/makefile b/tests/cxx/hybrid/test-template/makefile new file mode 100644 index 0000000..2a73ad9 --- /dev/null +++ b/tests/cxx/hybrid/test-template/makefile @@ -0,0 +1,88 @@ +# file : tests/cxx/hybrid/test-template/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,\ +$(cxx:.cxx=.o) \ +$(xsd:.xsd=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.o)) + +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=.hxx) \ + $(out_base)/$(xsd:.xsd=.cxx) \ + $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.hxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.cxx) \ + $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) \ + $(out_base)/$(xsd:.xsd=-simpl.hxx) \ + $(out_base)/$(xsd:.xsd=-simpl.cxx) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -ubB $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/test-template/output b/tests/cxx/hybrid/test-template/output new file mode 100644 index 0000000..66261f6 --- /dev/null +++ b/tests/cxx/hybrid/test-template/output @@ -0,0 +1 @@ +<t:root xmlns:t="test"><a>123</a></t:root>
\ No newline at end of file diff --git a/tests/cxx/hybrid/test-template/test.xml b/tests/cxx/hybrid/test-template/test.xml new file mode 100644 index 0000000..1b7571e --- /dev/null +++ b/tests/cxx/hybrid/test-template/test.xml @@ -0,0 +1,5 @@ +<t:root xmlns:t="test"> + + <a>123</a> + +</t:root> diff --git a/tests/cxx/hybrid/test-template/test.xsd b/tests/cxx/hybrid/test-template/test.xsd new file mode 100644 index 0000000..e0a9be1 --- /dev/null +++ b/tests/cxx/hybrid/test-template/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="a" type="int" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/hybrid/union/driver.cxx b/tests/cxx/hybrid/union/driver.cxx new file mode 100644 index 0000000..286bf14 --- /dev/null +++ b/tests/cxx/hybrid/union/driver.cxx @@ -0,0 +1,56 @@ +// file : tests/cxx/hybrid/union/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test union mapping. +// + +#include <iostream> + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/union/makefile b/tests/cxx/hybrid/union/makefile new file mode 100644 index 0000000..5c1289c --- /dev/null +++ b/tests/cxx/hybrid/union/makefile @@ -0,0 +1,88 @@ +# file : tests/cxx/hybrid/union/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,\ +$(cxx:.cxx=.o) \ +$(xsd:.xsd=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.o)) + +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=.hxx) \ + $(out_base)/$(xsd:.xsd=.cxx) \ + $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.hxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.cxx) \ + $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) \ + $(out_base)/$(xsd:.xsd=-simpl.hxx) \ + $(out_base)/$(xsd:.xsd=-simpl.cxx) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -ubB $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/union/output b/tests/cxx/hybrid/union/output new file mode 100644 index 0000000..9748083 --- /dev/null +++ b/tests/cxx/hybrid/union/output @@ -0,0 +1 @@ +<t:root xmlns:t="test"><int-string-union>123</int-string-union><int-string-union-lang lang="en">one</int-string-union-lang></t:root>
\ No newline at end of file diff --git a/tests/cxx/hybrid/union/test.xml b/tests/cxx/hybrid/union/test.xml new file mode 100644 index 0000000..a2218b2 --- /dev/null +++ b/tests/cxx/hybrid/union/test.xml @@ -0,0 +1,6 @@ +<t:root xmlns:t="test"> + + <int-string-union>123</int-string-union> + <int-string-union-lang lang="en">one</int-string-union-lang> + +</t:root> diff --git a/tests/cxx/hybrid/union/test.xsd b/tests/cxx/hybrid/union/test.xsd new file mode 100644 index 0000000..60a8d21 --- /dev/null +++ b/tests/cxx/hybrid/union/test.xsd @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="int-string-union"> + <union memberTypes="int string"/> + </simpleType> + + <complexType name="int-string-union-lang"> + <simpleContent> + <extension base="t:int-string-union"> + <attribute name="lang" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="int-string-union" type="t:int-string-union"/> + <element name="int-string-union-lang" type="t:int-string-union-lang"/> + <element name="dummy" type="boolean" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/makefile b/tests/cxx/makefile new file mode 100644 index 0000000..447d7ec --- /dev/null +++ b/tests/cxx/makefile @@ -0,0 +1,24 @@ +# file : tests/cxx/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +tests := hybrid parser serializer string + +ifeq ($(xsde_polymorphic),y) +tests += hashmap +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/parser/built-in/driver.cxx b/tests/cxx/parser/built-in/driver.cxx new file mode 100644 index 0000000..adaea5a --- /dev/null +++ b/tests/cxx/parser/built-in/driver.cxx @@ -0,0 +1,661 @@ +// file : tests/cxx/parser/built-in/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test built-in type parsing. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +using xml_schema::ro_string; + +struct any_type_pimpl: xml_schema::any_type_pimpl +{ + virtual void + pre () + { + cout << "{" << endl; + } + + virtual void +#ifndef XSDE_POLYMORPHIC + _start_any_element (ro_string const&, ro_string const& n) +#else + _start_any_element (ro_string const&, ro_string const& n, const char*) +#endif + { + cout << " start any element '" << n << "'" << endl; + } + + virtual void + _end_any_element (ro_string const&, ro_string const& n) + { + cout << " end any element '" << n << "'" << endl; + } + + virtual void + _any_attribute (ro_string const&, + ro_string const& n, + ro_string const& v) + { + cout << " any attribute " << n << " = '" << v << "'" << endl; + } + + virtual void + _any_characters (ro_string const& s) + { + cout << " any text: '" << s << "'" << endl; + } + + virtual void + post_any_type () + { + cout << "}" << endl + << endl; + } +}; + +struct any_simple_type_pimpl: xml_schema::any_simple_type_pimpl +{ + virtual void + pre () + { + cout << "{" << endl; + } + + virtual void + _any_characters (ro_string const& s) + { + cout << " any text: '" << s << "'" << endl; + } + + virtual void + post_any_simple_type () + { + cout << "}" << endl + << endl; + } +}; + +struct type_pimpl: type_pskel +{ + virtual void + boolean (bool v) + { + cout << v << endl; + } + + virtual void + byte (signed char v) + { + cout << short (v) << endl; + } + + virtual void + unsigned_byte (unsigned char v) + { + cout << (unsigned short) (v) << endl; + } + + virtual void + short_ (short v) + { + cout << v << endl; + } + + virtual void + unsigned_short (unsigned short v) + { + cout << v << endl; + } + + virtual void + int_ (int v) + { + cout << v << endl; + } + + virtual void + unsigned_int (unsigned int v) + { + cout << v << endl; + } + +#ifdef XSDE_LONGLONG + virtual void + long_ (long long v) + { + cout << v << endl; + } + + virtual void + unsigned_long (unsigned long long v) + { + cout << v << endl; + } +#else + virtual void + long_ (long v) + { + cout << v << endl; + } + + virtual void + unsigned_long (unsigned long v) + { + cout << v << endl; + } +#endif + + virtual void + integer (long v) + { + cout << v << endl; + } + + virtual void + negative_integer (long v) + { + cout << v << endl; + } + + + virtual void + non_positive_integer (long v) + { + cout << v << endl; + } + + + virtual void + positive_integer (unsigned long v) + { + cout << v << endl; + } + + virtual void + non_negative_integer (unsigned long v) + { + cout << v << endl; + } + + virtual void + float_ (float v) + { + cout << v << endl; + } + + virtual void + double_ (double v) + { + cout << v << endl; + } + + virtual void + decimal (double v) + { + cout << v << endl; + } + +#ifdef XSDE_STL + virtual void + string (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + normalized_string (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + token (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + name (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + nmtoken (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + nmtokens (xml_schema::string_sequence* s) + { + cout << "'"; + + for (xml_schema::string_sequence::const_iterator i (s->begin ()); + i != s->end (); ++i) + cout << *i << " "; + + cout << "'" << endl; + delete s; + } + + virtual void + ncname (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + id (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + idref (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + idrefs (xml_schema::string_sequence* s) + { + cout << "'"; + + for (xml_schema::string_sequence::const_iterator i (s->begin ()); + i != s->end (); ++i) + cout << *i << " "; + + cout << "'" << endl; + delete s; + } + + virtual void + language (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + uri (std::string const& v) + { + cout << "'" << v << "'" << endl; + } + + virtual void + qname (xml_schema::qname const& v) + { + cout << "'" << v.prefix () << ":" << v.name () << "'" << endl; + } + +#else // XSDE_STL + + virtual void + string (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + normalized_string (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + token (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + name (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + nmtoken (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + nmtokens (xml_schema::string_sequence* s) + { + cout << "'"; + + for (xml_schema::string_sequence::const_iterator i (s->begin ()); + i != s->end (); ++i) + cout << *i << " "; + + cout << "'" << endl; + delete s; + } + + virtual void + ncname (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + id (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + idref (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + idrefs (xml_schema::string_sequence* s) + { + cout << "'"; + + for (xml_schema::string_sequence::const_iterator i (s->begin ()); + i != s->end (); ++i) + cout << *i << " "; + + cout << "'" << endl; + delete s; + } + + virtual void + language (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + uri (char* v) + { + cout << "'" << v << "'" << endl; + delete[] v; + } + + virtual void + qname (xml_schema::qname* v) + { + cout << "'" << v->prefix () << ":" << v->name () << "'" << endl; + delete v; + } + +#endif // XSDE_STL + + + virtual void + base64_binary (xml_schema::buffer* v) + { + std::string tmp (v->data (), v->size ()); + cout << "'" << tmp << "'" << endl; + delete v; + } + + virtual void + hex_binary (xml_schema::buffer* v) + { + std::string tmp (v->data (), v->size ()); + cout << "'" << tmp << "'" << endl; + delete v; + } + + virtual void + gday (xml_schema::gday const& v) + { + cout << v.day (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + gmonth (xml_schema::gmonth const& v) + { + cout << v.month (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + gyear (xml_schema::gyear const& v) + { + cout << v.year (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + gmonth_day (xml_schema::gmonth_day const& v) + { + cout << v.month () << '-' << v.day (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + gyear_month (xml_schema::gyear_month const& v) + { + cout << v.year () << '-' << v.month (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + date (xml_schema::date const& v) + { + cout << v.year () << '-' << v.month () << '-' << v.day (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + time (xml_schema::time const& v) + { + cout << v.hours () << ':' << v.minutes () << ':' << v.seconds (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + date_time (xml_schema::date_time const& v) + { + cout << v.year () << '-' << v.month () << '-' << v.day () << 'T' + << v.hours () << ':' << v.minutes () << ':' << v.seconds (); + + if (v.zone_present ()) + cout << (v.zone_hours () < 0 ? "" : "+") << v.zone_hours () + << ':' << v.zone_minutes (); + + cout << endl; + } + + virtual void + duration (xml_schema::duration const& v) + { + cout << (v.negative () ? "-" : "") << 'P' + << v.years () << 'Y' + << v.months () << 'M' + << v.days () << 'D' + << 'T' + << v.hours () << 'H' + << v.minutes () << 'M' + << v.seconds () << 'S' + << endl; + } +}; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + try + { + any_type_pimpl any_type_p; + any_simple_type_pimpl any_simple_type_p; + + xml_schema::boolean_pimpl boolean_p; + + xml_schema::byte_pimpl byte_p; + xml_schema::unsigned_byte_pimpl unsigned_byte_p; + xml_schema::short_pimpl short_p; + xml_schema::unsigned_short_pimpl unsigned_short_p; + xml_schema::int_pimpl int_p; + xml_schema::unsigned_int_pimpl unsigned_int_p; + xml_schema::long_pimpl long_p; + xml_schema::unsigned_long_pimpl unsigned_long_p; + + xml_schema::integer_pimpl integer_p; + xml_schema::negative_integer_pimpl negative_integer_p; + xml_schema::non_positive_integer_pimpl non_positive_integer_p; + xml_schema::positive_integer_pimpl positive_integer_p; + xml_schema::non_negative_integer_pimpl non_negative_integer_p; + + xml_schema::float_pimpl float_p; + xml_schema::double_pimpl double_p; + xml_schema::decimal_pimpl decimal_p; + + xml_schema::string_pimpl string_p; + xml_schema::normalized_string_pimpl normalized_string_p; + xml_schema::token_pimpl token_p; + xml_schema::name_pimpl name_p; + xml_schema::nmtoken_pimpl nmtoken_p; + xml_schema::nmtokens_pimpl nmtokens_p; + xml_schema::ncname_pimpl ncname_p; + xml_schema::id_pimpl id_p; + xml_schema::idref_pimpl idref_p; + xml_schema::idrefs_pimpl idrefs_p; + + xml_schema::language_pimpl language_p; + xml_schema::uri_pimpl uri_p; + xml_schema::qname_pimpl qname_p; + + xml_schema::base64_binary_pimpl base64_binary_p; + xml_schema::hex_binary_pimpl hex_binary_p; + + xml_schema::gday_pimpl gday_p; + xml_schema::gmonth_pimpl gmonth_p; + xml_schema::gyear_pimpl gyear_p; + xml_schema::gmonth_day_pimpl gmonth_day_p; + xml_schema::gyear_month_pimpl gyear_month_p; + xml_schema::date_pimpl date_p; + xml_schema::time_pimpl time_p; + xml_schema::date_time_pimpl date_time_p; + xml_schema::duration_pimpl duration_p; + + type_pimpl type_p; + + type_p.parsers (any_type_p, + any_simple_type_p, + boolean_p, + byte_p, + unsigned_byte_p, + short_p, + unsigned_short_p, + int_p, + unsigned_int_p, + long_p, + unsigned_long_p, + integer_p, + negative_integer_p, + non_positive_integer_p, + positive_integer_p, + non_negative_integer_p, + float_p, + double_p, + decimal_p, + string_p, + normalized_string_p, + token_p, + name_p, + nmtoken_p, + nmtokens_p, + ncname_p, + id_p, + idref_p, + idrefs_p, + language_p, + uri_p, + qname_p, + base64_binary_p, + hex_binary_p, + gday_p, + gmonth_p, + gyear_p, + gmonth_day_p, + gyear_month_p, + date_p, + time_p, + date_time_p, + duration_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/built-in/makefile b/tests/cxx/parser/built-in/makefile new file mode 100644 index 0000000..9975660 --- /dev/null +++ b/tests/cxx/parser/built-in/makefile @@ -0,0 +1,79 @@ +# file : tests/cxx/parser/built-in/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde + +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) + +ifeq ($(xsde_longlong),y) +$(test): $(driver) $(src_base)/test-long-long.xml $(src_base)/output-long-long + $(call message,test $$1,$$1 $(src_base)/test-long-long.xml | diff -u $(src_base)/output-long-long -,$(driver)) +else +$(test): $(driver) $(src_base)/test-long.xml $(src_base)/output-long + $(call message,test $$1,$$1 $(src_base)/test-long.xml | diff -u $(src_base)/output-long -,$(driver)) +endif + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/built-in/output-long b/tests/cxx/parser/built-in/output-long new file mode 100644 index 0000000..f3526bc --- /dev/null +++ b/tests/cxx/parser/built-in/output-long @@ -0,0 +1,167 @@ +{ + any attribute x = 'x' + any text: ' +' + any text: ' ' + start any element 'a' + any text: 'a' + end any element 'a' + any text: ' +' + any text: ' ' + start any element 'any-type' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any-type' + any text: ' +' + any text: ' ' +} + +{ + any text: '123abc' +} + +1 +0 +1 +0 +0 +127 +-128 +123 +0 +255 +123 +0 +32767 +-32768 +-12345 +0 +65535 +12345 +0 +2147483647 +-2147483648 +-1234567890 +0 +4294967295 +1234567890 +0 +2147483647 +-2147483648 +-1234567890 +0 +4294967295 +1234567890 +0 +2147483647 +-2147483648 +-1234567890 +-2147483648 +-1234567890 +0 +-2147483648 +-1234567890 +4294967295 +1234567890 +0 +4294967295 +1234567890 +0 +0 +-0 +inf +-inf +nan +123.567 +123.567 +-1.23567e+07 +-4.5e-06 +0 +0 +-0 +inf +-inf +nan +123.567 +123.567 +-1.23567e+07 +-4.5e-06 +0 +0 +-0 +123.567 +123.567 +-123.567 +'string space +newline + ' +' string space newline ' +'string space newline' +'as123:345-.abs' +'1as123:345-.abs' +'abc 123 ' +'as123_345-.abs' +'as123_345-.abs' +'abc' +'a123' +'as123_345-.abs' +'abc a123 ' +'x' +'en' +'en-us' +'one-two-three-four44-seven77-eight888' +'' +'relative' +'#id' +'http://www.example.com/foo#bar' +':schemaLocation' +'xsi:schemaLocation' +'12345abcjk' +'a' +'ab' +'abc' +'' +'12345abcjk' +12+12:0 +1 +31 +15+0:0 +15-14:0 +10+12:0 +1 +12+0:0 +2007+12:0 +1 +-20000+0:0 +10-28+12:0 +12-31 +1-1+0:0 +2007-12+12:0 +-2007-10 +20007-10+0:0 +-20007-1 +2007-12-26+12:0 +-2007-10-15 +20007-12-31+0:0 +-20007-1-1 +12:46:23.456+12:0 +12:13:14 +12:13:14+0:0 +2007-12-26T12:13:14.123+12:0 +-2007-10-15T12:13:14 +20007-12-31T12:13:14+0:0 +-20007-1-1T12:13:14 +-P2007Y13M32DT25H61M61.123S +P1Y0M0DT0H0M0S +P0Y1M0DT0H0M0S +P0Y0M1DT0H0M0S +P0Y0M0DT1H0M0S +P0Y0M0DT0H1M0S +P0Y0M0DT0H0M1.1S +P1Y0M0DT0H0M1S diff --git a/tests/cxx/parser/built-in/output-long-long b/tests/cxx/parser/built-in/output-long-long new file mode 100644 index 0000000..3b80787 --- /dev/null +++ b/tests/cxx/parser/built-in/output-long-long @@ -0,0 +1,167 @@ +{ + any attribute x = 'x' + any text: ' +' + any text: ' ' + start any element 'a' + any text: 'a' + end any element 'a' + any text: ' +' + any text: ' ' + start any element 'any-type' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any-type' + any text: ' +' + any text: ' ' +} + +{ + any text: '123abc' +} + +1 +0 +1 +0 +0 +127 +-128 +123 +0 +255 +123 +0 +32767 +-32768 +-12345 +0 +65535 +12345 +0 +2147483647 +-2147483648 +-1234567890 +0 +4294967295 +1234567890 +0 +9223372036854775807 +-9223372036854775808 +-1234567890123456789 +0 +18446744073709551615 +12345678901234567890 +0 +2147483647 +-2147483648 +-1234567890 +-2147483648 +-1234567890 +0 +-2147483648 +-1234567890 +4294967295 +1234567890 +0 +4294967295 +1234567890 +0 +0 +-0 +inf +-inf +nan +123.567 +123.567 +-1.23567e+07 +-4.5e-06 +0 +0 +-0 +inf +-inf +nan +123.567 +123.567 +-1.23567e+07 +-4.5e-06 +0 +0 +-0 +123.567 +123.567 +-123.567 +'string space +newline + ' +' string space newline ' +'string space newline' +'as123:345-.abs' +'1as123:345-.abs' +'abc 123 ' +'as123_345-.abs' +'as123_345-.abs' +'abc' +'a123' +'as123_345-.abs' +'abc a123 ' +'x' +'en' +'en-us' +'one-two-three-four44-seven77-eight888' +'' +'relative' +'#id' +'http://www.example.com/foo#bar' +':schemaLocation' +'xsi:schemaLocation' +'12345abcjk' +'a' +'ab' +'abc' +'' +'12345abcjk' +12+12:0 +1 +31 +15+0:0 +15-14:0 +10+12:0 +1 +12+0:0 +2007+12:0 +1 +-20000+0:0 +10-28+12:0 +12-31 +1-1+0:0 +2007-12+12:0 +-2007-10 +20007-10+0:0 +-20007-1 +2007-12-26+12:0 +-2007-10-15 +20007-12-31+0:0 +-20007-1-1 +12:46:23.456+12:0 +12:13:14 +12:13:14+0:0 +2007-12-26T12:13:14.123+12:0 +-2007-10-15T12:13:14 +20007-12-31T12:13:14+0:0 +-20007-1-1T12:13:14 +-P2007Y13M32DT25H61M61.123S +P1Y0M0DT0H0M0S +P0Y1M0DT0H0M0S +P0Y0M1DT0H0M0S +P0Y0M0DT1H0M0S +P0Y0M0DT0H1M0S +P0Y0M0DT0H0M1.1S +P1Y0M0DT0H0M1S diff --git a/tests/cxx/parser/built-in/test-long-long.xml b/tests/cxx/parser/built-in/test-long-long.xml new file mode 100644 index 0000000..8d9332a --- /dev/null +++ b/tests/cxx/parser/built-in/test-long-long.xml @@ -0,0 +1,199 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <any-type x="x"> + <a>a</a> + <any-type x="xxx">aaa<a>bbb</a>ccc</any-type> + </any-type> + + <any-simple-type>123abc</any-simple-type> + + <boolean>1</boolean> + <boolean> 0 </boolean> + <boolean>true</boolean> + <boolean> false </boolean> + + <byte>0</byte> + <byte>+127</byte> + <byte>-128</byte> + <byte> 123 </byte> + + <unsigned-byte>0</unsigned-byte> + <unsigned-byte>255</unsigned-byte> + <unsigned-byte> 123 </unsigned-byte> + + <short>0</short> + <short>+32767</short> + <short>-32768</short> + <short> -12345 </short> + + <unsigned-short>0</unsigned-short> + <unsigned-short>65535</unsigned-short> + <unsigned-short> 12345 </unsigned-short> + + <int>0</int> + <int>+2147483647</int> + <int>-2147483648</int> + <int> -1234567890 </int> + + <unsigned-int>0</unsigned-int> + <unsigned-int>4294967295</unsigned-int> + <unsigned-int> 1234567890 </unsigned-int> + + <long>0</long> + <long>+9223372036854775807</long> + <long>-9223372036854775808</long> + <long> -1234567890123456789 </long> + + <unsigned-long>0</unsigned-long> + <unsigned-long>18446744073709551615</unsigned-long> + <unsigned-long> 12345678901234567890 </unsigned-long> + + <integer>0</integer> + <integer> +2147483647 </integer> + <integer>-02147483648</integer> + <integer>-1234567890</integer> + + <negative-integer>-02147483648</negative-integer> + <negative-integer> -1234567890 </negative-integer> + + <non-positive-integer>0</non-positive-integer> + <non-positive-integer>-02147483648</non-positive-integer> + <non-positive-integer> -1234567890 </non-positive-integer> + + <positive-integer>4294967295</positive-integer> + <positive-integer> +01234567890 </positive-integer> + + <non-negative-integer>0</non-negative-integer> + <non-negative-integer>4294967295</non-negative-integer> + <non-negative-integer> +01234567890 </non-negative-integer> + + <float>0</float> + <float>+0</float> + <float>-0</float> + <float>INF</float> + <float>-INF</float> + <float>NaN</float> + <float> 123.567 </float> + <float>+123.567</float> + <float>-123.567e5</float> + <float>-.45E-5</float> + + <double>0</double> + <double>+0</double> + <double>-0</double> + <double>INF</double> + <double>-INF</double> + <double>NaN</double> + <double> 123.567 </double> + <double>+123.567</double> + <double>-123.567e5</double> + <double>-.45E-5</double> + + <decimal>0</decimal> + <decimal>+0</decimal> + <decimal>-0</decimal> + <decimal> 123.567 </decimal> + <decimal>+123.567</decimal> + <decimal>-123.567</decimal> + + <string>string space +newline + </string> + + <normalized-string> string space +newline + + </normalized-string> + + <token> string space +newline + + </token> + + <name> as123:345-.abs </name> + + <nmtoken> 1as123:345-.abs </nmtoken> + + <nmtokens> abc 123 </nmtokens> + + <ncname> as123_345-.abs </ncname> + + <id> as123_345-.abs </id> + <id> abc </id> + <id> a123 </id> + + <idref> as123_345-.abs </idref> + + <idrefs> abc a123 </idrefs> + + <language> x </language> + <language> en </language> + <language> en-us </language> + <language>one-two-three-four44-seven77-eight888</language> + + <uri> </uri> + <uri> relative </uri> + <uri> #id </uri> + <uri> http://www.example.com/foo#bar </uri> + + <qname>schemaLocation</qname> + <qname>xsi:schemaLocation</qname> + + <base64_binary> MTIzND + VhYmNqaw = =</base64_binary> + <base64_binary>YQ==</base64_binary> + <base64_binary>YWI=</base64_binary> + <base64_binary>YWJj</base64_binary> + + <hex_binary> </hex_binary> + <hex_binary> 31323334356162636a6b </hex_binary> + + <gday> ---12+12:00 </gday> + <gday>---01</gday> + <gday>---31</gday> + <gday>---15Z</gday> + <gday>---15-14:00</gday> + + <gmonth> --10+12:00 </gmonth> + <gmonth>--01</gmonth> + <gmonth>--12Z</gmonth> + + <gyear> 2007+12:00 </gyear> + <gyear>0001</gyear> + <gyear>-20000Z</gyear> + + <gmonth_day> --10-28+12:00 </gmonth_day> + <gmonth_day>--12-31</gmonth_day> + <gmonth_day>--01-01Z</gmonth_day> + + <gyear_month> 2007-12+12:00 </gyear_month> + <gyear_month>-2007-10</gyear_month> + <gyear_month>20007-10Z</gyear_month> + <gyear_month>-20007-01</gyear_month> + + <date> 2007-12-26+12:00 </date> + <date>-2007-10-15</date> + <date>20007-12-31Z</date> + <date>-20007-01-01</date> + + <time> 12:46:23.456+12:00 </time> + <time>12:13:14</time> + <time>12:13:14Z</time> + + <date_time> 2007-12-26T12:13:14.123+12:00 </date_time> + <date_time>-2007-10-15T12:13:14</date_time> + <date_time>20007-12-31T12:13:14Z</date_time> + <date_time>-20007-01-01T12:13:14</date_time> + + <duration> -P2007Y13M32DT25H61M61.123S </duration> + <duration>P1Y</duration> + <duration>P1M</duration> + <duration>P1D</duration> + <duration>PT1H</duration> + <duration>PT1M</duration> + <duration>PT1.1S</duration> + <duration>P1YT1S</duration> + +</t:root> diff --git a/tests/cxx/parser/built-in/test-long.xml b/tests/cxx/parser/built-in/test-long.xml new file mode 100644 index 0000000..380b0f4 --- /dev/null +++ b/tests/cxx/parser/built-in/test-long.xml @@ -0,0 +1,199 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <any-type x="x"> + <a>a</a> + <any-type x="xxx">aaa<a>bbb</a>ccc</any-type> + </any-type> + + <any-simple-type>123abc</any-simple-type> + + <boolean>1</boolean> + <boolean> 0 </boolean> + <boolean>true</boolean> + <boolean> false </boolean> + + <byte>0</byte> + <byte>+127</byte> + <byte>-128</byte> + <byte> 123 </byte> + + <unsigned-byte>0</unsigned-byte> + <unsigned-byte>255</unsigned-byte> + <unsigned-byte> 123 </unsigned-byte> + + <short>0</short> + <short>+32767</short> + <short>-32768</short> + <short> -12345 </short> + + <unsigned-short>0</unsigned-short> + <unsigned-short>65535</unsigned-short> + <unsigned-short> 12345 </unsigned-short> + + <int>0</int> + <int>+2147483647</int> + <int>-2147483648</int> + <int> -1234567890 </int> + + <unsigned-int>0</unsigned-int> + <unsigned-int>4294967295</unsigned-int> + <unsigned-int> 1234567890 </unsigned-int> + + <long>0</long> + <long>+2147483647</long> + <long>-2147483648</long> + <long> -1234567890 </long> + + <unsigned-long>0</unsigned-long> + <unsigned-long>4294967295</unsigned-long> + <unsigned-long> 1234567890 </unsigned-long> + + <integer>0</integer> + <integer> +2147483647 </integer> + <integer>-02147483648</integer> + <integer>-1234567890</integer> + + <negative-integer>-02147483648</negative-integer> + <negative-integer> -1234567890 </negative-integer> + + <non-positive-integer>0</non-positive-integer> + <non-positive-integer>-02147483648</non-positive-integer> + <non-positive-integer> -1234567890 </non-positive-integer> + + <positive-integer>4294967295</positive-integer> + <positive-integer> +01234567890 </positive-integer> + + <non-negative-integer>0</non-negative-integer> + <non-negative-integer>4294967295</non-negative-integer> + <non-negative-integer> +01234567890 </non-negative-integer> + + <float>0</float> + <float>+0</float> + <float>-0</float> + <float>INF</float> + <float>-INF</float> + <float>NaN</float> + <float> 123.567 </float> + <float>+123.567</float> + <float>-123.567e5</float> + <float>-.45E-5</float> + + <double>0</double> + <double>+0</double> + <double>-0</double> + <double>INF</double> + <double>-INF</double> + <double>NaN</double> + <double> 123.567 </double> + <double>+123.567</double> + <double>-123.567e5</double> + <double>-.45E-5</double> + + <decimal>0</decimal> + <decimal>+0</decimal> + <decimal>-0</decimal> + <decimal> 123.567 </decimal> + <decimal>+123.567</decimal> + <decimal>-123.567</decimal> + + <string>string space +newline + </string> + + <normalized-string> string space +newline + + </normalized-string> + + <token> string space +newline + + </token> + + <name> as123:345-.abs </name> + + <nmtoken> 1as123:345-.abs </nmtoken> + + <nmtokens> abc 123 </nmtokens> + + <ncname> as123_345-.abs </ncname> + + <id> as123_345-.abs </id> + <id> abc </id> + <id> a123 </id> + + <idref> as123_345-.abs </idref> + + <idrefs> abc a123 </idrefs> + + <language> x </language> + <language> en </language> + <language> en-us </language> + <language>one-two-three-four44-seven77-eight888</language> + + <uri> </uri> + <uri> relative </uri> + <uri> #id </uri> + <uri> http://www.example.com/foo#bar </uri> + + <qname>schemaLocation</qname> + <qname>xsi:schemaLocation</qname> + + <base64_binary> MTIzND + VhYmNqaw = =</base64_binary> + <base64_binary>YQ==</base64_binary> + <base64_binary>YWI=</base64_binary> + <base64_binary>YWJj</base64_binary> + + <hex_binary> </hex_binary> + <hex_binary> 31323334356162636a6b </hex_binary> + + <gday> ---12+12:00 </gday> + <gday>---01</gday> + <gday>---31</gday> + <gday>---15Z</gday> + <gday>---15-14:00</gday> + + <gmonth> --10+12:00 </gmonth> + <gmonth>--01</gmonth> + <gmonth>--12Z</gmonth> + + <gyear> 2007+12:00 </gyear> + <gyear>0001</gyear> + <gyear>-20000Z</gyear> + + <gmonth_day> --10-28+12:00 </gmonth_day> + <gmonth_day>--12-31</gmonth_day> + <gmonth_day>--01-01Z</gmonth_day> + + <gyear_month> 2007-12+12:00 </gyear_month> + <gyear_month>-2007-10</gyear_month> + <gyear_month>20007-10Z</gyear_month> + <gyear_month>-20007-01</gyear_month> + + <date> 2007-12-26+12:00 </date> + <date>-2007-10-15</date> + <date>20007-12-31Z</date> + <date>-20007-01-01</date> + + <time> 12:46:23.456+12:00 </time> + <time>12:13:14</time> + <time>12:13:14Z</time> + + <date_time> 2007-12-26T12:13:14.123+12:00 </date_time> + <date_time>-2007-10-15T12:13:14</date_time> + <date_time>20007-12-31T12:13:14Z</date_time> + <date_time>-20007-01-01T12:13:14</date_time> + + <duration> -P2007Y13M32DT25H61M61.123S </duration> + <duration>P1Y</duration> + <duration>P1M</duration> + <duration>P1D</duration> + <duration>PT1H</duration> + <duration>PT1M</duration> + <duration>PT1.1S</duration> + <duration>P1YT1S</duration> + +</t:root> diff --git a/tests/cxx/parser/built-in/test.xsd b/tests/cxx/parser/built-in/test.xsd new file mode 100644 index 0000000..9c00eb4 --- /dev/null +++ b/tests/cxx/parser/built-in/test.xsd @@ -0,0 +1,63 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="any-type" type="anyType" maxOccurs="unbounded"/> + <element name="any-simple-type" type="anySimpleType" maxOccurs="unbounded"/> + + <element name="boolean" type="boolean" maxOccurs="unbounded"/> + + <element name="byte" type="byte" maxOccurs="unbounded"/> + <element name="unsigned-byte" type="unsignedByte" maxOccurs="unbounded"/> + <element name="short" type="short" maxOccurs="unbounded"/> + <element name="unsigned-short" type="unsignedShort" maxOccurs="unbounded"/> + <element name="int" type="int" maxOccurs="unbounded"/> + <element name="unsigned-int" type="unsignedInt" maxOccurs="unbounded"/> + <element name="long" type="long" maxOccurs="unbounded"/> + <element name="unsigned-long" type="unsignedLong" maxOccurs="unbounded"/> + + <element name="integer" type="integer" maxOccurs="unbounded"/> + <element name="negative-integer" type="negativeInteger" maxOccurs="unbounded"/> + <element name="non-positive-integer" type="nonPositiveInteger" maxOccurs="unbounded"/> + <element name="positive-integer" type="positiveInteger" maxOccurs="unbounded"/> + <element name="non-negative-integer" type="nonNegativeInteger" maxOccurs="unbounded"/> + + <element name="float" type="float" maxOccurs="unbounded"/> + <element name="double" type="double" maxOccurs="unbounded"/> + <element name="decimal" type="decimal" maxOccurs="unbounded"/> + + <element name="string" type="string" maxOccurs="unbounded"/> + <element name="normalized-string" type="normalizedString" maxOccurs="unbounded"/> + <element name="token" type="token" maxOccurs="unbounded"/> + <element name="name" type="Name" maxOccurs="unbounded"/> + <element name="nmtoken" type="NMTOKEN" maxOccurs="unbounded"/> + <element name="nmtokens" type="NMTOKENS" maxOccurs="unbounded"/> + <element name="ncname" type="NCName" maxOccurs="unbounded"/> + <element name="id" type="ID" maxOccurs="unbounded"/> + <element name="idref" type="IDREF" maxOccurs="unbounded"/> + <element name="idrefs" type="IDREFS" maxOccurs="unbounded"/> + + <element name="language" type="language" maxOccurs="unbounded"/> + <element name="uri" type="anyURI" maxOccurs="unbounded"/> + <element name="qname" type="QName" maxOccurs="unbounded"/> + + <element name="base64_binary" type="base64Binary" maxOccurs="unbounded"/> + <element name="hex_binary" type="hexBinary" maxOccurs="unbounded"/> + + <element name="gday" type="gDay" maxOccurs="unbounded"/> + <element name="gmonth" type="gMonth" maxOccurs="unbounded"/> + <element name="gyear" type="gYear" maxOccurs="unbounded"/> + <element name="gmonth_day" type="gMonthDay" maxOccurs="unbounded"/> + <element name="gyear_month" type="gYearMonth" maxOccurs="unbounded"/> + <element name="date" type="date" maxOccurs="unbounded"/> + <element name="time" type="time" maxOccurs="unbounded"/> + <element name="date_time" type="dateTime" maxOccurs="unbounded"/> + <element name="duration" type="duration" maxOccurs="unbounded"/> + + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/duplicate/makefile b/tests/cxx/parser/duplicate/makefile new file mode 100644 index 0000000..20b4a11 --- /dev/null +++ b/tests/cxx/parser/duplicate/makefile @@ -0,0 +1,79 @@ +# file : tests/cxx/parser/duplicate/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd + +obj := $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.o) $(xsd:.xsd=-pimpl.o) $(xsd:.xsd=-pdriver.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/$(xsd:.xsd=-pdriver) +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.hxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.cxx) \ + $(out_base)/$(xsd:.xsd=-pdriver.cxx) + +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-print-impl --generate-test-driver \ +--force-overwrite +$(gen): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pimpl.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +xsd_pimpl_suffix := -pimpl +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/duplicate/output b/tests/cxx/parser/duplicate/output new file mode 100644 index 0000000..f03814e --- /dev/null +++ b/tests/cxx/parser/duplicate/output @@ -0,0 +1,3 @@ +a: 1 +a: 2 +a: 3 diff --git a/tests/cxx/parser/duplicate/test.xml b/tests/cxx/parser/duplicate/test.xml new file mode 100644 index 0000000..62e4c0b --- /dev/null +++ b/tests/cxx/parser/duplicate/test.xml @@ -0,0 +1,9 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a>1</a> + <a>2</a> + <a>3</a> + +</t:root> diff --git a/tests/cxx/parser/duplicate/test.xsd b/tests/cxx/parser/duplicate/test.xsd new file mode 100644 index 0000000..ebe1295 --- /dev/null +++ b/tests/cxx/parser/duplicate/test.xsd @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- Test duplicate element handling --> + + <complexType name="type"> + <sequence> + <element name="a" type="int"/> + <element name="a" type="int"/> + <element name="a" type="int"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/enumeration/driver.cxx b/tests/cxx/parser/enumeration/driver.cxx new file mode 100644 index 0000000..e5440e1 --- /dev/null +++ b/tests/cxx/parser/enumeration/driver.cxx @@ -0,0 +1,99 @@ +// file : tests/cxx/parser/enumeration/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test xsd:enumeration parsing. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace xml_schema; + +namespace test +{ + struct digit_pimpl: digit_pskel + { + digit_pimpl () + : digit_pskel (&base_impl_) + { + } + + int_pimpl base_impl_; + }; + + struct gender_pimpl: gender_pskel + { + gender_pimpl () + : gender_pskel (&base_impl_) + { + } + + virtual ::gender + post_gender () + { + std::string str (post_string ()); + + if (str == "male") + return male; + else + return female; + } + + string_pimpl base_impl_; + }; + + struct type_pimpl: type_pskel + { + virtual void + digit (int i) + { + cout << i << endl; + } + + virtual void + gender (::gender g) + { + cout << g << endl; + } + }; +} + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + try + { + test::digit_pimpl digit_p; + test::gender_pimpl gender_p; + test::type_pimpl type_p; + + type_p.parsers (digit_p, gender_p); + + document_pimpl doc_p (type_p, "test", "root"); + + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/enumeration/gender.hxx b/tests/cxx/parser/enumeration/gender.hxx new file mode 100644 index 0000000..be74b4a --- /dev/null +++ b/tests/cxx/parser/enumeration/gender.hxx @@ -0,0 +1,15 @@ +// file : tests/cxx/parser/enumeration/gender.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef GENDER_HXX +#define GENDER_HXX + +enum gender +{ + male, + female +}; + +#endif // GENDER_HXX diff --git a/tests/cxx/parser/enumeration/makefile b/tests/cxx/parser/enumeration/makefile new file mode 100644 index 0000000..ef898da --- /dev/null +++ b/tests/cxx/parser/enumeration/makefile @@ -0,0 +1,76 @@ +# file : tests/cxx/parser/enumeration/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): cpp_options := -I$(out_base) -I$(src_base) +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): xsde_options += --type-map $(src_base)/test.map + +$(skel): $(out_root)/xsde/xsde $(src_base)/test.map + +$(call include-dep,$(dep)) + + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/enumeration/output b/tests/cxx/parser/enumeration/output new file mode 100644 index 0000000..16db301 --- /dev/null +++ b/tests/cxx/parser/enumeration/output @@ -0,0 +1,3 @@ +1 +0 +1 diff --git a/tests/cxx/parser/enumeration/test.map b/tests/cxx/parser/enumeration/test.map new file mode 100644 index 0000000..f8868d6 --- /dev/null +++ b/tests/cxx/parser/enumeration/test.map @@ -0,0 +1,7 @@ +namespace test +{ + include "gender.hxx"; + + digit int int; + gender ::gender ::gender; +} diff --git a/tests/cxx/parser/enumeration/test.xml b/tests/cxx/parser/enumeration/test.xml new file mode 100644 index 0000000..a6fa893 --- /dev/null +++ b/tests/cxx/parser/enumeration/test.xml @@ -0,0 +1,10 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <digit>1</digit> + + <gender>male</gender> + <gender>female</gender> + +</t:root> diff --git a/tests/cxx/parser/enumeration/test.xsd b/tests/cxx/parser/enumeration/test.xsd new file mode 100644 index 0000000..ded3a18 --- /dev/null +++ b/tests/cxx/parser/enumeration/test.xsd @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="digit"> + <restriction base="int"> + <enumeration value="0"/> + <enumeration value="1"/> + <enumeration value="2"/> + <enumeration value="3"/> + <enumeration value="4"/> + <enumeration value="5"/> + <enumeration value="6"/> + <enumeration value="7"/> + <enumeration value="8"/> + <enumeration value="9"/> + </restriction> + </simpleType> + + <simpleType name="gender"> + <restriction base="string"> + <enumeration value="male"/> + <enumeration value="female"/> + </restriction> + </simpleType> + + <complexType name="type"> + <choice maxOccurs="unbounded"> + <element name="digit" type="t:digit"/> + <element name="gender" type="t:gender"/> + </choice> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/error-handling/codes/driver.cxx b/tests/cxx/parser/error-handling/codes/driver.cxx new file mode 100644 index 0000000..8b3c693 --- /dev/null +++ b/tests/cxx/parser/error-handling/codes/driver.cxx @@ -0,0 +1,276 @@ +// file : tests/cxx/parser/error-handling/codes/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test error reporting with error codes. +// + +#include <string> +#include <cassert> +#include <sstream> +#include <fstream> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct person_pimpl: person_pskel +{ + person_pimpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { + if (i_ == 4) + _app_error (4); + } + +#ifdef XSDE_STL + virtual void + id (string const&) + { + if (i_ == 5) + _app_error (5); + } +#else + virtual void + id (char* s) + { + delete[] s; + + if (i_ == 5) + _app_error (5); + } +#endif + + virtual void + age (int age) + { + if (i_ == 6) + _app_error (6); + + age_ = age; + } + + virtual int + post_person () + { + if (i_ == 7) + { + _app_error (7); + return 0; + } + + return age_; + } + +private: + int age_; + unsigned long i_; + +}; + + +struct type_pimpl: type_pskel +{ + type_pimpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { + if (i_ == 1) + _app_error (1); + } + + virtual void + person (int) + { + if (i_ == 2) + _app_error (2); + } + + virtual void + post_type () + { + if (i_ == 3) + _app_error (3); + } + +private: + unsigned long i_; +}; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // 0: xml error + // + // 1: app error from top-level pre + // 2: app error from top-level callback + // 3: app error from top-level post + // 4: app error from nested pre + // 5: app error from nested attribute callback + // 6: app error from nested element callback + // 7: app error from nested post + // + // 8: schema error (root element mismatch) + // 9: schema error (missing required element) + // 10: schema error (missing required attribute) + // 11: schema error (extraneous element) + // 12: schema error (extraneous attribute) + // 13: schema error (invalid datatype value) + // + // 14: io error (no such file) + // + // + for (unsigned long i (0); i < 15; ++i) + { + xml_schema::int_pimpl int_p; + xml_schema::string_pimpl string_p; + person_pimpl person_p (i); + type_pimpl type_p (i); + + person_p.parsers (string_p, int_p); + type_p.parsers (person_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + // + // + typedef xml_schema::parser_error error; + + type_p.pre (); + + if (error e = type_p._error ()) + { + assert (e.type () == error::app); + cout << "app: " << e.app_code () << endl; + continue; + } + + + if (i == 0) + { + istringstream is ("<t:root xmlns:t='test'>\n</t:rot>"); + doc_p.parse (is); + } + else if (i == 8) + { + istringstream is ("<t:rot xmlns:t='test'>\n</t:rot>"); + doc_p.parse (is); + } + else if (i == 9) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a'/>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 10) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person><age>64</age></person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 11) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a'>\n" + "<age>64</age>\n" + "<foo/>\n" + "</person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 12) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a' foo='f'>\n" + "<age>64</age>\n" + "</person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 13) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a'>\n" + "<age>a64</age>\n" + "</person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 14) + { + doc_p.parse ("no-such-file.xml"); + } + else + doc_p.parse (argv[1]); + + + if (error e = doc_p._error ()) + { + switch (e.type ()) + { + case error::sys: + { + cout << "sys: " << e.sys_code () << ": " << e.sys_text () + << endl; + break; + } + case error::xml: + { + cout << "xml:" << e.line () << ":" << e.column () << ": " + << e.xml_code () << ": " << e.xml_text () << endl; + break; + } +#ifdef XSDE_PARSER_VALIDATION + case error::schema: + { + cout << "schema:" << e.line () << ":" << e.column () << ": " + << e.schema_code () << ": " << e.schema_text () << endl; + break; + } +#endif + case error::app: + { + cout << "app:" << e.line () << ":" << e.column () << ": " + << e.app_code () << endl; + break; + } + } + + continue; + } + + type_p.post_type (); + + if (error e = type_p._error ()) + { + assert (e.type () == error::app); + cout << "app: " << e.app_code () << endl; + continue; + } + } +} diff --git a/tests/cxx/parser/error-handling/codes/makefile b/tests/cxx/parser/error-handling/codes/makefile new file mode 100644 index 0000000..ca9ba5c --- /dev/null +++ b/tests/cxx/parser/error-handling/codes/makefile @@ -0,0 +1,74 @@ +# file : tests/cxx/parser/error-handling/codes/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): xsde_options += --no-exceptions --type-map $(src_base)/test.map + +$(skel): $(out_root)/xsde/xsde $(src_base)/test.map + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/error-handling/codes/output b/tests/cxx/parser/error-handling/codes/output new file mode 100644 index 0000000..bdf6520 --- /dev/null +++ b/tests/cxx/parser/error-handling/codes/output @@ -0,0 +1,15 @@ +xml:2:2: 7: mismatched tag +app: 1 +app:7:11: 2 +app: 3 +app:5:19: 4 +app:5:19: 5 +app:6:17: 6 +app:7:11: 7 +schema:1:22: 4: unexpected element encountered +schema:2:16: 3: expected element not encountered +schema:2:30: 1: expected attribute not encountered +schema:4:6: 4: unexpected element encountered +schema:2:23: 2: unexpected attribute encountered +schema:3:14: 11: invalid int value +sys: 2: open failed diff --git a/tests/cxx/parser/error-handling/codes/test.map b/tests/cxx/parser/error-handling/codes/test.map new file mode 100644 index 0000000..5da7e3d --- /dev/null +++ b/tests/cxx/parser/error-handling/codes/test.map @@ -0,0 +1,4 @@ +namespace test +{ + person int int; +} diff --git a/tests/cxx/parser/error-handling/codes/test.xml b/tests/cxx/parser/error-handling/codes/test.xml new file mode 100644 index 0000000..07def4b --- /dev/null +++ b/tests/cxx/parser/error-handling/codes/test.xml @@ -0,0 +1,9 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <person id="old"> + <age>67</age> + </person> + +</t:root> diff --git a/tests/cxx/parser/error-handling/codes/test.xsd b/tests/cxx/parser/error-handling/codes/test.xsd new file mode 100644 index 0000000..6850342 --- /dev/null +++ b/tests/cxx/parser/error-handling/codes/test.xsd @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="person"> + <sequence> + <element name="age" type="int"/> + </sequence> + <attribute name="id" type="string" use="required"/> + </complexType> + + <complexType name="type"> + <sequence> + <element name="person" type="t:person" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/error-handling/exceptions/driver.cxx b/tests/cxx/parser/error-handling/exceptions/driver.cxx new file mode 100644 index 0000000..0ad6b80 --- /dev/null +++ b/tests/cxx/parser/error-handling/exceptions/driver.cxx @@ -0,0 +1,256 @@ +// file : tests/cxx/parser/error-handling/exceptions/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test error reporting with exceptions. +// + +#include <string> +#include <sstream> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct app +{ + app (unsigned long code) + : code_ (code) + { + } + + unsigned long + code () const + { + return code_; + } + +private: + unsigned long code_; +}; + +struct person_pimpl: person_pskel +{ + person_pimpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { + if (i_ == 4) + throw app (4); + } + +#ifdef XSDE_STL + virtual void + id (string const&) + { + if (i_ == 5) + throw app (5); + } +#else + virtual void + id (char* s) + { + delete[] s; + + if (i_ == 5) + throw app (5); + } +#endif + + virtual void + age (int age) + { + if (i_ == 6) + throw app (6); + + age_ = age; + } + + virtual int + post_person () + { + if (i_ == 7) + throw app (7); + + return age_; + } + +private: + int age_; + unsigned long i_; +}; + + +struct type_pimpl: type_pskel +{ + type_pimpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { + if (i_ == 1) + throw app (1); + } + + virtual void + person (int) + { + if (i_ == 2) + throw app (2); + } + + virtual void + post_type () + { + if (i_ == 3) + throw app (3); + } + +private: + unsigned long i_; +}; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // 0: xml error + // + // 1: app error from top-level pre + // 2: app error from top-level callback + // 3: app error from top-level post + // 4: app error from nested pre + // 5: app error from nested attribute callback + // 6: app error from nested element callback + // 7: app error from nested post + // + // 8: schema error (root element mismatch) + // 9: schema error (missing required element) + // 10: schema error (missing required attribute) + // 11: schema error (extraneous element) + // 12: schema error (extraneous attribute) + // 13: schema error (invalid datatype value) + // + // 14: io error (no such file) + // + // + for (unsigned long i (0); i < 15; ++i) + { + try + { + xml_schema::int_pimpl int_p; + xml_schema::string_pimpl string_p; + person_pimpl person_p (i); + type_pimpl type_p (i); + + person_p.parsers (string_p, int_p); + type_p.parsers (person_p); + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + // + // + type_p.pre (); + + if (i == 0) + { + istringstream is ("<t:root xmlns:t='test'>\n</t:rot>"); + doc_p.parse (is); + } + else if (i == 8) + { + istringstream is ("<t:rot xmlns:t='test'>\n</t:rot>"); + doc_p.parse (is); + } + else if (i == 9) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a'/>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 10) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person><age>64</age></person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 11) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a'>\n" + "<age>64</age>\n" + "<foo/>\n" + "</person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 12) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a' foo='f'>\n" + "<age>64</age>\n" + "</person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 13) + { + istringstream is ( + "<t:root xmlns:t='test'>\n" + "<person id='a'>\n" + "<age>a64</age>\n" + "</person>\n" + "</t:root>"); + doc_p.parse (is); + } + else if (i == 14) + { + doc_p.parse ("no-such-file.xml"); + } + else + doc_p.parse (argv[1]); + + type_p.post_type (); + } + catch (ios_base::failure const&) + { + cout << "io: io error" << endl; + } + catch (xml_schema::parser_xml const& e) + { + cout << "xml:" << e.line () << ":" << e.column () << ": " + << e.code () << ": " << e.text () << endl; + } +#ifdef XSDE_PARSER_VALIDATION + catch (xml_schema::parser_schema const& e) + { + cout << "schema:" << e.line () << ":" << e.column () << ": " + << e.code () << ": " << e.text () << endl; + } +#endif + catch (app const& e) + { + cout << "app: " << e.code () << endl; + } + } +} diff --git a/tests/cxx/parser/error-handling/exceptions/makefile b/tests/cxx/parser/error-handling/exceptions/makefile new file mode 100644 index 0000000..8acb98a --- /dev/null +++ b/tests/cxx/parser/error-handling/exceptions/makefile @@ -0,0 +1,75 @@ +# file : tests/cxx/parser/error-handling/exceptions/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): xsde_options += --type-map $(src_base)/test.map + +$(skel): $(out_root)/xsde/xsde $(src_base)/test.map + + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/error-handling/exceptions/output b/tests/cxx/parser/error-handling/exceptions/output new file mode 100644 index 0000000..b8046aa --- /dev/null +++ b/tests/cxx/parser/error-handling/exceptions/output @@ -0,0 +1,15 @@ +xml:2:2: 7: mismatched tag +app: 1 +app: 2 +app: 3 +app: 4 +app: 5 +app: 6 +app: 7 +schema:1:22: 4: unexpected element encountered +schema:2:16: 3: expected element not encountered +schema:2:30: 1: expected attribute not encountered +schema:4:6: 4: unexpected element encountered +schema:2:23: 2: unexpected attribute encountered +schema:3:14: 11: invalid int value +io: io error diff --git a/tests/cxx/parser/error-handling/exceptions/test.map b/tests/cxx/parser/error-handling/exceptions/test.map new file mode 100644 index 0000000..5da7e3d --- /dev/null +++ b/tests/cxx/parser/error-handling/exceptions/test.map @@ -0,0 +1,4 @@ +namespace test +{ + person int int; +} diff --git a/tests/cxx/parser/error-handling/exceptions/test.xml b/tests/cxx/parser/error-handling/exceptions/test.xml new file mode 100644 index 0000000..07def4b --- /dev/null +++ b/tests/cxx/parser/error-handling/exceptions/test.xml @@ -0,0 +1,9 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <person id="old"> + <age>67</age> + </person> + +</t:root> diff --git a/tests/cxx/parser/error-handling/exceptions/test.xsd b/tests/cxx/parser/error-handling/exceptions/test.xsd new file mode 100644 index 0000000..6850342 --- /dev/null +++ b/tests/cxx/parser/error-handling/exceptions/test.xsd @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="person"> + <sequence> + <element name="age" type="int"/> + </sequence> + <attribute name="id" type="string" use="required"/> + </complexType> + + <complexType name="type"> + <sequence> + <element name="person" type="t:person" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/error-handling/makefile b/tests/cxx/parser/error-handling/makefile new file mode 100644 index 0000000..e183785 --- /dev/null +++ b/tests/cxx/parser/error-handling/makefile @@ -0,0 +1,24 @@ +# file : tests/cxx/parser/error-handling/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +ifeq ($(xsde_exceptions),y) +tests := exceptions +else +tests := codes +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/parser/generated-impl/makefile b/tests/cxx/parser/generated-impl/makefile new file mode 100644 index 0000000..94cb8fc --- /dev/null +++ b/tests/cxx/parser/generated-impl/makefile @@ -0,0 +1,79 @@ +# file : tests/cxx/parser/generated-impl/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd + +obj := $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.o) $(xsd:.xsd=-pimpl.o) $(xsd:.xsd=-pdriver.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/$(xsd:.xsd=-pdriver) +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.hxx) \ + $(out_base)/$(xsd:.xsd=-pimpl.cxx) \ + $(out_base)/$(xsd:.xsd=-pdriver.cxx) + +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-print-impl --generate-test-driver \ +--force-overwrite +$(gen): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pimpl.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +xsd_pimpl_suffix := -pimpl +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/generated-impl/output b/tests/cxx/parser/generated-impl/output new file mode 100644 index 0000000..7c58647 --- /dev/null +++ b/tests/cxx/parser/generated-impl/output @@ -0,0 +1,122 @@ +gender: male +foo: foo +gender: male +int: 0 +int: 1 +int: 2 +int: 3 +foo: foo +int: 3 +int: 2 +int: 1 +int: 0 +union: 9 +foo: foo +union: string +x: x +a: aaa +x: x +y: y +a: aaa +b: bbb +boolean: 1 +boolean: 0 +boolean: 1 +boolean: 0 +byte: 0 +byte: 123 +byte: -123 +unsigned-byte: 0 +unsigned-byte: 123 +short: 0 +short: -1234 +short: 1234 +unsigned-short: 0 +unsigned-short: 1234 +int: 0 +int: -12345 +int: 12345 +unsigned-int: 0 +unsigned-int: 12345 +long: 0 +long: -123456 +long: 123456 +unsigned-long: 0 +unsigned-long: 123456 +integer: 0 +integer: -123456 +integer: 123456 +negative-integer: -123456 +non-positive-integer: 0 +non-positive-integer: -123456 +positive-integer: 123456 +non-negative-integer: 0 +non-negative-integer: 123456 +float: 0 +float: 1.123 +float: -1.123 +double: 0 +double: 1.1234 +double: -1.1234 +decimal: 0 +decimal: 1.1234 +decimal: -1.1234 +string: string space newline +normalized-string: string space newline +token: string space newline +name: as123:345-.abs +nmtoken: 1as123:345-.abs +nmtokens: abc 123 +ncname: as123_345-.abs +id: abc +id: a123 +idref: abc +idrefs: abc a123 +language: en +language: en-us +uri: http://www.example.com/foo#bar +qname: schemaLocation +qname: xsi:schemaLocation +base64_binary: 10 bytes +base64_binary: 1 bytes +base64_binary: 2 bytes +base64_binary: 3 bytes +hex_binary: 0 bytes +hex_binary: 10 bytes +gday: ---12+12:0 +gday: ---1 +gday: ---31 +gday: ---15+0:0 +gday: ---15-14:0 +gmonth: --10+12:0 +gmonth: --1 +gmonth: --12+0:0 +gyear: 2007+12:0 +gyear: 1 +gyear: -20000+0:0 +gmonth_day: --10-28+12:0 +gmonth_day: --12-31 +gmonth_day: --1-1+0:0 +gyear_month: 2007-12+12:0 +gyear_month: -2007-10 +gyear_month: 20007-10+0:0 +gyear_month: -20007-1 +date: 2007-12-26+12:0 +date: -2007-10-15 +date: 20007-12-31+0:0 +date: -20007-1-1 +time: 12:46:23.456+12:0 +time: 12:13:14 +time: 12:13:14+0:0 +date_time: 2007-12-26T12:13:14.123+12:0 +date_time: -2007-10-15T12:13:14 +date_time: 20007-12-31T12:13:14+0:0 +date_time: -20007-1-1T12:13:14 +duration: -P2007Y13M32DT25H61M61.123S +duration: P1Y0M0DT0H0M0S +duration: P0Y1M0DT0H0M0S +duration: P0Y0M1DT0H0M0S +duration: P0Y0M0DT1H0M0S +duration: P0Y0M0DT0H1M0S +duration: P0Y0M0DT0H0M1.1S +duration: P1Y0M0DT0H0M1S diff --git a/tests/cxx/parser/generated-impl/test.xml b/tests/cxx/parser/generated-impl/test.xml new file mode 100644 index 0000000..2f29a39 --- /dev/null +++ b/tests/cxx/parser/generated-impl/test.xml @@ -0,0 +1,168 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <gender>male</gender> + <gender-extension foo="foo">male</gender-extension> + + <list>0 1 2 3</list> + <list-extension foo="foo">3 2 1 0</list-extension> + + <union>9</union> + <union-extension foo="foo">string</union-extension> + + <complex x="x"> + <a>aaa</a> + </complex> + + <complex-extension x="x" y="y"> + <a>aaa</a> + <b>bbb</b> + </complex-extension> + + <any-type>aaa<b>bbb</b>ccc</any-type> + <any-simple-type>abc123</any-simple-type> + + <boolean>1</boolean> + <boolean> 0 </boolean> + <boolean>true</boolean> + <boolean> false </boolean> + + <byte>0</byte> + <byte>123</byte> + <byte>-123</byte> + + <unsigned-byte>0</unsigned-byte> + <unsigned-byte>123</unsigned-byte> + + <short>0</short> + <short>-1234</short> + <short>1234</short> + + <unsigned-short>0</unsigned-short> + <unsigned-short>1234</unsigned-short> + + <int>0</int> + <int>-12345</int> + <int>12345</int> + + <unsigned-int>0</unsigned-int> + <unsigned-int>12345</unsigned-int> + + <long>0</long> + <long>-123456</long> + <long>123456</long> + + <unsigned-long>0</unsigned-long> + <unsigned-long>123456</unsigned-long> + + <integer>0</integer> + <integer>-123456</integer> + <integer>123456</integer> + + <negative-integer>-123456</negative-integer> + + <non-positive-integer>0</non-positive-integer> + <non-positive-integer>-123456</non-positive-integer> + + <positive-integer>123456</positive-integer> + + <non-negative-integer>0</non-negative-integer> + <non-negative-integer>123456</non-negative-integer> + + <float>0</float> + <float>1.123</float> + <float>-1.123</float> + + <double>0</double> + <double>1.1234</double> + <double>-1.1234</double> + + <decimal>0</decimal> + <decimal>1.1234</decimal> + <decimal>-1.1234</decimal> + + <string>string space newline</string> + + <normalized-string>string space newline</normalized-string> + + <token> string space newline</token> + + <name>as123:345-.abs</name> + + <nmtoken>1as123:345-.abs</nmtoken> + + <nmtokens>abc 123</nmtokens> + + <ncname>as123_345-.abs</ncname> + + <id>abc</id> + <id>a123</id> + + <idref>abc</idref> + + <idrefs>abc a123</idrefs> + + <language>en</language> + <language>en-us</language> + + <uri>http://www.example.com/foo#bar</uri> + + <qname>schemaLocation</qname> + <qname>xsi:schemaLocation</qname> + + <base64_binary>MTIzNDVhYmNqaw==</base64_binary> + <base64_binary>YQ==</base64_binary> + <base64_binary>YWI=</base64_binary> + <base64_binary>YWJj</base64_binary> + + <hex_binary></hex_binary> + <hex_binary>31323334356162636a6b</hex_binary> + + <gday>---12+12:00</gday> + <gday>---01</gday> + <gday>---31</gday> + <gday>---15Z</gday> + <gday>---15-14:00</gday> + + <gmonth>--10+12:00</gmonth> + <gmonth>--01</gmonth> + <gmonth>--12Z</gmonth> + + <gyear>2007+12:00</gyear> + <gyear>0001</gyear> + <gyear>-20000Z</gyear> + + <gmonth_day>--10-28+12:00</gmonth_day> + <gmonth_day>--12-31</gmonth_day> + <gmonth_day>--01-01Z</gmonth_day> + + <gyear_month>2007-12+12:00</gyear_month> + <gyear_month>-2007-10</gyear_month> + <gyear_month>20007-10Z</gyear_month> + <gyear_month>-20007-01</gyear_month> + + <date>2007-12-26+12:00</date> + <date>-2007-10-15</date> + <date>20007-12-31Z</date> + <date>-20007-01-01</date> + + <time>12:46:23.456+12:00</time> + <time>12:13:14</time> + <time>12:13:14Z</time> + + <date_time>2007-12-26T12:13:14.123+12:00</date_time> + <date_time>-2007-10-15T12:13:14</date_time> + <date_time>20007-12-31T12:13:14Z</date_time> + <date_time>-20007-01-01T12:13:14</date_time> + + <duration>-P2007Y13M32DT25H61M61.123S</duration> + <duration>P1Y</duration> + <duration>P1M</duration> + <duration>P1D</duration> + <duration>PT1H</duration> + <duration>PT1M</duration> + <duration>PT1.1S</duration> + <duration>P1YT1S</duration> + +</t:root> diff --git a/tests/cxx/parser/generated-impl/test.xsd b/tests/cxx/parser/generated-impl/test.xsd new file mode 100644 index 0000000..7bc8f23 --- /dev/null +++ b/tests/cxx/parser/generated-impl/test.xsd @@ -0,0 +1,142 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- enum --> + + <simpleType name="gender"> + <restriction base="string"> + <enumeration value="male"/> + <enumeration value="female"/> + </restriction> + </simpleType> + + <complexType name="gender-extension"> + <simpleContent> + <extension base="t:gender"> + <attribute name="foo" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- list --> + + <simpleType name="list"> + <list itemType="int"/> + </simpleType> + + <complexType name="list-extension"> + <simpleContent> + <extension base="t:list"> + <attribute name="foo" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- union --> + + <simpleType name="union"> + <union memberTypes="int string"/> + </simpleType> + + <complexType name="union-extension"> + <simpleContent> + <extension base="t:union"> + <attribute name="foo" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- complex --> + + <complexType name="complex"> + <sequence> + <element name="a" type="string"/> + </sequence> + <attribute name="x" type="string"/> + </complexType> + + <complexType name="complex-extension"> + <complexContent> + <extension base="t:complex"> + <sequence> + <element name="b" type="string"/> + </sequence> + <attribute name="y" type="string"/> + </extension> + </complexContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="gender" type="t:gender"/> + <element name="gender-extension" type="t:gender-extension"/> + + <element name="list" type="t:list"/> + <element name="list-extension" type="t:list-extension"/> + + <element name="union" type="t:union"/> + <element name="union-extension" type="t:union-extension"/> + + <element name="complex" type="t:complex"/> + <element name="complex-extension" type="t:complex-extension"/> + + <!-- Built-in types. --> + + <element name="any-type" type="anyType" maxOccurs="unbounded"/> + <element name="any-simple-type" type="anySimpleType" maxOccurs="unbounded"/> + + <element name="boolean" type="boolean" maxOccurs="unbounded"/> + + <element name="byte" type="byte" maxOccurs="unbounded"/> + <element name="unsigned-byte" type="unsignedByte" maxOccurs="unbounded"/> + <element name="short" type="short" maxOccurs="unbounded"/> + <element name="unsigned-short" type="unsignedShort" maxOccurs="unbounded"/> + <element name="int" type="int" maxOccurs="unbounded"/> + <element name="unsigned-int" type="unsignedInt" maxOccurs="unbounded"/> + <element name="long" type="long" maxOccurs="unbounded"/> + <element name="unsigned-long" type="unsignedLong" maxOccurs="unbounded"/> + + <element name="integer" type="integer" maxOccurs="unbounded"/> + <element name="negative-integer" type="negativeInteger" maxOccurs="unbounded"/> + <element name="non-positive-integer" type="nonPositiveInteger" maxOccurs="unbounded"/> + <element name="positive-integer" type="positiveInteger" maxOccurs="unbounded"/> + <element name="non-negative-integer" type="nonNegativeInteger" maxOccurs="unbounded"/> + + <element name="float" type="float" maxOccurs="unbounded"/> + <element name="double" type="double" maxOccurs="unbounded"/> + <element name="decimal" type="decimal" maxOccurs="unbounded"/> + + <element name="string" type="string" maxOccurs="unbounded"/> + <element name="normalized-string" type="normalizedString" maxOccurs="unbounded"/> + <element name="token" type="token" maxOccurs="unbounded"/> + <element name="name" type="Name" maxOccurs="unbounded"/> + <element name="nmtoken" type="NMTOKEN" maxOccurs="unbounded"/> + <element name="nmtokens" type="NMTOKENS" maxOccurs="unbounded"/> + <element name="ncname" type="NCName" maxOccurs="unbounded"/> + <element name="id" type="ID" maxOccurs="unbounded"/> + <element name="idref" type="IDREF" maxOccurs="unbounded"/> + <element name="idrefs" type="IDREFS" maxOccurs="unbounded"/> + + <element name="language" type="language" maxOccurs="unbounded"/> + <element name="uri" type="anyURI" maxOccurs="unbounded"/> + <element name="qname" type="QName" maxOccurs="unbounded"/> + + <element name="base64_binary" type="base64Binary" maxOccurs="unbounded"/> + <element name="hex_binary" type="hexBinary" maxOccurs="unbounded"/> + + <element name="gday" type="gDay" maxOccurs="unbounded"/> + <element name="gmonth" type="gMonth" maxOccurs="unbounded"/> + <element name="gyear" type="gYear" maxOccurs="unbounded"/> + <element name="gmonth_day" type="gMonthDay" maxOccurs="unbounded"/> + <element name="gyear_month" type="gYearMonth" maxOccurs="unbounded"/> + <element name="date" type="date" maxOccurs="unbounded"/> + <element name="time" type="time" maxOccurs="unbounded"/> + <element name="date_time" type="dateTime" maxOccurs="unbounded"/> + <element name="duration" type="duration" maxOccurs="unbounded"/> + + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/list/driver.cxx b/tests/cxx/parser/list/driver.cxx new file mode 100644 index 0000000..b920387 --- /dev/null +++ b/tests/cxx/parser/list/driver.cxx @@ -0,0 +1,127 @@ +// file : tests/cxx/parser/list/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test xsd:list parsing. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct string_list_pimpl: string_list_pskel +{ + virtual void + pre () + { + cout << "{" << endl; + } + +#ifdef XSDE_STL + virtual void + item (string const& v) + { + cout << " '" << v << "'" << endl; + } +#else + virtual void + item (char* v) + { + cout << " '" << v << "'" << endl; + delete[] v; + } +#endif + + virtual void + post_string_list () + { + cout << "}" << endl + << endl; + } +}; + +struct string_list_lang_pimpl: string_list_lang_pskel +{ + string_list_lang_pimpl () + : string_list_lang_pskel (&base_impl_) + { + } + + virtual void + pre () + { + cout << "{" << endl; + } + +#ifdef XSDE_STL + virtual void + lang (string const& v) + { + cout << " lang: '" << v << "'" << endl; + } +#else + virtual void + lang (char* v) + { + cout << " lang: '" << v << "'" << endl; + delete[] v; + } +#endif + + virtual void + post_string_list_lang () + { + cout << "}" << endl + << endl; + } + +private: + string_list_pimpl base_impl_; +}; + +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; + string_list_pimpl string_list_p; + string_list_lang_pimpl string_list_lang_p; + type_pimpl type_p; + + string_list_p.parsers (string_p); + string_list_lang_p.parsers (string_p, string_p); + type_p.parsers (string_list_p, string_list_lang_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/list/makefile b/tests/cxx/parser/list/makefile new file mode 100644 index 0000000..d98b11f --- /dev/null +++ b/tests/cxx/parser/list/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/parser/list/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/list/output b/tests/cxx/parser/list/output new file mode 100644 index 0000000..3642c4d --- /dev/null +++ b/tests/cxx/parser/list/output @@ -0,0 +1,26 @@ +{ +} + +{ +} + +{ +} + +{ + 'one' +} + +{ + 'one' + 'two' + 'three' +} + +{ + lang: 'en' + 'one' + 'two' + 'three' +} + diff --git a/tests/cxx/parser/list/test.xml b/tests/cxx/parser/list/test.xml new file mode 100644 index 0000000..52229db --- /dev/null +++ b/tests/cxx/parser/list/test.xml @@ -0,0 +1,25 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <string-list/> + + <string-list> </string-list> + + <string-list> + + </string-list> + + <string-list>one</string-list> + + <string-list> + one two + three + </string-list> + + <string-list-lang lang="en"> + one two + three + </string-list-lang> + +</t:root> diff --git a/tests/cxx/parser/list/test.xsd b/tests/cxx/parser/list/test.xsd new file mode 100644 index 0000000..79bd084 --- /dev/null +++ b/tests/cxx/parser/list/test.xsd @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="string-list"> + <list itemType="string"/> + </simpleType> + + <complexType name="string-list-lang"> + <simpleContent> + <extension base="t:string-list"> + <attribute name="lang" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="type"> + <choice maxOccurs="unbounded"> + <element name="string-list" type="t:string-list"/> + <element name="string-list-lang" type="t:string-list-lang"/> + </choice> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/makefile b/tests/cxx/parser/makefile new file mode 100644 index 0000000..94d6e45 --- /dev/null +++ b/tests/cxx/parser/makefile @@ -0,0 +1,57 @@ +# file : tests/cxx/parser/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +tests := generated-impl duplicate + +ifeq ($(xsde_iostream),y) +ifeq ($(xsde_exceptions),y) +tests += \ +built-in \ +recursive \ +test-template \ +union + +ifeq ($(xsde_reuse_style),tiein) +tests += \ +enumeration \ +list +endif + +endif # exceptions + +ifeq ($(xsde_polymorphic),y) +tests += polymorphism +endif + +tests += reset + +endif # iostream + + +ifeq ($(xsde_parser_validation),y) +tests += validation + +ifeq ($(xsde_iostream),y) +tests += error-handling + +ifeq ($(xsde_exceptions),y) +tests += name-clash/inheritance +endif +endif +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/parser/name-clash/inheritance/driver.cxx b/tests/cxx/parser/name-clash/inheritance/driver.cxx new file mode 100644 index 0000000..abe59b5 --- /dev/null +++ b/tests/cxx/parser/name-clash/inheritance/driver.cxx @@ -0,0 +1,87 @@ +// file : tests/cxx/parser/name-clash/inheritance/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test for name clashes across inheritance hierarchy. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct derived_pimpl: derived_pskel +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + derived_pimpl () + : derived_pskel (0) + { + } +#endif + +#ifdef XSDE_STL + virtual void + e (string const& v) + { + cout << "e: " << v << endl; + } + + virtual void + e1 (string const& v) + { + cout << "e1: " << v << endl; + } +#else + virtual void + e (char* v) + { + cout << "e: " << v << endl; + delete[] v; + } + + virtual void + e1 (char* v) + { + cout << "e1: " << v << endl; + delete[] v; + } +#endif +}; + +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; + derived_pimpl derived_p; + + derived_p.parsers (string_p, string_p); + + xml_schema::document_pimpl doc_p (derived_p, "test", "root"); + + derived_p.pre (); + doc_p.parse (argv[1]); + derived_p.post_derived (); + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/name-clash/inheritance/makefile b/tests/cxx/parser/name-clash/inheritance/makefile new file mode 100644 index 0000000..0c12f20 --- /dev/null +++ b/tests/cxx/parser/name-clash/inheritance/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/parser/name-clash/inheritance/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/name-clash/inheritance/output b/tests/cxx/parser/name-clash/inheritance/output new file mode 100644 index 0000000..4efd51b --- /dev/null +++ b/tests/cxx/parser/name-clash/inheritance/output @@ -0,0 +1,2 @@ +e: e +e1: e1 diff --git a/tests/cxx/parser/name-clash/inheritance/test.xml b/tests/cxx/parser/name-clash/inheritance/test.xml new file mode 100644 index 0000000..8c17101 --- /dev/null +++ b/tests/cxx/parser/name-clash/inheritance/test.xml @@ -0,0 +1,8 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <e>e</e> + <e>e1</e> + +</t:root> diff --git a/tests/cxx/parser/name-clash/inheritance/test.xsd b/tests/cxx/parser/name-clash/inheritance/test.xsd new file mode 100644 index 0000000..62a782e --- /dev/null +++ b/tests/cxx/parser/name-clash/inheritance/test.xsd @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="base"> + <sequence> + <element name="e" type="string"/> + </sequence> + </complexType> + + <complexType name="derived"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="e" type="string"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="root" type="t:derived"/> + +</schema> diff --git a/tests/cxx/parser/polymorphism/driver.cxx b/tests/cxx/parser/polymorphism/driver.cxx new file mode 100644 index 0000000..e9ef3f5 --- /dev/null +++ b/tests/cxx/parser/polymorphism/driver.cxx @@ -0,0 +1,124 @@ +// file : tests/cxx/parser/polymorphism/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test substitution groups and xsi:type support. +// +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct base_pimpl: base_pskel +{ + virtual void + a (int i) + { + cout << "a: " << i << endl; + } +}; + +struct interm_pimpl: interm_pskel +{ + interm_pimpl () + : interm_pskel (&base_impl_) + { + } + + virtual void + b (int i) + { + cout << "b: " << i << endl; + } + + base_pimpl base_impl_; +}; + +struct derived_pimpl: derived_pskel +{ + derived_pimpl () + : derived_pskel (&base_impl_) + { + } + + virtual void + c (int i) + { + cout << "c: " << i << endl; + } + + interm_pimpl base_impl_; +}; + +struct type_pimpl: type_pskel +{ +}; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + +#ifdef XSDE_EXCEPTIONS + try + { +#endif + xml_schema::int_pimpl int_p; + + base_pimpl base_p; + interm_pimpl interm_p; + derived_pimpl derived_p; + + xml_schema::parser_map_impl map (5); + type_pimpl type_p; + + base_p.parsers (int_p); + interm_p.parsers (int_p, int_p); + derived_p.parsers (int_p, int_p, int_p); + + map.insert (base_p); + map.insert (interm_p); + map.insert (derived_p); + + type_p.base_parser (map); + + xml_schema::document_pimpl doc_p (type_p, "test", "root", true); + + type_p.pre (); + doc_p.parse (argv[1]); + +#ifndef XSDE_EXCEPTIONS + if (doc_p._error ()) + { + cerr << "error" << endl; + return 1; + } +#endif + + type_p.post_type (); + + // Test parser resetting. + // + doc_p.reset (); + +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +#endif +} diff --git a/tests/cxx/parser/polymorphism/makefile b/tests/cxx/parser/polymorphism/makefile new file mode 100644 index 0000000..628ef02 --- /dev/null +++ b/tests/cxx/parser/polymorphism/makefile @@ -0,0 +1,73 @@ +# file : tests/cxx/parser/polymorphism/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): xsde_options += --generate-polymorphic +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/polymorphism/output b/tests/cxx/parser/polymorphism/output new file mode 100644 index 0000000..87168ca --- /dev/null +++ b/tests/cxx/parser/polymorphism/output @@ -0,0 +1,14 @@ +a: 1 +a: 1 +b: 2 +a: 1 +b: 2 +a: 1 +b: 2 +c: 3 +a: 1 +b: 2 +c: 3 +a: 1 +a: 1 +a: 1 diff --git a/tests/cxx/parser/polymorphism/test.xml b/tests/cxx/parser/polymorphism/test.xml new file mode 100644 index 0000000..8e635cc --- /dev/null +++ b/tests/cxx/parser/polymorphism/test.xml @@ -0,0 +1,19 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <t:base><a>1</a></t:base> + + <t:base xsi:type="t:interm"><a>1</a><b>2</b></t:base> + <t:interm><a>1</a><b>2</b></t:interm> + + <t:base xsi:type="t:derived"><a>1</a><b>2</b><c>3</c></t:base> + <t:derived><a>1</a><b>2</b><c>3</c></t:derived> + + <!-- same type substitution --> + + <t:another-base><a>1</a></t:another-base> + <t:base xsi:type="t:base"><a>1</a></t:base> + <t:another-base xsi:type="t:base"><a>1</a></t:another-base> + +</t:root> diff --git a/tests/cxx/parser/polymorphism/test.xsd b/tests/cxx/parser/polymorphism/test.xsd new file mode 100644 index 0000000..80c5e06 --- /dev/null +++ b/tests/cxx/parser/polymorphism/test.xsd @@ -0,0 +1,45 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="base"> + <sequence> + <element name="a" type="int"/> + </sequence> + </complexType> + + <element name="base" type="t:base"/> + <element name="another-base" type="t:base" substitutionGroup="t:base"/> + + <complexType name="interm"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="interm" type="t:interm" substitutionGroup="t:base"/> + + <complexType name="derived"> + <complexContent> + <extension base="t:interm"> + <sequence> + <element name="c" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="derived" type="t:derived" substitutionGroup="t:interm"/> + + <complexType name="type"> + <sequence> + <element ref="t:base" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/recursive/driver.cxx b/tests/cxx/parser/recursive/driver.cxx new file mode 100644 index 0000000..9e17242 --- /dev/null +++ b/tests/cxx/parser/recursive/driver.cxx @@ -0,0 +1,172 @@ +// file : tests/cxx/parser/recursive/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test recursive parser invocation. +// + +#include <iostream> +#include <string> + +#include "test-pskel.hxx" + +using namespace std; + +struct sub_pimpl: sub_type_pskel +{ + virtual void + pre () + { + cout << "sub::pre" << endl; + } + + virtual void + sub () + { + cout << "sub::sub" << endl; + } + + virtual void + sub2 () + { + cout << "sub::sub2" << endl; + } + +#ifdef XSDE_STL + virtual void + name (string const& n) + { + cout << "sub::name: " << n << endl; + } +#else + virtual void + name (char* n) + { + cout << "sub::name: " << n << endl; + delete[] n; + } +#endif + + virtual void + post_sub_type () + { + cout << "sub::post" << endl; + } +}; + +struct indir_pimpl: indir_type_pskel +{ + virtual void + pre () + { + cout << "indir::pre" << endl; + } + + virtual void + sub () + { + cout << "indir::sub" << endl; + } + +#ifdef XSDE_STL + virtual void + name (string const& n) + { + cout << "indir::name: " << n << endl; + } +#else + virtual void + name (char* n) + { + cout << "indir::name: " << n << endl; + delete[] n; + } +#endif + + virtual void + post_indir_type () + { + cout << "indir::post" << endl; + } +}; + +struct test_pimpl: test_type_pskel +{ + virtual void + pre () + { + cout << "test::pre" << endl; + } + + virtual void + sub () + { + cout << "test::sub" << endl; + } + +#ifdef XSDE_STL + virtual void + name (string const& n) + { + cout << "test::name: " << n << endl; + } +#else + virtual void + name (char* n) + { + cout << "test::name: " << n << endl; + delete[] n; + } +#endif + + virtual void + post_test_type () + { + cout << "test::post" << endl; + } +}; + + +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; + + sub_pimpl sub_p; + indir_pimpl indir_p; + test_pimpl test_p; + + sub_p.parsers (string_p, sub_p, indir_p, sub_p); + indir_p.parsers (string_p, sub_p); + test_p.parsers (string_p, sub_p); + + xml_schema::document_pimpl doc_p (test_p, "test"); + + test_p.pre (); + doc_p.parse (argv[1]); + test_p.post_test_type (); + + // Test parser resetting. + // + doc_p.reset (); + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/recursive/makefile b/tests/cxx/parser/recursive/makefile new file mode 100644 index 0000000..19ddfbd --- /dev/null +++ b/tests/cxx/parser/recursive/makefile @@ -0,0 +1,73 @@ +# file : tests/cxx/parser/recursive/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/recursive/output b/tests/cxx/parser/recursive/output new file mode 100644 index 0000000..f26fb72 --- /dev/null +++ b/tests/cxx/parser/recursive/output @@ -0,0 +1,22 @@ +test::pre +test::name: testName +sub::pre +sub::name: subName +sub::pre +sub::name: sub-subName +sub::post +sub::sub +indir::pre +indir::name: sub-indirName +sub::pre +sub::name: sub-indir-subName +sub::post +indir::sub +indir::post +sub::pre +sub::name: sub-sub2Name +sub::post +sub::sub2 +sub::post +test::sub +test::post diff --git a/tests/cxx/parser/recursive/test.xml b/tests/cxx/parser/recursive/test.xml new file mode 100644 index 0000000..f6c219d --- /dev/null +++ b/tests/cxx/parser/recursive/test.xml @@ -0,0 +1,11 @@ +<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="test.xsd" + name="testName"> + <sub name="subName"> + <sub name="sub-subName"/> + <indir name="sub-indirName"> + <sub name="sub-indir-subName"/> + </indir> + <sub2 name="sub-sub2Name"/> + </sub> +</test> diff --git a/tests/cxx/parser/recursive/test.xsd b/tests/cxx/parser/recursive/test.xsd new file mode 100644 index 0000000..33e1d2d --- /dev/null +++ b/tests/cxx/parser/recursive/test.xsd @@ -0,0 +1,27 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <xs:complexType name="sub_type"> + <xs:sequence> + <xs:element name="sub" type="sub_type" minOccurs="0"/> + <xs:element name="indir" type="indir_type" minOccurs="0"/> + <xs:element name="sub2" type="sub_type" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="name" type="xs:string" /> + </xs:complexType> + + <xs:complexType name="indir_type"> + <xs:sequence> + <xs:element name="sub" type="sub_type" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="name" type="xs:string" /> + </xs:complexType> + + <xs:complexType name="test_type"> + <xs:sequence> + <xs:element name="sub" type="sub_type" /> + </xs:sequence> + <xs:attribute name="name" type="xs:string" /> + </xs:complexType> + + <xs:element name="test" type="test_type" /> +</xs:schema> diff --git a/tests/cxx/parser/reset/driver.cxx b/tests/cxx/parser/reset/driver.cxx new file mode 100644 index 0000000..5701df5 --- /dev/null +++ b/tests/cxx/parser/reset/driver.cxx @@ -0,0 +1,300 @@ +// file : tests/cxx/parser/reset/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test parser resetting. +// + +#include <assert.h> + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +bool fail = true; + +struct error {}; + +#ifdef XSDE_REUSE_STYLE_MIXIN +struct base_pimpl: virtual base_pskel +#else +struct base_pimpl: base_pskel +#endif +{ + base_pimpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { +#ifndef XSDE_EXCEPTIONS + assert (!_error ()); +#endif + + if (fail && i_ == 3) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + +private: + unsigned long i_; +}; + +#ifdef XSDE_REUSE_STYLE_MIXIN +struct inner_pimpl: inner_pskel, base_pimpl +#else +struct inner_pimpl: inner_pskel +#endif +{ + inner_pimpl (unsigned long i) +#ifdef XSDE_REUSE_STYLE_MIXIN + : base_pimpl (i), i_ (i) +#else + : inner_pskel (&base_impl_), base_impl_ (i), i_ (i) +#endif + { + } + + virtual void + b (int v) + { + if (fail && i_ == 4) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + + if (!fail) + cout << i_ << ": " << v << endl; + } + + virtual void + post_inner () + { + if (fail && i_ == 5) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + +private: +#ifdef XSDE_REUSE_STYLE_TIEIN + base_pimpl base_impl_; +#endif + unsigned long i_; +}; + +struct type_pimpl: type_pskel +{ + type_pimpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { + if (fail && i_ == 0) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + + virtual void + a () + { + if (fail && i_ == 1) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + + virtual void + post_type () + { + if (fail && i_ == 2) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + +private: + unsigned long i_; +}; + +int +main (int argc, char* argv[]) +{ + if (argc != 4) + { + cerr << "usage: " << argv[0] << " pass.xml fail-xml.xml fail-schema.xml" + << endl; + return 1; + } + + const char* pass = argv[1]; + const char* fail_xml = argv[2]; + const char* fail_schema = argv[3]; + + try + { + for (unsigned long i (0); i < 8; ++i) + { +#ifndef XSDE_PARSER_VALIDATION + if (i == 7) + { + cout << "7: 1" << endl; + continue; + } +#endif + + xml_schema::int_pimpl int_p; + inner_pimpl inner_p (i); + type_pimpl type_p (i); + + inner_p.parsers (int_p); + type_p.parsers (inner_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + +#ifdef XSDE_EXCEPTIONS + try + { + fail = true; + + type_p.pre (); + + switch (i) + { + case 6: + { + doc_p.parse (fail_xml); + break; + } + case 7: + { + doc_p.parse (fail_schema); + break; + } + default: + { + doc_p.parse (pass); + break; + } + } + + type_p.post_type (); + assert (false); + } + catch (error const&) + { + } + catch (xml_schema::parser_exception const&) + { + } + + fail = false; + doc_p.reset (); + + type_p.pre (); + doc_p.parse (pass); + type_p.post_type (); +#else + do + { + fail = true; + + type_p.pre (); + + if (type_p._error ()) + break; + + switch (i) + { + case 6: + { + doc_p.parse (fail_xml); + break; + } + case 7: + { + doc_p.parse (fail_schema); + break; + } + default: + { + doc_p.parse (pass); + break; + } + } + + if (doc_p._error ()) + break; + + type_p.post_type (); + + if (type_p._error ()) + break; + + assert (false); + } + while (false); + + fail = false; + doc_p.reset (); + + type_p.pre (); + assert (!type_p._error ()); + + doc_p.parse (pass); + assert (!doc_p._error ()); + + type_p.post_type (); + assert (!type_p._error ()); +#endif + } + } +#ifdef XSDE_EXCEPTIONS + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } +#endif + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/reset/fail-schema.xml b/tests/cxx/parser/reset/fail-schema.xml new file mode 100644 index 0000000..92c6c8b --- /dev/null +++ b/tests/cxx/parser/reset/fail-schema.xml @@ -0,0 +1,8 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a><b>1</b></a> + <a><b>1</b></a> + +</t:root> diff --git a/tests/cxx/parser/reset/fail-xml.xml b/tests/cxx/parser/reset/fail-xml.xml new file mode 100644 index 0000000..b2aacb2 --- /dev/null +++ b/tests/cxx/parser/reset/fail-xml.xml @@ -0,0 +1,7 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a></b>1</b></a> + +</t:root> diff --git a/tests/cxx/parser/reset/makefile b/tests/cxx/parser/reset/makefile new file mode 100644 index 0000000..31dd3b4 --- /dev/null +++ b/tests/cxx/parser/reset/makefile @@ -0,0 +1,75 @@ +# file : tests/cxx/parser/reset/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/pass.xml $(src_base)/fail-xml.xml \ + $(src_base)/fail-schema.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/pass.xml \ +$(src_base)/fail-xml.xml $(src_base)/fail-schema.xml \ +| diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/reset/output b/tests/cxx/parser/reset/output new file mode 100644 index 0000000..0e6cb1e --- /dev/null +++ b/tests/cxx/parser/reset/output @@ -0,0 +1,8 @@ +0: 1 +1: 1 +2: 1 +3: 1 +4: 1 +5: 1 +6: 1 +7: 1 diff --git a/tests/cxx/parser/reset/pass.xml b/tests/cxx/parser/reset/pass.xml new file mode 100644 index 0000000..956ec2a --- /dev/null +++ b/tests/cxx/parser/reset/pass.xml @@ -0,0 +1,7 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a><b>1</b></a> + +</t:root> diff --git a/tests/cxx/parser/reset/test.xsd b/tests/cxx/parser/reset/test.xsd new file mode 100644 index 0000000..56ee5a4 --- /dev/null +++ b/tests/cxx/parser/reset/test.xsd @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="base"> + <sequence> + </sequence> + </complexType> + + <complexType name="inner"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="a" type="t:inner"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/test-template/driver.cxx b/tests/cxx/parser/test-template/driver.cxx new file mode 100644 index 0000000..3b77569 --- /dev/null +++ b/tests/cxx/parser/test-template/driver.cxx @@ -0,0 +1,77 @@ +// file : tests/cxx/parser/test-template/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Insert test description here. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct type_pimpl: type_pskel +{ + virtual void + pre () + { + } + +#ifdef XSDE_STL + virtual void + a (string const& v) + { + cout << v << endl; + } +#else + virtual void + a (char* v) + { + cout << v << endl; + delete[] v; + } +#endif + + virtual void + post_type () + { + } +}; + +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; + type_pimpl type_p; + + type_p.parsers (string_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/test-template/makefile b/tests/cxx/parser/test-template/makefile new file mode 100644 index 0000000..c618407 --- /dev/null +++ b/tests/cxx/parser/test-template/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/parser/test-template/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/test-template/output b/tests/cxx/parser/test-template/output new file mode 100644 index 0000000..7898192 --- /dev/null +++ b/tests/cxx/parser/test-template/output @@ -0,0 +1 @@ +a diff --git a/tests/cxx/parser/test-template/test.xml b/tests/cxx/parser/test-template/test.xml new file mode 100644 index 0000000..624a80c --- /dev/null +++ b/tests/cxx/parser/test-template/test.xml @@ -0,0 +1,7 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a>a</a> + +</t:root> diff --git a/tests/cxx/parser/test-template/test.xsd b/tests/cxx/parser/test-template/test.xsd new file mode 100644 index 0000000..07bebc7 --- /dev/null +++ b/tests/cxx/parser/test-template/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/union/driver.cxx b/tests/cxx/parser/union/driver.cxx new file mode 100644 index 0000000..d966c88 --- /dev/null +++ b/tests/cxx/parser/union/driver.cxx @@ -0,0 +1,62 @@ +// file : tests/cxx/parser/union/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test xsd:union parsing. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct int_string_union_pimpl: int_string_union_pskel +{ + virtual void + _characters (const xml_schema::ro_string& s) + { + cout << "'" << s << "'" << 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 + { + int_string_union_pimpl int_string_union_p; + type_pimpl type_p; + + type_p.parsers (int_string_union_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/union/makefile b/tests/cxx/parser/union/makefile new file mode 100644 index 0000000..46993f8 --- /dev/null +++ b/tests/cxx/parser/union/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/parser/union/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/union/output b/tests/cxx/parser/union/output new file mode 100644 index 0000000..b698505 --- /dev/null +++ b/tests/cxx/parser/union/output @@ -0,0 +1,3 @@ +' ' +'one' +'1' diff --git a/tests/cxx/parser/union/test.xml b/tests/cxx/parser/union/test.xml new file mode 100644 index 0000000..5b3e799 --- /dev/null +++ b/tests/cxx/parser/union/test.xml @@ -0,0 +1,10 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <int-string-union/> + <int-string-union> </int-string-union> + <int-string-union>one</int-string-union> + <int-string-union>1</int-string-union> + +</t:root> diff --git a/tests/cxx/parser/union/test.xsd b/tests/cxx/parser/union/test.xsd new file mode 100644 index 0000000..5bf3d47 --- /dev/null +++ b/tests/cxx/parser/union/test.xsd @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="int-string-union"> + <union memberTypes="int string"/> + </simpleType> + + <complexType name="type"> + <choice maxOccurs="unbounded"> + <element name="int-string-union" type="t:int-string-union"/> + </choice> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/validation/all/driver.cxx b/tests/cxx/parser/validation/all/driver.cxx new file mode 100644 index 0000000..7498465 --- /dev/null +++ b/tests/cxx/parser/validation/all/driver.cxx @@ -0,0 +1,121 @@ +// file : tests/cxx/parser/validation/all/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the all compositor validation. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; + +struct all_pimpl: all_pskel +{ + virtual void + pre () + { + cout << "{" << endl; + } + +#ifdef XSDE_STL + 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; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } + + virtual void + b (char* v) + { + cout << " b = " << v << endl; + delete[] v; + } + + virtual void + c (char* v) + { + cout << " c = " << v << endl; + delete[] v; + } +#endif + + virtual void + post_all () + { + 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; + all_pimpl all_p; + type_pimpl type_p; + + all_p.parsers (string_p, string_p, string_p); + type_p.parsers (all_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + try + { + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cout << " " << e.line () << ":" << e.column () << " " << e << endl + << "}" << endl + << endl; + } + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/validation/all/makefile b/tests/cxx/parser/validation/all/makefile new file mode 100644 index 0000000..75990e2 --- /dev/null +++ b/tests/cxx/parser/validation/all/makefile @@ -0,0 +1,82 @@ +# file : tests/cxx/parser/validation/all/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +tests := 000 001 002 003 + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +.PHONY: $(test) +$(test): $(test_targets) + + +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/all/test-000.std b/tests/cxx/parser/validation/all/test-000.std new file mode 100644 index 0000000..b4445f2 --- /dev/null +++ b/tests/cxx/parser/validation/all/test-000.std @@ -0,0 +1,46 @@ +{ + a = a + b = b + c = c +} + +{ + a = a + c = c + b = b +} + +{ + b = b + a = a + c = c +} + +{ + b = b + c = c + a = a +} + +{ + c = c + a = a + b = b +} + +{ + c = c + b = b + a = a +} + +{ + a = a + b = b +} + +{ + a = a + b = b +} + diff --git a/tests/cxx/parser/validation/all/test-000.xml b/tests/cxx/parser/validation/all/test-000.xml new file mode 100644 index 0000000..6e46fae --- /dev/null +++ b/tests/cxx/parser/validation/all/test-000.xml @@ -0,0 +1,53 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- all combinations --> + <all> + <a>a</a> + <b>b</b> + <c>c</c> + </all> + + <all> + <a>a</a> + <c>c</c> + <b>b</b> + </all> + + <all> + <b>b</b> + <a>a</a> + <c>c</c> + </all> + + <all> + <b>b</b> + <c>c</c> + <a>a</a> + </all> + + <all> + <c>c</c> + <a>a</a> + <b>b</b> + </all> + + <all> + <c>c</c> + <b>b</b> + <a>a</a> + </all> + + <!-- optional c is not present --> + <all> + <a>a</a> + <b>b</b> + </all> + + <all> + <a>a</a> + <b>b</b> + </all> + +</t:root> diff --git a/tests/cxx/parser/validation/all/test-001.std b/tests/cxx/parser/validation/all/test-001.std new file mode 100644 index 0000000..921402a --- /dev/null +++ b/tests/cxx/parser/validation/all/test-001.std @@ -0,0 +1,6 @@ +{ + a = a + c = c + 9:8 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/all/test-001.xml b/tests/cxx/parser/validation/all/test-001.xml new file mode 100644 index 0000000..3df5600 --- /dev/null +++ b/tests/cxx/parser/validation/all/test-001.xml @@ -0,0 +1,11 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- required b is not present (invalid) --> + <all> + <a>a</a> + <c>c</c> + </all> + +</t:root> diff --git a/tests/cxx/parser/validation/all/test-002.std b/tests/cxx/parser/validation/all/test-002.std new file mode 100644 index 0000000..55d65b3 --- /dev/null +++ b/tests/cxx/parser/validation/all/test-002.std @@ -0,0 +1,4 @@ +{ + 7:8 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/all/test-002.xml b/tests/cxx/parser/validation/all/test-002.xml new file mode 100644 index 0000000..aed0c0c --- /dev/null +++ b/tests/cxx/parser/validation/all/test-002.xml @@ -0,0 +1,9 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- invalid --> + <all> + </all> + +</t:root> diff --git a/tests/cxx/parser/validation/all/test-003.std b/tests/cxx/parser/validation/all/test-003.std new file mode 100644 index 0000000..1d22181 --- /dev/null +++ b/tests/cxx/parser/validation/all/test-003.std @@ -0,0 +1,6 @@ +{ + a = a + b = b + 9:6 unexpected element encountered +} + diff --git a/tests/cxx/parser/validation/all/test-003.xml b/tests/cxx/parser/validation/all/test-003.xml new file mode 100644 index 0000000..b147cba --- /dev/null +++ b/tests/cxx/parser/validation/all/test-003.xml @@ -0,0 +1,12 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- invalid --> + <all> + <a>a</a> + <b>b</b> + <a>a</a> + </all> + +</t:root> diff --git a/tests/cxx/parser/validation/all/test.xsd b/tests/cxx/parser/validation/all/test.xsd new file mode 100644 index 0000000..1f670e3 --- /dev/null +++ b/tests/cxx/parser/validation/all/test.xsd @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="all"> + <all minOccurs="1"> + <element name="a" type="string"/> + <element name="b" type="string"/> + <element name="c" type="string" minOccurs="0"/> + </all> + </complexType> + + <complexType name="type"> + <sequence> + <element name="all" type="t:all" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/validation/any/driver.cxx b/tests/cxx/parser/validation/any/driver.cxx new file mode 100644 index 0000000..827cbf8 --- /dev/null +++ b/tests/cxx/parser/validation/any/driver.cxx @@ -0,0 +1,139 @@ +// file : tests/cxx/parser/validation/any/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the any particle validation. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; +using xml_schema::ro_string; + +struct any_a_pimpl: any_a_pskel +{ + virtual void + pre () + { + cout << "{" << endl; + } + +#ifdef XSDE_STL + virtual void + a (string const& v) + { + cout << " a = " << v << endl; + } + + virtual void + x (string const& v) + { + cout << " x = " << v << endl; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } + + virtual void + x (char* v) + { + cout << " x = " << v << endl; + delete[] v; + } +#endif + + virtual void +#ifndef XSDE_POLYMORPHIC + _start_any_element (ro_string const&, ro_string const& n) +#else + _start_any_element (ro_string const&, ro_string const& n, const char*) +#endif + { + cout << " start any element '" << n << "'" << endl; + } + + virtual void + _end_any_element (ro_string const&, ro_string const& n) + { + cout << " end any element '" << n << "'" << endl; + } + + virtual void + _any_attribute (ro_string const&, + ro_string const& n, + ro_string const& v) + { + cout << " any attribute " << n << " = '" << v << "'" << endl; + } + + virtual void + _any_characters (ro_string const& s) + { + cout << " any text: '" << s << "'" << endl; + } + + virtual void + post_any_a () + { + 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; + any_a_pimpl any_a_p; + type_pimpl type_p; + + any_a_p.parsers (string_p, string_p); + type_p.parsers (any_a_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + try + { + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cout << " " << e.line () << ":" << e.column () << " " << e << endl + << "}" << endl + << endl; + } + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/validation/any/makefile b/tests/cxx/parser/validation/any/makefile new file mode 100644 index 0000000..dfc1c21 --- /dev/null +++ b/tests/cxx/parser/validation/any/makefile @@ -0,0 +1,82 @@ +# file : tests/cxx/parser/validation/any/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +tests := 000 + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +.PHONY: $(test) +$(test): $(test_targets) + + +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile)
\ No newline at end of file diff --git a/tests/cxx/parser/validation/any/test-000.std b/tests/cxx/parser/validation/any/test-000.std new file mode 100644 index 0000000..a1cc6e3 --- /dev/null +++ b/tests/cxx/parser/validation/any/test-000.std @@ -0,0 +1,29 @@ +{ + start any element 'any' + end any element 'any' +} + +{ + start any element 'any' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any' +} + +{ + x = x + a = a + start any element 'any' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any' +} + diff --git a/tests/cxx/parser/validation/any/test-000.xml b/tests/cxx/parser/validation/any/test-000.xml new file mode 100644 index 0000000..f1a0c83 --- /dev/null +++ b/tests/cxx/parser/validation/any/test-000.xml @@ -0,0 +1,21 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- test dispatching of any-nested elements and attributes --> + + <any-a> + <o:any/> + </any-a> + + <any-a> + <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> + </any-a> + + <any-a x="x"> + <a>a</a> + <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> + </any-a> + +</t:root> diff --git a/tests/cxx/parser/validation/any/test.xsd b/tests/cxx/parser/validation/any/test.xsd new file mode 100644 index 0000000..c05aeb5 --- /dev/null +++ b/tests/cxx/parser/validation/any/test.xsd @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="any-a"> + <sequence> + <element name="a" type="string" minOccurs="0"/> + <any namespace="other" processContents="skip" maxOccurs="unbounded"/> + </sequence> + <attribute name="x" type="string"/> + </complexType> + + <complexType name="type"> + <choice maxOccurs="unbounded"> + <element name="any-a" type="t:any-a"/> + </choice> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/validation/attribute/driver.cxx b/tests/cxx/parser/validation/attribute/driver.cxx new file mode 100644 index 0000000..935d2eb --- /dev/null +++ b/tests/cxx/parser/validation/attribute/driver.cxx @@ -0,0 +1,275 @@ +// file : tests/cxx/parser/validation/attribute/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test attribute and attribute wildcard (anyAttribute) validation. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; +using xml_schema::ro_string; + +struct pass_a_pimpl: pass_a_pskel +{ + virtual void + pre () + { + cout << "pass-a" << endl + << "{" << endl; + } + +#ifdef XSDE_STL + virtual void + a (string const& v) + { + cout << " a = " << v << endl; + } + + virtual void + b (string const& v) + { + cout << " b = " << v << endl; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } + + virtual void + b (char* v) + { + cout << " b = " << v << endl; + delete[] v; + } +#endif + + virtual void + _any_attribute (ro_string const& ns, + ro_string const& name, + ro_string const& value) + { + cout << " any: " << ns << "#" << name << " = " << value << endl; + } + + virtual void + post_pass_a () + { + cout << "}" << endl + << endl; + } +}; + +struct pass_b_pimpl: pass_b_pskel +{ + pass_b_pimpl () +#ifdef XSDE_REUSE_STYLE_TIEIN + : pass_b_pskel (0) +#endif + { + } + + virtual void + pre () + { + cout << "pass-b" << endl + << "{" << endl; + } + +#ifdef XSDE_STL + virtual void + a (string const& v) + { + cout << " a = " << v << endl; + } + + virtual void + b (string const& v) + { + cout << " b = " << v << endl; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } + + virtual void + b (char* v) + { + cout << " b = " << v << endl; + delete[] v; + } +#endif + + virtual void + _any_attribute (ro_string const& ns, + ro_string const& name, + ro_string const& value) + { + cout << " any: " << ns << "#" << name << " = " << value << endl; + } + + virtual void + post_pass_b () + { + cout << "}" << endl + << endl; + } +}; + +struct pass_c_pimpl: pass_c_pskel +{ + pass_c_pimpl () +#ifdef XSDE_REUSE_STYLE_TIEIN + : pass_c_pskel (0) +#endif + { + } + + virtual void + pre () + { + cout << "pass-c" << endl + << "{" << endl; + } + +#ifdef XSDE_STL + virtual void + a (string const& v) + { + cout << " a = " << v << endl; + } + + virtual void + b (string const& v) + { + cout << " b = " << v << endl; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } + + virtual void + b (char* v) + { + cout << " b = " << v << endl; + delete[] v; + } +#endif + + virtual void + post_pass_c () + { + cout << "}" << endl + << endl; + } +}; + +struct fail_pimpl: fail_pskel +{ + fail_pimpl () +#ifdef XSDE_REUSE_STYLE_TIEIN + : fail_pskel (0) +#endif + { + } + + virtual void + pre () + { + cout << "fail" << endl + << "{" << endl; + } + +#ifdef XSDE_STL + virtual void + a (string const& v) + { + cout << " a = " << v << endl; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } +#endif + + virtual void + post_fail () + { + 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; + pass_a_pimpl pass_a_p; + pass_b_pimpl pass_b_p; + pass_c_pimpl pass_c_p; + fail_pimpl fail_p; + type_pimpl type_p; + + pass_a_p.parsers (string_p, string_p); + pass_b_p.parsers (string_p, string_p); + pass_c_p.parsers (string_p, string_p); + fail_p.parsers (string_p); + type_p.parsers (pass_a_p, pass_b_p, pass_c_p, fail_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + try + { + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cout << " " << e.line () << ":" << e.column () << " " << e << endl + << "}" << endl + << endl; + } + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/validation/attribute/makefile b/tests/cxx/parser/validation/attribute/makefile new file mode 100644 index 0000000..d037791 --- /dev/null +++ b/tests/cxx/parser/validation/attribute/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/parser/validation/attribute/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/attribute/output b/tests/cxx/parser/validation/attribute/output new file mode 100644 index 0000000..990f995 --- /dev/null +++ b/tests/cxx/parser/validation/attribute/output @@ -0,0 +1,24 @@ +pass-a +{ + b = b + any: test#foo = foo + any: test#bar = bar +} + +pass-b +{ + a = a + b = b +} + +pass-c +{ + a = a + b = b +} + +fail +{ + 8:9 expected attribute not encountered +} + diff --git a/tests/cxx/parser/validation/attribute/test.xml b/tests/cxx/parser/validation/attribute/test.xml new file mode 100644 index 0000000..b994d1a --- /dev/null +++ b/tests/cxx/parser/validation/attribute/test.xml @@ -0,0 +1,10 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <pass-a b="b" t:foo="foo" t:bar="bar"/> + <pass-b a="a" b="b"/> + <pass-c a="a" b="b"/> + <fail/> + +</t:root> diff --git a/tests/cxx/parser/validation/attribute/test.xsd b/tests/cxx/parser/validation/attribute/test.xsd new file mode 100644 index 0000000..833eb8e --- /dev/null +++ b/tests/cxx/parser/validation/attribute/test.xsd @@ -0,0 +1,71 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + + <!-- Test optional and required attributes as well as a wildcard. --> + <complexType name="pass-a"> + <attribute name="a" type="string" use="optional"/> + <attribute name="b" type="string" use="required"/> + <anyAttribute namespace="##targetNamespace" processContents="skip"/> + </complexType> + + + <!-- Test that in inheritance attributes are checked before wildcards. --> + <complexType name="pass-b-base"> + <attribute name="a" type="string"/> + <anyAttribute namespace="#any" processContents="skip"/> + </complexType> + + <complexType name="pass-b"> + <complexContent> + <extension base="t:pass-b-base"> + <attribute name="b" type="string"/> + <anyAttribute namespace="#any" processContents="skip"/> + </extension> + </complexContent> + </complexType> + + + <!-- Test that in inheritance by restriction required attribute is + checked for even though it is not explicitly mentioned in + derived. --> + <complexType name="pass-c-base"> + <attribute name="a" type="string" use="required"/> + <attribute name="b" type="string" use="optional"/> + </complexType> + + <complexType name="pass-c"> + <complexContent> + <restriction base="t:pass-c-base"> + <attribute name="b" type="string" use="required"/> + </restriction> + </complexContent> + </complexType> + + + <!-- Test detection of missing required attribute. --> + <complexType name="fail-base"> + <attribute name="a" type="string" use="optional"/> + </complexType> + + <complexType name="fail"> + <complexContent> + <restriction base="t:fail-base"> + <attribute name="a" type="string" use="required"/> + </restriction> + </complexContent> + </complexType> + + + <complexType name="type"> + <sequence> + <element name="pass-a" type="t:pass-a"/> + <element name="pass-b" type="t:pass-b"/> + <element name="pass-c" type="t:pass-c"/> + <element name="fail" type="t:fail"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/validation/built-in/any-type/driver.cxx b/tests/cxx/parser/validation/built-in/any-type/driver.cxx new file mode 100644 index 0000000..6aadd78 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/any-type/driver.cxx @@ -0,0 +1,187 @@ +// file : tests/cxx/parser/validation/built-in/any-type/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the anyType and anySimpleType validation. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; +using xml_schema::ro_string; + +struct any_type_pimpl: xml_schema::any_type_pimpl +{ + virtual void + pre () + { + cout << "{" << endl; + } + + virtual void +#ifndef XSDE_POLYMORPHIC + _start_any_element (ro_string const&, ro_string const& n) +#else + _start_any_element (ro_string const&, ro_string const& n, const char*) +#endif + { + cout << " start any element '" << n << "'" << endl; + } + + virtual void + _end_any_element (ro_string const&, ro_string const& n) + { + cout << " end any element '" << n << "'" << endl; + } + + virtual void + _any_attribute (ro_string const&, + ro_string const& n, + ro_string const& v) + { + cout << " any attribute " << n << " = '" << v << "'" << endl; + } + + virtual void + _any_characters (ro_string const& s) + { + cout << " any text: '" << s << "'" << endl; + } + + virtual void + post_any_type () + { + cout << "}" << endl + << endl; + } +}; + +struct any_simple_type_pimpl: xml_schema::any_simple_type_pimpl +{ + virtual void + pre () + { + cout << "{" << endl; + } + + virtual void + _any_characters (ro_string const& s) + { + cout << " any text: '" << s << "'" << endl; + } + + virtual void + post_any_simple_type () + { + cout << "}" << endl + << endl; + } +}; + +struct any_extension_pimpl: any_extension_pskel +{ + any_extension_pimpl () + : any_extension_pskel (&base_impl_) + { + } + +#ifdef XSDE_STL + virtual void + x (const string& v) + { + cout << " x = " << v << endl; + } +#else + virtual void + x (char* v) + { + cout << " x = " << v << endl; + delete[] v; + } +#endif + +private: + any_type_pimpl base_impl_; +}; + +struct any_simple_extension_pimpl: any_simple_extension_pskel +{ + any_simple_extension_pimpl () + : any_simple_extension_pskel (&base_impl_) + { + } + +#ifdef XSDE_STL + virtual void + x (const string& v) + { + cout << " x = " << v << endl; + } +#else + virtual void + x (char* v) + { + cout << " x = " << v << endl; + delete[] v; + } +#endif + +private: + any_simple_type_pimpl base_impl_; +}; + +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; + + any_type_pimpl any_type_p; + any_simple_type_pimpl any_simple_type_p; + + any_extension_pimpl any_extension_p; + any_simple_extension_pimpl any_simple_extension_p; + + type_pimpl type_p; + + any_extension_p.parsers (string_p); + any_simple_extension_p.parsers (string_p); + + type_p.parsers (any_simple_type_p, + any_type_p, + any_extension_p, + any_simple_extension_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/validation/built-in/any-type/makefile b/tests/cxx/parser/validation/built-in/any-type/makefile new file mode 100644 index 0000000..951454e --- /dev/null +++ b/tests/cxx/parser/validation/built-in/any-type/makefile @@ -0,0 +1,82 @@ +# file : tests/cxx/parser/validation/built-in/any-type/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +tests := 000 + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +.PHONY: $(test) +$(test): $(test_targets) + + +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/any-type/test-000.std b/tests/cxx/parser/validation/built-in/any-type/test-000.std new file mode 100644 index 0000000..9e263c0 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/any-type/test-000.std @@ -0,0 +1,113 @@ +{ + any text: '123abc' +} + +{ + any text: ' +' + any text: ' ' + start any element 'any' + end any element 'any' + any text: ' +' + any text: ' ' +} + +{ + any text: ' +' + any text: ' ' + start any element 'any' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any' + any text: ' +' + any text: ' ' +} + +{ + any attribute x = 'x' + any text: ' +' + any text: ' ' + start any element 'a' + any text: 'a' + end any element 'a' + any text: ' +' + any text: ' ' + start any element 'any' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any' + any text: ' +' + any text: ' ' +} + +{ + any text: ' +' + any text: ' ' + start any element 'any' + end any element 'any' + any text: ' +' + any text: ' ' +} + +{ + any text: ' +' + any text: ' ' + start any element 'any' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any' + any text: ' +' + any text: ' ' +} + +{ + x = x + any text: ' +' + any text: ' ' + start any element 'a' + any text: 'a' + end any element 'a' + any text: ' +' + any text: ' ' + start any element 'any' + any attribute x = 'xxx' + any text: 'aaa' + start any element 'a' + any text: 'bbb' + end any element 'a' + any text: 'ccc' + end any element 'any' + any text: ' +' + any text: ' ' +} + +{ + x = x + any text: 'abc123' +} + diff --git a/tests/cxx/parser/validation/built-in/any-type/test-000.xml b/tests/cxx/parser/validation/built-in/any-type/test-000.xml new file mode 100644 index 0000000..7875b7e --- /dev/null +++ b/tests/cxx/parser/validation/built-in/any-type/test-000.xml @@ -0,0 +1,41 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd" + as="123abc"> + + <!-- test dispatching of anyType nested elements and attributes --> + + <a> + <o:any/> + </a> + + <a> + <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> + </a> + + <a x="x"> + <a>a</a> + <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> + </a> + + <!-- anyType extension --> + + <a-extension> + <o:any/> + </a-extension> + + <a-extension> + <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> + </a-extension> + + <a-extension x="x"> + <a>a</a> + <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> + </a-extension> + + <!-- anySimpleType extension --> + + <as-extension x="x">abc123</as-extension> + +</t:root> diff --git a/tests/cxx/parser/validation/built-in/any-type/test.xsd b/tests/cxx/parser/validation/built-in/any-type/test.xsd new file mode 100644 index 0000000..86a4e13 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/any-type/test.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="any-extension"> + <complexContent mixed="true"> + <extension base="anyType"> + <attribute name="x" type="string"/> + </extension> + </complexContent> + </complexType> + + <complexType name="any-simple-extension"> + <simpleContent> + <extension base="anySimpleType"> + <attribute name="x" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="type"> + <choice maxOccurs="unbounded"> + <element name="a" type="anyType"/> + <element name="a-extension" type="t:any-extension"/> + <element name="as-extension" type="t:any-simple-extension"/> + </choice> + <attribute name="as" type="anySimpleType"/> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/parser/validation/built-in/binary/driver.cxx b/tests/cxx/parser/validation/built-in/binary/driver.cxx new file mode 100644 index 0000000..23dbf45 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/binary/driver.cxx @@ -0,0 +1,176 @@ +// file : tests/cxx/parser/validation/built-in/binary/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in base64Binary and hexBinary types validation. +// +#include <cassert> +#include <string.h> // memcpy + +#include <xsde/cxx/parser/validating/base64-binary.hxx> +#include <xsde/cxx/parser/validating/hex-binary.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +bool +compare (buffer* x, const char* p, size_t n) +{ + buffer b; + b.size (n); + memcpy (b.data (), p, n); + + bool r = *x == b; + delete x; + return r; +} + +int +main () +{ + // Good. + // + + // hexBinary + // + { + context c (0); + hex_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + compare (p.post_hex_binary (), "", 0)); + } + + { + context c (0); + hex_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n313"); + p._characters ("23334356162636a6b "); + p._post (); + assert (!c.error_type () && + compare (p.post_hex_binary (), "12345abcjk", 10)); + } + + // base64Binary + // + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("MTIzND "); + p._characters ("VhYmNqaw = = "); + p._post (); + assert (!c.error_type () && + compare (p.post_base64_binary (), "12345abcjk", 10)); + } + + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("YQ=="); + p._post (); + assert (!c.error_type () && + compare (p.post_base64_binary (), "a", 1)); + } + + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("YWI="); + p._post (); + assert (!c.error_type () && + compare (p.post_base64_binary (), "ab", 2)); + } + + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("YWJj"); + p._post (); + assert (!c.error_type () && + compare (p.post_base64_binary (), "abc", 3)); + } + + // Bad + // + + // hexBinary + // + { + context c (0); + hex_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("313"); + p._post (); + assert (c.schema_error () == schema_error::invalid_hex_binary_value); + } + + { + context c (0); + hex_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("313233343X6162636a6b"); + p._post (); + assert (c.schema_error () == schema_error::invalid_hex_binary_value); + } + + // base64Binary + // + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_base64_binary_value); + } + + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("YQ"); + p._post (); + assert (c.schema_error () == schema_error::invalid_base64_binary_value); + } + + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("=="); + p._post (); + assert (c.schema_error () == schema_error::invalid_base64_binary_value); + } + + { + context c (0); + base64_binary_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("MTIzNDVhYmNqaw=A"); + p._post (); + assert (c.schema_error () == schema_error::invalid_base64_binary_value); + } +} diff --git a/tests/cxx/parser/validation/built-in/binary/makefile b/tests/cxx/parser/validation/built-in/binary/makefile new file mode 100644 index 0000000..5a07676 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/binary/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/binary/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/boolean/driver.cxx b/tests/cxx/parser/validation/built-in/boolean/driver.cxx new file mode 100644 index 0000000..7f08ed6 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/boolean/driver.cxx @@ -0,0 +1,150 @@ +// file : tests/cxx/parser/validation/built-in/boolean/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in boolean type validation. +// +#include <cassert> + +#include <xsde/cxx/parser/validating/boolean.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + // Good. + // + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("true"); + p._post (); + assert (!c.error_type () && p.post_boolean ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1"); + p._post (); + assert (!c.error_type () && p.post_boolean ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("false"); + p._post (); + assert (!c.error_type () && !p.post_boolean ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && !p.post_boolean ()); + } + + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" true "); + p._post (); + assert (!c.error_type () && p.post_boolean ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" "); + p._characters (" \n "); + p._characters (" fa"); + p._characters ("l"); + p._characters ("se "); + p._characters (" \n "); + p._characters (" "); + p._post (); + assert (!c.error_type () && !p.post_boolean ()); + } + + // Bad + // + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + //p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" "); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" "); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("fal"); + p._characters ("s "); + p._characters ("e"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + boolean_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("01"); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/boolean/makefile b/tests/cxx/parser/validation/built-in/boolean/makefile new file mode 100644 index 0000000..b844e00 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/boolean/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/boolean/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/byte/driver.cxx b/tests/cxx/parser/validation/built-in/byte/driver.cxx new file mode 100644 index 0000000..26f5a12 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/byte/driver.cxx @@ -0,0 +1,280 @@ +// file : tests/cxx/parser/validation/built-in/byte/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in byte and unsigned byte types validation. +// +#include <cassert> + +#include <xsde/cxx/parser/validating/byte.hxx> +#include <xsde/cxx/parser/validating/unsigned-byte.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + // Good. + // + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("123"); + p._post (); + assert (!c.error_type () && p.post_byte () == 123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("\t +123 \n "); + p._post (); + assert (!c.error_type () && p.post_byte () == 123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-123"); + p._post (); + assert (!c.error_type () && p.post_byte () == -123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+123"); + p._post (); + assert (!c.error_type () && p.post_byte () == 123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0000000000000000123"); + p._post (); + assert (!c.error_type () && p.post_byte () == 123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+0000000000000000123"); + p._post (); + assert (!c.error_type () && p.post_byte () == 123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-0000000000000000123"); + p._post (); + assert (!c.error_type () && p.post_byte () == -123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("\t \n"); + p._characters (" -"); + p._characters ("00000"); + p._characters ("001"); + p._characters ("23 \n\t"); + p._post (); + assert (!c.error_type () && p.post_byte () == -123); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-128"); + p._post (); + assert (!c.error_type () && p.post_byte () == -128); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("127"); + p._post (); + assert (!c.error_type () && p.post_byte () == 127); + } + + { + context c (0); + unsigned_byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+123"); + p._post (); + assert (!c.error_type () && p.post_unsigned_byte () == 123); + } + + { + context c (0); + unsigned_byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_unsigned_byte () == 0); + } + + { + context c (0); + unsigned_byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("255"); + p._post (); + assert (!c.error_type () && p.post_unsigned_byte () == 255); + } + + // Bad + // + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n \t "); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("++01"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--01"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-01"); + p._characters (" "); + p._characters ("23 "); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + unsigned_byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-123"); + p._post (); + assert (c.schema_error ()); + } + + // Ranges + // + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-129"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("128"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + unsigned_byte_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("256"); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/byte/makefile b/tests/cxx/parser/validation/built-in/byte/makefile new file mode 100644 index 0000000..855095f --- /dev/null +++ b/tests/cxx/parser/validation/built-in/byte/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/byte/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/date-time/driver.cxx b/tests/cxx/parser/validation/built-in/date-time/driver.cxx new file mode 100644 index 0000000..43b23f3 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/date-time/driver.cxx @@ -0,0 +1,1833 @@ +// file : tests/cxx/parser/validation/built-in/date-time/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in date and time types validation. +// +#include <cassert> + +#include <xsde/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + using xsde::cxx::time; + + // Good. + // + + // gday & time zone parsing + // + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("---1"); + p._characters ("2+12:00"); + p._post (); + assert (p.post_gday () == gday (12, 12, 0)); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---01"); + p._post (); + assert (p.post_gday () == gday (1)); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---31"); + p._post (); + assert (p.post_gday () == gday (31)); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---15Z"); + p._post (); + assert (p.post_gday () == gday (15, 0, 0)); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---15-14:00"); + p._post (); + assert (p.post_gday () == gday (15, -14, -0)); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---15-12:59"); + p._post (); + assert (p.post_gday () == gday (15, -12, -59)); + } + + // gmonth + // + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("--1"); + p._characters ("0+12:00"); + p._post (); + assert (p.post_gmonth () == gmonth (10, 12, 0)); + } + + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--01"); + p._post (); + assert (p.post_gmonth () == gmonth (1)); + } + + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--12Z"); + p._post (); + assert (p.post_gmonth () == gmonth (12, 0, 0)); + } + + // gyear + // + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("20"); + p._characters ("07+12:00"); + p._post (); + assert (p.post_gyear () == gyear (2007, 12, 0)); + } + + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0001"); + p._post (); + assert (p.post_gyear () == gyear (1)); + } + + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-20000Z"); + p._post (); + assert (p.post_gyear () == gyear (-20000, 0, 0)); + } + + // gmonth_day + // + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("--1"); + p._characters ("0-28+12:00 "); + p._post (); + assert (p.post_gmonth_day () == gmonth_day (10, 28, 12, 00)); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--12-31"); + p._post (); + assert (p.post_gmonth_day () == gmonth_day (12, 31)); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--01-01Z"); + p._post (); + assert (p.post_gmonth_day () == gmonth_day (1, 1, 0, 0)); + } + + // gyear_month + // + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("200"); + p._characters ("7-12+12:00 "); + p._post (); + assert (p.post_gyear_month () == gyear_month (2007, 12, 12, 0)); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2007-10"); + p._post (); + assert (p.post_gyear_month () == gyear_month (-2007, 10)); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("20007-10Z"); + p._post (); + assert (p.post_gyear_month () == gyear_month (20007, 10, 0, 0)); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-20007-01"); + p._post (); + assert (p.post_gyear_month () == gyear_month (-20007, 1)); + } + + // date + // + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("200"); + p._characters ("7-12-26+12:00 "); + p._post (); + assert (p.post_date () == date (2007, 12, 26, 12, 0)); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2007-10-15"); + p._post (); + assert (p.post_date () == date (-2007, 10, 15)); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("20007-12-31Z"); + p._post (); + assert (p.post_date () == date (20007, 12, 31, 0, 0)); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-20007-01-01"); + p._post (); + assert (p.post_date () == date (-20007, 1, 1)); + } + + // time + // + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("12:"); + p._characters ("46:23.456+12:00 "); + p._post (); + assert (p.post_time () == time (12, 46, 23.456, 12, 0)); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("12:13:14"); + p._post (); + assert (p.post_time () == time (12, 13, 14.0)); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("12:13:14Z"); + p._post (); + assert (p.post_time () == time (12, 13, 14.0, 0, 0)); + } + + // date_time + // + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("200"); + p._characters ("7-12-26T12:13:14.123+12:00 "); + p._post (); + assert (p.post_date_time () == + date_time (2007, 12, 26, 12, 13, 14.123, 12, 0)); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2007-10-15T12:13:14"); + p._post (); + assert (p.post_date_time () == date_time (-2007, 10, 15, 12, 13, 14.0)); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("20007-12-31T12:13:14Z"); + p._post (); + assert (p.post_date_time () == + date_time (20007, 12, 31, 12, 13, 14.0, 0, 0)); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-20007-01-01T12:13:14"); + p._post (); + assert (p.post_date_time () == date_time (-20007, 1, 1, 12, 13, 14.0)); + } + + // duration + // + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \t\n "); + p._characters ("-P200"); + p._characters ("7Y13M32DT25H61M61.123S "); + p._post (); + assert (p.post_duration () == + duration (true, 2007, 13, 32, 25, 61, 61.123)); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1Y"); + p._post (); + assert (p.post_duration () == duration (false, 1, 0, 0, 0, 0, 0.0)); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1M"); + p._post (); + assert (p.post_duration () == duration (false, 0, 1, 0, 0, 0, 0.0)); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1D"); + p._post (); + assert (p.post_duration () == duration (false, 0, 0, 1, 0, 0, 0.0)); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT1H"); + p._post (); + assert (p.post_duration () == duration (false, 0, 0, 0, 1, 0, 0.0)); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT1M"); + p._post (); + assert (p.post_duration () == duration (false, 0, 0, 0, 0, 1, 0.0)); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT1.1S"); + p._post (); + assert (p.post_duration () == duration (false, 0, 0, 0, 0, 0, 1.1)); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1YT1S"); + p._post (); + assert (p.post_duration () == duration (false, 1, 0, 0, 0, 0, 1.0)); + } + + // Bad + // + + // gday & time zone parsing + // + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---1"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---32"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---2X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---12asd"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---12X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---1212:00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---12+2:00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---12+1200"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---12+15:00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---12+12:60"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + context c (0); + gday_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("---12+14:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + // gmonth + // + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--13"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--1X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + { + context c (0); + gmonth_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--11+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + // gyear + // + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_value); + } + + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("207"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_value); + } + + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-207"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_value); + } + + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-0000"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_value); + } + + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("20X7"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_value); + } + + { + context c (0); + gyear_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_value); + } + + // gmonth_day + // + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-12-12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--1212"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--12?12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--00-12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--12-00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--13-23"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--12-32"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--1X-12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--12-2X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + context c (0); + gmonth_day_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("--11-11+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + // gyear_month + // + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("207-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-207-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0000-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("20X7-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007?12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-0"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-13"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-1X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + context c (0); + gyear_month_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + // date + // + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("207-01-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-207-01-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0000-01-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("20X7-01-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007?01-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-0-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-00-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-13-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-1X-01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10?12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-0"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-32"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-2X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + context c (0); + date_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + // time + // + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1:01:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2X:01:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23?01:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:0:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:60:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:4X:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:10"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:10?12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:10:"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:10:0"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:10:01."); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:10:60"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:10:2X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("24:01:00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("24:00:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + context c (0); + time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:01:01+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + // date_time + // + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("207-01-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-207-01-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0000-01-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("20X7-01-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007?01-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-0-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-00-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-13-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-1X-01T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10?12T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-0T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-00T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-32T12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-10-2XT12:13:14"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T1:01:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T2X:01:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23?01:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:0:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:60:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:4X:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:10"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:10?12"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:10:"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:10:0"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:10:01."); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:10:60"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T23:10:2X"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T24:01:00"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T24:00:01"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("23:01:01+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + context c (0); + date_time_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007-01-01T12:13:14+12:3o"); + p._post (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + // duration + // + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + // p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2007Y"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2007Y"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P-2007Y"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P-1M"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P-1D"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT-1H"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT-1M"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT-1.1S"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1H1M1S"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1M1Y"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT1S1H"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("PT1H1Y"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1Ygarbage"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } + + { + context c (0); + duration_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("P1YT"); + p._post (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } +} diff --git a/tests/cxx/parser/validation/built-in/date-time/makefile b/tests/cxx/parser/validation/built-in/date-time/makefile new file mode 100644 index 0000000..7e0b597 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/date-time/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/date-time/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/float/driver.cxx b/tests/cxx/parser/validation/built-in/float/driver.cxx new file mode 100644 index 0000000..852d158 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/float/driver.cxx @@ -0,0 +1,309 @@ +// file : tests/cxx/parser/validation/built-in/float/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in float, double, and decimal types validation. +// +#include <math.h> +#include <cassert> + +#include <xsde/cxx/parser/validating/float.hxx> +#include <xsde/cxx/parser/validating/double.hxx> +#include <xsde/cxx/parser/validating/decimal.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + // Good. + // + + // float + // + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" 0000123.456 "); + p._post (); + assert (!c.error_type () && p.post_float () == 123.456F); + } + + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-12.345E2"); + p._post (); + assert (!c.error_type () && p.post_float () == -12.345E2F); + } + + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_float () == 0.0F); + } + + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-0"); + p._post (); + assert (!c.error_type () && p.post_float () == -0.0F); + } + + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("INF"); + p._post (); + assert (!c.error_type () && isinf (p.post_float ())); + } + + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-INF"); + p._post (); + assert (!c.error_type () && isinf (p.post_float ())); + } + + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("NaN"); + p._post (); + assert (!c.error_type () && isnan (p.post_float ())); + } + + // double + // + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" 0000123.456789 "); + p._post (); + assert (!c.error_type () && p.post_double () == 123.456789); + } + + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-12.3456789E2"); + p._post (); + assert (!c.error_type () && p.post_double () == -12.3456789E2); + } + + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_double () == 0.0); + } + + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-0"); + p._post (); + assert (!c.error_type () && p.post_double () == -0.0); + } + + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("INF"); + p._post (); + assert (!c.error_type () && isinf (p.post_double ())); + } + + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-INF"); + p._post (); + assert (!c.error_type () && isinf (p.post_double ())); + } + + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("NaN"); + p._post (); + assert (!c.error_type () && isnan (p.post_double ())); + } + + // decimal + // + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" 0000123.456789 "); + p._post (); + assert (!c.error_type () && p.post_decimal () == 123.456789); + } + + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-123.45678912345"); + p._post (); + assert (!c.error_type () && p.post_decimal () == -123.45678912345); + } + + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_decimal () == 0.0); + } + + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-0"); + p._post (); + assert (!c.error_type () && p.post_decimal () == -0.0); + } + + + // Bad + // + + // float + // + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+INF"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + float_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1.45 E2"); + p._post (); + assert (c.schema_error ()); + } + + // double + // + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+INF"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + double_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1.45 E2"); + p._post (); + assert (c.schema_error ()); + } + + // decimal + // + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("INF"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+INF"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-INF"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("NaN"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + decimal_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1.45 2"); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/float/makefile b/tests/cxx/parser/validation/built-in/float/makefile new file mode 100644 index 0000000..0e5231e --- /dev/null +++ b/tests/cxx/parser/validation/built-in/float/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/float/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/int/driver.cxx b/tests/cxx/parser/validation/built-in/int/driver.cxx new file mode 100644 index 0000000..2395b04 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/int/driver.cxx @@ -0,0 +1,116 @@ +// file : tests/cxx/parser/validation/built-in/int/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in int and unsigned int types validation. +// +#include <cassert> + +#include <xsde/cxx/parser/validating/int.hxx> +#include <xsde/cxx/parser/validating/unsigned-int.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + // Good. + // + { + context c (0); + int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2147483648"); + p._post (); + assert (!c.error_type () && p.post_int () == -2147483648); + } + + { + context c (0); + int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_int () == 0); + } + + { + context c (0); + int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2147483647"); + p._post (); + assert (!c.error_type () && p.post_int () == 2147483647); + } + + { + context c (0); + unsigned_int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_unsigned_int () == 0); + } + + { + context c (0); + unsigned_int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("4294967295"); + p._post (); + assert (!c.error_type () && p.post_unsigned_int () == 4294967295); + } + + // Bad + // + + { + context c (0); + unsigned_int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-123"); + p._post (); + assert (c.schema_error ()); + } + + + // Ranges + // + { + context c (0); + int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2147483649"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2147483648"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + unsigned_int_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("4294967296"); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/int/makefile b/tests/cxx/parser/validation/built-in/int/makefile new file mode 100644 index 0000000..0fc4608 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/int/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/int/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/integer/driver.cxx b/tests/cxx/parser/validation/built-in/integer/driver.cxx new file mode 100644 index 0000000..9676046 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/integer/driver.cxx @@ -0,0 +1,317 @@ +// file : tests/cxx/parser/validation/built-in/int/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in integer & friends types validation. +// +#include <limits.h> + +#include <string> +#include <sstream> +#include <cassert> + +#include <xsde/cxx/parser/validating/integer.hxx> +#include <xsde/cxx/parser/validating/negative-integer.hxx> +#include <xsde/cxx/parser/validating/non-positive-integer.hxx> +#include <xsde/cxx/parser/validating/positive-integer.hxx> +#include <xsde/cxx/parser/validating/non-negative-integer.hxx> + +using namespace std; +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + // Good. + // + + std::string min; + std::string max; + std::string umax; + + { + ostringstream ostr; + ostr << LONG_MIN; + min = ostr.str (); + } + + { + ostringstream ostr; + ostr << LONG_MAX; + max = ostr.str (); + } + + { + ostringstream ostr; + ostr << ULONG_MAX; + umax = ostr.str (); + } + + // integer + // + { + context c (0); + integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (min.c_str ()); + p._post (); + assert (!c.error_type () && p.post_integer () == LONG_MIN); + } + + { + context c (0); + integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_integer () == 0); + } + + { + context c (0); + integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (max.c_str ()); + p._post (); + assert (!c.error_type () && p.post_integer () == LONG_MAX); + } + + // negative_integer + // + { + context c (0); + negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (min.c_str ()); + p._post (); + assert (!c.error_type () && p.post_negative_integer () == LONG_MIN); + } + + { + context c (0); + negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-1"); + p._post (); + assert (!c.error_type () && p.post_negative_integer () == -1); + } + + // non_positive_integer + // + { + context c (0); + non_positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (min.c_str ()); + p._post (); + assert (!c.error_type () && p.post_non_positive_integer () == LONG_MIN); + } + + { + context c (0); + non_positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+0"); + p._post (); + assert (!c.error_type () && p.post_non_positive_integer () == 0); + } + + // positive_integer + // + { + context c (0); + positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1"); + p._post (); + assert (!c.error_type () && p.post_positive_integer () == 1); + } + + { + context c (0); + positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (umax.c_str ()); + p._post (); + assert (!c.error_type () && p.post_positive_integer () == ULONG_MAX); + } + + // non_negative_integer + // + { + context c (0); + non_negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-0"); + p._post (); + assert (!c.error_type () && p.post_non_negative_integer () == 0); + } + + { + context c (0); + non_negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (umax.c_str ()); + p._post (); + assert (!c.error_type () && p.post_non_negative_integer () == ULONG_MAX); + } + + + // Bad + // + + std::string past_min (min); + std::string past_max (max); + std::string past_umax (umax); + + assert (*past_min.rbegin () != '9'); + assert (*past_max.rbegin () != '9'); + assert (*past_umax.rbegin () != '9'); + + (*past_min.rbegin ())++; + (*past_max.rbegin ())++; + (*past_umax.rbegin ())++; + + // integer + // + { + context c (0); + integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (past_min.c_str ()); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (past_max.c_str ()); + p._post (); + assert (c.schema_error ()); + } + + // negative_integer + // + { + context c (0); + negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (past_min.c_str ()); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-0"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1"); + p._post (); + assert (c.schema_error ()); + } + + // non_positive_integer + // + { + context c (0); + non_positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (past_min.c_str ()); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + non_positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1"); + p._post (); + assert (c.schema_error ()); + } + + // positive_integer + // + { + context c (0); + positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-1"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("+0"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + positive_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (past_umax.c_str ()); + p._post (); + assert (c.schema_error ()); + } + + // non_negative_integer + // + { + context c (0); + non_negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-1"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + non_negative_integer_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (past_umax.c_str ()); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/integer/makefile b/tests/cxx/parser/validation/built-in/integer/makefile new file mode 100644 index 0000000..8e5fa68 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/integer/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/integer/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/long-long/driver.cxx b/tests/cxx/parser/validation/built-in/long-long/driver.cxx new file mode 100644 index 0000000..3ddf6d9 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/long-long/driver.cxx @@ -0,0 +1,118 @@ +// file : tests/cxx/parser/validation/built-in/long-long/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in long and unsigned long types validation. +// +#include <cassert> + +#include <xsde/cxx/parser/validating/long-long.hxx> +#include <xsde/cxx/parser/validating/unsigned-long-long.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + // Good. + // + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-9223372036854775808"); + p._post (); + assert (!c.error_type () && + p.post_long () == (-9223372036854775807LL - 1)); + } + + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_long () == 0); + } + + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("9223372036854775807"); + p._post (); + assert (!c.error_type () && p.post_long () == 9223372036854775807LL); + } + + { + context c (0); + unsigned_long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_unsigned_long () == 0); + } + + { + context c (0); + unsigned_long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("18446744073709551615"); + p._post (); + assert (!c.error_type () && + p.post_unsigned_long () == 18446744073709551615ULL); + } + + // Bad + // + + { + context c (0); + unsigned_long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-123"); + p._post (); + assert (c.schema_error ()); + } + + + // Ranges + // + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-9223372036854775809"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("9223372036854775808"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + unsigned_long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("18446744073709551616"); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/long-long/makefile b/tests/cxx/parser/validation/built-in/long-long/makefile new file mode 100644 index 0000000..948c89a --- /dev/null +++ b/tests/cxx/parser/validation/built-in/long-long/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/long-long/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/long/driver.cxx b/tests/cxx/parser/validation/built-in/long/driver.cxx new file mode 100644 index 0000000..0312b3b --- /dev/null +++ b/tests/cxx/parser/validation/built-in/long/driver.cxx @@ -0,0 +1,106 @@ +// file : tests/cxx/parser/validation/built-in/long/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test built-in long and unsigned long types validation (32 bit fall-back). +// +#include <cassert> + +#include <xsde/cxx/parser/validating/long.hxx> +#include <xsde/cxx/parser/validating/unsigned-long.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main (int argc, char* argv[]) +{ + // Good. + // + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2147483648"); + p._post (); + assert (!c.error_type () && p.post_long () == -2147483648); + } + + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_long () == 0); + } + + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2147483647"); + p._post (); + assert (!c.error_type () && p.post_long () == 2147483647); + } + + { + context c (0); + unsigned_long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_unsigned_long () == 0); + } + + { + context c (0); + unsigned_long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("4294967295"); + p._post (); + assert (!c.error_type () && p.post_unsigned_long () == 4294967295); + } + + // Bad + // + + { + context c (0); + unsigned_long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-123"); + p._post (); + assert (c.schema_error ()); + } + + + // Ranges + // + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-2147483649"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + long_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("2147483648"); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/long/makefile b/tests/cxx/parser/validation/built-in/long/makefile new file mode 100644 index 0000000..e050feb --- /dev/null +++ b/tests/cxx/parser/validation/built-in/long/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/long/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/makefile b/tests/cxx/parser/validation/built-in/makefile new file mode 100644 index 0000000..0e6b3aa --- /dev/null +++ b/tests/cxx/parser/validation/built-in/makefile @@ -0,0 +1,35 @@ +# file : tests/cxx/parser/validation/built-in/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +tests := binary boolean byte date-time float int integer qname short \ +string uri + +ifeq ($(xsde_iostream),y) +ifeq ($(xsde_exceptions),y) +ifeq ($(xsde_reuse_style),tiein) +tests += any-type +endif +endif +endif + +ifeq ($(xsde_longlong),y) +tests += long-long +else +tests += long +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/parser/validation/built-in/qname/driver.cxx b/tests/cxx/parser/validation/built-in/qname/driver.cxx new file mode 100644 index 0000000..f3acc6b --- /dev/null +++ b/tests/cxx/parser/validation/built-in/qname/driver.cxx @@ -0,0 +1,132 @@ +// file : tests/cxx/parser/validation/built-in/qname/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in QName type validation. +// +#include <cassert> + +#include <xsde/config.h> + +// Let the runtime header sort out which version (stl/no-stl) to +// include. +// +#include <xsde/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +#ifdef XSDE_STL +bool +compare (const qname& x, const char* p, const char* n) +{ + return x == qname (p, n); +} +#else +bool +compare (qname* x, const char* p, const char* n) +{ + qname y; + y.prefix_copy (p); + y.name_copy (n); + + bool r = *x == y; + delete x; + return r; +} +#endif + +int +main () +{ + // Good. + // + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" xsi"); + p._characters (":"); + p._characters ("schemaLocation"); + p._post (); + assert (!c.error_type () && + compare (p.post_qname (), "xsi", "schemaLocation")); + } + + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("schemaLocation"); + p._post (); + assert (!c.error_type () && + compare (p.post_qname (), "", "schemaLocation")); + } + + + // Bad + // + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + //p._characters (""); + p._post (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } + + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (":"); + p._post (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } + + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("xsi:"); + p._post (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } + + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (":schemaLocation"); + p._post (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } + + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("x?i:schemaLocation"); + p._post (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } + + { + context c (0); + qname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("xsi:schema Location"); + p._post (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } +} diff --git a/tests/cxx/parser/validation/built-in/qname/makefile b/tests/cxx/parser/validation/built-in/qname/makefile new file mode 100644 index 0000000..eed5151 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/qname/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/qname/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/short/driver.cxx b/tests/cxx/parser/validation/built-in/short/driver.cxx new file mode 100644 index 0000000..6822f61 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/short/driver.cxx @@ -0,0 +1,116 @@ +// file : tests/cxx/parser/validation/built-in/short/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in short and unsigned short types validation. +// +#include <cassert> + +#include <xsde/cxx/parser/validating/short.hxx> +#include <xsde/cxx/parser/validating/unsigned-short.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + // Good. + // + { + context c (0); + short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-32768"); + p._post (); + assert (!c.error_type () && p.post_short () == -32768); + } + + { + context c (0); + short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_short () == 0); + } + + { + context c (0); + short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("32767"); + p._post (); + assert (!c.error_type () && p.post_short () == 32767); + } + + { + context c (0); + unsigned_short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("0"); + p._post (); + assert (!c.error_type () && p.post_unsigned_short () == 0); + } + + { + context c (0); + unsigned_short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("65535"); + p._post (); + assert (!c.error_type () && p.post_unsigned_short () == 65535); + } + + // Bad + // + + { + context c (0); + unsigned_short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-1234"); + p._post (); + assert (c.schema_error ()); + } + + + // Ranges + // + { + context c (0); + short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-32769"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("32768"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + unsigned_short_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("65536"); + p._post (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/parser/validation/built-in/short/makefile b/tests/cxx/parser/validation/built-in/short/makefile new file mode 100644 index 0000000..d82fc91 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/short/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/short/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/string/driver.cxx b/tests/cxx/parser/validation/built-in/string/driver.cxx new file mode 100644 index 0000000..06a4708 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/string/driver.cxx @@ -0,0 +1,613 @@ +// file : tests/cxx/parser/validation/built-in/string/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in string & friends types validation. +// +#include <string> +#include <cassert> + +#include <xsde/config.h> + +// Let the runtime header sort out which version (stl/no-stl) to +// include. +// +#include <xsde/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +bool +compare (const string_sequence* x, const string_sequence& y) +{ + bool r = *x == y; + delete x; + return r; +} + +int +main () +{ + // We are going to leak a bit of memory in the no-STL case. + // + using std::string; + + // Good. + // + + // string + // + { + context c (0); + string_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" aaa "); + p._characters ("bbb"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_string () == string (" \n\t aaa bbb ")); + } + + // normalized_string + // + { + context c (0); + normalized_string_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" aaa \n\t "); + p._characters (" bbb"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_normalized_string () == string (" aaa bbb ")); + } + + // token + // + { + context c (0); + token_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" aaa \n\t "); + p._characters (" bbb \n\t"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_token () == string ("aaa bbb")); + } + + // name + // + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a:b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_name () == string ("a:b-c_d123")); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" _12 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_name () == string ("_12")); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" :12 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_name () == string (":12")); + } + + // nmtoken + // + { + context c (0); + nmtoken_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" 123a:b-c_d123 "); + p._characters (" \n\t"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_nmtoken () == string ("123a:b-c_d123")); + } + + // nmtokens + // + { + context c (0); + string_sequence s; +#ifdef XSDE_STL + s.push_back ("123"); + s.push_back ("abc"); +#else + s.push_back_copy ("123"); + s.push_back_copy ("abc"); +#endif + + nmtokens_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" 123 "); + p._characters (" \n\t abc "); + p._characters (" "); + p._post (); + assert (!c.error_type () && compare (p.post_nmtokens (), s)); + } + + // ncname + // + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a.b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_ncname () == string ("a.b-c_d123")); + } + + // id + // + { + context c (0); + id_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a.b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_id () == string ("a.b-c_d123")); + } + + // idref + // + { + context c (0); + idref_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a.b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_idref () == string ("a.b-c_d123")); + } + + // idrefs + // + { + context c (0); + string_sequence s; +#ifdef XSDE_STL + s.push_back ("a123"); + s.push_back ("abc"); +#else + s.push_back_copy ("a123"); + s.push_back_copy ("abc"); +#endif + + idrefs_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a123 "); + p._characters (" \n\t abc "); + p._characters (" "); + p._post (); + assert (!c.error_type () && compare (p.post_idrefs (), s)); + } + + // language + // + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" x "); + p._post (); + assert (!c.error_type () && p.post_language () == string ("x")); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" en "); + p._post (); + assert (!c.error_type () && p.post_language () == string ("en")); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" en"); + p._characters ("-us "); + p._post (); + assert (!c.error_type () && p.post_language () == string ("en-us")); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("one-two-three-four44-seven77-eight888"); + p._post (); + assert (!c.error_type () && + p.post_language () == + string ("one-two-three-four44-seven77-eight888")); + } + + // Bad + // + + // name + // + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (".a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a,b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a<b"); + p._post (); + assert (c.schema_error ()); + } + + // nmtoken + // + { + context c (0); + nmtoken_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + nmtoken_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a,b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + nmtoken_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + nmtoken_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a<b"); + p._post (); + assert (c.schema_error ()); + } + + // nmtokens + // + { + context c (0); + nmtokens_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" "); + p._characters (" \t\n "); + p._post_impl (); + assert (c.schema_error () == schema_error::invalid_nmtokens_value); + } + + { + context c (0); + nmtokens_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("ab a,b"); + p._post_impl (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + // ncname + // + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (".a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (":a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a:b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a,b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a<b"); + p._post (); + assert (c.schema_error ()); + } + + // id + // + { + context c (0); + id_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a b"); + p._post (); + assert (c.schema_error () == schema_error::invalid_id_value); + } + + // idref + // + { + context c (0); + idref_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a b"); + p._post (); + assert (c.schema_error () == schema_error::invalid_idref_value); + } + + // idrefs + // + { + context c (0); + idrefs_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" "); + p._characters (" \t\n "); + p._post_impl (); + assert (c.schema_error () == schema_error::invalid_idrefs_value); + } + + { + context c (0); + idrefs_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("ab a<b"); + p._post_impl (); + assert (c.schema_error () == schema_error::invalid_idref_value); + } + + // language + // + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" "); + p._post (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("en-"); + p._post (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a1"); + p._post (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("en+us"); + p._post (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("en-nine99999"); + p._post (); + assert (c.schema_error () == schema_error::invalid_language_value); + } +} diff --git a/tests/cxx/parser/validation/built-in/string/makefile b/tests/cxx/parser/validation/built-in/string/makefile new file mode 100644 index 0000000..27fc822 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/string/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/string/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/built-in/uri/driver.cxx b/tests/cxx/parser/validation/built-in/uri/driver.cxx new file mode 100644 index 0000000..5d1f91a --- /dev/null +++ b/tests/cxx/parser/validation/built-in/uri/driver.cxx @@ -0,0 +1,66 @@ +// file : tests/cxx/parser/validation/built-in/uri/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in anyURI type validation. +// +#include <string> +#include <cassert> + +// Let the runtime header sort out which version (stl/no-stl) to +// include. +// +#include <xsde/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +int +main () +{ + using std::string; + + // Good. + // + { + context c (0); + uri_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" "); + p._post (); + assert (!c.error_type () && p.post_uri () == string ("")); + } + + { + context c (0); + uri_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("relative"); + p._post (); + assert (!c.error_type () && p.post_uri () == string ("relative")); + } + + { + context c (0); + uri_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("#id"); + p._post (); + assert (!c.error_type () && p.post_uri () == string ("#id")); + } + + { + context c (0); + uri_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("http://www.example.com/foo#bar"); + p._post (); + assert (!c.error_type () && + p.post_uri () == string ("http://www.example.com/foo#bar")); + } +} diff --git a/tests/cxx/parser/validation/built-in/uri/makefile b/tests/cxx/parser/validation/built-in/uri/makefile new file mode 100644 index 0000000..09da436 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/uri/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/parser/validation/built-in/uri/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/validation/choice/driver.cxx b/tests/cxx/parser/validation/choice/driver.cxx new file mode 100644 index 0000000..e49539a --- /dev/null +++ b/tests/cxx/parser/validation/choice/driver.cxx @@ -0,0 +1,158 @@ +// file : tests/cxx/parser/validation/choice/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the choice compositor validation. +// + +#include <string> +#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; + } + +#ifdef XSDE_STL + 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; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } + + virtual void + b (char* v) + { + cout << " b = " << v << endl; + delete[] v; + } + + virtual void + c (char* v) + { + cout << " c = " << v << endl; + delete[] v; + } + + virtual void + d (char* v) + { + cout << " d = " << v << endl; + delete[] v; + } +#endif + + virtual void +#ifndef XSDE_POLYMORPHIC + _start_any_element (ro_string const& ns, ro_string const& name) +#else + _start_any_element (ro_string const& ns, ro_string const& name, const char*) +#endif + { + 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_pimpl doc_p (type_p, "test", "root"); + + try + { + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cout << " " << e.line () << ":" << e.column () << " " << e << endl + << "}" << endl + << endl; + } + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/validation/choice/makefile b/tests/cxx/parser/validation/choice/makefile new file mode 100644 index 0000000..0df0020 --- /dev/null +++ b/tests/cxx/parser/validation/choice/makefile @@ -0,0 +1,81 @@ +# file : tests/cxx/parser/validation/choice/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +tests := 000 001 002 003 004 + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +.PHONY: $(test) +$(test): $(test_targets) + + +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile)
\ No newline at end of file diff --git a/tests/cxx/parser/validation/choice/test-000.std b/tests/cxx/parser/validation/choice/test-000.std new file mode 100644 index 0000000..856b7f5 --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-000.std @@ -0,0 +1,22 @@ +{ + a = a + b = b +} + +{ + c = c + d = d + any: other#any + { + chars = any + } + a = a +} + +{ + c = c + d = d + d = d + a = a +} + diff --git a/tests/cxx/parser/validation/choice/test-000.xml b/tests/cxx/parser/validation/choice/test-000.xml new file mode 100644 index 0000000..39b9614 --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-000.xml @@ -0,0 +1,30 @@ +<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> diff --git a/tests/cxx/parser/validation/choice/test-001.std b/tests/cxx/parser/validation/choice/test-001.std new file mode 100644 index 0000000..3be2413 --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-001.std @@ -0,0 +1,4 @@ +{ + 8:11 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/choice/test-001.xml b/tests/cxx/parser/validation/choice/test-001.xml new file mode 100644 index 0000000..c509e0d --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-001.xml @@ -0,0 +1,10 @@ +<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> diff --git a/tests/cxx/parser/validation/choice/test-002.std b/tests/cxx/parser/validation/choice/test-002.std new file mode 100644 index 0000000..0de284d --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-002.std @@ -0,0 +1,11 @@ +{ + c = c + d = d + any: other#any + { + chars = any + } + a = a + 14:7 unexpected element encountered +} + diff --git a/tests/cxx/parser/validation/choice/test-002.xml b/tests/cxx/parser/validation/choice/test-002.xml new file mode 100644 index 0000000..3b7e663 --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-002.xml @@ -0,0 +1,17 @@ +<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> diff --git a/tests/cxx/parser/validation/choice/test-003.std b/tests/cxx/parser/validation/choice/test-003.std new file mode 100644 index 0000000..8ecfdc2 --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-003.std @@ -0,0 +1,5 @@ +{ + c = c + 9:11 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/choice/test-003.xml b/tests/cxx/parser/validation/choice/test-003.xml new file mode 100644 index 0000000..ba15c7e --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-003.xml @@ -0,0 +1,11 @@ +<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> diff --git a/tests/cxx/parser/validation/choice/test-004.std b/tests/cxx/parser/validation/choice/test-004.std new file mode 100644 index 0000000..400577a --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-004.std @@ -0,0 +1,4 @@ +{ + 8:7 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/choice/test-004.xml b/tests/cxx/parser/validation/choice/test-004.xml new file mode 100644 index 0000000..f6960dd --- /dev/null +++ b/tests/cxx/parser/validation/choice/test-004.xml @@ -0,0 +1,11 @@ +<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> diff --git a/tests/cxx/parser/validation/choice/test.xsd b/tests/cxx/parser/validation/choice/test.xsd new file mode 100644 index 0000000..8132bbb --- /dev/null +++ b/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/tests/cxx/parser/validation/makefile b/tests/cxx/parser/validation/makefile new file mode 100644 index 0000000..e2f798c --- /dev/null +++ b/tests/cxx/parser/validation/makefile @@ -0,0 +1,26 @@ +# file : tests/cxx/parser/validation/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +tests := built-in + +ifeq ($(xsde_iostream),y) +ifeq ($(xsde_exceptions),y) +tests += all any attribute choice restriction sequence +endif +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/parser/validation/restriction/driver.cxx b/tests/cxx/parser/validation/restriction/driver.cxx new file mode 100644 index 0000000..0088893 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/driver.cxx @@ -0,0 +1,122 @@ +// file : tests/cxx/parser/validation/restriction/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the restriction compositor validation. +// + +#include <string> +#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 +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + restriction_a_pimpl () + : restriction_a_pskel (0) + { + } +#endif +}; + +struct extension_b_pimpl: extension_b_pskel +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + extension_b_pimpl () + : extension_b_pskel (0) + { + } +#endif +}; + +struct restriction_b_pimpl: restriction_b_pskel +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + restriction_b_pimpl () + : restriction_b_pskel (0) + { + } +#endif +}; + +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_pimpl doc_b_p (type_b_p, "test", "root"); + xml_schema::document_pimpl doc_r_p (type_r_p, "test", "root"); + + type_b_p.pre (); + doc_b_p.parse (argv[1]); + type_b_p.post_type_b (); + + try + { + type_r_p.pre (); + doc_r_p.parse (argv[1]); + type_r_p.post_type_r (); + } + catch (xml_schema::parser_exception const& e) + { + cout << e.line () << ":" << e.column () << " " << e << endl; + } + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/validation/restriction/makefile b/tests/cxx/parser/validation/restriction/makefile new file mode 100644 index 0000000..ba9dcff --- /dev/null +++ b/tests/cxx/parser/validation/restriction/makefile @@ -0,0 +1,81 @@ +# file : tests/cxx/parser/validation/restriction/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +tests := 000 001 002 003 004 005 + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +.PHONY: $(test) +$(test): $(test_targets) + + +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile)
\ No newline at end of file diff --git a/tests/cxx/parser/validation/restriction/test-000.std b/tests/cxx/parser/validation/restriction/test-000.std new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-000.std diff --git a/tests/cxx/parser/validation/restriction/test-000.xml b/tests/cxx/parser/validation/restriction/test-000.xml new file mode 100644 index 0000000..21402b4 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-000.xml @@ -0,0 +1,31 @@ +<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> diff --git a/tests/cxx/parser/validation/restriction/test-001.std b/tests/cxx/parser/validation/restriction/test-001.std new file mode 100644 index 0000000..1666695 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-001.std @@ -0,0 +1 @@ +7:7 expected element not encountered diff --git a/tests/cxx/parser/validation/restriction/test-001.xml b/tests/cxx/parser/validation/restriction/test-001.xml new file mode 100644 index 0000000..4015302 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-001.xml @@ -0,0 +1,11 @@ +<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> diff --git a/tests/cxx/parser/validation/restriction/test-002.std b/tests/cxx/parser/validation/restriction/test-002.std new file mode 100644 index 0000000..a261ba8 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-002.std @@ -0,0 +1 @@ +10:18 expected attribute not encountered diff --git a/tests/cxx/parser/validation/restriction/test-002.xml b/tests/cxx/parser/validation/restriction/test-002.xml new file mode 100644 index 0000000..eb7684c --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-002.xml @@ -0,0 +1,12 @@ +<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> diff --git a/tests/cxx/parser/validation/restriction/test-003.std b/tests/cxx/parser/validation/restriction/test-003.std new file mode 100644 index 0000000..c13bef2 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-003.std @@ -0,0 +1 @@ +11:7 unexpected element encountered diff --git a/tests/cxx/parser/validation/restriction/test-003.xml b/tests/cxx/parser/validation/restriction/test-003.xml new file mode 100644 index 0000000..49f18c7 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-003.xml @@ -0,0 +1,16 @@ +<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> diff --git a/tests/cxx/parser/validation/restriction/test-004.std b/tests/cxx/parser/validation/restriction/test-004.std new file mode 100644 index 0000000..1666695 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-004.std @@ -0,0 +1 @@ +7:7 expected element not encountered diff --git a/tests/cxx/parser/validation/restriction/test-004.xml b/tests/cxx/parser/validation/restriction/test-004.xml new file mode 100644 index 0000000..115cd38 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-004.xml @@ -0,0 +1,10 @@ +<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> diff --git a/tests/cxx/parser/validation/restriction/test-005.std b/tests/cxx/parser/validation/restriction/test-005.std new file mode 100644 index 0000000..b2ee79e --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-005.std @@ -0,0 +1 @@ +9:18 expected attribute not encountered diff --git a/tests/cxx/parser/validation/restriction/test-005.xml b/tests/cxx/parser/validation/restriction/test-005.xml new file mode 100644 index 0000000..e9ab7d9 --- /dev/null +++ b/tests/cxx/parser/validation/restriction/test-005.xml @@ -0,0 +1,11 @@ +<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> diff --git a/tests/cxx/parser/validation/restriction/test.xsd b/tests/cxx/parser/validation/restriction/test.xsd new file mode 100644 index 0000000..158ded5 --- /dev/null +++ b/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/tests/cxx/parser/validation/sequence/driver.cxx b/tests/cxx/parser/validation/sequence/driver.cxx new file mode 100644 index 0000000..60cef37 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/driver.cxx @@ -0,0 +1,185 @@ +// file : tests/cxx/parser/validation/sequence/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the sequence compositor validation. +// + +#include <string> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; +using xml_schema::ro_string; + +struct sequence_pimpl: sequence_pskel +{ + virtual void + pre () + { + cout << "{" << endl; + } + +#ifdef XSDE_STL + 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 + e (string const& v) + { + cout << " e = " << v << endl; + } + + virtual void + f (string const& v) + { + cout << " f = " << v << endl; + } +#else + virtual void + a (char* v) + { + cout << " a = " << v << endl; + delete[] v; + } + + virtual void + b (char* v) + { + cout << " b = " << v << endl; + delete[] v; + } + + virtual void + c (char* v) + { + cout << " c = " << v << endl; + delete[] v; + } + + virtual void + d (char* v) + { + cout << " d = " << v << endl; + delete[] v; + } + + virtual void + e (char* v) + { + cout << " e = " << v << endl; + delete[] v; + } + + virtual void + f (char* v) + { + cout << " f = " << v << endl; + delete[] v; + } +#endif + + virtual void +#ifndef XSDE_POLYMORPHIC + _start_any_element (ro_string const& ns, ro_string const& name) +#else + _start_any_element (ro_string const& ns, ro_string const& name, const char*) +#endif + { + 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_sequence () + { + 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; + sequence_pimpl sequence_p; + type_pimpl type_p; + + sequence_p.parsers (string_p, string_p, string_p, + string_p, string_p, string_p); + type_p.parsers (sequence_p); + + xml_schema::document_pimpl doc_p (type_p, "test", "root"); + + try + { + type_p.pre (); + doc_p.parse (argv[1]); + type_p.post_type (); + } + catch (xml_schema::parser_exception const& e) + { + cout << " " << e.line () << ":" << e.column () << " " << e << endl + << "}" << endl + << endl; + } + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/validation/sequence/makefile b/tests/cxx/parser/validation/sequence/makefile new file mode 100644 index 0000000..f7ee5a9 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/makefile @@ -0,0 +1,81 @@ +# file : tests/cxx/parser/validation/sequence/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +tests := 000 001 002 003 004 005 006 + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +.PHONY: $(test) +$(test): $(test_targets) + + +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile)
\ No newline at end of file diff --git a/tests/cxx/parser/validation/sequence/test-000.std b/tests/cxx/parser/validation/sequence/test-000.std new file mode 100644 index 0000000..8a44762 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-000.std @@ -0,0 +1,56 @@ +{ + c = c + d = d + any: test#any + { + chars = aaa + any: #a + { + chars = bbb + } + chars = ccc + } + f = f + e = e +} + +{ + a = a + b = b + c = c + d = d + d = d + d = d + any: other#any + { + chars = any + } + f = f + e = e + e = e +} + +{ + a = a + b = b + c = c + d = d + d = d + d = d + any: other#any + { + chars = any + } + f = f + e = e + e = e + c = c + d = d + any: test#any + { + chars = any + } + f = f + e = e +} + diff --git a/tests/cxx/parser/validation/sequence/test-000.xml b/tests/cxx/parser/validation/sequence/test-000.xml new file mode 100644 index 0000000..9bcbd7e --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-000.xml @@ -0,0 +1,46 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <sequence> + <c>c</c> + <d>d</d> + <t:any>aaa<a>bbb</a>ccc</t:any> + <f>f</f> + <e>e</e> + </sequence> + + <sequence> + <a>a</a> + <b>b</b> + <c>c</c> + <d>d</d> + <d>d</d> + <d>d</d> + <o:any>any</o:any> + <f>f</f> + <e>e</e> + <e>e</e> + </sequence> + + <sequence> + <a>a</a> + <b>b</b> + <c>c</c> + <d>d</d> + <d>d</d> + <d>d</d> + <o:any>any</o:any> + <f>f</f> + <e>e</e> + <e>e</e> + + <c>c</c> + <d>d</d> + <t:any>any</t:any> + <f>f</f> + <e>e</e> + </sequence> + +</t:root> diff --git a/tests/cxx/parser/validation/sequence/test-001.std b/tests/cxx/parser/validation/sequence/test-001.std new file mode 100644 index 0000000..733078a --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-001.std @@ -0,0 +1,4 @@ +{ + 8:13 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/sequence/test-001.xml b/tests/cxx/parser/validation/sequence/test-001.xml new file mode 100644 index 0000000..67d33ce --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-001.xml @@ -0,0 +1,10 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- fail minOccurs="1" --> + <sequence> + </sequence> + +</t:root> diff --git a/tests/cxx/parser/validation/sequence/test-002.std b/tests/cxx/parser/validation/sequence/test-002.std new file mode 100644 index 0000000..d58d744 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-002.std @@ -0,0 +1,20 @@ +{ + c = c + d = d + any: test#any + { + chars = any + } + f = f + e = e + c = c + d = d + any: test#any + { + chars = any + } + f = f + e = e + 20:7 unexpected element encountered +} + diff --git a/tests/cxx/parser/validation/sequence/test-002.xml b/tests/cxx/parser/validation/sequence/test-002.xml new file mode 100644 index 0000000..be25fcf --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-002.xml @@ -0,0 +1,27 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- fail maxOccurs="2" --> + <sequence> + <c>c</c> + <d>d</d> + <t:any>any</t:any> + <f>f</f> + <e>e</e> + + <c>c</c> + <d>d</d> + <t:any>any</t:any> + <f>f</f> + <e>e</e> + + <c>c</c> + <d>d</d> + <t:any>any</t:any> + <f>f</f> + <e>e</e> + </sequence> + +</t:root> diff --git a/tests/cxx/parser/validation/sequence/test-003.std b/tests/cxx/parser/validation/sequence/test-003.std new file mode 100644 index 0000000..db09f17 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-003.std @@ -0,0 +1,5 @@ +{ + a = a + 9:7 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/sequence/test-003.xml b/tests/cxx/parser/validation/sequence/test-003.xml new file mode 100644 index 0000000..af7d21d --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-003.xml @@ -0,0 +1,17 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- fail a maxOccurs="1" --> + <sequence> + <a>a</a> + <a>a</a> + <c>c</c> + <d>d</d> + <t:any>any</t:any> + <f>f</f> + <e>e</e> + </sequence> + +</t:root> diff --git a/tests/cxx/parser/validation/sequence/test-004.std b/tests/cxx/parser/validation/sequence/test-004.std new file mode 100644 index 0000000..400577a --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-004.std @@ -0,0 +1,4 @@ +{ + 8:7 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/sequence/test-004.xml b/tests/cxx/parser/validation/sequence/test-004.xml new file mode 100644 index 0000000..a58b6d4 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-004.xml @@ -0,0 +1,14 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- fail c minOccurs="1" --> + <sequence> + <d>d</d> + <t:any>any</t:any> + <f>f</f> + <e>e</e> + </sequence> + +</t:root> diff --git a/tests/cxx/parser/validation/sequence/test-005.std b/tests/cxx/parser/validation/sequence/test-005.std new file mode 100644 index 0000000..9603e0f --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-005.std @@ -0,0 +1,6 @@ +{ + c = c + d = d + 10:12 expected element not encountered +} + diff --git a/tests/cxx/parser/validation/sequence/test-005.xml b/tests/cxx/parser/validation/sequence/test-005.xml new file mode 100644 index 0000000..e3dd03d --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-005.xml @@ -0,0 +1,15 @@ +<t:root xmlns:t="test" + xmlns:o1="other1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- fail any namespace="##targetNamespace other" --> + <sequence> + <c>c</c> + <d>d</d> + <o1:any>any</o1:any> + <f>f</f> + <e>e</e> + </sequence> + +</t:root> diff --git a/tests/cxx/parser/validation/sequence/test-006.std b/tests/cxx/parser/validation/sequence/test-006.std new file mode 100644 index 0000000..d39b1b4 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-006.std @@ -0,0 +1,13 @@ +{ + c = c + d = d + any: test#any + { + chars = any + } + f = f + e = e + e = e + 14:7 unexpected element encountered +} + diff --git a/tests/cxx/parser/validation/sequence/test-006.xml b/tests/cxx/parser/validation/sequence/test-006.xml new file mode 100644 index 0000000..e1ecd69 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test-006.xml @@ -0,0 +1,17 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <!-- fail e maxOccurs="2" --> + <sequence> + <c>c</c> + <d>d</d> + <t:any>any</t:any> + <f>f</f> + <e>e</e> + <e>e</e> + <e>e</e> + </sequence> + +</t:root> diff --git a/tests/cxx/parser/validation/sequence/test.xsd b/tests/cxx/parser/validation/sequence/test.xsd new file mode 100644 index 0000000..8753f54 --- /dev/null +++ b/tests/cxx/parser/validation/sequence/test.xsd @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="sequence"> + <sequence minOccurs="1" maxOccurs="2"> + <element name="a" type="string" minOccurs="0"/> + <sequence> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string"/> + </sequence> + <element name="d" type="string" maxOccurs="unbounded"/> + <sequence> + <any namespace="##targetNamespace other"/> + <element name="f" type="string"/> + </sequence> + <element name="e" type="string" maxOccurs="2"/> + </sequence> + </complexType> + + <complexType name="type"> + <sequence> + <element name="sequence" type="t:sequence" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/serializer/all/driver.cxx b/tests/cxx/serializer/all/driver.cxx new file mode 100644 index 0000000..f781b94 --- /dev/null +++ b/tests/cxx/serializer/all/driver.cxx @@ -0,0 +1,108 @@ +// file : tests/cxx/serializer/all/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the all compositor serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: test_1_sskel +{ + virtual int + a () + { + return 123; + } + + virtual bool + b_present () + { + return true; + } + + virtual int + b () + { + return 234; + } +}; + +struct test_2_simpl: test_2_sskel +{ + test_2_simpl () + : i_ (0) + { + } + + virtual bool + all_present () + { + return i_++; + } + + virtual int + a () + { + return 123; + } + + virtual int + b () + { + return 234; + } + +private: + int i_; +}; + +struct root_simpl: root_sskel +{ + virtual void + pre () + { + n1_ = 0; + n2_ = 0; + } + + virtual bool + test_1_next () + { + return n1_++ < 1; + } + + virtual bool + test_2_next () + { + return n2_++ < 2; + } + +private: + int n1_, n2_; +}; + +int +main () +{ + xml_schema::int_simpl int_s; + test_1_simpl test_1_s; + test_2_simpl test_2_s; + root_simpl root_s; + + test_1_s.serializers (int_s, int_s); + test_2_s.serializers (int_s, int_s); + root_s.serializers (test_1_s, test_2_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/all/makefile b/tests/cxx/serializer/all/makefile new file mode 100644 index 0000000..d73444a --- /dev/null +++ b/tests/cxx/serializer/all/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/all/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/all/output b/tests/cxx/serializer/all/output new file mode 100644 index 0000000..ec04b95 --- /dev/null +++ b/tests/cxx/serializer/all/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><test-1><a>123</a><b>234</b></test-1><test-2></test-2><test-2><a>123</a><b>234</b></test-2></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/all/test.xsd b/tests/cxx/serializer/all/test.xsd new file mode 100644 index 0000000..7d369f5 --- /dev/null +++ b/tests/cxx/serializer/all/test.xsd @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <all> + <element name="a" type="int"/> + <element name="b" type="int" minOccurs="0"/> + </all> + </complexType> + + <complexType name="test-2"> + <all minOccurs="0"> + <element name="a" type="int"/> + <element name="b" type="int"/> + </all> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1" maxOccurs="unbounded"/> + <element name="test-2" type="t:test-2" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/built-in/driver.cxx b/tests/cxx/serializer/built-in/driver.cxx new file mode 100644 index 0000000..f1d17a1 --- /dev/null +++ b/tests/cxx/serializer/built-in/driver.cxx @@ -0,0 +1,1304 @@ +// file : tests/cxx/serializer/built-in/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test built-in type serialization. +// + +#include <stdlib.h> // strtof, strtod +#include <string.h> // memcpy +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct any_type_simpl: xml_schema::any_type_simpl +{ + virtual void + _serialize_attributes () + { + _attribute ("foo", "one"); + _attribute ("test", "foo", "two"); + } + + virtual void + _serialize_content () + { + _start_element ("test", "inner"); + _characters ("hello"); + _end_element (); + } +}; + +struct any_simple_type_simpl: xml_schema::any_simple_type_simpl +{ + virtual void + _serialize_content () + { + _characters ("hello"); + } +}; + +struct root_simpl: root_sskel +{ + virtual void + pre () + { + boolean_ = 0; + byte_ = 0; + unsigned_byte_ = 0; + short__ = 0; + unsigned_short_ = 0; + int__ = 0; + unsigned_int_ = 0; + long__ = 0; + unsigned_long_ = 0; + + integer_ = 0; + negative_integer_ = 0; + non_positive_integer_ = 0; + positive_integer_ = 0; + non_negative_integer_ = 0; + + float__ = 0; + double__ = 0; + decimal_ = 0; + + string_ = 0; + normalized_string_ = 0; + token_ = 0; + name_ = 0; + nmtoken_ = 0; + nmtokens_ = 0; + ncname_ = 0; + id_ = 0; + idref_ = 0; + idrefs_ = 0; + language_ = 0; + uri_ = 0; + qname_ = 0; + + base64_binary_ = 0; + hex_binary_ = 0; + + gday_ = 0; + gmonth_ = 0; + gyear_ = 0; + gmonth_day_ = 0; + gyear_month_ = 0; + date_ = 0; + time_ = 0; + date_time_ = 0; + duration_ = 0; + } + + virtual bool + boolean_next () + { + return boolean_ < 2; + } + + virtual bool + boolean () + { + static const bool v[] = {true, false}; + return v[boolean_++]; + } + + virtual bool + byte_next () + { + return byte_ < 4; + } + + virtual signed char + byte () + { + static const signed char v[] = {-128, -123, 0, 127}; + return v[byte_++]; + } + + virtual bool + unsigned_byte_next () + { + return unsigned_byte_ < 3; + } + + virtual unsigned char + unsigned_byte () + { + static const unsigned char v[] = {0, 123, 255}; + return v[unsigned_byte_++]; + } + + virtual bool + short__next () + { + return short__ < 4; + } + + virtual short + short_ () + { + static const short v[] = {-32768, -12345, 0, 32767}; + return v[short__++]; + } + + virtual bool + unsigned_short_next () + { + return unsigned_short_ < 3; + } + + virtual unsigned short + unsigned_short () + { + static const unsigned short v[] = {0, 12345, 65535}; + return v[unsigned_short_++]; + } + + virtual bool + int__next () + { + return int__ < 4; + } + + virtual int + int_ () + { + static const int v[] = {-2147483648, -1234567890, 0, 2147483647}; + return v[int__++]; + } + + virtual bool + unsigned_int_next () + { + return unsigned_int_ < 3; + } + + virtual unsigned int + unsigned_int () + { + static const unsigned int v[] = {0, 1234567890, 4294967295}; + return v[unsigned_int_++]; + } + + virtual bool + long__next () + { + return long__ < 4; + } + + virtual bool + unsigned_long_next () + { + return unsigned_long_ < 3; + } + +#ifdef XSDE_LONGLONG + virtual long long + long_ () + { + static const long long v[] = + { + -9223372036854775807LL, -1234567890123456789LL, + 0LL, 9223372036854775807LL + }; + + return long__ == 0 ? (v[long__++] - 1) : v[long__++]; + } + + virtual unsigned long long + unsigned_long () + { + static const unsigned long long v[] = + { + 0ULL, 12345678901234567890ULL, 18446744073709551615ULL + }; + + return v[unsigned_long_++]; + } +#else + virtual long + long_ () + { + static const long v[] = {-2147483647L, -1234567890L, 0L, 2147483647L}; + return long__ == 0 ? (v[long__++] - 1) : v[long__++]; + } + + virtual unsigned long + unsigned_long () + { + static const unsigned long v[] = {0UL, 1234567890UL, 4294967295UL}; + return v[unsigned_long_++]; + } +#endif + + // + // + virtual bool + integer_next () + { + return integer_ < 4; + } + + virtual long + integer () + { + static const long v[] = {-2147483647L, -1234567890L, 0L, 2147483647L}; + return integer_ == 0 ? (v[integer_++] - 1) : v[integer_++]; + } + + virtual bool + negative_integer_next () + { + return negative_integer_ < 2; + } + + virtual long + negative_integer () + { + static const long v[] = {-2147483647L, -1234567890L}; + return negative_integer_ == 0 + ? (v[negative_integer_++] - 1) + : v[negative_integer_++]; + } + + virtual bool + non_positive_integer_next () + { + return non_positive_integer_ < 3; + } + + virtual long + non_positive_integer () + { + static const long v[] = {-2147483647L, -1234567890L, 0L}; + return non_positive_integer_ == 0 + ? (v[non_positive_integer_++] - 1) + : v[non_positive_integer_++]; + } + + virtual bool + positive_integer_next () + { + return positive_integer_ < 2; + } + + virtual unsigned long + positive_integer () + { + static const unsigned long v[] = {1234567890UL, 4294967295UL}; + return v[positive_integer_++]; + } + + virtual bool + non_negative_integer_next () + { + return non_negative_integer_ < 3; + } + + virtual unsigned long + non_negative_integer () + { + static const unsigned long v[] = {0UL, 1234567890UL, 4294967295UL}; + return v[non_negative_integer_++]; + } + + // + // + virtual bool + float__next () + { + return float__ < 9; + } + + virtual float + float_ () + { + static const float v[] = {0.0, 0.0, 0.0, 0.0, 1.0, -1.0, + 123.567, -123.567e5, -0.45e-5}; + + switch (float__) + { + case 0: + { + float__++; + return strtof ("INF", 0); + } + case 1: + { + float__++; + return strtof ("-INF", 0); + } + case 2: + { + float__++; + return strtof ("NAN", 0); + } + default: + { + return v[float__++]; + } + } + } + + virtual bool + double__next () + { + return double__ < 9; + } + + virtual double + double_ () + { + static const double v[] = {0.0, 0.0, 0.0, 0.0, 1.0, -1.0, + 123.56789, -123.56789e8, -0.45E-5}; + + switch (double__) + { + case 0: + { + double__++; + return strtod ("INF", 0); + } + case 1: + { + double__++; + return strtod ("-INF", 0); + } + case 2: + { + double__++; + return strtod ("NAN", 0); + } + default: + { + return v[double__++]; + } + } + } + + virtual bool + decimal_next () + { + return decimal_ < 5; + } + + virtual double + decimal () + { + static const double v[] = {0.0, 1.0, -1.0, 123.56789, -123.56789}; + return v[decimal_++]; + } + + // + // + +#ifdef XSDE_STL + + virtual bool + string_next () + { + return string_++ < 1; + } + + virtual std::string + string () + { + return " test \n string "; + } + + virtual bool + normalized_string_next () + { + return normalized_string_++ < 1; + } + + virtual std::string + normalized_string () + { + return "test normalized string"; + } + + virtual bool + token_next () + { + return token_++ < 1; + } + + virtual std::string + token () + { + return "test token"; + } + + virtual bool + name_next () + { + return name_++ < 1; + } + + virtual std::string + name () + { + return "as123:345-.abs"; + } + + virtual bool + nmtoken_next () + { + return nmtoken_++ < 1; + } + + virtual std::string + nmtoken () + { + return "1as123:345-.abs"; + } + + virtual bool + nmtokens_next () + { + return nmtokens_ < 2; + } + + virtual xml_schema::string_sequence* + nmtokens () + { + using xml_schema::string_sequence; + + switch (nmtokens_++) + { + case 0: + { + string_sequence* r = new string_sequence; + r->push_back ("one"); + return r; + } + case 1: + { + string_sequence* r = new string_sequence; + r->push_back ("one"); + r->push_back ("two"); + r->push_back ("three"); + return r; + } + default: + return 0; + } + } + + virtual bool + ncname_next () + { + return ncname_++ < 1; + } + + virtual std::string + ncname () + { + return "as123_345-.abs"; + } + + virtual bool + id_next () + { + return id_ < 4; + } + + virtual std::string + id () + { + static const char* v[] = {"as123_345-.abs", "one", "two", "three"}; + return v[id_++]; + } + + virtual bool + idref_next () + { + return idref_++ < 1; + } + + virtual std::string + idref () + { + return "as123_345-.abs"; + } + + virtual bool + idrefs_next () + { + return idrefs_ < 2; + } + + virtual xml_schema::string_sequence* + idrefs () + { + using xml_schema::string_sequence; + + switch (idrefs_++) + { + case 0: + { + string_sequence* r = new string_sequence; + r->push_back ("one"); + return r; + } + case 1: + { + string_sequence* r = new string_sequence; + r->push_back ("two"); + r->push_back ("three"); + return r; + } + default: + return 0; + } + } + + virtual bool + language_next () + { + return language_++ < 1; + } + + virtual std::string + language () + { + return "en-us"; + } + + virtual bool + uri_next () + { + return uri_++ < 1; + } + + virtual std::string + uri () + { + return "http://www.example.com/foo#bar"; + } + + virtual bool + qname_next () + { + return qname_ < 2; + } + + virtual xml_schema::qname + qname () + { + using xml_schema::qname; + + switch (qname_++) + { + case 0: + { + qname r ("g1", "qname"); + return r; + } + case 1: + { + qname r ("qname"); + return r; + } + default: + return qname ("bad"); + } + } + +#else + + virtual bool + string_next () + { + return string_++ < 1; + } + + virtual const char* + string () + { + return " test \n string "; + } + + virtual bool + normalized_string_next () + { + return normalized_string_++ < 1; + } + + virtual const char* + normalized_string () + { + return "test normalized string"; + } + + virtual bool + token_next () + { + return token_++ < 1; + } + + virtual const char* + token () + { + return "test token"; + } + + virtual bool + name_next () + { + return name_++ < 1; + } + + virtual const char* + name () + { + return "as123:345-.abs"; + } + + virtual bool + nmtoken_next () + { + return nmtoken_++ < 1; + } + + virtual const char* + nmtoken () + { + return "1as123:345-.abs"; + } + + virtual bool + nmtokens_next () + { + return nmtokens_ < 2; + } + + virtual const xml_schema::string_sequence* + nmtokens () + { + using xml_schema::string_sequence; + + switch (nmtokens_++) + { + case 0: + { + string_sequence* r = new string_sequence (); + r->push_back_copy ("one"); + return r; + } + case 1: + { + string_sequence* r = new string_sequence (); + r->push_back_copy ("one"); + r->push_back_copy ("two"); + r->push_back_copy ("three"); + return r; + } + default: + return 0; + } + } + + virtual bool + ncname_next () + { + return ncname_++ < 1; + } + + virtual const char* + ncname () + { + return "as123_345-.abs"; + } + + virtual bool + id_next () + { + return id_ < 4; + } + + virtual const char* + id () + { + static const char* v[] = {"as123_345-.abs", "one", "two", "three"}; + return v[id_++]; + } + + virtual bool + idref_next () + { + return idref_++ < 1; + } + + virtual const char* + idref () + { + return "as123_345-.abs"; + } + + virtual bool + idrefs_next () + { + return idrefs_ < 2; + } + + virtual const xml_schema::string_sequence* + idrefs () + { + using xml_schema::string_sequence; + + switch (idrefs_++) + { + case 0: + { + string_sequence* r = new string_sequence (); + r->push_back_copy ("one"); + return r; + } + case 1: + { + string_sequence* r = new string_sequence (); + r->push_back_copy ("two"); + r->push_back_copy ("three"); + return r; + } + default: + return 0; + } + } + + virtual bool + language_next () + { + return language_++ < 1; + } + + virtual const char* + language () + { + return "en-us"; + } + + virtual bool + uri_next () + { + return uri_++ < 1; + } + + virtual const char* + uri () + { + return "http://www.example.com/foo#bar"; + } + + virtual bool + qname_next () + { + return qname_ < 2; + } + + virtual const xml_schema::qname* + qname () + { + using xml_schema::qname; + + switch (qname_++) + { + case 0: + { + qname* r = new qname (); + r->prefix_copy ("g1"); + r->name_copy ("qname"); + return r; + } + case 1: + { + qname* r = new qname (); + r->name_copy ("qname"); + return r; + } + default: + return 0; + } + } +#endif + + // + // + virtual bool + base64_binary_next () + { + return base64_binary_ < 6; + } + + virtual const xml_schema::buffer* + base64_binary () + { + xml_schema::buffer* r = new xml_schema::buffer (); + + switch (base64_binary_++) + { + case 0: + { + // Empty buffer. + // + break; + } + case 1: + { + const char data[] = "12345abcjk"; + const size_t size = sizeof (data) - 1; + r->size (size); + memcpy (r->data (), data, size); + break; + } + case 2: + { + const char data[] = "a"; + const size_t size = sizeof (data) - 1; + r->size (size); + memcpy (r->data (), data, size); + break; + } + case 3: + { + const char data[] = "ab"; + const size_t size = sizeof (data) -1; + r->size (size); + memcpy (r->data (), data, size); + break; + } + case 4: + { + const char data[] = "abc"; + const size_t size = sizeof (data) - 1; + r->size (size); + memcpy (r->data (), data, size); + break; + } + case 5: + { + const size_t size = 345; + + r->size (size); + unsigned char v = 0; + + for (size_t i = 0; i < size; ++i) + { + r->data ()[i] = static_cast<char> (v++); + } + + break; + } + } + + return r; + } + + virtual bool + hex_binary_next () + { + return hex_binary_ < 3; + } + + virtual const xml_schema::buffer* + hex_binary () + { + xml_schema::buffer* r = new xml_schema::buffer (); + + switch (hex_binary_++) + { + case 0: + { + // Empty buffer. + // + break; + } + case 1: + { + const char data[] = "12345abcjk"; + const size_t size = sizeof (data) - 1; + r->size (size); + memcpy (r->data (), data, size); + break; + } + case 2: + { + const size_t size = 345; + + r->size (size); + unsigned char v = 0; + + for (size_t i = 0; i < size; ++i) + { + r->data ()[i] = static_cast<char> (v++); + } + + break; + } + } + + return r; + } + + virtual bool + gday_next () + { + return gday_ < 3; + } + + virtual xml_schema::gday + gday () + { + using xml_schema::gday; + + switch (gday_++) + { + case 0: + return gday (23); + case 1: + return gday (31, 2, 30); + case 2: + return gday (15, 0, 0); + } + } + + virtual bool + gmonth_next () + { + return gmonth_ < 2; + } + + virtual ::xml_schema::gmonth + gmonth () + { + using xml_schema::gmonth; + + switch (gmonth_++) + { + case 0: + return gmonth (6); + case 1: + return gmonth (12, 2, 30); + } + } + + virtual bool + gyear_next () + { + return gyear_ < 2; + } + + virtual ::xml_schema::gyear + gyear () + { + using xml_schema::gyear; + + switch (gyear_++) + { + case 0: + return gyear (2007); + case 1: + return gyear (-2007, -2, -30); + } + } + + virtual bool + gmonth_day_next () + { + return gmonth_day_ < 2; + } + + virtual ::xml_schema::gmonth_day + gmonth_day () + { + using xml_schema::gmonth_day; + + switch (gmonth_day_++) + { + case 0: + return gmonth_day (6, 15); + case 1: + return gmonth_day (12, 31, 2, 30); + } + } + + virtual bool + gyear_month_next () + { + return gyear_month_ < 2; + } + + virtual ::xml_schema::gyear_month + gyear_month () + { + using xml_schema::gyear_month; + + switch (gyear_month_++) + { + case 0: + return gyear_month (2007, 10); + case 1: + return gyear_month (-2007, 12, -2, -30); + } + } + + virtual bool + date_next () + { + return date_ < 2; + } + + virtual ::xml_schema::date + date () + { + using xml_schema::date; + + switch (date_++) + { + case 0: + return date (2007, 6, 15); + case 1: + return date (-2007, 12, 31, -2, -30); + } + } + + virtual bool + time_next () + { + return time_ < 2; + } + + virtual ::xml_schema::time + time () + { + using xml_schema::time; + + switch (time_++) + { + case 0: + return time (12, 30, 30.0); + case 1: + return time (23, 59, 59.55, 2, 30); + } + } + + virtual bool + date_time_next () + { + return date_time_ < 2; + } + + virtual ::xml_schema::date_time + date_time () + { + using xml_schema::date_time; + + switch (date_time_++) + { + case 0: + return date_time (2007, 6, 15, 12, 30, 30.0); + case 1: + return date_time (-2007, 12, 31, 23, 59, 59.55, -2, -30); + } + } + + virtual bool + duration_next () + { + return duration_ < 7; + } + + virtual ::xml_schema::duration + duration () + { + using xml_schema::duration; + + switch (duration_++) + { + case 0: + return duration (false, 1, 0, 0, 0, 0, 0.0); + case 1: + return duration (true, 0, 1, 0, 0, 0, 0.0); + case 2: + return duration (false, 0, 0, 1, 0, 0, 0.0); + case 3: + return duration (true, 0, 0, 0, 1, 0, 0.0); + case 4: + return duration (false, 0, 0, 0, 0, 1, 0.0); + case 5: + return duration (true, 0, 0, 0, 0, 0, 1.1); + case 6: + return duration (false, 1, 2, 3, 4, 5, 6.7); + } + } + +private: + int boolean_; + int byte_; + int unsigned_byte_; + int short__; + int unsigned_short_; + int int__; + int unsigned_int_; + int long__; + int unsigned_long_; + + int integer_; + int negative_integer_; + int non_positive_integer_; + int positive_integer_; + int non_negative_integer_; + + int float__; + int double__; + int decimal_; + + int string_; + int normalized_string_; + int token_; + int name_; + int nmtoken_; + int nmtokens_; + int ncname_; + int id_; + int idref_; + int idrefs_; + int language_; + int uri_; + int qname_; + + int base64_binary_; + int hex_binary_; + + int gday_; + int gmonth_; + int gyear_; + int gmonth_day_; + int gyear_month_; + int date_; + int time_; + int date_time_; + int duration_; +}; + +int +main () +{ + any_type_simpl any_type_s; + any_simple_type_simpl any_simple_type_s; + + xml_schema::boolean_simpl boolean_s; + + xml_schema::byte_simpl byte_s; + xml_schema::unsigned_byte_simpl unsigned_byte_s; + xml_schema::short_simpl short_s; + xml_schema::unsigned_short_simpl unsigned_short_s; + xml_schema::int_simpl int_s; + xml_schema::unsigned_int_simpl unsigned_int_s; + xml_schema::long_simpl long_s; + xml_schema::unsigned_long_simpl unsigned_long_s; + + xml_schema::integer_simpl integer_s; + xml_schema::negative_integer_simpl negative_integer_s; + xml_schema::non_positive_integer_simpl non_sositive_integer_s; + xml_schema::positive_integer_simpl positive_integer_s; + xml_schema::non_negative_integer_simpl non_negative_integer_s; + + xml_schema::float_simpl float_s; + xml_schema::double_simpl double_s; + xml_schema::decimal_simpl decimal_s; + + xml_schema::string_simpl string_s; + xml_schema::normalized_string_simpl normalized_string_s; + xml_schema::token_simpl token_s; + xml_schema::name_simpl name_s; + xml_schema::nmtoken_simpl nmtoken_s; + xml_schema::ncname_simpl ncname_s; + xml_schema::id_simpl id_s; + xml_schema::idref_simpl idref_s; + + xml_schema::language_simpl language_s; + xml_schema::uri_simpl uri_s; + +#ifdef XSDE_STL + xml_schema::qname_simpl qname_s; +#else + xml_schema::qname_simpl qname_s (true); +#endif + + xml_schema::idrefs_simpl idrefs_s (true); + xml_schema::nmtokens_simpl nmtokens_s (true); + + xml_schema::base64_binary_simpl base64_binary_s (true); + xml_schema::hex_binary_simpl hex_binary_s (true); + + xml_schema::gday_simpl gday_s; + xml_schema::gmonth_simpl gmonth_s; + xml_schema::gyear_simpl gyear_s; + xml_schema::gmonth_day_simpl gmonth_day_s; + xml_schema::gyear_month_simpl gyear_month_s; + xml_schema::date_simpl date_s; + xml_schema::time_simpl time_s; + xml_schema::date_time_simpl date_time_s; + xml_schema::duration_simpl duration_s; + + root_simpl root_s; + + root_s.serializers (any_type_s, + any_simple_type_s, + boolean_s, + byte_s, + unsigned_byte_s, + short_s, + unsigned_short_s, + int_s, + unsigned_int_s, + long_s, + unsigned_long_s, + integer_s, + negative_integer_s, + non_sositive_integer_s, + positive_integer_s, + non_negative_integer_s, + float_s, + double_s, + decimal_s, + string_s, + normalized_string_s, + token_s, + name_s, + nmtoken_s, + nmtokens_s, + ncname_s, + id_s, + idref_s, + idrefs_s, + language_s, + uri_s, + qname_s, + base64_binary_s, + hex_binary_s, + gday_s, + gmonth_s, + gyear_s, + gmonth_day_s, + gyear_month_s, + date_s, + time_s, + date_time_s, + duration_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/built-in/makefile b/tests/cxx/serializer/built-in/makefile new file mode 100644 index 0000000..78a2055 --- /dev/null +++ b/tests/cxx/serializer/built-in/makefile @@ -0,0 +1,79 @@ +# file : tests/cxx/serializer/built-in/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) + +ifeq ($(xsde_longlong),y) +$(test): $(driver) $(src_base)/output-long-long + $(call message,test $$1,$$1 | diff -u $(src_base)/output-long-long -,$(driver)) +else +$(test): $(driver) $(src_base)/output-long + $(call message,test $$1,$$1 | diff -u $(src_base)/output-long -,$(driver)) +endif + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/built-in/output-long b/tests/cxx/serializer/built-in/output-long new file mode 100644 index 0000000..7333c2d --- /dev/null +++ b/tests/cxx/serializer/built-in/output-long @@ -0,0 +1,13 @@ +<g1:root xmlns:g1="test"><any-type foo="one" g1:foo="two"><g1:inner>hello</g1:inner></any-type><any-simple-type>hello</any-simple-type><boolean>true</boolean><boolean>false</boolean><byte>-128</byte><byte>-123</byte><byte>0</byte><byte>127</byte><unsigned-byte>0</unsigned-byte><unsigned-byte>123</unsigned-byte><unsigned-byte>255</unsigned-byte><short>-32768</short><short>-12345</short><short>0</short><short>32767</short><unsigned-short>0</unsigned-short><unsigned-short>12345</unsigned-short><unsigned-short>65535</unsigned-short><int>-2147483648</int><int>-1234567890</int><int>0</int><int>2147483647</int><unsigned-int>0</unsigned-int><unsigned-int>1234567890</unsigned-int><unsigned-int>4294967295</unsigned-int><long>-2147483648</long><long>-1234567890</long><long>0</long><long>2147483647</long><unsigned-long>0</unsigned-long><unsigned-long>1234567890</unsigned-long><unsigned-long>4294967295</unsigned-long><integer>-2147483648</integer><integer>-1234567890</integer><integer>0</integer><integer>2147483647</integer><negative-integer>-2147483648</negative-integer><negative-integer>-1234567890</negative-integer><non-positive-integer>-2147483648</non-positive-integer><non-positive-integer>-1234567890</non-positive-integer><non-positive-integer>0</non-positive-integer><positive-integer>1234567890</positive-integer><positive-integer>4294967295</positive-integer><non-negative-integer>0</non-negative-integer><non-negative-integer>1234567890</non-negative-integer><non-negative-integer>4294967295</non-negative-integer><float>INF</float><float>-INF</float><float>NaN</float><float>0</float><float>1</float><float>-1</float><float>123.567</float><float>-1.23567e+07</float><float>-4.5e-06</float><double>INF</double><double>-INF</double><double>NaN</double><double>0</double><double>1</double><double>-1</double><double>123.56789</double><double>-12356789000</double><double>-4.5e-06</double><decimal>0</decimal><decimal>1</decimal><decimal>-1</decimal><decimal>123.567890000000006</decimal><decimal>-123.567890000000006</decimal><string> test + string </string><normalized-string>test normalized string</normalized-string><token>test token</token><name>as123:345-.abs</name><nmtoken>1as123:345-.abs</nmtoken><nmtokens>one</nmtokens><nmtokens>one two three</nmtokens><ncname>as123_345-.abs</ncname><id>as123_345-.abs</id><id>one</id><id>two</id><id>three</id><idref>as123_345-.abs</idref><idrefs>one</idrefs><idrefs>two three</idrefs><language>en-us</language><uri>http://www.example.com/foo#bar</uri><qname>g1:qname</qname><qname>qname</qname><base64_binary></base64_binary><base64_binary>MTIzNDVhYmNqaw== +</base64_binary><base64_binary>YQ== +</base64_binary><base64_binary>YWI= +</base64_binary><base64_binary>YWJj +</base64_binary><base64_binary>AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4 +OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bx +cnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmq +q6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj +5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhsc +HR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RV +VldY +</base64_binary><hex_binary></hex_binary><hex_binary>31323334356162636A6B</hex_binary><hex_binary>000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758</hex_binary><gday>---23</gday><gday>---31+02:30</gday><gday>---15Z</gday><gmonth>--06</gmonth><gmonth>--12+02:30</gmonth><gyear>2007</gyear><gyear>-2007-02:30</gyear><gmonth_day>--06-15</gmonth_day><gmonth_day>--12-31+02:30</gmonth_day><gyear_month>2007-10</gyear_month><gyear_month>-2007-12-02:30</gyear_month><date>2007-06-15</date><date>-2007-12-31-02:30</date><time>12:30:30</time><time>23:59:59.55+02:30</time><date_time>2007-06-15T12:30:30</date_time><date_time>-2007-12-31T23:59:59.55-02:30</date_time><duration>P1Y</duration><duration>-P1M</duration><duration>P1D</duration><duration>-PT1H</duration><duration>PT1M</duration><duration>-PT1.1S</duration><duration>P1Y2M3DT4H5M6.7S</duration></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/built-in/output-long-long b/tests/cxx/serializer/built-in/output-long-long new file mode 100644 index 0000000..b0f36cc --- /dev/null +++ b/tests/cxx/serializer/built-in/output-long-long @@ -0,0 +1,13 @@ +<g1:root xmlns:g1="test"><any-type foo="one" g1:foo="two"><g1:inner>hello</g1:inner></any-type><any-simple-type>hello</any-simple-type><boolean>true</boolean><boolean>false</boolean><byte>-128</byte><byte>-123</byte><byte>0</byte><byte>127</byte><unsigned-byte>0</unsigned-byte><unsigned-byte>123</unsigned-byte><unsigned-byte>255</unsigned-byte><short>-32768</short><short>-12345</short><short>0</short><short>32767</short><unsigned-short>0</unsigned-short><unsigned-short>12345</unsigned-short><unsigned-short>65535</unsigned-short><int>-2147483648</int><int>-1234567890</int><int>0</int><int>2147483647</int><unsigned-int>0</unsigned-int><unsigned-int>1234567890</unsigned-int><unsigned-int>4294967295</unsigned-int><long>-9223372036854775808</long><long>-1234567890123456789</long><long>0</long><long>9223372036854775807</long><unsigned-long>0</unsigned-long><unsigned-long>12345678901234567890</unsigned-long><unsigned-long>18446744073709551615</unsigned-long><integer>-2147483648</integer><integer>-1234567890</integer><integer>0</integer><integer>2147483647</integer><negative-integer>-2147483648</negative-integer><negative-integer>-1234567890</negative-integer><non-positive-integer>-2147483648</non-positive-integer><non-positive-integer>-1234567890</non-positive-integer><non-positive-integer>0</non-positive-integer><positive-integer>1234567890</positive-integer><positive-integer>4294967295</positive-integer><non-negative-integer>0</non-negative-integer><non-negative-integer>1234567890</non-negative-integer><non-negative-integer>4294967295</non-negative-integer><float>INF</float><float>-INF</float><float>NaN</float><float>0</float><float>1</float><float>-1</float><float>123.567</float><float>-1.23567e+07</float><float>-4.5e-06</float><double>INF</double><double>-INF</double><double>NaN</double><double>0</double><double>1</double><double>-1</double><double>123.56789</double><double>-12356789000</double><double>-4.5e-06</double><decimal>0</decimal><decimal>1</decimal><decimal>-1</decimal><decimal>123.567890000000006</decimal><decimal>-123.567890000000006</decimal><string> test + string </string><normalized-string>test normalized string</normalized-string><token>test token</token><name>as123:345-.abs</name><nmtoken>1as123:345-.abs</nmtoken><nmtokens>one</nmtokens><nmtokens>one two three</nmtokens><ncname>as123_345-.abs</ncname><id>as123_345-.abs</id><id>one</id><id>two</id><id>three</id><idref>as123_345-.abs</idref><idrefs>one</idrefs><idrefs>two three</idrefs><language>en-us</language><uri>http://www.example.com/foo#bar</uri><qname>g1:qname</qname><qname>qname</qname><base64_binary></base64_binary><base64_binary>MTIzNDVhYmNqaw== +</base64_binary><base64_binary>YQ== +</base64_binary><base64_binary>YWI= +</base64_binary><base64_binary>YWJj +</base64_binary><base64_binary>AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4 +OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bx +cnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmq +q6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj +5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhsc +HR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RV +VldY +</base64_binary><hex_binary></hex_binary><hex_binary>31323334356162636A6B</hex_binary><hex_binary>000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758</hex_binary><gday>---23</gday><gday>---31+02:30</gday><gday>---15Z</gday><gmonth>--06</gmonth><gmonth>--12+02:30</gmonth><gyear>2007</gyear><gyear>-2007-02:30</gyear><gmonth_day>--06-15</gmonth_day><gmonth_day>--12-31+02:30</gmonth_day><gyear_month>2007-10</gyear_month><gyear_month>-2007-12-02:30</gyear_month><date>2007-06-15</date><date>-2007-12-31-02:30</date><time>12:30:30</time><time>23:59:59.55+02:30</time><date_time>2007-06-15T12:30:30</date_time><date_time>-2007-12-31T23:59:59.55-02:30</date_time><duration>P1Y</duration><duration>-P1M</duration><duration>P1D</duration><duration>-PT1H</duration><duration>PT1M</duration><duration>-PT1.1S</duration><duration>P1Y2M3DT4H5M6.7S</duration></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/built-in/test.xsd b/tests/cxx/serializer/built-in/test.xsd new file mode 100644 index 0000000..070e62d --- /dev/null +++ b/tests/cxx/serializer/built-in/test.xsd @@ -0,0 +1,64 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="root"> + <sequence> + <element name="any-type" type="anyType"/> + <element name="any-simple-type" type="anySimpleType"/> + + <element name="boolean" type="boolean" maxOccurs="unbounded"/> + <element name="byte" type="byte" maxOccurs="unbounded"/> + <element name="unsigned-byte" type="unsignedByte" maxOccurs="unbounded"/> + <element name="short" type="short" maxOccurs="unbounded"/> + <element name="unsigned-short" type="unsignedShort" maxOccurs="unbounded"/> + <element name="int" type="int" maxOccurs="unbounded"/> + <element name="unsigned-int" type="unsignedInt" maxOccurs="unbounded"/> + + <element name="long" type="long" maxOccurs="unbounded"/> + <element name="unsigned-long" type="unsignedLong" maxOccurs="unbounded"/> + + + <element name="integer" type="integer" maxOccurs="unbounded"/> + <element name="negative-integer" type="negativeInteger" maxOccurs="unbounded"/> + <element name="non-positive-integer" type="nonPositiveInteger" maxOccurs="unbounded"/> + <element name="positive-integer" type="positiveInteger" maxOccurs="unbounded"/> + <element name="non-negative-integer" type="nonNegativeInteger" maxOccurs="unbounded"/> + + <element name="float" type="float" maxOccurs="unbounded"/> + <element name="double" type="double" maxOccurs="unbounded"/> + <element name="decimal" type="decimal" maxOccurs="unbounded"/> + + <element name="string" type="string" maxOccurs="unbounded"/> + <element name="normalized-string" type="normalizedString" maxOccurs="unbounded"/> + <element name="token" type="token" maxOccurs="unbounded"/> + <element name="name" type="Name" maxOccurs="unbounded"/> + <element name="nmtoken" type="NMTOKEN" maxOccurs="unbounded"/> + <element name="nmtokens" type="NMTOKENS" maxOccurs="unbounded"/> + <element name="ncname" type="NCName" maxOccurs="unbounded"/> + <element name="id" type="ID" maxOccurs="unbounded"/> + <element name="idref" type="IDREF" maxOccurs="unbounded"/> + <element name="idrefs" type="IDREFS" maxOccurs="unbounded"/> + + <element name="language" type="language" maxOccurs="unbounded"/> + <element name="uri" type="anyURI" maxOccurs="unbounded"/> + <element name="qname" type="QName" maxOccurs="unbounded"/> + + <element name="base64_binary" type="base64Binary" maxOccurs="unbounded"/> + <element name="hex_binary" type="hexBinary" maxOccurs="unbounded"/> + + <element name="gday" type="gDay" maxOccurs="unbounded"/> + <element name="gmonth" type="gMonth" maxOccurs="unbounded"/> + <element name="gyear" type="gYear" maxOccurs="unbounded"/> + <element name="gmonth_day" type="gMonthDay" maxOccurs="unbounded"/> + <element name="gyear_month" type="gYearMonth" maxOccurs="unbounded"/> + <element name="date" type="date" maxOccurs="unbounded"/> + <element name="time" type="time" maxOccurs="unbounded"/> + <element name="date_time" type="dateTime" maxOccurs="unbounded"/> + <element name="duration" type="duration" maxOccurs="unbounded"/> + + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/choice/driver.cxx b/tests/cxx/serializer/choice/driver.cxx new file mode 100644 index 0000000..684f14d --- /dev/null +++ b/tests/cxx/serializer/choice/driver.cxx @@ -0,0 +1,253 @@ +// file : tests/cxx/serializer/choice/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the choice compositor serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: test_1_sskel +{ + test_1_simpl () + : i_ (0) + { + } + + virtual void + pre () + { + j_ = 0; + } + + virtual choice_arm_tag + choice_arm () + { + return static_cast<choice_arm_tag> (i_++); + } + + virtual int + a () + { + return 123; + } + + virtual bool + b_present () + { + return true; + } + + virtual int + b () + { + return 234; + } + + virtual bool + c_next () + { + return j_++ < 3; + } + + virtual int + c () + { + return j_; + } + +private: + int i_, j_; +}; + +struct test_2_simpl: test_2_sskel +{ + test_2_simpl () + : i_ (0) + { + } + + virtual bool + choice_present () + { + return i_++; + } + + virtual choice_arm_tag + choice_arm () + { + return b_tag; + } + + virtual int + a () + { + return 123; + } + + virtual int + b () + { + return 234; + } + +private: + int i_; +}; + +struct test_3_simpl: test_3_sskel +{ + virtual void + pre () + { + i_ = 0; + } + + virtual bool + choice_next () + { + return i_++ < 4; + } + + virtual choice_arm_tag + choice_arm () + { + return i_ % 2 ? a_tag : b_tag; + } + + virtual int + a () + { + return 123; + } + + virtual int + b () + { + return 234; + } + +private: + int i_; +}; + +struct test_4_simpl: test_4_sskel +{ + test_4_simpl () + : i_ (0) + { + } + + virtual choice_arm_tag + choice_arm () + { + return static_cast<choice_arm_tag> (i_++); + } + + virtual int + a () + { + return 123; + } + + virtual choice1_arm_tag + choice1_arm () + { + return c_tag; + } + + virtual int + b () + { + return 0; + } + + virtual int + c () + { + return 234; + } + + virtual int + d () + { + return 345; + } + + virtual int + e () + { + return 456; + } + +private: + int i_; +}; + +struct root_simpl: root_sskel +{ + virtual void + pre () + { + n1_ = 0; + n2_ = 0; + n3_ = 0; + n4_ = 0; + } + + virtual bool + test_1_next () + { + return n1_++ < 3; + } + + virtual bool + test_2_next () + { + return n2_++ < 2; + } + + virtual bool + test_3_next () + { + return n3_++ < 1; + } + + virtual bool + test_4_next () + { + return n4_++ < 3; + } + +private: + int n1_, n2_, n3_, n4_; +}; + +int +main () +{ + xml_schema::int_simpl int_s; + test_1_simpl test_1_s; + test_2_simpl test_2_s; + test_3_simpl test_3_s; + test_4_simpl test_4_s; + root_simpl root_s; + + test_1_s.serializers (int_s, int_s, int_s); + test_2_s.serializers (int_s, int_s); + test_3_s.serializers (int_s, int_s); + test_4_s.serializers (int_s, int_s, int_s, int_s, int_s); + root_s.serializers (test_1_s, test_2_s, test_3_s, test_4_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/choice/makefile b/tests/cxx/serializer/choice/makefile new file mode 100644 index 0000000..41df081 --- /dev/null +++ b/tests/cxx/serializer/choice/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/choice/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/choice/output b/tests/cxx/serializer/choice/output new file mode 100644 index 0000000..78a615a --- /dev/null +++ b/tests/cxx/serializer/choice/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><test-1><a>123</a></test-1><test-1><b>234</b></test-1><test-1><c>1</c><c>2</c><c>3</c></test-1><test-2></test-2><test-2><b>234</b></test-2><test-3><a>123</a><b>234</b><a>123</a><b>234</b></test-3><test-4><a>123</a></test-4><test-4><c>234</c></test-4><test-4><d>345</d><e>456</e></test-4></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/choice/test.xsd b/tests/cxx/serializer/choice/test.xsd new file mode 100644 index 0000000..2d7e33d --- /dev/null +++ b/tests/cxx/serializer/choice/test.xsd @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <choice> + <element name="a" type="int"/> + <element name="b" type="int" minOccurs="0"/> + <element name="c" type="int" maxOccurs="unbounded"/> + </choice> + </complexType> + + <complexType name="test-2"> + <choice minOccurs="0"> + <element name="a" type="int"/> + <element name="b" type="int"/> + </choice> + </complexType> + + <complexType name="test-3"> + <choice maxOccurs="unbounded"> + <element name="a" type="int"/> + <element name="b" type="int"/> + </choice> + </complexType> + + <complexType name="test-4"> + <choice> + <element name="a" type="int"/> + <choice> + <element name="b" type="int"/> + <element name="c" type="int"/> + </choice> + <sequence> + <element name="d" type="int"/> + <element name="e" type="int"/> + </sequence> + </choice> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1" maxOccurs="unbounded"/> + <element name="test-2" type="t:test-2" maxOccurs="unbounded"/> + <element name="test-3" type="t:test-3" maxOccurs="unbounded"/> + <element name="test-4" type="t:test-4" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/complex/driver.cxx b/tests/cxx/serializer/complex/driver.cxx new file mode 100644 index 0000000..d27aee1 --- /dev/null +++ b/tests/cxx/serializer/complex/driver.cxx @@ -0,0 +1,87 @@ +// file : tests/cxx/serializer/complex/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test complex types serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct base_simpl: virtual base_sskel +{ + virtual int + x () + { + return 123; + } + + virtual int + y () + { + return 234; + } + + virtual int + a () + { + return -123; + } + + virtual int + b () + { + return -234; + } +}; + +struct derived_simpl: derived_sskel +{ + derived_simpl () + : derived_sskel (&base_impl_) + { + } + + virtual int + z () + { + return 345; + } + + virtual int + c () + { + return -345; + } + +private: + base_simpl base_impl_; +}; + +struct root_simpl: virtual root_sskel +{ +}; + +int +main () +{ + xml_schema::int_simpl int_s; + base_simpl base_s; + derived_simpl derived_s; + root_simpl root_s; + + base_s.serializers (int_s, int_s, int_s, int_s); + derived_s.serializers (int_s, int_s, int_s, int_s, int_s, int_s); + root_s.serializers (base_s, derived_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/complex/makefile b/tests/cxx/serializer/complex/makefile new file mode 100644 index 0000000..75da9e3 --- /dev/null +++ b/tests/cxx/serializer/complex/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/complex/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/complex/output b/tests/cxx/serializer/complex/output new file mode 100644 index 0000000..82a19b6 --- /dev/null +++ b/tests/cxx/serializer/complex/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><base x="123" y="234"><a>-123</a><b>-234</b></base><derived x="123" y="234" z="345"><a>-123</a><b>-234</b><c>-345</c></derived></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/complex/test.xsd b/tests/cxx/serializer/complex/test.xsd new file mode 100644 index 0000000..c209b92 --- /dev/null +++ b/tests/cxx/serializer/complex/test.xsd @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="base"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="int"/> + </sequence> + <attribute name="x" type="int" use="required"/> + <attribute name="y" type="int" use="required"/> + </complexType> + + <complexType name="derived"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="c" type="int"/> + </sequence> + <attribute name="z" type="int" use="required"/> + </extension> + </complexContent> + </complexType> + + <complexType name="root"> + <sequence> + <element name="base" type="t:base"/> + <element name="derived" type="t:derived"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/enumeration/boolean.hxx b/tests/cxx/serializer/enumeration/boolean.hxx new file mode 100644 index 0000000..b648a56 --- /dev/null +++ b/tests/cxx/serializer/enumeration/boolean.hxx @@ -0,0 +1,15 @@ +// file : tests/cxx/serializer/enumeration/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef BOOLEAN_HXX +#define BOOLEAN_HXX + +enum boolean +{ + FALSE, + TRUE +}; + +#endif // BOOLEAN_HXX diff --git a/tests/cxx/serializer/enumeration/driver.cxx b/tests/cxx/serializer/enumeration/driver.cxx new file mode 100644 index 0000000..ae200ae --- /dev/null +++ b/tests/cxx/serializer/enumeration/driver.cxx @@ -0,0 +1,74 @@ +// file : tests/cxx/serializer/enumeration/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test enumeration type serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct digit_simpl: digit_sskel +{ + digit_simpl () + : digit_sskel (&base_impl_) + { + } + +private: + xml_schema::int_simpl base_impl_; +}; + +struct boolean_simpl: boolean_sskel +{ + boolean_simpl () + : boolean_sskel (&base_impl_) + { + } + + virtual void + pre (boolean b) + { + int i = b; + base_impl_.pre (i); + } + +private: + xml_schema::int_simpl base_impl_; +}; + +struct root_simpl: root_sskel +{ + virtual int + digit () + { + return 7; + } + + virtual ::boolean + boolean () + { + return TRUE; + } +}; + +int +main () +{ + digit_simpl digit_s; + boolean_simpl boolean_s; + root_simpl root_s; + + root_s.serializers (digit_s, boolean_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/enumeration/makefile b/tests/cxx/serializer/enumeration/makefile new file mode 100644 index 0000000..2ccb073 --- /dev/null +++ b/tests/cxx/serializer/enumeration/makefile @@ -0,0 +1,75 @@ +# file : tests/cxx/serializer/enumeration/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): cpp_options := -I$(out_base) -I$(src_base) +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): xsde_options += --type-map $(src_base)/test.map + +$(skel): $(out_root)/xsde/xsde $(src_base)/test.map + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/enumeration/output b/tests/cxx/serializer/enumeration/output new file mode 100644 index 0000000..4907042 --- /dev/null +++ b/tests/cxx/serializer/enumeration/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><digit>7</digit><boolean>1</boolean></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/enumeration/test.map b/tests/cxx/serializer/enumeration/test.map new file mode 100644 index 0000000..73f5d25 --- /dev/null +++ b/tests/cxx/serializer/enumeration/test.map @@ -0,0 +1,7 @@ +namespace test +{ + include "boolean.hxx"; + + digit int int; + boolean ::boolean ::boolean; +} diff --git a/tests/cxx/serializer/enumeration/test.xsd b/tests/cxx/serializer/enumeration/test.xsd new file mode 100644 index 0000000..c130f75 --- /dev/null +++ b/tests/cxx/serializer/enumeration/test.xsd @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="digit"> + <restriction base="int"> + <enumeration value="0"/> + <enumeration value="1"/> + <enumeration value="2"/> + <enumeration value="3"/> + <enumeration value="4"/> + <enumeration value="5"/> + <enumeration value="6"/> + <enumeration value="7"/> + <enumeration value="8"/> + <enumeration value="9"/> + </restriction> + </simpleType> + + <simpleType name="boolean"> + <restriction base="int"> + <enumeration value="0"/> + <enumeration value="1"/> + </restriction> + </simpleType> + + <complexType name="root"> + <sequence> + <element name="digit" type="t:digit"/> + <element name="boolean" type="t:boolean"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/error-handling/codes/driver.cxx b/tests/cxx/serializer/error-handling/codes/driver.cxx new file mode 100644 index 0000000..ba1f6cd --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/driver.cxx @@ -0,0 +1,327 @@ +// file : tests/cxx/serializer/error-handling/codes/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test error reporting with error codes. +// + +#include <cassert> +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +// bool fail = true; + +struct test_simpl: virtual test_sskel +{ + test_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 6) + _app_error (case_); + + n_ = 0; + } + + virtual void + _pre () + { + if (case_ == 7) + _app_error (case_); + + if (case_ == 19) + _end_element (); + } + + // Attributes. + // + virtual bool + x_present () + { + if (case_ == 8) + { + _app_error (case_); + return false; + } + + return true; + } + + virtual int + x () + { + if (case_ == 9) + _app_error (case_); + + return -1; + } + + virtual int + y () + { + if (case_ == 10) + _app_error (case_); + + return -2; + } + + // Elements. + // + virtual int + a () + { + if (case_ == 11) + _app_error (case_); + + return 1; + } + + virtual bool + b_present () + { + if (case_ == 12) + { + _app_error (case_); + return false; + } + + return true; + } + + virtual int + b () + { + if (case_ == 13) + _app_error (case_); + + return 2; + } + + virtual bool + c_next () + { + if (case_ == 14) + { + _app_error (case_); + return false; + } + + return n_++ < 3; + } + + virtual int + c () + { + if (case_ == 15) + _app_error (case_); + + return 2 + n_; + } + + virtual void + _post () + { + if (case_ == 16) + _app_error (case_); + } + + virtual void + post () + { + if (case_ == 17) + _app_error (case_); + } + +private: + int case_; + int n_; +}; + +struct root_simpl: root_sskel +{ + root_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 1) + _app_error (case_); + } + + virtual void + _pre () + { + if (case_ == 2) + _app_error (case_); + } + + virtual void + test () + { + if (case_ == 3) + _app_error (case_); + } + + virtual void + _post () + { + if (case_ == 4) + _app_error (case_); + } + + virtual void + post () + { + if (case_ == 5) + _app_error (case_); + } + +private: + int case_; +}; + +struct writer: xml_schema::writer +{ + virtual bool + write (const char*, size_t) + { + return false; + } + + virtual bool + flush () + { + return false; + } +}; + + +void +print (xml_schema::serializer_error e) +{ + typedef xml_schema::serializer_error error; + + switch (e.type ()) + { + case error::sys: + { + cout << "sys: " << e.sys_code () << ": " << e.sys_text () << endl; + break; + } + case error::xml: + { + cout << "xml: " << e.xml_code () << ": " << e.xml_text () << endl; + break; + } +#ifdef XSDE_SERIALIZER_VALIDATION + case error::schema: + { + cout << "schema: " << e.schema_code () << ": " << e.schema_text () + << endl; + break; + } +#endif + case error::app: + { + cout << "app: " << e.app_code () << endl; + break; + } + default: + { + cout << "no error" << endl; + } + } +} + +int +main () +{ + typedef xml_schema::serializer_error error; + + /* + string output ("<g1:root xmlns:g1=\"test\"><test x=\"-1\" y=\"-2\">" + "<a>1</a><b>2</b><c>3</c><c>4</c><c>5</c></test></g1:root>"); + */ + + // 1-5 : app errors in the root element serializer + // 6-17: app errors in the sub element serializer + // 18 : xml error in document serializer + // 19 : xml error in sub element serializer + // 20 : sys error + // + for (int i (1); i <= 20; ++i) + { + xml_schema::int_simpl int_s; + test_simpl test_s (i); + root_simpl root_s (i); + + test_s.serializers (int_s, int_s, int_s, int_s, int_s); + root_s.serializers (test_s); + + xml_schema::document_simpl doc_s ( + root_s, + "test", + (i == 18 ? "bad name" : "root")); + + root_s.pre (); + + if (error e = root_s._error ()) + print (e); + else + { + ostringstream os; + + if (i == 20) + { + writer w; + doc_s.serialize (w); + } + else + doc_s.serialize (os); + + if (error e = doc_s._error ()) + print (e); + else + { + root_s.post (); + + if (error e = root_s._error ()) + print (e); + } + } + + /* + { + fail = false; + + ostringstream os; + + root_s.pre (); + assert (!root_s.error ()); + + doc_s.serialize (os); + assert (!doc_s._error ()); + + root_s.post (); + assert (!root_s.error ()); + + assert (os.str () == output); + + fail = true; + } + */ + } +} diff --git a/tests/cxx/serializer/error-handling/codes/makefile b/tests/cxx/serializer/error-handling/codes/makefile new file mode 100644 index 0000000..bdaca6c --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/error-handling/codes/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/error-handling/codes/output b/tests/cxx/serializer/error-handling/codes/output new file mode 100644 index 0000000..c01aab9 --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/output @@ -0,0 +1,20 @@ +app: 1 +app: 2 +app: 3 +app: 4 +app: 5 +app: 6 +app: 7 +app: 8 +app: 9 +app: 10 +app: 11 +app: 12 +app: 13 +app: 14 +app: 15 +app: 16 +app: 17 +xml: 3: illegal name +xml: 8: call out of sequence +sys: 4: write failed diff --git a/tests/cxx/serializer/error-handling/codes/test.xsd b/tests/cxx/serializer/error-handling/codes/test.xsd new file mode 100644 index 0000000..530118c --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/test.xsd @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="int" minOccurs="0"/> + <element name="c" type="int" maxOccurs="unbounded"/> + </sequence> + <attribute name="x" type="int"/> + <attribute name="y" type="int" use="required"/> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test" type="t:test"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/error-handling/exceptions/driver.cxx b/tests/cxx/serializer/error-handling/exceptions/driver.cxx new file mode 100644 index 0000000..3a7437b --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/driver.cxx @@ -0,0 +1,285 @@ +// file : tests/cxx/serializer/error-handling/exceptions/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test error reporting with exceptions. +// + +#include <cassert> +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct app +{ + app (int code) + : code_ (code) + { + } + + int + code () const + { + return code_; + } + +private: + int code_; +}; + +struct test_simpl: virtual test_sskel +{ + test_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 6) + throw app (case_); + + n_ = 0; + } + + virtual void + _pre () + { + if (case_ == 7) + throw app (case_); + + if (case_ == 19) + _end_element (); + } + + // Attributes. + // + virtual bool + x_present () + { + if (case_ == 8) + { + throw app (case_); + return false; + } + + return true; + } + + virtual int + x () + { + if (case_ == 9) + throw app (case_); + + return -1; + } + + virtual int + y () + { + if (case_ == 10) + throw app (case_); + + return -2; + } + + // Elements. + // + virtual int + a () + { + if (case_ == 11) + throw app (case_); + + return 1; + } + + virtual bool + b_present () + { + if (case_ == 12) + { + throw app (case_); + return false; + } + + return true; + } + + virtual int + b () + { + if (case_ == 13) + throw app (case_); + + return 2; + } + + virtual bool + c_next () + { + if (case_ == 14) + { + throw app (case_); + return false; + } + + return n_++ < 3; + } + + virtual int + c () + { + if (case_ == 15) + throw app (case_); + + return 2 + n_; + } + + virtual void + _post () + { + if (case_ == 16) + throw app (case_); + } + + virtual void + post () + { + if (case_ == 17) + throw app (case_); + } + +private: + int case_; + int n_; +}; + +struct root_simpl: root_sskel +{ + root_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 1) + throw app (case_); + } + + virtual void + _pre () + { + if (case_ == 2) + throw app (case_); + } + + virtual void + test () + { + if (case_ == 3) + throw app (case_); + } + + virtual void + _post () + { + if (case_ == 4) + throw app (case_); + } + + virtual void + post () + { + if (case_ == 5) + throw app (case_); + } + +private: + int case_; +}; + +struct writer: xml_schema::writer +{ + virtual void + write (const char*, size_t) + { + throw ios_base::failure ("write failed"); + } + + virtual void + flush () + { + throw ios_base::failure ("write failed"); + } +}; + +int +main () +{ + + // 1-5 : app errors in the root element serializer + // 6-17: app errors in the sub element serializer + // 18 : xml error in document serializer + // 19 : xml error in sub element serializer + // 20 : sys error + // + for (int i (1); i <= 20; ++i) + { + try + { + xml_schema::int_simpl int_s; + test_simpl test_s (i); + root_simpl root_s (i); + + test_s.serializers (int_s, int_s, int_s, int_s, int_s); + root_s.serializers (test_s); + + xml_schema::document_simpl doc_s ( + root_s, + "test", + (i == 18 ? "bad name" : "root")); + + root_s.pre (); + + ostringstream os; + + if (i == 20) + { + writer w; + doc_s.serialize (w); + } + else + doc_s.serialize (os); + + root_s.post (); + } + catch (ios_base::failure const&) + { + cout << "sys: write failed" << endl; + } + catch (xml_schema::serializer_xml const& e) + { + cout << "xml: " << e.text () << endl; + } +#ifdef XSDE_SERIALIZER_VALIDATION + catch (xml_schema::serializer_schema const& e) + { + cout << "schema: " << e.text () << endl; + } +#endif + catch (app const& e) + { + cout << "app: " << e.code () << endl; + } + } +} diff --git a/tests/cxx/serializer/error-handling/exceptions/makefile b/tests/cxx/serializer/error-handling/exceptions/makefile new file mode 100644 index 0000000..19027cc --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/error-handling/exceptions/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/error-handling/exceptions/output b/tests/cxx/serializer/error-handling/exceptions/output new file mode 100644 index 0000000..e640bd6 --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/output @@ -0,0 +1,20 @@ +app: 1 +app: 2 +app: 3 +app: 4 +app: 5 +app: 6 +app: 7 +app: 8 +app: 9 +app: 10 +app: 11 +app: 12 +app: 13 +app: 14 +app: 15 +app: 16 +app: 17 +xml: illegal name +xml: call out of sequence +sys: write failed diff --git a/tests/cxx/serializer/error-handling/exceptions/test.xsd b/tests/cxx/serializer/error-handling/exceptions/test.xsd new file mode 100644 index 0000000..530118c --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/test.xsd @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="int" minOccurs="0"/> + <element name="c" type="int" maxOccurs="unbounded"/> + </sequence> + <attribute name="x" type="int"/> + <attribute name="y" type="int" use="required"/> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test" type="t:test"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/error-handling/makefile b/tests/cxx/serializer/error-handling/makefile new file mode 100644 index 0000000..03597f5 --- /dev/null +++ b/tests/cxx/serializer/error-handling/makefile @@ -0,0 +1,24 @@ +# file : tests/cxx/serializer/error-handling/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +ifeq ($(xsde_exceptions),y) +tests := exceptions +else +tests := codes +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/serializer/generated-driver/makefile b/tests/cxx/serializer/generated-driver/makefile new file mode 100644 index 0000000..08957fa --- /dev/null +++ b/tests/cxx/serializer/generated-driver/makefile @@ -0,0 +1,75 @@ +# file : tests/cxx/serializer/generated-driver/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd + +obj := $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.o) $(xsd:.xsd=-simpl.o) $(xsd:.xsd=-sdriver.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/$(xsd:.xsd=-sdriver) +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) \ + $(out_base)/$(xsd:.xsd=-sdriver.cxx) + +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-test-driver --force-overwrite +$(gen): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +xsd_simpl_suffix := -simpl +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/generated-driver/output b/tests/cxx/serializer/generated-driver/output new file mode 100644 index 0000000..d544e67 --- /dev/null +++ b/tests/cxx/serializer/generated-driver/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><value>123</value></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/generated-driver/test-simpl.cxx b/tests/cxx/serializer/generated-driver/test-simpl.cxx new file mode 100644 index 0000000..7acda2c --- /dev/null +++ b/tests/cxx/serializer/generated-driver/test-simpl.cxx @@ -0,0 +1,28 @@ +// file : tests/cxx/serializer/generated-driver/test-simpl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include "test-simpl.hxx" + +namespace test +{ + // type_simpl + // + + void type_simpl:: + pre () + { + } + + int type_simpl:: + value () + { + return 123; + } + + void type_simpl:: + post () + { + } +} diff --git a/tests/cxx/serializer/generated-driver/test-simpl.hxx b/tests/cxx/serializer/generated-driver/test-simpl.hxx new file mode 100644 index 0000000..4700a9f --- /dev/null +++ b/tests/cxx/serializer/generated-driver/test-simpl.hxx @@ -0,0 +1,27 @@ +// file : tests/cxx/serializer/generated-driver/test-simpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef TEST_SIMPL_HXX +#define TEST_SIMPL_HXX + +#include "test-sskel.hxx" + +namespace test +{ + class type_simpl: public virtual type_sskel + { + public: + virtual void + pre (); + + virtual int + value (); + + virtual void + post (); + }; +} + +#endif // TEST_SIMPL_HXX diff --git a/tests/cxx/serializer/generated-driver/test.xsd b/tests/cxx/serializer/generated-driver/test.xsd new file mode 100644 index 0000000..7ceb607 --- /dev/null +++ b/tests/cxx/serializer/generated-driver/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="value" type="int"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/serializer/generated-impl/makefile b/tests/cxx/serializer/generated-impl/makefile new file mode 100644 index 0000000..fc6c6b9 --- /dev/null +++ b/tests/cxx/serializer/generated-impl/makefile @@ -0,0 +1,84 @@ +# file : tests/cxx/serializer/generated-impl/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +# Note that this test only checks compilation of the generated empty +# implementation and test driver. It may not work with some compilers +# (missing return statements). +# + +xsd := test.xsd + +obj := $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.o) $(xsd:.xsd=-simpl.o) $(xsd:.xsd=-sdriver.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/$(xsd:.xsd=-sdriver) +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +gen := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) \ + $(out_base)/$(xsd:.xsd=-simpl.hxx) \ + $(out_base)/$(xsd:.xsd=-simpl.cxx) \ + $(out_base)/$(xsd:.xsd=-sdriver.cxx) + +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-empty-impl --generate-test-driver \ +--force-overwrite +$(gen): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,:,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-simpl.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +xsd_simpl_suffix := -simpl +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/generated-impl/test.xsd b/tests/cxx/serializer/generated-impl/test.xsd new file mode 100644 index 0000000..f38c005 --- /dev/null +++ b/tests/cxx/serializer/generated-impl/test.xsd @@ -0,0 +1,193 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- enum --> + + <simpleType name="gender"> + <restriction base="string"> + <enumeration value="male"/> + <enumeration value="female"/> + </restriction> + </simpleType> + + <complexType name="gender-extension"> + <simpleContent> + <extension base="t:gender"> + <attribute name="foo" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- list --> + + <simpleType name="list"> + <list itemType="int"/> + </simpleType> + + <complexType name="list-extension"> + <simpleContent> + <extension base="t:list"> + <attribute name="foo" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- union --> + + <simpleType name="union"> + <union memberTypes="int string"/> + </simpleType> + + <complexType name="union-extension"> + <simpleContent> + <extension base="t:union"> + <attribute name="foo" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- complex --> + + <complexType name="complex"> + <sequence> + <element name="a" type="string"/> + </sequence> + <attribute name="x" type="string" use="required"/> + </complexType> + + <complexType name="complex-extension"> + <complexContent> + <extension base="t:complex"> + <sequence> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string" maxOccurs="unbounded"/> + </sequence> + <attribute name="y" type="string"/> + </extension> + </complexContent> + </complexType> + + <complexType name="complex-opt-all"> + <all minOccurs="0"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </all> + </complexType> + + <complexType name="complex-opt-seq"> + <sequence minOccurs="0"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </sequence> + </complexType> + + <complexType name="complex-seq-seq"> + <sequence maxOccurs="unbounded"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </sequence> + </complexType> + + <complexType name="complex-opt-choice"> + <choice minOccurs="0"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </choice> + </complexType> + + <complexType name="complex-seq-choice"> + <choice maxOccurs="unbounded"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </choice> + </complexType> + + <complexType name="complex-any"> + <sequence> + <any namespace="foo" processContents="skip" minOccurs="0"/> + <any namespace="bar" processContents="skip" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="foo" processContents="skip"/> + </complexType> + + <complexType name="type"> + <sequence> + <element name="gender" type="t:gender"/> + <element name="gender-extension" type="t:gender-extension"/> + + <element name="list" type="t:list"/> + <element name="list-extension" type="t:list-extension"/> + + <element name="union" type="t:union"/> + <element name="union-extension" type="t:union-extension"/> + + <element name="complex" type="t:complex"/> + <element name="complex-extension" type="t:complex-extension"/> + + <element name="complex-opt-all" type="t:complex-opt-all"/> + <element name="complex-opt-seq" type="t:complex-opt-seq"/> + <element name="complex-seq-seq" type="t:complex-seq-seq"/> + <element name="complex-opt-choice" type="t:complex-opt-choice"/> + <element name="complex-seq-choice" type="t:complex-seq-choice"/> + <element name="complex-any" type="t:complex-any"/> + + <!-- Built-in types. --> + + <element name="any-type" type="anyType" maxOccurs="unbounded"/> + <element name="any-simple-type" type="anySimpleType" maxOccurs="unbounded"/> + + <element name="boolean" type="boolean" maxOccurs="unbounded"/> + + <element name="byte" type="byte" maxOccurs="unbounded"/> + <element name="unsigned-byte" type="unsignedByte" maxOccurs="unbounded"/> + <element name="short" type="short" maxOccurs="unbounded"/> + <element name="unsigned-short" type="unsignedShort" maxOccurs="unbounded"/> + <element name="int" type="int" maxOccurs="unbounded"/> + <element name="unsigned-int" type="unsignedInt" maxOccurs="unbounded"/> + <element name="long" type="long" maxOccurs="unbounded"/> + <element name="unsigned-long" type="unsignedLong" maxOccurs="unbounded"/> + + <element name="integer" type="integer" maxOccurs="unbounded"/> + <element name="negative-integer" type="negativeInteger" maxOccurs="unbounded"/> + <element name="non-positive-integer" type="nonPositiveInteger" maxOccurs="unbounded"/> + <element name="positive-integer" type="positiveInteger" maxOccurs="unbounded"/> + <element name="non-negative-integer" type="nonNegativeInteger" maxOccurs="unbounded"/> + + <element name="float" type="float" maxOccurs="unbounded"/> + <element name="double" type="double" maxOccurs="unbounded"/> + <element name="decimal" type="decimal" maxOccurs="unbounded"/> + + <element name="string" type="string" maxOccurs="unbounded"/> + <element name="normalized-string" type="normalizedString" maxOccurs="unbounded"/> + <element name="token" type="token" maxOccurs="unbounded"/> + <element name="name" type="Name" maxOccurs="unbounded"/> + <element name="nmtoken" type="NMTOKEN" maxOccurs="unbounded"/> + <element name="nmtokens" type="NMTOKENS" maxOccurs="unbounded"/> + <element name="ncname" type="NCName" maxOccurs="unbounded"/> + <element name="id" type="ID" maxOccurs="unbounded"/> + <element name="idref" type="IDREF" maxOccurs="unbounded"/> + <element name="idrefs" type="IDREFS" maxOccurs="unbounded"/> + + <element name="language" type="language" maxOccurs="unbounded"/> + <element name="uri" type="anyURI" maxOccurs="unbounded"/> + <element name="qname" type="QName" maxOccurs="unbounded"/> + + <element name="base64_binary" type="base64Binary" maxOccurs="unbounded"/> + <element name="hex_binary" type="hexBinary" maxOccurs="unbounded"/> + + <element name="gday" type="gDay" maxOccurs="unbounded"/> + <element name="gmonth" type="gMonth" maxOccurs="unbounded"/> + <element name="gyear" type="gYear" maxOccurs="unbounded"/> + <element name="gmonth_day" type="gMonthDay" maxOccurs="unbounded"/> + <element name="gyear_month" type="gYearMonth" maxOccurs="unbounded"/> + <element name="date" type="date" maxOccurs="unbounded"/> + <element name="time" type="time" maxOccurs="unbounded"/> + <element name="date_time" type="dateTime" maxOccurs="unbounded"/> + <element name="duration" type="duration" maxOccurs="unbounded"/> + + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/serializer/list/driver.cxx b/tests/cxx/serializer/list/driver.cxx new file mode 100644 index 0000000..7ed5ee1 --- /dev/null +++ b/tests/cxx/serializer/list/driver.cxx @@ -0,0 +1,114 @@ +// file : tests/cxx/serializer/list/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test list type serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct int_list_simpl: int_list_sskel +{ + int_list_simpl () + : n_ (0) + { + } + + virtual void + pre () + { + i_ = 0; + n_++; + } + + virtual bool + item_next () + { + switch (n_) + { + case 1: + return false; + case 2: + return i_++ < 1; + case 3: + return i_++ < 3; + default: + return false; + } + } + + virtual int + item () + { + return i_; + } + +private: + int n_, i_; +}; + +struct int_list_base_simpl: int_list_base_sskel +{ + int_list_base_simpl () + : int_list_base_sskel (&base_impl_) + { + } + + virtual int + base () + { + return 123; + } + +private: + int_list_simpl base_impl_; +}; + +struct root_simpl: root_sskel +{ + virtual void + pre () + { + n_ = 0; + } + + virtual bool + int_list_next () + { + return n_++ < 3; + } + + virtual bool + int_list_base_next () + { + return n_++ < 7; + } + +private: + int n_; +}; + +int +main () +{ + xml_schema::int_simpl int_s; + int_list_simpl int_list_s; + int_list_base_simpl int_list_base_s; + root_simpl root_s; + + int_list_s.serializers (int_s); + int_list_base_s.serializers (int_s, int_s); + root_s.serializers (int_list_s, int_list_base_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/list/makefile b/tests/cxx/serializer/list/makefile new file mode 100644 index 0000000..6d5a876 --- /dev/null +++ b/tests/cxx/serializer/list/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/list/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/list/output b/tests/cxx/serializer/list/output new file mode 100644 index 0000000..c1ef004 --- /dev/null +++ b/tests/cxx/serializer/list/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><int-list></int-list><int-list>1</int-list><int-list>1 2 3</int-list><int-list-base base="123"></int-list-base><int-list-base base="123">1</int-list-base><int-list-base base="123">1 2 3</int-list-base></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/list/test.xsd b/tests/cxx/serializer/list/test.xsd new file mode 100644 index 0000000..d4aff01 --- /dev/null +++ b/tests/cxx/serializer/list/test.xsd @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="int-list"> + <list itemType="int"/> + </simpleType> + + <complexType name="int-list-base"> + <simpleContent> + <extension base="t:int-list"> + <attribute name="base" type="int" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="root"> + <sequence> + <element name="int-list" type="t:int-list" maxOccurs="unbounded"/> + <element name="int-list-base" type="t:int-list-base" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/makefile b/tests/cxx/serializer/makefile new file mode 100644 index 0000000..8d72167 --- /dev/null +++ b/tests/cxx/serializer/makefile @@ -0,0 +1,52 @@ +# file : tests/cxx/serializer/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +tests := generated-driver generated-impl + +ifeq ($(xsde_iostream),y) + +tests += \ +all \ +built-in \ +choice \ +error-handling \ +recursive \ +reset \ +restriction \ +sequence \ +test-template \ +wildcard + +ifeq ($(xsde_reuse_style),tiein) +tests += \ +complex \ +enumeration \ +list \ +union +endif + +ifeq ($(xsde_polymorphic),y) +tests += polymorphism +endif + +endif # xsde_iostream + +ifeq ($(xsde_serializer_validation),y) +tests += validation +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/serializer/polymorphism/driver.cxx b/tests/cxx/serializer/polymorphism/driver.cxx new file mode 100644 index 0000000..ebb0244 --- /dev/null +++ b/tests/cxx/serializer/polymorphism/driver.cxx @@ -0,0 +1,203 @@ +// file : tests/cxx/serializer/polymorphism/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test substitution groups and xsi:type support. +// +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct base_simpl: base_sskel +{ + virtual int + a () + { + return 1; + } +}; + +struct interm_type_simpl: interm_type_sskel +{ + interm_type_simpl () + : interm_type_sskel (&base_impl_) + { + } + + virtual int + b () + { + return 2; + } + + base_simpl base_impl_; +}; + +struct interm_simpl: interm_sskel +{ + interm_simpl () + : interm_sskel (&base_impl_) + { + } + + virtual int + b () + { + return 2; + } + + base_simpl base_impl_; +}; + +struct derived_type_simpl: derived_type_sskel +{ + derived_type_simpl () + : derived_type_sskel (&base_impl_) + { + } + + virtual int + c () + { + return 3; + } + + interm_type_simpl base_impl_; +}; + +struct derived_simpl: derived_sskel +{ + derived_simpl () + : derived_sskel (&base_impl_) + { + } + + virtual int + c () + { + return 3; + } + + interm_simpl base_impl_; +}; + +struct type_simpl: type_sskel +{ + virtual void + pre () + { + i_ = 0; + } + + virtual bool + base_next () + { + return i_ < 5; + } + + virtual void + base () + { + xml_schema::serializer_context& ctx = _context (); + + switch (i_++) + { + case 0: + { + ctx.type_id (base_sskel::_static_type ()); + break; + } + case 1: + { + ctx.type_id (interm_type_sskel::_static_type ()); + break; + } + case 2: + { + ctx.type_id (interm_sskel::_static_type ()); + break; + } + case 3: + { + ctx.type_id (derived_type_sskel::_static_type ()); + break; + } + case 4: + { + ctx.type_id (derived_sskel::_static_type ()); + break; + } + } + } + +private: + int i_; +}; + +int +main () +{ +#ifdef XSDE_EXCEPTIONS + try + { +#endif + xml_schema::int_simpl int_s; + + base_simpl base_s; + interm_type_simpl interm_type_s; + interm_simpl interm_s; + derived_type_simpl derived_type_s; + derived_simpl derived_s; + + xml_schema::serializer_map_impl map (7); + type_simpl type_s; + + base_s.serializers (int_s); + interm_type_s.serializers (int_s, int_s); + interm_s.serializers (int_s, int_s); + derived_s.serializers (int_s, int_s, int_s); + derived_type_s.serializers (int_s, int_s, int_s); + + map.insert (base_s); + map.insert (interm_type_s); + map.insert (interm_s); + map.insert (derived_s); + map.insert (derived_type_s); + + type_s.base_serializer (map); + + xml_schema::document_simpl doc_s (type_s, "test", "root", true); + + doc_s.add_prefix ("t", "test"); + doc_s.add_prefix ("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + + type_s.pre (); + doc_s.serialize (cout); + +#ifndef XSDE_EXCEPTIONS + if (doc_s._error ()) + { + cerr << "error" << endl; + return 1; + } +#endif + + type_s.post (); + + // Test serializer resetting. + // + doc_s.reset (); + +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::serializer_exception const& e) + { + cerr << e << endl; + return 1; + } +#endif +} diff --git a/tests/cxx/serializer/polymorphism/makefile b/tests/cxx/serializer/polymorphism/makefile new file mode 100644 index 0000000..ff2ccbe --- /dev/null +++ b/tests/cxx/serializer/polymorphism/makefile @@ -0,0 +1,73 @@ +# file : tests/cxx/serializer/polymorphism/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): xsde_options += --generate-polymorphic +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/polymorphism/output b/tests/cxx/serializer/polymorphism/output new file mode 100644 index 0000000..5107439 --- /dev/null +++ b/tests/cxx/serializer/polymorphism/output @@ -0,0 +1 @@ +<t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><t:base><a>1</a></t:base><t:base xsi:type="t:interm_type"><a>1</a><b>2</b></t:base><t:interm><a>1</a><b>2</b></t:interm><t:base xsi:type="t:derived_type"><a>1</a><b>2</b><c>3</c></t:base><t:derived><a>1</a><b>2</b><c>3</c></t:derived></t:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/polymorphism/test.xsd b/tests/cxx/serializer/polymorphism/test.xsd new file mode 100644 index 0000000..d6aa1e3 --- /dev/null +++ b/tests/cxx/serializer/polymorphism/test.xsd @@ -0,0 +1,64 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="base"> + <sequence> + <element name="a" type="int"/> + </sequence> + </complexType> + + <element name="base" type="t:base"/> + + <complexType name="interm_type"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="interm"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="interm" type="t:interm" substitutionGroup="t:base"/> + + <complexType name="derived_type"> + <complexContent> + <extension base="t:interm_type"> + <sequence> + <element name="c" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="derived"> + <complexContent> + <extension base="t:interm"> + <sequence> + <element name="c" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="derived" type="t:derived" substitutionGroup="t:interm"/> + + <complexType name="type"> + <sequence> + <element ref="t:base" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/serializer/recursive/driver.cxx b/tests/cxx/serializer/recursive/driver.cxx new file mode 100644 index 0000000..c474191 --- /dev/null +++ b/tests/cxx/serializer/recursive/driver.cxx @@ -0,0 +1,135 @@ +// file : tests/cxx/serializer/recursive/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test recursive type serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; + +struct sub_type_simpl: virtual sub_type_sskel +{ + sub_type_simpl () + : n_ (0) + { + } + + virtual void + pre () + { + n_++; + } + + // Attributes. + // + virtual bool + name_present () + { + return true; + } + + virtual int + name () + { + return n_; + } + + // Elements. + // + virtual bool + sub_present () + { + return n_ == 1; + } + + virtual bool + indir_present () + { + return n_ == 1; + } + + virtual bool + sub2_present () + { + return n_ == 1; + } + + virtual void + post () + { + n_--; + } + +private: + int n_; +}; + +struct indir_type_simpl: virtual indir_type_sskel +{ + // Attributes. + // + virtual bool + name_present () + { + return true; + } + + virtual int + name () + { + return 123; + } + + // Elements. + // + virtual bool + sub_present () + { + return true; + } +}; + +struct test_type_simpl: virtual test_type_sskel +{ + // Attributes. + // + virtual bool + name_present () + { + return true; + } + + virtual int + name () + { + return 234; + } +}; + +int +main () +{ + xml_schema::int_simpl int_s; + sub_type_simpl sub_s; + indir_type_simpl indir_s; + test_type_simpl test_s; + + sub_s.serializers (int_s, sub_s, indir_s, sub_s); + indir_s.serializers (int_s, sub_s); + test_s.serializers (int_s, sub_s); + + xml_schema::document_simpl doc_s (test_s, "test", "root"); + + test_s.pre (); + doc_s.serialize (cout); + test_s.post (); + + // Test serializer resetting. + // + doc_s.reset (); +} diff --git a/tests/cxx/serializer/recursive/makefile b/tests/cxx/serializer/recursive/makefile new file mode 100644 index 0000000..4de9d93 --- /dev/null +++ b/tests/cxx/serializer/recursive/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/recursive/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/recursive/output b/tests/cxx/serializer/recursive/output new file mode 100644 index 0000000..717654f --- /dev/null +++ b/tests/cxx/serializer/recursive/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test" name="234"><sub name="1"><sub name="2"></sub><indir name="123"><sub name="2"></sub></indir><sub2 name="2"></sub2></sub></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/recursive/test.xsd b/tests/cxx/serializer/recursive/test.xsd new file mode 100644 index 0000000..0e915c9 --- /dev/null +++ b/tests/cxx/serializer/recursive/test.xsd @@ -0,0 +1,27 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <xs:complexType name="sub_type"> + <xs:sequence> + <xs:element name="sub" type="sub_type" minOccurs="0"/> + <xs:element name="indir" type="indir_type" minOccurs="0"/> + <xs:element name="sub2" type="sub_type" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="name" type="xs:int" /> + </xs:complexType> + + <xs:complexType name="indir_type"> + <xs:sequence> + <xs:element name="sub" type="sub_type" minOccurs="0"/> + </xs:sequence> + <xs:attribute name="name" type="xs:int" /> + </xs:complexType> + + <xs:complexType name="test_type"> + <xs:sequence> + <xs:element name="sub" type="sub_type" /> + </xs:sequence> + <xs:attribute name="name" type="xs:int" /> + </xs:complexType> + + <xs:element name="test" type="test_type" /> +</xs:schema> diff --git a/tests/cxx/serializer/reset/driver.cxx b/tests/cxx/serializer/reset/driver.cxx new file mode 100644 index 0000000..49e5d32 --- /dev/null +++ b/tests/cxx/serializer/reset/driver.cxx @@ -0,0 +1,281 @@ +// file : tests/cxx/serializer/reset/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test serializer resetting. +// + +#include <assert.h> + +#include <string> +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +bool fail = true; + +struct error {}; + +#ifdef XSDE_REUSE_STYLE_MIXIN +struct base_simpl: virtual base_sskel +#else +struct base_simpl: base_sskel +#endif +{ + base_simpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { +#ifndef XSDE_EXCEPTIONS + assert (!_error ()); +#endif + + if (fail && i_ == 3) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + +private: + unsigned long i_; +}; + +#ifdef XSDE_REUSE_STYLE_MIXIN +struct inner_simpl: inner_sskel, base_simpl +#else +struct inner_simpl: inner_sskel +#endif +{ + inner_simpl (unsigned long i) +#ifdef XSDE_REUSE_STYLE_MIXIN + : base_simpl (i), i_ (i) +#else + : inner_sskel (&base_impl_), base_impl_ (i), i_ (i) +#endif + { + } + + virtual void + _pre () + { + n_ = 0; + } + + virtual bool + b_next () + { + if (fail && i_ == 6) + { +#ifdef XSDE_SERIALIZER_VALIDATION + return false; +#else +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + return true; +#endif + } + + return n_++ == 0; + } + + virtual int + b () + { + if (fail && i_ == 4) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + + return 1; + } + + virtual void + post () + { + if (fail && i_ == 5) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + +private: +#ifdef XSDE_REUSE_STYLE_TIEIN + base_simpl base_impl_; +#endif + unsigned long i_; + unsigned long n_; +}; + +struct type_simpl: type_sskel +{ + type_simpl (unsigned long i) + : i_ (i) + { + } + + virtual void + pre () + { + if (fail && i_ == 0) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + + virtual void + a () + { + if (fail && i_ == 1) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + + virtual void + post () + { + if (fail && i_ == 2) + { +#ifdef XSDE_EXCEPTIONS + throw error (); +#else + _app_error (1); +#endif + } + } + +private: + unsigned long i_; +}; + +int +main () +{ + try + { + for (unsigned long i (0); i < 7; ++i) + { + xml_schema::int_simpl int_s; + inner_simpl inner_s (i); + type_simpl type_s (i); + + inner_s.serializers (int_s); + type_s.serializers (inner_s); + + xml_schema::document_simpl doc_s (type_s, "test", "root"); + + doc_s.add_prefix ("t", "test"); + doc_s.add_schema ("test", "test.xsd"); + + ostringstream ostr; + + cout << i << ": "; + +#ifdef XSDE_EXCEPTIONS + try + { + fail = true; + + type_s.pre (); + doc_s.serialize (ostr); + type_s.post (); + assert (false); + } + catch (error const&) + { + } + catch (xml_schema::serializer_exception const&) + { + } + + fail = false; + doc_s.reset (); + + type_s.pre (); + doc_s.serialize (cout); + type_s.post (); +#else + do + { + fail = true; + + type_s.pre (); + + if (type_s._error ()) + break; + + doc_s.serialize (ostr); + + if (doc_s._error ()) + break; + + type_s.post (); + + if (type_s._error ()) + break; + + assert (false); + } + while (false); + + fail = false; + doc_s.reset (); + + type_s.pre (); + assert (!type_s._error ()); + + doc_s.serialize (cout); + assert (!doc_s._error ()); + + type_s.post (); + assert (!type_s._error ()); +#endif + + cout << endl; + } + } +#ifdef XSDE_EXCEPTIONS + catch (xml_schema::serializer_exception const& e) + { + cerr << e << endl; + return 1; + } +#endif + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/serializer/reset/makefile b/tests/cxx/serializer/reset/makefile new file mode 100644 index 0000000..2d87e58 --- /dev/null +++ b/tests/cxx/serializer/reset/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/reset/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/reset/output b/tests/cxx/serializer/reset/output new file mode 100644 index 0000000..8e0b569 --- /dev/null +++ b/tests/cxx/serializer/reset/output @@ -0,0 +1,7 @@ +0: <t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"><a><b>1</b></a></t:root> +1: <t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"><a><b>1</b></a></t:root> +2: <t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"><a><b>1</b></a></t:root> +3: <t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"><a><b>1</b></a></t:root> +4: <t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"><a><b>1</b></a></t:root> +5: <t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"><a><b>1</b></a></t:root> +6: <t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"><a><b>1</b></a></t:root> diff --git a/tests/cxx/serializer/reset/test.xsd b/tests/cxx/serializer/reset/test.xsd new file mode 100644 index 0000000..f368fa0 --- /dev/null +++ b/tests/cxx/serializer/reset/test.xsd @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="base"> + <sequence> + </sequence> + </complexType> + + <complexType name="inner"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="int" maxOccurs="unbounded"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="a" type="t:inner"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/serializer/restriction/driver.cxx b/tests/cxx/serializer/restriction/driver.cxx new file mode 100644 index 0000000..0430765 --- /dev/null +++ b/tests/cxx/serializer/restriction/driver.cxx @@ -0,0 +1,246 @@ +// file : tests/cxx/serializer/restriction/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test inheritance-by-restriction serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: test_1_sskel +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + test_1_simpl () + : test_1_sskel (0) + { + } +#endif + + virtual int + optional () + { + return 123; + } + + virtual int + required () + { + return 234; + } +}; + +struct test_2_simpl: test_2_sskel +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + test_2_simpl () + : test_2_sskel (0) + { + } +#endif + + virtual void + pre () + { + i_ = 0; + } + + virtual int + a () + { + return 1; + } + + virtual bool + sequence_next () + { + return i_++ < 1; + } + + virtual int + b () + { + return 2; + } + + virtual int + c () + { + return 3; + } + + virtual choice_arm_tag + choice_arm () + { + return e_tag; + } + + virtual int + d () + { + return 4; + } + + virtual int + e () + { + return 5; + } + +private: + int i_; +}; + +struct test_3_simpl: test_3_sskel +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + test_3_simpl () + : test_3_sskel (0) + { + } +#endif + + virtual int + a () + { + return 1; + } + + virtual int + b () + { + return 2; + } + + virtual int + c () + { + return 3; + } + + virtual int + d () + { + return 4; + } + + virtual choice_arm_tag + choice_arm () + { + return g_tag; + } + + virtual int + e () + { + return 5; + } + + virtual int + f () + { + return 6; + } + + virtual int + g () + { + return 7; + } + +private: + int i_; +}; + +struct test_4_simpl: test_4_sskel +{ +#ifdef XSDE_REUSE_STYLE_TIEIN + test_4_simpl () + : test_4_sskel (0) + { + } +#endif + + virtual int + a () + { + return 1; + } + + virtual int + b () + { + return 2; + } + + virtual int + c () + { + return 3; + } + + virtual int + d () + { + return 4; + } + + virtual choice_arm_tag + choice_arm () + { + return g_tag; + } + + virtual int + e () + { + return 5; + } + + virtual int + f () + { + return 6; + } + + virtual int + g () + { + return 7; + } + +private: + int i_; +}; + +struct root_simpl: root_sskel +{ +}; + +int +main () +{ + xml_schema::int_simpl int_s; + test_1_simpl test_1_s; + test_2_simpl test_2_s; + test_3_simpl test_3_s; + test_4_simpl test_4_s; + root_simpl root_s; + + test_1_s.serializers (int_s, int_s); + test_2_s.serializers (int_s, int_s, int_s, int_s, int_s); + test_3_s.serializers (int_s, int_s, int_s, int_s, int_s, int_s, int_s); + test_4_s.serializers (int_s, int_s, int_s, int_s, int_s, int_s, int_s); + root_s.serializers (test_1_s, test_2_s, test_3_s, test_4_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/restriction/makefile b/tests/cxx/serializer/restriction/makefile new file mode 100644 index 0000000..0a4f081 --- /dev/null +++ b/tests/cxx/serializer/restriction/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/restriction/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/restriction/output b/tests/cxx/serializer/restriction/output new file mode 100644 index 0000000..6cb29b4 --- /dev/null +++ b/tests/cxx/serializer/restriction/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><test-1 optional="123" required="234"></test-1><test-2><a>1</a><b>2</b><c>3</c><e>5</e></test-2><test-3><b>2</b><g>7</g></test-3><test-4><b>2</b><g>7</g></test-4></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/restriction/test.xsd b/tests/cxx/serializer/restriction/test.xsd new file mode 100644 index 0000000..0557e5e --- /dev/null +++ b/tests/cxx/serializer/restriction/test.xsd @@ -0,0 +1,175 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- attribute restriction --> + + <complexType name="test-1-base"> + <attribute name="optional" type="int"/> + <attribute name="required" type="int" use="required"/> + <anyAttribute namespace="foo bar" processContents="skip"/> + </complexType> + + <complexType name="test-1"> + <complexContent> + <restriction base="t:test-1-base"> + <attribute name="optional" type="int" use="required"/> + <anyAttribute namespace="foo" processContents="skip"/> + </restriction> + </complexContent> + </complexType> + + <!-- simple content restriction --> + + <complexType name="test-2-base"> + <sequence> + <element name="a" type="int" minOccurs="0"/> + <sequence maxOccurs="unbounded"> + <element name="b" type="int"/> + <element name="c" type="int"/> + </sequence> + <choice> + <element name="d" type="int"/> + <element name="e" type="int" minOccurs="0"/> + </choice> + </sequence> + </complexType> + + <complexType name="test-2"> + <complexContent> + <restriction base="t:test-2-base"> + <sequence> + <element name="a" type="int" minOccurs="1"/> + <sequence maxOccurs="2"> + <element name="b" type="int"/> + <element name="c" type="int"/> + </sequence> + <choice> + <element name="d" type="int"/> + <element name="e" type="int" minOccurs="1"/> + </choice> + </sequence> + </restriction> + </complexContent> + </complexType> + + <!-- more complex content restriction with some parts removed--> + + <complexType name="test-3-base"> + <sequence> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="int"/> + <sequence minOccurs="0"> + <element name="c" type="int"/> + <element name="d" type="int"/> + </sequence> + <choice> + <element name="e" type="int" minOccurs="0"/> + <element name="f" type="int"/> + <element name="g" type="int"/> + </choice> + </sequence> + </complexType> + + <complexType name="test-3"> + <complexContent> + <restriction base="t:test-3-base"> + <sequence> + <element name="b" type="int"/> + <choice> + <element name="f" type="int"/> + <element name="g" type="int"/> + </choice> + </sequence> + </restriction> + </complexContent> + </complexType> + + <!-- complex content restriction spread over inheritance-by-extension--> + + <complexType name="test-4-base"> + <sequence> + <element name="a" type="int" minOccurs="0"/> + <element name="b" type="int"/> + </sequence> + <anyAttribute namespace="foo bar" processContents="skip"/> + </complexType> + + <complexType name="test-4-ext"> + <complexContent> + <extension base="t:test-4-base"> + <sequence> + <sequence minOccurs="0"> + <element name="c" type="int"/> + <element name="d" type="int"/> + </sequence> + <choice> + <element name="e" type="int" minOccurs="0"/> + <element name="f" type="int"/> + <element name="g" type="int"/> + </choice> + </sequence> + <anyAttribute namespace="baz biz" processContents="skip"/> + </extension> + </complexContent> + </complexType> + + <complexType name="test-4"> + <complexContent> + <restriction base="t:test-4-ext"> + <sequence> + <sequence> + <element name="b" type="int"/> + </sequence> + <sequence> + <choice> + <element name="f" type="int"/> + <element name="g" type="int"/> + </choice> + </sequence> + </sequence> + <anyAttribute namespace="foo" processContents="skip"/> + <anyAttribute namespace="baz" processContents="skip"/> + </restriction> + </complexContent> + </complexType> + + <!-- restriction of sequence into optional (compilation only) --> + + <complexType name="test-5-base"> + <sequence minOccurs="0" maxOccurs="unbounded"> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="a" type="int" minOccurs="0" maxOccurs="unbounded"/> + <element name="b" type="int"/> + </choice> + <any namespace="foo" minOccurs="0" maxOccurs="unbounded" processContents="skip"/> + </sequence> + </complexType> + + <complexType name="test-5"> + <complexContent> + <restriction base="t:test-5-base"> + <sequence minOccurs="0" maxOccurs="1"> + <choice minOccurs="0" maxOccurs="1"> + <element name="a" type="int" minOccurs="0" maxOccurs="1"/> + <element name="b" type="int"/> + </choice> + <any namespace="foo" minOccurs="0" maxOccurs="1" processContents="skip"/> + </sequence> + </restriction> + </complexContent> + </complexType> + + <!-- --> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1"/> + <element name="test-2" type="t:test-2"/> + <element name="test-3" type="t:test-3"/> + <element name="test-4" type="t:test-4"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/sequence/driver.cxx b/tests/cxx/serializer/sequence/driver.cxx new file mode 100644 index 0000000..ed6c5fb --- /dev/null +++ b/tests/cxx/serializer/sequence/driver.cxx @@ -0,0 +1,231 @@ +// file : tests/cxx/serializer/sequence/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the sequence compositor serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: test_1_sskel +{ + virtual void + pre () + { + i_ = 0; + } + + virtual int + a () + { + return 123; + } + + virtual bool + b_present () + { + return true; + } + + virtual int + b () + { + return 234; + } + + virtual bool + c_next () + { + return i_++ < 3; + } + + virtual int + c () + { + return i_; + } + +private: + int i_; +}; + +struct test_2_simpl: test_2_sskel +{ + test_2_simpl () + : i_ (0) + { + } + + virtual bool + sequence_present () + { + return i_++; + } + + virtual int + a () + { + return 123; + } + + virtual int + b () + { + return 234; + } + +private: + int i_; +}; + +struct test_3_simpl: test_3_sskel +{ + virtual void + pre () + { + i_ = 0; + } + + virtual bool + sequence_next () + { + return i_++ < 3; + } + + virtual int + a () + { + return 123 + i_; + } + + virtual int + b () + { + return 234 + i_; + } + +private: + int i_; +}; + +struct test_4_simpl: test_4_sskel +{ + virtual void + pre () + { + i_ = 0; + } + + virtual int + a () + { + return 123; + } + + virtual choice_arm_tag + choice_arm () + { + return c_tag; + } + + virtual int + b () + { + return 0; + } + + virtual int + c () + { + return 234; + } + + virtual bool + sequence_next () + { + return i_++ < 3; + } + + virtual int + d () + { + return 345 + i_; + } + + virtual int + e () + { + return 456 + i_; + } + +private: + int i_; +}; + +struct root_simpl: root_sskel +{ + virtual void + pre () + { + n1_ = 0; + n2_ = 0; + n3_ = 0; + n4_ = 0; + } + + virtual bool + test_1_next () + { + return n1_++ < 1; + } + + virtual bool + test_2_next () + { + return n2_++ < 2; + } + + virtual bool + test_3_next () + { + return n3_++ < 1; + } + + virtual bool + test_4_next () + { + return n4_++ < 1; + } + +private: + int n1_, n2_, n3_, n4_; +}; + +int +main () +{ + xml_schema::int_simpl int_s; + test_1_simpl test_1_s; + test_2_simpl test_2_s; + test_3_simpl test_3_s; + test_4_simpl test_4_s; + root_simpl root_s; + + test_1_s.serializers (int_s, int_s, int_s); + test_2_s.serializers (int_s, int_s); + test_3_s.serializers (int_s, int_s); + test_4_s.serializers (int_s, int_s, int_s, int_s, int_s); + root_s.serializers (test_1_s, test_2_s, test_3_s, test_4_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/sequence/makefile b/tests/cxx/serializer/sequence/makefile new file mode 100644 index 0000000..a3a109e --- /dev/null +++ b/tests/cxx/serializer/sequence/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/sequence/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/sequence/output b/tests/cxx/serializer/sequence/output new file mode 100644 index 0000000..a76f191 --- /dev/null +++ b/tests/cxx/serializer/sequence/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><test-1><a>123</a><b>234</b><c>1</c><c>2</c><c>3</c></test-1><test-2></test-2><test-2><a>123</a><b>234</b></test-2><test-3><a>124</a><b>235</b><a>125</a><b>236</b><a>126</a><b>237</b></test-3><test-4><a>123</a><c>234</c><d>346</d><e>457</e><d>347</d><e>458</e><d>348</d><e>459</e></test-4></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/sequence/test.xsd b/tests/cxx/serializer/sequence/test.xsd new file mode 100644 index 0000000..696a1f2 --- /dev/null +++ b/tests/cxx/serializer/sequence/test.xsd @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="int" minOccurs="0"/> + <element name="c" type="int" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <complexType name="test-2"> + <sequence minOccurs="0"> + <element name="a" type="int"/> + <element name="b" type="int"/> + </sequence> + </complexType> + + <complexType name="test-3"> + <sequence maxOccurs="unbounded"> + <element name="a" type="int"/> + <element name="b" type="int"/> + </sequence> + </complexType> + + <complexType name="test-4"> + <sequence> + <element name="a" type="int"/> + <choice> + <element name="b" type="int"/> + <element name="c" type="int"/> + </choice> + <sequence maxOccurs="unbounded"> + <element name="d" type="int"/> + <element name="e" type="int"/> + </sequence> + </sequence> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1" maxOccurs="unbounded"/> + <element name="test-2" type="t:test-2" maxOccurs="unbounded"/> + <element name="test-3" type="t:test-3" maxOccurs="unbounded"/> + <element name="test-4" type="t:test-4" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/test-template/driver.cxx b/tests/cxx/serializer/test-template/driver.cxx new file mode 100644 index 0000000..784f223 --- /dev/null +++ b/tests/cxx/serializer/test-template/driver.cxx @@ -0,0 +1,48 @@ +// file : tests/cxx/serializer/test-template/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Insert test description here. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct root_simpl: root_sskel +{ + virtual void + pre () + { + } + + virtual int + a () + { + return 1234; + } + + virtual void + post_type () + { + } +}; + +int +main () +{ + xml_schema::int_simpl int_s; + root_simpl root_s; + + root_s.serializers (int_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/test-template/makefile b/tests/cxx/serializer/test-template/makefile new file mode 100644 index 0000000..28e1f5f --- /dev/null +++ b/tests/cxx/serializer/test-template/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/test-template/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/test-template/output b/tests/cxx/serializer/test-template/output new file mode 100644 index 0000000..509a8ed --- /dev/null +++ b/tests/cxx/serializer/test-template/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><a>1234</a></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/test-template/test.xsd b/tests/cxx/serializer/test-template/test.xsd new file mode 100644 index 0000000..164b72c --- /dev/null +++ b/tests/cxx/serializer/test-template/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="root"> + <sequence> + <element name="a" type="int"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/union/driver.cxx b/tests/cxx/serializer/union/driver.cxx new file mode 100644 index 0000000..566b681 --- /dev/null +++ b/tests/cxx/serializer/union/driver.cxx @@ -0,0 +1,93 @@ +// file : tests/cxx/serializer/union/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test union type serialization. +// + +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct int_bool_union_simpl: virtual int_bool_union_sskel +{ + int_bool_union_simpl () + : n_ (0) + { + } + + virtual void + _serialize_content () + { + if (n_++ == 0) + _characters ("123"); + else + _characters ("false"); + } + +private: + int n_; +}; + +struct int_bool_base_simpl: int_bool_base_sskel +{ + int_bool_base_simpl () + : int_bool_base_sskel (&base_impl_) + { + } + + virtual int + base () + { + return 123; + } + +private: + int_bool_union_simpl base_impl_; +}; + +struct root_simpl: root_sskel +{ + virtual void + pre () + { + n_ = 0; + } + + virtual bool + int_bool_union_next () + { + return n_++ < 2; + } + + virtual bool + int_bool_base_next () + { + return n_++ < 5; + } + +private: + int n_; +}; + +int +main () +{ + xml_schema::int_simpl int_s; + int_bool_union_simpl int_bool_union_s; + int_bool_base_simpl int_bool_base_s; + root_simpl root_s; + + int_bool_base_s.serializers (int_s); + root_s.serializers (int_bool_union_s, int_bool_base_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/union/makefile b/tests/cxx/serializer/union/makefile new file mode 100644 index 0000000..f361564 --- /dev/null +++ b/tests/cxx/serializer/union/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/union/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/union/output b/tests/cxx/serializer/union/output new file mode 100644 index 0000000..70363b0 --- /dev/null +++ b/tests/cxx/serializer/union/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test"><int-bool-union>123</int-bool-union><int-bool-union>false</int-bool-union><int-bool-base base="123">123</int-bool-base><int-bool-base base="123">false</int-bool-base></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/union/test.xsd b/tests/cxx/serializer/union/test.xsd new file mode 100644 index 0000000..b5b7707 --- /dev/null +++ b/tests/cxx/serializer/union/test.xsd @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="int-bool-union"> + <union memberTypes="int boolean"/> + </simpleType> + + <complexType name="int-bool-base"> + <simpleContent> + <extension base="t:int-bool-union"> + <attribute name="base" type="int" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="root"> + <sequence> + <element name="int-bool-union" type="t:int-bool-union" maxOccurs="unbounded"/> + <element name="int-bool-base" type="t:int-bool-base" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/validation/any/driver.cxx b/tests/cxx/serializer/validation/any/driver.cxx new file mode 100644 index 0000000..ecdf7f8 --- /dev/null +++ b/tests/cxx/serializer/validation/any/driver.cxx @@ -0,0 +1,317 @@ +// file : tests/cxx/serializer/validation/any/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test any validation. +// + +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: virtual test_1_sskel +{ + virtual bool + any_next () + { + return false; + } + + virtual void +#ifdef XSDE_STL + any (std::string&, std::string&) + { +#else + any (const char*&, const char*&, bool&) + { +#endif + } + + virtual void + serialize_any () + { + } +}; + +// ##any +// +struct test_2_simpl: virtual test_2_sskel +{ + virtual void +#ifdef XSDE_STL + any (std::string& ns, std::string& name) + { +#else + any (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + ns = "foo"; + name = ""; + } + + virtual void + serialize_any () + { + } +}; + +// ##other +// +struct test_3_simpl: virtual test_3_sskel +{ + test_3_simpl (int state) + : state_ (state) + { + } + + virtual void +#ifdef XSDE_STL + any (std::string& ns, std::string& name) + { +#else + any (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + switch (state_) + { + case 2: + { + // target + // + ns = "test"; + name = "x"; + break; + } + case 3: + { + // local + // + ns = ""; + name = "x"; + break; + } + } + } + + virtual void + serialize_any () + { + } + +private: + int state_; +}; + +// ##local +// +struct test_4_simpl: virtual test_4_sskel +{ + virtual void +#ifdef XSDE_STL + any (std::string& ns, std::string& name) + { +#else + any (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + ns = "foo"; + name = "x"; + } + + virtual void + serialize_any () + { + } +}; + +// ##targetNamespace +// +struct test_5_simpl: virtual test_5_sskel +{ + test_5_simpl (int state) + : state_ (state) + { + } + + virtual void +#ifdef XSDE_STL + any (std::string& ns, std::string& name) + { +#else + any (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + switch (state_++) + { + case 5: + { + // target + // + ns = "foo"; + name = "x"; + break; + } + case 6: + { + // local + // + ns = ""; + name = "x"; + break; + } + } + } + + virtual void + serialize_any () + { + } + +private: + int state_; +}; + +// foo +// +struct test_6_simpl: virtual test_6_sskel +{ + test_6_simpl (int state) + : state_ (state) + { + } + + virtual void +#ifdef XSDE_STL + any (std::string& ns, std::string& name) + { +#else + any (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + switch (state_++) + { + case 7: + { + // bar + // + ns = "bar"; + name = "x"; + break; + } + case 8: + { + // local + // + ns = ""; + name = "x"; + break; + } + } + } + + virtual void + serialize_any () + { + } + +private: + int state_; +}; + +struct root_simpl: root_sskel +{ + root_simpl (int state) + : state_ (state) + { + } + + virtual choice_arm_tag + choice_arm () + { + switch (state_) + { + case 0: + return test_1_tag; + case 1: + return test_2_tag; + case 2: + case 3: + return test_3_tag; + case 4: + return test_4_tag; + case 5: + case 6: + return test_5_tag; + case 7: + case 8: + return test_5_tag; + default: + return choice_arm_tag (state_); + } + } + +private: + int state_; +}; + +int +main () +{ + for (int i = 0; i < 9; ++i) + { +#ifdef XSDE_EXCEPTIONS + try + { +#endif + test_1_simpl test_1_s; + test_2_simpl test_2_s; + test_3_simpl test_3_s (i); + test_4_simpl test_4_s; + test_5_simpl test_5_s (i); + test_6_simpl test_6_s (i); + root_simpl root_s (i); + + root_s.serializers (test_1_s, test_2_s, test_3_s, test_4_s, + test_5_s, test_6_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + + ostringstream os; + doc_s.serialize (os); + +#ifndef XSDE_EXCEPTIONS + if (xml_schema::serializer_error e = doc_s._error ()) + { + if (e.type () == xml_schema::serializer_error::schema) + { + cout << "schema: " << e.schema_text () << endl; + continue; + } + } +#endif + + root_s.post (); +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::serializer_schema const& e) + { + cout << "schema: " << e.text () << endl; + continue; + } +#endif + + cout << "no error" << endl; + } +} diff --git a/tests/cxx/serializer/validation/any/makefile b/tests/cxx/serializer/validation/any/makefile new file mode 100644 index 0000000..2365ef1 --- /dev/null +++ b/tests/cxx/serializer/validation/any/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/validation/any/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/any/output b/tests/cxx/serializer/validation/any/output new file mode 100644 index 0000000..cf16193 --- /dev/null +++ b/tests/cxx/serializer/validation/any/output @@ -0,0 +1,9 @@ +schema: expected element not encountered +schema: unexpected element encountered +schema: unexpected element encountered +schema: unexpected element encountered +schema: unexpected element encountered +schema: unexpected element encountered +schema: unexpected element encountered +schema: unexpected element encountered +schema: unexpected element encountered diff --git a/tests/cxx/serializer/validation/any/test.xsd b/tests/cxx/serializer/validation/any/test.xsd new file mode 100644 index 0000000..4457d58 --- /dev/null +++ b/tests/cxx/serializer/validation/any/test.xsd @@ -0,0 +1,53 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <sequence> + <any namespace="foo" processContents="skip" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <complexType name="test-2"> + <sequence> + <any namespace="##any" processContents="skip"/> + </sequence> + </complexType> + + <complexType name="test-3"> + <sequence> + <any namespace="##other" processContents="skip"/> + </sequence> + </complexType> + + <complexType name="test-4"> + <sequence> + <any namespace="##local" processContents="skip"/> + </sequence> + </complexType> + + <complexType name="test-5"> + <sequence> + <any namespace="##targetNamespace" processContents="skip"/> + </sequence> + </complexType> + + <complexType name="test-6"> + <sequence> + <any namespace="bar" processContents="skip"/> + </sequence> + </complexType> + + <complexType name="root"> + <choice> + <element name="test-1" type="t:test-1"/> + <element name="test-2" type="t:test-2"/> + <element name="test-3" type="t:test-3"/> + <element name="test-4" type="t:test-4"/> + <element name="test-5" type="t:test-5"/> + <element name="test-6" type="t:test-6"/> + </choice> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/validation/attribute/driver.cxx b/tests/cxx/serializer/validation/attribute/driver.cxx new file mode 100644 index 0000000..96a4629 --- /dev/null +++ b/tests/cxx/serializer/validation/attribute/driver.cxx @@ -0,0 +1,247 @@ +// file : tests/cxx/serializer/validation/attribute/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test attribute and anyAttribute validation. +// + +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: virtual test_1_sskel +{ + test_1_simpl (int state) + : state_ (state) + { + } + + virtual int + x () + { + if (state_ == 0) + state_ ++; + + return 123; + } + + // ##any + // + virtual bool + any_attribute_next () + { + return state_ == 1; + } + + virtual void +#ifdef XSDE_STL + any_attribute (std::string& ns, std::string& name) + { +#else + any_attribute (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + state_++; + ns = "foo"; + name = ""; + } + + // ##other + // + virtual bool + any_attribute1_next () + { + return state_ > 1 && state_ < 4; + } + + virtual void +#ifdef XSDE_STL + any_attribute1 (std::string& ns, std::string& name) + { +#else + any_attribute1 (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + switch (state_++) + { + case 2: + { + // target + // + ns = "test"; + name = "x"; + break; + } + case 3: + { + // local + // + ns = ""; + name = "x"; + break; + } + } + } + + // ##local + // + virtual bool + any_attribute2_next () + { + return state_ == 4; + } + + virtual void +#ifdef XSDE_STL + any_attribute2 (std::string& ns, std::string& name) + { +#else + any_attribute2 (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + state_++; + ns = "foo"; + name = "x"; + } + + // ##targetNamespace + // + virtual bool + any_attribute3_next () + { + return state_ > 4 && state_ < 7; + } + + virtual void +#ifdef XSDE_STL + any_attribute3 (std::string& ns, std::string& name) + { +#else + any_attribute3 (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + switch (state_++) + { + case 5: + { + // target + // + ns = "foo"; + name = "x"; + break; + } + case 6: + { + // local + // + ns = ""; + name = "x"; + break; + } + } + } + + // foo + // + virtual bool + any_attribute4_next () + { + return state_ > 6 && state_ < 9; + } + + virtual void +#ifdef XSDE_STL + any_attribute4 (std::string& ns, std::string& name) + { +#else + any_attribute4 (const char*& ns, const char*& name, bool& free) + { + free = false; +#endif + switch (state_++) + { + case 7: + { + // bar + // + ns = "bar"; + name = "x"; + break; + } + case 8: + { + // local + // + ns = ""; + name = "x"; + break; + } + } + } + +private: + int state_; +}; + +struct root_simpl: root_sskel +{ +}; + +int +main () +{ + for (int i = 0; i < 9; ++i) + { +#ifdef XSDE_EXCEPTIONS + try + { +#endif + xml_schema::int_simpl int_s; + test_1_simpl test_1_s (i); + root_simpl root_s; + + if (i != 0) + test_1_s.serializers (int_s); + + root_s.serializers (test_1_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + + ostringstream os; + doc_s.serialize (os); + +#ifndef XSDE_EXCEPTIONS + if (xml_schema::serializer_error e = doc_s._error ()) + { + if (e.type () == xml_schema::serializer_error::schema) + { + cout << "schema: " << e.schema_text () << endl; + continue; + } + } +#endif + + root_s.post (); +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::serializer_schema const& e) + { + cout << "schema: " << e.text () << endl; + continue; + } +#endif + + cout << "no error" << endl; + } +} diff --git a/tests/cxx/serializer/validation/attribute/makefile b/tests/cxx/serializer/validation/attribute/makefile new file mode 100644 index 0000000..586b957 --- /dev/null +++ b/tests/cxx/serializer/validation/attribute/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/validation/attribute/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/attribute/output b/tests/cxx/serializer/validation/attribute/output new file mode 100644 index 0000000..2b9de1e --- /dev/null +++ b/tests/cxx/serializer/validation/attribute/output @@ -0,0 +1,9 @@ +schema: expected attribute not encountered +schema: unexpected attribute encountered +schema: unexpected attribute encountered +schema: unexpected attribute encountered +schema: unexpected attribute encountered +schema: unexpected attribute encountered +schema: unexpected attribute encountered +schema: unexpected attribute encountered +schema: unexpected attribute encountered diff --git a/tests/cxx/serializer/validation/attribute/test.xsd b/tests/cxx/serializer/validation/attribute/test.xsd new file mode 100644 index 0000000..deb3f3b --- /dev/null +++ b/tests/cxx/serializer/validation/attribute/test.xsd @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <attribute name="x" type="int" use="required"/> + <anyAttribute namespace="##any" processContents="skip"/> + <anyAttribute namespace="##other" processContents="skip"/> + <anyAttribute namespace="##local" processContents="skip"/> + <anyAttribute namespace="##targetNamespace" processContents="skip"/> + <anyAttribute namespace="foo" processContents="skip"/> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/validation/built-in/date-time/driver.cxx b/tests/cxx/serializer/validation/built-in/date-time/driver.cxx new file mode 100644 index 0000000..bdc196e --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/date-time/driver.cxx @@ -0,0 +1,398 @@ +// file : tests/cxx/serializer/validation/built-in/date-time/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in date and time types validation. +// +#include <cassert> + +#include <xsde/cxx/serializer/validating/xml-schema-simpl.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::serializer; +using namespace xsde::cxx::serializer::validating; + +int +main () +{ + using xsde::cxx::time; // Conflicts with system time. + + // gday & time zone + // + { + gday_simpl s; + context c (0); + s.pre (gday (0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + gday_simpl s; + context c (0); + s.pre (gday (32)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + gday_simpl s; + context c (0); + s.pre (gday (15, 15, 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + gday_simpl s; + context c (0); + s.pre (gday (15, 12, 60)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + gday_simpl s; + context c (0); + s.pre (gday (15, -12, 30)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + gday_simpl s; + context c (0); + s.pre (gday (15, 12, -30)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + { + gday_simpl s; + context c (0); + s.pre (gday (15, 14, 1)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gday_value); + } + + // gmonth + // + { + gmonth_simpl s; + context c (0); + s.pre (gmonth (0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + { + gmonth_simpl s; + context c (0); + s.pre (gmonth (13)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gmonth_value); + } + + // gyear + // + { + gyear_simpl s; + context c (0); + s.pre (gyear (0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gyear_value); + } + + // gmonth_day + // + { + gmonth_day_simpl s; + context c (0); + s.pre (gmonth_day (0, 15)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + gmonth_day_simpl s; + context c (0); + s.pre (gmonth_day (6, 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + gmonth_day_simpl s; + context c (0); + s.pre (gmonth_day (13, 15)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + { + gmonth_day_simpl s; + context c (0); + s.pre (gmonth_day (6, 32)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gmonth_day_value); + } + + // gyear_month + // + { + gyear_month_simpl s; + context c (0); + s.pre (gyear_month (0, 6)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + gyear_month_simpl s; + context c (0); + s.pre (gyear_month (2007, 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + { + gyear_month_simpl s; + context c (0); + s.pre (gyear_month (2007, 32)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_gyear_month_value); + } + + // date + // + { + date_simpl s; + context c (0); + s.pre (date (0, 6, 15)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + date_simpl s; + context c (0); + s.pre (date (2007, 0, 15)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + date_simpl s; + context c (0); + s.pre (date (2007, 13, 15)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + date_simpl s; + context c (0); + s.pre (date (2007, 6, 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + { + date_simpl s; + context c (0); + s.pre (date (2007, 6, 32)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_value); + } + + // time + // + { + time_simpl s; + context c (0); + s.pre (time (25, 30, 30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + time_simpl s; + context c (0); + s.pre (time (24, 1, 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + time_simpl s; + context c (0); + s.pre (time (24, 0, 0.1)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + time_simpl s; + context c (0); + s.pre (time (12, 60, 30)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + time_simpl s; + context c (0); + s.pre (time (12, 30, 60.1)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + { + time_simpl s; + context c (0); + s.pre (time (12, 30, -30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_time_value); + } + + // date_time + // + { + date_time_simpl s; + context c (0); + s.pre (date_time (0, 6, 32, 12, 30, 30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 0, 32, 12, 30, 30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 13, 32, 12, 30, 30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 0, 12, 30, 30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 32, 12, 30, 30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 15, 25, 30, 30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 15, 24, 1, 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 15, 24, 0, 0.1)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 15, 12, 60, 30)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 15, 12, 30, 60.1)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + { + date_time_simpl s; + context c (0); + s.pre (date_time (2007, 6, 15, 12, 30, -30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_date_time_value); + } + + // duration + // + { + duration_simpl s; + context c (0); + s.pre (duration (false, 2007, 6, 15, 12, 30, -30.0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_duration_value); + } +} diff --git a/tests/cxx/serializer/validation/built-in/date-time/makefile b/tests/cxx/serializer/validation/built-in/date-time/makefile new file mode 100644 index 0000000..aa45e21 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/date-time/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/serializer/validation/built-in/date-time/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/built-in/decimal/driver.cxx b/tests/cxx/serializer/validation/built-in/decimal/driver.cxx new file mode 100644 index 0000000..9349e6b --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/decimal/driver.cxx @@ -0,0 +1,46 @@ +// file : tests/cxx/serializer/validation/built-in/decimal/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in decimal type validation. +// +#include <stdlib.h> // strtod +#include <cassert> + +#include <xsde/cxx/serializer/validating/decimal.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::serializer; +using namespace xsde::cxx::serializer::validating; + +int +main () +{ + { + decimal_simpl s; + context c (0); + s.pre (strtod ("NAN", 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_decimal_value); + } + + { + decimal_simpl s; + context c (0); + s.pre (strtod ("INF", 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_decimal_value); + } + + { + decimal_simpl s; + context c (0); + s.pre (strtod ("-INF", 0)); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_decimal_value); + } +} diff --git a/tests/cxx/serializer/validation/built-in/decimal/makefile b/tests/cxx/serializer/validation/built-in/decimal/makefile new file mode 100644 index 0000000..e4517b6 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/decimal/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/serializer/validation/built-in/decimal/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/built-in/integer/driver.cxx b/tests/cxx/serializer/validation/built-in/integer/driver.cxx new file mode 100644 index 0000000..e20a561 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/integer/driver.cxx @@ -0,0 +1,63 @@ +// file : tests/cxx/serializer/validation/built-in/int/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in integer & friends types validation. +// + +#include <cassert> + +#include <xsde/cxx/serializer/validating/negative-integer.hxx> +#include <xsde/cxx/serializer/validating/non-positive-integer.hxx> +#include <xsde/cxx/serializer/validating/positive-integer.hxx> + +using namespace xsde::cxx::serializer; +using namespace xsde::cxx::serializer::validating; +using namespace std; + +int +main () +{ + // negative_integer + // + { + negative_integer_simpl s; + context c (0); + s.pre (0); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error ()); + } + + { + negative_integer_simpl s; + context c (0); + s.pre (1); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error ()); + } + + // non_positive_integer + // + { + non_positive_integer_simpl s; + context c (0); + s.pre (1); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error ()); + } + + // positive_integer + // + { + positive_integer_simpl s; + context c (0); + s.pre (0); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error ()); + } +} diff --git a/tests/cxx/serializer/validation/built-in/integer/makefile b/tests/cxx/serializer/validation/built-in/integer/makefile new file mode 100644 index 0000000..37bd439 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/integer/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/serializer/validation/built-in/integer/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/built-in/makefile b/tests/cxx/serializer/validation/built-in/makefile new file mode 100644 index 0000000..7fdeec7 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/makefile @@ -0,0 +1,20 @@ +# file : tests/cxx/serializer/validation/built-in/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +tests := date-time decimal integer qname string + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/serializer/validation/built-in/qname/driver.cxx b/tests/cxx/serializer/validation/built-in/qname/driver.cxx new file mode 100644 index 0000000..33ccdc1 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/qname/driver.cxx @@ -0,0 +1,70 @@ +// file : tests/cxx/serializer/validation/built-in/qname/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in QName type validation. +// +#include <cassert> + +#include <xsde/config.h> + +// Let the runtime header sort out which version (stl/no-stl) to +// include. +// +#include <xsde/cxx/serializer/validating/xml-schema-simpl.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::serializer; +using namespace xsde::cxx::serializer::validating; + +int +main () +{ + { + qname_simpl s; + context c (0); +#ifdef XSDE_STL + s.pre (qname ("a b")); +#else + qname qn; + qn.name_copy ("a b"); + s.pre (&qn); +#endif + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } + + { + qname_simpl s; + context c (0); +#ifdef XSDE_STL + s.pre (qname ("ab", "a b")); +#else + qname qn; + qn.name_copy ("a b"); + qn.prefix_copy ("ab"); + s.pre (&qn); +#endif + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } + + { + qname_simpl s; + context c (0); +#ifdef XSDE_STL + s.pre (qname ("a b", "ab")); +#else + qname qn; + qn.name_copy ("ab"); + qn.prefix_copy ("a b"); + s.pre (&qn); +#endif + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_qname_value); + } +} diff --git a/tests/cxx/serializer/validation/built-in/qname/makefile b/tests/cxx/serializer/validation/built-in/qname/makefile new file mode 100644 index 0000000..ec2d802 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/qname/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/serializer/validation/built-in/qname/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/built-in/string/driver.cxx b/tests/cxx/serializer/validation/built-in/string/driver.cxx new file mode 100644 index 0000000..c1cfe21 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/string/driver.cxx @@ -0,0 +1,485 @@ +// file : tests/cxx/serializer/validation/built-in/string/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in string & friends types validation. +// +#include <string> +#include <cassert> + +#include <xsde/config.h> + +// Let the runtime header sort out which version (stl/no-stl) to +// include. +// +#include <xsde/cxx/serializer/validating/xml-schema-simpl.hxx> + +using namespace xsde::cxx; +using namespace xsde::cxx::serializer; +using namespace xsde::cxx::serializer::validating; + +int +main () +{ + // normalized_string + // + { + normalized_string_simpl s; + context c (0); + s.pre ("aaa\nbbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_normalized_string_value); + } + + { + normalized_string_simpl s; + context c (0); + s.pre ("aaa\tbbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_normalized_string_value); + } + + { + normalized_string_simpl s; + context c (0); + s.pre ("aaa\rbbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_normalized_string_value); + } + + // token + // + { + token_simpl s; + context c (0); + s.pre ("aaa\nbbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_token_value); + } + + { + token_simpl s; + context c (0); + s.pre ("aaa\tbbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_token_value); + } + + { + token_simpl s; + context c (0); + s.pre ("aaa\rbbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_token_value); + } + + { + token_simpl s; + context c (0); + s.pre ("aaa bbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_token_value); + } + + { + token_simpl s; + context c (0); + s.pre (" aaa bbb"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_token_value); + } + + { + token_simpl s; + context c (0); + s.pre ("aaa bbb "); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_token_value); + } + + // name + // + { + name_simpl s; + context c (0); + s.pre (""); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre (".a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre ("-a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre ("1a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre (" a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre ("a,b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre ("a b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre ("a<b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + { + name_simpl s; + context c (0); + s.pre ("a "); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_name_value); + } + + // nmtoken + // + { + nmtoken_simpl s; + context c (0); + s.pre (""); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + { + nmtoken_simpl s; + context c (0); + s.pre (" a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + { + nmtoken_simpl s; + context c (0); + s.pre ("a,b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + { + nmtoken_simpl s; + context c (0); + s.pre ("a b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + { + nmtoken_simpl s; + context c (0); + s.pre ("a<b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + { + nmtoken_simpl s; + context c (0); + s.pre ("a "); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + // nmtokens + // + { + nmtokens_simpl s; + context c (0); + string_sequence seq; + s.pre (&seq); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtokens_value); + } + + { + nmtokens_simpl s; + context c (0); + string_sequence seq; +#ifdef XSDE_STL + seq.push_back ("a,b"); + seq.push_back ("ab"); +#else + seq.push_back_copy ("a,b"); + seq.push_back_copy ("ab"); +#endif + s.pre (&seq); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_nmtoken_value); + } + + // ncname + // + { + ncname_simpl s; + context c (0); + s.pre (""); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre (" a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre (".a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre ("-a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre (":a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre ("1a"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre ("a,b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre ("a b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre ("a:b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre ("a<b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + { + ncname_simpl s; + context c (0); + s.pre ("a "); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_ncname_value); + } + + // id + // + { + id_simpl s; + context c (0); + s.pre ("a b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_id_value); + } + + // idref + // + { + idref_simpl s; + context c (0); + s.pre ("a b"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_idref_value); + } + + // idrefs + // + { + idrefs_simpl s; + context c (0); + string_sequence seq; + s.pre (&seq); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_idrefs_value); + } + + { + idrefs_simpl s; + context c (0); + string_sequence seq; +#ifdef XSDE_STL + seq.push_back ("a,b"); + seq.push_back ("ab"); +#else + seq.push_back_copy ("a,b"); + seq.push_back_copy ("ab"); +#endif + s.pre (&seq); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_idref_value); + } + + // language + // + { + language_simpl s; + context c (0); + s.pre (""); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + language_simpl s; + context c (0); + s.pre (" "); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + language_simpl s; + context c (0); + s.pre ("en-"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + language_simpl s; + context c (0); + s.pre ("a1"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + language_simpl s; + context c (0); + s.pre ("en+us"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_language_value); + } + + { + language_simpl s; + context c (0); + s.pre ("en-nine99999"); + s._pre_impl (c); + s._serialize_content (); + assert (c.schema_error () == schema_error::invalid_language_value); + } +} diff --git a/tests/cxx/serializer/validation/built-in/string/makefile b/tests/cxx/serializer/validation/built-in/string/makefile new file mode 100644 index 0000000..42a7d81 --- /dev/null +++ b/tests/cxx/serializer/validation/built-in/string/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/serializer/validation/built-in/string/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/choice/driver.cxx b/tests/cxx/serializer/validation/choice/driver.cxx new file mode 100644 index 0000000..11e1aaa --- /dev/null +++ b/tests/cxx/serializer/validation/choice/driver.cxx @@ -0,0 +1,114 @@ +// file : tests/cxx/serializer/validation/choice/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test choice validation. +// + +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: virtual test_1_sskel +{ + test_1_simpl (int state) + : state_ (state) + { + } + + virtual bool + choice_next () + { + return true; + } + + virtual choice_arm_tag + choice_arm () + { + return static_cast<choice_arm_tag> (state_); + } + + // + // + virtual bool + choice1_next () + { + return false; + } + + virtual choice1_arm_tag + choice1_arm () + { + return a_tag; + } + + virtual int + a () + { + return 123; + } + + virtual int + b () + { + return 234; + } + +private: + int state_; +}; + +struct root_simpl: root_sskel +{ +}; + +int +main () +{ + for (int i = 0; i < 2; ++i) + { +#ifdef XSDE_EXCEPTIONS + try + { +#endif + test_1_simpl test_1_s (i); + root_simpl root_s; + + root_s.serializers (test_1_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + + ostringstream os; + doc_s.serialize (os); + +#ifndef XSDE_EXCEPTIONS + if (xml_schema::serializer_error e = doc_s._error ()) + { + if (e.type () == xml_schema::serializer_error::schema) + { + cout << "schema: " << e.schema_text () << endl; + continue; + } + } +#endif + + root_s.post (); +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::serializer_schema const& e) + { + cout << "schema: " << e.text () << endl; + continue; + } +#endif + + cout << "no error" << endl; + } +} diff --git a/tests/cxx/serializer/validation/choice/makefile b/tests/cxx/serializer/validation/choice/makefile new file mode 100644 index 0000000..79d45eb --- /dev/null +++ b/tests/cxx/serializer/validation/choice/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/validation/choice/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/choice/output b/tests/cxx/serializer/validation/choice/output new file mode 100644 index 0000000..7ec90f4 --- /dev/null +++ b/tests/cxx/serializer/validation/choice/output @@ -0,0 +1,2 @@ +schema: expected element not encountered +schema: unexpected element encountered diff --git a/tests/cxx/serializer/validation/choice/test.xsd b/tests/cxx/serializer/validation/choice/test.xsd new file mode 100644 index 0000000..b87d638 --- /dev/null +++ b/tests/cxx/serializer/validation/choice/test.xsd @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <choice maxOccurs="5"> + <choice maxOccurs="unbounded"> <!-- 1..unbounded--> + <element name="a" type="int"/> + <element name="b" type="int"/> + </choice> + </choice> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/validation/element/driver.cxx b/tests/cxx/serializer/validation/element/driver.cxx new file mode 100644 index 0000000..b0ff7ed --- /dev/null +++ b/tests/cxx/serializer/validation/element/driver.cxx @@ -0,0 +1,106 @@ +// file : tests/cxx/serializer/validation/element/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test element validation. +// + +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: virtual test_1_sskel +{ + test_1_simpl (int state) + : state_ (state) + { + } + + virtual bool + a_next () + { + if (state_ == 0) + { + state_++; + return true; + } + + return false; + } + + virtual int + a () + { + return 123; + } + + virtual bool + b_next () + { + return false; + } + + virtual int + b () + { + return 234; + } + +private: + int state_; +}; + +struct root_simpl: root_sskel +{ +}; + +int +main () +{ + for (int i = 0; i < 2; ++i) + { +#ifdef XSDE_EXCEPTIONS + try + { +#endif + test_1_simpl test_1_s (i); + root_simpl root_s; + + root_s.serializers (test_1_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + + ostringstream os; + doc_s.serialize (os); + +#ifndef XSDE_EXCEPTIONS + if (xml_schema::serializer_error e = doc_s._error ()) + { + if (e.type () == xml_schema::serializer_error::schema) + { + cout << "schema: " << e.schema_text () << endl; + continue; + } + } +#endif + + root_s.post (); +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::serializer_schema const& e) + { + cout << "schema: " << e.text () << endl; + continue; + } +#endif + + cout << "no error" << endl; + } +} diff --git a/tests/cxx/serializer/validation/element/makefile b/tests/cxx/serializer/validation/element/makefile new file mode 100644 index 0000000..ef916ed --- /dev/null +++ b/tests/cxx/serializer/validation/element/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/validation/element/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/element/output b/tests/cxx/serializer/validation/element/output new file mode 100644 index 0000000..e8e09d0 --- /dev/null +++ b/tests/cxx/serializer/validation/element/output @@ -0,0 +1,2 @@ +schema: expected element not encountered +schema: expected element not encountered diff --git a/tests/cxx/serializer/validation/element/test.xsd b/tests/cxx/serializer/validation/element/test.xsd new file mode 100644 index 0000000..7f20008 --- /dev/null +++ b/tests/cxx/serializer/validation/element/test.xsd @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <sequence> + <element name="a" type="int" minOccurs="0" maxOccurs="5"/> + <element name="b" type="int" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/validation/makefile b/tests/cxx/serializer/validation/makefile new file mode 100644 index 0000000..1304574 --- /dev/null +++ b/tests/cxx/serializer/validation/makefile @@ -0,0 +1,24 @@ +# file : tests/cxx/serializer/validation/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +tests := built-in + +ifeq ($(xsde_iostream),y) +tests += any attribute choice element sequence +endif + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +.PHONY: $(default) $(test) $(clean) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/cxx/serializer/validation/sequence/driver.cxx b/tests/cxx/serializer/validation/sequence/driver.cxx new file mode 100644 index 0000000..562874c --- /dev/null +++ b/tests/cxx/serializer/validation/sequence/driver.cxx @@ -0,0 +1,102 @@ +// file : tests/cxx/serializer/validation/sequence/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test sequence validation. +// + +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct test_1_simpl: virtual test_1_sskel +{ + test_1_simpl (int state) + : state_ (state) + { + } + + virtual bool + sequence_next () + { + return true; + } + + // + // + virtual bool + sequence1_next () + { + return false; + } + + virtual int + a () + { + return 123; + } + + virtual int + b () + { + return 234; + } + +private: + int state_; +}; + +struct root_simpl: root_sskel +{ +}; + +int +main () +{ + for (int i = 0; i < 1; ++i) + { +#ifdef XSDE_EXCEPTIONS + try + { +#endif + test_1_simpl test_1_s (i); + root_simpl root_s; + + root_s.serializers (test_1_s); + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + + ostringstream os; + doc_s.serialize (os); + +#ifndef XSDE_EXCEPTIONS + if (xml_schema::serializer_error e = doc_s._error ()) + { + if (e.type () == xml_schema::serializer_error::schema) + { + cout << "schema: " << e.schema_text () << endl; + continue; + } + } +#endif + + root_s.post (); +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::serializer_schema const& e) + { + cout << "schema: " << e.text () << endl; + continue; + } +#endif + + cout << "no error" << endl; + } +} diff --git a/tests/cxx/serializer/validation/sequence/makefile b/tests/cxx/serializer/validation/sequence/makefile new file mode 100644 index 0000000..e16d8bf --- /dev/null +++ b/tests/cxx/serializer/validation/sequence/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/validation/sequence/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/validation/sequence/output b/tests/cxx/serializer/validation/sequence/output new file mode 100644 index 0000000..3333a0c --- /dev/null +++ b/tests/cxx/serializer/validation/sequence/output @@ -0,0 +1 @@ +schema: expected element not encountered diff --git a/tests/cxx/serializer/validation/sequence/test.xsd b/tests/cxx/serializer/validation/sequence/test.xsd new file mode 100644 index 0000000..d7b2517 --- /dev/null +++ b/tests/cxx/serializer/validation/sequence/test.xsd @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test-1"> + <sequence maxOccurs="5"> + <sequence maxOccurs="unbounded"> <!-- 1..unbounded--> + <element name="a" type="int"/> + <element name="b" type="int"/> + </sequence> + </sequence> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test-1" type="t:test-1"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/serializer/wildcard/driver.cxx b/tests/cxx/serializer/wildcard/driver.cxx new file mode 100644 index 0000000..195c6a0 --- /dev/null +++ b/tests/cxx/serializer/wildcard/driver.cxx @@ -0,0 +1,237 @@ +// file : tests/cxx/serializer/wildcard/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test wildcard (any & anyAttribute) serialization. +// + +#include <string.h> // strcpy +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct content_simpl: virtual content_sskel +{ + virtual int + x () + { + return 123; + } + + virtual int + a () + { + return 321; + } +}; + +struct root_simpl: virtual root_sskel +{ + virtual void + pre () + { + aa1_ = 0; + aa2_ = 0; + choice_ = 0; + ae1_ = 0; + } + + // anyAttribute + // + virtual bool + any_attribute_next () + { + return aa2_++ < 1; + } + +#ifdef XSDE_STL + virtual void + any_attribute (std::string& ns, std::string& name) + { + ns = "foo"; + name = "x"; + } +#else + virtual void + any_attribute (const char*& ns, const char*& name, bool& free) + { + char* ns_ = new char[4]; + char* name_ = new char[2]; + + strcpy (ns_, "foo"); + strcpy (name_, "x"); + + ns = ns_; + name = name_; + free = true; + } +#endif + + virtual void + serialize_any_attribute () + { + _characters ("foo#x"); + } + + virtual bool + any_attribute1_next () + { + return aa1_++ < 1; + } + +#ifdef XSDE_STL + virtual void + any_attribute1 (std::string& ns, std::string& name) + { + ns = ""; + name = "x"; + } +#else + virtual void + any_attribute1 (const char*& ns, const char*& name, bool& free) + { + ns = ""; + name = "x"; + free = false; + } +#endif + + virtual void + serialize_any_attribute1 () + { + _characters ("##local#x"); + } + + // any + // +#ifdef XSDE_STL + virtual void + any (std::string& ns, std::string& name) + { + ns = ""; + name = "a"; + } +#else + virtual void + any (const char*& ns, const char*& name, bool& free) + { + ns = ""; + name = "a"; + free = false; + } +#endif + + + virtual void + serialize_any () + { + xml_schema::int_simpl int_s; + content_simpl content_s; + + content_s.serializers (int_s, int_s); + + content_s.pre (); + content_s._pre_impl (_context ()); + content_s._serialize_attributes (); + content_s._serialize_content (); + content_s._post_impl (); + content_s.post (); + } + + virtual bool + choice_next () + { + return choice_ < 2; + } + + virtual choice_arm_tag + choice_arm () + { + return static_cast<choice_arm_tag> (choice_++); + } + + virtual bool + any1_next () + { + return ae1_ < 3; + } + +#ifdef XSDE_STL + virtual void + any1 (::std::string& ns, ::std::string& name) + { + ns = "foo"; + name = "a"; + } +#else + virtual void + any1 (const char*& ns, const char*& name, bool& free) + { + ns = "foo"; + name = "a"; + free = false; + } +#endif + + virtual void + serialize_any1 () + { + xml_schema::int_simpl s; + + s.pre (ae1_++); + s._pre_impl (_context ()); + s._serialize_content (); + s._post_impl (); + s.post (); + } + + virtual bool + any2_present () + { + return true; + } + +#ifdef XSDE_STL + virtual void + any2 (std::string& ns, std::string& name) + { + ns = "bar"; + name = "b"; + } +#else + virtual void + any2 (const char*& ns, const char*& name, bool& free) + { + ns = "bar"; + name = "b"; + free = false; + } +#endif + + virtual void + serialize_any2 () + { + _characters ("bar#b"); + } + +private: + int aa1_, aa2_; + int choice_; + int ae1_; +}; + +int +main () +{ + root_simpl root_s; + + xml_schema::document_simpl doc_s (root_s, "test", "root"); + + root_s.pre (); + doc_s.serialize (cout); + root_s.post (); +} diff --git a/tests/cxx/serializer/wildcard/makefile b/tests/cxx/serializer/wildcard/makefile new file mode 100644 index 0000000..44db0ef --- /dev/null +++ b/tests/cxx/serializer/wildcard/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/wildcard/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output + $(call message,test $$1,$$1 | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/serializer/wildcard/output b/tests/cxx/serializer/wildcard/output new file mode 100644 index 0000000..a55bc57 --- /dev/null +++ b/tests/cxx/serializer/wildcard/output @@ -0,0 +1 @@ +<g1:root xmlns:g1="test" xmlns:g2="foo" x="##local#x" g2:x="foo#x"><a x="123"><a>321</a></a><g2:a>0</g2:a><g2:a>1</g2:a><g2:a>2</g2:a><g3:b xmlns:g3="bar">bar#b</g3:b></g1:root>
\ No newline at end of file diff --git a/tests/cxx/serializer/wildcard/test.xsd b/tests/cxx/serializer/wildcard/test.xsd new file mode 100644 index 0000000..074679f --- /dev/null +++ b/tests/cxx/serializer/wildcard/test.xsd @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="content"> + <sequence> + <element name="a" type="int"/> + </sequence> + <attribute name="x" type="int" use="required"/> + </complexType> + + <complexType name="root"> + <sequence> + <any namespace="##local" processContents="skip"/> + <choice maxOccurs="unbounded"> + <any namespace="foo" processContents="skip" maxOccurs="unbounded"/> + <any namespace="bar" processContents="skip" minOccurs="0"/> + </choice> + </sequence> + <anyAttribute namespace="foo" processContents="skip"/> + <anyAttribute namespace="##local" processContents="skip"/> + </complexType> + + <element name="root" type="t:root"/> + +</schema> diff --git a/tests/cxx/string/driver.cxx b/tests/cxx/string/driver.cxx new file mode 100644 index 0000000..4b8484a --- /dev/null +++ b/tests/cxx/string/driver.cxx @@ -0,0 +1,102 @@ +// file : tests/cxx/string/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test xsde::cxx::string string type. +// +#include <assert.h> + +#include <xsde/cxx/string.hxx> + +using xsde::cxx::string; + +int +main () +{ + // Start with un-initialized string. + // + { + string s; + assert (s.data () == 0 && s.size () == 0 && s.capacity () == 0); + } + + // Test initialization with an empty string. + // + { + string s; + s.assign ("", 0); + assert (s.size () == 0 && s.capacity () == 64 && s == ""); + } + + // String starts with at least 64 bytes. + // + { + string s; + s.assign ("aaa"); + assert (s.size () == 3 && s == "aaa" && s.capacity () == 64); + } + + + // If we grow beyond 32 it should be greater of new size and 2*64. + // + { + const char v[] = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" // 32 + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "cccccccccccccccccccccccccccccccc"; + + string s; + s.assign ("aaa"); + s.assign (v); + assert (s.size () == 96 && s == v && s.capacity () == 128); + } + + // If we grow beyond 32 it should be greater of new size and 2*32. + // + { + const char v[] = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" // 32 + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "cccccccccccccccccccccccccccccccc" + "dddddddddddddddddddddddddddddddd" + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + + string s; + s.assign ("aaa"); + s.assign (v); + assert (s.size () == 159 && s == v && s.capacity () == 160); + } + + // Make sure the new capacity is even. + // + { + const char v[] = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" // 32 + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "cccccccccccccccccccccccccccccccc" + "dddddddddddddddddddddddddddddddd" + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + + string s; + s.assign ("aaa"); + s.assign (v); + assert (s.size () == 160 && s == v && s.capacity () == 162); + } + + // Test append + // + { + const char v[] = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" // 32 + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "cccccccccccccccccccccccccccccccc" + "dddddddddddddddddddddddddddddddd" + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + + string s; + s.assign ("aaa"); + s.append (&v[3]); + assert (s.size () == 160 && s == v && s.capacity () == 162); + } +} diff --git a/tests/cxx/string/makefile b/tests/cxx/string/makefile new file mode 100644 index 0000000..f9b239a --- /dev/null +++ b/tests/cxx/string/makefile @@ -0,0 +1,61 @@ +# file : tests/cxx/string/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Test. +# +.PHONY: $(test) + +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + + +# Dependencies. +# +$(call import,$(src_root)/libxsde/xsde/makefile) |