Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / ub_objref_seq.cpp
blob29c31d7cd3fc7df22dabca9d638cbfd7d6062ddc
2 //=============================================================================
3 /**
4 * @file ub_objref_seq.cpp
6 * tests unbounded objref sequences
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "ub_objref_seq.h"
16 // ************************************************************************
17 // Test_ObjRef_Sequence
18 // ************************************************************************
20 static const char *Coffee_Flavor [] = {
21 "Italian Roast",
22 "Irish Creme",
23 "Costa Rican",
24 "Colombian Supremo",
25 "Macademia Nut",
26 "Swiss Chocolate Mocha"
29 Test_ObjRef_Sequence::Test_ObjRef_Sequence ()
30 : opname_ (CORBA::string_dup ("test_coffe_mix")),
31 inout_ (new Param_Test::Coffee_Mix),
32 out_ (new Param_Test::Coffee_Mix),
33 ret_ (new Param_Test::Coffee_Mix)
37 Test_ObjRef_Sequence::~Test_ObjRef_Sequence ()
39 CORBA::string_free (this->opname_);
40 this->opname_ = 0;
41 // the other data members will be freed as they are "_var"s and objects
42 // (rather than pointers to objects)
45 const char *
46 Test_ObjRef_Sequence::opname () const
48 return this->opname_;
51 void
52 Test_ObjRef_Sequence::dii_req_invoke (CORBA::Request *req)
54 req->add_in_arg ("s1") <<= this->in_;
55 req->add_inout_arg ("s2") <<= this->inout_.in ();
56 req->add_out_arg ("s3") <<= this->out_.in ();
58 req->set_return_type (Param_Test::_tc_Coffee_Mix);
60 req->invoke ();
62 const Param_Test::Coffee_Mix *tmp = 0;
63 req->return_value () >>= tmp;
64 this->ret_ = new Param_Test::Coffee_Mix (*tmp);
66 CORBA::NamedValue_ptr o2 =
67 req->arguments ()->item (1);
68 *o2->value () >>= tmp;
69 this->inout_ = new Param_Test::Coffee_Mix (*tmp);
71 CORBA::NamedValue_ptr o3 =
72 req->arguments ()->item (2);
73 *o3->value () >>= tmp;
74 this->out_ = new Param_Test::Coffee_Mix (*tmp);
77 int
78 Test_ObjRef_Sequence::init_parameters (Param_Test_ptr objref)
80 try
82 Coffee::Desc desc;
83 Generator *gen = GENERATOR::instance (); // value generator
85 // get some sequence length (not more than 10)
86 CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 5) + 5;
88 // set the length of the sequence
89 this->in_.length (len);
90 // now set each individual element
92 for (CORBA::ULong i = 0; i < this->in_.length (); i++)
94 // generate some arbitrary string to be filled into the ith location in
95 // the sequence
96 this->in_[i] = objref->make_coffee ();
98 // select a Coffee flavor at random
99 CORBA::ULong index = (CORBA::ULong) (gen->gen_long () % 6);
101 desc.name = Coffee_Flavor [index];
102 // set the attribute for the in object
103 Coffee_ptr tmp = this->in_[i];
105 tmp->description (desc);
108 return 0;
110 catch (const CORBA::Exception& ex)
112 ex._tao_print_exception ("Test_ObjRef_Sequence::init_parameters\n");
114 return -1;
118 Test_ObjRef_Sequence::reset_parameters ()
120 this->inout_ = new Param_Test::Coffee_Mix; // delete the previous ones
121 this->out_ = new Param_Test::Coffee_Mix;
122 this->ret_ = new Param_Test::Coffee_Mix;
123 return 0;
127 Test_ObjRef_Sequence::run_sii_test (Param_Test_ptr objref)
131 Param_Test::Coffee_Mix_out out (this->out_.out ());
133 this->ret_ = objref->test_coffe_mix (this->in_,
134 this->inout_.inout (),
135 out);
137 return 0;
139 catch (const CORBA::Exception& ex)
141 ex._tao_print_exception ("Test_ObjRef_Sequence::run_sii_test\n");
143 return -1;
146 CORBA::Boolean
147 Test_ObjRef_Sequence::check_validity ()
151 this->compare (this->in_,
152 this->inout_.in ());
154 this->compare (this->in_,
155 this->out_.in ());
157 this->compare (this->in_,
158 this->ret_.in ());
160 return 1;
162 catch (const CORBA::Exception& ex)
164 ex._tao_print_exception ("Test_ObjRef_Sequence::check_validity");
166 return 0;
169 CORBA::Boolean
170 Test_ObjRef_Sequence::check_validity (CORBA::Request_ptr )
172 //ACE_UNUSED_ARG (req);
173 return this->check_validity ();
176 void
177 Test_ObjRef_Sequence::print_values ()
179 ACE_DEBUG ((LM_DEBUG,
180 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
181 "IN sequence\n"));
182 this->print_sequence (this->in_);
183 ACE_DEBUG ((LM_DEBUG,
184 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
185 "INOUT sequence\n"));
186 this->print_sequence (this->inout_.in ());
187 ACE_DEBUG ((LM_DEBUG,
188 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
189 "OUT sequence\n"));
190 this->print_sequence (this->out_.in ());
191 ACE_DEBUG ((LM_DEBUG,
192 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
193 "RET sequence\n"));
194 this->print_sequence (this->ret_.in ());
197 CORBA::Boolean
198 Test_ObjRef_Sequence::compare (const Param_Test::Coffee_Mix &s1,
199 const Param_Test::Coffee_Mix &s2)
203 if (s1.maximum () != s2.maximum ())
205 return 0;
207 if (s1.length () != s2.length ())
209 return 0;
212 for (CORBA::ULong i=0; i < s1.length (); i++)
214 Coffee_ptr vs1 = s1[i];
215 Coffee_ptr vs2 = s2[i];
217 if (CORBA::is_nil (vs1) && CORBA::is_nil (vs2))
219 continue;
222 if (CORBA::is_nil (vs1) || CORBA::is_nil (vs2))
224 return 0;
227 Coffee::Desc_var desc1 = vs1->description ();
229 CORBA::String_var n1 = desc1->name.in ();
231 Coffee::Desc_var desc2 = vs2->description ();
233 CORBA::String_var n2 = desc2->name.in ();
235 if (ACE_OS::strcmp(n1.in (), n2.in ()) != 0)
237 return 0;
241 return 1; // success
243 catch (const CORBA::Exception& ex)
245 ex._tao_print_exception ("Test_ObjRef_Sequence::compare");
247 return 0;
250 void
251 Test_ObjRef_Sequence::print_sequence (const Param_Test::Coffee_Mix &s)
253 ACE_DEBUG ((LM_DEBUG,
254 "maximum = %d\n"
255 "length = %d\n",
256 s.maximum (),
257 s.length ()));
258 ACE_DEBUG ((LM_DEBUG, "Elements -\n"));
259 for (CORBA::ULong i=0; i < s.length (); i++)
261 Coffee_ptr c = s[i];
262 if (CORBA::is_nil (c))
264 ACE_DEBUG ((LM_DEBUG,
265 "Element #%d is nil\n", i));
266 continue;
268 ACE_DEBUG ((LM_DEBUG,
269 "Element #%d\n"
270 "\ttype = <%C>\n",
272 c->_interface_repository_id ()));