1 //=============================================================================
3 * @file test_dynstruct.cpp
5 * Implementation of the DynStruct basic test
7 * @author Jeff Parsons <parsons@cs.wustl.edu>
9 //=============================================================================
12 #include "test_dynstruct.h"
13 #include "da_testsC.h"
15 #include "tao/DynamicAny/DynamicAny.h"
17 #include "ace/OS_NS_string.h"
19 Test_DynStruct::Test_DynStruct (CORBA::ORB_var orb
, int debug
)
21 test_name_ (CORBA::string_dup ("test_dynstruct")),
27 Test_DynStruct::~Test_DynStruct (void)
29 CORBA::string_free (this->test_name_
);
34 Test_DynStruct::test_name (void) const
36 return this->test_name_
;
40 Test_DynStruct::run_test (void)
42 Data
data (this->orb_
);
44 DynAnyTests::test_struct ts
;
47 ts
.es
.f
= data
.m_float2
;
48 ts
.es
.s
= data
.m_short2
;
53 "testing: constructor(Any)/insert/get/next/seek/"
54 "rewind/current_component\n"));
56 CORBA::Object_var factory_obj
=
57 this->orb_
->resolve_initial_references ("DynAnyFactory");
59 DynamicAny::DynAnyFactory_var dynany_factory
=
60 DynamicAny::DynAnyFactory::_narrow (factory_obj
.in ());
62 if (CORBA::is_nil (dynany_factory
.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR
,
65 "Nil dynamic any factory after narrow\n"),
69 DynAnyAnalyzer
analyzer (this->orb_
.in (),
75 DynamicAny::DynAny_var dp1
=
76 dynany_factory
->create_dyn_any (in_any1
);
78 DynamicAny::DynStruct_var fa1
=
79 DynamicAny::DynStruct::_narrow (dp1
.in ());
81 fa1
->insert_char (data
.m_char1
);
85 fa1
->insert_short_seq (data
.m_shortseq1
);
89 DynamicAny::DynAny_var cc
=
90 fa1
->current_component ();
92 cc
->insert_float (data
.m_float1
);
96 cc
->insert_short (data
.m_short1
);
99 // To show that calling destroy() on a component does
100 // nothing, as required by the spec.
105 CORBA::Char c
= fa1
->get_char ();
107 if (c
!= data
.m_char1
)
109 ++this->error_count_
;
115 fa1
->get_short_seq ();
118 data
.m_shortseq2
->length () == data
.m_shortseq1
.length ();
122 for (CORBA::ULong i
= 0; i
< data
.m_shortseq1
.length (); ++i
)
124 if (data
.m_shortseq2
[i
] != data
.m_shortseq1
[i
])
126 ++this->error_count_
;
133 ++this->error_count_
;
138 cc
= fa1
->current_component ();
142 CORBA::Short s
= cc
->get_short ();
144 if (s
!= data
.m_short1
)
146 ++this->error_count_
;
149 if (this->error_count_
== 0)
151 ACE_DEBUG ((LM_DEBUG
,
155 ACE_DEBUG ((LM_DEBUG
,
156 "testing: constructor(TypeCode)/from_any/to_any\n"));
158 DynamicAny::DynAny_var ftc1_base
=
159 dynany_factory
->create_dyn_any_from_type_code (DynAnyTests::_tc_test_struct
);
161 DynamicAny::DynStruct_var ftc1
=
162 DynamicAny::DynStruct::_narrow (ftc1_base
.in ());
164 if (CORBA::is_nil (ftc1
.in ()))
166 ACE_ERROR_RETURN ((LM_ERROR
,
167 "DynStruct::_narrow() returned nil\n"),
173 ts
.es
.f
= data
.m_float1
;
174 ts
.es
.s
= data
.m_short1
;
177 ftc1
->from_any (in_any2
);
179 analyzer
.analyze (ftc1
.in ());
181 CORBA::Any_var out_any1
=
184 const DynAnyTests::test_struct
* ts_out
= 0;
185 out_any1
.in () >>= ts_out
;
187 if (ts_out
->es
.s
== data
.m_short1
)
189 ACE_DEBUG ((LM_DEBUG
,
194 ++this->error_count_
;
197 ACE_DEBUG ((LM_DEBUG
,
198 "testing: constructor(TypeCode alias)/from_any/to_any\n"));
201 const DynAnyTests::test_struct
*ts_out2
= 0;
202 CORBA::Any_var out_any2
;
203 DynamicAny::DynStruct_var ftc2
;
207 DynamicAny::DynAny_var ftc2_base
=
208 dynany_factory
->create_dyn_any_from_type_code (
209 DynAnyTests::_tc_test_struct_alias
212 ftc2
= DynamicAny::DynStruct::_narrow (ftc2_base
.in ());
214 if (CORBA::is_nil (ftc2
.in ()))
216 ACE_ERROR_RETURN ((LM_ERROR
,
217 "DynStruct::_narrow() returned nil\n"),
223 ts
.es
.f
= data
.m_float1
;
224 ts
.es
.s
= data
.m_short1
;
227 ftc2
->from_any (in_any3
);
229 // char c = ftc2->get_char ();
230 // CORBA::Boolean status = ftc2->next ();
231 // CORBA::Long lo = ftc2->get_long ();
232 // analyzer.analyze (ftc2.in ());
234 out_any2
= ftc2
->to_any ();
236 if (!(out_any2
.in () >>= ts_out2
)) // problem
241 catch (const CORBA::TypeCode::BadKind
& )
245 if (ts_out2
!= 0 && ts_out2
->es
.s
== data
.m_short1
)
247 ACE_DEBUG ((LM_DEBUG
,
252 ++this->error_count_
;
256 ACE_DEBUG ((LM_DEBUG
,
257 "testing: current_member_name/current_member_kind\n"));
261 DynamicAny::FieldName_var fn
=
262 ftc1
->current_member_name ();
264 if (ACE_OS::strcmp (fn
.in (), "es"))
266 ++this->error_count_
;
270 ftc1
->current_member_kind ();
272 if (tk
!= CORBA::tk_struct
)
274 ++this->error_count_
;
277 if (this->error_count_
== 0)
279 ACE_DEBUG ((LM_DEBUG
,
283 ACE_DEBUG ((LM_DEBUG
,
284 "testing: current_member_name/current_member_kind "
288 DynamicAny::FieldName_var fn2
=
289 ftc2
->current_member_name ();
291 if (ACE_OS::strcmp (fn2
.in (), "es"))
293 ++this->error_count_
;
297 ftc2
->current_member_kind ();
299 if (tk2
!= CORBA::tk_struct
)
301 ++this->error_count_
;
304 if (this->error_count_
== 0)
306 ACE_DEBUG ((LM_DEBUG
,
310 ACE_DEBUG ((LM_DEBUG
,
311 "testing: get_members/set_members\n"));
313 DynamicAny::NameValuePairSeq_var nvps
=
316 DynamicAny::DynAny_var sm_base
=
317 dynany_factory
->create_dyn_any_from_type_code (
318 DynAnyTests::_tc_test_struct
321 DynamicAny::DynStruct_var sm
=
322 DynamicAny::DynStruct::_narrow (sm_base
.in ());
324 if (CORBA::is_nil (sm
.in ()))
326 ACE_ERROR_RETURN ((LM_ERROR
,
327 "DynStruct::_narrow()[2] returned nil\n"),
331 sm
->set_members (nvps
.in ());
333 DynamicAny::NameValuePairSeq_var gm
=
336 CORBA::ULong index
= 2;
338 if (ACE_OS::strcmp (gm
[index
].id
, "es"))
340 ++this->error_count_
;
349 ACE_DEBUG ((LM_DEBUG
,
352 ACE_DEBUG ((LM_DEBUG
,
353 "testing: struct_with_long_double destroy\n"));
355 // Test fix for bug on destroy when struct contains long_double value.
356 DynAnyTests::test_struct_with_long_double l_long_double_in_struct
;
358 CORBA::Any corba_long_double
;
359 corba_long_double
<<= l_long_double_in_struct
;
361 DynamicAny::DynAny_var l_dynany
= dynany_factory
->create_dyn_any (corba_long_double
);
364 l_dynany
->destroy ();
365 ACE_DEBUG ((LM_DEBUG
,
370 ++this->error_count_
;
373 catch (const CORBA::Exception
& ex
)
375 ex
._tao_print_exception ("test_dynstruct::run_test");
376 ++this->error_count_
;
379 ACE_DEBUG ((LM_DEBUG
,
381 this->error_count_
));
383 return !!error_count_
;