Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Param_Test / var_struct.cpp
blobb151e26ddb2220cc26af92463102ffb9e018b5bd
2 //=============================================================================
3 /**
4 * @file var_struct.cpp
6 * test variable sized structures
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "var_struct.h"
16 // ************************************************************************
17 // Test_Var_Struct
18 // ************************************************************************
20 Test_Var_Struct::Test_Var_Struct (void)
21 : opname_ (CORBA::string_dup ("test_var_struct")),
22 inout_ (new Param_Test::Var_Struct),
23 out_ (new Param_Test::Var_Struct),
24 ret_ (new Param_Test::Var_Struct)
28 Test_Var_Struct::~Test_Var_Struct (void)
30 CORBA::string_free (this->opname_);
31 this->opname_ = 0;
32 // the other data members will be freed as they are "_var"s and objects
33 // (rather than pointers to objects)
36 const char *
37 Test_Var_Struct::opname (void) const
39 return this->opname_;
42 void
43 Test_Var_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_Var_Struct);
51 req->invoke ();
53 const Param_Test::Var_Struct *tmp = 0;
54 req->return_value () >>= tmp;
55 this->ret_ = new Param_Test::Var_Struct (*tmp);
57 CORBA::NamedValue_ptr o2 =
58 req->arguments ()->item (1);
59 *o2->value () >>= tmp;
60 this->inout_ = new Param_Test::Var_Struct (*tmp);
62 CORBA::NamedValue_ptr o3 =
63 req->arguments ()->item (2);
64 *o3->value () >>= tmp;
65 this->out_ = new Param_Test::Var_Struct (*tmp);
68 int
69 Test_Var_Struct::init_parameters (Param_Test_ptr)
71 Generator *gen = GENERATOR::instance (); // value generator
73 // get some sequence length (not more than 10)
74 CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 10) + 1;
76 this->in_.dbl = 3.14159;
77 this->in_.dummy1 = gen->gen_string ();
78 this->in_.boole = gen->gen_short () % 2;
79 this->in_.dummy2 = gen->gen_string ();
80 this->in_.shrt = gen->gen_short ();
81 // set the length of the sequence
82 this->in_.seq.length (len);
84 // now set each individual element
85 for (CORBA::ULong i = 0; i < this->in_.seq.length (); i++)
87 // generate some arbitrary string to be filled into the ith location in
88 // the sequence
89 char *str = gen->gen_string ();
90 this->in_.seq[i] = str;
93 this->inout_->dbl = 0.0;
94 this->inout_->dummy1 = CORBA::string_dup ("");
95 this->inout_->boole = 0;
96 this->inout_->dummy2 = CORBA::string_dup ("");
97 this->inout_->shrt = 0;
98 // set the length of the sequence
99 this->inout_->seq.length (0);
101 return 0;
105 Test_Var_Struct::reset_parameters (void)
107 this->inout_ = new Param_Test::Var_Struct; // delete the previous ones
108 this->out_ = new Param_Test::Var_Struct;
109 this->ret_ = new Param_Test::Var_Struct;
111 this->inout_->dbl = 0.0;
112 this->inout_->dummy1 = CORBA::string_dup ("");
113 this->inout_->boole = 0;
114 this->inout_->dummy2 = CORBA::string_dup ("");
115 this->inout_->shrt = 0;
116 // set the length of the sequence
117 this->inout_->seq.length (0);
119 return 0;
123 Test_Var_Struct::run_sii_test (Param_Test_ptr objref)
127 Param_Test::Var_Struct_out out (this->out_.out ());
128 this->ret_ = objref->test_var_struct (this->in_,
129 this->inout_.inout (),
130 out);
132 return 0;
134 catch (const CORBA::Exception& ex)
136 ex._tao_print_exception ("Test_Var_Struct::run_sii_test\n");
139 return -1;
142 CORBA::Boolean
143 Test_Var_Struct::check_validity (void)
145 CORBA::Boolean flag = 0;
146 if (ACE::is_equal (this->in_.dbl, this->inout_->dbl) &&
147 ACE::is_equal (this->in_.dbl, this->out_->dbl) &&
148 ACE::is_equal (this->in_.dbl, this->ret_->dbl) &&
149 (!ACE_OS::strcmp (this->in_.dummy1, this->inout_->dummy1)) &&
150 (!ACE_OS::strcmp (this->in_.dummy1, this->out_->dummy1)) &&
151 (!ACE_OS::strcmp (this->in_.dummy1, this->ret_->dummy1)) &&
152 this->in_.boole == this->inout_->boole &&
153 this->in_.boole == this->out_->boole &&
154 this->in_.boole == this->ret_->boole &&
155 (!ACE_OS::strcmp (this->in_.dummy2, this->inout_->dummy2)) &&
156 (!ACE_OS::strcmp (this->in_.dummy2, this->out_->dummy2)) &&
157 (!ACE_OS::strcmp (this->in_.dummy2, this->ret_->dummy2)) &&
158 this->in_.shrt == this->inout_->shrt &&
159 this->in_.shrt == this->out_->shrt &&
160 this->in_.shrt == this->ret_->shrt &&
161 (this->in_.seq.length () == this->inout_->seq.length ()) &&
162 (this->in_.seq.length () == this->out_->seq.length ()) &&
163 (this->in_.seq.length () == this->ret_->seq.length ()))
165 flag = 1; // assume all are equal
166 // lengths are same. Now compare the contents
167 for (CORBA::ULong i=0; i < this->in_.seq.length () && flag; i++)
169 if (ACE_OS::strcmp (this->in_.seq[i], this->inout_->seq[i]) ||
170 ACE_OS::strcmp (this->in_.seq[i], this->out_->seq[i]) ||
171 ACE_OS::strcmp (this->in_.seq[i], this->ret_->seq[i]))
172 // not equal
173 flag = 0;
176 return flag;
179 CORBA::Boolean
180 Test_Var_Struct::check_validity (CORBA::Request_ptr )
182 return this->check_validity ();
185 void
186 Test_Var_Struct::print_values (void)
188 ACE_DEBUG ((LM_DEBUG,
189 "\n*=*=*=*=*=*=*=*=*=*=\n"
190 "in_.dummy1 = %s\n"
191 "inout_.dummy1 = %s\n"
192 "out_.dummy1 = %s\n"
193 "ret_.dummy1 = %s\n",
194 this->in_.dummy1.in (),
195 this->inout_->dummy1.in (),
196 this->out_->dummy1.in (),
197 this->ret_->dummy1.in ()));
199 ACE_DEBUG ((LM_DEBUG,
200 "\n*=*=*=*=*=*=*=*=*=*=\n"
201 "in_.dummy2 = %s\n"
202 "inout_.dummy2 = %s\n"
203 "out_.dummy2 = %s\n"
204 "ret_.dummy2 = %s\n",
205 this->in_.dummy2.in (),
206 this->inout_->dummy2.in (),
207 this->out_->dummy2.in (),
208 this->ret_->dummy2.in ()));
210 CORBA::ULong i;
211 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
212 for (i=0; i < this->in_.seq.length (); i++)
214 ACE_DEBUG ((LM_DEBUG,
215 "Element #%d\n"
216 "in.seq : %s\n",
218 (this->in_.seq[i]? (const char *)this->in_.seq[i]:"<nul>")));
220 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
221 for (i=0; this->inout_.ptr () && (i < this->inout_->seq.length ()); i++)
223 ACE_DEBUG ((LM_DEBUG,
224 "Element #%d\n"
225 "inout : %s\n",
227 (this->inout_->seq[i]? (const char *)this->inout_->seq[i]:"<nul>")));
229 if (!this->inout_.ptr ())
230 ACE_DEBUG ((LM_DEBUG, "\ninout struct does not exist\n"));
231 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
232 for (i=0; this->out_.ptr () && (i < this->out_->seq.length ()); i++)
234 ACE_DEBUG ((LM_DEBUG,
235 "Element #%d\n"
236 "in : %s\n",
238 (this->out_->seq[i]? (const char *)this->out_->seq[i]:"<nul>")));
240 if (!this->out_.ptr ())
241 ACE_DEBUG ((LM_DEBUG, "\nout struct is NUL\n"));
242 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
243 for (i=0; this->ret_.ptr () && (i < this->ret_->seq.length ()); i++)
245 ACE_DEBUG ((LM_DEBUG,
246 "Element #%d\n"
247 "in : %s\n",
249 (this->ret_->seq[i]? (const char *)this->ret_->seq[i]:"<nul>")));
251 if (!this->ret_.ptr ())
252 ACE_DEBUG ((LM_DEBUG, "\nret struct is NUL\n"));
253 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));