2 //=============================================================================
8 * @author Aniruddha Gokhale
10 //=============================================================================
15 #include "tao/debug.h"
17 // ************************************************************************
19 // ************************************************************************
21 size_t Test_Any::counter
= 0;
24 : opname_ (CORBA::string_dup ("test_any")),
25 out_ (new CORBA::Any
),
30 Test_Any::~Test_Any ()
32 CORBA::string_free (this->opname_
);
37 Test_Any::opname () const
43 Test_Any::dii_req_invoke (CORBA::Request
*req
)
45 req
->add_in_arg ("o1") <<= this->in_
;
46 req
->add_inout_arg ("o2") <<= this->inout_
;
47 req
->add_out_arg ("o3") <<= this->out_
.in ();
49 req
->set_return_type (CORBA::_tc_any
);
53 const CORBA::Any
*tmp
;
54 req
->return_value () >>= tmp
;
55 this->ret_
= new CORBA::Any (*tmp
);
57 CORBA::NamedValue_ptr o2
=
58 req
->arguments ()->item (1);
59 *o2
->value () >>= tmp
;
60 this->inout_
= CORBA::Any (*tmp
);
62 CORBA::NamedValue_ptr o3
=
63 req
->arguments ()->item (2);
64 *o3
->value () >>= tmp
;
65 this->out_
= new CORBA::Any (*tmp
);
68 #if 0 /* any_table isn't currently used */
69 static const CORBA::TypeCode_ptr any_table
[] =
71 // primitive parameterless typecodes
73 // typecode with a simple parameter
77 Param_Test::_tc_StrSeq
,
78 Param_Test::_tc_StructSeq
,
79 Param_Test::_tc_Nested_Struct
81 #endif /* any_table isn't currently used */
84 Test_Any::init_parameters (Param_Test_ptr objref
)
88 // get access to a Coffee Object
89 this->cobj_
= objref
->make_coffee ();
91 this->reset_parameters ();
94 catch (const CORBA::SystemException
& sysex
)
96 sysex
._tao_print_exception ("System Exception doing make_coffee");
102 Test_Any::reset_parameters ()
104 Generator
*gen
= GENERATOR::instance (); // value generator
105 CORBA::ULong index
= (counter
++ % Test_Any::ANY_LAST_TEST_ITEM
);
110 case Test_Any::ANY_SHORT
:
112 if (TAO_debug_level
> 0)
113 ACE_DEBUG ((LM_DEBUG
,
114 "Param_Test: ANY_SHORT subtest\n"));
116 s
= gen
->gen_short ();
118 if (TAO_debug_level
> 0)
119 ACE_DEBUG ((LM_DEBUG
, "setting short = %d\n", s
));
125 case Test_Any::ANY_STRING
:
127 if (TAO_debug_level
> 0)
128 ACE_DEBUG ((LM_DEBUG
,
129 "Param_Test: ANY_STRING subtest\n"));
130 char *str
= gen
->gen_string ();
132 if (TAO_debug_level
> 0)
133 ACE_DEBUG ((LM_DEBUG
, "setting string = %C\n", str
));
135 this->inout_
<<= str
;
136 CORBA::string_free (str
);
140 case Test_Any::ANY_OBJREF
:
142 if (TAO_debug_level
> 0)
143 ACE_DEBUG ((LM_DEBUG
,
144 "Param_Test: ANY_OBJREF subtest\n"));
146 // insert the coffee object into the Any
147 this->in_
<<= this->cobj_
.in ();
148 this->inout_
<<= this->cobj_
.in ();
152 case Test_Any::ANY_ARRAY
:
154 if (TAO_debug_level
> 0)
155 ACE_DEBUG ((LM_DEBUG
,
156 "Param_Test: ANY_ARRAY subtest\n"));
158 Param_Test::Fixed_Array array
;
159 for (size_t i
= 0; i
< Param_Test::DIM1
; i
++)
161 if (TAO_debug_level
> 0)
162 ACE_DEBUG ((LM_DEBUG
, "Setting Fixed_Array\n"));
163 this->in_
<<= Param_Test::Fixed_Array_forany (array
);
164 this->inout_
<<= Param_Test::Fixed_Array_forany (array
);
168 case Test_Any::ANY_SHORT_SEQ
:
170 if (TAO_debug_level
> 0)
171 ACE_DEBUG ((LM_DEBUG
,
172 "Param_Test: ANY_SHORT_SEQ subtest\n"));
174 seq
.length (gen
->gen_short () % 16);
175 for (size_t i
= 0; i
< seq
.length (); i
++)
176 seq
[i
] = gen
->gen_short ();
178 this->inout_
<<= seq
;
182 case Test_Any::ANY_BD_SHORT_SEQ
:
184 if (TAO_debug_level
> 0)
185 ACE_DEBUG ((LM_DEBUG
,
186 "Param_Test: ANY_BD_SHORT_SEQ subtest\n"));
187 Param_Test::Bounded_Short_Seq seq
;
188 seq
.length (gen
->gen_short () % seq
.maximum ());
189 for (size_t i
= 0; i
< seq
.length (); i
++)
190 seq
[i
] = gen
->gen_short ();
192 this->inout_
<<= seq
;
196 case Test_Any::ANY_STRUCT
:
198 if (TAO_debug_level
> 0)
199 ACE_DEBUG ((LM_DEBUG
,
200 "Param_Test: ANY_STRUCT subtest\n"));
201 Param_Test::Fixed_Struct structure
;
202 structure
= gen
->gen_fixed_struct ();
203 this->in_
<<= structure
;
204 this->inout_
<<= structure
;
208 case Test_Any::ANY_BIG_UNION
:
210 CORBA::Long x
= gen
->gen_long ();
211 Param_Test::Big_Union the_union
;
212 the_union
.the_long (x
);
213 this->in_
<<= the_union
;
214 this->inout_
<<= the_union
;
216 if (TAO_debug_level
> 0)
218 const Param_Test::Big_Union
*bu_in
= 0;
219 const Param_Test::Big_Union
*bu_inout
= 0;
221 this->inout_
>>= bu_inout
;
222 ACE_DEBUG ((LM_DEBUG
,
223 "Param_Test: ANY_BIG_UNION subtest\n"
227 bu_inout
->the_long ()));
232 case Test_Any::ANY_SMALL_UNION
:
234 CORBA::Long x
= gen
->gen_long ();
235 Param_Test::Small_Union the_union
;
236 the_union
.the_long (x
);
237 this->in_
<<= the_union
;
238 this->inout_
<<= the_union
;
240 if (TAO_debug_level
> 0)
242 const Param_Test::Small_Union
*bu_in
= 0;
243 const Param_Test::Small_Union
*bu_inout
= 0;
245 this->inout_
>>= bu_inout
;
246 ACE_DEBUG ((LM_DEBUG
,
247 "Param_Test: ANY_SMALL_UNION subtest\n"
251 bu_inout
->the_long ()));
260 Test_Any::run_sii_test (Param_Test_ptr objref
)
264 this->ret_
= objref
->test_any (this->in_
,
268 catch (const CORBA::Exception
&)
276 Test_Any::check_validity ()
278 CORBA::Short short_in
, short_inout
, short_out
, short_ret
;
280 const char *str_inout
;
283 Coffee_ptr obj_in
, obj_inout
, obj_out
, obj_ret
;
284 Param_Test::Fixed_Array_forany array_in
, array_inout
, array_out
, array_ret
;
285 const Param_Test::Bounded_Short_Seq
*bdss_in
, *bdss_inout
, *bdss_out
, *bdss_ret
;
286 const CORBA::ShortSeq
*ubss_in
, *ubss_inout
, *ubss_out
, *ubss_ret
;
287 const Param_Test::Fixed_Struct
*fs_in
, *fs_inout
, *fs_out
, *fs_ret
;
288 const Param_Test::Big_Union
*bu_in
, *bu_inout
, *bu_out
, *bu_ret
;
289 const Param_Test::Small_Union
*su_in
, *su_inout
, *su_out
, *su_ret
;
291 if ((this->in_
>>= short_in
) &&
292 (this->inout_
>>= short_inout
) &&
293 (this->out_
.in () >>= short_out
) &&
294 (this->ret_
.in () >>= short_ret
))
296 // ACE_DEBUG ((LM_DEBUG, "Received shorts: in = %d, "
297 // "inout = %d, out = %d, ret = %d\n",
298 // short_in, short_inout, short_out, short_ret));
300 if ((short_in
== short_inout
) &&
301 (short_in
== short_out
) &&
302 (short_in
== short_ret
))
306 ACE_DEBUG ((LM_DEBUG
, "mismatch of short values\n"));
310 else if ((this->in_
>>= str_in
) &&
311 (this->inout_
>>= str_inout
) &&
312 (this->out_
.in () >>= str_out
) &&
313 (this->ret_
.in () >>= str_ret
))
315 if (!ACE_OS::strcmp (str_in
, str_inout
) &&
316 !ACE_OS::strcmp (str_in
, str_out
) &&
317 !ACE_OS::strcmp (str_in
, str_ret
))
321 ACE_DEBUG ((LM_DEBUG
, "mismatch of string values\n"));
325 else if ((this->in_
>>= obj_in
) &&
326 (this->inout_
>>= obj_inout
) &&
327 (this->out_
.in () >>= obj_out
) &&
328 (this->ret_
.in () >>= obj_ret
))
330 // all the >>= operators returned true so we are OK.
333 else if ((this->in_
>>= array_in
) &&
334 (this->inout_
>>= array_inout
) &&
335 (this->out_
.in () >>= array_out
) &&
336 (this->ret_
.in () >>= array_ret
))
338 for (CORBA::ULong i
= 0; i
< Param_Test::DIM1
; i
++)
341 CORBA::Long square
= i
* i
;
342 if (array_in
[i
] != ii
||
343 array_out
[i
] != ii
||
344 array_inout
[i
] != square
||
345 array_ret
[i
] != square
)
350 else if ((this->in_
>>= bdss_in
) &&
351 (this->inout_
>>= bdss_inout
) &&
352 (this->out_
.in () >>= bdss_out
) &&
353 (this->ret_
.in () >>= bdss_ret
))
355 for (size_t i
= 0; i
< bdss_in
->length (); i
++)
357 ssize_t square
= i
* i
;
358 if ((*bdss_in
)[i
] != (*bdss_out
)[i
] ||
359 (*bdss_inout
)[i
] != square
||
360 (*bdss_inout
)[i
] != (*bdss_ret
)[i
])
365 else if ((this->in_
>>= ubss_in
) &&
366 (this->inout_
>>= ubss_inout
) &&
367 (this->out_
.in () >>= ubss_out
) &&
368 (this->ret_
.in () >>= ubss_ret
))
370 for (size_t i
= 0; i
< ubss_in
->length (); i
++)
372 ssize_t square
= i
* i
;
373 if ((*ubss_in
)[i
] != (*ubss_out
)[i
] ||
374 (*ubss_inout
)[i
] != square
||
375 (*ubss_inout
)[i
] != (*ubss_ret
)[i
])
380 else if ((this->in_
>>= fs_in
) &&
381 (this->inout_
>>= fs_inout
) &&
382 (this->out_
.in () >>= fs_out
) &&
383 (this->ret_
.in () >>= fs_ret
))
385 // @@ Added test for data validity here.
388 else if ((this->in_
>>= bu_in
) &&
389 (this->inout_
>>= bu_inout
) &&
390 (this->out_
.in () >>= bu_out
) &&
391 (this->ret_
.in () >>= bu_ret
))
393 if (bu_in
->_d () != 2
394 || bu_inout
->_d () != 2
395 || bu_out
->_d () != 2
396 || bu_ret
->_d () != 2)
398 ACE_DEBUG ((LM_DEBUG
,
399 "Test_Any - not all unions contain a long\n"));
403 if (bu_in
->the_long () != bu_inout
->the_long ()
404 || bu_in
->the_long () != bu_out
->the_long ()
405 || bu_in
->the_long () != bu_ret
->the_long ())
407 ACE_DEBUG ((LM_DEBUG
,
408 "Test_Any - values mismatch\n"
414 bu_inout
->the_long (),
416 bu_ret
->the_long () ));
421 else if ((this->in_
>>= su_in
) &&
422 (this->inout_
>>= su_inout
) &&
423 (this->out_
.in () >>= su_out
) &&
424 (this->ret_
.in () >>= su_ret
))
426 if (su_in
->_d () != Param_Test::A_LONG
427 || su_inout
->_d () != Param_Test::A_LONG
428 || su_out
->_d () != Param_Test::A_LONG
429 || su_ret
->_d () != Param_Test::A_LONG
)
431 ACE_DEBUG ((LM_DEBUG
,
432 "Test_Any - not all unions contain a long\n"));
436 if (su_in
->the_long () != su_inout
->the_long ()
437 || su_in
->the_long () != su_out
->the_long ()
438 || su_in
->the_long () != su_ret
->the_long ())
440 ACE_DEBUG ((LM_DEBUG
,
441 "Test_Any - values mismatch\n"
447 su_inout
->the_long (),
449 su_ret
->the_long () ));
459 Test_Any::check_validity (CORBA::Request_ptr
/*req*/)
461 return this->check_validity ();
465 Test_Any::print_values ()