diff options
Diffstat (limited to 'tests/cxx/parser/polymorphism')
-rw-r--r-- | tests/cxx/parser/polymorphism/driver.cxx | 124 | ||||
-rw-r--r-- | tests/cxx/parser/polymorphism/makefile | 73 | ||||
-rw-r--r-- | tests/cxx/parser/polymorphism/output | 14 | ||||
-rw-r--r-- | tests/cxx/parser/polymorphism/test.xml | 19 | ||||
-rw-r--r-- | tests/cxx/parser/polymorphism/test.xsd | 45 |
5 files changed, 275 insertions, 0 deletions
diff --git a/tests/cxx/parser/polymorphism/driver.cxx b/tests/cxx/parser/polymorphism/driver.cxx new file mode 100644 index 0000000..e9ef3f5 --- /dev/null +++ b/tests/cxx/parser/polymorphism/driver.cxx @@ -0,0 +1,124 @@ +// file : tests/cxx/parser/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-pskel.hxx" + +using namespace std; +using namespace test; + +struct base_pimpl: base_pskel +{ + virtual void + a (int i) + { + cout << "a: " << i << endl; + } +}; + +struct interm_pimpl: interm_pskel +{ + interm_pimpl () + : interm_pskel (&base_impl_) + { + } + + virtual void + b (int i) + { + cout << "b: " << i << endl; + } + + base_pimpl base_impl_; +}; + +struct derived_pimpl: derived_pskel +{ + derived_pimpl () + : derived_pskel (&base_impl_) + { + } + + virtual void + c (int i) + { + cout << "c: " << i << endl; + } + + interm_pimpl base_impl_; +}; + +struct type_pimpl: type_pskel +{ +}; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + +#ifdef XSDE_EXCEPTIONS + try + { +#endif + xml_schema::int_pimpl int_p; + + base_pimpl base_p; + interm_pimpl interm_p; + derived_pimpl derived_p; + + xml_schema::parser_map_impl map (5); + type_pimpl type_p; + + base_p.parsers (int_p); + interm_p.parsers (int_p, int_p); + derived_p.parsers (int_p, int_p, int_p); + + map.insert (base_p); + map.insert (interm_p); + map.insert (derived_p); + + type_p.base_parser (map); + + xml_schema::document_pimpl doc_p (type_p, "test", "root", true); + + type_p.pre (); + doc_p.parse (argv[1]); + +#ifndef XSDE_EXCEPTIONS + if (doc_p._error ()) + { + cerr << "error" << endl; + return 1; + } +#endif + + type_p.post_type (); + + // Test parser resetting. + // + doc_p.reset (); + +#ifdef XSDE_EXCEPTIONS + } + catch (xml_schema::parser_exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +#endif +} diff --git a/tests/cxx/parser/polymorphism/makefile b/tests/cxx/parser/polymorphism/makefile new file mode 100644 index 0000000..628ef02 --- /dev/null +++ b/tests/cxx/parser/polymorphism/makefile @@ -0,0 +1,73 @@ +# file : tests/cxx/parser/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=-pskel.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=-pskel.hxx) \ + $(out_base)/$(xsd:.xsd=-pskel.ixx) \ + $(out_base)/$(xsd:.xsd=-pskel.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)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | 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=-pskel.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/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/parser/polymorphism/output b/tests/cxx/parser/polymorphism/output new file mode 100644 index 0000000..87168ca --- /dev/null +++ b/tests/cxx/parser/polymorphism/output @@ -0,0 +1,14 @@ +a: 1 +a: 1 +b: 2 +a: 1 +b: 2 +a: 1 +b: 2 +c: 3 +a: 1 +b: 2 +c: 3 +a: 1 +a: 1 +a: 1 diff --git a/tests/cxx/parser/polymorphism/test.xml b/tests/cxx/parser/polymorphism/test.xml new file mode 100644 index 0000000..8e635cc --- /dev/null +++ b/tests/cxx/parser/polymorphism/test.xml @@ -0,0 +1,19 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <t:base><a>1</a></t:base> + + <t:base xsi:type="t:interm"><a>1</a><b>2</b></t:base> + <t:interm><a>1</a><b>2</b></t:interm> + + <t:base xsi:type="t:derived"><a>1</a><b>2</b><c>3</c></t:base> + <t:derived><a>1</a><b>2</b><c>3</c></t:derived> + + <!-- same type substitution --> + + <t:another-base><a>1</a></t:another-base> + <t:base xsi:type="t:base"><a>1</a></t:base> + <t:another-base xsi:type="t:base"><a>1</a></t:another-base> + +</t:root> diff --git a/tests/cxx/parser/polymorphism/test.xsd b/tests/cxx/parser/polymorphism/test.xsd new file mode 100644 index 0000000..80c5e06 --- /dev/null +++ b/tests/cxx/parser/polymorphism/test.xsd @@ -0,0 +1,45 @@ +<?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"/> + <element name="another-base" type="t:base" substitutionGroup="t:base"/> + + <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"> + <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> |