Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Param_Test / big_union.cpp
blobf1826497abe851d664ce3401f3d76be555510c3d
2 //=============================================================================
3 /**
4 * @file big_union.cpp
6 * tests Big_Unions
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "big_union.h"
16 // ************************************************************************
17 // Test_Big_Union
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_);
30 this->opname_ = 0;
33 const char *
34 Test_Big_Union::opname () const
36 return this->opname_;
39 void
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);
48 req->invoke ();
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;
57 this->inout_ = *tmp;
59 CORBA::NamedValue_ptr o3 =
60 req->arguments ()->item (2);
61 *o3->value () >>= tmp;
62 this->out_ = new Param_Test::Big_Union (*tmp);
65 int
66 Test_Big_Union::init_parameters (Param_Test_ptr objref)
68 try
70 // get access to a Coffee Object
71 this->cobj_ = objref->make_coffee ();
73 this->reset_parameters ();
74 return 0;
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");
85 return -1;
88 int
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);
94 switch (index)
96 case 0:
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);
106 break;
107 case 1:
109 this->in_.the_interface (this->cobj_.in ());
110 this->inout_.the_interface (this->cobj_.in ());
112 break;
113 case 2:
115 CORBA::Long x = gen->gen_long ();
116 this->in_.the_long (x);
117 this->inout_.the_long (x);
119 break;
120 case 3:
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);
131 break;
132 case 4:
134 CORBA::String_var str = gen->gen_string ();
135 this->in_.the_string (str);
136 this->inout_.the_string (str);
138 break;
139 case 5:
141 CORBA::ShortSeq seq;
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);
148 break;
149 case 6:
151 CORBA::Any any;
152 any <<= CORBA::Short (25);
153 this->in_.the_any (any);
154 this->inout_.the_any (any);
156 break;
157 case 7:
159 CORBA::Octet octet = gen->gen_short () % 255;
160 this->in_.the_octet (octet);
161 this->inout_.the_octet (octet);
163 break;
164 case 8:
166 CORBA::Char x = '@';
167 this->in_.the_char (x);
168 this->inout_.the_char (x);
170 break;
171 case 9:
173 CORBA::Boolean x = gen->gen_short () % 2;
174 this->in_.the_boolean (x);
175 this->inout_.the_boolean (x);
177 break;
178 case 10:
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);
196 break;
197 case 11:
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);
210 break;
212 this->out_ = new Param_Test::Big_Union (this->in_);
213 this->ret_ = new Param_Test::Big_Union (this->in_);
214 return 0;
218 Test_Big_Union::run_sii_test (Param_Test_ptr objref)
222 this->ret_ = objref->test_big_union (this->in_,
223 this->inout_,
224 this->out_);
226 return 0;
228 catch (const CORBA::Exception& ex)
230 ex._tao_print_exception ("Test_Big_Union::run_sii_test\n");
232 return -1;
235 CORBA::Boolean
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"));
243 return 0;
247 switch (this->in_._d ())
249 case 0:
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"));
263 return 0;
267 break;
268 case 1:
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))
281 return 0;
283 Coffee::Desc_var in_desc =
284 in->description ();
285 Coffee::Desc_var inout_desc =
286 inout->description ();
287 Coffee::Desc_var out_desc =
288 out->description ();
289 Coffee::Desc_var ret_desc =
290 ret->description ();
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 ()))
298 return 0;
300 catch (const CORBA::Exception&)
302 return 0;
305 break;
306 case 2:
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)
315 return 0;
318 break;
319 case 3:
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])
336 return 0;
340 break;
341 case 4:
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))
352 return 0;
355 break;
356 case 5:
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 ())
370 return 0;
372 for (CORBA::ULong i = 0; i != in.length (); ++i)
374 if (in[i] != out[i]
375 || in[i] != inout[i]
376 || in[i] != ret[i])
378 return 0;
382 break;
383 case 6:
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))
400 return 0;
403 if (in_short != inout_short
404 || in_short != out_short
405 || in_short != ret_short)
407 return 0;
410 break;
411 case 7:
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)
420 return 0;
423 break;
424 case 8:
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)
433 return 0;
436 break;
437 case 9:
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)
446 return 0;
449 break;
450 case 10:
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))
474 return 0;
477 if (in.seq.length () != inout.seq.length ()
478 || in.seq.length () != out.seq.length ()
479 || in.seq.length () != ret.seq.length ())
481 return 0;
484 CORBA::ULong len = in.seq.length ();
486 for (CORBA::ULong i = 0; i != len; ++i)
488 if (ACE_OS::strcmp (in.seq[i],
489 inout.seq[i])
490 || ACE_OS::strcmp (in.seq[i],
491 out.seq[i])
492 || ACE_OS::strcmp (in.seq[i],
493 ret.seq[i]))
495 return 0;
499 break;
500 case 11:
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
512 && in.c == inout.c
513 && in.s == inout.s
514 && in.o == inout.o
515 && ACE::is_equal (in.f, inout.f)
516 && in.b == inout.b
517 && ACE::is_equal (in.d, inout.d))
518 || !(in.l == out.l
519 && in.c == out.c
520 && in.s == out.s
521 && in.o == out.o
522 && ACE::is_equal (in.f, out.f)
523 && in.b == out.b
524 && ACE::is_equal (in.d, out.d))
525 || !(in.l == ret.l
526 && in.c == ret.c
527 && in.s == ret.s
528 && in.o == ret.o
529 && ACE::is_equal (in.f, ret.f)
530 && in.b == ret.b
531 && ACE::is_equal (in.d, ret.d)))
533 return 0;
536 break;
539 return 1;
542 CORBA::Boolean
543 Test_Big_Union::check_validity (CORBA::Request_ptr /*req*/)
545 //ACE_UNUSED_ARG (req);
546 return this->check_validity ();
549 void
550 Test_Big_Union::print_values ()