1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
//=============================================================================
/**
* @file test_dynsequence.cpp
*
* $Id$
*
* Implementation of the simple DynSequence test
*
*
* @author Jeff Parsons <jp4@cs.wustl.edu>
*/
//=============================================================================
#include "test_dynsequence.h"
#include "da_testsC.h"
#include "data.h"
#include "tao/DynamicAny/DynamicAny.h"
#include "analyzer.h"
#include "ace/OS_NS_string.h"
Test_DynSequence::Test_DynSequence (CORBA::ORB_var orb, int debug)
: orb_ (orb),
test_name_ (CORBA::string_dup ("test_dynsequence")),
error_count_ (0),
debug_ (debug)
{
}
Test_DynSequence::~Test_DynSequence (void)
{
CORBA::string_free (this->test_name_);
this->test_name_ = 0;
}
const char*
Test_DynSequence::test_name (void) const
{
return this->test_name_;
}
int
Test_DynSequence::run_test (void)
{
Data data (this->orb_);
DynAnyTests::test_seq ts (2);
ts.length (2);
try
{
ACE_DEBUG ((LM_DEBUG,
"\t*=*=*=*= %s =*=*=*=*\n",
data.labels[11]));
ACE_DEBUG ((LM_DEBUG,
"testing: constructor(Any)/insert/get/seek/"
"rewind/current_component\n"));
CORBA::Object_var factory_obj =
this->orb_->resolve_initial_references ("DynAnyFactory");
DynamicAny::DynAnyFactory_var dynany_factory =
DynamicAny::DynAnyFactory::_narrow (factory_obj.in ());
if (CORBA::is_nil (dynany_factory.in ()))
{
ACE_ERROR_RETURN ((LM_ERROR,
"Nil dynamic any factory after narrow\n"),
-1);
}
DynAnyAnalyzer analyzer (this->orb_.in (),
dynany_factory.in (),
debug_);
DynAnyTests::SeqShort shortseq1;
shortseq1.length (2);
shortseq1[0] = 2;
shortseq1[1] = -2;
CORBA::Any any;
any <<= shortseq1;
DynamicAny::DynAny_var shortdany =
dynany_factory->create_dyn_any (any);
analyzer.analyze(shortdany.in ());
CORBA::Any_var any3;
any3 = shortdany->to_any ();
ts[0] = data.m_string2;
ts[1] = data.m_string2;
CORBA::Any in_any1;
in_any1 <<= ts;
DynamicAny::DynAny_var dp1 =
dynany_factory->create_dyn_any (in_any1);
DynamicAny::DynSequence_var fa1 =
DynamicAny::DynSequence::_narrow (dp1.in ());
fa1->seek (1);
fa1->insert_string (data.m_string1);
fa1->rewind ();
fa1->seek (1);
CORBA::String_var out_str1 =
fa1->get_string ();
if (!ACE_OS::strcmp (out_str1.in (), data.m_string1))
{
ACE_DEBUG ((LM_DEBUG,
"++ OK ++\n"));
}
else
{
++this->error_count_;
}
ACE_DEBUG ((
LM_DEBUG,
"testing: set_elements_as_dyn_any/get_elements_as_dyn_any/equal\n"
));
static const char *values[] =
{
"zero",
"one",
"two"
};
CORBA::ULong length = 3;
DynamicAny::DynAnySeq *elem_ptr = 0;
ACE_NEW_RETURN (elem_ptr,
DynamicAny::DynAnySeq (length),
-1);
elem_ptr->length (length);
DynamicAny::DynAnySeq_var elements (elem_ptr);
CORBA::Any elem_any;
CORBA::ULong i;
for (i = 0; i < length; ++i)
{
elem_any <<= CORBA::Any::from_string (values[i],
8);
elements[i] = dynany_factory->create_dyn_any (elem_any);
}
fa1->set_elements_as_dyn_any (elements.in ());
DynamicAny::DynAnySeq_var out_elems =
fa1->get_elements_as_dyn_any ();
if (out_elems->length () != 3)
{
++this->error_count_;
return -1;
}
analyzer.analyze (fa1.in());
CORBA::String_var out_str;
for (i = 0; i < length; ++i)
{
out_str = out_elems[i]->get_string ();
CORBA::Boolean equal =
out_elems[i]->equal (elements[i]);
if (!equal)
{
++this->error_count_;
}
// To show that calling destroy() on a component does
// nothing, as required by the spec.
out_elems[i]->destroy ();
}
if (this->error_count_ == 0)
{
ACE_DEBUG ((LM_DEBUG,
"++ OK ++\n"));
}
ACE_DEBUG ((LM_DEBUG,
"testing: constructor(TypeCode)/from_any/to_any\n"));
DynamicAny::DynAny_var ftc1_base =
dynany_factory->create_dyn_any_from_type_code (
DynAnyTests::_tc_test_seq
);
DynamicAny::DynSequence_var ftc1 =
DynamicAny::DynSequence::_narrow (ftc1_base.in ());
if (CORBA::is_nil (ftc1.in ()))
{
ACE_ERROR_RETURN ((LM_ERROR,
"DynSequence::_narrow() returned nil\n"),
-1);
}
ts[0] = CORBA::string_dup (data.m_string1);
CORBA::Any in_any2;
in_any2 <<= ts;
ftc1->from_any (in_any2);
analyzer.analyze (ftc1.in());
CORBA::Any_var out_any1 =
ftc1->to_any ();
DynAnyTests::test_seq *ts_out;
out_any1.in () >>= ts_out;
if (!ACE_OS::strcmp ((*ts_out)[0U], data.m_string1))
{
ACE_DEBUG ((LM_DEBUG,
"++ OK ++\n"));
}
else
{
++this->error_count_;
}
ACE_DEBUG ((LM_DEBUG,
"testing: length/set_elements/get_elements\n"));
length = ftc1->get_length ();
if (length != 2)
{
++this->error_count_;
}
ftc1->set_length (3);
DynamicAny::AnySeq as_in (3);
as_in.length (3);
CORBA::Any in_any3;
in_any3 <<= CORBA::Any::from_string (data.m_string2, 8);
as_in[0] = in_any3;
as_in[1] = in_any3;
in_any3 <<= CORBA::Any::from_string (data.m_string1, 8);
as_in[2] = in_any3;
ftc1->set_elements (as_in);
DynamicAny::AnySeq_var as_out =
ftc1->get_elements ();
CORBA::ULong index = 2;
CORBA::Any out_any2 = as_out[index];
char* out_str2;
out_any2 >>= CORBA::Any::to_string (out_str2, 8);
if (ACE_OS::strcmp (out_str2, data.m_string1))
{
++this->error_count_;
}
if (this->error_count_ == 0)
{
ACE_DEBUG ((LM_DEBUG,
"++ OK ++\n"));
}
fa1->destroy ();
ftc1->destroy ();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("test_dynsequence::run_test");
return -1;
}
ACE_DEBUG ((LM_DEBUG,
"\n%d errors\n",
this->error_count_));
return 0;
}
|