diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2025-05-02 07:42:02 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2025-05-02 07:42:02 +0200 |
commit | fc486627a4ecbae797fa6856d8a9204ea85f4db8 (patch) | |
tree | ff3dae4c0e5d980d8e2da4fc6256ae839269bbcd /xsd/tests/cxx/tree/polymorphism | |
parent | 1c188393cd2e271ed2581471b601fb5960777fd8 (diff) | |
parent | ecba0bbd9947036dd82f16ab95252f8db445e149 (diff) |
Merge tag 'debian/4.0.0-10' into developdevelop
Bugfix release
Diffstat (limited to 'xsd/tests/cxx/tree/polymorphism')
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/comparison/driver.cxx | 74 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/comparison/makefile | 87 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/comparison/test.xml | 7 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/comparison/test.xsd | 39 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/makefile | 17 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/ostream/driver.cxx | 35 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/ostream/makefile | 88 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/ostream/output | 18 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/ostream/test.xml | 10 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/ostream/test.xsd | 53 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/same-type/driver.cxx | 36 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/same-type/makefile | 87 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/same-type/output | 9 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/same-type/test.xml | 10 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/polymorphism/same-type/test.xsd | 21 |
15 files changed, 591 insertions, 0 deletions
diff --git a/xsd/tests/cxx/tree/polymorphism/comparison/driver.cxx b/xsd/tests/cxx/tree/polymorphism/comparison/driver.cxx new file mode 100644 index 0000000..5394991 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/comparison/driver.cxx @@ -0,0 +1,74 @@ +// file : tests/cxx/tree/polymorphism/comparison/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test comparison of polymorphic object models. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <iostream> + +#include "test.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; + } + + try + { + XSD_AUTO_PTR<type> r (root (argv[1])); + + // Equals. + // + { + derived1 d ("a", 1); + d.b ("b"); + type r1 (d); + + assert (*r == r1); + } + + // Values are not equal. + // + { + derived1 d ("a", 1); + d.b ("c"); + type r1 (d); + + assert (*r != r1); + } + + // Values are not equal. + // + { + derived1 d ("a", 2); + d.b ("b"); + type r1 (d); + + assert (*r != r1); + } + + // Different types. + // + { + derived2 d ("a", 1); + d.c ().push_back ("c"); + type r1 (d); + + assert (*r != r1); + } + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/polymorphism/comparison/makefile b/xsd/tests/cxx/tree/polymorphism/comparison/makefile new file mode 100644 index 0000000..ef3e70a --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/comparison/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/polymorphism/comparison/makefile +# copyright : Copyright (c) 2006-2014 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$(out_base) -I$(src_base) -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-polymorphic --polymorphic-type base \ +--generate-comparison +$(gen): $(out_root)/xsd/xsd + +$(call include-dep,$(dep),$(obj),$(gen)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml + $(call message,test $$1,$$1 $(src_base)/test.xml,$(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,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): xsd_options += --std $(cxx_standard) +$(call include,$(scf_root)/xsd/tree/xsd-cxx.make) +endif + + +# Dependencies. +# +$(call import,$(src_root)/xsd/makefile) diff --git a/xsd/tests/cxx/tree/polymorphism/comparison/test.xml b/xsd/tests/cxx/tree/polymorphism/comparison/test.xml new file mode 100644 index 0000000..0b8c125 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/comparison/test.xml @@ -0,0 +1,7 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <base xsi:type="t:derived1"><a>a</a><fund>1</fund><b>b</b></base> + +</t:root> diff --git a/xsd/tests/cxx/tree/polymorphism/comparison/test.xsd b/xsd/tests/cxx/tree/polymorphism/comparison/test.xsd new file mode 100644 index 0000000..18532f2 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/comparison/test.xsd @@ -0,0 +1,39 @@ +<?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"/> + <element name="fund" type="int"/> + </sequence> + </complexType> + + <complexType name="derived1"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="string" minOccurs="0"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="derived2"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="c" type="string" maxOccurs="unbounded"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="base" type="t:base"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/polymorphism/makefile b/xsd/tests/cxx/tree/polymorphism/makefile new file mode 100644 index 0000000..9215e44 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/polymorphism/makefile +# copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +tests := comparison ostream same-type + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.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/xsd/tests/cxx/tree/polymorphism/ostream/driver.cxx b/xsd/tests/cxx/tree/polymorphism/ostream/driver.cxx new file mode 100644 index 0000000..bfbd2d4 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/ostream/driver.cxx @@ -0,0 +1,35 @@ +// file : tests/cxx/tree/polymorphism/ostream/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test printing of polymorphic object models. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <iostream> + +#include "test.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; + } + + try + { + XSD_AUTO_PTR<type> r (root (argv[1])); + cout << *r << endl; + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/polymorphism/ostream/makefile b/xsd/tests/cxx/tree/polymorphism/ostream/makefile new file mode 100644 index 0000000..76a366f --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/ostream/makefile @@ -0,0 +1,88 @@ +# file : tests/cxx/tree/polymorphism/ostream/makefile +# copyright : Copyright (c) 2006-2014 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$(out_base) -I$(src_base) -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-polymorphic --polymorphic-type-all \ +--root-element root --generate-ostream +$(gen): $(out_root)/xsd/xsd + +$(call include-dep,$(dep),$(obj),$(gen)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(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,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): xsd_options += --std $(cxx_standard) +$(call include,$(scf_root)/xsd/tree/xsd-cxx.make) +endif + + +# Dependencies. +# +$(call import,$(src_root)/xsd/makefile) diff --git a/xsd/tests/cxx/tree/polymorphism/ostream/output b/xsd/tests/cxx/tree/polymorphism/ostream/output new file mode 100644 index 0000000..e7fbd68 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/ostream/output @@ -0,0 +1,18 @@ + +base: +a: a +fund: 1 +base: +a: a +fund: 1 +b: b +base: +a: a +fund: 1 +c: c1 +c: c2 +base: +a: a +fund: 1 +d: d1 +d: d2 diff --git a/xsd/tests/cxx/tree/polymorphism/ostream/test.xml b/xsd/tests/cxx/tree/polymorphism/ostream/test.xml new file mode 100644 index 0000000..5409d2a --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/ostream/test.xml @@ -0,0 +1,10 @@ +<root xmlns="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <base><a>a</a><fund>1</fund></base> + <base xsi:type="derived1"><a>a</a><fund>1</fund><b>b</b></base> + <base xsi:type="derived2"><a>a</a><fund>1</fund><c>c1</c><c>c2</c></base> + <derived3><a>a</a><fund>1</fund><d>d1</d><d>d2</d></derived3> + +</root> diff --git a/xsd/tests/cxx/tree/polymorphism/ostream/test.xsd b/xsd/tests/cxx/tree/polymorphism/ostream/test.xsd new file mode 100644 index 0000000..ddeaeae --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/ostream/test.xsd @@ -0,0 +1,53 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" + targetNamespace="test" elementFormDefault="qualified"> + + <complexType name="base"> + <sequence> + <element name="a" type="string"/> + <element name="fund" type="int"/> + </sequence> + </complexType> + <element name="base" type="t:base"/> + + <complexType name="derived1"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="string" minOccurs="0"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="derived2"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="c" type="string" maxOccurs="unbounded"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="derived3" substitutionGroup="t:base"> + <complexType> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="d" type="string" maxOccurs="unbounded"/> + </sequence> + </extension> + </complexContent> + </complexType> + </element> + + <complexType name="type"> + <sequence> + <element ref="t:base" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/polymorphism/same-type/driver.cxx b/xsd/tests/cxx/tree/polymorphism/same-type/driver.cxx new file mode 100644 index 0000000..0846b04 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/same-type/driver.cxx @@ -0,0 +1,36 @@ +// file : tests/cxx/tree/polymorphism/same-type/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test substitution group and xsi:type that don't change the type. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <iostream> + +#include "test.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; + } + + try + { + XSD_AUTO_PTR<type> r (root (argv[1])); + + cout << *r << endl; + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/polymorphism/same-type/makefile b/xsd/tests/cxx/tree/polymorphism/same-type/makefile new file mode 100644 index 0000000..549f590 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/same-type/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/polymorphism/same-type/makefile +# copyright : Copyright (c) 2006-2014 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$(out_base) -I$(src_base) -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-ostream --generate-polymorphic \ +--root-element root +$(gen): $(out_root)/xsd/xsd + +$(call include-dep,$(dep),$(obj),$(gen)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(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,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): xsd_options += --std $(cxx_standard) +$(call include,$(scf_root)/xsd/tree/xsd-cxx.make) +endif + + +# Dependencies. +# +$(call import,$(src_root)/xsd/makefile) diff --git a/xsd/tests/cxx/tree/polymorphism/same-type/output b/xsd/tests/cxx/tree/polymorphism/same-type/output new file mode 100644 index 0000000..04b5cbf --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/same-type/output @@ -0,0 +1,9 @@ + +base: +a: a1 +base: +a: a2 +base: +a: a3 +base: +a: a4 diff --git a/xsd/tests/cxx/tree/polymorphism/same-type/test.xml b/xsd/tests/cxx/tree/polymorphism/same-type/test.xml new file mode 100644 index 0000000..f8b6d1e --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/same-type/test.xml @@ -0,0 +1,10 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <t:base><a>a1</a></t:base> + <t:derived><a>a2</a></t:derived> + <t:base xsi:type="t:base"><a>a3</a></t:base> + <t:derived xsi:type="t:base"><a>a4</a></t:derived> + +</t:root> diff --git a/xsd/tests/cxx/tree/polymorphism/same-type/test.xsd b/xsd/tests/cxx/tree/polymorphism/same-type/test.xsd new file mode 100644 index 0000000..a4157d3 --- /dev/null +++ b/xsd/tests/cxx/tree/polymorphism/same-type/test.xsd @@ -0,0 +1,21 @@ +<?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> + + <element name="base" type="t:base"/> + <element name="derived" type="t:base" substitutionGroup="t:base"/> + + <complexType name="type"> + <sequence> + <element ref="t:base" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> |