summaryrefslogtreecommitdiff
path: root/tests/cxx/tree/complex
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cxx/tree/complex')
-rw-r--r--tests/cxx/tree/complex/ctor/driver.cxx112
-rw-r--r--tests/cxx/tree/complex/ctor/makefile83
-rw-r--r--tests/cxx/tree/complex/ctor/test.xsd182
-rw-r--r--tests/cxx/tree/complex/makefile20
4 files changed, 397 insertions, 0 deletions
diff --git a/tests/cxx/tree/complex/ctor/driver.cxx b/tests/cxx/tree/complex/ctor/driver.cxx
new file mode 100644
index 0000000..a46bac8
--- /dev/null
+++ b/tests/cxx/tree/complex/ctor/driver.cxx
@@ -0,0 +1,112 @@
+// file : tests/cxx/tree/complex/ctor/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 generation of varous complex type constructors.
+//
+
+#include <cassert>
+#include <memory>
+
+#include "test.hxx"
+
+using namespace std;
+using namespace test;
+
+int
+main ()
+{
+ // Test case A.
+ //
+ {
+ a_base b1;
+ a_base b2 ("abc"); // empty ultimate base + required
+ a_base b3 ("abc", "foo"); // ultimate base + required
+
+ a_derived a1;
+ a_derived a2 ("foo", "bar"); // empty ultimate base + required
+ a_derived a3 (b3, "bar"); // base + required
+ a_derived a4 ("abc", "foo", "bar"); // ultimate base + required
+ }
+
+ // Test case B.
+ //
+ {
+ b_simple s ("base");
+ b_base b ("base", "foo");
+ b_derived d ("base", "foo", "bar");
+ b_type t ("base");
+ }
+
+ // Test case C.
+ //
+ {
+ c_simple s (c_enum::a);
+ c_base b (c_enum::a, "foo");
+ c_derived d (c_enum::a, "foo", "bar");
+ c_type t (c_enum::a);
+ }
+
+ // Test case D.
+ //
+ {
+ d_simple s (1);
+ d_base b (1, "foo");
+ d_derived d (1, "foo", "bar");
+ d_type t (1);
+ }
+
+ // Test case E.
+ //
+ {
+ // e_base
+ //
+ e_base b1 (1, "foo", e_complex_type ("bar"));
+
+ auto_ptr<e_complex_type> c2 (new e_complex_type ("bar"));
+ e_base b2 (1, "foo", c2);
+
+ auto_ptr<e_simple_type> s3 (new e_simple_type ("foo"));
+ auto_ptr<e_complex_type> c3 (new e_complex_type ("bar"));
+ e_base b3 (1, s3, c3);
+
+ assert (b1 == b2);
+ assert (b1 == b3);
+
+ // e_derived
+ //
+ e_derived d1 (1, "foo", e_complex_type ("bar"),
+ true, "baz", e_complex_type ("biz"));
+
+ auto_ptr<e_complex_type> c2a (new e_complex_type ("bar"));
+ auto_ptr<e_complex_type> c2b (new e_complex_type ("biz"));
+ e_derived d2 (1, "foo", c2a, true, "baz", c2b);
+
+ auto_ptr<e_simple_type> s3a (new e_simple_type ("foo"));
+ auto_ptr<xml_schema::string> s3b (new xml_schema::string ("baz"));
+ auto_ptr<e_complex_type> c3a (new e_complex_type ("bar"));
+ auto_ptr<e_complex_type> c3b (new e_complex_type ("biz"));
+ e_derived d3 (1, s3a, c3a, true, s3b, c3b);
+
+ assert (d1 == d2);
+ assert (d1 == d3);
+
+ }
+
+ // Test case F.
+ //
+ {
+ f_type f1 (xml_schema::type (), 1, "foo", f_complex_type ("bar"));
+
+ auto_ptr<f_complex_type> c2 (new f_complex_type ("bar"));
+ f_type f2 (1, "foo", c2);
+
+ auto_ptr<f_simple_type> s3 (new f_simple_type ("foo"));
+ auto_ptr<f_complex_type> c3 (new f_complex_type ("bar"));
+ f_type f3 (1, s3, c3);
+
+ assert (f1 == f2);
+ assert (f1 == f3);
+ }
+}
diff --git a/tests/cxx/tree/complex/ctor/makefile b/tests/cxx/tree/complex/ctor/makefile
new file mode 100644
index 0000000..4894a6f
--- /dev/null
+++ b/tests/cxx/tree/complex/ctor/makefile
@@ -0,0 +1,83 @@
+# file : tests/cxx/tree/complex/ctor/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))
+dep := $(obj:.o=.o.d)
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/libxerces-c/stub.make,\
+ l: xerces_c.l,cpp-options: xerces_c.l.cpp-options)
+
+
+# Build.
+#
+$(driver): $(obj) $(xerces_c.l)
+
+$(obj) $(dep): cpp_options := -I$(src_root)/libxsd
+$(obj) $(dep): $(xerces_c.l.cpp-options)
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): xsd := $(out_root)/xsd/xsd
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): xsd_options := --generate-default-ctor \
+--generate-from-base-ctor --generate-doxygen --generate-polymorphic \
+--generate-comparison
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): $(out_root)/xsd/xsd
+
+$(call include-dep,$(dep))
+
+# Convenience alias for default target.
+#
+.PHONY: $(out_base)/
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+.PHONY: $(test)
+
+$(test): driver := $(driver)
+$(test): $(driver)
+ $(call message,test $$1,$$1,$(driver))
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(xsd:.xsd=.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)/xsd/tree/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsd/makefile)
diff --git a/tests/cxx/tree/complex/ctor/test.xsd b/tests/cxx/tree/complex/ctor/test.xsd
new file mode 100644
index 0000000..b8dd95e
--- /dev/null
+++ b/tests/cxx/tree/complex/ctor/test.xsd
@@ -0,0 +1,182 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <!-- Test case A: several levels of inheritance with ultimate base. -->
+
+ <complexType name="a_base">
+ <simpleContent>
+ <extension base="string">
+ <attribute name="foo" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="a_derived">
+ <simpleContent>
+ <extension base="t:a_base">
+ <attribute name="bar" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <!-- Test case B: string-based c-tors. -->
+
+ <simpleType name="b_simple">
+ <restriction base="string">
+ </restriction>
+ </simpleType>
+
+ <complexType name="b_base">
+ <simpleContent>
+ <extension base="t:b_simple">
+ <attribute name="foo" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="b_derived">
+ <simpleContent>
+ <extension base="t:b_base">
+ <attribute name="bar" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="b_type">
+ <sequence>
+ <element name="a" type="t:b_simple"/>
+ </sequence>
+ </complexType>
+
+ <!-- Test case C: enum-based c-tors. -->
+
+ <simpleType name="c_enum_base">
+ <restriction base="string">
+ <enumeration value="a"/>
+ <enumeration value="b"/>
+ <enumeration value="c"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="c_enum">
+ <restriction base="t:c_enum_base">
+ <enumeration value="a"/>
+ <enumeration value="c"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="c_simple">
+ <restriction base="t:c_enum">
+ </restriction>
+ </simpleType>
+
+ <complexType name="c_base">
+ <simpleContent>
+ <extension base="t:c_simple">
+ <attribute name="foo" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="c_derived">
+ <simpleContent>
+ <extension base="t:c_base">
+ <attribute name="bar" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="c_type">
+ <sequence>
+ <element name="a" type="t:c_simple"/>
+ </sequence>
+ </complexType>
+
+ <!-- Test case D: fundamental type c-tors. -->
+
+ <simpleType name="d_simple">
+ <restriction base="int">
+ </restriction>
+ </simpleType>
+
+ <complexType name="d_base">
+ <simpleContent>
+ <extension base="t:d_simple">
+ <attribute name="foo" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="d_derived">
+ <simpleContent>
+ <extension base="t:d_base">
+ <attribute name="bar" type="string" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="d_type">
+ <sequence>
+ <element name="a" type="t:d_simple"/>
+ </sequence>
+ </complexType>
+
+ <!-- Test case E: auto_ptr ctors. -->
+
+ <simpleType name="e_simple_type">
+ <restriction base="string">
+ </restriction>
+ </simpleType>
+
+ <complexType name="e_complex_type">
+ <sequence>
+ <element name="a" type="string"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="e_base">
+ <sequence>
+ <element name="fund" type="int"/>
+ <element name="simple" type="t:e_simple_type"/>
+ <element name="complex" type="t:e_complex_type"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="e_derived">
+ <complexContent>
+ <extension base="t:e_base">
+ <sequence>
+ <element name="fund1" type="boolean"/>
+ <element name="simple1" type="string"/>
+ <element name="complex1" type="t:e_complex_type"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <!-- Test case F: auto_ptr args in c-tor (all-non-optional-members) -->
+
+ <simpleType name="f_simple_type">
+ <restriction base="string">
+ </restriction>
+ </simpleType>
+
+ <complexType name="f_complex_type">
+ <sequence>
+ <element name="a" type="string"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="f_type">
+ <complexContent>
+ <restriction base="anyType">
+ <sequence>
+ <element name="fund" type="int"/>
+ <element name="simple" type="t:f_simple_type"/>
+ <element name="complex" type="t:f_complex_type"/>
+ </sequence>
+ </restriction>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/tests/cxx/tree/complex/makefile b/tests/cxx/tree/complex/makefile
new file mode 100644
index 0000000..ed6e5de
--- /dev/null
+++ b/tests/cxx/tree/complex/makefile
@@ -0,0 +1,20 @@
+# file : tests/cxx/tree/complex/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 := ctor
+
+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))