Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / objref.cpp
blobe86581104f8f0baea60d45fc0e09af92bc4890b0
2 //=============================================================================
3 /**
4 * @file objref.cpp
6 * tests object references
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "objref.h"
16 // ************************************************************************
17 // Test_ObjRef
18 // ************************************************************************
20 Test_ObjRef::Test_ObjRef ()
21 : opname_ (CORBA::string_dup ("test_objref"))
25 Test_ObjRef::~Test_ObjRef ()
27 CORBA::string_free (this->opname_);
28 this->opname_ = 0;
31 const char *
32 Test_ObjRef::opname () const
34 return this->opname_;
37 void
38 Test_ObjRef::dii_req_invoke (CORBA::Request *req)
40 req->add_in_arg ("s1") <<= this->in_.in ();
41 req->add_inout_arg ("s2") <<= this->inout_.in ();
42 req->add_out_arg ("s3") <<= this->out_.in ();
44 req->set_return_type (_tc_Coffee);
46 req->invoke ();
48 Coffee_ptr tmp;
49 req->return_value () >>= tmp;
50 this->ret_ = Coffee::_duplicate (tmp);
52 CORBA::NamedValue_ptr o2 =
53 req->arguments ()->item (1);
54 *o2->value () >>= tmp;
55 this->inout_ = Coffee::_duplicate (tmp);
57 CORBA::NamedValue_ptr o3 =
58 req->arguments ()->item (2);
59 *o3->value () >>= tmp;
60 this->out_ = Coffee::_duplicate (tmp);
63 static const char *Coffee_Flavor [] = {
64 "Italian Roast",
65 "Irish Creme",
66 "Costa Rican",
67 "Colombian Supremo",
68 "Macademia Nut",
69 "Swiss Chocolate Mocha"
72 int
73 Test_ObjRef::init_parameters (Param_Test_ptr objref)
75 Coffee::Desc desc;
76 Generator *gen = GENERATOR::instance (); // value generator
78 char msg_str[256] = "";
80 try
82 ACE_OS::strcpy (msg_str, "make_cofee");
84 // first get a Coffee object
85 this->in_ = objref->make_coffee ();
87 // Get some index into Coffee_Flavor [].
88 CORBA::ULong index = (CORBA::ULong) (gen->gen_long () % 6);
89 desc.name = Coffee_Flavor [index];
91 // set the attribute of the object
92 ACE_OS::strcpy (msg_str, "set coffee attribute");
93 this->in_->description (desc); // set the attribute for the in object
95 this->inout_ = Coffee::_nil ();
96 this->out_ = Coffee::_nil ();
97 this->ret_ = Coffee::_nil ();
99 return 0;
101 catch (const CORBA::Exception& ex)
103 ex._tao_print_exception (msg_str);
105 return -1;
109 Test_ObjRef::reset_parameters ()
111 // Environemnt variable
112 Coffee::Desc desc;
113 Generator *gen = GENERATOR::instance (); // value generator
115 // Get some index into Coffee_Flavor [].
116 CORBA::ULong index = (CORBA::ULong) (gen->gen_long () % 6);
117 desc.name = Coffee_Flavor [index];
121 // set the attribute of the object
122 this->in_->description (desc); // set the attribute for the in object
124 catch (const CORBA::Exception& ex)
126 ex._tao_print_exception ("set coffee attribute");
127 return -1;
130 this->inout_ = Coffee::_nil ();
131 this->out_ = Coffee::_nil ();
132 this->ret_ = Coffee::_nil ();
134 return 0;
138 Test_ObjRef::run_sii_test (Param_Test_ptr objref)
142 this->ret_ =
143 objref->test_objref (this->in_.in (),
144 this->inout_.inout (),
145 this->out_.out ());
147 return 0;
149 catch (const CORBA::Exception& ex)
151 ex._tao_print_exception ("Test_ObjRef::run_sii_test\n");
153 return -1;
156 CORBA::Boolean
157 Test_ObjRef::check_validity ()
159 // Environemnt variable
163 if (CORBA::is_nil (this->in_.in ())
164 || CORBA::is_nil (this->inout_.in ())
165 || CORBA::is_nil (this->out_.in ())
166 || CORBA::is_nil (this->ret_.in ()))
168 ACE_ERROR ((LM_ERROR, "Nil object references returned\n"));
169 return 0;
171 Coffee::Desc_var in_desc =
172 this->in_->description ();
174 const char *in = in_desc->name.in ();
176 Coffee::Desc_var inout_desc =
177 this->inout_->description ();
179 const char *inout = inout_desc->name.in ();
181 Coffee::Desc_var out_desc =
182 this->out_->description ();
184 const char *out = out_desc->name.in ();
186 Coffee::Desc_var ret_desc = this->out_->description ();
188 const char* ret = ret_desc->name.in ();
190 // now compare them
191 if (!ACE_OS::strcmp (in, inout) &&
192 !ACE_OS::strcmp (in, out) &&
193 !ACE_OS::strcmp (in, ret))
194 return 1; // success
196 catch (const CORBA::Exception& ex)
198 ex._tao_print_exception ("Retrieving description");
199 return 0;
202 return 1;
205 CORBA::Boolean
206 Test_ObjRef::check_validity (CORBA::Request_ptr)
208 return this->check_validity ();
211 void
212 Test_ObjRef::print_values ()
214 // Env. variable
216 Coffee::Desc_var in_desc;
217 Coffee::Desc_var inout_desc;
218 Coffee::Desc_var out_desc;
219 Coffee::Desc_var ret_desc;
220 const char *in = 0;
221 const char *out = 0;
222 const char *inout = 0;
223 const char *ret = 0;
226 if (!CORBA::is_nil (this->in_.in ()))
228 in_desc =
229 this->in_->description ();
230 in = in_desc->name.in ();
233 if (!CORBA::is_nil (this->inout_.in ()))
235 inout_desc =
236 this->inout_->description ();
237 inout = inout_desc->name.in ();
240 if (!CORBA::is_nil (this->out_.in ()))
242 out_desc =
243 this->out_->description ();
244 out = out_desc->name.in ();
247 if (!CORBA::is_nil (this->ret_.in ()))
249 ret_desc =
250 this->ret_->description ();
251 ret = ret_desc->name.in ();
254 catch (const CORBA::Exception& ex)
256 ex._tao_print_exception ("Retrieving Description");
257 return;
261 ACE_DEBUG ((LM_DEBUG,
262 "\n=*=*=*=*=*=*"
263 "in = %C, "
264 "inout = %C, "
265 "out = %C, "
266 "ret = %C*=*=*=*=*=\n",
267 in?in:"ERROR(null string)",
268 inout?inout:"ERROR(null string)",
269 out?out:"ERROR(null string)",
270 ret?ret:"ERROR(null string)"