1 //=============================================================================
3 * @file test_dynany.cpp
5 * Implementation of the basic test for simple DynAnys
7 * @author Jeff Parsons <parsons@cs.wustl.edu>
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"
19 Test_DynAny::Test_DynAny (CORBA::ORB_var orb
, int debug
)
21 test_name_ (CORBA::string_dup ("test_dynany")),
27 Test_DynAny::~Test_DynAny ()
29 CORBA::string_free (this->test_name_
);
34 Test_DynAny::test_name () const
36 return this->test_name_
;
40 Test_DynAny::run_test ()
42 Data
data (this->orb_
);
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"),
59 DynAnyAnalyzer
analyzer (this->orb_
.in (),
64 "\t*=*=*=*= %C =*=*=*=*\n",
68 "testing: constructor(Any)/insert/get\n"));
71 in1
<<= data
.m_double2
;
72 DynamicAny::DynAny_var fa1
=
73 dynany_factory
->create_dyn_any (in1
);
75 if (fa1
->equal(fa1
.in ()))
83 "Double Not equal\n"));
86 fa1
->insert_double (data
.m_double1
);
91 if (ACE::is_equal (d_out
, data
.m_double1
))
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
);
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 ();
114 if (ACE::is_equal (d_out
, data
.m_double1
))
116 ACE_DEBUG ((LM_DEBUG
,
121 ++this->error_count_
;
129 ACE_DEBUG ((LM_DEBUG
,
130 "\t*=*=*=*= %C =*=*=*=*\n",
133 ACE_DEBUG ((LM_DEBUG
,
134 "testing: constructor(Any)/insert/get\n"));
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
,
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
,
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
);
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
,
191 ++this->error_count_
;
198 ACE_DEBUG ((LM_DEBUG
,
199 "\t*=*=*=*= %C =*=*=*=*\n",
202 ACE_DEBUG ((LM_DEBUG
,
203 "testing: constructor(Any)/insert/get\n"));
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
,
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
);
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
;
237 CORBA::Boolean equal
= out_tc
->equal (data
.m_typecode1
);
241 ACE_DEBUG ((LM_DEBUG
,
246 ++this->error_count_
;
253 ACE_DEBUG ((LM_DEBUG
,
254 "\t*=*=*=*= %C =*=*=*=*\n",
257 ACE_DEBUG ((LM_DEBUG
,
258 "testing: constructor(Any)/insert/get\n"));
264 DynamicAny::DynAny_var fa3
=
265 dynany_factory
->create_dyn_any (in3
);
266 fa3
->insert_short_seq (data
.m_shortseq1
);
268 fa3
->get_short_seq ();
271 data
.m_shortseq2
->length () == data
.m_shortseq1
.length ();
275 for (CORBA::ULong i
= 0; i
< data
.m_shortseq1
.length (); ++i
)
277 if (data
.m_shortseq2
[i
] != data
.m_shortseq1
[i
])
287 ACE_DEBUG ((LM_DEBUG
,
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
);
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
;
311 outseq
->length () == data
.m_shortseq1
.length ();
315 for (CORBA::ULong i
= 0; i
< data
.m_shortseq1
.length (); ++i
)
317 if ((*outseq
)[i
] != data
.m_shortseq1
[i
])
327 ACE_DEBUG ((LM_DEBUG
,
332 ++this->error_count_
;
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
345 in4
<<= data
.m_shortseq1
;
346 DynamicAny::DynAny_var fa4
=
347 dynany_factory
->create_dyn_any (in4
);
350 good
= fa4
->equal(fa4
.in ());
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
);
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 ());
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 ());
387 ACE_DEBUG ((LM_DEBUG
,
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
,
404 this->error_count_
));