Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / ub_any_seq.cpp
blobb471b54a13fdd1aafecc83f3562e98a81a8ee462
2 //=============================================================================
3 /**
4 * @file ub_any_seq.cpp
6 * tests unbounded Any sequences
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "ub_any_seq.h"
15 #include "tao/debug.h"
17 const CORBA::ULong TEST_SEQ_LENGTH = 5;
18 const CORBA::ULong NUM_TEST_TYPES = 4;
20 // ************************************************************************
21 // Test_AnySeq
22 // ************************************************************************
24 Test_AnySeq::Test_AnySeq ()
25 : opname_ (CORBA::string_dup ("test_anyseq")),
26 in_ (new CORBA::AnySeq (TEST_SEQ_LENGTH)),
27 inout_ (new CORBA::AnySeq (TEST_SEQ_LENGTH)),
28 out_ (new CORBA::AnySeq),
29 ret_ (new CORBA::AnySeq)
33 Test_AnySeq::~Test_AnySeq ()
35 CORBA::string_free (this->opname_);
36 this->opname_ = 0;
39 const char *
40 Test_AnySeq::opname () const
42 return this->opname_;
45 void
46 Test_AnySeq::dii_req_invoke (CORBA::Request *req)
48 req->add_in_arg ("s1") <<= this->in_.in ();
49 req->add_inout_arg ("s2") <<= this->inout_.in ();
50 req->add_out_arg ("s3") <<= this->out_.in ();
52 req->set_return_type (CORBA::_tc_AnySeq);
54 req->invoke ();
56 const CORBA::AnySeq* tmp = 0;
57 req->return_value () >>= tmp;
58 this->ret_ = new CORBA::AnySeq (*tmp);
60 CORBA::NamedValue_ptr o2 =
61 req->arguments ()->item (1);
62 *o2->value () >>= tmp;
63 this->inout_ = new CORBA::AnySeq (*tmp);
65 CORBA::NamedValue_ptr o3 =
66 req->arguments ()->item (2);
67 *o3->value () >>= tmp;
68 this->out_ = new CORBA::AnySeq (*tmp);
71 int
72 Test_AnySeq::init_parameters (Param_Test_ptr objref)
74 Generator *gen = GENERATOR::instance (); // value generator
76 // Must be set explicitly (CORBA spec)
77 this->in_->length (TEST_SEQ_LENGTH);
78 this->inout_->length (TEST_SEQ_LENGTH);
80 for (CORBA::ULong i=0; i < this->in_->length (); i++)
82 CORBA::ULong index =
83 (CORBA::ULong) (gen->gen_short () % NUM_TEST_TYPES);
84 switch (index)
86 case 0:
88 CORBA::Short s;
89 s = gen->gen_short ();
90 if (TAO_debug_level > 0)
91 ACE_DEBUG ((LM_DEBUG,
92 "setting short = %d\n", s));
93 this->in_[i] <<= s;
94 this->inout_[i] <<= 0; // different from in_
96 break;
97 case 1:
99 CORBA::String_var str = gen->gen_string ();
100 if (TAO_debug_level > 0)
101 ACE_DEBUG ((LM_DEBUG,
102 "setting string = %C\n", str.in ()));
103 this->in_[i] <<= str.in ();
104 this->inout_[i] <<= 0; // different from in_
106 break;
107 case 2:
109 if (TAO_debug_level > 0)
110 ACE_DEBUG ((LM_DEBUG,
111 "setting coffee object\n" ));
114 // get access to a Coffee Object
115 Coffee_var cobj = objref->make_coffee ();
117 // insert the coffee object into the Any
118 this->in_[i] <<= cobj.in ();
119 this->inout_[i] <<= 0; // different from in_
121 catch (const CORBA::SystemException& sysex)
123 sysex._tao_print_exception (
124 "System Exception doing make_coffee");
125 return -1;
128 break;
129 case 3:
130 if (TAO_debug_level > 0)
131 ACE_DEBUG ((LM_DEBUG,
132 "setting constant string\n" ));
133 this->in_[i] <<= "Const string";
134 this->inout_[i] <<= 0; // different from in_
135 break;
139 return 0;
143 Test_AnySeq::reset_parameters ()
145 Generator *gen = GENERATOR::instance (); // value generator
147 for (CORBA::ULong i=0; i < this->in_->length (); i++)
149 CORBA::ULong index =
150 (CORBA::ULong) (gen->gen_long () % NUM_TEST_TYPES);
152 switch (index)
154 case 0:
156 CORBA::Short s;
157 s = gen->gen_short ();
158 this->in_[i] <<= s;
159 this->inout_[i] <<= s;
161 break;
162 case 1:
164 CORBA::String_var str = gen->gen_string ();
165 this->in_[i] <<= str.in ();
166 this->inout_[i] <<= str.in ();
168 break;
169 case 2:
171 this->inout_[i] = this->in_[i];
173 break;
174 case 3:
175 this->in_[i] <<= "Const string";
176 this->inout_[i] <<= "Const string";
177 break;
181 return 0;
186 Test_AnySeq::run_sii_test (Param_Test_ptr objref)
190 CORBA::AnySeq_out out (this->out_.out ());
192 this->ret_ = objref->test_anyseq (this->in_.in (),
193 this->inout_.inout (),
194 out);
196 return 0;
198 catch (const CORBA::Exception& ex)
200 ex._tao_print_exception ("Test_AnySeq::run_sii_test\n");
202 return -1;
205 CORBA::Boolean
206 Test_AnySeq::check_validity ()
208 CORBA::Short short_in, short_inout, short_out, short_ret;
209 const char *str_in;
210 const char *str_inout;
211 const char *str_out;
212 const char *str_ret;
213 Coffee_ptr obj_in, obj_inout, obj_out, obj_ret;
215 for (CORBA::ULong i=0; i < this->in_->length (); i++)
217 if ((this->in_[i] >>= short_in) &&
218 (this->inout_[i] >>= short_inout) &&
219 (this->out_[i] >>= short_out) &&
220 (this->ret_[i] >>= short_ret))
222 if (TAO_debug_level > 0)
224 ACE_DEBUG ((LM_DEBUG,
225 "Received shorts: in = %d, "
226 "inout = %d, out = %d, ret = %d\n",
227 short_in,
228 short_inout,
229 short_out,
230 short_ret));
233 if ((short_in != short_inout) ||
234 (short_in != short_out) ||
235 (short_in != short_ret))
237 ACE_DEBUG ((LM_DEBUG,
238 "mismatch of short values\n"));
239 return 0;
241 else
242 continue;
244 else if ((this->in_[i] >>= str_in) &&
245 (this->inout_[i] >>= str_inout) &&
246 (this->out_[i] >>= str_out) &&
247 (this->ret_[i] >>= str_ret))
249 if (ACE_OS::strcmp (str_in, str_inout) ||
250 ACE_OS::strcmp (str_in, str_out) ||
251 ACE_OS::strcmp (str_in, str_ret))
253 ACE_DEBUG ((LM_DEBUG,
254 "mismatch of string values\n"));
255 return 0;
257 else
258 continue;
260 else if ((this->in_[i] >>= obj_in) &&
261 (this->inout_[i] >>= obj_inout) &&
262 (this->out_[i] >>= obj_out) &&
263 (this->ret_[i] >>= obj_ret))
265 if (!(obj_in->_is_equivalent (obj_inout)) ||
266 !(obj_in->_is_equivalent (obj_out)) ||
267 !(obj_in->_is_equivalent (obj_ret)))
269 ACE_DEBUG ((LM_DEBUG,
270 "mismatch of Coffee values\n"));
271 return 0;
274 else
275 continue;
278 // Everything checks out.
279 return 1;
282 CORBA::Boolean
283 Test_AnySeq::check_validity (CORBA::Request_ptr)
285 return this->check_validity ();
288 void
289 Test_AnySeq::print_values ()
291 ACE_DEBUG ((LM_DEBUG,
292 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
293 "IN sequence\n"));
294 this->print_sequence (this->in_.in ());
295 ACE_DEBUG ((LM_DEBUG,
296 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
297 "INOUT sequence\n"));
298 this->print_sequence (this->inout_.in ());
299 ACE_DEBUG ((LM_DEBUG,
300 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
301 "OUT sequence\n"));
302 this->print_sequence (this->out_.in ());
303 ACE_DEBUG ((LM_DEBUG,
304 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
305 "RET sequence\n"));
306 this->print_sequence (this->ret_.in ());
309 void
310 Test_AnySeq::print_sequence (const CORBA::AnySeq &s)
312 ACE_DEBUG ((LM_DEBUG,
313 "maximum = %d\n"
314 "length = %d\n",
315 s.maximum (),
316 s.length ()));
317 ACE_DEBUG ((LM_DEBUG, "Elements -\n"));
318 for (CORBA::ULong i=0; i < s.length (); i++)
320 /* const CORBA::Any& vs = s[i];
322 ACE_DEBUG ((LM_DEBUG,
323 "Element #%d\n"
324 "\tl = %d\n"
325 "\tc = %c\n"
326 "\ts = %d\n"
327 "\to = %x\n"
328 "\tf = %f\n"
329 "\tb = %d\n"
330 "\td = %f\n",
332 vs.l, vs.c, vs.s, vs.o, vs.f, vs.b, vs.d));