diff options
Diffstat (limited to 'xsd/tests/cxx/tree/wildcard')
-rw-r--r-- | xsd/tests/cxx/tree/wildcard/driver.cxx | 202 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/wildcard/makefile | 83 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/wildcard/output | 24 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/wildcard/test.xml | 19 | ||||
-rw-r--r-- | xsd/tests/cxx/tree/wildcard/test.xsd | 18 |
5 files changed, 346 insertions, 0 deletions
diff --git a/xsd/tests/cxx/tree/wildcard/driver.cxx b/xsd/tests/cxx/tree/wildcard/driver.cxx new file mode 100644 index 0000000..5bd8229 --- /dev/null +++ b/xsd/tests/cxx/tree/wildcard/driver.cxx @@ -0,0 +1,202 @@ +// file : tests/cxx/tree/wildcard/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test wildcard (any & anyAttribute) mapping. +// + +#include <memory> // std::auto_ptr +#include <sstream> +#include <iostream> + +#include <xsd/cxx/xml/string.hxx> + +#include "test.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 + // + 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; + + 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..b7b114f --- /dev/null +++ b/xsd/tests/cxx/tree/wildcard/makefile @@ -0,0 +1,83 @@ +# file : tests/cxx/tree/wildcard/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2006-2010 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$(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)) + +# 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,$(scf_root)/xsd/tree/xsd-cxx.make) + + +# 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> |