summaryrefslogtreecommitdiff
path: root/xsd-tests/cxx/tree/dom-association
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-18 18:48:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-02-25 13:45:48 +0300
commit5e527213a2430bb3018e5eebd909aef294edf9b5 (patch)
tree94de33c82080b53d9a9e300170f6d221d89078f4 /xsd-tests/cxx/tree/dom-association
parent7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff)
Switch to build2
Diffstat (limited to 'xsd-tests/cxx/tree/dom-association')
-rw-r--r--xsd-tests/cxx/tree/dom-association/buildfile27
-rw-r--r--xsd-tests/cxx/tree/dom-association/dom-parse.cxx95
-rw-r--r--xsd-tests/cxx/tree/dom-association/dom-parse.hxx23
-rw-r--r--xsd-tests/cxx/tree/dom-association/driver.cxx71
-rw-r--r--xsd-tests/cxx/tree/dom-association/output0
-rw-r--r--xsd-tests/cxx/tree/dom-association/test.xml7
-rw-r--r--xsd-tests/cxx/tree/dom-association/test.xsd12
7 files changed, 235 insertions, 0 deletions
diff --git a/xsd-tests/cxx/tree/dom-association/buildfile b/xsd-tests/cxx/tree/dom-association/buildfile
new file mode 100644
index 0000000..85593e5
--- /dev/null
+++ b/xsd-tests/cxx/tree/dom-association/buildfile
@@ -0,0 +1,27 @@
+# file : cxx/tree/dom-association/buildfile
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+import libs = libxsd%lib{xsd}
+import libs += libxerces-c%lib{xerces-c}
+
+exe{driver}: {hxx cxx}{* -test} {hxx ixx cxx}{test} $libs
+
+exe{driver}: xml{test}: test.input = true
+exe{driver}: file{output}: test.stdout = true
+
+<{hxx ixx cxx}{test}>: xsd{test} $xsd
+{{
+ diag xsd ($<[0]) # @@ TMP
+
+ $xsd cxx-tree --std c++11 \
+ --generate-inline \
+ --generate-ostream \
+ --output-dir $out_base \
+ $path($<[0])
+}}
+
+cxx.poptions =+ "-I$out_base"
+
+# Define XSD_CXX11 since we include libxsd headers directly.
+#
+cxx.poptions += -DXSD_CXX11
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..281eb2c
--- /dev/null
+++ b/xsd-tests/cxx/tree/dom-association/dom-parse.cxx
@@ -0,0 +1,95 @@
+// file : cxx/tree/dom-association/dom-parse.cxx
+// 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..f14a53b
--- /dev/null
+++ b/xsd-tests/cxx/tree/dom-association/dom-parse.hxx
@@ -0,0 +1,23 @@
+// file : cxx/tree/dom-association/dom-parse.hxx
+// 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..d85e105
--- /dev/null
+++ b/xsd-tests/cxx/tree/dom-association/driver.cxx
@@ -0,0 +1,71 @@
+// file : cxx/tree/dom-association/driver.cxx
+// 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/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>