1 //=============================================================================
3 * @file test_dynenum.cpp
5 * Implementation of the simple DynEnum test
7 * @author Jeff Parsons <parsons@cs.wustl.edu>
9 //=============================================================================
12 #include "test_dynenum.h"
13 #include "da_testsC.h"
15 #include "tao/DynamicAny/DynamicAny.h"
17 #include "ace/OS_NS_string.h"
19 Test_DynEnum::Test_DynEnum (CORBA::ORB_var orb
, int debug
)
21 test_name_ (CORBA::string_dup ("test_dynenum")),
27 Test_DynEnum::~Test_DynEnum ()
29 CORBA::string_free (this->test_name_
);
34 Test_DynEnum::test_name () const
36 return this->test_name_
;
40 Test_DynEnum::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",
67 "testing: constructor(Any)/set_as_string/get_as_ulong\n"));
70 DynAnyTests::test_enum te
= DynAnyTests::TE_ZEROTH
;
73 DynamicAny::DynAny_var dp1
=
74 dynany_factory
->create_dyn_any (in_any1
);
76 DynamicAny::DynEnum_var de1
=
77 DynamicAny::DynEnum::_narrow (dp1
.in ());
79 analyzer
.analyze(dp1
.in());
81 de1
->set_as_string ("TE_FIRST");
83 CORBA::ULong ul_out1
=
86 analyzer
.analyze(de1
.in());
88 CORBA::Any_var out_any2
=
102 ACE_DEBUG ((LM_DEBUG
,
103 "testing: set_as_ulong/get_as_string\n"));
105 de1
->set_as_ulong (3);
106 CORBA::String_var s
=
107 de1
->get_as_string ();
109 if (ACE_OS::strcmp (s
.in (), "TE_THIRD") == 0)
111 ACE_DEBUG ((LM_DEBUG
,
116 ++this->error_count_
;
120 ACE_DEBUG ((LM_DEBUG
,
121 "testing: constructor(TypeCode)/from_any/to_any\n"));
123 DynamicAny::DynAny_var de2_base
=
124 dynany_factory
->create_dyn_any_from_type_code (DynAnyTests::_tc_test_enum
);
126 DynamicAny::DynEnum_var de2
=
127 DynamicAny::DynEnum::_narrow (de2_base
.in ());
129 if (CORBA::is_nil (de2
.in ()))
131 ACE_ERROR_RETURN ((LM_ERROR
,
132 "DynEnum::_narrow() returned nil\n"),
137 in_any2
<<= DynAnyTests::TE_THIRD
;
138 de2
->from_any (in_any2
);
140 analyzer
.analyze(de2
.in());
142 CORBA::Any_var out_any1
=
145 out_any1
.in () >>= te
;
147 if (te
== DynAnyTests::TE_THIRD
)
149 ACE_DEBUG ((LM_DEBUG
,
154 ++this->error_count_
;
157 ACE_DEBUG ((LM_DEBUG
,
158 "testing: equal\n"));
160 CORBA::Boolean equal
=
161 de1
->equal (de2
.in ());
165 ACE_DEBUG ((LM_DEBUG
,
170 ++this->error_count_
;
178 ACE_DEBUG ((LM_DEBUG
,
179 "\t*=*=*=*= %C =*=*=*=*\n",
181 ACE_DEBUG ((LM_DEBUG
,
182 "testing: set_as_string/get_as_ulong\n"));
184 // initialise instances
185 DynAnyTests::StructTypedefEnum l_struct_typedef_enum
;
186 l_struct_typedef_enum
.field_1
= DynAnyTests::TE_ZEROTH
;
187 l_struct_typedef_enum
.field_2
= DynAnyTests::TE_FIRST
;
188 l_struct_typedef_enum
.field_3
= DynAnyTests::TE_SECOND
;
189 CORBA::Any l_any_struct_typedef_enum
;
190 l_any_struct_typedef_enum
<<= l_struct_typedef_enum
;
192 DynamicAny::DynAny_var da
193 = dynany_factory
->create_dyn_any (l_any_struct_typedef_enum
);
194 DynamicAny::DynStruct_var ds
=
195 DynamicAny::DynStruct::_narrow (da
.in ());
196 DynamicAny::DynAny_var cc
197 = ds
->current_component();
199 DynamicAny::FieldName_var fn
200 = ds
->current_member_name();
202 DynamicAny::DynEnum_var member1
203 = DynamicAny::DynEnum::_narrow(cc
.in ());
205 member1
->set_as_string ("TE_FOURTH");
207 CORBA::ULong ul_out1
= member1
->get_as_ulong ();
211 ACE_DEBUG ((LM_DEBUG
,
216 ++this->error_count_
;
219 ACE_DEBUG ((LM_DEBUG
,
220 "testing: set_as_ulong/get_as_string\n"));
222 member1
->set_as_ulong (3);
224 CORBA::String_var s
= member1
->get_as_string ();
226 if (ACE_OS::strcmp (s
.in (), "TE_THIRD") == 0)
228 ACE_DEBUG ((LM_DEBUG
,
233 ++this->error_count_
;
237 catch (const CORBA::Exception
& ex
)
239 ex
._tao_print_exception ("test_dynenum::run_test");
240 ++this->error_count_
;
243 ACE_DEBUG ((LM_DEBUG
,
245 this->error_count_
));
247 return !!error_count_
;