2 //=============================================================================
4 * @file recursive_union.cpp
6 * test union that contains a sequence of itself
8 * @author Jeff Parsons <parsons@cs.wustl.edu>
10 //=============================================================================
13 #include "recursive_union.h"
15 const CORBA::ULong MAX_DEPTH
= 3;
16 const CORBA::ULong MAX_SEQ_LENGTH
= 2;
18 // ************************************************************************
19 // Test_Recursive_Union
20 // ************************************************************************
22 Test_Recursive_Union::Test_Recursive_Union ()
23 : opname_ (CORBA::string_dup ("test_recursive_union"))
27 Test_Recursive_Union::~Test_Recursive_Union ()
29 CORBA::string_free (this->opname_
);
31 // the other data members will be freed as they are "_var"s and objects
32 // (rather than pointers to objects)
36 Test_Recursive_Union::opname () const
42 Test_Recursive_Union::dii_req_invoke (CORBA::Request
*req
)
44 req
->add_in_arg ("s1") <<= this->in_
;
45 req
->add_inout_arg ("s2") <<= this->inout_
.in ();
46 req
->add_out_arg ("s3") <<= this->out_
.in ();
48 req
->set_return_type (Param_Test::_tc_Recursive_Union
);
52 const Param_Test::Recursive_Union
*tmp
= 0;
53 req
->return_value () >>= tmp
;
54 this->ret_
= new Param_Test::Recursive_Union (*tmp
);
56 CORBA::NamedValue_ptr o2
=
57 req
->arguments ()->item (1);
58 *o2
->value () >>= tmp
;
59 this->inout_
= new Param_Test::Recursive_Union (*tmp
);
61 CORBA::NamedValue_ptr o3
=
62 req
->arguments ()->item (2);
63 *o3
->value () >>= tmp
;
64 this->out_
= new Param_Test::Recursive_Union (*tmp
);
68 Test_Recursive_Union::init_parameters (Param_Test_ptr
)
70 // The client calls init_parameters() before the first
71 // call and reset_parameters() after each call. For this
72 // test, we want the same thing to happen each time.
73 return this->reset_parameters ();
77 Test_Recursive_Union::reset_parameters ()
79 // Since these are _vars, we do this the first call and
80 // every call thereafter (if any).
81 this->inout_
= new Param_Test::Recursive_Union
;
82 this->out_
= new Param_Test::Recursive_Union
;
83 this->ret_
= new Param_Test::Recursive_Union
;
86 Generator
*gen
= GENERATOR::instance ();
88 // Set the depth of recursion.
90 (CORBA::ULong
) (gen
->gen_long () % MAX_DEPTH
) + 1;
92 // Create a nested union to put in inout_.
93 Param_Test::nested_rec_union nru
;
97 this->inout_
->nested_member (nru
);
99 // Call the recursive helper function. to initialize in_.
100 this->deep_init (this->in_
,
108 Test_Recursive_Union::run_sii_test (Param_Test_ptr objref
)
112 Param_Test::Recursive_Union_out
out (this->out_
.out ());
114 this->ret_
= objref
->test_recursive_union (this->in_
,
115 this->inout_
.inout (),
120 catch (const CORBA::Exception
& ex
)
122 ex
._tao_print_exception ("Test_Recursive_Union::run_sii_test\n");
128 Test_Recursive_Union::check_validity ()
130 // Pair in_ with each of the returned values and call the
131 // helper function with that pair.
133 if (this->deep_check (this->in_
, this->inout_
.in ()) == 0)
135 ACE_DEBUG ((LM_DEBUG
,
136 "mismatch of inout arg\n"));
141 if (this->deep_check (this->in_
, this->out_
.in ()) == 0)
143 ACE_DEBUG ((LM_DEBUG
,
144 "mismatch of out arg\n"));
149 if (this->deep_check (this->in_
, this->ret_
.in ()) == 0)
151 ACE_DEBUG ((LM_DEBUG
,
152 "mismatch of ret value\n"));
157 // If we get this far, all is correct.
162 Test_Recursive_Union::check_validity (CORBA::Request_ptr
)
164 return this->check_validity ();
168 Test_Recursive_Union::print_values ()
172 // Private helper function to recursively initialize the union.
174 Test_Recursive_Union::deep_init (Param_Test::Recursive_Union
&ru
,
179 // No more recursion, just insert a nested_rec_union.
181 CORBA::ULong nested_depth
=
182 (CORBA::ULong
) (gen
->gen_long () % MAX_DEPTH
) + 1;
184 Param_Test::nested_rec_union nru
;
186 this->deep_init_nested (nru
,
190 ru
.nested_member (nru
);
192 Param_Test::RecUnionSeq
tmp (MAX_SEQ_LENGTH
);
200 // Generate a member sequence.
202 (CORBA::ULong
) (gen
->gen_long () % MAX_SEQ_LENGTH
) + 1;
204 // This line is TAO-specific, but some compilers we support
205 // are broken in their handling of the portable scoped typedef
206 // required by CORBA 2.3
207 Param_Test::RecUnionSeq
tmp (MAX_SEQ_LENGTH
);
213 // We recurse for each element of the member sequence.
214 for (CORBA::ULong i
= 0; i
< len
; i
++)
216 this->deep_init (ru
.rec_member ()[i
],
223 // Private helper function to recursively initialize the nested union.
225 Test_Recursive_Union::deep_init_nested (Param_Test::nested_rec_union
&nu
,
232 nu
.value (gen
->gen_long ());
238 // Generate a sequence length.
240 (CORBA::ULong
) (gen
->gen_long () % MAX_SEQ_LENGTH
) + 1;
242 // This line is TAO-specific, but some compilers we support
243 // are broken in their handling of the portable scoped typedef
244 // required by CORBA 2.3
245 Param_Test::NestedSeq
tmp (MAX_SEQ_LENGTH
);
249 nu
.nested_rec_member (tmp
);
251 // We recurse for each element of the member sequence.
252 for (CORBA::ULong i
= 0; i
< len
; i
++)
254 this->deep_init_nested (nu
.nested_rec_member ()[i
],
261 // Private helper function for check_validity (so we can recurse).
263 Test_Recursive_Union::deep_check (const Param_Test::Recursive_Union
&in_union
,
264 const Param_Test::Recursive_Union
&test_union
)
266 // Do the discriminators match?
267 if (in_union
._d () != test_union
._d ())
269 ACE_DEBUG ((LM_DEBUG
,
270 "mismatch of Recursive_Union discriminators\n"));
275 switch (in_union
._d ())
277 // Active member is the Recursive_Union sequence.
280 // Do the sequence lengths match?
281 if (in_union
.rec_member ().length () !=
282 test_union
.rec_member ().length ())
284 ACE_DEBUG ((LM_DEBUG
,
285 "mismatch of Recursive_Union member sequence lengths\n"));
290 for (CORBA::ULong i
= 0; i
< in_union
.rec_member ().length (); i
++)
292 if (!this->deep_check (in_union
.rec_member ()[i
],
293 test_union
.rec_member ()[i
]))
295 ACE_DEBUG ((LM_DEBUG
,
296 "mismatch of contained Recursive_Unions\n"));
305 // Active member is the nested union.
307 return this->deep_check_nested (in_union
.nested_member (),
308 test_union
.nested_member ());
311 ACE_DEBUG ((LM_DEBUG
,
312 "bad discriminator value\n"));
321 Test_Recursive_Union::deep_check_nested (const Param_Test::nested_rec_union
&in
,
322 const Param_Test::nested_rec_union
&test
)
324 if (in
._d () != test
._d ())
326 ACE_DEBUG ((LM_DEBUG
,
327 "mismatch of nested union discriminators\n"));
334 // Active member is the long integer.
336 // Do the nested_rec_union member values match?
337 if (in
.value () != test
.value ())
339 ACE_DEBUG ((LM_DEBUG
,
340 "mismatch of nested_rec_union member values\n"));
347 // Active member is the recursive sequence.
350 // Do the sequence lengths match?
351 if (in
.nested_rec_member ().length () !=
352 test
.nested_rec_member ().length ())
354 ACE_DEBUG ((LM_DEBUG
,
355 "mismatch of nested_rec_union member sequence lengths\n"));
360 for (CORBA::ULong i
= 0; i
< in
.nested_rec_member ().length (); i
++)
362 if (!this->deep_check_nested (in
.nested_rec_member ()[i
],
363 test
.nested_rec_member ()[i
]))
365 ACE_DEBUG ((LM_DEBUG
,
366 "mismatch of contained nested_rec_unions\n"));