diff options
Diffstat (limited to 'tests/cxx/serializer/union')
-rw-r--r-- | tests/cxx/serializer/union/driver.cxx | 93 | ||||
-rw-r--r-- | tests/cxx/serializer/union/makefile | 72 | ||||
-rw-r--r-- | tests/cxx/serializer/union/output | 1 | ||||
-rw-r--r-- | tests/cxx/serializer/union/test.xsd | 25 |
4 files changed, 191 insertions, 0 deletions
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> |