summaryrefslogtreecommitdiff
path: root/xsd-tests/cxx/tree/containment
diff options
context:
space:
mode:
Diffstat (limited to 'xsd-tests/cxx/tree/containment')
-rw-r--r--xsd-tests/cxx/tree/containment/buildfile20
-rw-r--r--xsd-tests/cxx/tree/containment/driver.cxx118
-rw-r--r--xsd-tests/cxx/tree/containment/test.xsd59
3 files changed, 197 insertions, 0 deletions
diff --git a/xsd-tests/cxx/tree/containment/buildfile b/xsd-tests/cxx/tree/containment/buildfile
new file mode 100644
index 0000000..1d0272b
--- /dev/null
+++ b/xsd-tests/cxx/tree/containment/buildfile
@@ -0,0 +1,20 @@
+# file : cxx/tree/containment/buildfile
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+import libs = libxsd%lib{xsd}
+import libs += libxerces-c%lib{xerces-c}
+
+exe{driver}: {hxx cxx}{* -test} {hxx ixx cxx}{test} $libs
+
+<{hxx ixx cxx}{test}>: xsd{test} $xsd
+{{
+ diag xsd ($<[0]) # @@ TMP
+
+ $xsd cxx-tree --std c++11 \
+ --generate-inline \
+ --generate-default-ctor \
+ --output-dir $out_base \
+ $path($<[0])
+}}
+
+cxx.poptions =+ "-I$out_base"
diff --git a/xsd-tests/cxx/tree/containment/driver.cxx b/xsd-tests/cxx/tree/containment/driver.cxx
new file mode 100644
index 0000000..65c17fc
--- /dev/null
+++ b/xsd-tests/cxx/tree/containment/driver.cxx
@@ -0,0 +1,118 @@
+// file : cxx/tree/containment/driver.cxx
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+// Test tree node containment.
+//
+
+#include <memory> // std::auto_ptr/unique_ptr
+#include <cassert>
+
+#include "test.hxx"
+
+#ifdef XSD_CXX11
+# include <utility> // std::move
+# define XSD_MOVE(x) std::move(x)
+#else
+# define XSD_MOVE(x) x
+#endif
+
+using namespace std;
+using namespace test;
+
+int
+main ()
+{
+ // Change of a container in a sub-tree without ID.
+ //
+ {
+ XSD_AUTO_PTR<inner> i (new inner ());
+ i->ref ("foo");
+
+ outer o;
+ o.i (XSD_MOVE (i));
+ o.ref ("foo");
+
+ assert (o.i ()->ref ()->get () == 0);
+ assert (o.ref ()->get () == 0);
+ }
+
+ // Change of container in a sub-tree with ID inside.
+ //
+ {
+ XSD_AUTO_PTR<inner> i (new inner ());
+ inner* p (i.get ());
+ i->id ("foo");
+ i->ref ("foo");
+ assert (i->ref ()->get () == p);
+
+ outer o;
+ o.i (XSD_MOVE (i));
+ o.ref ("foo");
+
+ assert (o.i ()->ref ()->get () == p);
+ assert (o.ref ()->get () == p);
+ }
+
+ // Change of a container in ID.
+ //
+ {
+ XSD_AUTO_PTR<xml_schema::id> id (new xml_schema::id ("foo"));
+
+ inner i;
+ i.id (XSD_MOVE (id));
+ i.ref ("foo");
+ assert (i.ref ()->get () == &i);
+ }
+
+ // Change of a container in a type derived from ID with ID inside.
+ //
+ {
+ XSD_AUTO_PTR<id_ex> id (new id_ex ("foo"));
+ id_ex* p (id.get ());
+ id->id ("bar");
+
+ inner i;
+ i.id_ex (XSD_MOVE (id));
+
+ i.ref ("foo");
+ assert (i.ref ()->get () == &i);
+
+ i.ref ("bar");
+ assert (i.ref ()->get () == p);
+ }
+
+ // IDREF lists
+ //
+ {
+ id i1 ("a"), i2 ("b");
+
+ XSD_AUTO_PTR<ids> ic (new ids);
+ ic->id ().push_back (i1);
+ ic->id ().push_back (i2);
+
+ XSD_AUTO_PTR<xml_schema::idrefs> r1 (new xml_schema::idrefs);
+ r1->push_back (xml_schema::idref ("a"));
+ r1->push_back (xml_schema::idref ("b"));
+
+ XSD_AUTO_PTR<idref_list> r2 (new idref_list);
+ r2->push_back (xml_schema::idref ("a"));
+ r2->push_back (xml_schema::idref ("b"));
+
+ XSD_AUTO_PTR<idrefs1> rc1 (new idrefs1);
+ XSD_AUTO_PTR<idrefs2> rc2 (new idrefs2);
+
+ rc1->idrefs (XSD_MOVE (r1));
+ rc2->idrefs (XSD_MOVE (r2));
+
+ model m;
+ m.ids (XSD_MOVE (ic));
+ m.idrefs1 (XSD_MOVE (rc1));
+ m.idrefs2 (XSD_MOVE (rc2));
+
+ assert (m.idrefs1 ().idrefs ()[0].get () != 0);
+ assert (m.idrefs1 ().idrefs ()[1].get () != 0);
+
+ assert (m.idrefs2 ().idrefs ()[0].get () != 0);
+ assert (m.idrefs2 ().idrefs ()[1].get () != 0);
+ }
+}
diff --git a/xsd-tests/cxx/tree/containment/test.xsd b/xsd-tests/cxx/tree/containment/test.xsd
new file mode 100644
index 0000000..72c9379
--- /dev/null
+++ b/xsd-tests/cxx/tree/containment/test.xsd
@@ -0,0 +1,59 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <complexType name="id-ex">
+ <simpleContent>
+ <extension base="ID">
+ <attribute name="id" type="ID"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <complexType name="inner">
+ <sequence>
+ <element name="id" type="ID" minOccurs="0"/>
+ <element name="id-ex" type="t:id-ex" minOccurs="0"/>
+ <element name="ref" type="IDREF" minOccurs="0"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="outer">
+ <sequence>
+ <element name="i" type="t:inner" minOccurs="0"/>
+ <element name="ref" type="IDREF" minOccurs="0"/>
+ </sequence>
+ </complexType>
+
+ <!-- IDREF lists -->
+
+ <complexType name="id">
+ <attribute name="id" type="ID" use="required"/>
+ </complexType>
+
+ <complexType name="ids">
+ <sequence>
+ <element name="id" type="t:id" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="idrefs1">
+ <attribute name="idrefs" type="IDREFS" use="required"/>
+ </complexType>
+
+ <simpleType name="idref-list">
+ <list itemType="IDREF"/>
+ </simpleType>
+
+ <complexType name="idrefs2">
+ <attribute name="idrefs" type="t:idref-list" use="required"/>
+ </complexType>
+
+ <complexType name="model">
+ <sequence>
+ <element name="ids" type="t:ids"/>
+ <element name="idrefs1" type="t:idrefs1"/>
+ <element name="idrefs2" type="t:idrefs2"/>
+ </sequence>
+ </complexType>
+
+</schema>