summaryrefslogtreecommitdiff
path: root/TAO/tests/Any/Indirected/client.cpp
blob: 6adaee0394ae28334c4f49aba57826e241fb5709 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#include "testC.h"
#include "tao/IFR_Client/IFR_BaseC.h"
#include "tao/TypeCodeFactory/TypeCodeFactory_Loader.h"
#include "tao/CDR.h"
#include "tao/debug.h"

#include "ace/OS_NS_string.h"

#if TAO_HAS_MINIMUM_CORBA == 0

bool
recursive_union_test ()
{
  bool rc = true;

  ACE_DEBUG ((LM_INFO,
              "Executing recursive union test\n"));


  ACE_DEBUG ((LM_INFO,
              "* Simple marshaling -> demarshaling\n"));
  {
    CORBA::Any the_any, the_out_any;

    static CORBA::Short const test_short = 23901;
    Test::RecursiveUnion3 foo3;
    foo3.a (test_short);

    the_any <<= foo3;

    TAO_OutputCDR out;

    out << the_any;

    out.consolidate ();

    if (TAO_debug_level >= 2)
    {
      if (out.length () > 512)
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
        ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):")));
      }
      else
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:")));
      }
    }

    TAO_InputCDR in(out);

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracting any\n"));

    in >> the_out_any;

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracted any\n"));
  }
  // Any's typecode out of scope
  if (TAO_debug_level >= 1)
    ACE_DEBUG ((LM_INFO,
                "> Any destructed\n"));

  ACE_DEBUG ((LM_INFO,
              "* Marshaling -> demarshaling with external reference\n"));
  {
    CORBA::TypeCode_var tc;

    {
      CORBA::Any the_any, the_out_any;

      static CORBA::Short const test_short = 23901;
      Test::RecursiveUnion3 foo3;
      foo3.a (test_short);

      the_any <<= foo3;

      TAO_OutputCDR out;

      out << the_any;

      out.consolidate ();

      if (TAO_debug_level >= 2)
      {
        if (out.length () > 512)
        {
          ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
          ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):")));
        }
        else
        {
          ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:")));
        }
      }

      TAO_InputCDR in(out);

      if (TAO_debug_level >= 1)
        ACE_DEBUG ((LM_INFO,
                    "> Extracting any\n"));

      in >> the_out_any;

      tc = the_out_any._tao_get_typecode ()->member_type (1); // union case type -> alias
      tc = tc->content_type (); // alias content type -> sequence
      tc = tc->content_type (); // sequence content type -> recursive struct
      tc = tc->member_type (0); // struct member type -> union
      tc = tc->member_type (1); // union case type -> alias
      tc = tc->content_type (); // alias content type -> sequence
      tc = tc->content_type (); // sequence content type -> indirected struct

      if (TAO_debug_level >= 1)
        ACE_DEBUG ((LM_INFO,
                    "> Extracted any and stored external reference to Indirected_Type typecode\n"));
    }
    // Any's typecode out of scope
    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Any destructed\n"));
  }
  // referenced recursive typecode out of scope
  // Any's typecode out of scope
  if (TAO_debug_level >= 1)
    ACE_DEBUG ((LM_INFO,
                "> External Indirected_Type typecode reference destructed\n"));


  ACE_DEBUG ((LM_INFO,
              "* Marshaling -> demarshaling -> marshaling -> demarshaling\n"));
  {
    CORBA::Any the_any, the_out_any, the_out_any2;

    static CORBA::Short const test_short = 23901;
    Test::RecursiveUnion3 foo3;
    foo3.a (test_short);

    the_any <<= foo3;

    TAO_OutputCDR out;

    out << the_any;

    out.consolidate ();

    if (TAO_debug_level >= 2)
    {
      if (out.length () > 512)
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
        ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):")));
      }
      else
      {
        ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:")));
      }
    }

    TAO_InputCDR in(out);

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracting any\n"));

    in >> the_out_any;

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Extracted any\n"));

    TAO_OutputCDR out2;

    out2 << the_out_any;

    out2.consolidate ();

    if (TAO_debug_level >= 2)
    {
      if (out2.length () > 512)
      {
        ACE_HEX_DUMP ((LM_INFO, out2.buffer (), 512, ACE_TEXT ("Re-encoded union (1):")));
        ACE_HEX_DUMP ((LM_INFO, out2.buffer ()+512, out2.length ()-512, ACE_TEXT ("Re-encoded union (2):")));
      }
      else
      {
        ACE_HEX_DUMP ((LM_INFO, out2.buffer (), out2.length (), ACE_TEXT ("Re-encoded union:")));
      }
    }

// Unfortunately this test in unreliable due to the memory management optimizations of ACE, particularly
// concerning the non-initialization of allocated memory. When running with Valgrind all memory is forcibly
// initialized to 0 and than this test passes.
//
//    if (out.length () != out2.length () || ACE_OS::memcmp (out.buffer (), out2.buffer (), out.length ()) != 0)
//    {
//      ACE_ERROR ((LM_ERROR,
//                  "encoded representations of recursive typecodes differ\n"));
//
//      rc = false;
//    }

    TAO_InputCDR in2(out2);

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Re-extracting any\n"));

    in2 >> the_out_any2;

    if (TAO_debug_level >= 1)
      ACE_DEBUG ((LM_INFO,
                  "> Re-extracted any\n"));

    if (!the_out_any._tao_get_typecode ()->equal (the_out_any2._tao_get_typecode ()))
    {
      ACE_ERROR ((LM_ERROR,
                  "extracted recursive typecodes differ\n"));
      rc = false;
    }
  }
  // Any's typecodes out of scope
  if (TAO_debug_level >= 1)
    ACE_DEBUG ((LM_INFO,
                "> Anys destructed\n"));

  return rc;
}

int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      recursive_union_test ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}

#else

int
ACE_TMAIN(int , ACE_TCHAR *[])
{
  return 0;
}

#endif  /* TAO_HAS_MINIMUM_CORBA != 0 */