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/wildcard |
Start tracking XSD/e with git after version 3.0.03.0.0
Diffstat (limited to 'tests/cxx/serializer/wildcard')
-rw-r--r-- | tests/cxx/serializer/wildcard/driver.cxx | 237 | ||||
-rw-r--r-- | tests/cxx/serializer/wildcard/makefile | 72 | ||||
-rw-r--r-- | tests/cxx/serializer/wildcard/output | 1 | ||||
-rw-r--r-- | tests/cxx/serializer/wildcard/test.xsd | 25 |
4 files changed, 335 insertions, 0 deletions
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> |