Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / DynAny_Test / test_dynany.cpp
blob4bed14fab5b385f6b0ebbd6f2b664811b1fa1b52
1 //=============================================================================
2 /**
3 * @file test_dynany.cpp
5 * Implementation of the basic test for simple DynAnys
7 * @author Jeff Parsons <parsons@cs.wustl.edu>
8 */
9 //=============================================================================
11 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
12 #include "tao/AnyTypeCode/ShortSeqA.h"
13 #include "tao/DynamicAny/DynamicAny.h"
15 #include "test_dynany.h"
16 #include "data.h"
17 #include "analyzer.h"
19 Test_DynAny::Test_DynAny (CORBA::ORB_var orb, int debug)
20 : orb_ (orb),
21 test_name_ (CORBA::string_dup ("test_dynany")),
22 error_count_ (0),
23 debug_ (debug)
27 Test_DynAny::~Test_DynAny ()
29 CORBA::string_free (this->test_name_);
30 this->test_name_ = 0;
33 const char*
34 Test_DynAny::test_name () const
36 return this->test_name_;
39 int
40 Test_DynAny::run_test ()
42 Data data (this->orb_);
44 try
46 CORBA::Object_var factory_obj =
47 this->orb_->resolve_initial_references ("DynAnyFactory");
49 DynamicAny::DynAnyFactory_var dynany_factory =
50 DynamicAny::DynAnyFactory::_narrow (factory_obj.in ());
52 if (CORBA::is_nil (dynany_factory.in ()))
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "Nil dynamic any factory after narrow\n"),
56 -1);
59 DynAnyAnalyzer analyzer (this->orb_.in (),
60 dynany_factory.in (),
61 debug_);
63 ACE_DEBUG ((LM_DEBUG,
64 "\t*=*=*=*= %C =*=*=*=*\n",
65 data.labels[8]));
67 ACE_DEBUG ((LM_DEBUG,
68 "testing: constructor(Any)/insert/get\n"));
70 CORBA::Any in1;
71 in1 <<= data.m_double2;
72 DynamicAny::DynAny_var fa1 =
73 dynany_factory->create_dyn_any (in1);
75 if (fa1->equal(fa1.in ()))
77 ACE_DEBUG ((LM_DEBUG,
78 "++ OK ++\n"));
80 else
82 ACE_DEBUG ((LM_DEBUG,
83 "Double Not equal\n"));
84 ++this->error_count_;
86 fa1->insert_double (data.m_double1);
88 CORBA::Double d_out =
89 fa1->get_double ();
91 if (ACE::is_equal (d_out, data.m_double1))
93 ACE_DEBUG ((LM_DEBUG,
94 "++ OK ++\n"));
96 else
98 ++this->error_count_;
101 ACE_DEBUG ((LM_DEBUG,
102 "testing: constructor(TypeCode)/from_any/to_any\n"));
104 d_out = data.m_double2;
105 DynamicAny::DynAny_var ftc1 =
106 dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_double);
107 CORBA::Any in_any1;
108 in_any1 <<= data.m_double1;
109 ftc1->from_any (in_any1);
110 analyzer.analyze (ftc1.in());
111 CORBA::Any_var out_any1 = ftc1->to_any ();
112 out_any1 >>= d_out;
114 if (ACE::is_equal (d_out, data.m_double1))
116 ACE_DEBUG ((LM_DEBUG,
117 "++ OK ++\n"));
119 else
121 ++this->error_count_;
124 fa1->destroy ();
125 ftc1->destroy ();
129 ACE_DEBUG ((LM_DEBUG,
130 "\t*=*=*=*= %C =*=*=*=*\n",
131 data.labels[17]));
133 ACE_DEBUG ((LM_DEBUG,
134 "testing: constructor(Any)/insert/get\n"));
136 CORBA::Any in1;
137 in1 <<= data.m_longdouble2;
138 DynamicAny::DynAny_var fa1 =
139 dynany_factory->create_dyn_any (in1);
141 if (fa1->equal(fa1.in ()))
143 ACE_DEBUG ((LM_DEBUG,
144 "++ OK ++\n"));
146 else
148 ACE_DEBUG ((LM_DEBUG,
149 "Long Double Not equal\n"));
150 ++this->error_count_;
153 fa1->insert_longdouble (data.m_longdouble1);
155 CORBA::LongDouble d_out = fa1->get_longdouble ();
157 if (ACE::is_equal (d_out, data.m_longdouble1))
159 ACE_DEBUG ((LM_DEBUG,
160 "++ OK ++\n"));
162 else
164 ++this->error_count_;
167 ACE_DEBUG ((LM_DEBUG,
168 "testing: constructor(TypeCode)/from_any/to_any\n"));
170 d_out = data.m_longdouble2;
171 DynamicAny::DynAny_var ftc1 =
172 dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_longdouble);
174 CORBA::Any in_any1;
175 in_any1 <<= data.m_longdouble1;
176 ftc1->from_any (in_any1);
178 analyzer.analyze(ftc1.in());
180 CORBA::Any_var out_any1 = ftc1->to_any ();
182 out_any1.in() >>= d_out;
184 if (ACE::is_equal (d_out, data.m_longdouble1))
186 ACE_DEBUG ((LM_DEBUG,
187 "++ OK ++\n"));
189 else
191 ++this->error_count_;
194 fa1->destroy ();
195 ftc1->destroy ();
198 ACE_DEBUG ((LM_DEBUG,
199 "\t*=*=*=*= %C =*=*=*=*\n",
200 data.labels[12]));
202 ACE_DEBUG ((LM_DEBUG,
203 "testing: constructor(Any)/insert/get\n"));
205 CORBA::Any in;
206 in <<= data.m_typecode2;
207 DynamicAny::DynAny_var fa2 =
208 dynany_factory->create_dyn_any (in);
209 fa2->insert_typecode (data.m_typecode1);
210 CORBA::TypeCode_var tc_out =
211 fa2->get_typecode ();
213 if (tc_out->equal (data.m_typecode1))
215 ACE_DEBUG ((LM_DEBUG,
216 "++ OK ++\n"));
218 else
220 ++this->error_count_;
224 ACE_DEBUG ((LM_DEBUG,
225 "testing: constructor(TypeCode)/from_any/to_any\n"));
227 DynamicAny::DynAny_var ftc2 =
228 dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_TypeCode);
229 CORBA::Any in_any2;
230 in_any2 <<= data.m_typecode1;
231 ftc2->from_any (in_any2);
232 analyzer.analyze (ftc2.in());
233 CORBA::Any_var out_any2 = ftc2->to_any ();
234 CORBA::TypeCode_ptr out_tc;
235 out_any2 >>= out_tc;
237 CORBA::Boolean equal = out_tc->equal (data.m_typecode1);
239 if (equal)
241 ACE_DEBUG ((LM_DEBUG,
242 "++ OK ++\n"));
244 else
246 ++this->error_count_;
250 fa2->destroy ();
251 ftc2->destroy ();
253 ACE_DEBUG ((LM_DEBUG,
254 "\t*=*=*=*= %C =*=*=*=*\n",
255 data.labels[16]));
257 ACE_DEBUG ((LM_DEBUG,
258 "testing: constructor(Any)/insert/get\n"));
260 CORBA::Any in3;
261 CORBA::ShortSeq ss;
262 ss.length (0UL);
263 in3 <<= ss;
264 DynamicAny::DynAny_var fa3 =
265 dynany_factory->create_dyn_any (in3);
266 fa3->insert_short_seq (data.m_shortseq1);
267 data.m_shortseq2 =
268 fa3->get_short_seq ();
270 bool good =
271 data.m_shortseq2->length () == data.m_shortseq1.length ();
273 if (good)
275 for (CORBA::ULong i = 0; i < data.m_shortseq1.length (); ++i)
277 if (data.m_shortseq2[i] != data.m_shortseq1[i])
279 good = false;
280 break;
285 if (good)
287 ACE_DEBUG ((LM_DEBUG,
288 "++ OK ++\n"));
290 else
292 ++this->error_count_;
296 ACE_DEBUG ((LM_DEBUG,
297 "testing: constructor(TypeCode)/from_any/to_any\n"));
299 DynamicAny::DynAny_var ftc3 =
300 dynany_factory->create_dyn_any_from_type_code (CORBA::_tc_ShortSeq);
301 CORBA::Any in_any3;
302 in_any3 <<= data.m_shortseq1;
303 ftc3->from_any (in_any3);
304 analyzer.analyze (ftc3.in ());
305 CORBA::Any_var out_any3 = ftc3->to_any ();
307 const CORBA::ShortSeq *outseq = 0;
308 out_any3.in () >>= outseq;
310 good =
311 outseq->length () == data.m_shortseq1.length ();
313 if (good)
315 for (CORBA::ULong i = 0; i < data.m_shortseq1.length (); ++i)
317 if ((*outseq)[i] != data.m_shortseq1[i])
319 good = false;
320 break;
325 if (good)
327 ACE_DEBUG ((LM_DEBUG,
328 "++ OK ++\n"));
330 else
332 ++this->error_count_;
335 fa3->destroy ();
336 ftc3->destroy ();
338 ACE_DEBUG ((LM_DEBUG,
339 "testing: equal\n"));
341 // Simple equal to self test for basic sequence
342 // Check equal to self, not equal for different length
343 // not equal for different values
344 CORBA::Any in4;
345 in4 <<= data.m_shortseq1;
346 DynamicAny::DynAny_var fa4 =
347 dynany_factory->create_dyn_any (in4);
349 // is equal to self
350 good = fa4->equal(fa4.in ());
352 CORBA::ShortSeq ss5;
353 ss5.length(1);
354 ss5[0] = 5;
355 CORBA::Any in5;
356 in5 <<= ss5;
357 DynamicAny::DynAny_var fa5 =
358 dynany_factory->create_dyn_any (in5);
360 // is not equal for different lengths
361 good = good && !fa4->equal(fa5.in ());
363 CORBA::ShortSeq ss6(data.m_shortseq1);
364 ss6[0]++;
365 CORBA::Any in6;
366 in6 <<= ss6;
368 DynamicAny::DynAny_var fa6 =
369 dynany_factory->create_dyn_any (in6);
371 // is not equal for different values
372 good = good && !fa4->equal(fa6.in ());
375 CORBA::Any in7;
376 in7 <<= data.m_shortseq1;
377 DynamicAny::DynAny_var fa7 =
378 dynany_factory->create_dyn_any (in7);
381 // is equal to identical sequence, not self
382 good = good && fa4->equal(fa7.in ());
385 if (good)
387 ACE_DEBUG ((LM_DEBUG,
388 "++ OK ++\n"));
390 else
392 ++this->error_count_;
396 catch (const CORBA::Exception& ex)
398 ex._tao_print_exception ("test_dynany::run_test");
399 ++this->error_count_;
402 ACE_DEBUG ((LM_DEBUG,
403 "\n%d errors\n",
404 this->error_count_));
406 return error_count_;