aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/tree/binary/polymorphic/driver.cxx
blob: 5ea1c650315e9f00f3eb21672c448c72ef47f8f3 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// file      : tests/cxx/tree/binary/polymorphic/driver.cxx
// copyright : Copyright (c) 2006-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

// Test polymorphic binary serialization.
//

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

#include <ace/Log_Msg.h>  // ACE_HEX_DUMP

#include "test.hxx"

using namespace std;
using namespace test;

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

  try
  {
    XSD_AUTO_PTR<type> r (root (argv[1]));

    // Save to a CDR stream.
    //
    ACE_OutputCDR ace_ocdr;
    xml_schema::ostream<ACE_OutputCDR> ocdr (ace_ocdr);
    ocdr << *r;

    /*
    // Print the binary representation.
    //
    cerr << "binary representation size: " << ace_ocdr.total_length () << endl;

    for (const ACE_Message_Block* mb = ace_ocdr.begin ();
         mb != 0;
         mb = mb->cont ())
    {
      ACE_HEX_DUMP ((LM_DEBUG, mb->rd_ptr (), mb->length ()));
    }
    */

    // Load from a CDR stream.
    //
    ACE_InputCDR ace_icdr (ace_ocdr);
    xml_schema::istream<ACE_InputCDR> icdr (ace_icdr);
    XSD_AUTO_PTR<type> c (new type (icdr));

    // Compare the two.
    //
    assert (r->list () == c->list ());
    assert (r->union_ () == c->union_ ());
    assert (r->enumeration () == c->enumeration ());

    {
      complex& rc (dynamic_cast<complex&> (r->base ()));
      complex& cc (dynamic_cast<complex&> (c->base ()));

      assert (rc.a () == cc.a ());
      if (rc.b ())
        assert (rc.b () == cc.b ());
      assert (rc.c () == cc.c ());

      assert (rc.x () == cc.x ());
      if (rc.y ())
        assert (rc.y () == cc.y ());
    }

    {
      complex& rc (dynamic_cast<complex&> (r->sbase ()));
      complex& cc (dynamic_cast<complex&> (c->sbase ()));

      assert (rc.a () == cc.a ());
      if (rc.b ())
        assert (rc.b () == cc.b ());
      assert (rc.c () == cc.c ());

      assert (rc.x () == cc.x ());
      if (rc.y ())
        assert (rc.y () == cc.y ());
    }

    // integers
    //
    assert (r->byte () == c->byte ());
    assert (r->unsigned_byte () == c->unsigned_byte ());
    assert (r->short_ () == c->short_ ());
    assert (r->unsigned_short () == c->unsigned_short ());
    assert (r->int_ () == c->int_ ());
    assert (r->unsigned_int () == c->unsigned_int ());
    assert (r->long_ () == c->long_ ());
    assert (r->unsigned_long () == c->unsigned_long ());
    assert (r->integer () == c->integer ());
    assert (r->non_positive_integer () == c->non_positive_integer ());
    assert (r->non_negative_integer () == c->non_negative_integer ());
    assert (r->positive_integer () == c->positive_integer ());
    assert (r->negative_integer () == c->negative_integer ());

    // boolean
    //
    assert (r->boolean () == c->boolean ());

    // floats
    //
    assert (r->float_ () == c->float_ ());
    assert (r->double_ () == c->double_ ());
    assert (r->decimal () == c->decimal ());

    // strings
    //
    assert (r->string () == c->string ());
    assert (r->normalized_string () == c->normalized_string ());
    assert (r->token () == c->token ());
    assert (r->name () == c->name ());
    assert (r->name_token () == c->name_token ());
    assert (r->name_tokens () == c->name_tokens ());
    assert (r->ncname () == c->ncname ());
    assert (r->language () == c->language ());

    // qualified name
    //
    assert (r->qname () == c->qname ());

    // ID/IDREF
    //
    assert (r->id () == c->id ());
    assert (r->id_ref () == c->id_ref ());
    assert (r->id_refs () == c->id_refs ());

    // URI
    //
    assert (r->any_uri () == c->any_uri ());

    // binary
    //
    assert (r->base64_binary () == c->base64_binary ());
    assert (r->hex_binary () == c->hex_binary ());

    // date/time
    //
    assert (r->date () == c->date ());
    assert (r->date_time () == c->date_time ());
    assert (r->duration () == c->duration ());
    assert (r->day () == c->day ());
    assert (r->month () == c->month ());
    assert (r->month_day () == c->month_day ());
    assert (r->year () == c->year ());
    assert (r->year_month () == c->year_month ());
    assert (r->time () == c->time ());
  }
  catch (xml_schema::exception const& e)
  {
    cerr << e << endl;
    return 1;
  }
}