Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Param_Test / var_struct.cpp
blobe865893a4bce2a2aadf0965d6efbbd568fba472b
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 ()
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 ()
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 () 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 ()
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");
138 return -1;
141 CORBA::Boolean
142 Test_Var_Struct::check_validity ()
144 CORBA::Boolean flag = 0;
145 if (ACE::is_equal (this->in_.dbl, this->inout_->dbl) &&
146 ACE::is_equal (this->in_.dbl, this->out_->dbl) &&
147 ACE::is_equal (this->in_.dbl, this->ret_->dbl) &&
148 (!ACE_OS::strcmp (this->in_.dummy1, this->inout_->dummy1)) &&
149 (!ACE_OS::strcmp (this->in_.dummy1, this->out_->dummy1)) &&
150 (!ACE_OS::strcmp (this->in_.dummy1, this->ret_->dummy1)) &&
151 this->in_.boole == this->inout_->boole &&
152 this->in_.boole == this->out_->boole &&
153 this->in_.boole == this->ret_->boole &&
154 (!ACE_OS::strcmp (this->in_.dummy2, this->inout_->dummy2)) &&
155 (!ACE_OS::strcmp (this->in_.dummy2, this->out_->dummy2)) &&
156 (!ACE_OS::strcmp (this->in_.dummy2, this->ret_->dummy2)) &&
157 this->in_.shrt == this->inout_->shrt &&
158 this->in_.shrt == this->out_->shrt &&
159 this->in_.shrt == this->ret_->shrt &&
160 (this->in_.seq.length () == this->inout_->seq.length ()) &&
161 (this->in_.seq.length () == this->out_->seq.length ()) &&
162 (this->in_.seq.length () == this->ret_->seq.length ()))
164 flag = 1; // assume all are equal
165 // lengths are same. Now compare the contents
166 for (CORBA::ULong i=0; i < this->in_.seq.length () && flag; i++)
168 if (ACE_OS::strcmp (this->in_.seq[i], this->inout_->seq[i]) ||
169 ACE_OS::strcmp (this->in_.seq[i], this->out_->seq[i]) ||
170 ACE_OS::strcmp (this->in_.seq[i], this->ret_->seq[i]))
171 // not equal
172 flag = 0;
175 return flag;
178 CORBA::Boolean
179 Test_Var_Struct::check_validity (CORBA::Request_ptr )
181 return this->check_validity ();
184 void
185 Test_Var_Struct::print_values ()
187 ACE_DEBUG ((LM_DEBUG,
188 "\n*=*=*=*=*=*=*=*=*=*=\n"
189 "in_.dummy1 = %C\n"
190 "inout_.dummy1 = %C\n"
191 "out_.dummy1 = %C\n"
192 "ret_.dummy1 = %C\n",
193 this->in_.dummy1.in (),
194 this->inout_->dummy1.in (),
195 this->out_->dummy1.in (),
196 this->ret_->dummy1.in ()));
198 ACE_DEBUG ((LM_DEBUG,
199 "\n*=*=*=*=*=*=*=*=*=*=\n"
200 "in_.dummy2 = %C\n"
201 "inout_.dummy2 = %C\n"
202 "out_.dummy2 = %C\n"
203 "ret_.dummy2 = %C\n",
204 this->in_.dummy2.in (),
205 this->inout_->dummy2.in (),
206 this->out_->dummy2.in (),
207 this->ret_->dummy2.in ()));
209 CORBA::ULong i;
210 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
211 for (i=0; i < this->in_.seq.length (); i++)
213 ACE_DEBUG ((LM_DEBUG,
214 "Element #%d\n"
215 "in.seq : %C\n",
217 (this->in_.seq[i]? (const char *)this->in_.seq[i]:"<nul>")));
219 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
220 for (i=0; this->inout_.ptr () && (i < this->inout_->seq.length ()); i++)
222 ACE_DEBUG ((LM_DEBUG,
223 "Element #%d\n"
224 "inout : %C\n",
226 (this->inout_->seq[i]? (const char *)this->inout_->seq[i]:"<nul>")));
228 if (!this->inout_.ptr ())
229 ACE_DEBUG ((LM_DEBUG, "\ninout struct does not exist\n"));
230 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
231 for (i=0; this->out_.ptr () && (i < this->out_->seq.length ()); i++)
233 ACE_DEBUG ((LM_DEBUG,
234 "Element #%d\n"
235 "in : %C\n",
237 (this->out_->seq[i]? (const char *)this->out_->seq[i]:"<nul>")));
239 if (!this->out_.ptr ())
240 ACE_DEBUG ((LM_DEBUG, "\nout struct is NUL\n"));
241 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
242 for (i=0; this->ret_.ptr () && (i < this->ret_->seq.length ()); i++)
244 ACE_DEBUG ((LM_DEBUG,
245 "Element #%d\n"
246 "in : %C\n",
248 (this->ret_->seq[i]? (const char *)this->ret_->seq[i]:"<nul>")));
250 if (!this->ret_.ptr ())
251 ACE_DEBUG ((LM_DEBUG, "\nret struct is NUL\n"));
252 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));