2 //=============================================================================
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 #include "big_union.h"
16 // ************************************************************************
18 // ************************************************************************
20 size_t Test_Big_Union::counter
= 0;
22 Test_Big_Union::Test_Big_Union ()
23 : opname_ (CORBA::string_dup ("test_big_union"))
27 Test_Big_Union::~Test_Big_Union ()
29 CORBA::string_free (this->opname_
);
34 Test_Big_Union::opname () const
40 Test_Big_Union::dii_req_invoke (CORBA::Request
*req
)
42 req
->add_in_arg ("s1") <<= this->in_
;
43 req
->add_inout_arg ("s2") <<= this->inout_
;
44 req
->add_out_arg ("s3") <<= this->out_
.in ();
46 req
->set_return_type (Param_Test::_tc_Big_Union
);
50 const Param_Test::Big_Union
*tmp
= 0;
51 req
->return_value () >>= tmp
;
52 this->ret_
= new Param_Test::Big_Union (*tmp
);
54 CORBA::NamedValue_ptr o2
=
55 req
->arguments ()->item (1);
56 *o2
->value () >>= tmp
;
59 CORBA::NamedValue_ptr o3
=
60 req
->arguments ()->item (2);
61 *o3
->value () >>= tmp
;
62 this->out_
= new Param_Test::Big_Union (*tmp
);
66 Test_Big_Union::init_parameters (Param_Test_ptr objref
)
70 // get access to a Coffee Object
71 this->cobj_
= objref
->make_coffee ();
73 this->reset_parameters ();
76 catch (const CORBA::SystemException
& sysex
)
78 sysex
._tao_print_exception ("System Exception doing make_coffee");
80 catch (const CORBA::Exception
& ex
)
82 ex
._tao_print_exception (
83 "An exception caught in make_coffee");
89 Test_Big_Union::reset_parameters ()
91 Generator
*gen
= GENERATOR::instance (); // value generator
92 CORBA::ULong index
= (counter
++ % Test_Big_Union::BIG_UNION_N_BRANCHES
);
98 Param_Test::Fixed_Array x
;
99 for (CORBA::ULong i
= 0; i
< Param_Test::DIM1
; ++i
)
101 x
[i
] = gen
->gen_long ();
103 this->in_
.the_array (x
);
104 this->inout_
.the_array (x
);
109 this->in_
.the_interface (this->cobj_
.in ());
110 this->inout_
.the_interface (this->cobj_
.in ());
115 CORBA::Long x
= gen
->gen_long ();
116 this->in_
.the_long (x
);
117 this->inout_
.the_long (x
);
122 Param_Test::short_array x
;
124 for (int i
= 0; i
< 32; ++i
)
126 x
[i
] = gen
->gen_short ();
128 this->in_
.another_array (x
);
129 this->inout_
.another_array (x
);
134 CORBA::String_var str
= gen
->gen_string ();
135 this->in_
.the_string (str
);
136 this->inout_
.the_string (str
);
142 seq
.length (gen
->gen_short () % 50);
143 for (size_t i
= 0; i
< seq
.length (); i
++)
144 seq
[i
] = gen
->gen_short ();
145 this->in_
.the_sequence (seq
);
146 this->inout_
.the_sequence (seq
);
152 any
<<= CORBA::Short (25);
153 this->in_
.the_any (any
);
154 this->inout_
.the_any (any
);
159 CORBA::Octet octet
= gen
->gen_short () % 255;
160 this->in_
.the_octet (octet
);
161 this->inout_
.the_octet (octet
);
167 this->in_
.the_char (x
);
168 this->inout_
.the_char (x
);
173 CORBA::Boolean x
= gen
->gen_short () % 2;
174 this->in_
.the_boolean (x
);
175 this->inout_
.the_boolean (x
);
180 Param_Test::Var_Struct var_struct
;
181 var_struct
.dbl
= 3.14159;
182 var_struct
.boole
= gen
->gen_short () % 2;
183 var_struct
.shrt
= gen
->gen_short ();
184 // set the length of the sequence
185 var_struct
.dummy1
= gen
->gen_string ();
186 var_struct
.dummy2
= gen
->gen_string ();
187 CORBA::ULong len
= gen
->gen_long () % 10 + 1;
188 var_struct
.seq
.length (len
);
189 for (CORBA::ULong i
= 0; i
!= len
; ++i
)
191 var_struct
.seq
[i
] = gen
->gen_string ();
193 this->in_
.the_var_struct (var_struct
);
194 this->inout_
.the_var_struct (var_struct
);
199 Param_Test::Fixed_Struct fixed_struct
;
200 fixed_struct
.l
= gen
->gen_long ();
201 fixed_struct
.c
= gen
->gen_long () % 255;
202 fixed_struct
.s
= gen
->gen_long () % 32768;
203 fixed_struct
.o
= gen
->gen_long () % 255;
204 fixed_struct
.f
= gen
->gen_short () / 255.0f
;
205 fixed_struct
.b
= gen
->gen_long () % 2;
206 fixed_struct
.d
= gen
->gen_short () / 255.0;
207 this->in_
.the_fixed_struct (fixed_struct
);
208 this->inout_
.the_fixed_struct (fixed_struct
);
212 this->out_
= new Param_Test::Big_Union (this->in_
);
213 this->ret_
= new Param_Test::Big_Union (this->in_
);
218 Test_Big_Union::run_sii_test (Param_Test_ptr objref
)
222 this->ret_
= objref
->test_big_union (this->in_
,
228 catch (const CORBA::Exception
& ex
)
230 ex
._tao_print_exception ("Test_Big_Union::run_sii_test\n");
236 Test_Big_Union::check_validity ()
238 if (this->in_
._d () != this->inout_
._d ()
239 || this->in_
._d () != this->out_
->_d ()
240 || this->in_
._d () != this->ret_
->_d ())
242 ACE_DEBUG ((LM_DEBUG
, "mismatch of discriminators\n"));
247 switch (this->in_
._d ())
251 Param_Test::Fixed_Array_slice
* in_array
= this->in_
.the_array ();
252 Param_Test::Fixed_Array_slice
* inout_array
= this->inout_
.the_array ();
253 Param_Test::Fixed_Array_slice
* out_array
= this->out_
->the_array ();
254 Param_Test::Fixed_Array_slice
* ret_array
= this->ret_
->the_array ();
255 for (CORBA::ULong i
= 0; i
< Param_Test::DIM1
; ++i
)
257 if (in_array
[i
] != inout_array
[i
]
258 || in_array
[i
] != out_array
[i
]
259 || in_array
[i
] != ret_array
[i
])
261 ACE_DEBUG ((LM_DEBUG
,
262 "mismatch of arrays\n"));
272 Coffee_ptr in
= this->in_
.the_interface ();
273 Coffee_ptr inout
= this->inout_
.the_interface ();
274 Coffee_ptr out
= this->out_
->the_interface ();
275 Coffee_ptr ret
= this->ret_
->the_interface ();
277 if (CORBA::is_nil (in
)
278 || CORBA::is_nil (inout
)
279 || CORBA::is_nil (out
)
280 || CORBA::is_nil (ret
))
283 Coffee::Desc_var in_desc
=
285 Coffee::Desc_var inout_desc
=
286 inout
->description ();
287 Coffee::Desc_var out_desc
=
289 Coffee::Desc_var ret_desc
=
292 if (ACE_OS::strcmp (in_desc
->name
.in (),
293 inout_desc
->name
.in ())
294 || ACE_OS::strcmp (in_desc
->name
.in (),
295 out_desc
->name
.in ())
296 || ACE_OS::strcmp (in_desc
->name
.in (),
297 ret_desc
->name
.in ()))
300 catch (const CORBA::Exception
&)
308 CORBA::Long in
= this->in_
.the_long ();
309 CORBA::Long inout
= this->inout_
.the_long ();
310 CORBA::Long out
= this->out_
->the_long ();
311 CORBA::Long ret
= this->ret_
->the_long ();
313 if (in
!= out
|| in
!= inout
|| in
!= ret
)
321 Param_Test::short_array_slice
* in_array
=
322 this->in_
.another_array ();
323 Param_Test::short_array_slice
* inout_array
=
324 this->inout_
.another_array ();
325 Param_Test::short_array_slice
* out_array
=
326 this->out_
->another_array ();
327 Param_Test::short_array_slice
* ret_array
=
328 this->ret_
->another_array ();
330 for (int i
= 0; i
!= 32; ++i
)
332 if (in_array
[i
] != inout_array
[i
]
333 || in_array
[i
] != out_array
[i
]
334 || in_array
[i
] != ret_array
[i
])
343 const char* in
= this->in_
.the_string ();
344 const char* inout
= this->inout_
.the_string ();
345 const char* out
= this->out_
->the_string ();
346 const char* ret
= this->ret_
->the_string ();
348 if (ACE_OS::strcmp (in
,out
)
349 || ACE_OS::strcmp (in
,inout
)
350 || ACE_OS::strcmp (in
,ret
))
358 const CORBA::ShortSeq
& in
=
359 this->in_
.the_sequence ();
360 const CORBA::ShortSeq
& inout
=
361 this->inout_
.the_sequence ();
362 const CORBA::ShortSeq
& out
=
363 this->out_
->the_sequence ();
364 const CORBA::ShortSeq
& ret
=
365 this->ret_
->the_sequence ();
367 if (in
.length () != out
.length ()
368 || in
.length () != inout
.length ()
369 || in
.length () != ret
.length ())
372 for (CORBA::ULong i
= 0; i
!= in
.length (); ++i
)
385 CORBA::Any in
= this->in_
.the_any ();
386 CORBA::Any inout
= this->inout_
.the_any ();
387 CORBA::Any out
= this->out_
->the_any ();
388 CORBA::Any ret
= this->ret_
->the_any ();
390 CORBA::Short in_short
;
391 CORBA::Short inout_short
;
392 CORBA::Short out_short
;
393 CORBA::Short ret_short
;
395 if (!(in
>>= in_short
)
396 || !(inout
>>= inout_short
)
397 || !(out
>>= out_short
)
398 || !(ret
>>= ret_short
))
403 if (in_short
!= inout_short
404 || in_short
!= out_short
405 || in_short
!= ret_short
)
413 CORBA::Octet in
= this->in_
.the_octet ();
414 CORBA::Octet inout
= this->inout_
.the_octet ();
415 CORBA::Octet out
= this->out_
->the_octet ();
416 CORBA::Octet ret
= this->ret_
->the_octet ();
418 if (in
!= out
|| in
!= inout
|| in
!= ret
)
426 CORBA::Char in
= this->in_
.the_char ();
427 CORBA::Char inout
= this->inout_
.the_char ();
428 CORBA::Char out
= this->out_
->the_char ();
429 CORBA::Char ret
= this->ret_
->the_char ();
431 if (in
!= out
|| in
!= inout
|| in
!= ret
)
439 CORBA::Boolean in
= this->in_
.the_boolean ();
440 CORBA::Boolean inout
= this->inout_
.the_boolean ();
441 CORBA::Boolean out
= this->out_
->the_boolean ();
442 CORBA::Boolean ret
= this->ret_
->the_boolean ();
444 if (in
!= out
|| in
!= inout
|| in
!= ret
)
452 const Param_Test::Var_Struct
& in
=
453 this->in_
.the_var_struct ();
454 const Param_Test::Var_Struct
& inout
=
455 this->inout_
.the_var_struct ();
456 const Param_Test::Var_Struct
& out
=
457 this->out_
->the_var_struct ();
458 const Param_Test::Var_Struct
& ret
=
459 this->ret_
->the_var_struct ();
461 if (!(ACE_OS::strcmp (in
.dummy1
.in (),
462 inout
.dummy1
.in ()) == 0
463 && ACE_OS::strcmp (in
.dummy2
.in (),
464 inout
.dummy2
.in ()) == 0)
465 || !(ACE_OS::strcmp (in
.dummy1
.in (),
466 out
.dummy1
.in ()) == 0
467 && ACE_OS::strcmp (in
.dummy2
.in (),
468 out
.dummy2
.in ()) == 0)
469 || !(ACE_OS::strcmp (in
.dummy1
.in (),
470 ret
.dummy1
.in ()) == 0
471 && ACE_OS::strcmp (in
.dummy2
.in (),
472 ret
.dummy2
.in ()) == 0))
477 if (in
.seq
.length () != inout
.seq
.length ()
478 || in
.seq
.length () != out
.seq
.length ()
479 || in
.seq
.length () != ret
.seq
.length ())
484 CORBA::ULong len
= in
.seq
.length ();
486 for (CORBA::ULong i
= 0; i
!= len
; ++i
)
488 if (ACE_OS::strcmp (in
.seq
[i
],
490 || ACE_OS::strcmp (in
.seq
[i
],
492 || ACE_OS::strcmp (in
.seq
[i
],
502 const Param_Test::Fixed_Struct
& in
=
503 this->in_
.the_fixed_struct ();
504 const Param_Test::Fixed_Struct
& inout
=
505 this->inout_
.the_fixed_struct ();
506 const Param_Test::Fixed_Struct
& out
=
507 this->out_
->the_fixed_struct ();
508 const Param_Test::Fixed_Struct
& ret
=
509 this->ret_
->the_fixed_struct ();
511 if (! (in
.l
== inout
.l
515 && ACE::is_equal (in
.f
, inout
.f
)
517 && ACE::is_equal (in
.d
, inout
.d
))
522 && ACE::is_equal (in
.f
, out
.f
)
524 && ACE::is_equal (in
.d
, out
.d
))
529 && ACE::is_equal (in
.f
, ret
.f
)
531 && ACE::is_equal (in
.d
, ret
.d
)))
543 Test_Big_Union::check_validity (CORBA::Request_ptr
/*req*/)
545 //ACE_UNUSED_ARG (req);
546 return this->check_validity ();
550 Test_Big_Union::print_values ()