diff options
Diffstat (limited to 'tests/cxx/serializer/validation/any')
-rw-r--r-- | tests/cxx/serializer/validation/any/driver.cxx | 317 | ||||
-rw-r--r-- | tests/cxx/serializer/validation/any/makefile | 72 | ||||
-rw-r--r-- | tests/cxx/serializer/validation/any/output | 9 | ||||
-rw-r--r-- | tests/cxx/serializer/validation/any/test.xsd | 53 |
4 files changed, 451 insertions, 0 deletions
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> |