From a8ce5c380c69539fe0c7c62c397634d9d0c9fde2 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- xsd-tests/cxx/tree/dom-association/buildfile | 27 +++++++ xsd-tests/cxx/tree/dom-association/dom-parse.cxx | 95 ++++++++++++++++++++++++ xsd-tests/cxx/tree/dom-association/dom-parse.hxx | 23 ++++++ xsd-tests/cxx/tree/dom-association/driver.cxx | 71 ++++++++++++++++++ xsd-tests/cxx/tree/dom-association/output | 0 xsd-tests/cxx/tree/dom-association/test.xml | 7 ++ xsd-tests/cxx/tree/dom-association/test.xsd | 12 +++ 7 files changed, 235 insertions(+) create mode 100644 xsd-tests/cxx/tree/dom-association/buildfile create mode 100644 xsd-tests/cxx/tree/dom-association/dom-parse.cxx create mode 100644 xsd-tests/cxx/tree/dom-association/dom-parse.hxx create mode 100644 xsd-tests/cxx/tree/dom-association/driver.cxx create mode 100644 xsd-tests/cxx/tree/dom-association/output create mode 100644 xsd-tests/cxx/tree/dom-association/test.xml create mode 100644 xsd-tests/cxx/tree/dom-association/test.xsd (limited to 'xsd-tests/cxx/tree/dom-association') 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 + +#include +#include // chLatin_* +#include + +#include +#include + +#include +#include + +using namespace xercesc; +namespace xml = xsd::cxx::xml; +namespace tree = xsd::cxx::tree; + +XSD_DOM_AUTO_PTR +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 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 eh; + xml::dom::bits::error_handler_proxy 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 doc (parser->parse (&wrap)); + + eh.throw_if_failed > (); + + 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 +#include + +#include + +#include + +// 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 +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 // std::auto_ptr/unique_ptr +#include +#include + +#include + +#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 doc (parse (ifs, argv[1], true)); + ptr = doc.get (); + unique_ptr r ( + root (std::move (doc), + xml_schema::flags::keep_dom | xml_schema::flags::own_dom)); +#else + xml_schema::dom::auto_ptr doc (parse (ifs, argv[1], true)); + ptr = doc.get (); + auto_ptr 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 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 @@ + + + a + + 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 @@ + + + + + + + + + + + + -- cgit v1.1