2 //=============================================================================
6 * tests unbounded Any sequences
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 #include "ub_any_seq.h"
15 #include "tao/debug.h"
17 const CORBA::ULong TEST_SEQ_LENGTH
= 5;
18 const CORBA::ULong NUM_TEST_TYPES
= 4;
20 // ************************************************************************
22 // ************************************************************************
24 Test_AnySeq::Test_AnySeq ()
25 : opname_ (CORBA::string_dup ("test_anyseq")),
26 in_ (new CORBA::AnySeq (TEST_SEQ_LENGTH
)),
27 inout_ (new CORBA::AnySeq (TEST_SEQ_LENGTH
)),
28 out_ (new CORBA::AnySeq
),
29 ret_ (new CORBA::AnySeq
)
33 Test_AnySeq::~Test_AnySeq ()
35 CORBA::string_free (this->opname_
);
40 Test_AnySeq::opname () const
46 Test_AnySeq::dii_req_invoke (CORBA::Request
*req
)
48 req
->add_in_arg ("s1") <<= this->in_
.in ();
49 req
->add_inout_arg ("s2") <<= this->inout_
.in ();
50 req
->add_out_arg ("s3") <<= this->out_
.in ();
52 req
->set_return_type (CORBA::_tc_AnySeq
);
56 const CORBA::AnySeq
* tmp
= 0;
57 req
->return_value () >>= tmp
;
58 this->ret_
= new CORBA::AnySeq (*tmp
);
60 CORBA::NamedValue_ptr o2
=
61 req
->arguments ()->item (1);
62 *o2
->value () >>= tmp
;
63 this->inout_
= new CORBA::AnySeq (*tmp
);
65 CORBA::NamedValue_ptr o3
=
66 req
->arguments ()->item (2);
67 *o3
->value () >>= tmp
;
68 this->out_
= new CORBA::AnySeq (*tmp
);
72 Test_AnySeq::init_parameters (Param_Test_ptr objref
)
74 Generator
*gen
= GENERATOR::instance (); // value generator
76 // Must be set explicitly (CORBA spec)
77 this->in_
->length (TEST_SEQ_LENGTH
);
78 this->inout_
->length (TEST_SEQ_LENGTH
);
80 for (CORBA::ULong i
=0; i
< this->in_
->length (); i
++)
83 (CORBA::ULong
) (gen
->gen_short () % NUM_TEST_TYPES
);
89 s
= gen
->gen_short ();
90 if (TAO_debug_level
> 0)
92 "setting short = %d\n", s
));
94 this->inout_
[i
] <<= 0; // different from in_
99 CORBA::String_var str
= gen
->gen_string ();
100 if (TAO_debug_level
> 0)
101 ACE_DEBUG ((LM_DEBUG
,
102 "setting string = %C\n", str
.in ()));
103 this->in_
[i
] <<= str
.in ();
104 this->inout_
[i
] <<= 0; // different from in_
109 if (TAO_debug_level
> 0)
110 ACE_DEBUG ((LM_DEBUG
,
111 "setting coffee object\n" ));
114 // get access to a Coffee Object
115 Coffee_var cobj
= objref
->make_coffee ();
117 // insert the coffee object into the Any
118 this->in_
[i
] <<= cobj
.in ();
119 this->inout_
[i
] <<= 0; // different from in_
121 catch (const CORBA::SystemException
& sysex
)
123 sysex
._tao_print_exception (
124 "System Exception doing make_coffee");
130 if (TAO_debug_level
> 0)
131 ACE_DEBUG ((LM_DEBUG
,
132 "setting constant string\n" ));
133 this->in_
[i
] <<= "Const string";
134 this->inout_
[i
] <<= 0; // different from in_
143 Test_AnySeq::reset_parameters ()
145 Generator
*gen
= GENERATOR::instance (); // value generator
147 for (CORBA::ULong i
=0; i
< this->in_
->length (); i
++)
150 (CORBA::ULong
) (gen
->gen_long () % NUM_TEST_TYPES
);
157 s
= gen
->gen_short ();
159 this->inout_
[i
] <<= s
;
164 CORBA::String_var str
= gen
->gen_string ();
165 this->in_
[i
] <<= str
.in ();
166 this->inout_
[i
] <<= str
.in ();
171 this->inout_
[i
] = this->in_
[i
];
175 this->in_
[i
] <<= "Const string";
176 this->inout_
[i
] <<= "Const string";
186 Test_AnySeq::run_sii_test (Param_Test_ptr objref
)
190 CORBA::AnySeq_out
out (this->out_
.out ());
192 this->ret_
= objref
->test_anyseq (this->in_
.in (),
193 this->inout_
.inout (),
198 catch (const CORBA::Exception
& ex
)
200 ex
._tao_print_exception ("Test_AnySeq::run_sii_test\n");
206 Test_AnySeq::check_validity ()
208 CORBA::Short short_in
, short_inout
, short_out
, short_ret
;
210 const char *str_inout
;
213 Coffee_ptr obj_in
, obj_inout
, obj_out
, obj_ret
;
215 for (CORBA::ULong i
=0; i
< this->in_
->length (); i
++)
217 if ((this->in_
[i
] >>= short_in
) &&
218 (this->inout_
[i
] >>= short_inout
) &&
219 (this->out_
[i
] >>= short_out
) &&
220 (this->ret_
[i
] >>= short_ret
))
222 if (TAO_debug_level
> 0)
224 ACE_DEBUG ((LM_DEBUG
,
225 "Received shorts: in = %d, "
226 "inout = %d, out = %d, ret = %d\n",
233 if ((short_in
!= short_inout
) ||
234 (short_in
!= short_out
) ||
235 (short_in
!= short_ret
))
237 ACE_DEBUG ((LM_DEBUG
,
238 "mismatch of short values\n"));
244 else if ((this->in_
[i
] >>= str_in
) &&
245 (this->inout_
[i
] >>= str_inout
) &&
246 (this->out_
[i
] >>= str_out
) &&
247 (this->ret_
[i
] >>= str_ret
))
249 if (ACE_OS::strcmp (str_in
, str_inout
) ||
250 ACE_OS::strcmp (str_in
, str_out
) ||
251 ACE_OS::strcmp (str_in
, str_ret
))
253 ACE_DEBUG ((LM_DEBUG
,
254 "mismatch of string values\n"));
260 else if ((this->in_
[i
] >>= obj_in
) &&
261 (this->inout_
[i
] >>= obj_inout
) &&
262 (this->out_
[i
] >>= obj_out
) &&
263 (this->ret_
[i
] >>= obj_ret
))
265 if (!(obj_in
->_is_equivalent (obj_inout
)) ||
266 !(obj_in
->_is_equivalent (obj_out
)) ||
267 !(obj_in
->_is_equivalent (obj_ret
)))
269 ACE_DEBUG ((LM_DEBUG
,
270 "mismatch of Coffee values\n"));
278 // Everything checks out.
283 Test_AnySeq::check_validity (CORBA::Request_ptr
)
285 return this->check_validity ();
289 Test_AnySeq::print_values ()
291 ACE_DEBUG ((LM_DEBUG
,
292 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
294 this->print_sequence (this->in_
.in ());
295 ACE_DEBUG ((LM_DEBUG
,
296 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
297 "INOUT sequence\n"));
298 this->print_sequence (this->inout_
.in ());
299 ACE_DEBUG ((LM_DEBUG
,
300 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
302 this->print_sequence (this->out_
.in ());
303 ACE_DEBUG ((LM_DEBUG
,
304 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
306 this->print_sequence (this->ret_
.in ());
310 Test_AnySeq::print_sequence (const CORBA::AnySeq
&s
)
312 ACE_DEBUG ((LM_DEBUG
,
317 ACE_DEBUG ((LM_DEBUG
, "Elements -\n"));
318 for (CORBA::ULong i
=0; i
< s
.length (); i
++)
320 /* const CORBA::Any& vs = s[i];
322 ACE_DEBUG ((LM_DEBUG,
332 vs.l, vs.c, vs.s, vs.o, vs.f, vs.b, vs.d));