summaryrefslogtreecommitdiff
path: root/xsd-tests/cxx/tree/dom-association/driver.cxx
blob: d85e10593cad17ff607a8bcbbb2e14a1c0a43a4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;
}