aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-01-22 15:40:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-01-22 15:40:12 +0200
commitf60df03e3cedb86508645357e17003eb9281f31a (patch)
treed65c9cd62a6500b7d0f8303caf64797d08f508c0 /tests
parent55ffb84acf75d3fa475dfe21d053e404eb753e5a (diff)
Add support for detaching subtrees in C++/Tree
New option: --generate-detach. New test: cxx/tree/detach.
Diffstat (limited to 'tests')
-rw-r--r--tests/cxx/tree/detach/driver.cxx101
-rw-r--r--tests/cxx/tree/detach/makefile82
-rw-r--r--tests/cxx/tree/detach/test.xsd32
-rw-r--r--tests/cxx/tree/makefile1
4 files changed, 216 insertions, 0 deletions
diff --git a/tests/cxx/tree/detach/driver.cxx b/tests/cxx/tree/detach/driver.cxx
new file mode 100644
index 0000000..afcb90d
--- /dev/null
+++ b/tests/cxx/tree/detach/driver.cxx
@@ -0,0 +1,101 @@
+// file : tests/cxx/tree/detach/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+// Test the detach functionality.
+//
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+
+#include "test.hxx"
+
+using namespace std;
+using namespace test;
+
+int
+main ()
+{
+ // Construct the model.
+ //
+ object o1 ("o1");
+ o1.data ().push_back ("1-1");
+ o1.data ().push_back ("1-2");
+ o1.data ().push_back ("1-3");
+
+ object o2 ("o2");
+ o1.data ().push_back ("2-1");
+ o1.data ().push_back ("2-2");
+ o1.data ().push_back ("2-3");
+
+ object o3 ("o3");
+ o1.data ().push_back ("3-1");
+ o1.data ().push_back ("3-2");
+ o1.data ().push_back ("3-3");
+
+ object o4 ("o4");
+ o1.data ().push_back ("4-1");
+ o1.data ().push_back ("4-2");
+ o1.data ().push_back ("4-3");
+
+ subtree s1;
+ s1.o ().push_back (o1);
+ s1.o ().push_back (o2);
+ s1.r ().push_back (ref ("o2"));
+ s1.r ().push_back (ref ("o3"));
+
+ subtree s2;
+ s2.o ().push_back (o3);
+ s2.o ().push_back (o4);
+ s2.r ().push_back (ref ("o4"));
+ s2.r ().push_back (ref ("o1"));
+
+ model m;
+ m.one (s1);
+ m.opt (s2);
+
+ // Detach one.
+ //
+ auto_ptr<subtree> p (m.detach_one ());
+ assert (p->_container () == 0);
+ assert (p->r ()[0].get () == &p->o ()[1]);
+ assert (m.opt ()->r ()[1].get () == 0);
+
+ m.one (p);
+ assert (m.opt ()->r ()[1].get () == &m.one ().o ()[0]);
+ p = m.detach_one ();
+
+ model m1;
+ m1.one (p);
+ m1.opt (s2);
+ assert (m1.opt ()->r ()[1].get () == &m1.one ().o ()[0]);
+
+ p = m1.detach_one ();
+ m.seq ().push_back (p);
+
+ // Detach opt.
+ //
+ p = m.opt ().detach ();
+ assert (!m.opt ());
+ assert (p->_container () == 0);
+ assert (p->r ()[0].get () == &p->o ()[1]);
+ assert (m.seq ()[0].r ()[1].get () == 0);
+
+ m.seq ().push_back (p);
+
+ // Detach seq.
+ //
+ p = m.seq ().detach_back ();
+ assert (p->_container () == 0);
+ assert (p->r ()[0].get () == &p->o ()[1]);
+ assert (m.seq ()[0].r ()[1].get () == 0);
+
+ m.seq ().push_back (p);
+ assert (m.seq ()[0].r ()[1].get () == &m.seq ()[1].o ()[0]);
+
+ m.seq ().detach (m.seq ().begin (), p);
+ assert (p->_container () == 0);
+ assert (p->r ()[0].get () == &p->o ()[1]);
+ assert (m.seq ()[0].r ()[1].get () == 0);
+}
diff --git a/tests/cxx/tree/detach/makefile b/tests/cxx/tree/detach/makefile
new file mode 100644
index 0000000..938fba2
--- /dev/null
+++ b/tests/cxx/tree/detach/makefile
@@ -0,0 +1,82 @@
+# file : tests/cxx/tree/detach/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2006-2010 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)
+
+genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.ixx) $(xsd:.xsd=.cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): xsd := $(out_root)/xsd/xsd
+$(gen): xsd_options := --generate-detach --generate-default-ctor
+$(gen): $(out_root)/xsd/xsd
+
+$(call include-dep,$(dep))
+
+# Convenience alias for default target.
+#
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+$(test): driver := $(driver)
+$(test): $(driver)
+ $(call message,test $$1,$$1,$(driver))
+
+# 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)/xsd/tree/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsd/makefile)
diff --git a/tests/cxx/tree/detach/test.xsd b/tests/cxx/tree/detach/test.xsd
new file mode 100644
index 0000000..b9f5166
--- /dev/null
+++ b/tests/cxx/tree/detach/test.xsd
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <complexType name="object">
+ <sequence>
+ <element name="data" type="string" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="id" type="ID" use="required"/>
+ </complexType>
+
+ <complexType name="ref">
+ <simpleContent>
+ <extension base="IDREF"/>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="subtree">
+ <sequence>
+ <element name="o" type="t:object" minOccurs="0" maxOccurs="unbounded"/>
+ <element name="r" type="t:ref" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="model">
+ <sequence>
+ <element name="one" type="t:subtree"/>
+ <element name="opt" type="t:subtree" minOccurs="0"/>
+ <element name="seq" type="t:subtree" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+</schema>
diff --git a/tests/cxx/tree/makefile b/tests/cxx/tree/makefile
index da848e8..9b79424 100644
--- a/tests/cxx/tree/makefile
+++ b/tests/cxx/tree/makefile
@@ -13,6 +13,7 @@ compilation \
complex \
containment \
default \
+detach \
encoding \
enumeration \
float \