2 #include "tao/IFR_Client/IFR_BaseC.h"
3 #include "tao/TypeCodeFactory/TypeCodeFactory_Loader.h"
7 #include "ace/OS_NS_string.h"
9 #if TAO_HAS_MINIMUM_CORBA == 0
12 recursive_union_test ()
17 "Executing recursive union test\n"));
21 "* Simple marshaling -> demarshaling\n"));
23 CORBA::Any the_any
, the_out_any
;
25 static CORBA::Short
const test_short
= 23901;
26 Test::RecursiveUnion3 foo3
;
37 if (TAO_debug_level
>= 2)
39 if (out
.length () > 512)
41 ACE_HEX_DUMP ((LM_INFO
, out
.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
42 ACE_HEX_DUMP ((LM_INFO
, out
.buffer ()+512, out
.length ()-512, ACE_TEXT ("Encoded union (2):")));
46 ACE_HEX_DUMP ((LM_INFO
, out
.buffer (), out
.length (), ACE_TEXT ("Encoded union:")));
52 if (TAO_debug_level
>= 1)
54 "> Extracting any\n"));
58 if (TAO_debug_level
>= 1)
60 "> Extracted any\n"));
62 // Any's typecode out of scope
63 if (TAO_debug_level
>= 1)
65 "> Any destructed\n"));
68 "* Marshaling -> demarshaling with external reference\n"));
70 CORBA::TypeCode_var tc
;
73 CORBA::Any the_any
, the_out_any
;
75 static CORBA::Short
const test_short
= 23901;
76 Test::RecursiveUnion3 foo3
;
87 if (TAO_debug_level
>= 2)
89 if (out
.length () > 512)
91 ACE_HEX_DUMP ((LM_INFO
, out
.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
92 ACE_HEX_DUMP ((LM_INFO
, out
.buffer ()+512, out
.length ()-512, ACE_TEXT ("Encoded union (2):")));
96 ACE_HEX_DUMP ((LM_INFO
, out
.buffer (), out
.length (), ACE_TEXT ("Encoded union:")));
100 TAO_InputCDR
in(out
);
102 if (TAO_debug_level
>= 1)
104 "> Extracting any\n"));
108 tc
= the_out_any
._tao_get_typecode ()->member_type (1); // union case type -> alias
109 tc
= tc
->content_type (); // alias content type -> sequence
110 tc
= tc
->content_type (); // sequence content type -> recursive struct
111 tc
= tc
->member_type (0); // struct member type -> union
112 tc
= tc
->member_type (1); // union case type -> alias
113 tc
= tc
->content_type (); // alias content type -> sequence
114 tc
= tc
->content_type (); // sequence content type -> indirected struct
116 if (TAO_debug_level
>= 1)
118 "> Extracted any and stored external reference to Indirected_Type typecode\n"));
120 // Any's typecode out of scope
121 if (TAO_debug_level
>= 1)
123 "> Any destructed\n"));
125 // referenced recursive typecode out of scope
126 // Any's typecode out of scope
127 if (TAO_debug_level
>= 1)
129 "> External Indirected_Type typecode reference destructed\n"));
133 "* Marshaling -> demarshaling -> marshaling -> demarshaling\n"));
135 CORBA::Any the_any
, the_out_any
, the_out_any2
;
137 static CORBA::Short
const test_short
= 23901;
138 Test::RecursiveUnion3 foo3
;
149 if (TAO_debug_level
>= 2)
151 if (out
.length () > 512)
153 ACE_HEX_DUMP ((LM_INFO
, out
.buffer (), 512, ACE_TEXT ("Encoded union (1):")));
154 ACE_HEX_DUMP ((LM_INFO
, out
.buffer ()+512, out
.length ()-512, ACE_TEXT ("Encoded union (2):")));
158 ACE_HEX_DUMP ((LM_INFO
, out
.buffer (), out
.length (), ACE_TEXT ("Encoded union:")));
162 TAO_InputCDR
in(out
);
164 if (TAO_debug_level
>= 1)
166 "> Extracting any\n"));
170 if (TAO_debug_level
>= 1)
172 "> Extracted any\n"));
180 if (TAO_debug_level
>= 2)
182 if (out2
.length () > 512)
184 ACE_HEX_DUMP ((LM_INFO
, out2
.buffer (), 512, ACE_TEXT ("Re-encoded union (1):")));
185 ACE_HEX_DUMP ((LM_INFO
, out2
.buffer ()+512, out2
.length ()-512, ACE_TEXT ("Re-encoded union (2):")));
189 ACE_HEX_DUMP ((LM_INFO
, out2
.buffer (), out2
.length (), ACE_TEXT ("Re-encoded union:")));
193 // Unfortunately this test in unreliable due to the memory management optimizations of ACE, particularly
194 // concerning the non-initialization of allocated memory. When running with Valgrind all memory is forcibly
195 // initialized to 0 and than this test passes.
197 // if (out.length () != out2.length () || ACE_OS::memcmp (out.buffer (), out2.buffer (), out.length ()) != 0)
199 // ACE_ERROR ((LM_ERROR,
200 // "encoded representations of recursive typecodes differ\n"));
205 TAO_InputCDR
in2(out2
);
207 if (TAO_debug_level
>= 1)
209 "> Re-extracting any\n"));
213 if (TAO_debug_level
>= 1)
215 "> Re-extracted any\n"));
217 if (!the_out_any
._tao_get_typecode ()->equal (the_out_any2
._tao_get_typecode ()))
219 ACE_ERROR ((LM_ERROR
,
220 "extracted recursive typecodes differ\n"));
224 // Any's typecodes out of scope
225 if (TAO_debug_level
>= 1)
227 "> Anys destructed\n"));
233 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
238 CORBA::ORB_init (argc
, argv
);
240 recursive_union_test ();
244 catch (const CORBA::Exception
& ex
)
246 ex
._tao_print_exception ("Exception caught:");
256 ACE_TMAIN(int , ACE_TCHAR
*[])
261 #endif /* TAO_HAS_MINIMUM_CORBA != 0 */