summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-07-03 09:57:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-07-03 09:57:09 +0200
commit1a4099b78717b16f632b0e7e0980a27811221e52 (patch)
tree87a63393fc207082b7418987309581a9a79e49a4 /tests
parent06258b8eae3d5af9a1af0206bb5a8e5c80dde455 (diff)
Implement anyType and anySimpleType content representation
anyType as a DOM fragment, similar to wildcards. anySimpleType as a text string.
Diffstat (limited to 'tests')
-rw-r--r--tests/cxx/tree/any-type/driver.cxx145
-rw-r--r--tests/cxx/tree/any-type/makefile87
-rw-r--r--tests/cxx/tree/any-type/output73
-rw-r--r--tests/cxx/tree/any-type/test.xml26
-rw-r--r--tests/cxx/tree/any-type/test.xsd19
-rw-r--r--tests/cxx/tree/binary/cdr/driver.cxx8
-rw-r--r--tests/cxx/tree/binary/cdr/makefile2
-rw-r--r--tests/cxx/tree/binary/cdr/test.xml4
-rw-r--r--tests/cxx/tree/binary/cdr/test.xsd3
-rw-r--r--tests/cxx/tree/binary/polymorphic/makefile3
-rw-r--r--tests/cxx/tree/binary/xdr/driver.cxx8
-rw-r--r--tests/cxx/tree/binary/xdr/makefile3
-rw-r--r--tests/cxx/tree/binary/xdr/test.xml4
-rw-r--r--tests/cxx/tree/binary/xdr/test.xsd3
-rw-r--r--tests/cxx/tree/compilation/driver.cxx2
-rw-r--r--tests/cxx/tree/makefile1
16 files changed, 385 insertions, 6 deletions
diff --git a/tests/cxx/tree/any-type/driver.cxx b/tests/cxx/tree/any-type/driver.cxx
new file mode 100644
index 0000000..1ac5274
--- /dev/null
+++ b/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/tests/cxx/tree/any-type/makefile b/tests/cxx/tree/any-type/makefile
new file mode 100644
index 0000000..1d0590f
--- /dev/null
+++ b/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/tests/cxx/tree/any-type/output b/tests/cxx/tree/any-type/output
new file mode 100644
index 0000000..580e7db
--- /dev/null
+++ b/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/tests/cxx/tree/any-type/test.xml b/tests/cxx/tree/any-type/test.xml
new file mode 100644
index 0000000..7c9035a
--- /dev/null
+++ b/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/tests/cxx/tree/any-type/test.xsd b/tests/cxx/tree/any-type/test.xsd
new file mode 100644
index 0000000..37dcc8d
--- /dev/null
+++ b/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/tests/cxx/tree/binary/cdr/driver.cxx b/tests/cxx/tree/binary/cdr/driver.cxx
index 65c88fa..a2d7195 100644
--- a/tests/cxx/tree/binary/cdr/driver.cxx
+++ b/tests/cxx/tree/binary/cdr/driver.cxx
@@ -127,6 +127,14 @@ main (int argc, char* argv[])
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)
{
diff --git a/tests/cxx/tree/binary/cdr/makefile b/tests/cxx/tree/binary/cdr/makefile
index 9613841..eb80d35 100644
--- a/tests/cxx/tree/binary/cdr/makefile
+++ b/tests/cxx/tree/binary/cdr/makefile
@@ -37,7 +37,7 @@ gen := $(addprefix $(out_base)/,$(genf))
$(gen): xsd := $(out_root)/xsd/xsd
$(gen): xsd_options += --generate-insertion ACE_OutputCDR \
---generate-extraction ACE_InputCDR
+--generate-extraction ACE_InputCDR --generate-comparison
$(gen): $(out_root)/xsd/xsd
$(call include-dep,$(dep),$(obj),$(gen))
diff --git a/tests/cxx/tree/binary/cdr/test.xml b/tests/cxx/tree/binary/cdr/test.xml
index 928b4cf..5cedd98 100644
--- a/tests/cxx/tree/binary/cdr/test.xml
+++ b/tests/cxx/tree/binary/cdr/test.xml
@@ -1,6 +1,7 @@
<t:root xmlns:t="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="test test.xsd">
+ xsi:schemaLocation="test test.xsd"
+ any_simple_type_attr="any simple content">
<list>1 2 3</list>
@@ -87,5 +88,6 @@
<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/tests/cxx/tree/binary/cdr/test.xsd b/tests/cxx/tree/binary/cdr/test.xsd
index e593f64..0629e94 100644
--- a/tests/cxx/tree/binary/cdr/test.xsd
+++ b/tests/cxx/tree/binary/cdr/test.xsd
@@ -112,7 +112,10 @@
<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"/>
diff --git a/tests/cxx/tree/binary/polymorphic/makefile b/tests/cxx/tree/binary/polymorphic/makefile
index f9ddf67..05c5186 100644
--- a/tests/cxx/tree/binary/polymorphic/makefile
+++ b/tests/cxx/tree/binary/polymorphic/makefile
@@ -37,7 +37,8 @@ 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-insertion ACE_OutputCDR --generate-extraction ACE_InputCDR \
+ --generate-comparison
$(gen): $(out_root)/xsd/xsd
$(call include-dep,$(dep),$(obj),$(gen))
diff --git a/tests/cxx/tree/binary/xdr/driver.cxx b/tests/cxx/tree/binary/xdr/driver.cxx
index ddc196d..623a953 100644
--- a/tests/cxx/tree/binary/xdr/driver.cxx
+++ b/tests/cxx/tree/binary/xdr/driver.cxx
@@ -171,6 +171,14 @@ main (int argc, char* argv[])
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)
{
diff --git a/tests/cxx/tree/binary/xdr/makefile b/tests/cxx/tree/binary/xdr/makefile
index 184c5d2..2994134 100644
--- a/tests/cxx/tree/binary/xdr/makefile
+++ b/tests/cxx/tree/binary/xdr/makefile
@@ -32,7 +32,8 @@ 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
+$(gen): xsd_options += --generate-insertion XDR --generate-extraction XDR \
+--generate-comparison
$(gen): $(out_root)/xsd/xsd
$(call include-dep,$(dep),$(obj),$(gen))
diff --git a/tests/cxx/tree/binary/xdr/test.xml b/tests/cxx/tree/binary/xdr/test.xml
index 928b4cf..5cedd98 100644
--- a/tests/cxx/tree/binary/xdr/test.xml
+++ b/tests/cxx/tree/binary/xdr/test.xml
@@ -1,6 +1,7 @@
<t:root xmlns:t="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="test test.xsd">
+ xsi:schemaLocation="test test.xsd"
+ any_simple_type_attr="any simple content">
<list>1 2 3</list>
@@ -87,5 +88,6 @@
<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/tests/cxx/tree/binary/xdr/test.xsd b/tests/cxx/tree/binary/xdr/test.xsd
index e593f64..0629e94 100644
--- a/tests/cxx/tree/binary/xdr/test.xsd
+++ b/tests/cxx/tree/binary/xdr/test.xsd
@@ -112,7 +112,10 @@
<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"/>
diff --git a/tests/cxx/tree/compilation/driver.cxx b/tests/cxx/tree/compilation/driver.cxx
index c396ec5..c2e6298 100644
--- a/tests/cxx/tree/compilation/driver.cxx
+++ b/tests/cxx/tree/compilation/driver.cxx
@@ -13,7 +13,7 @@
using namespace std;
using namespace test;
-template class xsd::cxx::tree::simple_type<xml_schema::type>;
+template class xsd::cxx::tree::simple_type<char, xml_schema::type>;
// String types.
//
diff --git a/tests/cxx/tree/makefile b/tests/cxx/tree/makefile
index cd081e8..7fd9f63 100644
--- a/tests/cxx/tree/makefile
+++ b/tests/cxx/tree/makefile
@@ -5,6 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
tests := \
+any-type \
built-in \
chameleon \
comparison \