Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / ub_struct_seq.cpp
blob41b7bfa40ecae46bc81d3497d41fc014a44ba7f3
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file ub_struct_seq.cpp
7 * tests unbounded struct sequences
9 * @author Aniruddha Gokhale
11 //=============================================================================
14 #include "helper.h"
15 #include "ub_struct_seq.h"
17 // ************************************************************************
18 // Test_Struct_Sequence
19 // ************************************************************************
21 Test_Struct_Sequence::Test_Struct_Sequence ()
22 : opname_ (CORBA::string_dup ("test_struct_sequence")),
23 inout_ (new Param_Test::StructSeq),
24 out_ (new Param_Test::StructSeq),
25 ret_ (new Param_Test::StructSeq)
29 Test_Struct_Sequence::~Test_Struct_Sequence ()
31 CORBA::string_free (this->opname_);
32 this->opname_ = 0;
33 // the other data members will be freed as they are "_var"s and objects
34 // (rather than pointers to objects)
37 const char *
38 Test_Struct_Sequence::opname () const
40 return this->opname_;
43 void
44 Test_Struct_Sequence::dii_req_invoke (CORBA::Request *req)
46 req->add_in_arg ("s1") <<= this->in_;
47 req->add_inout_arg ("s2") <<= this->inout_.in ();
48 req->add_out_arg ("s3") <<= this->out_.in ();
50 req->set_return_type (Param_Test::_tc_StructSeq);
52 req->invoke ();
54 const Param_Test::StructSeq *tmp = 0;
55 req->return_value () >>= tmp;
56 this->ret_ = new Param_Test::StructSeq (*tmp);
58 CORBA::NamedValue_ptr o2 =
59 req->arguments ()->item (1);
60 *o2->value () >>= tmp;
61 this->inout_ = new Param_Test::StructSeq (*tmp);
63 CORBA::NamedValue_ptr o3 =
64 req->arguments ()->item (2);
65 *o3->value () >>= tmp;
66 this->out_ = new Param_Test::StructSeq (*tmp);
69 int
70 Test_Struct_Sequence::init_parameters (Param_Test_ptr)
72 Generator *gen = GENERATOR::instance (); // value generator
74 // get some sequence length (not more than 10)
75 CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 10) + 1;
77 // set the length of the sequence
78 this->in_.length (len);
79 this->inout_->length (len);
80 // now set each individual element
81 for (CORBA::ULong i = 0; i < this->in_.length (); i++)
83 // generate some arbitrary struct to be filled into the ith location in
84 // the sequence
85 this->in_[i] = gen->gen_fixed_struct ();
86 this->inout_[i] = gen->gen_fixed_struct ();
88 return 0;
91 int
92 Test_Struct_Sequence::reset_parameters ()
94 this->inout_ = new Param_Test::StructSeq; // delete the previous one
95 this->out_ = new Param_Test::StructSeq;
96 this->ret_ = new Param_Test::StructSeq;
97 return 0;
101 Test_Struct_Sequence::run_sii_test (Param_Test_ptr objref)
105 Param_Test::StructSeq_out out (this->out_.out ());
107 this->ret_ = objref->test_struct_sequence (this->in_,
108 this->inout_.inout (),
109 out);
111 return 0;
113 catch (const CORBA::Exception& ex)
115 ex._tao_print_exception ("Test_Struct_Sequence::run_sii_test\n");
117 return -1;
120 CORBA::Boolean
121 Test_Struct_Sequence::check_validity ()
123 if (this->compare (this->in_, this->inout_.in ()) &&
124 this->compare (this->in_, this->out_.in ()) &&
125 this->compare (this->in_, this->ret_.in ()))
126 return 1;
127 else
128 return 0;
131 CORBA::Boolean
132 Test_Struct_Sequence::check_validity (CORBA::Request_ptr )
134 return this->check_validity ();
137 void
138 Test_Struct_Sequence::print_values ()
140 ACE_DEBUG ((LM_DEBUG,
141 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
142 "IN sequence\n"));
143 this->print_sequence (this->in_);
144 ACE_DEBUG ((LM_DEBUG,
145 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
146 "INOUT sequence\n"));
147 this->print_sequence (this->inout_.in ());
148 ACE_DEBUG ((LM_DEBUG,
149 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
150 "OUT sequence\n"));
151 this->print_sequence (this->out_.in ());
152 ACE_DEBUG ((LM_DEBUG,
153 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
154 "RET sequence\n"));
155 this->print_sequence (this->ret_.in ());
158 CORBA::Boolean
159 Test_Struct_Sequence::compare (const Param_Test::StructSeq &s1,
160 const Param_Test::StructSeq &s2)
162 if (s1.maximum () != s2.maximum ())
163 return 0;
164 if (s1.length () != s2.length ())
165 return 0;
167 for (CORBA::ULong i=0; i < s1.length (); i++)
169 const Param_Test::Fixed_Struct& vs1 = s1[i];
170 const Param_Test::Fixed_Struct& vs2 = s2[i];
172 if (vs1.l != vs2.l
173 || vs1.c != vs2.c
174 || vs1.s != vs2.s
175 || vs1.o != vs2.o
176 || !ACE::is_equal (vs1.f, vs2.f)
177 || vs1.b != vs2.b
178 || !ACE::is_equal (vs1.d, vs2.d))
179 return 0;
182 return 1; // success
185 void
186 Test_Struct_Sequence::print_sequence (const Param_Test::StructSeq &s)
188 ACE_DEBUG ((LM_DEBUG,
189 "maximum = %d\n"
190 "length = %d\n",
191 s.maximum (),
192 s.length ()));
193 ACE_DEBUG ((LM_DEBUG, "Elements -\n"));
194 for (CORBA::ULong i=0; i < s.length (); i++)
196 const Param_Test::Fixed_Struct& vs = s[i];
198 ACE_DEBUG ((LM_DEBUG,
199 "Element #%d\n"
200 "\tl = %d\n"
201 "\tc = %c\n"
202 "\ts = %d\n"
203 "\to = %x\n"
204 "\tf = %f\n"
205 "\tb = %d\n"
206 "\td = %f\n",
208 vs.l, vs.c, vs.s, vs.o, vs.f, vs.b, vs.d));
213 // ************************************************************************
214 // Test_Unbounded_Struct_Sequence
215 // ************************************************************************
217 Test_Unbounded_Struct_Sequence::Test_Unbounded_Struct_Sequence ()
218 : opname_ (CORBA::string_dup ("test_unbounded_struct_sequence")),
219 inout_ (new Param_Test::PathSpec),
220 out_ (new Param_Test::PathSpec),
221 ret_ (new Param_Test::PathSpec)
225 Test_Unbounded_Struct_Sequence::~Test_Unbounded_Struct_Sequence ()
227 CORBA::string_free (this->opname_);
228 this->opname_ = 0;
229 // the other data members will be freed as they are "_var"s and objects
230 // (rather than pointers to objects)
233 const char *
234 Test_Unbounded_Struct_Sequence::opname () const
236 return this->opname_;
239 void
240 Test_Unbounded_Struct_Sequence::dii_req_invoke (CORBA::Request *req)
242 req->add_in_arg ("s1") <<= this->in_;
243 req->add_inout_arg ("s2") <<= this->inout_.in ();
244 req->add_out_arg ("s3") <<= this->out_.in ();
246 req->set_return_type (Param_Test::_tc_PathSpec);
248 req->invoke ();
250 const Param_Test::PathSpec *tmp = 0;
251 req->return_value () >>= tmp;
252 this->ret_ = new Param_Test::PathSpec (*tmp);
254 CORBA::NamedValue_ptr o2 =
255 req->arguments ()->item (1);
256 *o2->value () >>= tmp;
257 this->inout_ = new Param_Test::PathSpec (*tmp);
259 CORBA::NamedValue_ptr o3 =
260 req->arguments ()->item (2);
261 *o3->value () >>= tmp;
262 this->out_ = new Param_Test::PathSpec (*tmp);
266 Test_Unbounded_Struct_Sequence::init_parameters (Param_Test_ptr)
268 Generator *gen = GENERATOR::instance (); // value generator
270 // get some sequence length (not more than 10)
271 CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 10) + 1;
273 // set the length of the sequence
274 this->in_.length (len);
275 this->inout_->length (len);
276 // now set each individual element
278 for (CORBA::ULong i = 0; i < this->in_.length (); i++)
280 // generate some arbitrary string to be filled into the ith location in
281 // the sequence
282 this->in_[i] = gen->gen_step ();
283 this->inout_[i] = gen->gen_step ();
285 return 0;
289 Test_Unbounded_Struct_Sequence::reset_parameters ()
291 this->inout_ = new Param_Test::PathSpec; // delete the previous one
292 this->out_ = new Param_Test::PathSpec;
293 this->ret_ = new Param_Test::PathSpec;
294 return 0;
298 Test_Unbounded_Struct_Sequence::run_sii_test (Param_Test_ptr objref)
300 Param_Test::PathSpec_out out (this->out_.out ());
301 this->ret_ = objref->test_unbounded_struct_sequence (this->in_,
302 this->inout_.inout (),
303 out);
305 return 0;
308 CORBA::Boolean
309 Test_Unbounded_Struct_Sequence::check_validity ()
311 if (this->compare (this->in_, this->inout_.in ()) &&
312 this->compare (this->in_, this->out_.in ()) &&
313 this->compare (this->in_, this->ret_.in ()))
314 return 1;
315 else
316 return 0;
319 CORBA::Boolean
320 Test_Unbounded_Struct_Sequence::check_validity (CORBA::Request_ptr )
322 return this->check_validity ();
325 void
326 Test_Unbounded_Struct_Sequence::print_values ()
328 ACE_DEBUG ((LM_DEBUG,
329 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
330 "IN sequence\n"));
331 this->print_sequence (this->in_);
332 ACE_DEBUG ((LM_DEBUG,
333 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
334 "INOUT sequence\n"));
335 this->print_sequence (this->inout_.in ());
336 ACE_DEBUG ((LM_DEBUG,
337 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
338 "OUT sequence\n"));
339 this->print_sequence (this->out_.in ());
340 ACE_DEBUG ((LM_DEBUG,
341 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
342 "RET sequence\n"));
343 this->print_sequence (this->ret_.in ());
346 CORBA::Boolean
347 Test_Unbounded_Struct_Sequence::compare (const Param_Test::PathSpec &s1,
348 const Param_Test::PathSpec &s2)
350 if (s1.maximum () != s2.maximum ())
351 return 0;
352 if (s1.length () != s2.length ())
353 return 0;
355 for (CORBA::ULong i=0; i < s1.length (); i++)
357 const Param_Test::Step& vs1 = s1[i];
358 const Param_Test::Step& vs2 = s2[i];
360 if (ACE_OS::strcmp (vs1.name.id.in (), vs2.name.id.in ())
361 || ACE_OS::strcmp (vs1.name.kind.in (), vs2.name.kind.in ())
362 || vs1.process != vs2.process)
363 return 0;
365 return 1; // success
368 void
369 Test_Unbounded_Struct_Sequence::print_sequence (const Param_Test::PathSpec &s)
371 ACE_DEBUG ((LM_DEBUG,
372 "maximum = %d\n"
373 "length = %d\n",
374 s.maximum (),
375 s.length ()));
376 ACE_DEBUG ((LM_DEBUG, "Elements -\n"));
377 for (CORBA::ULong i=0; i < s.length (); i++)
379 const Param_Test::Step& vs = s[i];
381 ACE_DEBUG ((LM_DEBUG,
382 "Element #%d\n"
383 "\tname.id = %C\n"
384 "\tname.kind = %C\n"
385 "\tprocess = %d\n",
387 vs.name.id.in (), vs.name.kind.in (), vs.process));