aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-03-26 17:09:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-03-26 17:09:53 +0200
commite4c22d3686da0e973e21eae0561c1169c0eeff36 (patch)
tree0a49e9167edc88938b0287949080931314e8afea /tests/cxx
parent0d62005a3ff3b62d02c2eb3fd8644e0e19b202e8 (diff)
Implement support for XML Schema polymorphism in C++/Hybrid
examples/cxx/hybrid/polyroot/ examples/cxx/hybrid/polymorphism/: new examples tests/cxx/hybrid/polymorphism/: new tests
Diffstat (limited to 'tests/cxx')
-rw-r--r--tests/cxx/hybrid/makefile2
-rw-r--r--tests/cxx/hybrid/polymorphism/any-type/driver.cxx59
-rw-r--r--tests/cxx/hybrid/polymorphism/any-type/makefile99
-rw-r--r--tests/cxx/hybrid/polymorphism/any-type/test.xml7
-rw-r--r--tests/cxx/hybrid/polymorphism/any-type/test.xsd37
-rw-r--r--tests/cxx/hybrid/polymorphism/makefile24
-rw-r--r--tests/cxx/hybrid/polymorphism/multischema/driver.cxx60
-rw-r--r--tests/cxx/hybrid/polymorphism/multischema/makefile100
-rw-r--r--tests/cxx/hybrid/polymorphism/multischema/output1
-rw-r--r--tests/cxx/hybrid/polymorphism/multischema/test.xml7
-rw-r--r--tests/cxx/hybrid/polymorphism/multischema/test.xsd28
-rw-r--r--tests/cxx/hybrid/polymorphism/multischema/type.xsd26
12 files changed, 449 insertions, 1 deletions
diff --git a/tests/cxx/hybrid/makefile b/tests/cxx/hybrid/makefile
index 2ea9a3d..24ed1f0 100644
--- a/tests/cxx/hybrid/makefile
+++ b/tests/cxx/hybrid/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
-tests := sequences
+tests := polymorphism sequences
ifeq ($(xsde_iostream),y)
tests += built-in list recursive test-template union
diff --git a/tests/cxx/hybrid/polymorphism/any-type/driver.cxx b/tests/cxx/hybrid/polymorphism/any-type/driver.cxx
new file mode 100644
index 0000000..555c145
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/any-type/driver.cxx
@@ -0,0 +1,59 @@
+// file : tests/cxx/hybrid/polymorphism/any-type/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 polymorphic parsing and serialization of anyType-based hierarchy.
+//
+
+#include <iostream>
+
+#include "test.hxx"
+#include "test-pimpl.hxx"
+#include "test-simpl.hxx"
+
+using namespace std;
+using namespace test;
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " test.xml" << endl;
+ return 1;
+ }
+
+ // Parse.
+ //
+ root_paggr root_p;
+
+ xml_schema::document_pimpl doc_p (
+ root_p.root_parser (),
+ root_p.root_namespace (),
+ root_p.root_name (),
+ true);
+
+ root_p.pre ();
+ doc_p.parse (argv[1]);
+ type* r = root_p.post ();
+
+ // Serialize.
+ //
+ root_saggr root_s;
+
+ xml_schema::document_simpl doc_s (
+ root_s.root_serializer (),
+ root_s.root_namespace (),
+ root_s.root_name (),
+ true);
+
+ doc_s.add_prefix ("t", "test");
+ doc_s.add_prefix ("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+
+ root_s.pre (*r);
+ doc_s.serialize (cout);
+ root_s.post ();
+
+ delete r;
+}
diff --git a/tests/cxx/hybrid/polymorphism/any-type/makefile b/tests/cxx/hybrid/polymorphism/any-type/makefile
new file mode 100644
index 0000000..57d58f6
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/any-type/makefile
@@ -0,0 +1,99 @@
+# file : tests/cxx/hybrid/polymorphism/any-type/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=.o) \
+$(xsd:.xsd=-pskel.o) \
+$(xsd:.xsd=-pimpl.o) \
+$(xsd:.xsd=-sskel.o) \
+$(xsd:.xsd=-simpl.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)
+
+genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \
+ $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \
+ $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \
+ $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \
+ $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx)
+
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(out_root)/xsde/xsde
+$(gen): xsde := $(out_root)/xsde/xsde
+$(gen): xsde_options += --generate-parser --generate-serializer \
+--generate-aggregate --generate-polymorphic --generate-typeinfo \
+--root-element root --polymorphic-type anyType
+
+$(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 -ubB $(src_base)/output -,$(driver))
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean))
+
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(gen): | $(out_base)/.gitignore
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+
+# 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/hybrid/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsde/makefile)
+$(call import,$(src_root)/libxsde/xsde/makefile)
diff --git a/tests/cxx/hybrid/polymorphism/any-type/test.xml b/tests/cxx/hybrid/polymorphism/any-type/test.xml
new file mode 100644
index 0000000..f0a8bcb
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/any-type/test.xml
@@ -0,0 +1,7 @@
+<t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <t:any><x>abc</x>junk<y>123</y></t:any>
+ <t:base ><a>123</a><b>abc</b></t:base>
+ <t:any xsi:type="t:derived"><a>123</a><b>abc</b><c>9</c><c>8</c><c>7</c></t:any>
+
+</t:root>
diff --git a/tests/cxx/hybrid/polymorphism/any-type/test.xsd b/tests/cxx/hybrid/polymorphism/any-type/test.xsd
new file mode 100644
index 0000000..33b5251
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/any-type/test.xsd
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <element name="any" type="anyType"/>
+
+ <complexType name="base">
+ <complexContent>
+ <restriction base="anyType">
+ <sequence>
+ <element name="a" type="int"/>
+ <element name="b" type="string"/>
+ </sequence>
+ </restriction>
+ </complexContent>
+ </complexType>
+
+ <element name="base" type="t:base" substitutionGroup="t:any"/>
+
+ <complexType name="derived">
+ <complexContent>
+ <extension base="t:base">
+ <sequence>
+ <element name="c" type="int" maxOccurs="unbounded"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="type">
+ <sequence>
+ <element ref="t:any" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <element name="root" type="t:type"/>
+
+</schema>
diff --git a/tests/cxx/hybrid/polymorphism/makefile b/tests/cxx/hybrid/polymorphism/makefile
new file mode 100644
index 0000000..921ceae
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/makefile
@@ -0,0 +1,24 @@
+# file : tests/cxx/hybrid/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
+
+tests :=
+
+ifeq ($(xsde_iostream),y)
+tests += multischema
+endif
+
+default := $(out_base)/
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+.PHONY: $(default) $(test) $(clean)
+
+$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests)))
+$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests)))
+$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests)))
+
+$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile))
diff --git a/tests/cxx/hybrid/polymorphism/multischema/driver.cxx b/tests/cxx/hybrid/polymorphism/multischema/driver.cxx
new file mode 100644
index 0000000..895d600
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/multischema/driver.cxx
@@ -0,0 +1,60 @@
+// file : tests/cxx/hybrid/polymorphism/multischema/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 polymorphic parsing and serialization with the type hierarchy
+// split into several schemas.
+//
+
+#include <iostream>
+
+#include "test.hxx"
+#include "test-pimpl.hxx"
+#include "test-simpl.hxx"
+
+using namespace std;
+using namespace test;
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " test.xml" << endl;
+ return 1;
+ }
+
+ // Parse.
+ //
+ root_paggr root_p;
+
+ xml_schema::document_pimpl doc_p (
+ root_p.root_parser (),
+ root_p.root_namespace (),
+ root_p.root_name (),
+ true);
+
+ root_p.pre ();
+ doc_p.parse (argv[1]);
+ type* r = root_p.post ();
+
+ // Serialize.
+ //
+ root_saggr root_s;
+
+ xml_schema::document_simpl doc_s (
+ root_s.root_serializer (),
+ root_s.root_namespace (),
+ root_s.root_name (),
+ true);
+
+ doc_s.add_prefix ("t", "test");
+ doc_s.add_prefix ("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+
+ root_s.pre (*r);
+ doc_s.serialize (cout);
+ root_s.post ();
+
+ delete r;
+}
diff --git a/tests/cxx/hybrid/polymorphism/multischema/makefile b/tests/cxx/hybrid/polymorphism/multischema/makefile
new file mode 100644
index 0000000..c0db0f2
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/multischema/makefile
@@ -0,0 +1,100 @@
+# file : tests/cxx/hybrid/polymorphism/multischema/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 type.xsd
+cxx := driver.cxx
+
+obj := $(addprefix $(out_base)/,\
+$(cxx:.cxx=.o) \
+$(xsd:.xsd=.o) \
+$(xsd:.xsd=-pskel.o) \
+$(xsd:.xsd=-pimpl.o) \
+$(xsd:.xsd=-sskel.o) \
+$(xsd:.xsd=-simpl.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)
+
+genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \
+ $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \
+ $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \
+ $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \
+ $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx)
+
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(out_root)/xsde/xsde
+$(gen): xsde := $(out_root)/xsde/xsde
+$(gen): xsde_options += --generate-parser --generate-serializer \
+--generate-aggregate --generate-polymorphic --generate-typeinfo \
+--polymorphic-type base --polymorphic-schema $(src_base)/type.xsd \
+--include-regex '%.*/([^/]*)%$$$$1%'
+
+$(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 -ubB $(src_base)/output -,$(driver))
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean))
+
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(gen): | $(out_base)/.gitignore
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+
+# 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/hybrid/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsde/makefile)
+$(call import,$(src_root)/libxsde/xsde/makefile)
diff --git a/tests/cxx/hybrid/polymorphism/multischema/output b/tests/cxx/hybrid/polymorphism/multischema/output
new file mode 100644
index 0000000..341775b
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/multischema/output
@@ -0,0 +1 @@
+<t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><x xsi:type="t:foo"><a>abc</a><b>123</b></x><x xsi:type="t:bar"><a>abc</a><b>true</b></x><x xsi:type="t:baz"><a>abc</a><b>123</b><c>true</c></x></t:root> \ No newline at end of file
diff --git a/tests/cxx/hybrid/polymorphism/multischema/test.xml b/tests/cxx/hybrid/polymorphism/multischema/test.xml
new file mode 100644
index 0000000..d6e3e43
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/multischema/test.xml
@@ -0,0 +1,7 @@
+<t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <x xsi:type="t:foo"><a>abc</a><b>123</b></x>
+ <x xsi:type="t:bar"><a>abc</a><b>true</b></x>
+ <x xsi:type="t:baz"><a>abc</a><b>123</b><c>true</c></x>
+
+</t:root>
diff --git a/tests/cxx/hybrid/polymorphism/multischema/test.xsd b/tests/cxx/hybrid/polymorphism/multischema/test.xsd
new file mode 100644
index 0000000..ed5a666
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/multischema/test.xsd
@@ -0,0 +1,28 @@
+<?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="string"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="foo">
+ <complexContent>
+ <extension base="t:base">
+ <sequence>
+ <element name="b" type="int"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="type">
+ <sequence>
+ <element name="x" type="t:base" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <element name="root" type="t:type"/>
+
+</schema>
diff --git a/tests/cxx/hybrid/polymorphism/multischema/type.xsd b/tests/cxx/hybrid/polymorphism/multischema/type.xsd
new file mode 100644
index 0000000..cb93000
--- /dev/null
+++ b/tests/cxx/hybrid/polymorphism/multischema/type.xsd
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <include schemaLocation="test.xsd"/>
+
+ <complexType name="bar">
+ <complexContent>
+ <extension base="t:base">
+ <sequence>
+ <element name="b" type="boolean"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="baz">
+ <complexContent>
+ <extension base="t:foo">
+ <sequence>
+ <element name="c" type="boolean"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>