diff options
author | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 |
commit | a15cf65c44d5c224169c32ef5495b68c758134b7 (patch) | |
tree | 3419f58fc8e1b315ba8171910ee044c5d467c162 /xsd/tests/cxx/tree/containment |
Imported Upstream version 3.3.0.2upstream/3.3.0.2
Diffstat (limited to 'xsd/tests/cxx/tree/containment')
-rw-r--r-- | xsd/tests/cxx/tree/containment/driver.cxx | 113 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/containment/makefile | 82 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/containment/test.xsd | 59 |
3 files changed, 254 insertions, 0 deletions
diff --git a/xsd/tests/cxx/tree/containment/driver.cxx b/xsd/tests/cxx/tree/containment/driver.cxx new file mode 100644 index 0000000..cb6c76e --- /dev/null +++ b/xsd/tests/cxx/tree/containment/driver.cxx @@ -0,0 +1,113 @@ +// file : tests/cxx/tree/containment/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 tree node containment. +// + +#include <memory> // std::auto_ptr +#include <cassert> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + // Change of a container in a sub-tree without ID. + // + { + auto_ptr<inner> i (new inner ()); + i->ref ("foo"); + + outer o; + o.i (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. + // + { + 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 (i); + o.ref ("foo"); + + assert (o.i ()->ref ()->get () == p); + assert (o.ref ()->get () == p); + } + + // Change of a container in ID. + // + { + auto_ptr<xml_schema::id> id (new xml_schema::id ("foo")); + + inner i; + i.id (id); + i.ref ("foo"); + assert (i.ref ()->get () == &i); + } + + // Change of a container in a type derived from ID with ID inside. + // + { + auto_ptr<id_ex> id (new id_ex ("foo")); + id_ex* p (id.get ()); + id->id ("bar"); + + inner i; + i.id_ex (id); + + i.ref ("foo"); + assert (i.ref ()->get () == &i); + + i.ref ("bar"); + assert (i.ref ()->get () == p); + } + + // IDREF lists + // + { + id i1 ("a"), i2 ("b"); + + auto_ptr<ids> ic (new ids); + ic->id ().push_back (i1); + ic->id ().push_back (i2); + + auto_ptr<xml_schema::idrefs> r1 (new xml_schema::idrefs); + r1->push_back (xml_schema::idref ("a")); + r1->push_back (xml_schema::idref ("b")); + + auto_ptr<idref_list> r2 (new idref_list); + r2->push_back (xml_schema::idref ("a")); + r2->push_back (xml_schema::idref ("b")); + + auto_ptr<idrefs1> rc1 (new idrefs1); + auto_ptr<idrefs2> rc2 (new idrefs2); + + rc1->idrefs (r1); + rc2->idrefs (r2); + + model m; + m.ids (ic); + m.idrefs1 (rc1); + m.idrefs2 (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/makefile b/xsd/tests/cxx/tree/containment/makefile new file mode 100644 index 0000000..fcdd792 --- /dev/null +++ b/xsd/tests/cxx/tree/containment/makefile @@ -0,0 +1,82 @@ +# file : tests/cxx/tree/containment/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-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/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> |