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