diff options
Diffstat (limited to 'xsd/tests/cxx/tree')
166 files changed, 9850 insertions, 0 deletions
diff --git a/xsd/tests/cxx/tree/any-type/driver.cxx b/xsd/tests/cxx/tree/any-type/driver.cxx new file mode 100644 index 0000000..1ac5274 --- /dev/null +++ b/xsd/tests/cxx/tree/any-type/driver.cxx @@ -0,0 +1,145 @@ +// file : tests/cxx/tree/any-type/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test anyType and anySimpleType content extraction. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <utility> // std::move +#include <sstream> +#include <iostream> + +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/PlatformUtils.hpp> + +#include "test.hxx" // Get XSD_CXX11 defined. + +#include <xsd/cxx/xml/string.hxx> + +using namespace std; +using namespace test; +using namespace xercesc; + +namespace xml = xsd::cxx::xml; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + XMLPlatformUtils::Initialize (); + + try + { + // Test parsing + // + XSD_AUTO_PTR<type> r (root (argv[1])); + + // Test API. + // + { + assert (type::a_default_value ().text_content () == "default value"); + } + + { + xml_schema::simple_type x ("fox"); + assert (x.text_content () == "fox"); + x.text_content ("foo"); + assert (x.text_content () == "foo"); + x.text_content ().clear (); + assert (x.text_content () == ""); + x.text_content () = "baz"; + r->s ().push_back (x); + } + + { + xml_schema::type x; + + DOMDocument& doc (x.dom_content_document ()); + + // Copy. + // + DOMElement* e (doc.createElement (xml::string ("dummy").c_str ())); + e->setAttribute (xml::string ("x").c_str (), + xml::string ("foo").c_str ()); + e->setTextContent (xml::string ("data").c_str ()); + x.dom_content ().set (*e); + e->release (); + + r->t ().push_back (x); + } + + { + XSD_AUTO_PTR<xml_schema::type> x (new xml_schema::type); + + DOMDocument& doc (x->dom_content_document ()); + + // Assume ownership. + // + DOMElement* e (doc.createElement (xml::string ("dummy").c_str ())); + e->setAttribute (xml::string ("x").c_str (), + xml::string ("foo").c_str ()); + e->setTextContent (xml::string ("data").c_str ()); + x->dom_content ().set (e); + +#ifdef XSD_CXX11 + r->t ().push_back (std::move (x)); +#else + r->t ().push_back (x); +#endif + } + + // Test printing. + // + cout << *r << endl + << endl; + + // Test serialization. + // + xml_schema::namespace_infomap map; + + map["t"].name = "test"; + map["t"].schema = "test.xsd"; + map["o"].name = "other"; + + stringstream iostr; + root (iostr, *r, map); + + cout << iostr.str () << endl + << endl; + + { + XSD_AUTO_PTR<type> r1 (root (iostr, argv[1])); + + // Xerces-C++ mis-indentation of mixed content messes this up. + // assert (*r == *r); + + stringstream iostr; + root (iostr, *r1, map); + + cout << iostr.str () << endl + << endl; + } + + // Test comparison. + // + assert (*r == *r); + + // Test copy c-tor. + // + type copy (*r); + assert (copy == *r); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } + + XMLPlatformUtils::Terminate (); +} diff --git a/xsd/tests/cxx/tree/any-type/makefile b/xsd/tests/cxx/tree/any-type/makefile new file mode 100644 index 0000000..1d0590f --- /dev/null +++ b/xsd/tests/cxx/tree/any-type/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/any-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-any-type --generate-serialization \ +--generate-ostream --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 $(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/any-type/output b/xsd/tests/cxx/tree/any-type/output new file mode 100644 index 0000000..580e7db --- /dev/null +++ b/xsd/tests/cxx/tree/any-type/output @@ -0,0 +1,73 @@ + +t: +t: +t: +t: +t: +t: +t: +t: +s: +s: simple +s: baz +l: one two three +a: any simple content + +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<t:root xmlns:t="test" a="any simple content" xmlns:o="other" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"> + <t/> + <t x="x"/> + <t>any</t> + <t x="x">any</t> + <t o:y="y" x="x"> + <n1> + <n2>nested 1</n2> + <n2>nested 2</n2> + </n1> + <o:n2 o:x="x">more</o:n2> + </t><t x="x"> + <n1>mi + <n2>nested 1</n2>x + <n2>nested 2</n2>ed + </n1>content + </t> + <t x="foo">data</t> + <t x="foo">data</t> + <s/> + <s>simple</s> + <s>baz</s> + <l>one two three</l> +</t:root> + + +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<t:root xmlns:t="test" a="any simple content" xmlns:o="other" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test test.xsd"> + <t/> + <t x="x"/> + <t>any</t> + <t x="x">any</t> + <t o:y="y" x="x"> + <n1> + <n2>nested 1</n2> + <n2>nested 2</n2> + </n1> + <o:n2 o:x="x">more</o:n2> + </t><t x="x"> + <n1>mi + + <n2>nested 1</n2>x + + <n2>nested 2</n2>ed + + </n1>content + + </t> + <t x="foo">data</t> + <t x="foo">data</t> + <s/> + <s>simple</s> + <s>baz</s> + <l>one two three</l> +</t:root> + + diff --git a/xsd/tests/cxx/tree/any-type/test.xml b/xsd/tests/cxx/tree/any-type/test.xml new file mode 100644 index 0000000..7c9035a --- /dev/null +++ b/xsd/tests/cxx/tree/any-type/test.xml @@ -0,0 +1,26 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd" + + a="any simple content"> + + <t/> + <t x="x"/> + <t>any</t> + <t x="x">any</t> + <t x="x" o:y="y"> + <n1> + <n2>nested 1</n2> + <n2>nested 2</n2> + </n1> + <o:n2 o:x="x">more</o:n2> + </t> + <t x="x"><n1>mi<n2>nested 1</n2>x<n2>nested 2</n2>ed</n1>content</t> + + <s/> + <s>simple</s> + + <l>one two three</l> + +</t:root> diff --git a/xsd/tests/cxx/tree/any-type/test.xsd b/xsd/tests/cxx/tree/any-type/test.xsd new file mode 100644 index 0000000..37dcc8d --- /dev/null +++ b/xsd/tests/cxx/tree/any-type/test.xsd @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="any-list"> + <!--Not allowed? list itemType="anySimpleType"/--> + <list itemType="string"/> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="t" type="anyType" maxOccurs="unbounded"/> + <element name="s" type="anySimpleType" maxOccurs="unbounded"/> + <element name="l" type="t:any-list" maxOccurs="unbounded"/> + </sequence> + <attribute name="a" type="anySimpleType" default="default value"/> + </complexType> + + <element name="root" type="t:type"/> +</schema> diff --git a/xsd/tests/cxx/tree/binary/cdr/driver.cxx b/xsd/tests/cxx/tree/binary/cdr/driver.cxx new file mode 100644 index 0000000..a2d7195 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/cdr/driver.cxx @@ -0,0 +1,144 @@ +// file : tests/cxx/tree/binary/cdr/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test non-polymorphic binary serialization to ACE CDR. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <cassert> +#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])); + + // Save to a CDR stream. + // + ACE_OutputCDR ace_ocdr; + xml_schema::ostream<ACE_OutputCDR> ocdr (ace_ocdr); + ocdr << *r; + + // Load from a CDR stream. + // + ACE_InputCDR ace_icdr (ace_ocdr); + xml_schema::istream<ACE_InputCDR> icdr (ace_icdr); + XSD_AUTO_PTR<type> c (new type (icdr)); + + // Compare the two. + // + assert (r->list () == c->list ()); + assert (r->union_ () == c->union_ ()); + assert (r->enumeration () == c->enumeration ()); + + type::complex_sequence rs (r->complex ()), cs (c->complex ()); + + for (type::complex_iterator ri (rs.begin ()), ci (cs.begin ()); + ri != rs.end () && ci != rs.end (); ++ri, ++ci) + { + assert (ri->a () == ci->a ()); + if (ri->b ()) + assert (ri->b () == ci->b ()); + assert (ri->c () == ci->c ()); + + assert (ri->x () == ci->x ()); + if (ri->y ()) + assert (ri->y () == ci->y ()); + } + + // integers + // + assert (r->byte () == c->byte ()); + assert (r->unsigned_byte () == c->unsigned_byte ()); + assert (r->short_ () == c->short_ ()); + assert (r->unsigned_short () == c->unsigned_short ()); + assert (r->int_ () == c->int_ ()); + assert (r->unsigned_int () == c->unsigned_int ()); + assert (r->long_ () == c->long_ ()); + assert (r->unsigned_long () == c->unsigned_long ()); + assert (r->integer () == c->integer ()); + assert (r->non_positive_integer () == c->non_positive_integer ()); + assert (r->non_negative_integer () == c->non_negative_integer ()); + assert (r->positive_integer () == c->positive_integer ()); + assert (r->negative_integer () == c->negative_integer ()); + + // boolean + // + assert (r->boolean () == c->boolean ()); + + // floats + // + assert (r->float_ () == c->float_ ()); + assert (r->double_ () == c->double_ ()); + assert (r->decimal () == c->decimal ()); + + // strings + // + assert (r->string () == c->string ()); + assert (r->normalized_string () == c->normalized_string ()); + assert (r->token () == c->token ()); + assert (r->name () == c->name ()); + assert (r->name_token () == c->name_token ()); + assert (r->name_tokens () == c->name_tokens ()); + assert (r->ncname () == c->ncname ()); + assert (r->language () == c->language ()); + + // qualified name + // + assert (r->qname () == c->qname ()); + + // ID/IDREF + // + assert (r->id () == c->id ()); + assert (r->id_ref () == c->id_ref ()); + assert (r->id_refs () == c->id_refs ()); + + // URI + // + assert (r->any_uri () == c->any_uri ()); + + // binary + // + assert (r->base64_binary () == c->base64_binary ()); + assert (r->hex_binary () == c->hex_binary ()); + + // date/time + // + assert (r->day () == c->day ()); + assert (r->month () == c->month ()); + assert (r->year () == c->year ()); + assert (r->month_day () == c->month_day ()); + assert (r->year_month () == c->year_month ()); + assert (r->date () == c->date ()); + assert (r->time () == c->time ()); + assert (r->date_time () == c->date_time ()); + assert (r->duration () == c->duration ()); + + // anySimpleType + // + assert (!r->any_simple_type_attr ().text_content ().empty ()); + assert (r->any_simple_type_attr () == c->any_simple_type_attr ()); + + assert (!r->any_simple_type ().text_content ().empty ()); + assert (r->any_simple_type () == c->any_simple_type ()); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/binary/cdr/makefile b/xsd/tests/cxx/tree/binary/cdr/makefile new file mode 100644 index 0000000..eb80d35 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/cdr/makefile @@ -0,0 +1,90 @@ +# file : tests/cxx/tree/binary/cdr/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) + +$(call import,\ + $(scf_root)/import/libace/stub.make,\ + l: ace.l,cpp-options: ace.l.cpp-options) + +# Build. +# +$(driver): $(obj) $(xerces_c.l) $(ace.l) + +$(obj) $(dep): cpp_options := -I$(out_base) -I$(src_base) -I$(src_root)/libxsd +$(obj) $(dep): $(xerces_c.l.cpp-options) $(ace.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-insertion ACE_OutputCDR \ +--generate-extraction ACE_InputCDR --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/binary/cdr/test.xml b/xsd/tests/cxx/tree/binary/cdr/test.xml new file mode 100644 index 0000000..5cedd98 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/cdr/test.xml @@ -0,0 +1,93 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd" + any_simple_type_attr="any simple content"> + + <list>1 2 3</list> + + <union>abc</union> + + <enumeration>left</enumeration> + + <complex x="1"> + <a>aaa</a> + </complex> + <complex x="1" y="2"> + <a>aaa</a> + <b>bbb</b> + <c>c</c> + <c>cc</c> + <c>ccc</c> + </complex> + + + <!-- integers --> + <byte>65</byte> + <unsigned_byte>66</unsigned_byte> + <short>-222</short> + <unsigned_short>57005</unsigned_short> + <int>-57005</int> + <unsigned_int>3735928559</unsigned_int> + <long>-3735928559</long> + <unsigned_long>16045690984833335023</unsigned_long> + <integer>-3735928559</integer> + <non_positive_integer>-3735928559</non_positive_integer> + <non_negative_integer>3735928559</non_negative_integer> + <positive_integer>3735928559</positive_integer> + <negative_integer>-3735928559</negative_integer> + + + <!-- boolean --> + <boolean>true</boolean> + + + <!-- floats --> + <float>1234.1234</float> + <double>12345678.12345678</double> + <decimal>1234567812345678.1234567812345678</decimal> + + + <!-- strings --> + <string>string</string> + <normalized_string>normalized string</normalized_string> + <token>one two three</token> + <name>name</name> + <name_token>name-token</name_token> + <name_tokens>name tokens</name_tokens> + <ncname>ncname</ncname> + <language>en-us</language> + + <!-- qualified name --> + <qname>xsi:schemaLocation</qname> + + + <!-- ID/IDREF --> + <id>elements1</id> + <id>elements2</id> + <id_ref>elements1</id_ref> + <id_refs>elements1 elements2</id_refs> + + + <!-- URI --> + <any_uri>http://www.codesynthesis.com</any_uri> + + + <!-- binary --> + <base64_binary>YmFzZTY0IGJpbmFyeQ==</base64_binary> + <hex_binary>6865782052696E617279</hex_binary> + + + <!-- date/time --> + <date>2001-10-26+02:00</date> + <date_time>2001-10-26T21:32:52+02:00</date_time> + <duration>P1Y2M3DT5H20M30S</duration> + <day>---01+02:00</day> + <month>--11+02:00</month> + <month_day>--11-02+02:00</month_day> + <year>2001+02:00</year> + <year_month>2001-11+02:00</year_month> + <time>21:32:52+02:00</time> + + <any_simple_type>any simple content in element</any_simple_type> + +</t:root> diff --git a/xsd/tests/cxx/tree/binary/cdr/test.xsd b/xsd/tests/cxx/tree/binary/cdr/test.xsd new file mode 100644 index 0000000..0629e94 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/cdr/test.xsd @@ -0,0 +1,123 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:t="test" + targetNamespace="test"> + + <simpleType name="list"> + <list itemType="int"/> + </simpleType> + + <simpleType name="union"> + <union memberTypes="int string"/> + </simpleType> + + <simpleType name="enumeration"> + <restriction base="string"> + <enumeration value="top"/> + <enumeration value="left"/> + <enumeration value="bottom"/> + <enumeration value="right"/> + </restriction> + </simpleType> + + <complexType name="base"> + <sequence> + <element name="a" type="string"/> + </sequence> + <attribute name="x" type="int" use="required"/> + </complexType> + + <complexType name="complex"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="y" type="int"/> + </extension> + </complexContent> + </complexType> + + + <complexType name="type"> + <sequence> + <element name="list" type="t:list"/> + <element name="union" type="t:union"/> + <element name="enumeration" type="t:enumeration"/> + <element name="complex" type="t:complex" maxOccurs="unbounded"/> + + <!-- integers --> + <element name="byte" type="byte"/> + <element name="unsigned_byte" type="unsignedByte"/> + <element name="short" type="short"/> + <element name="unsigned_short" type="unsignedShort"/> + <element name="int" type="int"/> + <element name="unsigned_int" type="unsignedInt"/> + <element name="long" type="long"/> + <element name="unsigned_long" type="unsignedLong"/> + <element name="integer" type="integer"/> + <element name="non_positive_integer" type="nonPositiveInteger"/> + <element name="non_negative_integer" type="nonNegativeInteger"/> + <element name="positive_integer" type="positiveInteger"/> + <element name="negative_integer" type="negativeInteger"/> + + + <!-- boolean --> + <element name="boolean" type="boolean"/> + + + <!-- floats --> + <element name="float" type="float"/> + <element name="double" type="double"/> + <element name="decimal" type="decimal"/> + + + <!-- strings --> + <element name="string" type="string"/> + <element name="normalized_string" type="normalizedString"/> + <element name="token" type="token"/> + <element name="name" type="Name"/> + <element name="name_token" type="NMTOKEN"/> + <element name="name_tokens" type="NMTOKENS"/> + <element name="ncname" type="NCName"/> + <element name="language" type="language"/> + + <!-- qualified name --> + <element name="qname" type="QName"/> + + + <!-- ID/IDREF --> + <element name="id" maxOccurs="2" type="ID"/> + <element name="id_ref" type="IDREF"/> + <element name="id_refs" type="IDREFS"/> + + + <!-- URI --> + <element name="any_uri" type="anyURI"/> + + + <!-- binary --> + <element name="base64_binary" type="base64Binary"/> + <element name="hex_binary" type="hexBinary"/> + + + <!-- date/time --> + <element name="date" type="date"/> + <element name="date_time" type="dateTime"/> + <element name="duration" type="duration"/> + <element name="day" type="gDay"/> + <element name="month" type="gMonth"/> + <element name="month_day" type="gMonthDay"/> + <element name="year" type="gYear"/> + <element name="year_month" type="gYearMonth"/> + <element name="time" type="time"/> + + <element name="any_simple_type" type="anySimpleType"/> + </sequence> + <attribute name="any_simple_type_attr" type="anySimpleType" use="required"/> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/binary/makefile b/xsd/tests/cxx/tree/binary/makefile new file mode 100644 index 0000000..7ec2f6a --- /dev/null +++ b/xsd/tests/cxx/tree/binary/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/binary/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 := cdr polymorphic xdr + +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/binary/polymorphic/driver.cxx b/xsd/tests/cxx/tree/binary/polymorphic/driver.cxx new file mode 100644 index 0000000..8e7256e --- /dev/null +++ b/xsd/tests/cxx/tree/binary/polymorphic/driver.cxx @@ -0,0 +1,165 @@ +// file : tests/cxx/tree/binary/polymorphic/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test polymorphic binary serialization. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <cassert> +#include <iostream> +#include <typeinfo> + +#include <ace/Log_Msg.h> // ACE_HEX_DUMP + +#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])); + + // Save to a CDR stream. + // + ACE_OutputCDR ace_ocdr; + xml_schema::ostream<ACE_OutputCDR> ocdr (ace_ocdr); + ocdr << *r; + + /* + // Print the binary representation. + // + cerr << "binary representation size: " << ace_ocdr.total_length () << endl; + + for (const ACE_Message_Block* mb = ace_ocdr.begin (); + mb != 0; + mb = mb->cont ()) + { + ACE_HEX_DUMP ((LM_DEBUG, mb->rd_ptr (), mb->length ())); + } + */ + + // Load from a CDR stream. + // + ACE_InputCDR ace_icdr (ace_ocdr); + xml_schema::istream<ACE_InputCDR> icdr (ace_icdr); + XSD_AUTO_PTR<type> c (new type (icdr)); + + // Compare the two. + // + assert (r->list () == c->list ()); + assert (r->union_ () == c->union_ ()); + assert (r->enumeration () == c->enumeration ()); + + { + complex& rc (dynamic_cast<complex&> (r->base ())); + complex& cc (dynamic_cast<complex&> (c->base ())); + + assert (rc.a () == cc.a ()); + if (rc.b ()) + assert (rc.b () == cc.b ()); + assert (rc.c () == cc.c ()); + + assert (rc.x () == cc.x ()); + if (rc.y ()) + assert (rc.y () == cc.y ()); + } + + { + complex& rc (dynamic_cast<complex&> (r->sbase ())); + complex& cc (dynamic_cast<complex&> (c->sbase ())); + + assert (rc.a () == cc.a ()); + if (rc.b ()) + assert (rc.b () == cc.b ()); + assert (rc.c () == cc.c ()); + + assert (rc.x () == cc.x ()); + if (rc.y ()) + assert (rc.y () == cc.y ()); + } + + // integers + // + assert (r->byte () == c->byte ()); + assert (r->unsigned_byte () == c->unsigned_byte ()); + assert (r->short_ () == c->short_ ()); + assert (r->unsigned_short () == c->unsigned_short ()); + assert (r->int_ () == c->int_ ()); + assert (r->unsigned_int () == c->unsigned_int ()); + assert (r->long_ () == c->long_ ()); + assert (r->unsigned_long () == c->unsigned_long ()); + assert (r->integer () == c->integer ()); + assert (r->non_positive_integer () == c->non_positive_integer ()); + assert (r->non_negative_integer () == c->non_negative_integer ()); + assert (r->positive_integer () == c->positive_integer ()); + assert (r->negative_integer () == c->negative_integer ()); + + // boolean + // + assert (r->boolean () == c->boolean ()); + + // floats + // + assert (r->float_ () == c->float_ ()); + assert (r->double_ () == c->double_ ()); + assert (r->decimal () == c->decimal ()); + + // strings + // + assert (r->string () == c->string ()); + assert (r->normalized_string () == c->normalized_string ()); + assert (r->token () == c->token ()); + assert (r->name () == c->name ()); + assert (r->name_token () == c->name_token ()); + assert (r->name_tokens () == c->name_tokens ()); + assert (r->ncname () == c->ncname ()); + assert (r->language () == c->language ()); + + // qualified name + // + assert (r->qname () == c->qname ()); + + // ID/IDREF + // + assert (r->id () == c->id ()); + assert (r->id_ref () == c->id_ref ()); + assert (r->id_refs () == c->id_refs ()); + + // URI + // + assert (r->any_uri () == c->any_uri ()); + + // binary + // + assert (r->base64_binary () == c->base64_binary ()); + assert (r->hex_binary () == c->hex_binary ()); + + // date/time + // + assert (r->date () == c->date ()); + assert (r->date_time () == c->date_time ()); + assert (r->duration () == c->duration ()); + assert (r->day () == c->day ()); + assert (r->month () == c->month ()); + assert (r->month_day () == c->month_day ()); + assert (r->year () == c->year ()); + assert (r->year_month () == c->year_month ()); + assert (r->time () == c->time ()); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/binary/polymorphic/makefile b/xsd/tests/cxx/tree/binary/polymorphic/makefile new file mode 100644 index 0000000..05c5186 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/polymorphic/makefile @@ -0,0 +1,91 @@ +# file : tests/cxx/tree/binary/polymorphic/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) + +$(call import,\ + $(scf_root)/import/libace/stub.make,\ + l: ace.l,cpp-options: ace.l.cpp-options) + +# Build. +# +$(driver): $(obj) $(xerces_c.l) $(ace.l) + +$(obj) $(dep): cpp_options := -I$(out_base) -I$(src_base) -I$(src_root)/libxsd +$(obj) $(dep): $(xerces_c.l.cpp-options) $(ace.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 --root-element-last \ +--generate-insertion ACE_OutputCDR --generate-extraction ACE_InputCDR \ + --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/binary/polymorphic/test.xml b/xsd/tests/cxx/tree/binary/polymorphic/test.xml new file mode 100644 index 0000000..ad3a403 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/polymorphic/test.xml @@ -0,0 +1,92 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <list>1 2 3</list> + + <union>abc</union> + + <enumeration>left</enumeration> + + <base x="1" xsi:type="t:complex"> + <a>aaa</a> + </base> + + <t:scomplex x="1" y="2"> + <a>aaa</a> + <b>bbb</b> + <c>c</c> + <c>cc</c> + <c>ccc</c> + </t:scomplex> + + + <!-- integers --> + <byte>65</byte> + <unsigned_byte>66</unsigned_byte> + <short>-222</short> + <unsigned_short>57005</unsigned_short> + <int>-57005</int> + <unsigned_int>3735928559</unsigned_int> + <long>-3735928559</long> + <unsigned_long>16045690984833335023</unsigned_long> + <integer>-3735928559</integer> + <non_positive_integer>-3735928559</non_positive_integer> + <non_negative_integer>3735928559</non_negative_integer> + <positive_integer>3735928559</positive_integer> + <negative_integer>-3735928559</negative_integer> + + + <!-- boolean --> + <boolean>true</boolean> + + + <!-- floats --> + <float>1234.1234</float> + <double>12345678.12345678</double> + <decimal>1234567812345678.1234567812345678</decimal> + + + <!-- strings --> + <string>string</string> + <normalized_string>normalized string</normalized_string> + <token>one two three</token> + <name>name</name> + <name_token>name-token</name_token> + <name_tokens>name tokens</name_tokens> + <ncname>ncname</ncname> + <language>en-us</language> + + <!-- qualified name --> + <qname>xsi:schemaLocation</qname> + + + <!-- ID/IDREF --> + <id>elements1</id> + <id>elements2</id> + <id_ref>elements1</id_ref> + <id_refs>elements1 elements2</id_refs> + + + <!-- URI --> + <any_uri>http://www.codesynthesis.com</any_uri> + + + <!-- binary --> + <base64_binary>YmFzZTY0IGJpbmFyeQ==</base64_binary> + <hex_binary>6865782052696E617279</hex_binary> + + + <!-- date/time --> + <date>2001-10-26+02:00</date> + <date_time>2001-10-26T21:32:52+02:00</date_time> + <duration>P1Y2M3DT5H20M30S</duration> + <day>---01+02:00</day> + <month>--11+02:00</month> + <month_day>--11-02+02:00</month_day> + <year>2001+02:00</year> + <year_month>2001-11+02:00</year_month> + <time>21:32:52+02:00</time> + + +</t:root> diff --git a/xsd/tests/cxx/tree/binary/polymorphic/test.xsd b/xsd/tests/cxx/tree/binary/polymorphic/test.xsd new file mode 100644 index 0000000..8c214e5 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/polymorphic/test.xsd @@ -0,0 +1,125 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:t="test" + targetNamespace="test"> + + <simpleType name="list"> + <list itemType="int"/> + </simpleType> + + <simpleType name="union"> + <union memberTypes="int string"/> + </simpleType> + + <simpleType name="enumeration"> + <restriction base="string"> + <enumeration value="top"/> + <enumeration value="left"/> + <enumeration value="bottom"/> + <enumeration value="right"/> + </restriction> + </simpleType> + + <complexType name="base"> + <sequence> + <element name="a" type="string"/> + </sequence> + <attribute name="x" type="int" use="required"/> + </complexType> + + <element name="sbase" type="t:base"/> + + <complexType name="complex"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="y" type="int"/> + </extension> + </complexContent> + </complexType> + + <element name="scomplex" type="t:complex" substitutionGroup="t:sbase"/> + + <complexType name="type"> + <sequence> + <element name="list" type="t:list"/> + <element name="union" type="t:union"/> + <element name="enumeration" type="t:enumeration"/> + + <element name="base" type="t:base"/> + <element ref="t:sbase"/> + + <!-- integers --> + <element name="byte" type="byte"/> + <element name="unsigned_byte" type="unsignedByte"/> + <element name="short" type="short"/> + <element name="unsigned_short" type="unsignedShort"/> + <element name="int" type="int"/> + <element name="unsigned_int" type="unsignedInt"/> + <element name="long" type="long"/> + <element name="unsigned_long" type="unsignedLong"/> + <element name="integer" type="integer"/> + <element name="non_positive_integer" type="nonPositiveInteger"/> + <element name="non_negative_integer" type="nonNegativeInteger"/> + <element name="positive_integer" type="positiveInteger"/> + <element name="negative_integer" type="negativeInteger"/> + + + <!-- boolean --> + <element name="boolean" type="boolean"/> + + + <!-- floats --> + <element name="float" type="float"/> + <element name="double" type="double"/> + <element name="decimal" type="decimal"/> + + + <!-- strings --> + <element name="string" type="string"/> + <element name="normalized_string" type="normalizedString"/> + <element name="token" type="token"/> + <element name="name" type="Name"/> + <element name="name_token" type="NMTOKEN"/> + <element name="name_tokens" type="NMTOKENS"/> + <element name="ncname" type="NCName"/> + <element name="language" type="language"/> + + <!-- qualified name --> + <element name="qname" type="QName"/> + + + <!-- ID/IDREF --> + <element name="id" maxOccurs="2" type="ID"/> + <element name="id_ref" type="IDREF"/> + <element name="id_refs" type="IDREFS"/> + + + <!-- URI --> + <element name="any_uri" type="anyURI"/> + + + <!-- binary --> + <element name="base64_binary" type="base64Binary"/> + <element name="hex_binary" type="hexBinary"/> + + + <!-- date/time --> + <element name="date" type="date"/> + <element name="date_time" type="dateTime"/> + <element name="duration" type="duration"/> + <element name="day" type="gDay"/> + <element name="month" type="gMonth"/> + <element name="month_day" type="gMonthDay"/> + <element name="year" type="gYear"/> + <element name="year_month" type="gYearMonth"/> + <element name="time" type="time"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/binary/xdr/driver.cxx b/xsd/tests/cxx/tree/binary/xdr/driver.cxx new file mode 100644 index 0000000..623a953 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/xdr/driver.cxx @@ -0,0 +1,188 @@ +// file : tests/cxx/tree/binary/xdr/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test non-polymorphic binary serialization to XDR. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <cstring> // std::memcpy +#include <cassert> +#include <iostream> + +#include "test.hxx" + +using namespace std; +using namespace test; + +extern "C" int +overflow (char* p, char* buf, int in) +{ + xml_schema::buffer* dst (reinterpret_cast<xml_schema::buffer*> (p)); + + size_t n (static_cast<size_t> (in)), size (dst->size ()); + dst->size (size + n); + memcpy (dst->data () + size, buf, n); + + return static_cast<int> (n); +} + +struct underflow_info +{ + xml_schema::buffer* buf; + std::size_t pos; +}; + +extern "C" int +underflow (char* p, char* buf, int in) +{ + underflow_info* ui (reinterpret_cast<underflow_info*> (p)); + + size_t n (static_cast<size_t> (in)), size (ui->buf->size () - ui->pos); + n = size > n ? n : size; + + memcpy (buf, ui->buf->data () + ui->pos, n); + ui->pos += n; + + return static_cast<int> (n); +} + +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])); + + // Save to an XDR stream. + // + XDR xdr; + xml_schema::buffer buf; + xdrrec_create (&xdr, 0, 0, reinterpret_cast<char*> (&buf), 0, &overflow); + xdr.x_op = XDR_ENCODE; + xsd::cxx::tree::ostream<XDR> oxdr (xdr); + oxdr << *r; + xdrrec_endofrecord (&xdr, true); // flush the data + xdr_destroy (&xdr); + + // Load from an XDR stream. + // + underflow_info ui; + ui.buf = &buf; + ui.pos = 0; + xdrrec_create (&xdr, 0, 0, reinterpret_cast<char*> (&ui), &underflow, 0); + xdr.x_op = XDR_DECODE; + xdrrec_skiprecord (&xdr); + xsd::cxx::tree::istream<XDR> ixdr (xdr); + XSD_AUTO_PTR<type> c (new type (ixdr)); + xdr_destroy (&xdr); + + // Compare the two. + // + assert (r->list () == c->list ()); + assert (r->union_ () == c->union_ ()); + assert (r->enumeration () == c->enumeration ()); + + type::complex_sequence rs (r->complex ()), cs (c->complex ()); + + for (type::complex_iterator ri (rs.begin ()), ci (cs.begin ()); + ri != rs.end () && ci != rs.end (); ++ri, ++ci) + { + assert (ri->a () == ci->a ()); + if (ri->b ()) + assert (ri->b () == ci->b ()); + assert (ri->c () == ci->c ()); + + assert (ri->x () == ci->x ()); + if (ri->y ()) + assert (ri->y () == ci->y ()); + } + + // integers + // + assert (r->byte () == c->byte ()); + assert (r->unsigned_byte () == c->unsigned_byte ()); + assert (r->short_ () == c->short_ ()); + assert (r->unsigned_short () == c->unsigned_short ()); + assert (r->int_ () == c->int_ ()); + assert (r->unsigned_int () == c->unsigned_int ()); + assert (r->long_ () == c->long_ ()); + assert (r->unsigned_long () == c->unsigned_long ()); + assert (r->integer () == c->integer ()); + assert (r->non_positive_integer () == c->non_positive_integer ()); + assert (r->non_negative_integer () == c->non_negative_integer ()); + assert (r->positive_integer () == c->positive_integer ()); + assert (r->negative_integer () == c->negative_integer ()); + + // boolean + // + assert (r->boolean () == c->boolean ()); + + // floats + // + assert (r->float_ () == c->float_ ()); + assert (r->double_ () == c->double_ ()); + assert (r->decimal () == c->decimal ()); + + // strings + // + assert (r->string () == c->string ()); + assert (r->normalized_string () == c->normalized_string ()); + assert (r->token () == c->token ()); + assert (r->name () == c->name ()); + assert (r->name_token () == c->name_token ()); + assert (r->name_tokens () == c->name_tokens ()); + assert (r->ncname () == c->ncname ()); + assert (r->language () == c->language ()); + + // qualified name + // + assert (r->qname () == c->qname ()); + + // ID/IDREF + // + assert (r->id () == c->id ()); + assert (r->id_ref () == c->id_ref ()); + assert (r->id_refs () == c->id_refs ()); + + // URI + // + assert (r->any_uri () == c->any_uri ()); + + // binary + // + assert (r->base64_binary () == c->base64_binary ()); + assert (r->hex_binary () == c->hex_binary ()); + + // date/time + // + assert (r->date () == c->date ()); + assert (r->date_time () == c->date_time ()); + assert (r->duration () == c->duration ()); + assert (r->day () == c->day ()); + assert (r->month () == c->month ()); + assert (r->month_day () == c->month_day ()); + assert (r->year () == c->year ()); + assert (r->year_month () == c->year_month ()); + assert (r->time () == c->time ()); + + // anySimpleType + // + assert (!r->any_simple_type_attr ().text_content ().empty ()); + assert (r->any_simple_type_attr () == c->any_simple_type_attr ()); + + assert (!r->any_simple_type ().text_content ().empty ()); + assert (r->any_simple_type () == c->any_simple_type ()); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/binary/xdr/makefile b/xsd/tests/cxx/tree/binary/xdr/makefile new file mode 100644 index 0000000..2994134 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/xdr/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/binary/xdr/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-insertion XDR --generate-extraction XDR \ +--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/binary/xdr/test.xml b/xsd/tests/cxx/tree/binary/xdr/test.xml new file mode 100644 index 0000000..5cedd98 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/xdr/test.xml @@ -0,0 +1,93 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd" + any_simple_type_attr="any simple content"> + + <list>1 2 3</list> + + <union>abc</union> + + <enumeration>left</enumeration> + + <complex x="1"> + <a>aaa</a> + </complex> + <complex x="1" y="2"> + <a>aaa</a> + <b>bbb</b> + <c>c</c> + <c>cc</c> + <c>ccc</c> + </complex> + + + <!-- integers --> + <byte>65</byte> + <unsigned_byte>66</unsigned_byte> + <short>-222</short> + <unsigned_short>57005</unsigned_short> + <int>-57005</int> + <unsigned_int>3735928559</unsigned_int> + <long>-3735928559</long> + <unsigned_long>16045690984833335023</unsigned_long> + <integer>-3735928559</integer> + <non_positive_integer>-3735928559</non_positive_integer> + <non_negative_integer>3735928559</non_negative_integer> + <positive_integer>3735928559</positive_integer> + <negative_integer>-3735928559</negative_integer> + + + <!-- boolean --> + <boolean>true</boolean> + + + <!-- floats --> + <float>1234.1234</float> + <double>12345678.12345678</double> + <decimal>1234567812345678.1234567812345678</decimal> + + + <!-- strings --> + <string>string</string> + <normalized_string>normalized string</normalized_string> + <token>one two three</token> + <name>name</name> + <name_token>name-token</name_token> + <name_tokens>name tokens</name_tokens> + <ncname>ncname</ncname> + <language>en-us</language> + + <!-- qualified name --> + <qname>xsi:schemaLocation</qname> + + + <!-- ID/IDREF --> + <id>elements1</id> + <id>elements2</id> + <id_ref>elements1</id_ref> + <id_refs>elements1 elements2</id_refs> + + + <!-- URI --> + <any_uri>http://www.codesynthesis.com</any_uri> + + + <!-- binary --> + <base64_binary>YmFzZTY0IGJpbmFyeQ==</base64_binary> + <hex_binary>6865782052696E617279</hex_binary> + + + <!-- date/time --> + <date>2001-10-26+02:00</date> + <date_time>2001-10-26T21:32:52+02:00</date_time> + <duration>P1Y2M3DT5H20M30S</duration> + <day>---01+02:00</day> + <month>--11+02:00</month> + <month_day>--11-02+02:00</month_day> + <year>2001+02:00</year> + <year_month>2001-11+02:00</year_month> + <time>21:32:52+02:00</time> + + <any_simple_type>any simple content in element</any_simple_type> + +</t:root> diff --git a/xsd/tests/cxx/tree/binary/xdr/test.xsd b/xsd/tests/cxx/tree/binary/xdr/test.xsd new file mode 100644 index 0000000..0629e94 --- /dev/null +++ b/xsd/tests/cxx/tree/binary/xdr/test.xsd @@ -0,0 +1,123 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:t="test" + targetNamespace="test"> + + <simpleType name="list"> + <list itemType="int"/> + </simpleType> + + <simpleType name="union"> + <union memberTypes="int string"/> + </simpleType> + + <simpleType name="enumeration"> + <restriction base="string"> + <enumeration value="top"/> + <enumeration value="left"/> + <enumeration value="bottom"/> + <enumeration value="right"/> + </restriction> + </simpleType> + + <complexType name="base"> + <sequence> + <element name="a" type="string"/> + </sequence> + <attribute name="x" type="int" use="required"/> + </complexType> + + <complexType name="complex"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="y" type="int"/> + </extension> + </complexContent> + </complexType> + + + <complexType name="type"> + <sequence> + <element name="list" type="t:list"/> + <element name="union" type="t:union"/> + <element name="enumeration" type="t:enumeration"/> + <element name="complex" type="t:complex" maxOccurs="unbounded"/> + + <!-- integers --> + <element name="byte" type="byte"/> + <element name="unsigned_byte" type="unsignedByte"/> + <element name="short" type="short"/> + <element name="unsigned_short" type="unsignedShort"/> + <element name="int" type="int"/> + <element name="unsigned_int" type="unsignedInt"/> + <element name="long" type="long"/> + <element name="unsigned_long" type="unsignedLong"/> + <element name="integer" type="integer"/> + <element name="non_positive_integer" type="nonPositiveInteger"/> + <element name="non_negative_integer" type="nonNegativeInteger"/> + <element name="positive_integer" type="positiveInteger"/> + <element name="negative_integer" type="negativeInteger"/> + + + <!-- boolean --> + <element name="boolean" type="boolean"/> + + + <!-- floats --> + <element name="float" type="float"/> + <element name="double" type="double"/> + <element name="decimal" type="decimal"/> + + + <!-- strings --> + <element name="string" type="string"/> + <element name="normalized_string" type="normalizedString"/> + <element name="token" type="token"/> + <element name="name" type="Name"/> + <element name="name_token" type="NMTOKEN"/> + <element name="name_tokens" type="NMTOKENS"/> + <element name="ncname" type="NCName"/> + <element name="language" type="language"/> + + <!-- qualified name --> + <element name="qname" type="QName"/> + + + <!-- ID/IDREF --> + <element name="id" maxOccurs="2" type="ID"/> + <element name="id_ref" type="IDREF"/> + <element name="id_refs" type="IDREFS"/> + + + <!-- URI --> + <element name="any_uri" type="anyURI"/> + + + <!-- binary --> + <element name="base64_binary" type="base64Binary"/> + <element name="hex_binary" type="hexBinary"/> + + + <!-- date/time --> + <element name="date" type="date"/> + <element name="date_time" type="dateTime"/> + <element name="duration" type="duration"/> + <element name="day" type="gDay"/> + <element name="month" type="gMonth"/> + <element name="month_day" type="gMonthDay"/> + <element name="year" type="gYear"/> + <element name="year_month" type="gYearMonth"/> + <element name="time" type="time"/> + + <element name="any_simple_type" type="anySimpleType"/> + </sequence> + <attribute name="any_simple_type_attr" type="anySimpleType" use="required"/> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/built-in/attributes.xml b/xsd/tests/cxx/tree/built-in/attributes.xml new file mode 100644 index 0000000..609a757 --- /dev/null +++ b/xsd/tests/cxx/tree/built-in/attributes.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<test:attributes + xmlns:test="http://www.codesynthesis.com/xmlns/test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.codesynthesis.com/xmlns/test types.xsd" + + + byte="65" + unsigned_byte="66" + short="-222" + unsigned_short="57005" + int="-57005" + unsigned_int="3735928559" + long="-3735928559" + unsigned_long="16045690984833335023" + integer="-3735928559" + non_positive_integer="-3735928559" + non_negative_integer="3735928559" + positive_integer="3735928559" + negative_integer="-3735928559" + + + + boolean="false" + + + + float="1234.1234" + double="12345678.12345678" + decimal="12345678.12345678" + + + + string="string" + normalized_string="normalized string" + token=" one two three " + name="name" + name_token="name-token" + name_tokens="name tokens" + ncname="ncname" + language="en-us" + + + qname="xsi:schemaLocation" + + + + id="attributes" + id_ref="attributes" + id_refs="attributes" + + + + any_uri="http://www.codesynthesis.com" + + + + base64_binary="YmFzZTY0IGJpbmFyeQ==" + hex_binary="6865782052696E617279" + + + + date="2001-10-26+02:00" + date_time="2001-10-26T21:32:52+02:00" + duration="P1Y2M3DT5H20M30S" + day="---01+02:00" + month="--11+02:00" + month_day="--11-02+02:00" + year="2001+02:00" + year_month="2001-11+02:00" + time="21:32:52+02:00" + +/> diff --git a/xsd/tests/cxx/tree/built-in/driver.cxx b/xsd/tests/cxx/tree/built-in/driver.cxx new file mode 100644 index 0000000..f60ac16 --- /dev/null +++ b/xsd/tests/cxx/tree/built-in/driver.cxx @@ -0,0 +1,94 @@ +// file : tests/cxx/tree/built-in/driver.cxx +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test built-in type mapping. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <sstream> +#include <iostream> + + +#include "types.hxx" + +using std::cerr; +using std::endl; + +int +main (int argc, char* argv[]) +{ + if (argc != 4) + { + cerr << "usage: " << argv[0] << " elements.xml attributes.xml inherited.xml" << endl; + return 1; + } + + XSD_AUTO_PTR<xmlns::test::Elements> elements ( + xmlns::test::elements (argv[1])); + + XSD_AUTO_PTR<xmlns::test::Attributes> attributes ( + xmlns::test::attributes (argv[2])); + + XSD_AUTO_PTR<xmlns::test::Inherited> inherited ( + xmlns::test::inherited (argv[3])); + + cerr << "elements: " << *elements << endl + << endl + << "attributes: " << *attributes << endl + << endl + << "inherited: " << *inherited << endl; + + // Test parsing/serialization. + // + + xml_schema::namespace_infomap map; + + map["test"].name = "http://www.codesynthesis.com/xmlns/test"; + map["test"].schema = "types.xsd"; + + { + std::ostringstream ostr; + xmlns::test::elements (ostr, *elements, map); + + std::istringstream istr (ostr.str ()); + XSD_AUTO_PTR<xmlns::test::Elements> elements1 ( + xmlns::test::elements (istr)); + + std::ostringstream ostr1; + xmlns::test::elements (ostr1, *elements1, map); + + if (ostr.str () != ostr1.str ()) + return 1; + } + + { + std::ostringstream ostr; + xmlns::test::attributes (ostr, *attributes, map); + + std::istringstream istr (ostr.str ()); + XSD_AUTO_PTR<xmlns::test::Attributes> attributes1 ( + xmlns::test::attributes (istr)); + + std::ostringstream ostr1; + xmlns::test::attributes (ostr1, *attributes1, map); + + if (ostr.str () != ostr1.str ()) + return 1; + } + + { + std::ostringstream ostr; + xmlns::test::inherited (ostr, *inherited, map); + + std::istringstream istr (ostr.str ()); + XSD_AUTO_PTR<xmlns::test::Inherited> inherited1 ( + xmlns::test::inherited (istr)); + + std::ostringstream ostr1; + xmlns::test::inherited (ostr1, *inherited1, map); + + if (ostr.str () != ostr1.str ()) + return 1; + } +} diff --git a/xsd/tests/cxx/tree/built-in/elements.xml b/xsd/tests/cxx/tree/built-in/elements.xml new file mode 100644 index 0000000..f76f019 --- /dev/null +++ b/xsd/tests/cxx/tree/built-in/elements.xml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<test:elements + xmlns:test="http://www.codesynthesis.com/xmlns/test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.codesynthesis.com/xmlns/test types.xsd"> + + <!-- integers --> + <byte>65</byte> + <unsigned_byte>66</unsigned_byte> + <short>-222</short> + <unsigned_short>57005</unsigned_short> + <int>-57005</int> + <unsigned_int>3735928559</unsigned_int> + <long>-3735928559</long> + <unsigned_long>16045690984833335023</unsigned_long> + <integer>-3735928559</integer> + <non_positive_integer>-3735928559</non_positive_integer> + <non_negative_integer>3735928559</non_negative_integer> + <positive_integer>3735928559</positive_integer> + <negative_integer>-3735928559</negative_integer> + + + <!-- boolean --> + <boolean>true</boolean> + + + <!-- floats --> + <float>1234.1234</float> + <double>12345678.12345678</double> + <decimal>12345678.12345678</decimal> + + + <!-- strings --> + <string>string</string> + <normalized_string>normalized +string</normalized_string> + <token> + one + two three </token> + <name>name</name> + <name_token>name-token</name_token> + <name_tokens>name tokens</name_tokens> + <ncname>ncname</ncname> + <language>en-us</language> + + <!-- qualified name --> + <qname>xsi:schemaLocation</qname> + + + <!-- ID/IDREF --> + <id>elements1</id> + <id>elements2</id> + <id_ref>elements1</id_ref> + <id_refs>elements1 elements2</id_refs> + + + <!-- URI --> + <any_uri>http://www.codesynthesis.com</any_uri> + + + <!-- binary --> + <base64_binary>YmFzZTY0IGJpbmFyeQ==</base64_binary> + <hex_binary>6865782052696E617279</hex_binary> + + + <!-- date/time --> + <date>2001-10-26+02:00</date> + <date_time>2001-10-26T21:32:52+02:00</date_time> + <duration>P1Y2M3DT5H20M30S</duration> + <day>---01+02:00</day> + <month>--11+02:00</month> + <month_day>--11-02+02:00</month_day> + <year>2001+02:00</year> + <year_month>2001-11+02:00</year_month> + <time>21:32:52+02:00</time> + + + <!-- entity --> + <!-- + <entity>foo</entity> + <entities>foo bar</entities> + --> + +</test:elements> diff --git a/xsd/tests/cxx/tree/built-in/inherited.xml b/xsd/tests/cxx/tree/built-in/inherited.xml new file mode 100644 index 0000000..1781a69 --- /dev/null +++ b/xsd/tests/cxx/tree/built-in/inherited.xml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<test:inherited + xmlns:test="http://www.codesynthesis.com/xmlns/test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.codesynthesis.com/xmlns/test types.xsd"> + + <!-- integers --> + <byte>65</byte> + <unsigned_byte>66</unsigned_byte> + <short>-222</short> + <unsigned_short>57005</unsigned_short> + <int>-57005</int> + <unsigned_int>3735928559</unsigned_int> + <long>-3735928559</long> + <unsigned_long>16045690984833335023</unsigned_long> + <integer>-3735928559</integer> + <non_positive_integer>-3735928559</non_positive_integer> + <non_negative_integer>3735928559</non_negative_integer> + <positive_integer>3735928559</positive_integer> + <negative_integer>-3735928559</negative_integer> + + + <!-- boolean --> + <boolean>true</boolean> + + + <!-- floats --> + <float>1234.1234</float> + <double>12345678.12345678</double> + <decimal>12345678.12345678</decimal> + + + <!-- strings --> + <string>string</string> + <normalized_string>normalized +string</normalized_string> + <token> + one + two three </token> + <name>name</name> + <name_token>name-token</name_token> + <name_tokens>name tokens</name_tokens> + <ncname>ncname</ncname> + <language>en-us</language> + + <!-- qualified name --> + <qname>xsi:schemaLocation</qname> + + + <!-- ID/IDREF --> + <id>elements1</id> + <id>elements2</id> + <id_ref>elements1</id_ref> + <id_refs>elements1 elements2</id_refs> + + + <!-- URI --> + <any_uri>http://www.codesynthesis.com</any_uri> + + + <!-- binary --> + <base64_binary>YmFzZTY0IGJpbmFyeQ==</base64_binary> + <hex_binary>6865782052696E617279</hex_binary> + + + <!-- date/time --> + <date>2001-10-26+02:00</date> + <date_time>2001-10-26T21:32:52+02:00</date_time> + <duration>P1Y2M3DT5H20M30S</duration> + <day>---01+02:00</day> + <month>--11+02:00</month> + <month_day>--11-02+02:00</month_day> + <year>2001+02:00</year> + <year_month>2001-11+02:00</year_month> + <time>21:32:52+02:00</time> + + + <!-- entity --> + <!-- + <entity>foo</entity> + <entities>foo bar</entities> + --> + +</test:inherited> diff --git a/xsd/tests/cxx/tree/built-in/makefile b/xsd/tests/cxx/tree/built-in/makefile new file mode 100644 index 0000000..3df37c3 --- /dev/null +++ b/xsd/tests/cxx/tree/built-in/makefile @@ -0,0 +1,100 @@ +# file : tests/cxx/tree/built-in/makefile +# copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := types.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 += \ +--char-type char \ +--generate-inline \ +--generate-ostream \ +--generate-serialization \ +--generate-default-ctor \ +--generate-from-base-ctor \ +--root-element-all + +$(gen): $(out_root)/xsd/xsd + +$(call include-dep,$(dep),$(obj),$(gen)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +# We need to cd to src_base in order to have the schema in the working +# directory. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/elements.xml $(src_base)/attributes.xml \ +$(src_base)/inherited.xml + cd $(src_base) && $(driver) $(src_base)/elements.xml \ +$(src_base)/attributes.xml $(src_base)/inherited.xml + + +# 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/built-in/types.xsd b/xsd/tests/cxx/tree/built-in/types.xsd new file mode 100644 index 0000000..22582cb --- /dev/null +++ b/xsd/tests/cxx/tree/built-in/types.xsd @@ -0,0 +1,460 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3.org/2001/XMLSchema XMLSchema.xsd" + xmlns="http://www.codesynthesis.com/xmlns/test" + targetNamespace="http://www.codesynthesis.com/xmlns/test"> + + <!-- elements --> + + <xsd:complexType name="Elements"> + <xsd:sequence> + + <!-- integers --> + <xsd:element name="byte" type="xsd:byte"/> + <xsd:element name="unsigned_byte" type="xsd:unsignedByte"/> + <xsd:element name="short" type="xsd:short"/> + <xsd:element name="unsigned_short" type="xsd:unsignedShort"/> + <xsd:element name="int" type="xsd:int"/> + <xsd:element name="unsigned_int" type="xsd:unsignedInt"/> + <xsd:element name="long" type="xsd:long"/> + <xsd:element name="unsigned_long" type="xsd:unsignedLong"/> + <xsd:element name="integer" type="xsd:integer"/> + <xsd:element name="non_positive_integer" type="xsd:nonPositiveInteger"/> + <xsd:element name="non_negative_integer" type="xsd:nonNegativeInteger"/> + <xsd:element name="positive_integer" type="xsd:positiveInteger"/> + <xsd:element name="negative_integer" type="xsd:negativeInteger"/> + + + <!-- boolean --> + <xsd:element name="boolean" type="xsd:boolean"/> + + + <!-- floats --> + <xsd:element name="float" type="xsd:float"/> + <xsd:element name="double" type="xsd:double"/> + <xsd:element name="decimal" type="xsd:decimal"/> + + + <!-- strings --> + <xsd:element name="string" type="xsd:string"/> + <xsd:element name="normalized_string" type="xsd:normalizedString"/> + <xsd:element name="token" type="xsd:token"/> + <xsd:element name="name" type="xsd:Name"/> + <xsd:element name="name_token" type="xsd:NMTOKEN"/> + <xsd:element name="name_tokens" type="xsd:NMTOKENS"/> + <xsd:element name="ncname" type="xsd:NCName"/> + <xsd:element name="language" type="xsd:language"/> + + <!-- qualified name --> + <xsd:element name="qname" type="xsd:QName"/> + + + <!-- ID/IDREF --> + <xsd:element name="id" maxOccurs="2" type="xsd:ID"/> + <xsd:element name="id_ref" type="xsd:IDREF"/> + <xsd:element name="id_refs" type="xsd:IDREFS"/> + + + <!-- URI --> + <xsd:element name="any_uri" type="xsd:anyURI"/> + + + <!-- binary --> + <xsd:element name="base64_binary" type="xsd:base64Binary"/> + <xsd:element name="hex_binary" type="xsd:hexBinary"/> + + + <!-- date/time --> + <xsd:element name="date" type="xsd:date"/> + <xsd:element name="date_time" type="xsd:dateTime"/> + <xsd:element name="duration" type="xsd:duration"/> + <xsd:element name="day" type="xsd:gDay"/> + <xsd:element name="month" type="xsd:gMonth"/> + <xsd:element name="month_day" type="xsd:gMonthDay"/> + <xsd:element name="year" type="xsd:gYear"/> + <xsd:element name="year_month" type="xsd:gYearMonth"/> + <xsd:element name="time" type="xsd:time"/> + + + <!-- entity --> + <!-- + <xsd:element name="entity" type="xsd:ENTITY"/> + <xsd:element name="entities" type="xsd:ENTITIES"/> + --> + + + <!-- notation --> + <!-- xsd:element name="notation" type="xsd:NOTATION"/ --> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="elements" type="Elements"/> + + + + <!-- attributes --> + + <xsd:complexType name="Attributes"> + <!-- integers --> + <xsd:attribute name="byte" type="xsd:byte"/> + <xsd:attribute name="unsigned_byte" type="xsd:unsignedByte"/> + <xsd:attribute name="short" type="xsd:short"/> + <xsd:attribute name="unsigned_short" type="xsd:unsignedShort"/> + <xsd:attribute name="int" type="xsd:int"/> + <xsd:attribute name="unsigned_int" type="xsd:unsignedInt"/> + <xsd:attribute name="long" type="xsd:long"/> + <xsd:attribute name="unsigned_long" type="xsd:unsignedLong"/> + <xsd:attribute name="integer" type="xsd:integer"/> + <xsd:attribute name="non_positive_integer" type="xsd:nonPositiveInteger"/> + <xsd:attribute name="non_negative_integer" type="xsd:nonNegativeInteger"/> + <xsd:attribute name="positive_integer" type="xsd:positiveInteger"/> + <xsd:attribute name="negative_integer" type="xsd:negativeInteger"/> + + + <!-- boolean --> + <xsd:attribute name="boolean" type="xsd:boolean"/> + + + <!-- floats --> + <xsd:attribute name="float" type="xsd:float"/> + <xsd:attribute name="double" type="xsd:double"/> + <xsd:attribute name="decimal" type="xsd:decimal"/> + + + <!-- strings --> + <xsd:attribute name="string" type="xsd:string"/> + <xsd:attribute name="normalized_string" type="xsd:normalizedString"/> + <xsd:attribute name="token" type="xsd:token"/> + <xsd:attribute name="name" type="xsd:Name"/> + <xsd:attribute name="name_token" type="xsd:NMTOKEN"/> + <xsd:attribute name="name_tokens" type="xsd:NMTOKENS"/> + <xsd:attribute name="ncname" type="xsd:NCName"/> + <xsd:attribute name="language" type="xsd:language"/> + + <!-- qualified name --> + <xsd:attribute name="qname" type="xsd:QName"/> + + + <!-- ID/IDREF --> + <xsd:attribute name="id" type="xsd:ID"/> + <xsd:attribute name="id_ref" type="xsd:IDREF"/> + <xsd:attribute name="id_refs" type="xsd:IDREFS"/> + + + <!-- URI --> + <xsd:attribute name="any_uri" type="xsd:anyURI"/> + + + <!-- binary --> + <xsd:attribute name="base64_binary" type="xsd:base64Binary"/> + <xsd:attribute name="hex_binary" type="xsd:hexBinary"/> + + + <!-- date/time --> + <xsd:attribute name="date" type="xsd:date"/> + <xsd:attribute name="date_time" type="xsd:dateTime"/> + <xsd:attribute name="duration" type="xsd:duration"/> + <xsd:attribute name="day" type="xsd:gDay"/> + <xsd:attribute name="month" type="xsd:gMonth"/> + <xsd:attribute name="month_day" type="xsd:gMonthDay"/> + <xsd:attribute name="year" type="xsd:gYear"/> + <xsd:attribute name="year_month" type="xsd:gYearMonth"/> + <xsd:attribute name="time" type="xsd:time"/> + + + <!-- entity --> + <!-- + <xsd:attribute name="entity" type="xsd:ENTITY"/> + <xsd:attribute name="entities" type="xsd:ENTITIES"/> + --> + + + <!-- notation --> + <!-- xsd:element name="notation" type="xsd:NOTATION"/ --> + </xsd:complexType> + + <xsd:element name="attributes" type="Attributes"/> + + + <!-- inheritance --> + + <!-- integers --> + <xsd:simpleType name="Byte"> + <xsd:restriction base="xsd:byte"/> + </xsd:simpleType> + + <xsd:simpleType name="UnsignedByte"> + <xsd:restriction base="xsd:unsignedByte"/> + </xsd:simpleType> + + <xsd:simpleType name="Short"> + <xsd:restriction base="xsd:short"/> + </xsd:simpleType> + + <xsd:simpleType name="UnsignedShort"> + <xsd:restriction base="xsd:unsignedShort"/> + </xsd:simpleType> + + <xsd:simpleType name="Int"> + <xsd:restriction base="xsd:int"/> + </xsd:simpleType> + + <xsd:simpleType name="UnsignedInt"> + <xsd:restriction base="xsd:unsignedInt"/> + </xsd:simpleType> + + <xsd:simpleType name="Long"> + <xsd:restriction base="xsd:long"/> + </xsd:simpleType> + + <xsd:simpleType name="UnsignedLong"> + <xsd:restriction base="xsd:unsignedLong"/> + </xsd:simpleType> + + <xsd:simpleType name="Integer"> + <xsd:restriction base="xsd:integer"/> + </xsd:simpleType> + + <xsd:simpleType name="NonPositiveInteger"> + <xsd:restriction base="xsd:nonPositiveInteger"/> + </xsd:simpleType> + + <xsd:simpleType name="NonNegativeInteger"> + <xsd:restriction base="xsd:nonNegativeInteger"/> + </xsd:simpleType> + + <xsd:simpleType name="PositiveInteger"> + <xsd:restriction base="xsd:positiveInteger"/> + </xsd:simpleType> + + <xsd:simpleType name="NegativeInteger"> + <xsd:restriction base="xsd:negativeInteger"/> + </xsd:simpleType> + + + <!-- boolean --> + <xsd:simpleType name="Boolean"> + <xsd:restriction base="xsd:boolean"/> + </xsd:simpleType> + + + <!-- floats --> + <xsd:simpleType name="Float"> + <xsd:restriction base="xsd:float"/> + </xsd:simpleType> + + <xsd:simpleType name="Double"> + <xsd:restriction base="xsd:double"/> + </xsd:simpleType> + + <xsd:simpleType name="Decimal"> + <xsd:restriction base="xsd:decimal"/> + </xsd:simpleType> + + + <!-- strings --> + <xsd:simpleType name="String"> + <xsd:restriction base="xsd:string"/> + </xsd:simpleType> + + <xsd:simpleType name="NormalizedString"> + <xsd:restriction base="xsd:normalizedString"/> + </xsd:simpleType> + + <xsd:simpleType name="Token"> + <xsd:restriction base="xsd:token"/> + </xsd:simpleType> + + <xsd:simpleType name="Name"> + <xsd:restriction base="xsd:Name"/> + </xsd:simpleType> + + <xsd:simpleType name="NameToken"> + <xsd:restriction base="xsd:NMTOKEN"/> + </xsd:simpleType> + + <xsd:simpleType name="NameTokens"> + <xsd:restriction base="xsd:NMTOKENS"/> + </xsd:simpleType> + + <xsd:simpleType name="NCName"> + <xsd:restriction base="xsd:NCName"/> + </xsd:simpleType> + + <xsd:simpleType name="Language"> + <xsd:restriction base="xsd:language"/> + </xsd:simpleType> + + + <!-- qualified name --> + <xsd:simpleType name="QName"> + <xsd:restriction base="xsd:QName"/> + </xsd:simpleType> + + + <!-- ID/IDREF --> + <xsd:simpleType name="Id"> + <xsd:restriction base="xsd:ID"/> + </xsd:simpleType> + + <xsd:simpleType name="IdRef"> + <xsd:restriction base="xsd:IDREF"/> + </xsd:simpleType> + + <xsd:simpleType name="IdRefs"> + <xsd:restriction base="xsd:IDREFS"/> + </xsd:simpleType> + + + <!-- URI --> + <xsd:simpleType name="URI"> + <xsd:restriction base="xsd:anyURI"/> + </xsd:simpleType> + + + <!-- binary --> + <xsd:simpleType name="Base64Binary"> + <xsd:restriction base="xsd:base64Binary"/> + </xsd:simpleType> + + <xsd:simpleType name="HexBinary"> + <xsd:restriction base="xsd:hexBinary"/> + </xsd:simpleType> + + + <!-- date/time --> + <xsd:simpleType name="Date"> + <xsd:restriction base="xsd:date"/> + </xsd:simpleType> + + <xsd:simpleType name="DateTime"> + <xsd:restriction base="xsd:dateTime"/> + </xsd:simpleType> + + <xsd:simpleType name="Duration"> + <xsd:restriction base="xsd:duration"/> + </xsd:simpleType> + + <xsd:simpleType name="Day"> + <xsd:restriction base="xsd:gDay"/> + </xsd:simpleType> + + <xsd:simpleType name="Month"> + <xsd:restriction base="xsd:gMonth"/> + </xsd:simpleType> + + <xsd:simpleType name="MonthDay"> + <xsd:restriction base="xsd:gMonthDay"/> + </xsd:simpleType> + + <xsd:simpleType name="Year"> + <xsd:restriction base="xsd:gYear"/> + </xsd:simpleType> + + <xsd:simpleType name="YearMonth"> + <xsd:restriction base="xsd:gYearMonth"/> + </xsd:simpleType> + + <xsd:simpleType name="Time"> + <xsd:restriction base="xsd:time"/> + </xsd:simpleType> + + + <!-- entity --> + <!-- + <xsd:element name="entity" type="xsd:ENTITY"/> + <xsd:element name="entities" type="xsd:ENTITIES"/> + --> + + + <!-- notation --> + <!-- xsd:element name="notation" type="xsd:NOTATION"/ --> + + <!-- elements --> + + <xsd:complexType name="Inherited"> + <xsd:sequence> + + <!-- integers --> + <xsd:element name="byte" type="Byte"/> + <xsd:element name="unsigned_byte" type="UnsignedByte"/> + <xsd:element name="short" type="Short"/> + <xsd:element name="unsigned_short" type="UnsignedShort"/> + <xsd:element name="int" type="Int"/> + <xsd:element name="unsigned_int" type="UnsignedInt"/> + <xsd:element name="long" type="Long"/> + <xsd:element name="unsigned_long" type="UnsignedLong"/> + <xsd:element name="integer" type="Integer"/> + <xsd:element name="non_positive_integer" type="NonPositiveInteger"/> + <xsd:element name="non_negative_integer" type="NonNegativeInteger"/> + <xsd:element name="positive_integer" type="PositiveInteger"/> + <xsd:element name="negative_integer" type="NegativeInteger"/> + + + <!-- boolean --> + <xsd:element name="boolean" type="Boolean"/> + + + <!-- floats --> + <xsd:element name="float" type="Float"/> + <xsd:element name="double" type="Double"/> + <xsd:element name="decimal" type="Decimal"/> + + + <!-- strings --> + <xsd:element name="string" type="String"/> + <xsd:element name="normalized_string" type="NormalizedString"/> + <xsd:element name="token" type="Token"/> + <xsd:element name="name" type="Name"/> + <xsd:element name="name_token" type="NameToken"/> + <xsd:element name="name_tokens" type="NameTokens"/> + <xsd:element name="ncname" type="NCName"/> + <xsd:element name="language" type="Language"/> + + <!-- qualified name --> + <xsd:element name="qname" type="QName"/> + + + <!-- ID/IDREF --> + <xsd:element name="id" maxOccurs="2" type="Id"/> + <xsd:element name="id_ref" type="IdRef"/> + <xsd:element name="id_refs" type="IdRefs"/> + + + <!-- URI --> + <xsd:element name="any_uri" type="URI"/> + + + <!-- binary --> + <xsd:element name="base64_binary" type="Base64Binary"/> + <xsd:element name="hex_binary" type="HexBinary"/> + + + <!-- date/time --> + <xsd:element name="date" type="Date"/> + <xsd:element name="date_time" type="DateTime"/> + <xsd:element name="duration" type="Duration"/> + <xsd:element name="day" type="Day"/> + <xsd:element name="month" type="Month"/> + <xsd:element name="month_day" type="MonthDay"/> + <xsd:element name="year" type="Year"/> + <xsd:element name="year_month" type="YearMonth"/> + <xsd:element name="time" type="Time"/> + + + <!-- entity --> + <!-- + <xsd:element name="entity" type="xsd:ENTITY"/> + <xsd:element name="entities" type="xsd:ENTITIES"/> + --> + + + <!-- notation --> + <!-- xsd:element name="notation" type="xsd:NOTATION"/ --> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="inherited" type="Inherited"/> + +</xsd:schema> diff --git a/xsd/tests/cxx/tree/chameleon/driver.cxx b/xsd/tests/cxx/tree/chameleon/driver.cxx new file mode 100644 index 0000000..80c67da --- /dev/null +++ b/xsd/tests/cxx/tree/chameleon/driver.cxx @@ -0,0 +1,36 @@ +// file : tests/cxx/tree/chameleon/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test chameleon inclusion. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <iostream> + +#include "includer.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<root_t> 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/chameleon/includee.xsd b/xsd/tests/cxx/tree/chameleon/includee.xsd new file mode 100644 index 0000000..531a7d0 --- /dev/null +++ b/xsd/tests/cxx/tree/chameleon/includee.xsd @@ -0,0 +1,13 @@ +<?xml version="1.0" ?> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <xsd:complexType name="root_t"> + <xsd:sequence> + <xsd:element name="a" type="type"/> + <xsd:element ref="b"/> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="root" type="root_t"/> + +</xsd:schema> diff --git a/xsd/tests/cxx/tree/chameleon/includer.xsd b/xsd/tests/cxx/tree/chameleon/includer.xsd new file mode 100644 index 0000000..a1c850a --- /dev/null +++ b/xsd/tests/cxx/tree/chameleon/includer.xsd @@ -0,0 +1,12 @@ +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns="test" targetNamespace="test"> + + <xsd:include schemaLocation="includee.xsd"/> + + <xsd:simpleType name="type"> + <xsd:restriction base="xsd:string"/> + </xsd:simpleType> + + <xsd:element name="b" type="xsd:string"/> + +</xsd:schema> diff --git a/xsd/tests/cxx/tree/chameleon/makefile b/xsd/tests/cxx/tree/chameleon/makefile new file mode 100644 index 0000000..4ae7eb7 --- /dev/null +++ b/xsd/tests/cxx/tree/chameleon/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/chameleon/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 := includer.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 += --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/chameleon/output b/xsd/tests/cxx/tree/chameleon/output new file mode 100644 index 0000000..c40f715 --- /dev/null +++ b/xsd/tests/cxx/tree/chameleon/output @@ -0,0 +1,3 @@ + +a: a +b: b diff --git a/xsd/tests/cxx/tree/chameleon/test.xml b/xsd/tests/cxx/tree/chameleon/test.xml new file mode 100644 index 0000000..12ff279 --- /dev/null +++ b/xsd/tests/cxx/tree/chameleon/test.xml @@ -0,0 +1,8 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test includer.xsd"> + + <a>a</a> + <t:b>b</t:b> + +</t:root> diff --git a/xsd/tests/cxx/tree/comparison/driver.cxx b/xsd/tests/cxx/tree/comparison/driver.cxx new file mode 100644 index 0000000..e685050 --- /dev/null +++ b/xsd/tests/cxx/tree/comparison/driver.cxx @@ -0,0 +1,39 @@ +// file : tests/cxx/tree/comparison/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test generated comparison operators. +// + +#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])); + + type::complex_sequence s (r->complex ()); + + assert (s[0] == s[0]); + assert (s[0] != s[1]); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/comparison/makefile b/xsd/tests/cxx/tree/comparison/makefile new file mode 100644 index 0000000..82cb7b0 --- /dev/null +++ b/xsd/tests/cxx/tree/comparison/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/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-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/comparison/test.xml b/xsd/tests/cxx/tree/comparison/test.xml new file mode 100644 index 0000000..b5d8158 --- /dev/null +++ b/xsd/tests/cxx/tree/comparison/test.xml @@ -0,0 +1,19 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <complex x="123" y="abc"> + <a>123</a> + <b>abc</b> + <c x="123">abc</c> + <c x="456">def</c> + </complex> + + <complex x="123" y="abc"> + <a>123</a> + <b>abc</b> + <c x="123">abc</c> + <c x="456">xyz</c> + </complex> + +</t:root> diff --git a/xsd/tests/cxx/tree/comparison/test.xsd b/xsd/tests/cxx/tree/comparison/test.xsd new file mode 100644 index 0000000..c234add --- /dev/null +++ b/xsd/tests/cxx/tree/comparison/test.xsd @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="member"> + <simpleContent> + <extension base="string"> + <attribute name="x" type="int" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="complex"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="t:member" maxOccurs="unbounded"/> + </sequence> + <attribute name="x" type="int"/> + <attribute name="y" type="string" use="required"/> + </complexType> + + <complexType name="type"> + <sequence> + <element name="complex" type="t:complex" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/compilation/driver.cxx b/xsd/tests/cxx/tree/compilation/driver.cxx new file mode 100644 index 0000000..c2e6298 --- /dev/null +++ b/xsd/tests/cxx/tree/compilation/driver.cxx @@ -0,0 +1,117 @@ +// file : tests/cxx/tree/compilation/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Make sure the runtime library compiles by explicitly instantiating +// all the types. +// + +#include <iostream> + +#include "test.hxx" + +using namespace std; +using namespace test; + +template class xsd::cxx::tree::simple_type<char, xml_schema::type>; + +// String types. +// +template class xsd::cxx::tree::string< char, xml_schema::simple_type >; +template class xsd::cxx::tree::normalized_string< char, xml_schema::string >; +template class xsd::cxx::tree::token< char, xml_schema::normalized_string >; +template class xsd::cxx::tree::name< char, xml_schema::token >; +template class xsd::cxx::tree::nmtoken< char, xml_schema::token >; +template class xsd::cxx::tree::nmtokens< char, xml_schema::simple_type, xml_schema::nmtoken >; +template class xsd::cxx::tree::ncname< char, xml_schema::name >; +template class xsd::cxx::tree::language< char, xml_schema::token >; + +// ID/IDREF. +// +template class xsd::cxx::tree::id< char, xml_schema::ncname >; +template class xsd::cxx::tree::idref< char, xml_schema::ncname, xml_schema::type >; +template class xsd::cxx::tree::idrefs< char, xml_schema::simple_type, xml_schema::idref >; + +// URI. +// +template class xsd::cxx::tree::uri< char, xml_schema::simple_type >; + +// Qualified name. +// +template class xsd::cxx::tree::qname< char, xml_schema::simple_type, xml_schema::uri, xml_schema::ncname >; + +// Binary. +// +template class xsd::cxx::tree::buffer< char >; +template class xsd::cxx::tree::base64_binary< char, xml_schema::simple_type >; +template class xsd::cxx::tree::hex_binary< char, xml_schema::simple_type >; + +// Date/time. +// +template class xsd::cxx::tree::date< char, xml_schema::simple_type >; +template class xsd::cxx::tree::date_time< char, xml_schema::simple_type >; +template class xsd::cxx::tree::duration< char, xml_schema::simple_type >; +template class xsd::cxx::tree::gday< char, xml_schema::simple_type >; +template class xsd::cxx::tree::gmonth< char, xml_schema::simple_type >; +template class xsd::cxx::tree::gmonth_day< char, xml_schema::simple_type >; +template class xsd::cxx::tree::gyear< char, xml_schema::simple_type >; +template class xsd::cxx::tree::gyear_month< char, xml_schema::simple_type >; +template class xsd::cxx::tree::time< char, xml_schema::simple_type >; + +// Entity. +// +template class xsd::cxx::tree::entity< char, xml_schema::ncname >; +template class xsd::cxx::tree::entities< char, xml_schema::simple_type, xml_schema::entity >; + +// Namespace information and list stream. Used in +// serialization functions. +// +template class xsd::cxx::xml::dom::namespace_info < char >; +template class xsd::cxx::xml::dom::namespace_infomap < char >; +template class xsd::cxx::tree::list_stream < char >; + +// Flags and properties. +// +template class xsd::cxx::tree::properties< char >; + +// Exceptions. +// +template class xsd::cxx::tree::exception< char >; +template class xsd::cxx::tree::parsing< char >; +template class xsd::cxx::tree::expected_element< char >; +template class xsd::cxx::tree::unexpected_element< char >; +template class xsd::cxx::tree::expected_attribute< char >; +template class xsd::cxx::tree::unexpected_enumerator< char >; +template class xsd::cxx::tree::expected_text_content< char >; +template class xsd::cxx::tree::no_type_info< char >; +template class xsd::cxx::tree::not_derived< char >; +template class xsd::cxx::tree::duplicate_id< char >; +template class xsd::cxx::tree::serialization< char >; +template class xsd::cxx::tree::no_prefix_mapping< char >; +template class xsd::cxx::tree::bounds< char >; + +// Parsing/serialization diagnostics. +// +template class xsd::cxx::tree::error< char >; +template class xsd::cxx::tree::diagnostics< char >; + +// Error handler interface. +// +template class xsd::cxx::xml::error_handler< char >; + + +// +// +template class xsd::cxx::tree::fundamental_base<int, char, xml_schema::type>; +template class xsd::cxx::tree::one<int>; +template class xsd::cxx::tree::one<xml_schema::string>; +template class xsd::cxx::tree::optional<int>; +template class xsd::cxx::tree::optional<xml_schema::string>; +template class xsd::cxx::tree::sequence<int>; +template class xsd::cxx::tree::sequence<xml_schema::string>; + + +int +main () +{ +} diff --git a/xsd/tests/cxx/tree/compilation/makefile b/xsd/tests/cxx/tree/compilation/makefile new file mode 100644 index 0000000..16dbb91 --- /dev/null +++ b/xsd/tests/cxx/tree/compilation/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/compilation/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-serialization +$(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) + $(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,$(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/compilation/test.xsd b/xsd/tests/cxx/tree/compilation/test.xsd new file mode 100644 index 0000000..07bebc7 --- /dev/null +++ b/xsd/tests/cxx/tree/compilation/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/complex/ctor/driver.cxx b/xsd/tests/cxx/tree/complex/ctor/driver.cxx new file mode 100644 index 0000000..8ea8c87 --- /dev/null +++ b/xsd/tests/cxx/tree/complex/ctor/driver.cxx @@ -0,0 +1,123 @@ +// file : tests/cxx/tree/complex/ctor/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test generation of varous complex type constructors. +// + +#include <cassert> +#include <memory> + +#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 () +{ + // Test case A. + // + { + a_base b1; + a_base b2 ("abc"); // empty ultimate base + required + a_base b3 ("abc", "foo"); // ultimate base + required + + a_derived a1; + a_derived a2 ("foo", "bar"); // empty ultimate base + required + a_derived a3 (b3, "bar"); // base + required + a_derived a4 ("abc", "foo", "bar"); // ultimate base + required + } + + // Test case B. + // + { + b_simple s ("base"); + b_base b ("base", "foo"); + b_derived d ("base", "foo", "bar"); + b_type t ("base"); + } + + // Test case C. + // + { + c_simple s (c_enum::a); + c_base b (c_enum::a, "foo"); + c_derived d (c_enum::a, "foo", "bar"); + c_type t (c_enum::a); + } + + // Test case D. + // + { + d_simple s (1); + d_base b (1, "foo"); + d_derived d (1, "foo", "bar"); + d_type t (1); + } + + // Test case E. + // + { + // e_base + // + e_base b1 (1, "foo", e_complex_type ("bar")); + + XSD_AUTO_PTR<e_complex_type> c2 (new e_complex_type ("bar")); + e_base b2 (1, "foo", XSD_MOVE (c2)); + + XSD_AUTO_PTR<e_simple_type> s3 (new e_simple_type ("foo")); + XSD_AUTO_PTR<e_complex_type> c3 (new e_complex_type ("bar")); + e_base b3 (1, XSD_MOVE (s3), XSD_MOVE (c3)); + + assert (b1 == b2); + assert (b1 == b3); + + // e_derived + // + e_derived d1 (1, "foo", e_complex_type ("bar"), + true, "baz", e_complex_type ("biz")); + + XSD_AUTO_PTR<e_complex_type> c2a (new e_complex_type ("bar")); + XSD_AUTO_PTR<e_complex_type> c2b (new e_complex_type ("biz")); + e_derived d2 (1, "foo", XSD_MOVE (c2a), true, "baz", XSD_MOVE (c2b)); + + XSD_AUTO_PTR<e_simple_type> s3a (new e_simple_type ("foo")); + XSD_AUTO_PTR<xml_schema::string> s3b (new xml_schema::string ("baz")); + XSD_AUTO_PTR<e_complex_type> c3a (new e_complex_type ("bar")); + XSD_AUTO_PTR<e_complex_type> c3b (new e_complex_type ("biz")); + e_derived d3 (1, + XSD_MOVE (s3a), + XSD_MOVE (c3a), + true, + XSD_MOVE (s3b), + XSD_MOVE (c3b)); + + assert (d1 == d2); + assert (d1 == d3); + + } + + // Test case F. + // + { + f_type f1 (xml_schema::type (), 1, "foo", f_complex_type ("bar")); + + XSD_AUTO_PTR<f_complex_type> c2 (new f_complex_type ("bar")); + f_type f2 (1, "foo", XSD_MOVE (c2)); + + XSD_AUTO_PTR<f_simple_type> s3 (new f_simple_type ("foo")); + XSD_AUTO_PTR<f_complex_type> c3 (new f_complex_type ("bar")); + f_type f3 (1, XSD_MOVE (s3), XSD_MOVE (c3)); + + assert (f1 == f2); + assert (f1 == f3); + } +} diff --git a/xsd/tests/cxx/tree/complex/ctor/makefile b/xsd/tests/cxx/tree/complex/ctor/makefile new file mode 100644 index 0000000..ffc82b0 --- /dev/null +++ b/xsd/tests/cxx/tree/complex/ctor/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/complex/ctor/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-default-ctor --generate-from-base-ctor \ +--generate-doxygen --generate-polymorphic --polymorphic-type-all \ +--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) + $(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,$(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/complex/ctor/test.xsd b/xsd/tests/cxx/tree/complex/ctor/test.xsd new file mode 100644 index 0000000..b8dd95e --- /dev/null +++ b/xsd/tests/cxx/tree/complex/ctor/test.xsd @@ -0,0 +1,182 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- Test case A: several levels of inheritance with ultimate base. --> + + <complexType name="a_base"> + <simpleContent> + <extension base="string"> + <attribute name="foo" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="a_derived"> + <simpleContent> + <extension base="t:a_base"> + <attribute name="bar" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <!-- Test case B: string-based c-tors. --> + + <simpleType name="b_simple"> + <restriction base="string"> + </restriction> + </simpleType> + + <complexType name="b_base"> + <simpleContent> + <extension base="t:b_simple"> + <attribute name="foo" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="b_derived"> + <simpleContent> + <extension base="t:b_base"> + <attribute name="bar" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="b_type"> + <sequence> + <element name="a" type="t:b_simple"/> + </sequence> + </complexType> + + <!-- Test case C: enum-based c-tors. --> + + <simpleType name="c_enum_base"> + <restriction base="string"> + <enumeration value="a"/> + <enumeration value="b"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <simpleType name="c_enum"> + <restriction base="t:c_enum_base"> + <enumeration value="a"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <simpleType name="c_simple"> + <restriction base="t:c_enum"> + </restriction> + </simpleType> + + <complexType name="c_base"> + <simpleContent> + <extension base="t:c_simple"> + <attribute name="foo" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="c_derived"> + <simpleContent> + <extension base="t:c_base"> + <attribute name="bar" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="c_type"> + <sequence> + <element name="a" type="t:c_simple"/> + </sequence> + </complexType> + + <!-- Test case D: fundamental type c-tors. --> + + <simpleType name="d_simple"> + <restriction base="int"> + </restriction> + </simpleType> + + <complexType name="d_base"> + <simpleContent> + <extension base="t:d_simple"> + <attribute name="foo" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="d_derived"> + <simpleContent> + <extension base="t:d_base"> + <attribute name="bar" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="d_type"> + <sequence> + <element name="a" type="t:d_simple"/> + </sequence> + </complexType> + + <!-- Test case E: auto_ptr ctors. --> + + <simpleType name="e_simple_type"> + <restriction base="string"> + </restriction> + </simpleType> + + <complexType name="e_complex_type"> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + + <complexType name="e_base"> + <sequence> + <element name="fund" type="int"/> + <element name="simple" type="t:e_simple_type"/> + <element name="complex" type="t:e_complex_type"/> + </sequence> + </complexType> + + <complexType name="e_derived"> + <complexContent> + <extension base="t:e_base"> + <sequence> + <element name="fund1" type="boolean"/> + <element name="simple1" type="string"/> + <element name="complex1" type="t:e_complex_type"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <!-- Test case F: auto_ptr args in c-tor (all-non-optional-members) --> + + <simpleType name="f_simple_type"> + <restriction base="string"> + </restriction> + </simpleType> + + <complexType name="f_complex_type"> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + + <complexType name="f_type"> + <complexContent> + <restriction base="anyType"> + <sequence> + <element name="fund" type="int"/> + <element name="simple" type="t:f_simple_type"/> + <element name="complex" type="t:f_complex_type"/> + </sequence> + </restriction> + </complexContent> + </complexType> + +</schema> diff --git a/xsd/tests/cxx/tree/complex/makefile b/xsd/tests/cxx/tree/complex/makefile new file mode 100644 index 0000000..db6e6a8 --- /dev/null +++ b/xsd/tests/cxx/tree/complex/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/complex/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 := ctor + +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/containment/driver.cxx b/xsd/tests/cxx/tree/containment/driver.cxx new file mode 100644 index 0000000..f019de8 --- /dev/null +++ b/xsd/tests/cxx/tree/containment/driver.cxx @@ -0,0 +1,119 @@ +// file : tests/cxx/tree/containment/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// 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/makefile b/xsd/tests/cxx/tree/containment/makefile new file mode 100644 index 0000000..d181fb5 --- /dev/null +++ b/xsd/tests/cxx/tree/containment/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/containment/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-default-ctor +$(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) + $(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,$(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/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> diff --git a/xsd/tests/cxx/tree/default/general/driver.cxx b/xsd/tests/cxx/tree/default/general/driver.cxx new file mode 100644 index 0000000..b0df8ba --- /dev/null +++ b/xsd/tests/cxx/tree/default/general/driver.cxx @@ -0,0 +1,38 @@ +// file : tests/cxx/tree/default/general/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test default attribute/element values. +// + +#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], xml_schema::flags::dont_validate)); + + xml_schema::namespace_infomap map; + map["t"].name = "test"; + root (cout, *r, map); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/default/general/makefile b/xsd/tests/cxx/tree/default/general/makefile new file mode 100644 index 0000000..6c2dfe6 --- /dev/null +++ b/xsd/tests/cxx/tree/default/general/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/default/general/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-serialization \ +--generate-default-ctor --generate-from-base-ctor +$(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/default/general/output b/xsd/tests/cxx/tree/default/general/output new file mode 100644 index 0000000..396a698 --- /dev/null +++ b/xsd/tests/cxx/tree/default/general/output @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<t:root xmlns:t="test" base64_bin1="" base64_bin2="YmFzZTY0IGJpbmFyeQ==
" bool1="true" bool2="true" bool3="false" bool4="false" byte="-99" decimal1="1.12345" decimal2="-0.456" double1="1.12345" double2="1123.45" double3="-0.00012345" double4="NaN" double5="-INF" fix1="123" fix2="123" fix3="abc" fix4="abc" fix5="aaa bbb ccc" fix6="aaa bbb ccc" float1="1.123" float2="1123" float3="-0.000123" float4="NaN" float5="-INF" hex_bin1="" hex_bin2="6865782052696E617279" id="this" idref="this" idrefs="this" int="-99999" integer="-99999" language="en-us" long="-99999" ncname="abcd" ninteger="-99999" nmtoken="ab:cd" nmtokens1="a:b efg aaa" nmtokens2="abc" nninteger="99999" npinteger="-99999" nstring=" a b " pinteger="99999" qname1="foo" qname2="t:bar" short="-999" string1="" string2=" a b " token="a b" ubyte="99" uint="99999" ulong="99999" uri="http://example.com" ushort="999"> + <union a="abc"/> + <list a="123 345 678" b="ab cd ef" c="abc" d="abc def"/> + <simple a="123" b="abc" c="123" d="abc" e="abc" f="abc 123"/> + <date a="2009-03-31" b="2009-03-31Z" c="2009-03-31Z" d="2009-03-31Z" e="2009-03-31+12:30" f="2009-03-31-12:30" g="2002009-03-31-12:30"/> + <time a="12:03:45" b="12:03:45.123Z" c="12:03:05.123Z" d="12:03:45.123Z" e="12:03:45.123+12:30" f="12:03:45-12:30"/> + <date-time a="2009-03-31T12:03:45" b="2009-03-31T12:03:45.123Z" c="2002009-03-31T12:03:05.123-12:30"/> + <duration a="P100Y" b="P100M" c="P100D" d="PT12H" e="PT12M" f="PT12.123S" g="-P100Y10M20DT12H12M1.123S"/> + <day a="---02" b="---22Z" c="---22-12:30"/> + <month a="--02" b="--12Z" c="--12+12:30"/> + <year a="2009" b="-2002009Z" c="2009-12:30"/> + <month-day a="--02-02" b="--12-22Z" c="--12-22+12:30"/> + <year-month a="2009-02" b="-2002009-12Z" c="2009-12-12:30"/> +</t:root> diff --git a/xsd/tests/cxx/tree/default/general/test.xml b/xsd/tests/cxx/tree/default/general/test.xml new file mode 100644 index 0000000..11bd0a7 --- /dev/null +++ b/xsd/tests/cxx/tree/default/general/test.xml @@ -0,0 +1,16 @@ +<t:root xmlns:t="test" id="this" fix2="123" fix4="abc" fix6="aaa bbb ccc"> + + <union/> + <list/> + <simple/> + <date/> + <time/> + <date-time/> + <duration/> + <day/> + <month/> + <year/> + <month-day/> + <year-month/> + +</t:root> diff --git a/xsd/tests/cxx/tree/default/general/test.xsd b/xsd/tests/cxx/tree/default/general/test.xsd new file mode 100644 index 0000000..9d9cd38 --- /dev/null +++ b/xsd/tests/cxx/tree/default/general/test.xsd @@ -0,0 +1,241 @@ +<?xml version="1.0"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- union --> + + <xs:simpleType name="union"> + <xs:union memberTypes="xs:int xs:string"/> + </xs:simpleType> + + <xs:complexType name="union-test"> + <xs:attribute default="abc" name="a" type="t:union"/> + </xs:complexType> + + <!-- list --> + + <xs:simpleType name="fix-list"> + <xs:list itemType="xs:int"/> + </xs:simpleType> + + <xs:simpleType name="var-list"> + <xs:list itemType="xs:string"/> + </xs:simpleType> + + <xs:simpleType name="list-item"> + <xs:restriction base="xs:string"/> + </xs:simpleType> + + <xs:simpleType name="usr-list"> + <xs:list itemType="t:list-item"/> + </xs:simpleType> + + <xs:simpleType name="union-list"> + <xs:list itemType="t:union"/> + </xs:simpleType> + + <xs:complexType name="list-test"> + <xs:attribute default="123 345 678" name="a" type="t:fix-list"/> + <xs:attribute default=" ab cd ef " name="b" type="t:var-list"/> + <xs:attribute default="abc" name="c" type="t:usr-list"/> + <xs:attribute default="abc def" name="d" type="t:union-list"/> + </xs:complexType> + + <!-- simple type --> + + <xs:simpleType name="int-base"> + <xs:restriction base="xs:int"/> + </xs:simpleType> + + <xs:simpleType name="str-base"> + <xs:restriction base="xs:string"/> + </xs:simpleType> + + <xs:simpleType name="int"> + <xs:restriction base="t:int-base"/> + </xs:simpleType> + + <xs:simpleType name="str"> + <xs:restriction base="t:str-base"/> + </xs:simpleType> + + <xs:simpleType name="union-derived"> + <xs:restriction base="t:union"/> + </xs:simpleType> + + <xs:simpleType name="list-derived"> + <xs:restriction base="t:usr-list"/> + </xs:simpleType> + + <xs:complexType name="simple-test"> + <xs:attribute default="123" name="a" type="t:int-base"/> + <xs:attribute default="abc" name="b" type="t:str-base"/> + <xs:attribute default="123" name="c" type="t:int"/> + <xs:attribute default="abc" name="d" type="t:str"/> + <xs:attribute default="abc" name="e" type="t:union-derived"/> + <xs:attribute default="abc 123" name="f" type="t:list-derived"/> + </xs:complexType> + + <!-- date/time types --> + + <xs:simpleType name="date-derived"> + <xs:restriction base="xs:date"/> + </xs:simpleType> + + <xs:complexType name="date-test"> + <xs:attribute default="2009-03-31" name="a" type="xs:date"/> + <xs:attribute default="2009-03-31Z" name="b" type="xs:date"/> + <xs:attribute default="2009-03-31+00:00" name="c" type="xs:date"/> + <xs:attribute default="2009-03-31-00:00" name="d" type="xs:date"/> + <xs:attribute default="2009-03-31+12:30" name="e" type="xs:date"/> + <xs:attribute default="2009-03-31-12:30" name="f" type="xs:date"/> + <xs:attribute default="2002009-03-31-12:30" name="g" type="t:date-derived"/> + </xs:complexType> + + <xs:complexType name="time-test"> + <xs:attribute default="12:03:45" name="a" type="xs:time"/> + <xs:attribute default="12:03:45.123Z" name="b" type="xs:time"/> + <xs:attribute default="12:03:05.123+00:00" name="c" type="xs:time"/> + <xs:attribute default="12:03:45.123-00:00" name="d" type="xs:time"/> + <xs:attribute default="12:03:45.123+12:30" name="e" type="xs:time"/> + <xs:attribute default="12:03:45-12:30" name="f" type="xs:time"/> + </xs:complexType> + + <xs:complexType name="date-time-test"> + <xs:attribute default="2009-03-31T12:03:45" name="a" type="xs:dateTime"/> + <xs:attribute default="2009-03-31T12:03:45.123Z" name="b" type="xs:dateTime"/> + <xs:attribute default="2002009-03-31T12:03:05.123-12:30" name="c" type="xs:dateTime"/> + </xs:complexType> + + <xs:complexType name="duration-test"> + <xs:attribute default="P100Y" name="a" type="xs:duration"/> + <xs:attribute default="P100M" name="b" type="xs:duration"/> + <xs:attribute default="P100D" name="c" type="xs:duration"/> + <xs:attribute default="PT12H" name="d" type="xs:duration"/> + <xs:attribute default="PT12M" name="e" type="xs:duration"/> + <xs:attribute default="PT12.123S" name="f" type="xs:duration"/> + <xs:attribute default="-P100Y10M20DT12H12M1.123S" name="g" type="xs:duration"/> + </xs:complexType> + + <xs:complexType name="day-test"> + <xs:attribute default="---02" name="a" type="xs:gDay"/> + <xs:attribute default="---22Z" name="b" type="xs:gDay"/> + <xs:attribute default="---22-12:30" name="c" type="xs:gDay"/> + </xs:complexType> + + <xs:complexType name="month-test"> + <xs:attribute default="--02" name="a" type="xs:gMonth"/> + <xs:attribute default="--12Z" name="b" type="xs:gMonth"/> + <xs:attribute default="--12+12:30" name="c" type="xs:gMonth"/> + </xs:complexType> + + <xs:complexType name="year-test"> + <xs:attribute default="2009" name="a" type="xs:gYear"/> + <xs:attribute default="-2002009Z" name="b" type="xs:gYear"/> + <xs:attribute default="2009-12:30" name="c" type="xs:gYear"/> + </xs:complexType> + + <xs:complexType name="month-day-test"> + <xs:attribute default="--02-02" name="a" type="xs:gMonthDay"/> + <xs:attribute default="--12-22Z" name="b" type="xs:gMonthDay"/> + <xs:attribute default="--12-22+12:30" name="c" type="xs:gMonthDay"/> + </xs:complexType> + + <xs:complexType name="year-month-test"> + <xs:attribute default="2009-02" name="a" type="xs:gYearMonth"/> + <xs:attribute default="-2002009-12Z" name="b" type="xs:gYearMonth"/> + <xs:attribute default="2009-12-12:30" name="c" type="xs:gYearMonth"/> + </xs:complexType> + + + <xs:complexType name="type"> + <xs:sequence> + <xs:element name="union" type="t:union-test"/> + <xs:element name="list" type="t:list-test"/> + <xs:element name="simple" type="t:simple-test"/> + <xs:element name="date" type="t:date-test"/> + <xs:element name="time" type="t:time-test"/> + <xs:element name="date-time" type="t:date-time-test"/> + <xs:element name="duration" type="t:duration-test"/> + <xs:element name="day" type="t:day-test"/> + <xs:element name="month" type="t:month-test"/> + <xs:element name="year" type="t:year-test"/> + <xs:element name="month-day" type="t:month-day-test"/> + <xs:element name="year-month" type="t:year-month-test"/> + </xs:sequence> + +<!-- + <xs:attribute name="any" type="xs:anySimpleType" default=""/> +--> + + <xs:attribute name="bool1" type="xs:boolean" default="true"/> + <xs:attribute name="bool2" type="xs:boolean" default="1"/> + <xs:attribute name="bool3" type="xs:boolean" default="false"/> + <xs:attribute name="bool4" type="xs:boolean" default="0"/> + + <xs:attribute name="byte" type="xs:byte" default="-99"/> + <xs:attribute name="ubyte" type="xs:unsignedByte" default="99"/> + <xs:attribute name="short" type="xs:short" default="-999"/> + <xs:attribute name="ushort" type="xs:unsignedShort" default="999"/> + <xs:attribute name="int" type="xs:int" default="-99999"/> + <xs:attribute name="uint" type="xs:unsignedInt" default="99999"/> + <xs:attribute name="long" type="xs:long" default="-99999"/> + <xs:attribute name="ulong" type="xs:unsignedLong" default="99999"/> + + <xs:attribute name="integer" type="xs:integer" default="-99999"/> + <xs:attribute name="npinteger" type="xs:nonPositiveInteger" default="-99999"/> + <xs:attribute name="nninteger" type="xs:nonNegativeInteger" default="99999"/> + <xs:attribute name="pinteger" type="xs:positiveInteger" default="99999"/> + <xs:attribute name="ninteger" type="xs:negativeInteger" default="-99999"/> + + <xs:attribute name="float1" type="xs:float" default="1.123"/> + <xs:attribute name="float2" type="xs:float" default="1.123e3"/> + <xs:attribute name="float3" type="xs:float" default="-.123E-3"/> + <xs:attribute name="float4" type="xs:float" default="NaN"/> + <xs:attribute name="float5" type="xs:float" default="-INF"/> + + <xs:attribute name="double1" type="xs:double" default="1.12345"/> + <xs:attribute name="double2" type="xs:double" default="1.12345e3"/> + <xs:attribute name="double3" type="xs:double" default="-.12345E-3"/> + <xs:attribute name="double4" type="xs:double" default="NaN"/> + <xs:attribute name="double5" type="xs:double" default="-INF"/> + + <xs:attribute name="decimal1" type="xs:decimal" default="1.12345"/> + <xs:attribute name="decimal2" type="xs:decimal" default="-.456"/> + + <xs:attribute name="string1" type="xs:string" default=""/> + <xs:attribute name="string2" type="xs:string" default=" a b "/> + <xs:attribute name="nstring" type="xs:normalizedString" default=" a b "/> + <xs:attribute name="token" type="xs:token" default=" a b "/> + <xs:attribute name="nmtoken" type="xs:NMTOKEN" default="ab:cd"/> + <xs:attribute name="nmtokens1" type="xs:NMTOKENS" default=" a:b efg aaa "/> + <xs:attribute name="nmtokens2" type="xs:NMTOKENS" default="abc"/> + <xs:attribute name="ncname" type="xs:NCName" default=" abcd "/> + <xs:attribute name="language" type="xs:language" default=" en-us "/> + <xs:attribute name="id" type="xs:ID"/> + <xs:attribute name="idref" type="xs:IDREF" default="this"/> + <xs:attribute name="idrefs" type="xs:IDREFS" default=" this "/> + <xs:attribute name="uri" type="xs:anyURI" default=" http://example.com "/> + + <xs:attribute name="qname1" type="xs:QName" default="foo"/> + <xs:attribute name="qname2" type="xs:QName" default="t:bar"/> + + <xs:attribute name="base64_bin1" type="xs:base64Binary" default=""/> + <xs:attribute name="base64_bin2" type="xs:base64Binary" default="YmFzZTY0IGJpbmFyeQ=="/> + + <xs:attribute name="hex_bin1" type="xs:hexBinary" default=""/> + <xs:attribute name="hex_bin2" type="xs:hexBinary" default="6865782052696E617279"/> + + <!-- fixed --> + + <xs:attribute name="fix1" type="xs:int" fixed="123"/> + <xs:attribute name="fix2" type="xs:int" fixed="123" use="required"/> + <xs:attribute name="fix3" type="xs:string" fixed="abc"/> + <xs:attribute name="fix4" type="xs:string" fixed="abc" use="required"/> + <xs:attribute name="fix5" type="xs:NMTOKENS" fixed="aaa bbb ccc"/> + <xs:attribute name="fix6" type="xs:NMTOKENS" fixed="aaa bbb ccc" use="required"/> + + </xs:complexType> + + <xs:element name="root" type="t:type"/> + +</xs:schema> diff --git a/xsd/tests/cxx/tree/default/makefile b/xsd/tests/cxx/tree/default/makefile new file mode 100644 index 0000000..56fa53d --- /dev/null +++ b/xsd/tests/cxx/tree/default/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/default/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 := general omit + +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/default/omit/driver.cxx b/xsd/tests/cxx/tree/default/omit/driver.cxx new file mode 100644 index 0000000..6a074c1 --- /dev/null +++ b/xsd/tests/cxx/tree/default/omit/driver.cxx @@ -0,0 +1,47 @@ +// file : tests/cxx/tree/default/omit/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test default attribute omission from the output. +// + +#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], xml_schema::flags::dont_validate)); + + cout << *r << endl + << "default x: " << derived::x_default_value () << endl + << "default y: " << derived::y_default_value () << endl + << "fixed p: " << derived::p_default_value () << endl + << "fixed q1: " << derived::q1_default_value () << endl + << "fixed q2: " << derived::q2_default_value () << endl; + + // Serialize. + // + xml_schema::namespace_infomap map; + map["t"].name = "test"; + root (cout, *r, map); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/default/omit/makefile b/xsd/tests/cxx/tree/default/omit/makefile new file mode 100644 index 0000000..caaec12 --- /dev/null +++ b/xsd/tests/cxx/tree/default/omit/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/default/omit/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-serialization \ +--generate-default-ctor --generate-from-base-ctor --omit-default-attributes +$(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/default/omit/output b/xsd/tests/cxx/tree/default/omit/output new file mode 100644 index 0000000..150ad58 --- /dev/null +++ b/xsd/tests/cxx/tree/default/omit/output @@ -0,0 +1,19 @@ + +derived: +a: a +x: foo +q1: 1 +y: -20 +p: bar +q2: 2 +default x: foo +default y: -20 +fixed p: bar +fixed q1: 1 +fixed q2: 2 +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<t:root xmlns:t="test"> + <derived q1="1" q2="2"> + <a>a</a> + </derived> +</t:root> diff --git a/xsd/tests/cxx/tree/default/omit/test.xml b/xsd/tests/cxx/tree/default/omit/test.xml new file mode 100644 index 0000000..dec39b4 --- /dev/null +++ b/xsd/tests/cxx/tree/default/omit/test.xml @@ -0,0 +1,9 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <derived q1="1" q2="2"> + <a>a</a> + </derived> + +</t:root> diff --git a/xsd/tests/cxx/tree/default/omit/test.xsd b/xsd/tests/cxx/tree/default/omit/test.xsd new file mode 100644 index 0000000..bfc68d4 --- /dev/null +++ b/xsd/tests/cxx/tree/default/omit/test.xsd @@ -0,0 +1,30 @@ +<?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> + <attribute name="x" type="string" default="foo"/> + <attribute name="q1" type="int" fixed="1" use="required"/> + </complexType> + + <complexType name="derived"> + <complexContent> + <extension base="t:base"> + <attribute name="y" type="int" default="-20"/> + <attribute name="p" type="string" fixed="bar"/> + <attribute name="q2" type="int" fixed="2" use="required"/> + </extension> + </complexContent> + </complexType> + + <complexType name="type"> + <sequence> + <element name="derived" type="t:derived"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/detach/driver.cxx b/xsd/tests/cxx/tree/detach/driver.cxx new file mode 100644 index 0000000..cabd9ea --- /dev/null +++ b/xsd/tests/cxx/tree/detach/driver.cxx @@ -0,0 +1,109 @@ +// file : tests/cxx/tree/detach/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the detach functionality. +// + +#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 () +{ + using test::ref; + + // 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. + // + XSD_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 (XSD_MOVE (p)); + assert (m.opt ()->r ()[1].get () == &m.one ().o ()[0]); + p = m.detach_one (); + + model m1; + m1.one (XSD_MOVE (p)); + m1.opt (s2); + assert (m1.opt ()->r ()[1].get () == &m1.one ().o ()[0]); + + p = m1.detach_one (); + m.seq ().push_back (XSD_MOVE (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 (XSD_MOVE (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 (XSD_MOVE (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/xsd/tests/cxx/tree/detach/makefile b/xsd/tests/cxx/tree/detach/makefile new file mode 100644 index 0000000..64def55 --- /dev/null +++ b/xsd/tests/cxx/tree/detach/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/detach/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-detach --generate-default-ctor +$(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) + $(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,$(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/detach/test.xsd b/xsd/tests/cxx/tree/detach/test.xsd new file mode 100644 index 0000000..b9f5166 --- /dev/null +++ b/xsd/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/xsd/tests/cxx/tree/dom-association/dom-parse.cxx b/xsd/tests/cxx/tree/dom-association/dom-parse.cxx new file mode 100644 index 0000000..c065d19 --- /dev/null +++ b/xsd/tests/cxx/tree/dom-association/dom-parse.cxx @@ -0,0 +1,96 @@ +// file : tests/cxx/tree/dom-association/dom-parse.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include "dom-parse.hxx" + +#include <istream> + +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/XMLUniDefs.hpp> // chLatin_* +#include <xercesc/framework/Wrapper4InputSource.hpp> + +#include <xsd/cxx/xml/sax/std-input-source.hxx> +#include <xsd/cxx/xml/dom/bits/error-handler-proxy.hxx> + +#include <xsd/cxx/tree/exceptions.hxx> +#include <xsd/cxx/tree/error-handler.hxx> + +using namespace xercesc; +namespace xml = xsd::cxx::xml; +namespace tree = xsd::cxx::tree; + +XSD_DOM_AUTO_PTR<DOMDocument> +parse (std::istream& is, + const std::string& id, + bool validate) +{ + const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull}; + + // Get an implementation of the Load-Store (LS) interface. + // + DOMImplementation* impl ( + DOMImplementationRegistry::getDOMImplementation (ls_id)); + + XSD_DOM_AUTO_PTR<DOMLSParser> parser ( + impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0)); + + DOMConfiguration* conf (parser->getDomConfig ()); + + // Discard comment nodes in the document. + // + conf->setParameter (XMLUni::fgDOMComments, false); + + // Enable datatype normalization. + // + conf->setParameter (XMLUni::fgDOMDatatypeNormalization, true); + + // Do not create EntityReference nodes in the DOM tree. No + // EntityReference nodes will be created, only the nodes + // corresponding to their fully expanded substitution text + // will be created. + // + conf->setParameter (XMLUni::fgDOMEntities, false); + + // Perform namespace processing. + // + conf->setParameter (XMLUni::fgDOMNamespaces, true); + + // Do not include ignorable whitespace in the DOM tree. + // + conf->setParameter (XMLUni::fgDOMElementContentWhitespace, false); + + // Enable/Disable validation. + // + conf->setParameter (XMLUni::fgDOMValidate, validate); + conf->setParameter (XMLUni::fgXercesSchema, validate); + conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false); + + // Xerces-C++ 3.1.0 is the first version with working multi import + // support. + // +#if _XERCES_VERSION >= 30100 + conf->setParameter (XMLUni::fgXercesHandleMultipleImports, true); +#endif + + // We will release the DOM document ourselves. + // + conf->setParameter (XMLUni::fgXercesUserAdoptsDOMDocument, true); + + // Set error handler. + // + tree::error_handler<char> eh; + xml::dom::bits::error_handler_proxy<char> ehp (eh); + conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); + + // Prepare input stream. + // + xml::sax::std_input_source isrc (is, id); + Wrapper4InputSource wrap (&isrc, false); + + XSD_DOM_AUTO_PTR<DOMDocument> doc (parser->parse (&wrap)); + + eh.throw_if_failed<tree::parsing<char> > (); + + return doc; +} diff --git a/xsd/tests/cxx/tree/dom-association/dom-parse.hxx b/xsd/tests/cxx/tree/dom-association/dom-parse.hxx new file mode 100644 index 0000000..2c3bd3f --- /dev/null +++ b/xsd/tests/cxx/tree/dom-association/dom-parse.hxx @@ -0,0 +1,24 @@ +// file : tests/cxx/tree/dom-association/dom-parse.hxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef DOM_PARSE +#define DOM_PARSE + +#include <string> +#include <iosfwd> + +#include <xercesc/dom/DOMDocument.hpp> + +#include <xsd/cxx/xml/dom/auto-ptr.hxx> + +// Parse an XML document from the standard input stream with an +// optional resource id. Resource id is used in diagnostics as +// well as to locate schemas referenced from inside the document. +// +XSD_DOM_AUTO_PTR<xercesc::DOMDocument> +parse (std::istream& is, + const std::string& id, + bool validate); + +#endif // DOM_PARSE diff --git a/xsd/tests/cxx/tree/dom-association/driver.cxx b/xsd/tests/cxx/tree/dom-association/driver.cxx new file mode 100644 index 0000000..edcda50 --- /dev/null +++ b/xsd/tests/cxx/tree/dom-association/driver.cxx @@ -0,0 +1,72 @@ +// file : tests/cxx/tree/dom-association/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test DOM association/ownership. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <fstream> +#include <iostream> + +#include <xercesc/dom/DOM.hpp> + +#include "dom-parse.hxx" +#include "test.hxx" + +using namespace std; +using namespace test; +using namespace xercesc; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + int r (0); + + XMLPlatformUtils::Initialize (); + + try + { + ifstream ifs; + ifs.exceptions (ifstream::badbit | ifstream::failbit); + ifs.open (argv[1]); + + DOMDocument* ptr; + +#ifdef XSD_CXX11 + xml_schema::dom::unique_ptr<DOMDocument> doc (parse (ifs, argv[1], true)); + ptr = doc.get (); + unique_ptr<type> r ( + root (std::move (doc), + xml_schema::flags::keep_dom | xml_schema::flags::own_dom)); +#else + xml_schema::dom::auto_ptr<DOMDocument> doc (parse (ifs, argv[1], true)); + ptr = doc.get (); + auto_ptr<type> r ( + root (doc, + xml_schema::flags::keep_dom | xml_schema::flags::own_dom)); +#endif + + assert (doc.get () == 0); + assert (r->_node ()->getOwnerDocument () == ptr); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + r = 1; + } + catch (const std::ios_base::failure&) + { + cerr << argv[1] << ": unable to open or read failure" << endl; + r = 1; + } + + XMLPlatformUtils::Terminate (); + return r; +} diff --git a/xsd/tests/cxx/tree/dom-association/makefile b/xsd/tests/cxx/tree/dom-association/makefile new file mode 100644 index 0000000..4a05d45 --- /dev/null +++ b/xsd/tests/cxx/tree/dom-association/makefile @@ -0,0 +1,92 @@ +# file : tests/cxx/tree/dom-association/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 dom-parse.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) + +# Define XSD_CXX11 since we include libxsd headers directly. +# +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifeq ($(cxx_standard),c++11) +$(obj) $(dep): cpp_options += -DXSD_CXX11 +endif + +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 +$(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) + +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/dom-association/output b/xsd/tests/cxx/tree/dom-association/output new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/xsd/tests/cxx/tree/dom-association/output diff --git a/xsd/tests/cxx/tree/dom-association/test.xml b/xsd/tests/cxx/tree/dom-association/test.xml new file mode 100644 index 0000000..624a80c --- /dev/null +++ b/xsd/tests/cxx/tree/dom-association/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"> + + <a>a</a> + +</t:root> diff --git a/xsd/tests/cxx/tree/dom-association/test.xsd b/xsd/tests/cxx/tree/dom-association/test.xsd new file mode 100644 index 0000000..07bebc7 --- /dev/null +++ b/xsd/tests/cxx/tree/dom-association/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx new file mode 100644 index 0000000..6a92ae0 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx @@ -0,0 +1,75 @@ +// file : tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test ISO-8859-1 encoding. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <fstream> +#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 + { + try + { + root (argv[1]); + return 1; + } + catch (xsd::cxx::xml::iso8859_1_unrepresentable const&) + { + } + + xsd::cxx::xml::char_transcoder::unrep_char ('?'); + XSD_AUTO_PTR<type> r (root (argv[1])); + + { + type::a_sequence const& s (r->a ()); + + if (s[0] != "abc" || + s[1] != "\xE6" || + s[2] != "\xA2\xA3\xA4\xA5" || + s[3] != "???") + { + cerr << "invalid encoding" << endl; + return 1; + } + } + + { + type::b_sequence const& s (r->b ()); + + if (s[0] != strenum::abc || + s[1] != strenum::a_c || + s[2] != strenum::cxx__bc) + { + cerr << "invalid encoding" << endl; + return 1; + } + } + + xml_schema::namespace_infomap map; + map["t"].name = "test"; + + root (std::cout, *r, map, "ISO-8859-1"); + } + catch (xml_schema::exception const& e) + { + cerr << "xml_schema::exception: " << e.what () << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/encoding/char/iso-8859-1/makefile b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/makefile new file mode 100644 index 0000000..8a952f7 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/encoding/char/iso-8859-1/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 += --char-encoding iso8859-1 --generate-serialization \ +--generate-doxygen +$(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)/test.std + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/test.std -,$(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/encoding/char/iso-8859-1/test.std b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.std new file mode 100644 index 0000000..d26b30f --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.std @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?> +<t:root xmlns:t="test"> + <a>abc</a> + <a>æ</a> + <a>¢£¤¥</a> + <a>???</a> + <b>abc</b> + <b>aâc</b> + <b>âòbc</b> +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.xml b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.xml new file mode 100644 index 0000000..9c9e752 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.xml @@ -0,0 +1,14 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a>abc</a> + <a>æ</a> + <a>¢£¤¥</a> + <a>Āꪪ򪪪</a> + + <b>abc</b> + <b>aâc</b> + <b>âòbc</b> + +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.xsd b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.xsd new file mode 100644 index 0000000..31b8901 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/iso-8859-1/test.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="strenum"> + + <annotation> + <documentation> + Test enum. Valid values are: + abc + aâc + òbc + </documentation> + </annotation> + + <restriction base="string"> + <enumeration value="abc"/> + <enumeration value="aâc"/> + <enumeration value="âòbc"/> + </restriction> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="a" type="string" maxOccurs="unbounded"/> + <element name="b" type="t:strenum" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/encoding/char/lcp/driver.cxx b/xsd/tests/cxx/tree/encoding/char/lcp/driver.cxx new file mode 100644 index 0000000..d44d0fe --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/lcp/driver.cxx @@ -0,0 +1,41 @@ +// file : tests/cxx/tree/encoding/char/lcp/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test local code page encoding (--char-encoding lcp). +// The test just makes sure it still compiles and works. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <fstream> +#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])); + + xml_schema::namespace_infomap map; + map["t"].name = "test"; + + root (std::cout, *r, map); + } + catch (xml_schema::exception const& e) + { + cerr << "xml_schema::exception: " << e.what () << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/encoding/char/lcp/makefile b/xsd/tests/cxx/tree/encoding/char/lcp/makefile new file mode 100644 index 0000000..9dc599d --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/lcp/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/encoding/char/lcp/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-serialization --char-encoding lcp +$(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)/test.std + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/test.std -,$(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/encoding/char/lcp/test.std b/xsd/tests/cxx/tree/encoding/char/lcp/test.std new file mode 100644 index 0000000..368826d --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/lcp/test.std @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<t:root xmlns:t="test"> + <a>abcd</a> +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/char/lcp/test.xml b/xsd/tests/cxx/tree/encoding/char/lcp/test.xml new file mode 100644 index 0000000..772512e --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/lcp/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"> + + <a>abcd</a> + +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/char/lcp/test.xsd b/xsd/tests/cxx/tree/encoding/char/lcp/test.xsd new file mode 100644 index 0000000..1e264e3 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/lcp/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="a" type="string" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/encoding/char/makefile b/xsd/tests/cxx/tree/encoding/char/makefile new file mode 100644 index 0000000..587eeb1 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/encoding/char/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 := lcp utf-8 iso-8859-1 + +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/encoding/char/utf-8/driver.cxx b/xsd/tests/cxx/tree/encoding/char/utf-8/driver.cxx new file mode 100644 index 0000000..9d12659 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/utf-8/driver.cxx @@ -0,0 +1,66 @@ +// file : tests/cxx/tree/encoding/char/utf-8/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test UTF-8 encoding. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <fstream> +#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])); + + { + type::a_sequence const& s (r->a ()); + + if (s[0] != "abc" || + s[1] != "\xD5\x95" || + s[2] != "\xEA\xAA\xAA" || + s[3] != "\xF2\xAA\xAA\xAA") + { + cerr << "invalid encoding" << endl; + return 1; + } + } + + { + type::b_sequence const& s (r->b ()); + + if (s[0] != strenum::abc || + s[1] != strenum::a_c || + s[2] != strenum::cxx_bc || + s[3] != strenum::ab_) + { + cerr << "invalid encoding" << endl; + return 1; + } + } + + xml_schema::namespace_infomap map; + map["t"].name = "test"; + + root (std::cout, *r, map, "ASCII"); + } + catch (xml_schema::exception const& e) + { + cerr << "xml_schema::exception: " << e.what () << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/encoding/char/utf-8/makefile b/xsd/tests/cxx/tree/encoding/char/utf-8/makefile new file mode 100644 index 0000000..e2bbdfc --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/utf-8/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/encoding/char/utf-8/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-serialization --generate-doxygen +$(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)/test.std + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/test.std -,$(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/encoding/char/utf-8/test.std b/xsd/tests/cxx/tree/encoding/char/utf-8/test.std new file mode 100644 index 0000000..ffce337 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/utf-8/test.std @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="ASCII" standalone="no" ?> +<t:root xmlns:t="test"> + <a>abc</a> + <a>Օ</a> + <a>ꪪ</a> + <a>򪪪</a> + <b>abc</b> + <b>aՕc</b> + <b>ꪪbc</b> + <b>ab򪪪</b> +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/char/utf-8/test.xml b/xsd/tests/cxx/tree/encoding/char/utf-8/test.xml new file mode 100644 index 0000000..a6e5d99 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/utf-8/test.xml @@ -0,0 +1,15 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a>abc</a> + <a>Օ</a> + <a>ꪪ</a> + <a>򪪪</a> + + <b>abc</b> + <b>aՕc</b> + <b>ꪪbc</b> + <b>ab򪪪</b> + +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/char/utf-8/test.xsd b/xsd/tests/cxx/tree/encoding/char/utf-8/test.xsd new file mode 100644 index 0000000..6c32a32 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/char/utf-8/test.xsd @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="strenum"> + + <annotation> + <documentation> + Test enum. Valid values are: + abc + aՕc + ꪪbc + ab򪪪 + </documentation> + </annotation> + + <restriction base="string"> + <enumeration value="abc"/> + <enumeration value="aՕc"/> + <enumeration value="ꪪbc"/> + <enumeration value="ab򪪪"/> + </restriction> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="a" type="string" maxOccurs="unbounded"/> + <element name="b" type="t:strenum" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/encoding/makefile b/xsd/tests/cxx/tree/encoding/makefile new file mode 100644 index 0000000..2108fa2 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/encoding/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 := char wchar + +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/encoding/wchar/driver.cxx b/xsd/tests/cxx/tree/encoding/wchar/driver.cxx new file mode 100644 index 0000000..6b8d51e --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/wchar/driver.cxx @@ -0,0 +1,56 @@ +// file : tests/cxx/tree/encoding/wchar/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the wide character mapping. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <fstream> +#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 + { + // Use dont_validate because we do not have instance's system id (path). + // + std::ifstream ifs (argv[1]); + XSD_AUTO_PTR<type> r (root (ifs, xml_schema::flags::dont_validate)); + + { + type::b_sequence const& s (r->b ()); + + if (s[0] != strenum::abc || + s[1] != strenum::a__c || + s[2] != strenum::cxx__bc || + s[3] != strenum::ab__) + { + cerr << "invalid encoding" << endl; + return 1; + } + } + + xml_schema::namespace_infomap map; + map[L"t"].name = L"test"; + + root (std::cout, *r, map, L"ASCII"); + } + catch (xml_schema::exception const& e) + { + cerr << "xml_schema::exception: " << e.what () << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/encoding/wchar/makefile b/xsd/tests/cxx/tree/encoding/wchar/makefile new file mode 100644 index 0000000..e66d3a5 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/wchar/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/encoding/wchar/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-serialization --generate-doxygen \ +--char-type wchar_t +$(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)/test.std + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/test.std -,$(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/encoding/wchar/test.std b/xsd/tests/cxx/tree/encoding/wchar/test.std new file mode 100644 index 0000000..815ba6c --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/wchar/test.std @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="ASCII" standalone="no" ?> +<t:root xmlns:t="test"> + <a>abc</a> + <a>῿퟿</a> + <a>𐀀􏿽</a> + <b>abc</b> + <b>a῿퟿c</b> + <b>𐀀􏿽bc</b> + <b>ab𐀀􏿽</b> +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/wchar/test.xml b/xsd/tests/cxx/tree/encoding/wchar/test.xml new file mode 100644 index 0000000..c6ec850 --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/wchar/test.xml @@ -0,0 +1,14 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a>abc</a> + <a>῿퟿</a> + <a>𐀀􏿽</a> + + <b>abc</b> + <b>a῿퟿c</b> + <b>𐀀􏿽bc</b> + <b>ab𐀀􏿽</b> + +</t:root> diff --git a/xsd/tests/cxx/tree/encoding/wchar/test.xsd b/xsd/tests/cxx/tree/encoding/wchar/test.xsd new file mode 100644 index 0000000..0bf4bdd --- /dev/null +++ b/xsd/tests/cxx/tree/encoding/wchar/test.xsd @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="strenum"> + + <annotation> + <documentation> + Test enum. Valid values are: + abc + a῿퟿c + 𐀀􏿽bc + ab𐀀􏿽 + </documentation> + </annotation> + + <restriction base="string"> + <enumeration value="abc"/> + <enumeration value="a῿퟿c"/> + <enumeration value="𐀀􏿽bc"/> + <enumeration value="ab𐀀􏿽"/> + </restriction> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="a" type="string" maxOccurs="unbounded"/> + <element name="b" type="t:strenum" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/enumeration/ctor/driver.cxx b/xsd/tests/cxx/tree/enumeration/ctor/driver.cxx new file mode 100644 index 0000000..bd2589f --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/ctor/driver.cxx @@ -0,0 +1,31 @@ +// file : tests/cxx/tree/enumeration/ctor/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test enumeration constructors. +// +#include <string> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + // Test ctor(const char*). + // + { + string_enum se ("a"); + type t ("a", 1); + } + + // Test ctor(const std::string&) + // + { + string const s ("c"); + string_enum se (s); + type t (s, 3); + } +} diff --git a/xsd/tests/cxx/tree/enumeration/ctor/makefile b/xsd/tests/cxx/tree/enumeration/ctor/makefile new file mode 100644 index 0000000..2fae138 --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/ctor/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/enumeration/ctor/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-default-ctor --generate-from-base-ctor \ +--generate-doxygen +$(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) + $(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,$(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/enumeration/ctor/test.xsd b/xsd/tests/cxx/tree/enumeration/ctor/test.xsd new file mode 100644 index 0000000..c5d625a --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/ctor/test.xsd @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="string-enum-base"> + <restriction base="string"> + <enumeration value="a"/> + <enumeration value="b"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <simpleType name="string-enum"> + <restriction base="t:string-enum-base"> + <enumeration value="a"/> + <enumeration value="c"/> + </restriction> + </simpleType> + + <simpleType name="int-enum-base"> + <restriction base="int"> + <enumeration value="1"/> + <enumeration value="2"/> + <enumeration value="3"/> + </restriction> + </simpleType> + + <simpleType name="int-enum"> + <restriction base="t:int-enum-base"> + <enumeration value="1"/> + <enumeration value="3"/> + </restriction> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="a" type="t:string-enum"/> + <element name="b" type="t:int-enum"/> + </sequence> + </complexType> + +</schema> diff --git a/xsd/tests/cxx/tree/enumeration/inheritance/driver.cxx b/xsd/tests/cxx/tree/enumeration/inheritance/driver.cxx new file mode 100644 index 0000000..0a6d5d2 --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/inheritance/driver.cxx @@ -0,0 +1,54 @@ +// file : tests/cxx/tree/enumeration/inheritance/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Insert test description here. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <cassert> +#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<top_bottom> r (root (argv[1])); + + switch (*r) + { + case top_bottom::top: + { + cout << "top" << endl; + break; + } + case top_bottom::bottom: + { + cout << "bottom" << endl; + break; + } + default: // Suppress warning. + { + assert (false); + break; + } + } + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/enumeration/inheritance/makefile b/xsd/tests/cxx/tree/enumeration/inheritance/makefile new file mode 100644 index 0000000..77df855 --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/inheritance/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/enumeration/inheritance/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 +$(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/enumeration/inheritance/output b/xsd/tests/cxx/tree/enumeration/inheritance/output new file mode 100644 index 0000000..fef12e2 --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/inheritance/output @@ -0,0 +1 @@ +bottom diff --git a/xsd/tests/cxx/tree/enumeration/inheritance/test.xml b/xsd/tests/cxx/tree/enumeration/inheritance/test.xml new file mode 100644 index 0000000..1de9043 --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/inheritance/test.xml @@ -0,0 +1,3 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd">bottom</t:root> diff --git a/xsd/tests/cxx/tree/enumeration/inheritance/test.xsd b/xsd/tests/cxx/tree/enumeration/inheritance/test.xsd new file mode 100644 index 0000000..cf2eeb1 --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/inheritance/test.xsd @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="side"> + <restriction base="string"> + <enumeration value="top"/> + <enumeration value="left"/> + <enumeration value="bottom"/> + <enumeration value="right"/> + </restriction> + </simpleType> + + <simpleType name="top-bottom"> + <restriction base="t:side"> + <enumeration value="top"/> + <enumeration value="bottom"/> + </restriction> + </simpleType> + + <element name="root" type="t:top-bottom"/> + +</schema> diff --git a/xsd/tests/cxx/tree/enumeration/makefile b/xsd/tests/cxx/tree/enumeration/makefile new file mode 100644 index 0000000..8f55b20 --- /dev/null +++ b/xsd/tests/cxx/tree/enumeration/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/enumeration/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 := ctor inheritance + +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/float/driver.cxx b/xsd/tests/cxx/tree/float/driver.cxx new file mode 100644 index 0000000..a71d2f3 --- /dev/null +++ b/xsd/tests/cxx/tree/float/driver.cxx @@ -0,0 +1,54 @@ +// file : tests/cxx/tree/float/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test floating point (xsd:{float, double, decimal}) type parsing +// and serialization. +// + +#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])); + + r->simple ().push_back (12.129456); + r->simple ().push_back (123.129456); + r->simple ().push_back (1234.129456); + + r->s (12.129456); + + r->complex ().push_back (12.129456); + r->complex ().push_back (123.129456); + r->complex ().push_back (1234.129456); + r->complex ().push_back (-12.12); + r->complex ().push_back (-123.12); + + r->s (12.129456); + + xml_schema::namespace_infomap map; + + map["t"].name = "test"; + root (cout, *r, map); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/float/makefile b/xsd/tests/cxx/tree/float/makefile new file mode 100644 index 0000000..a585afb --- /dev/null +++ b/xsd/tests/cxx/tree/float/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/float/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-serialization --root-element-all +$(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)/test.std + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/test.std -,$(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/float/test.std b/xsd/tests/cxx/tree/float/test.std new file mode 100644 index 0000000..399e28c --- /dev/null +++ b/xsd/tests/cxx/tree/float/test.std @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<t:root xmlns:t="test" de="0" do="0" f="0" s="12.13"> + <float>0</float> + <float>1</float> + <float>1e+06</float> + <float>1e-07</float> + <float-list>0 1 1e+06 1e-07</float-list> + <double>0</double> + <double>1</double> + <double>100000000000000</double> + <double>1e-15</double> + <double-list>0 1 100000000000000 1e-15</double-list> + <decimal>0</decimal> + <decimal>1</decimal> + <decimal>10000</decimal> + <decimal>100000000000000</decimal> + <decimal>0.000000000000001</decimal> + <decimal-list>0 1 100000000000000 0.000000000000001</decimal-list> + <simple>0</simple> + <simple>1</simple> + <simple>12.34</simple> + <simple>0.12</simple> + <simple>12.13</simple> + <simple>123.1</simple> + <simple>1234</simple> + <complex>0</complex> + <complex>1</complex> + <complex>12.34</complex> + <complex>0.12</complex> + <complex>12.13</complex> + <complex>123.1</complex> + <complex>1234</complex> + <complex>-12.12</complex> + <complex>-123.1</complex> +</t:root> diff --git a/xsd/tests/cxx/tree/float/test.xml b/xsd/tests/cxx/tree/float/test.xml new file mode 100644 index 0000000..e5124a4 --- /dev/null +++ b/xsd/tests/cxx/tree/float/test.xml @@ -0,0 +1,35 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd" + f="0.0" do="0.0" de="0.0"> + + <float>0.0</float> + <float>1.0</float> + <float>1000000.0</float> + <float>0.0000001</float> + <float-list>0.0 1.0 1000000.0 0.0000001</float-list> + + <double>0.0</double> + <double>1.0</double> + <double>100000000000000.0</double> + <double>0.000000000000001</double> + <double-list>0.0 1.0 100000000000000.0 0.000000000000001</double-list> + + <decimal>0.0</decimal> + <decimal>1.0</decimal> + <decimal>10000</decimal> + <decimal>100000000000000.0</decimal> + <decimal>0.000000000000001</decimal> + <decimal-list>0.0 1.0 100000000000000.0 0.000000000000001</decimal-list> + + <simple>0.0</simple> + <simple>1.0</simple> + <simple>12.34</simple> + <simple>0.12</simple> + + <complex>0.0</complex> + <complex>1.0</complex> + <complex>12.34</complex> + <complex>0.12</complex> + +</t:root> diff --git a/xsd/tests/cxx/tree/float/test.xsd b/xsd/tests/cxx/tree/float/test.xsd new file mode 100644 index 0000000..c02678d --- /dev/null +++ b/xsd/tests/cxx/tree/float/test.xsd @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="float-list"> + <list itemType="float"/> + </simpleType> + + <simpleType name="double-list"> + <list itemType="double"/> + </simpleType> + + <simpleType name="decimal-list"> + <list itemType="decimal"/> + </simpleType> + + <!-- decimal facets --> + + <simpleType name="simple"> + <restriction base="t:base-simple"> + <fractionDigits value="2"/> + </restriction> + </simpleType> + + <simpleType name="base-simple"> + <restriction base="decimal"> + <totalDigits value="4"/> + </restriction> + </simpleType> + + <complexType name="complex"> + <simpleContent> + <restriction base="t:base-complex"> + <fractionDigits value="2"/> + <totalDigits value="4"/> + <attribute name="x" type="int"/> + </restriction> + </simpleContent> + </complexType> + + <complexType name="base-complex"> + <simpleContent> + <extension base="decimal"> + <attribute name="x" type="int"/> + </extension> + </simpleContent> + </complexType> + + + <complexType name="type"> + <sequence> + <element name="float" type="float" maxOccurs="unbounded"/> + <element name="float-list" type="t:float-list"/> + <element name="double" type="double" maxOccurs="unbounded"/> + <element name="double-list" type="t:double-list"/> + <element name="decimal" type="decimal" maxOccurs="unbounded"/> + <element name="decimal-list" type="t:decimal-list"/> + + <element name="simple" type="t:simple" maxOccurs="unbounded"/> + <element name="complex" type="t:complex" maxOccurs="unbounded"/> + + </sequence> + <attribute name="f" type="float" default="12.34"/> + <attribute name="do" type="double" default="1234.1234"/> + <attribute name="de" type="decimal" default="1234.1234"/> + + <attribute name="s" type="t:simple"/> + </complexType> + + <element name="root" type="t:type"/> + + <element name="double" type="double"/> + <element name="decimal" type="decimal"/> + +</schema> diff --git a/xsd/tests/cxx/tree/list/ctor/driver.cxx b/xsd/tests/cxx/tree/list/ctor/driver.cxx new file mode 100644 index 0000000..784ae01 --- /dev/null +++ b/xsd/tests/cxx/tree/list/ctor/driver.cxx @@ -0,0 +1,51 @@ +// file : tests/cxx/tree/list/ctor/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test list constructors. +// +#include <string> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + // Test ctor() + // + { + string_list sl; + + xml_schema::nmtokens nt; + xml_schema::idrefs id; + } + + // Test ctor(size_type, const X&) + // + { + string_list sl (10, "abc"); + size_type st (10, 123); + + xml_schema::nmtokens nt (10, "abc"); + xml_schema::idrefs id (10, "abc"); + } + + // Test ctor(const I& begin, const I& end) + // + { + string_list sl1 (10, "abc"); + string_list sl2 (sl1.begin (), sl1.end ()); + + I i1 (10, 123); + I i2 (i1.begin (), i1.end ()); + + xml_schema::nmtokens nt1 (10, "abc"); + xml_schema::nmtokens nt2 (nt1.begin (), nt1.end ()); + + xml_schema::idrefs id1 (10, "abc"); + xml_schema::idrefs id2 (id1.begin (), id1.end ()); + } +} diff --git a/xsd/tests/cxx/tree/list/ctor/makefile b/xsd/tests/cxx/tree/list/ctor/makefile new file mode 100644 index 0000000..4115606 --- /dev/null +++ b/xsd/tests/cxx/tree/list/ctor/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/list/ctor/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-default-ctor --generate-from-base-ctor \ +--generate-doxygen +$(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) + $(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,$(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/list/ctor/test.xsd b/xsd/tests/cxx/tree/list/ctor/test.xsd new file mode 100644 index 0000000..f090bb8 --- /dev/null +++ b/xsd/tests/cxx/tree/list/ctor/test.xsd @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="string-list"> + <list itemType="string"/> + </simpleType> + + <!-- Test name conflict resolution. --> + + <simpleType name="size_type"> + <list itemType="int"/> + </simpleType> + + <simpleType name="I"> + <list itemType="int"/> + </simpleType> + +</schema> diff --git a/xsd/tests/cxx/tree/list/makefile b/xsd/tests/cxx/tree/list/makefile new file mode 100644 index 0000000..4af3e22 --- /dev/null +++ b/xsd/tests/cxx/tree/list/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/list/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 := ctor + +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/makefile b/xsd/tests/cxx/tree/makefile new file mode 100644 index 0000000..7fd9f63 --- /dev/null +++ b/xsd/tests/cxx/tree/makefile @@ -0,0 +1,44 @@ +# file : tests/cxx/tree/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 := \ +any-type \ +built-in \ +chameleon \ +comparison \ +compilation \ +complex \ +containment \ +default \ +detach \ +dom-association \ +encoding \ +enumeration \ +float \ +list \ +name-clash \ +naming \ +order \ +polymorphism \ +prefix \ +test-template \ +types-only \ +union \ +wildcard + +ifeq ($(xsd_with_ace),y) +tests += binary +endif + +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/name-clash/inheritance/driver.cxx b/xsd/tests/cxx/tree/name-clash/inheritance/driver.cxx new file mode 100644 index 0000000..07e0c00 --- /dev/null +++ b/xsd/tests/cxx/tree/name-clash/inheritance/driver.cxx @@ -0,0 +1,36 @@ +// file : tests/cxx/tree/name-clash/inheritance/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test for name clashes across inheritance hierarchy. +// + +#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<derived> 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/name-clash/inheritance/makefile b/xsd/tests/cxx/tree/name-clash/inheritance/makefile new file mode 100644 index 0000000..ea05693 --- /dev/null +++ b/xsd/tests/cxx/tree/name-clash/inheritance/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/name-clash/inheritance/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 +$(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/name-clash/inheritance/output b/xsd/tests/cxx/tree/name-clash/inheritance/output new file mode 100644 index 0000000..54565bb --- /dev/null +++ b/xsd/tests/cxx/tree/name-clash/inheritance/output @@ -0,0 +1,3 @@ + +e: e +e: e1 diff --git a/xsd/tests/cxx/tree/name-clash/inheritance/test.xml b/xsd/tests/cxx/tree/name-clash/inheritance/test.xml new file mode 100644 index 0000000..8c17101 --- /dev/null +++ b/xsd/tests/cxx/tree/name-clash/inheritance/test.xml @@ -0,0 +1,8 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <e>e</e> + <e>e1</e> + +</t:root> diff --git a/xsd/tests/cxx/tree/name-clash/inheritance/test.xsd b/xsd/tests/cxx/tree/name-clash/inheritance/test.xsd new file mode 100644 index 0000000..b83d7df --- /dev/null +++ b/xsd/tests/cxx/tree/name-clash/inheritance/test.xsd @@ -0,0 +1,53 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- same member name in base and derived --> + + <complexType name="base"> + <sequence> + <element name="e" type="string"/> + </sequence> + </complexType> + + <complexType name="derived"> + <complexContent> + <extension base="t:base"> + <sequence> + <element name="e" type="string"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="root" type="t:derived"/> + + <!-- same c-tor argument names (compilation only) --> + + <complexType name="ctor-args"> + <simpleContent> + <extension base="string"> + <attribute name="string" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + + <!-- same c-tor argument names (compilation only) --> + + <complexType name="ctor-args-base"> + <simpleContent> + <extension base="string"> + <attribute name="ctor-args-derived" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + + <complexType name="ctor-args-derived"> + <simpleContent> + <extension base="t:ctor-args-base"> + <attribute name="foo" type="string" use="required"/> + </extension> + </simpleContent> + </complexType> + +</schema> diff --git a/xsd/tests/cxx/tree/name-clash/makefile b/xsd/tests/cxx/tree/name-clash/makefile new file mode 100644 index 0000000..c9a4d0f --- /dev/null +++ b/xsd/tests/cxx/tree/name-clash/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/name-clash/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 := inheritance + +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/naming/camel/driver.cxx b/xsd/tests/cxx/tree/naming/camel/driver.cxx new file mode 100644 index 0000000..716a544 --- /dev/null +++ b/xsd/tests/cxx/tree/naming/camel/driver.cxx @@ -0,0 +1,155 @@ +// file : tests/cxx/tree/naming/camel/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test camel case (upper for types, lower for functions) naming style. +// + +#include <sstream> +#include <iostream> + +#include <xercesc/util/PlatformUtils.hpp> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + xercesc::XMLPlatformUtils::Initialize (); + + try + { + // Enum 'value' type. + // + { + Gender::Value v; + v = Gender::female; + XSD_UNUSED (v); + } + + // Anonymous type. + // + { + Foo f ("a", "b"); + + if (f.a () != "a" || f.b () != "b") + return 1; + } + + // Type name and accessors/modifiers. + // + { + Type t ("bar"); + + // foo + // + { + Type::FooType* p = 0; + XSD_UNUSED (p); + + Type::FooOptional o; + + if (t.foo ().present ()) + return 1; + + t.foo (o); + } + + // bar + // + { + Type::BarType* p = 0; + XSD_UNUSED (p); + + if (t.bar () != "bar") + return 1; + + t.bar ("barbar"); + } + + // baz + // + { + Type::BazType* p = 0; + XSD_UNUSED (p); + + Type::BazSequence s; + Type::BazIterator i (s.begin ()); + Type::BazConstIterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.baz () != s) + return 1; + + t.baz (s); + } + + // any + // + { + Type::AnySequence s (t.domDocument ()); + Type::AnyIterator i (s.begin ()); + Type::AnyConstIterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.any () != s) + return 1; + + t.any (s); + } + + // foo + // + { + Type::FoxType x = Type::foxDefaultValue (); + + if (t.fox () != x) + return 1; + + t.fox ("fox"); + } + + // any_attribute + // + { + Type::AnyAttributeSet s (t.domDocument ()); + Type::AnyAttributeIterator i (s.begin ()); + Type::AnyAttributeConstIterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.anyAttribute () != s) + return 1; + + t.anyAttribute (s); + } + } + + // Parsing/serialization functions. + // + { + istringstream is ("<t:Root xmlns:t='test'>foo</t:Root>"); + root (is, xml_schema::Flags::dont_validate); + } + + { + ostringstream os; + xml_schema::NamespaceInfomap m; + m["t"].name = "test"; + + root (os, "foo", m); + } + } + catch (xml_schema::Exception const& e) + { + cerr << e << endl; + return 1; + } + + xercesc::XMLPlatformUtils::Terminate (); +} diff --git a/xsd/tests/cxx/tree/naming/camel/makefile b/xsd/tests/cxx/tree/naming/camel/makefile new file mode 100644 index 0000000..6364196 --- /dev/null +++ b/xsd/tests/cxx/tree/naming/camel/makefile @@ -0,0 +1,94 @@ +# file : tests/cxx/tree/naming/camel/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 += \ +--type-naming ucc \ +--function-naming lcc \ +--generate-ostream \ +--generate-serialization \ +--generate-comparison \ +--generate-wildcard + +$(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) + $(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,$(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/naming/camel/test.xsd b/xsd/tests/cxx/tree/naming/camel/test.xsd new file mode 100644 index 0000000..7d0a745 --- /dev/null +++ b/xsd/tests/cxx/tree/naming/camel/test.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="gender"> + <restriction base="string"> + <enumeration value="male"/> + <enumeration value="female"/> + </restriction> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="foo" minOccurs="0"> + <complexType> + <sequence> + <element name="a" type="string"/> + <element name="b" type="string"/> + </sequence> + </complexType> + </element> + <element name="Bar" type="string"/> + <element name="Baz" type="string" maxOccurs="unbounded"/> + <any namespace="other" processContents="skip" maxOccurs="unbounded"/> + </sequence> + <attribute name="Fox" type="string" default="hello"/> + <anyAttribute namespace="##other" processContents="skip"/> + </complexType> + + <element name="Root" type="string"/> + +</schema> diff --git a/xsd/tests/cxx/tree/naming/java/driver.cxx b/xsd/tests/cxx/tree/naming/java/driver.cxx new file mode 100644 index 0000000..f35607a --- /dev/null +++ b/xsd/tests/cxx/tree/naming/java/driver.cxx @@ -0,0 +1,154 @@ +// file : tests/cxx/tree/naming/java/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test Java naming style. +// + +#include <sstream> +#include <iostream> + +#include <xercesc/util/PlatformUtils.hpp> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + xercesc::XMLPlatformUtils::Initialize (); + + try + { + // Enum 'value' type. + // + { + Gender::Value v; + v = Gender::female; + XSD_UNUSED (v); + } + + // Anonymous type. + // + { + Foo f ("a", "b"); + + if (f.getA () != "a" || f.getB () != "b") + return 1; + } + + // Type name and accessors/modifiers. + // + { + Type t ("bar"); + + // foo + // + { + Type::FooType* p = 0; + XSD_UNUSED (p); + Type::FooOptional o; + + if (t.getFoo ().present ()) + return 1; + + t.setFoo (o); + } + + // bar + // + { + Type::BarType* p = 0; + XSD_UNUSED (p); + + if (t.getBar () != "bar") + return 1; + + t.setBar ("barbar"); + } + + // baz + // + { + Type::BazType* p = 0; + XSD_UNUSED (p); + + Type::BazSequence s; + Type::BazIterator i (s.begin ()); + Type::BazConstIterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.getBaz () != s) + return 1; + + t.setBaz (s); + } + + // any + // + { + Type::AnySequence s (t.getDomDocument ()); + Type::AnyIterator i (s.begin ()); + Type::AnyConstIterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.getAny () != s) + return 1; + + t.setAny (s); + } + + // foo + // + { + Type::FoxType x = Type::getFoxDefaultValue (); + + if (t.getFox () != x) + return 1; + + t.setFox ("fox"); + } + + // any_attribute + // + { + Type::AnyAttributeSet s (t.getDomDocument ()); + Type::AnyAttributeIterator i (s.begin ()); + Type::AnyAttributeConstIterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.getAnyAttribute () != s) + return 1; + + t.setAnyAttribute (s); + } + } + + // Parsing/serialization functions. + // + { + istringstream is ("<t:root xmlns:t='test'>foo</t:root>"); + parseRoot (is, xml_schema::Flags::dont_validate); + } + + { + ostringstream os; + xml_schema::NamespaceInfomap m; + m["t"].name = "test"; + + serializeRoot (os, "foo", m); + } + } + catch (xml_schema::Exception const& e) + { + cerr << e << endl; + return 1; + } + + xercesc::XMLPlatformUtils::Terminate (); +} diff --git a/xsd/tests/cxx/tree/naming/java/makefile b/xsd/tests/cxx/tree/naming/java/makefile new file mode 100644 index 0000000..83d73e1 --- /dev/null +++ b/xsd/tests/cxx/tree/naming/java/makefile @@ -0,0 +1,94 @@ +# file : tests/cxx/tree/naming/java/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 += \ +--type-naming java \ +--function-naming java \ +--generate-ostream \ +--generate-serialization \ +--generate-comparison \ +--generate-wildcard + +$(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) + $(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,$(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/naming/java/test.xsd b/xsd/tests/cxx/tree/naming/java/test.xsd new file mode 100644 index 0000000..f525534 --- /dev/null +++ b/xsd/tests/cxx/tree/naming/java/test.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="gender"> + <restriction base="string"> + <enumeration value="male"/> + <enumeration value="female"/> + </restriction> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="foo" minOccurs="0"> + <complexType> + <sequence> + <element name="a" type="string"/> + <element name="b" type="string"/> + </sequence> + </complexType> + </element> + <element name="bar" type="string"/> + <element name="Baz" type="string" maxOccurs="unbounded"/> + <any namespace="other" processContents="skip" maxOccurs="unbounded"/> + </sequence> + <attribute name="Fox" type="string" default="hello"/> + <anyAttribute namespace="##other" processContents="skip"/> + </complexType> + + <element name="root" type="string"/> + +</schema> diff --git a/xsd/tests/cxx/tree/naming/knr/driver.cxx b/xsd/tests/cxx/tree/naming/knr/driver.cxx new file mode 100644 index 0000000..5038d7b --- /dev/null +++ b/xsd/tests/cxx/tree/naming/knr/driver.cxx @@ -0,0 +1,155 @@ +// file : tests/cxx/tree/naming/knr/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test K&R naming style. +// + +#include <sstream> +#include <iostream> + +#include <xercesc/util/PlatformUtils.hpp> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + xercesc::XMLPlatformUtils::Initialize (); + + try + { + // Enum 'value' type. + // + { + gender::value v; + v = gender::female; + XSD_UNUSED (v); + } + + // Anonymous type. + // + { + foo f ("a", "b"); + + if (f.a () != "a" || f.b () != "b") + return 1; + } + + // Type name and accessors/modifiers. + // + { + type t ("bar"); + + // foo + // + { + type::foo_type* p = 0; + XSD_UNUSED (p); + + type::foo_optional o; + + if (t.foo ().present ()) + return 1; + + t.foo (o); + } + + // bar + // + { + type::bar_type* p = 0; + XSD_UNUSED (p); + + if (t.bar () != "bar") + return 1; + + t.bar ("barbar"); + } + + // baz + // + { + type::baz_type* p = 0; + XSD_UNUSED (p); + + type::baz_sequence s; + type::baz_iterator i (s.begin ()); + type::baz_const_iterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.baz () != s) + return 1; + + t.baz (s); + } + + // any + // + { + type::any_sequence s (t.dom_document ()); + type::any_iterator i (s.begin ()); + type::any_const_iterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.any () != s) + return 1; + + t.any (s); + } + + // foo + // + { + type::fox_type x = type::fox_default_value (); + + if (t.fox () != x) + return 1; + + t.fox ("fox"); + } + + // any_attribute + // + { + type::any_attribute_set s (t.dom_document ()); + type::any_attribute_iterator i (s.begin ()); + type::any_attribute_const_iterator ci (s.begin ()); + XSD_UNUSED (i); + XSD_UNUSED (ci); + + if (t.any_attribute () != s) + return 1; + + t.any_attribute (s); + } + } + + // Parsing/serialization functions. + // + { + istringstream is ("<t:root xmlns:t='test'>foo</t:root>"); + root (is, xml_schema::flags::dont_validate); + } + + { + ostringstream os; + xml_schema::namespace_infomap m; + m["t"].name = "test"; + + root (os, "foo", m); + } + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } + + xercesc::XMLPlatformUtils::Terminate (); +} diff --git a/xsd/tests/cxx/tree/naming/knr/makefile b/xsd/tests/cxx/tree/naming/knr/makefile new file mode 100644 index 0000000..d8ecbab --- /dev/null +++ b/xsd/tests/cxx/tree/naming/knr/makefile @@ -0,0 +1,94 @@ +# file : tests/cxx/tree/naming/knr/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 += \ +--type-naming knr \ +--function-naming knr \ +--generate-ostream \ +--generate-serialization \ +--generate-comparison \ +--generate-wildcard + +$(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) + $(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,$(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/naming/knr/test.xsd b/xsd/tests/cxx/tree/naming/knr/test.xsd new file mode 100644 index 0000000..4361544 --- /dev/null +++ b/xsd/tests/cxx/tree/naming/knr/test.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="gender"> + <restriction base="string"> + <enumeration value="male"/> + <enumeration value="female"/> + </restriction> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="foo" minOccurs="0"> + <complexType> + <sequence> + <element name="a" type="string"/> + <element name="b" type="string"/> + </sequence> + </complexType> + </element> + <element name="bar" type="string"/> + <element name="baz" type="string" maxOccurs="unbounded"/> + <any namespace="other" processContents="skip" maxOccurs="unbounded"/> + </sequence> + <attribute name="fox" type="string" default="hello"/> + <anyAttribute namespace="##other" processContents="skip"/> + </complexType> + + <element name="root" type="string"/> + +</schema> diff --git a/xsd/tests/cxx/tree/naming/makefile b/xsd/tests/cxx/tree/naming/makefile new file mode 100644 index 0000000..60ac63b --- /dev/null +++ b/xsd/tests/cxx/tree/naming/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/naming/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 := camel java knr + +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/order/driver.cxx b/xsd/tests/cxx/tree/order/driver.cxx new file mode 100644 index 0000000..01d8d9f --- /dev/null +++ b/xsd/tests/cxx/tree/order/driver.cxx @@ -0,0 +1,65 @@ +// file : tests/cxx/tree/order/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test ordered type support. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <cassert> +#include <iostream> + +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/PlatformUtils.hpp> + +#include "test.hxx" + +using namespace std; +using namespace test; +using namespace xercesc; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + XMLPlatformUtils::Initialize (); + + try + { + XSD_AUTO_PTR<root> r (root_ (argv[1], xml_schema::flags::dont_initialize)); + + root c (*r); + assert (c == *r); + + for (root::t1_const_iterator j (r->t1 ().begin ()); + j != r->t1 ().end (); ++j) + { + const t1_derived& d (*j); + + for (t1_derived::content_order_const_iterator i ( + d.content_order ().begin ()); i != d.content_order ().end (); ++i) + { + cout << i->id << ' ' << i->index << endl; + } + } + + xml_schema::namespace_infomap map; + + map["t"].name = "test"; + map["t1"].name = "test1"; + + root_ (cout, *r, map, "UTF-8", xml_schema::flags::dont_initialize); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } + + XMLPlatformUtils::Terminate (); +} diff --git a/xsd/tests/cxx/tree/order/makefile b/xsd/tests/cxx/tree/order/makefile new file mode 100644 index 0000000..0dff0f9 --- /dev/null +++ b/xsd/tests/cxx/tree/order/makefile @@ -0,0 +1,94 @@ +# file : tests/cxx/tree/order/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-serialization --generate-wildcard \ +--generate-comparison \ +--ordered-type t1_base --ordered-type t1_derived \ +--ordered-type t2_base --ordered-type t2_derived \ +--ordered-type t3_type \ +--ordered-type t4_base --ordered-type t4_derived \ +--ordered-type t5_base --ordered-type t5_derived \ +--ordered-type t6_base --ordered-type t6_derived \ +--ordered-type t7_type +$(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/order/output b/xsd/tests/cxx/tree/order/output new file mode 100644 index 0000000..73442fe --- /dev/null +++ b/xsd/tests/cxx/tree/order/output @@ -0,0 +1,92 @@ +2 0 +1 0 +1 1 +2 1 +3 0 +4 0 +3 1 +4 1 +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<t:root xmlns:t="test" xmlns:t1="test1"> + <t1> + <b>b1</b> + <a>a1</a> + <a>a2</a> + <b>b2</b> + <c>c1</c> + <d>d1</d> + <t1:e>e1</t1:e> + <d>d2</d> + <t1:f>f1</t1:f> + </t1> + <t2> + <b>b1</b> + <a>a1</a> + <b>b2</b> + <a>a2</a> + </t2> + <t3> + <a>a1</a> + <b>b1</b> + <c>c1</c> + <c>c2</c> + </t3> + <t3> + <a>a1</a> + <c>c1</c> + </t3> + <t4> + t1 + + <b>b1</b> + t2 + + <a>a1</a> + t3 + + <b>b2</b> + t4 + + <a>a2</a> + t5 + + <t1:d>d1</t1:d> + t6 + + <c>c1</c> + t7 + + </t4> + <t5a> + t5a + </t5a> + <t5b> + t1 + + <b>b1</b> + t2 + + <a>a1</a> + t3 + + <a>a2</a> + t4 + + <b>b2</b> + t5 + + </t5b> + <t6> + t6 + </t6> + <t7> + t1 + + <t1:a>a1</t1:a> + t2 + + <t1:b>b1</t1:b> + t3 + + </t7> +</t:root> diff --git a/xsd/tests/cxx/tree/order/test.xml b/xsd/tests/cxx/tree/order/test.xml new file mode 100644 index 0000000..cd82936 --- /dev/null +++ b/xsd/tests/cxx/tree/order/test.xml @@ -0,0 +1,71 @@ +<t:root xmlns:t="test" + xmlns:t1="test1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + <t1> + <b>b1</b> + <a>a1</a> + <a>a2</a> + <b>b2</b> + <c>c1</c> + <d>d1</d> + <t1:e>e1</t1:e> + <d>d2</d> + <t1:f>f1</t1:f> + </t1> + <t2> + <b>b1</b> + <a>a1</a> + <b>b2</b> + <a>a2</a> + </t2> + <t3> + <a>a1</a> + <b>b1</b> + <c>c1</c> + <c>c2</c> + </t3> + <t3> + <a>a1</a> + <c>c1</c> + </t3> + <t4> + t1 + <b>b1</b> + t2 + <a>a1</a> + t3 + <b>b2</b> + t4 + <a>a2</a> + t5 + <t1:d>d1</t1:d> + t6 + <c>c1</c> + t7 + </t4> + <t5a> + t5a + </t5a> + <t5b> + t1 + <b>b1</b> + t2 + <a>a1</a> + t3 + <a>a2</a> + t4 + <b>b2</b> + t5 + </t5b> + <t6> + t6 + </t6> + <t7> + t1 + <t1:a>a1</t1:a> + t2 + <t1:b>b1</t1:b> + t3 + </t7> +</t:root> diff --git a/xsd/tests/cxx/tree/order/test.xsd b/xsd/tests/cxx/tree/order/test.xsd new file mode 100644 index 0000000..c30c027 --- /dev/null +++ b/xsd/tests/cxx/tree/order/test.xsd @@ -0,0 +1,130 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <!-- Test 1: general, with non-ordered intermediate. --> + + <complexType name="t1_base"> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </choice> + </complexType> + + <complexType name="t1_interm"> + <complexContent> + <extension base="t:t1_base"> + <sequence> + <element name="c" type="string" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="t1_derived"> + <complexContent> + <extension base="t:t1_interm"> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="d" type="string"/> + <any namespace="##other" processContents="lax"/> + </choice> + </extension> + </complexContent> + </complexType> + + <!-- Test 2: empty base. --> + + <complexType name="t2_base"/> + + <complexType name="t2_derived"> + <complexContent> + <extension base="t:t2_base"> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </choice> + </extension> + </complexContent> + </complexType> + + <!-- Test 3: element cardinalities. --> + + <complexType name="t3_type"> + <sequence> + <element name="a" type="string"/> + <element name="b" type="string" minOccurs="0"/> + <element name="c" type="string" maxOccurs="unbounded"/> + </sequence> + </complexType> + + + <!-- Test 4: mixed content, general. --> + + <complexType name="t4_base" mixed="true"> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </choice> + </complexType> + + <complexType name="t4_derived"> + <complexContent mixed="true"> + <extension base="t:t4_base"> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="c" type="string"/> + <any namespace="##other" processContents="lax"/> + </choice> + </extension> + </complexContent> + </complexType> + + <!-- Test 5: mixed content, empty base. --> + + <complexType name="t5_base" mixed="true"/> + + <complexType name="t5_derived"> + <complexContent mixed="true"> + <extension base="t:t5_base"> + <choice minOccurs="0" maxOccurs="unbounded"> + <element name="a" type="string"/> + <element name="b" type="string"/> + </choice> + </extension> + </complexContent> + </complexType> + + <!-- Test 6: mixed content, empty base and derived. --> + + <complexType name="t6_base" mixed="true"/> + + <complexType name="t6_derived"> + <complexContent mixed="true"> + <extension base="t:t6_base"/> + </complexContent> + </complexType> + + <!-- Test 7: mixed content wildcard only. --> + + <complexType name="t7_type" mixed="true"> + <sequence> + <any namespace="##other" processContents="lax" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <!-- Root --> + + <complexType name="root"> + <sequence> + <element name="t1" type="t:t1_derived" maxOccurs="unbounded"/> + <element name="t2" type="t:t2_derived" maxOccurs="unbounded"/> + <element name="t3" type="t:t3_type" maxOccurs="unbounded"/> + <element name="t4" type="t:t4_derived" maxOccurs="unbounded"/> + <element name="t5a" type="t:t5_base" maxOccurs="unbounded"/> + <element name="t5b" type="t:t5_derived" maxOccurs="unbounded"/> + <element name="t6" type="t:t6_derived" maxOccurs="unbounded"/> + <element name="t7" type="t:t7_type" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> 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> diff --git a/xsd/tests/cxx/tree/prefix/bar.xsd b/xsd/tests/cxx/tree/prefix/bar.xsd new file mode 100644 index 0000000..4e20902 --- /dev/null +++ b/xsd/tests/cxx/tree/prefix/bar.xsd @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:f="foo" + xmlns:b="bar" + targetNamespace="bar" + attributeFormDefault="qualified"> + + <import namespace="foo" schemaLocation="foo.xsd"/> + + <attribute name="abar" type="int"/> + + <complexType name="derived1"> + <complexContent> + <extension base="f:base"> + <sequence> + <element name="y" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <complexType name="derived2"> + <complexContent> + <extension base="f:base"> + <sequence> + <element name="z" type="int"/> + </sequence> + </extension> + </complexContent> + </complexType> + + <element name="derived" type="b:derived1" substitutionGroup="f:base"/> + +</schema> diff --git a/xsd/tests/cxx/tree/prefix/driver.cxx b/xsd/tests/cxx/tree/prefix/driver.cxx new file mode 100644 index 0000000..244f815 --- /dev/null +++ b/xsd/tests/cxx/tree/prefix/driver.cxx @@ -0,0 +1,35 @@ +// file : tests/cxx/tree/prefix/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test automatic prefix assignment. +// + +#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])); + root (std::cout, *r); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd/tests/cxx/tree/prefix/foo.xsd b/xsd/tests/cxx/tree/prefix/foo.xsd new file mode 100644 index 0000000..97a35cf --- /dev/null +++ b/xsd/tests/cxx/tree/prefix/foo.xsd @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:f="foo" + targetNamespace="foo"> + + <element name="efoo" type="int"/> + + <complexType name="base"> + <sequence> + <element name="x" type="int"/> + </sequence> + </complexType> + + <element name="base" type="f:base"/> + +</schema> diff --git a/xsd/tests/cxx/tree/prefix/makefile b/xsd/tests/cxx/tree/prefix/makefile new file mode 100644 index 0000000..688111e --- /dev/null +++ b/xsd/tests/cxx/tree/prefix/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/prefix/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 foo.xsd bar.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-serialization --generate-polymorphic \ +--polymorphic-type foo\#base --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/prefix/output b/xsd/tests/cxx/tree/prefix/output new file mode 100644 index 0000000..9801a23 --- /dev/null +++ b/xsd/tests/cxx/tree/prefix/output @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no" ?> +<p1:root xmlns:p1="test"> + <a xmlns:p3="bar" p3:abar="456" xmlns:p2="foo"> + <p2:efoo>123</p2:efoo> + </a> + <b xmlns:p2="bar"> + <p2:derived> + <x>1</x> + <y>2</y> + </p2:derived> + </b> + <c xmlns:p2="foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <p2:base xmlns:p3="bar" xsi:type="p3:derived2"> + <x>1</x> + <z>2</z> + </p2:base> + </c> +</p1:root> diff --git a/xsd/tests/cxx/tree/prefix/test.xml b/xsd/tests/cxx/tree/prefix/test.xml new file mode 100644 index 0000000..b6d0dd6 --- /dev/null +++ b/xsd/tests/cxx/tree/prefix/test.xml @@ -0,0 +1,19 @@ +<t:root xmlns:t="test" + xmlns:f="foo" + xmlns:b="bar" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a b:abar="456"> + <f:efoo>123</f:efoo> + </a> + + <b> + <b:derived><x>1</x><y>2</y></b:derived> + </b> + + <c> + <f:base xsi:type="b:derived2"><x>1</x><z>2</z></f:base> + </c> + +</t:root> diff --git a/xsd/tests/cxx/tree/prefix/test.xsd b/xsd/tests/cxx/tree/prefix/test.xsd new file mode 100644 index 0000000..421fdc0 --- /dev/null +++ b/xsd/tests/cxx/tree/prefix/test.xsd @@ -0,0 +1,40 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:f="foo" + xmlns:b="bar" + xmlns:t="test" + targetNamespace="test"> + + <import namespace="foo" schemaLocation="foo.xsd"/> + <import namespace="bar" schemaLocation="bar.xsd"/> + + <complexType name="a"> + <sequence> + <element ref="f:efoo"/> + </sequence> + <attribute ref="b:abar"/> + </complexType> + + <complexType name="b"> + <sequence> + <element ref="f:base"/> + </sequence> + </complexType> + + <complexType name="c"> + <sequence> + <element ref="f:base"/> + </sequence> + </complexType> + + <complexType name="type"> + <sequence> + <element name="a" type="t:a"/> + <element name="b" type="t:b"/> + <element name="c" type="t:c"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/test-template/driver.cxx b/xsd/tests/cxx/tree/test-template/driver.cxx new file mode 100644 index 0000000..f28e501 --- /dev/null +++ b/xsd/tests/cxx/tree/test-template/driver.cxx @@ -0,0 +1,36 @@ +// file : tests/cxx/tree/test-template/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Insert test description here. +// + +#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/test-template/makefile b/xsd/tests/cxx/tree/test-template/makefile new file mode 100644 index 0000000..32af96b --- /dev/null +++ b/xsd/tests/cxx/tree/test-template/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/test-template/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 +$(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/test-template/output b/xsd/tests/cxx/tree/test-template/output new file mode 100644 index 0000000..2a50681 --- /dev/null +++ b/xsd/tests/cxx/tree/test-template/output @@ -0,0 +1,2 @@ + +a: a diff --git a/xsd/tests/cxx/tree/test-template/test.xml b/xsd/tests/cxx/tree/test-template/test.xml new file mode 100644 index 0000000..624a80c --- /dev/null +++ b/xsd/tests/cxx/tree/test-template/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"> + + <a>a</a> + +</t:root> diff --git a/xsd/tests/cxx/tree/test-template/test.xsd b/xsd/tests/cxx/tree/test-template/test.xsd new file mode 100644 index 0000000..07bebc7 --- /dev/null +++ b/xsd/tests/cxx/tree/test-template/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/types-only/driver.cxx b/xsd/tests/cxx/tree/types-only/driver.cxx new file mode 100644 index 0000000..8ba7500 --- /dev/null +++ b/xsd/tests/cxx/tree/types-only/driver.cxx @@ -0,0 +1,31 @@ +// file : tests/cxx/tree/types-only/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test that code generated without parsing and serialization functions +// still compiles. +// + +#include <iostream> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + color_enum red (color_enum::red); + red_blue_enum blue (red_blue_enum::blue); + + long_string_union num ("123"); + + string_list list; + list.push_back ("Hello"); + list.push_back ("World"); + + complex_type t ("Hello, World!", "foo", color_enum::red); + + anon a ("Hello, World!"); +} diff --git a/xsd/tests/cxx/tree/types-only/makefile b/xsd/tests/cxx/tree/types-only/makefile new file mode 100644 index 0000000..25520a4 --- /dev/null +++ b/xsd/tests/cxx/tree/types-only/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/types-only/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 += --suppress-parsing +$(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) + $(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,$(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/types-only/test.xsd b/xsd/tests/cxx/tree/types-only/test.xsd new file mode 100644 index 0000000..9f02240 --- /dev/null +++ b/xsd/tests/cxx/tree/types-only/test.xsd @@ -0,0 +1,52 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="color-enum"> + <restriction base="token"> + <enumeration value="red"/> + <enumeration value="green"/> + <enumeration value="blue"/> + </restriction> + </simpleType> + + <simpleType name="red-blue-enum"> + <restriction base="t:color-enum"> + <enumeration value="red"/> + <enumeration value="blue"/> + </restriction> + </simpleType> + + <simpleType name="long-string-union"> + <union memberTypes="long string"/> + </simpleType> + + <simpleType name="string-list"> + <list itemType="string"/> + </simpleType> + + <complexType name="complex-type"> + <sequence> + <element name="a" type="string"/> + </sequence> + <attribute name="text" type="string" use="required"/> + <attribute name="color" type="t:color-enum" use="required"/> + <attribute name="ftext" type="string" fixed="foo"/> + <attribute name="dcolor" type="t:color-enum" default="red"/> + </complexType> + + <!-- Test that we do not perform type/element name conflict resolution + as well as print any warnings. --> + <element name="type" type="string"/> + + <!-- Test that we generate anonymous type for global element. --> + <element name="anon"> + <complexType> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + </element> + + <element name="root" type="t:complex-type"/> + +</schema> diff --git a/xsd/tests/cxx/tree/union/ctor/driver.cxx b/xsd/tests/cxx/tree/union/ctor/driver.cxx new file mode 100644 index 0000000..14a8565 --- /dev/null +++ b/xsd/tests/cxx/tree/union/ctor/driver.cxx @@ -0,0 +1,31 @@ +// file : tests/cxx/tree/union/ctor/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test union constructors. +// +#include <string> + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main () +{ + // Test ctor(const std::string&) + // + { + string const s ("123"); + int_string_union u (s); + type t (s); + } + + // Test ctor(const char*). + // + { + int_string_union u ("123"); + type t ("123"); + } +} diff --git a/xsd/tests/cxx/tree/union/ctor/makefile b/xsd/tests/cxx/tree/union/ctor/makefile new file mode 100644 index 0000000..1edd762 --- /dev/null +++ b/xsd/tests/cxx/tree/union/ctor/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/union/ctor/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-default-ctor --generate-from-base-ctor \ +--generate-doxygen +$(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) + $(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,$(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/union/ctor/test.xsd b/xsd/tests/cxx/tree/union/ctor/test.xsd new file mode 100644 index 0000000..9601093 --- /dev/null +++ b/xsd/tests/cxx/tree/union/ctor/test.xsd @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <simpleType name="int-string-union"> + <union memberTypes="int string"/> + </simpleType> + + <complexType name="type"> + <sequence> + <element name="a" type="t:int-string-union"/> + </sequence> + </complexType> + +</schema> diff --git a/xsd/tests/cxx/tree/union/makefile b/xsd/tests/cxx/tree/union/makefile new file mode 100644 index 0000000..59abec6 --- /dev/null +++ b/xsd/tests/cxx/tree/union/makefile @@ -0,0 +1,17 @@ +# file : tests/cxx/tree/union/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 := ctor + +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/wildcard/driver.cxx b/xsd/tests/cxx/tree/wildcard/driver.cxx new file mode 100644 index 0000000..e2db827 --- /dev/null +++ b/xsd/tests/cxx/tree/wildcard/driver.cxx @@ -0,0 +1,204 @@ +// file : tests/cxx/tree/wildcard/driver.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test wildcard (any & anyAttribute) mapping. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <sstream> +#include <iostream> + +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/PlatformUtils.hpp> + +#include "test.hxx" // Get XSD_CXX11 defined. + +#include <xsd/cxx/xml/string.hxx> + +using namespace std; +using namespace test; +using namespace xercesc; + +namespace xml = xsd::cxx::xml; + +void +print (type& t) +{ + if (t.att ()) + cout << *t.att () << endl; + + type::any_attribute_set& as (t.any_attribute ()); + + for (type::any_attribute_iterator i (as.begin ()); i != as.end (); ++i) + { + cout << xml::transcode<char> (i->getTextContent ()) << endl; + } + + cout << xml::transcode<char> (t.any ().getTextContent ()) << endl + << t.foo () << endl; + + if (t.any1 ()) + cout << xml::transcode<char> (t.any1 ()->getTextContent ()) << endl; + + cout << t.bar () << endl; + + type::any2_sequence& es (t.any2 ()); + + for (type::any2_iterator i (es.begin ()); i != es.end (); ++i) + { + cout << xml::transcode<char> (i->getTextContent ()) << endl; + } + + cout << endl; +} + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + XMLPlatformUtils::Initialize (); + + try + { + // Test accessors/modifiers for various cardinalities. + // + type t; + + DOMDocument& doc (t.dom_document ()); + + // one + // + { + DOMElement* e (doc.createElement (xml::string ("a").c_str ())); + t.any (*e); + e->release (); + assert (xml::transcode<char> (t.any ().getTagName ()) == "a"); + + t.any (doc.createElement (xml::string ("b").c_str ())); + assert (xml::transcode<char> (t.any ().getTagName ()) == "b"); + } + + // optional + // + { + assert (!t.any1 ().present ()); + + DOMElement* e (doc.createElement (xml::string ("a").c_str ())); + t.any1 (*e); + e->release (); + assert (t.any1 ().present ()); + assert (xml::transcode<char> (t.any1 ().get ().getTagName ()) == "a"); + + t.any1 (doc.createElement (xml::string ("b").c_str ())); + assert (xml::transcode<char> (t.any1 ()->getTagName ()) == "b"); + + type::any1_optional c ( + doc.createElement (xml::string ("c").c_str ()), doc); + t.any1 (c); + assert (xml::transcode<char> (t.any1 ()->getTagName ()) == "c"); + } + + + // sequence + // + { + type::any2_sequence& s (t.any2 ()); + + DOMElement* e (doc.createElement (xml::string ("a").c_str ())); + s.push_back (*e); + e->release (); + s.push_back (doc.createElement (xml::string ("b").c_str ())); + assert (s.size () == 2); + + for (type::any2_iterator i (s.begin ()); i != s.end (); ++i) + { + if (i == s.begin ()) + assert (xml::transcode<char> (i->getTagName ()) == "a"); + else + assert (xml::transcode<char> ((*i).getTagName ()) == "b"); + } + + // copy c-tor + type::any2_sequence cs (s, doc); + assert (cs.size () == 2); + assert (xml::transcode<char> (cs[0].getTagName ()) == "a"); + assert (xml::transcode<char> (cs[1].getTagName ()) == "b"); + + // assignment + t.any2 (cs); + assert (s.size () == 2); + assert (xml::transcode<char> (s[0].getTagName ()) == "a"); + assert (xml::transcode<char> (s[1].getTagName ()) == "b"); + } + + // anyAttribute + // + { + type::any_attribute_set& s (t.any_attribute ()); + + DOMAttr* a (doc.createAttribute (xml::string ("a").c_str ())); + s.insert (*a); + a->release (); + s.insert (doc.createAttribute (xml::string ("b").c_str ())); + assert (s.size () == 2); + + assert (s.find ("a") != s.end ()); + assert (s.find ("b") != s.end ()); + + for (type::any_attribute_iterator i (s.begin ()); i != s.end (); ++i) + { + assert (xml::transcode<char> (i->getName ()) == "a" || + xml::transcode<char> ((*i).getName ()) == "b"); + } + + // copy c-tor + type::any_attribute_set cs (s, doc); + assert (cs.size () == 2); + assert (cs.count ("a")); + assert (cs.count ("b")); + + // assignment + t.any_attribute (cs); + assert (s.size () == 2); + assert (s.count ("a")); + assert (s.count ("b")); + } + + // Test parsing + // + XSD_AUTO_PTR<type> r (root (argv[1])); + print (*r); + + // Test serialization. + // + xml_schema::namespace_infomap map; + + map["t"].name = "test"; + map["t"].schema = "test.xsd"; + map["o"].name = "other"; + + stringstream iostr; + root (iostr, *r, map); + + // cout << iostr.str () << endl + // << endl; + + XSD_AUTO_PTR<type> copy (root (iostr, argv[1])); + assert (*copy == *r); + + print (*copy); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } + + XMLPlatformUtils::Terminate (); +} diff --git a/xsd/tests/cxx/tree/wildcard/makefile b/xsd/tests/cxx/tree/wildcard/makefile new file mode 100644 index 0000000..b86c34a --- /dev/null +++ b/xsd/tests/cxx/tree/wildcard/makefile @@ -0,0 +1,87 @@ +# file : tests/cxx/tree/wildcard/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-wildcard --generate-default-ctor \ +--generate-from-base-ctor --generate-serialization --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 $(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/wildcard/output b/xsd/tests/cxx/tree/wildcard/output new file mode 100644 index 0000000..b23b488 --- /dev/null +++ b/xsd/tests/cxx/tree/wildcard/output @@ -0,0 +1,24 @@ +att +any +o:any +t:any +o:one +foo +t:bar +bar +o:one1 +o:one2 +o:one3 + +att +any +o:any +t:any +o:one +foo +t:bar +bar +o:one1 +o:one2 +o:one3 + diff --git a/xsd/tests/cxx/tree/wildcard/test.xml b/xsd/tests/cxx/tree/wildcard/test.xml new file mode 100644 index 0000000..b0c3267 --- /dev/null +++ b/xsd/tests/cxx/tree/wildcard/test.xml @@ -0,0 +1,19 @@ +<t:root xmlns:t="test" + xmlns:o="other" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd" + + att="att" + any="any" + t:any="t:any" + o:any="o:any"> + + <o:one>o:one</o:one> + <foo>foo</foo> + <t:bar>t:bar</t:bar> + <bar>bar</bar> + <o:seq1>o:one1</o:seq1> + <o:seq2>o:one2</o:seq2> + <o:seq3>o:one3</o:seq3> + +</t:root> diff --git a/xsd/tests/cxx/tree/wildcard/test.xsd b/xsd/tests/cxx/tree/wildcard/test.xsd new file mode 100644 index 0000000..6c7b308 --- /dev/null +++ b/xsd/tests/cxx/tree/wildcard/test.xsd @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <any namespace="##other" processContents="skip"/> + <element name="foo" type="string"/> + <any namespace="##targetNamespace" minOccurs="0" processContents="skip"/> + <element name="bar" type="string"/> + <any namespace="##other" maxOccurs="unbounded" processContents="skip"/> + </sequence> + <attribute name="att" type="string"/> + <anyAttribute namespace="##any" processContents="skip"/> + </complexType> + + <element name="root" type="t:type"/> + +</schema> |