aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/tree/containment/driver.cxx
blob: 5fcffbf97bff16b629c42938dfd2d714f94e7950 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// file      : tests/cxx/tree/containment/driver.cxx
// copyright : Copyright (c) 2006-2017 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

// Test tree node containment.
//

#include <memory> // std::auto_ptr/unique_ptr
#include <cassert>

#include "test.hxx"

#ifdef XSD_CXX11
#  include <utility> // std::move
#  define XSD_MOVE(x) std::move(x)
#else
#  define XSD_MOVE(x) x
#endif

using namespace std;
using namespace test;

int
main ()
{
  // Change of a container in a sub-tree without ID.
  //
  {
    XSD_AUTO_PTR<inner> i (new inner ());
    i->ref ("foo");

    outer o;
    o.i (XSD_MOVE (i));
    o.ref ("foo");

    assert (o.i ()->ref ()->get () == 0);
    assert (o.ref ()->get () == 0);
  }

  // Change of container in a sub-tree with ID inside.
  //
  {
    XSD_AUTO_PTR<inner> i (new inner ());
    inner* p (i.get ());
    i->id ("foo");
    i->ref ("foo");
    assert (i->ref ()->get () == p);

    outer o;
    o.i (XSD_MOVE (i));
    o.ref ("foo");

    assert (o.i ()->ref ()->get () == p);
    assert (o.ref ()->get () == p);
  }

  // Change of a container in ID.
  //
  {
    XSD_AUTO_PTR<xml_schema::id> id (new xml_schema::id ("foo"));

    inner i;
    i.id (XSD_MOVE (id));
    i.ref ("foo");
    assert (i.ref ()->get () == &i);
  }

  // Change of a container in a type derived from ID with ID inside.
  //
  {
    XSD_AUTO_PTR<id_ex> id (new id_ex ("foo"));
    id_ex* p (id.get ());
    id->id ("bar");

    inner i;
    i.id_ex (XSD_MOVE (id));

    i.ref ("foo");
    assert (i.ref ()->get () == &i);

    i.ref ("bar");
    assert (i.ref ()->get () == p);
  }

  // IDREF lists
  //
  {
    id i1 ("a"), i2 ("b");

    XSD_AUTO_PTR<ids> ic (new ids);
    ic->id ().push_back (i1);
    ic->id ().push_back (i2);

    XSD_AUTO_PTR<xml_schema::idrefs> r1 (new xml_schema::idrefs);
    r1->push_back (xml_schema::idref ("a"));
    r1->push_back (xml_schema::idref ("b"));

    XSD_AUTO_PTR<idref_list> r2 (new idref_list);
    r2->push_back (xml_schema::idref ("a"));
    r2->push_back (xml_schema::idref ("b"));

    XSD_AUTO_PTR<idrefs1> rc1 (new idrefs1);
    XSD_AUTO_PTR<idrefs2> rc2 (new idrefs2);

    rc1->idrefs (XSD_MOVE (r1));
    rc2->idrefs (XSD_MOVE (r2));

    model m;
    m.ids (XSD_MOVE (ic));
    m.idrefs1 (XSD_MOVE (rc1));
    m.idrefs2 (XSD_MOVE (rc2));

    assert (m.idrefs1 ().idrefs ()[0].get () != 0);
    assert (m.idrefs1 ().idrefs ()[1].get () != 0);

    assert (m.idrefs2 ().idrefs ()[0].get () != 0);
    assert (m.idrefs2 ().idrefs ()[1].get () != 0);
  }
}