aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/tree/built-in/driver.cxx
blob: 7cb8d0f4ef63210ac62999f06a1499f2ac000102 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// file      : tests/cxx/tree/built-in/driver.cxx
// copyright : Copyright (c) 2005-2017 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

// Test built-in type mapping.
//

#include <memory>  // std::auto_ptr/unique_ptr
#include <sstream>
#include <iostream>


#include "types.hxx"

using std::cerr;
using std::endl;

int
main (int argc, char* argv[])
{
  if (argc != 4)
  {
    cerr << "usage: " << argv[0] << " elements.xml attributes.xml inherited.xml" << endl;
    return 1;
  }

  XSD_AUTO_PTR<xmlns::test::Elements> elements (
    xmlns::test::elements (argv[1]));

  XSD_AUTO_PTR<xmlns::test::Attributes> attributes (
    xmlns::test::attributes (argv[2]));

  XSD_AUTO_PTR<xmlns::test::Inherited> inherited (
    xmlns::test::inherited (argv[3]));

  cerr << "elements: " << *elements << endl
       << endl
       << "attributes: " << *attributes << endl
       << endl
       << "inherited: " << *inherited << endl;

  // Test parsing/serialization.
  //

  xml_schema::namespace_infomap map;

  map["test"].name = "http://www.codesynthesis.com/xmlns/test";
  map["test"].schema = "types.xsd";

  {
    std::ostringstream ostr;
    xmlns::test::elements (ostr, *elements, map);

    std::istringstream istr (ostr.str ());
    XSD_AUTO_PTR<xmlns::test::Elements> elements1 (
      xmlns::test::elements (istr));

    std::ostringstream ostr1;
    xmlns::test::elements (ostr1, *elements1, map);

    if (ostr.str () != ostr1.str ())
      return 1;
  }

  {
    std::ostringstream ostr;
    xmlns::test::attributes (ostr, *attributes, map);

    std::istringstream istr (ostr.str ());
    XSD_AUTO_PTR<xmlns::test::Attributes> attributes1 (
      xmlns::test::attributes (istr));

    std::ostringstream ostr1;
    xmlns::test::attributes (ostr1, *attributes1, map);

    if (ostr.str () != ostr1.str ())
      return 1;
  }

  {
    std::ostringstream ostr;
    xmlns::test::inherited (ostr, *inherited, map);

    std::istringstream istr (ostr.str ());
    XSD_AUTO_PTR<xmlns::test::Inherited> inherited1 (
      xmlns::test::inherited (istr));

    std::ostringstream ostr1;
    xmlns::test::inherited (ostr1, *inherited1, map);

    if (ostr.str () != ostr1.str ())
      return 1;
  }
}