Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / DynAny_Test / test_dynarray.cpp
blob57b5ccb71e829313ade6efce1d36fb264aaef959
1 //=============================================================================
2 /**
3 * @file test_dynarray.cpp
5 * Implementation of the DynArray test
7 * @author Jeff Parsons <parsons@cs.wustl.edu>
8 */
9 //=============================================================================
12 #include "test_dynarray.h"
13 #include "da_testsC.h"
14 #include "data.h"
15 #include "tao/DynamicAny/DynamicAny.h"
16 #include "analyzer.h"
18 Test_DynArray::Test_DynArray (CORBA::ORB_var orb, int debug)
19 : orb_ (orb),
20 test_name_ (CORBA::string_dup ("test_dynarray")),
21 error_count_ (0),
22 debug_ (debug)
26 Test_DynArray::~Test_DynArray ()
28 CORBA::string_free (this->test_name_);
29 this->test_name_ = 0;
32 const char*
33 Test_DynArray::test_name () const
35 return this->test_name_;
38 int
39 Test_DynArray::run_test ()
41 Data data (this->orb_);
43 DynAnyTests::test_array ta = {0};
45 try
47 ACE_DEBUG ((LM_DEBUG,
48 "\t*=*=*=*= %C =*=*=*=*\n",
49 data.labels[4]));
51 ACE_DEBUG ((LM_DEBUG,
52 "testing: constructor(Any)/insert/get/seek/rewind/current_component\n"));
54 CORBA::Object_var factory_obj =
55 this->orb_->resolve_initial_references ("DynAnyFactory");
57 DynamicAny::DynAnyFactory_var dynany_factory =
58 DynamicAny::DynAnyFactory::_narrow (factory_obj.in ());
60 if (CORBA::is_nil (dynany_factory.in ()))
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "Nil dynamic any factory after narrow\n"),
64 -1);
67 DynAnyAnalyzer analyzer (this->orb_.in (),
68 dynany_factory.in (),
69 debug_);
71 CORBA::Any in_any1;
72 in_any1 <<= DynAnyTests::test_array_forany (ta);
73 DynamicAny::DynAny_var dp1 =
74 dynany_factory->create_dyn_any (in_any1);
76 DynamicAny::DynArray_var fa1 =
77 DynamicAny::DynArray::_narrow (dp1.in ());
79 fa1->seek (1);
81 fa1->insert_long (data.m_long1);
83 fa1->rewind ();
85 CORBA::Long l_out1 = data.m_long2;
86 fa1->seek (1);
88 l_out1 = fa1->get_long ();
90 if (l_out1 == data.m_long1)
92 ACE_DEBUG ((LM_DEBUG,
93 "++ OK ++\n"));
95 else
97 ++this->error_count_;
100 ACE_DEBUG ((LM_DEBUG,
101 "testing: constructor(TypeCode)/from_any/to_any\n"));
103 DynamicAny::DynAny_var ftc1_base =
104 dynany_factory->create_dyn_any_from_type_code (DynAnyTests::_tc_test_array);
106 DynamicAny::DynArray_var ftc1 =
107 DynamicAny::DynArray::_narrow (ftc1_base.in ());
109 if (CORBA::is_nil (ftc1.in ()))
111 ACE_ERROR_RETURN ((LM_ERROR,
112 "DynArray::_narrow() returned nil\n"),
113 -1);
116 ta[1U] = data.m_long1;
117 CORBA::Any in_any2;
118 in_any2 <<= DynAnyTests::test_array_forany (ta);
120 ftc1->from_any (in_any2);
123 analyzer.analyze (ftc1.in ());
125 CORBA::Any_var out_any1 =
126 ftc1->to_any ();
128 DynAnyTests::test_array_forany ta_out;
129 out_any1.in () >>= ta_out;
131 if (ta_out[1U] == data.m_long1)
133 ACE_DEBUG ((LM_DEBUG,
134 "++ OK ++\n"));
136 else
138 ++this->error_count_;
141 ACE_DEBUG ((LM_DEBUG,
142 "testing: set_elements/get_elements\n"));
144 DynamicAny::AnySeq as_in (2);
145 as_in.length (2);
146 CORBA::Any in_any3;
147 in_any3 <<= data.m_long1;
148 as_in[0] = in_any3;
149 as_in[1] = in_any3;
150 ftc1->set_elements (as_in);
152 DynamicAny::AnySeq_var as_out =
153 ftc1->get_elements ();
154 CORBA::Any out_any2 = as_out[1U];
155 CORBA::Long l_out2;
156 out_any2 >>= l_out2;
158 if (l_out2 == data.m_long1)
160 ACE_DEBUG ((LM_DEBUG,
161 "++ OK ++\n"));
163 else
165 ++this->error_count_;
168 fa1->destroy ();
170 ftc1->destroy ();
172 catch (const CORBA::Exception& ex)
174 ex._tao_print_exception ("test_dynarray::run_test");
175 ++this->error_count_;
178 ACE_DEBUG ((LM_DEBUG,
179 "\n%d errors\n",
180 this->error_count_));
182 return !!error_count_;