Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Any / Indirected / client.cpp
blob6adaee0394ae28334c4f49aba57826e241fb5709
1 #include "testC.h"
2 #include "tao/IFR_Client/IFR_BaseC.h"
3 #include "tao/TypeCodeFactory/TypeCodeFactory_Loader.h"
4 #include "tao/CDR.h"
5 #include "tao/debug.h"
7 #include "ace/OS_NS_string.h"
9 #if TAO_HAS_MINIMUM_CORBA == 0
11 bool
12 recursive_union_test ()
14 bool rc = true;
16 ACE_DEBUG ((LM_INFO,
17 "Executing recursive union test\n"));
20 ACE_DEBUG ((LM_INFO,
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;
27 foo3.a (test_short);
29 the_any <<= foo3;
31 TAO_OutputCDR out;
33 out << the_any;
35 out.consolidate ();
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):")));
44 else
46 ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:")));
50 TAO_InputCDR in(out);
52 if (TAO_debug_level >= 1)
53 ACE_DEBUG ((LM_INFO,
54 "> Extracting any\n"));
56 in >> the_out_any;
58 if (TAO_debug_level >= 1)
59 ACE_DEBUG ((LM_INFO,
60 "> Extracted any\n"));
62 // Any's typecode out of scope
63 if (TAO_debug_level >= 1)
64 ACE_DEBUG ((LM_INFO,
65 "> Any destructed\n"));
67 ACE_DEBUG ((LM_INFO,
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;
77 foo3.a (test_short);
79 the_any <<= foo3;
81 TAO_OutputCDR out;
83 out << the_any;
85 out.consolidate ();
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):")));
94 else
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)
103 ACE_DEBUG ((LM_INFO,
104 "> Extracting any\n"));
106 in >> the_out_any;
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)
117 ACE_DEBUG ((LM_INFO,
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)
122 ACE_DEBUG ((LM_INFO,
123 "> Any destructed\n"));
125 // referenced recursive typecode out of scope
126 // Any's typecode out of scope
127 if (TAO_debug_level >= 1)
128 ACE_DEBUG ((LM_INFO,
129 "> External Indirected_Type typecode reference destructed\n"));
132 ACE_DEBUG ((LM_INFO,
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;
139 foo3.a (test_short);
141 the_any <<= foo3;
143 TAO_OutputCDR out;
145 out << the_any;
147 out.consolidate ();
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):")));
156 else
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)
165 ACE_DEBUG ((LM_INFO,
166 "> Extracting any\n"));
168 in >> the_out_any;
170 if (TAO_debug_level >= 1)
171 ACE_DEBUG ((LM_INFO,
172 "> Extracted any\n"));
174 TAO_OutputCDR out2;
176 out2 << the_out_any;
178 out2.consolidate ();
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):")));
187 else
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)
198 // {
199 // ACE_ERROR ((LM_ERROR,
200 // "encoded representations of recursive typecodes differ\n"));
202 // rc = false;
203 // }
205 TAO_InputCDR in2(out2);
207 if (TAO_debug_level >= 1)
208 ACE_DEBUG ((LM_INFO,
209 "> Re-extracting any\n"));
211 in2 >> the_out_any2;
213 if (TAO_debug_level >= 1)
214 ACE_DEBUG ((LM_INFO,
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"));
221 rc = false;
224 // Any's typecodes out of scope
225 if (TAO_debug_level >= 1)
226 ACE_DEBUG ((LM_INFO,
227 "> Anys destructed\n"));
229 return rc;
233 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
237 CORBA::ORB_var orb =
238 CORBA::ORB_init (argc, argv);
240 recursive_union_test ();
242 orb->destroy ();
244 catch (const CORBA::Exception& ex)
246 ex._tao_print_exception ("Exception caught:");
247 return 1;
250 return 0;
253 #else
256 ACE_TMAIN(int , ACE_TCHAR *[])
258 return 0;
261 #endif /* TAO_HAS_MINIMUM_CORBA != 0 */