summaryrefslogtreecommitdiff
path: root/tests/cxx/tree/any-type
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/cxx/tree/any-type
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/cxx/tree/any-type')
-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
5 files changed, 350 insertions, 0 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>