1 //=============================================================================
3 * @file test_dynunion.cpp
5 * Implementation of the simple DynUnion test
7 * @author Jeff Parsons <parsons@cs.wustl.edu>
9 //=============================================================================
11 #include "da_testsC.h"
12 #include "test_dynunion.h"
15 #include "tao/DynamicAny/DynamicAny.h"
16 #include "ace/OS_NS_string.h"
18 Test_DynUnion::Test_DynUnion (CORBA::ORB_var orb
, int debug
)
20 test_name_ (CORBA::string_dup ("test_dynunion")),
26 Test_DynUnion::~Test_DynUnion ()
28 CORBA::string_free (this->test_name_
);
33 Test_DynUnion::test_name () const
35 return this->test_name_
;
39 Test_DynUnion::run_test ()
41 Data
data (this->orb_
);
43 DynAnyTests::test_union tu
;
48 "\t*=*=*=*= %C =*=*=*=*\n",
51 CORBA::Object_var factory_obj
=
52 this->orb_
->resolve_initial_references ("DynAnyFactory");
54 DynamicAny::DynAnyFactory_var dynany_factory
=
55 DynamicAny::DynAnyFactory::_narrow (factory_obj
.in ());
57 if (CORBA::is_nil (dynany_factory
.in ()))
59 ACE_ERROR_RETURN ((LM_ERROR
,
60 "Nil dynamic any factory after narrow\n"),
64 DynAnyAnalyzer
analyzer(this->orb_
.in(), dynany_factory
.in(), debug_
);
67 "testing: constructor(Any)/from_any/to_any with string\n"));
69 DynAnyTests::test_union tstring
;
70 tstring
._d (DynAnyTests::TE_THIRD
);
71 tstring
.str (CORBA::string_dup (data
.m_string1
));
74 DynamicAny::DynAny_var dp4
=
75 dynany_factory
->create_dyn_any (in_any4
);
76 DynamicAny::DynUnion_var fa4
=
77 DynamicAny::DynUnion::_narrow (dp4
.in ());
79 analyzer
.analyze(fa4
.in());
81 CORBA::Any_var out_any5
= fa4
->to_any ();
83 DynamicAny::DynAny_var dp5
=
84 dynany_factory
->create_dyn_any (out_any5
.in());
87 "testing: constructor(Any)/insert/get\n"));
89 tu
._d (DynAnyTests::TE_SECOND
);
90 tu
.tc (data
.m_typecode2
);
93 DynamicAny::DynAny_var dp1
=
94 dynany_factory
->create_dyn_any (in_any1
);
95 DynamicAny::DynUnion_var fa1
=
96 DynamicAny::DynUnion::_narrow (dp1
.in ());
98 fa1
->insert_typecode (data
.m_typecode1
);
100 CORBA::TypeCode_var s_out1
= fa1
->get_typecode ();
102 CORBA::Boolean
const equal_tc1
=
103 s_out1
->equal (data
.m_typecode1
);
107 ACE_DEBUG ((LM_DEBUG
,
112 ++this->error_count_
;
115 ACE_DEBUG ((LM_DEBUG
,
116 "testing: constructor(TypeCode)/from_any/to_any\n"));
118 analyzer
.analyze (fa1
.in());
120 CORBA::Any_var out_any1
= fa1
->to_any ();
121 DynamicAny::DynAny_var ftc1_base
=
122 dynany_factory
->create_dyn_any_from_type_code (DynAnyTests::_tc_test_union
);
124 DynamicAny::DynUnion_var ftc1
=
125 DynamicAny::DynUnion::_narrow (ftc1_base
.in ());
127 if (CORBA::is_nil (ftc1
.in ()))
129 ACE_ERROR_RETURN ((LM_ERROR
,
130 "DynUnion::_narrow() returned nil\n"),
134 ftc1
->from_any (out_any1
.in ());
138 CORBA::TypeCode_var s_out2
=
139 ftc1
->get_typecode ();
141 CORBA::Boolean
const equal_tc2
=
142 s_out2
->equal (data
.m_typecode1
);
146 ACE_DEBUG ((LM_DEBUG
,
151 ++this->error_count_
;
154 ACE_DEBUG ((LM_DEBUG
,
155 "testing: constructor(TypeCode alias)/from_any/to_any\n"));
157 analyzer
.analyze( fa1
.in());
159 CORBA::Any_var out_any2
= fa1
->to_any ();
161 CORBA::TypeCode_var s_out3
;
165 DynamicAny::DynAny_var ftc2_base
=
166 dynany_factory
->create_dyn_any_from_type_code
167 (DynAnyTests::_tc_test_union_alias
);
169 DynamicAny::DynUnion_var ftc2
=
170 DynamicAny::DynUnion::_narrow (ftc2_base
.in ());
172 if (CORBA::is_nil (ftc2
.in ()))
174 ACE_ERROR_RETURN ((LM_ERROR
,
175 "DynUnion::_narrow() returned nil\n"),
179 ftc2
->from_any (out_any2
.in ());
183 s_out3
= ftc2
->get_typecode ();
185 catch (const CORBA::TypeCode::BadKind
& )
190 if (!CORBA::is_nil (s_out3
.in ()))
192 CORBA::Boolean
const equal_tc
=
193 s_out3
->equal (data
.m_typecode1
);
197 ACE_DEBUG ((LM_DEBUG
,
202 ++this->error_count_
;
207 ++this->error_count_
;
210 ACE_DEBUG ((LM_DEBUG
,
211 "testing:discriminator/discriminator_kind\n"));
213 DynamicAny::DynAny_var dp2
=
214 ftc1
->get_discriminator ();
216 CORBA::TypeCode_var tc2
=
219 CORBA::TCKind tc1kind
=
220 ftc1
->discriminator_kind ();
222 CORBA::TCKind tc2kind
= tc2
->kind ();
224 if (tc2kind
== tc1kind
)
226 ACE_DEBUG ((LM_DEBUG
,
231 ++this->error_count_
;
234 ACE_DEBUG ((LM_DEBUG
,
235 "testing:member/member_kind/member_name\n"));
237 DynamicAny::DynAny_var dp3
=
240 CORBA::String_var m_nm
=
241 ftc1
->member_name ();
244 ftc1
->member_kind ();
246 CORBA::TypeCode_var tc3
=
247 dp3
->get_typecode ();
249 CORBA::Boolean
const equal_tc3
=
250 data
.m_typecode1
->equal (tc3
.in ());
252 if (!ACE_OS::strcmp (m_nm
.in (), "tc")
253 && tk
== CORBA::tk_TypeCode
256 ACE_DEBUG ((LM_DEBUG
,
261 ++this->error_count_
;
264 ACE_DEBUG ((LM_DEBUG
,
265 "testing: set_to_default_member\n"));
267 ftc1
->set_to_default_member ();
271 ftc1
->insert_short (data
.m_short1
);
273 DynamicAny::DynAny_var mem
=
279 if (out_s
== data
.m_short1
)
281 ACE_DEBUG ((LM_DEBUG
,
286 ++this->error_count_
;
293 ACE_DEBUG ((LM_DEBUG
,
294 "testing: create_dyn_any with _default()\n"));
295 DynAnyTests::test_implicit_def test_implicit_def_union
;
296 CORBA::Any any_union
;
298 test_implicit_def_union
._default();
300 any_union
<<= test_implicit_def_union
;
302 DynamicAny::DynAny_var da_union
=
303 dynany_factory
->create_dyn_any (any_union
);
304 ACE_DEBUG ((LM_DEBUG
,
307 ACE_DEBUG ((LM_DEBUG
,
308 "testing: union_no_active_member destroy\n"));
310 // Test fix for bug on destroy when there is no active member in union.
311 DynAnyTests::test_union_no_active_member l_union_value_no_active_member
;
313 CORBA::Any corba_union
;
314 corba_union
<<= l_union_value_no_active_member
;
316 DynamicAny::DynAny_var l_dynany
= dynany_factory
->create_dyn_any (corba_union
);
319 l_dynany
->destroy ();
320 ACE_DEBUG ((LM_DEBUG
,
325 ++this->error_count_
;
329 // if we get here the create_dyn_any worked.
331 catch (const CORBA::Exception
& ex
)
333 ex
._tao_print_exception ("test_dynunion::run_test");
334 ++this->error_count_
;
337 ACE_DEBUG ((LM_DEBUG
,
339 this->error_count_
));
341 return !!error_count_
;