diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-02-24 15:16:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-02-24 15:16:26 +0200 |
commit | 707cc94fe52463870a9c6c8e2e66eaaa389e601d (patch) | |
tree | 13e10ff28bf4455d915f9d59b401bdbb62a393cb /tests/cxx/serializer/polymorphism |
Start tracking XSD/e with git after version 3.0.03.0.0
Diffstat (limited to 'tests/cxx/serializer/polymorphism')
-rw-r--r-- | tests/cxx/serializer/polymorphism/driver.cxx | 203 | ||||
-rw-r--r-- | tests/cxx/serializer/polymorphism/makefile | 73 | ||||
-rw-r--r-- | tests/cxx/serializer/polymorphism/output | 1 | ||||
-rw-r--r-- | tests/cxx/serializer/polymorphism/test.xsd | 64 |
4 files changed, 341 insertions, 0 deletions
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> |