summaryrefslogtreecommitdiff
path: root/xsd-tests/cxx/tree/dom-association/driver.cxx
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/driver.cxx
parent7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff)
Switch to build2
Diffstat (limited to 'xsd-tests/cxx/tree/dom-association/driver.cxx')
-rw-r--r--xsd-tests/cxx/tree/dom-association/driver.cxx71
1 files changed, 71 insertions, 0 deletions
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;
+}