diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-10-27 10:10:46 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-10-27 10:10:46 +0200 |
commit | 3dcdc88b14aec626c87f8f480a1d07781a27c069 (patch) | |
tree | 3d64d4701e07441545ffaf3afe0050c4c9e35b41 /tests | |
parent | 8161144e7f3182d9dc66a811b4618a81232d4af3 (diff) |
Implement schema enumeration to C++ enum mapping in C++/Hybrid
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cxx/hybrid/enumeration/driver.cxx | 97 | ||||
-rw-r--r-- | tests/cxx/hybrid/enumeration/makefile | 109 | ||||
-rw-r--r-- | tests/cxx/hybrid/enumeration/test-000.std | 1 | ||||
-rw-r--r-- | tests/cxx/hybrid/enumeration/test-000.xml | 24 | ||||
-rw-r--r-- | tests/cxx/hybrid/enumeration/test.xsd | 88 | ||||
-rw-r--r-- | tests/cxx/hybrid/polymorphism/enumeration/driver.cxx | 67 | ||||
-rw-r--r-- | tests/cxx/hybrid/polymorphism/enumeration/makefile | 110 | ||||
-rw-r--r-- | tests/cxx/hybrid/polymorphism/enumeration/test-000.std | 1 | ||||
-rw-r--r-- | tests/cxx/hybrid/polymorphism/enumeration/test-000.xml | 13 | ||||
-rw-r--r-- | tests/cxx/hybrid/polymorphism/enumeration/test.xsd | 58 | ||||
-rw-r--r-- | tests/cxx/hybrid/polymorphism/makefile | 7 |
11 files changed, 573 insertions, 2 deletions
diff --git a/tests/cxx/hybrid/enumeration/driver.cxx b/tests/cxx/hybrid/enumeration/driver.cxx new file mode 100644 index 0000000..ffbbf0b --- /dev/null +++ b/tests/cxx/hybrid/enumeration/driver.cxx @@ -0,0 +1,97 @@ +// file : tests/cxx/hybrid/enumeration/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 XML Schema enumeration to C++ enum mapping. +// + +#include <cassert> +#include <iostream> + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.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; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + // Test the mapping. + // + { + simple x; + x = simple::a; + assert (x == simple::a); + + x.value (simple::b); + assert (x == simple::b); + + simple y (simple::c); + + switch (y) + { + case simple::c: + { + break; + } + default: + assert (false); + } + } + + { + final x (final::c); + assert (x == final::c); + + simple s = x; + assert (s == simple::c); + } + + { + complex c; + c.value (complex::a); + assert (c == complex::a); + + simple s = c; + assert (s == simple::a); + } + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/enumeration/makefile b/tests/cxx/hybrid/enumeration/makefile new file mode 100644 index 0000000..a7a6b3c --- /dev/null +++ b/tests/cxx/hybrid/enumeration/makefile @@ -0,0 +1,109 @@ +# file : tests/cxx/hybrid/enumeration/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) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.o)) + +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +dist := $(out_base)/.dist +dist-win := $(out_base)/.dist-win +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \ + $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \ + $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \ + $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \ + $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx) + +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen) $(dist) $(dist-win): xsde_options += --generate-parser \ +--generate-serializer --generate-aggregate --custom-data simple-cd \ +--custom-data fbvd + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test-000.xml $(src_base)/test-000.std + $(call message,test $$1,$$1 $(src_base)/test-000.xml | diff -u $(src_base)/test-000.std -,$(driver)) + + +# Dist. +# +$(dist) $(dist-win): opt := -src $(src_base) -cmd cxx-hybrid -xsd "$(xsd)" \ +-cxx "$(cxx)" -gen "$(genf)" -opt "$(xsde_options)" -out $(dist_prefix) + +$(dist): + $(call message,install $(src_base),$(scf_root)/dist $(opt)) + +$(dist-win): + $(call message,install $(src_base),$(scf_root)/dist -win $(opt)) + + +# 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)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/enumeration/test-000.std b/tests/cxx/hybrid/enumeration/test-000.std new file mode 100644 index 0000000..8bb771a --- /dev/null +++ b/tests/cxx/hybrid/enumeration/test-000.std @@ -0,0 +1 @@ +<t:root xmlns:t="test" x="a" y="c" z="b"><simple>a</simple><simple>b</simple><derived>a</derived><derived>b</derived><final>a</final><final>c</final><complex x="a">a</complex><complex x="c">c</complex><simple-cd>a</simple-cd><simple-cd>b</simple-cd><fbvd>a</fbvd><fbvd>c</fbvd><vbvd>a</vbvd><vbvd>c</vbvd></t:root>
\ No newline at end of file diff --git a/tests/cxx/hybrid/enumeration/test-000.xml b/tests/cxx/hybrid/enumeration/test-000.xml new file mode 100644 index 0000000..6db0a36 --- /dev/null +++ b/tests/cxx/hybrid/enumeration/test-000.xml @@ -0,0 +1,24 @@ +<t:root xmlns:t="test"> + + <simple>a</simple> + <simple>b</simple> + + <derived>a</derived> + <derived>b</derived> + + <final>a</final> + <final>c</final> + + <complex x="a">a</complex> + <complex x="c">c</complex> + + <simple-cd>a</simple-cd> + <simple-cd>b</simple-cd> + + <fbvd>a</fbvd> + <fbvd>c</fbvd> + + <vbvd>a</vbvd> + <vbvd>c</vbvd> + +</t:root> diff --git a/tests/cxx/hybrid/enumeration/test.xsd b/tests/cxx/hybrid/enumeration/test.xsd new file mode 100644 index 0000000..782c707 --- /dev/null +++ b/tests/cxx/hybrid/enumeration/test.xsd @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="base"> + <restriction base="string"/> + </simpleType> + + <simpleType name="simple"> + <restriction base="string"> + <enumeration value="a"/> + <enumeration value="b"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <simpleType name="derived"> + <restriction base="t:base"> + <enumeration value="a"/> + <enumeration value="b"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <simpleType name="interm"> + <restriction base="t:simple"/> + </simpleType> + + <simpleType name="final"> + <restriction base="t:interm"> + <enumeration value="a"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <complexType name="complex"> + <simpleContent> + <extension base="t:final"> + <attribute name="x" type="string"/> + </extension> + </simpleContent> + </complexType> + + <!-- Variable-length (custom data) --> + + <simpleType name="simple-cd"> + <restriction base="string"> + <enumeration value="a"/> + <enumeration value="b"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <!-- fixed base, variable derived --> + <simpleType name="fbvd"> + <restriction base="t:simple"> + <enumeration value="a"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <!-- variable base, variable derived --> + <simpleType name="vbvd"> + <restriction base="t:simple-cd"> + <enumeration value="a"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + + <complexType name="type"> + <sequence> + <element name="simple" type="t:simple" maxOccurs="unbounded"/> + <element name="derived" type="t:derived" maxOccurs="unbounded"/> + <element name="final" type="t:final" maxOccurs="unbounded"/> + <element name="complex" type="t:complex" maxOccurs="unbounded"/> + + <element name="simple-cd" type="t:simple-cd" maxOccurs="unbounded"/> + <element name="fbvd" type="t:fbvd" maxOccurs="unbounded"/> + <element name="vbvd" type="t:vbvd" maxOccurs="unbounded"/> + </sequence> + <attribute name="x" type="t:simple" default="a"/> + <attribute name="y" type="t:final" default="c"/> + <attribute name="z" type="t:simple-cd" default="b"/> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/hybrid/polymorphism/enumeration/driver.cxx b/tests/cxx/hybrid/polymorphism/enumeration/driver.cxx new file mode 100644 index 0000000..b2c9429 --- /dev/null +++ b/tests/cxx/hybrid/polymorphism/enumeration/driver.cxx @@ -0,0 +1,67 @@ +// file : tests/cxx/hybrid/polymorphism/enumeration/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 XML Schema enumeration to C++ enum mapping. +// + +#include <iostream> + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.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; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name (), + true); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + // Test the mapping. + // + simple s (simple::a); + s.value (simple::b); + + complex c; + c.value (complex::a); + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name (), + true); + + doc_s.add_prefix ("t", "test"); + doc_s.add_prefix ("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + + root_s.pre (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/polymorphism/enumeration/makefile b/tests/cxx/hybrid/polymorphism/enumeration/makefile new file mode 100644 index 0000000..fbd4337 --- /dev/null +++ b/tests/cxx/hybrid/polymorphism/enumeration/makefile @@ -0,0 +1,110 @@ +# file : tests/cxx/hybrid/polymorphism/enumeration/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) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.o)) + +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +dist := $(out_base)/.dist +dist-win := $(out_base)/.dist-win +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \ + $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \ + $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \ + $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \ + $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx) + +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen) $(dist) $(dist-win): xsde_options += --generate-parser \ +--generate-serializer --generate-aggregate --custom-data simple-cd \ +--custom-data fbvd --generate-polymorphic --generate-typeinfo \ +--polymorphic-type base --polymorphic-type simple + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test-000.xml $(src_base)/test-000.std + $(call message,test $$1,$$1 $(src_base)/test-000.xml | diff -u $(src_base)/test-000.std -,$(driver)) + + +# Dist. +# +$(dist) $(dist-win): opt := -src $(src_base) -cmd cxx-hybrid -xsd "$(xsd)" \ +-cxx "$(cxx)" -gen "$(genf)" -opt "$(xsde_options)" -out $(dist_prefix) + +$(dist): + $(call message,install $(src_base),$(scf_root)/dist $(opt)) + +$(dist-win): + $(call message,install $(src_base),$(scf_root)/dist -win $(opt)) + + +# 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)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/polymorphism/enumeration/test-000.std b/tests/cxx/hybrid/polymorphism/enumeration/test-000.std new file mode 100644 index 0000000..ecb1b29 --- /dev/null +++ b/tests/cxx/hybrid/polymorphism/enumeration/test-000.std @@ -0,0 +1 @@ +<t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><base xsi:type="t:derived">a</base><base xsi:type="t:derived">b</base><simple>a</simple><simple>b</simple><simple xsi:type="t:interm">b</simple><simple xsi:type="t:final">c</simple><simple x="c" xsi:type="t:complex">c</simple></t:root>
\ No newline at end of file diff --git a/tests/cxx/hybrid/polymorphism/enumeration/test-000.xml b/tests/cxx/hybrid/polymorphism/enumeration/test-000.xml new file mode 100644 index 0000000..b43342e --- /dev/null +++ b/tests/cxx/hybrid/polymorphism/enumeration/test-000.xml @@ -0,0 +1,13 @@ +<t:root xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <base xsi:type="t:derived">a</base> + <base xsi:type="t:derived">b</base> + + <simple>a</simple> + <simple>b</simple> + + <simple xsi:type="t:interm">b</simple> + <simple xsi:type="t:final">c</simple> + <simple xsi:type="t:complex" x="c">c</simple> + +</t:root> diff --git a/tests/cxx/hybrid/polymorphism/enumeration/test.xsd b/tests/cxx/hybrid/polymorphism/enumeration/test.xsd new file mode 100644 index 0000000..235990c --- /dev/null +++ b/tests/cxx/hybrid/polymorphism/enumeration/test.xsd @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- base is polymorphic --> + + <simpleType name="base"> + <restriction base="string"/> + </simpleType> + + <simpleType name="derived"> + <restriction base="t:base"> + <enumeration value="a"/> + <enumeration value="b"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <!-- enum is polymorphic --> + + <simpleType name="simple"> + <restriction base="string"> + <enumeration value="a"/> + <enumeration value="b"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <!-- base enum is polymorphic --> + + <simpleType name="interm"> + <restriction base="t:simple"/> + </simpleType> + + <simpleType name="final"> + <restriction base="t:interm"> + <enumeration value="a"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <complexType name="complex"> + <simpleContent> + <extension base="t:final"> + <attribute name="x" type="string"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="base" type="t:base" maxOccurs="unbounded"/> + <element name="simple" type="t:simple" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/tests/cxx/hybrid/polymorphism/makefile b/tests/cxx/hybrid/polymorphism/makefile index 72f0c87..703ef9a 100644 --- a/tests/cxx/hybrid/polymorphism/makefile +++ b/tests/cxx/hybrid/polymorphism/makefile @@ -5,12 +5,15 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make -all_tests := multischema +# NOTE: remember to update dist/tests/cxx/hybrid/polymorphis/{makefile, +# nmakefile} if you change anything here. +# +all_tests := enumeration multischema build_tests := ifeq ($(xsde_iostream),y) -build_tests += multischema +build_tests += enumeration multischema endif default := $(out_base)/ |