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 (void)
23 : opname_ (CORBA::string_dup ("test_recursive_union"))
27 Test_Recursive_Union::~Test_Recursive_Union (void)
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 (void) 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 (void)
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");
129 Test_Recursive_Union::check_validity (void)
131 // Pair in_ with each of the returned values and call the
132 // helper function with that pair.
134 if (this->deep_check (this->in_
, this->inout_
.in ()) == 0)
136 ACE_DEBUG ((LM_DEBUG
,
137 "mismatch of inout arg\n"));
142 if (this->deep_check (this->in_
, this->out_
.in ()) == 0)
144 ACE_DEBUG ((LM_DEBUG
,
145 "mismatch of out arg\n"));
150 if (this->deep_check (this->in_
, this->ret_
.in ()) == 0)
152 ACE_DEBUG ((LM_DEBUG
,
153 "mismatch of ret value\n"));
158 // If we get this far, all is correct.
163 Test_Recursive_Union::check_validity (CORBA::Request_ptr
)
165 return this->check_validity ();
169 Test_Recursive_Union::print_values (void)
173 // Private helper function to recursively initialize the union.
175 Test_Recursive_Union::deep_init (Param_Test::Recursive_Union
&ru
,
180 // No more recursion, just insert a nested_rec_union.
182 CORBA::ULong nested_depth
=
183 (CORBA::ULong
) (gen
->gen_long () % MAX_DEPTH
) + 1;
185 Param_Test::nested_rec_union nru
;
187 this->deep_init_nested (nru
,
191 ru
.nested_member (nru
);
193 Param_Test::RecUnionSeq
tmp (MAX_SEQ_LENGTH
);
201 // Generate a member sequence.
203 (CORBA::ULong
) (gen
->gen_long () % MAX_SEQ_LENGTH
) + 1;
205 // This line is TAO-specific, but some compilers we support
206 // are broken in their handling of the portable scoped typedef
207 // required by CORBA 2.3
208 Param_Test::RecUnionSeq
tmp (MAX_SEQ_LENGTH
);
214 // We recurse for each element of the member sequence.
215 for (CORBA::ULong i
= 0; i
< len
; i
++)
217 this->deep_init (ru
.rec_member ()[i
],
224 // Private helper function to recursively initialize the nested union.
226 Test_Recursive_Union::deep_init_nested (Param_Test::nested_rec_union
&nu
,
233 nu
.value (gen
->gen_long ());
239 // Generate a sequence length.
241 (CORBA::ULong
) (gen
->gen_long () % MAX_SEQ_LENGTH
) + 1;
243 // This line is TAO-specific, but some compilers we support
244 // are broken in their handling of the portable scoped typedef
245 // required by CORBA 2.3
246 Param_Test::NestedSeq
tmp (MAX_SEQ_LENGTH
);
250 nu
.nested_rec_member (tmp
);
252 // We recurse for each element of the member sequence.
253 for (CORBA::ULong i
= 0; i
< len
; i
++)
255 this->deep_init_nested (nu
.nested_rec_member ()[i
],
262 // Private helper function for check_validity (so we can recurse).
264 Test_Recursive_Union::deep_check (const Param_Test::Recursive_Union
&in_union
,
265 const Param_Test::Recursive_Union
&test_union
)
267 // Do the discriminators match?
268 if (in_union
._d () != test_union
._d ())
270 ACE_DEBUG ((LM_DEBUG
,
271 "mismatch of Recursive_Union discriminators\n"));
276 switch (in_union
._d ())
278 // Active member is the Recursive_Union sequence.
281 // Do the sequence lengths match?
282 if (in_union
.rec_member ().length () !=
283 test_union
.rec_member ().length ())
285 ACE_DEBUG ((LM_DEBUG
,
286 "mismatch of Recursive_Union member sequence lengths\n"));
291 for (CORBA::ULong i
= 0; i
< in_union
.rec_member ().length (); i
++)
293 if (!this->deep_check (in_union
.rec_member ()[i
],
294 test_union
.rec_member ()[i
]))
296 ACE_DEBUG ((LM_DEBUG
,
297 "mismatch of contained Recursive_Unions\n"));
306 // Active member is the nested union.
308 return this->deep_check_nested (in_union
.nested_member (),
309 test_union
.nested_member ());
312 ACE_DEBUG ((LM_DEBUG
,
313 "bad discriminator value\n"));
322 Test_Recursive_Union::deep_check_nested (const Param_Test::nested_rec_union
&in
,
323 const Param_Test::nested_rec_union
&test
)
325 if (in
._d () != test
._d ())
327 ACE_DEBUG ((LM_DEBUG
,
328 "mismatch of nested union discriminators\n"));
335 // Active member is the long integer.
337 // Do the nested_rec_union member values match?
338 if (in
.value () != test
.value ())
340 ACE_DEBUG ((LM_DEBUG
,
341 "mismatch of nested_rec_union member values\n"));
348 // Active member is the recursive sequence.
351 // Do the sequence lengths match?
352 if (in
.nested_rec_member ().length () !=
353 test
.nested_rec_member ().length ())
355 ACE_DEBUG ((LM_DEBUG
,
356 "mismatch of nested_rec_union member sequence lengths\n"));
361 for (CORBA::ULong i
= 0; i
< in
.nested_rec_member ().length (); i
++)
363 if (!this->deep_check_nested (in
.nested_rec_member ()[i
],
364 test
.nested_rec_member ()[i
]))
366 ACE_DEBUG ((LM_DEBUG
,
367 "mismatch of contained nested_rec_unions\n"));