2 //=============================================================================
4 * @file recursive_struct.cpp
6 * test structure that contains a sequence of itself
8 * @author Aniruddha Gokhale
11 //=============================================================================
14 #include "recursive_struct.h"
16 const CORBA::ULong MAX_DEPTH
= 5;
17 const CORBA::ULong MAX_SEQ_LENGTH
= 3;
19 // ************************************************************************
20 // Test_Recursive_Struct
21 // ************************************************************************
23 Test_Recursive_Struct::Test_Recursive_Struct ()
24 : opname_ (CORBA::string_dup ("test_recursive_struct"))
28 Test_Recursive_Struct::~Test_Recursive_Struct ()
30 CORBA::string_free (this->opname_
);
32 // the other data members will be freed as they are "_var"s and objects
33 // (rather than pointers to objects)
37 Test_Recursive_Struct::opname () const
43 Test_Recursive_Struct::dii_req_invoke (CORBA::Request
*req
)
45 req
->add_in_arg ("s1") <<= this->in_
;
46 req
->add_inout_arg ("s2") <<= this->inout_
.in ();
47 req
->add_out_arg ("s3") <<= this->out_
.in ();
49 req
->set_return_type (Param_Test::_tc_Recursive_Struct
);
53 const Param_Test::Recursive_Struct
*tmp
= 0;
54 req
->return_value () >>= tmp
;
55 this->ret_
= new Param_Test::Recursive_Struct (*tmp
);
57 CORBA::NamedValue_ptr o2
=
58 req
->arguments ()->item (1);
59 *o2
->value () >>= tmp
;
60 this->inout_
= new Param_Test::Recursive_Struct (*tmp
);
62 CORBA::NamedValue_ptr o3
=
63 req
->arguments ()->item (2);
64 *o3
->value () >>= tmp
;
65 this->out_
= new Param_Test::Recursive_Struct (*tmp
);
69 Test_Recursive_Struct::init_parameters (Param_Test_ptr
)
71 // The client calls init_parameters() before the first
72 // call and reset_parameters() after each call. For this
73 // test, we want the same thing to happen each time.
74 return this->reset_parameters ();
78 Test_Recursive_Struct::reset_parameters ()
80 // Since these are _vars, we do this the first call and
81 // every call thereafter (if any).
82 this->inout_
= new Param_Test::Recursive_Struct
;
83 this->out_
= new Param_Test::Recursive_Struct
;
84 this->ret_
= new Param_Test::Recursive_Struct
;
87 Generator
*gen
= GENERATOR::instance ();
89 // Set the depth of recursion.
90 CORBA::ULong depth
= (CORBA::ULong
) (gen
->gen_long () % MAX_DEPTH
) + 1;
92 // No recursion for inout_ until after the call.
93 this->inout_
->children
.length (0);
95 // Keeps Purify happy.
98 // Call the recursive helper function.
99 this->deep_init (this->in_
,
107 Test_Recursive_Struct::run_sii_test (Param_Test_ptr objref
)
111 Param_Test::Recursive_Struct_out
out (this->out_
.out ());
113 this->ret_
= objref
->test_recursive_struct (this->in_
,
114 this->inout_
.inout (),
119 catch (const CORBA::Exception
& ex
)
121 ex
._tao_print_exception ("Test_Recursive_Struct::run_sii_test\n");
127 Test_Recursive_Struct::check_validity ()
129 // Pair in_ with each of the returned values and call the
130 // helper function with that pair.
132 if (this->deep_check (this->in_
, this->inout_
.in ()) == 0)
134 ACE_DEBUG ((LM_DEBUG
,
135 "mismatch of inout arg\n"));
140 if (this->deep_check (this->in_
, this->out_
.in ()) == 0)
142 ACE_DEBUG ((LM_DEBUG
,
143 "mismatch of out arg\n"));
148 if (this->deep_check (this->in_
, this->ret_
.in ()) == 0)
150 ACE_DEBUG ((LM_DEBUG
,
151 "mismatch of ret value\n"));
156 // If we get this far, all is correct.
161 Test_Recursive_Struct::check_validity (CORBA::Request_ptr
)
163 return this->check_validity ();
167 Test_Recursive_Struct::print_values ()
171 // Private helper function to recursively initialize the struct.
173 Test_Recursive_Struct::deep_init (Param_Test::Recursive_Struct
&rs
,
177 rs
.x
= gen
->gen_long ();
180 // No more recursion.
182 rs
.children
.length (0);
188 // Generate a sequence length.
189 CORBA::ULong len
= (CORBA::ULong
) (gen
->gen_long () % MAX_SEQ_LENGTH
) + 1;
191 rs
.children
.length (len
);
193 // We recurse for each element of the member sequence.
194 for (CORBA::ULong i
= 0; i
< len
; i
++)
196 this->deep_init (rs
.children
[i
],
203 // Private helper function for check_validity (so we can recurse).
205 Test_Recursive_Struct::deep_check (const Param_Test::Recursive_Struct
&in_struct
,
206 const Param_Test::Recursive_Struct
&test_struct
)
208 // Do the CORBA::Long members match?
209 if (in_struct
.x
!= test_struct
.x
)
211 ACE_DEBUG ((LM_DEBUG
,
212 "mismatch of CORBA::Long struct members\n"));
217 // Do the sequence lengths match?
218 if (in_struct
.children
.length () != test_struct
.children
.length ())
220 ACE_DEBUG ((LM_DEBUG
,
221 "mismatch of member sequence lengths\n"));
226 // At the bottom level, the length is 0 and we skip this part.
227 // Otherwise recurse.
228 for (CORBA::ULong i
= 0; i
< in_struct
.children
.length (); i
++)
230 if (!this->deep_check (in_struct
.children
[i
],
231 test_struct
.children
[i
]))
233 ACE_DEBUG ((LM_DEBUG
,
234 "mismatch of contained structs\n"));