Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / objref_struct.cpp
blob834d50f3212cb5d0a7cfae262c0ef99e6d399704
2 //=============================================================================
3 /**
4 * @file objref_struct.cpp
6 * test structures containing object references.
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "objref_struct.h"
16 // ************************************************************************
17 // Test_Objref_Struct
18 // ************************************************************************
20 Test_Objref_Struct::Test_Objref_Struct ()
21 : opname_ (CORBA::string_dup ("test_objref_struct")),
22 inout_ (new Param_Test::Objref_Struct),
23 out_ (new Param_Test::Objref_Struct),
24 ret_ (new Param_Test::Objref_Struct)
28 Test_Objref_Struct::~Test_Objref_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_Objref_Struct::opname () const
39 return this->opname_;
42 void
43 Test_Objref_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_Objref_Struct);
51 req->invoke ();
53 const Param_Test::Objref_Struct *tmp = 0;
54 req->return_value () >>= tmp;
55 this->ret_ = new Param_Test::Objref_Struct (*tmp);
57 CORBA::NamedValue_ptr o2 =
58 req->arguments ()->item (1);
59 *o2->value () >>= tmp;
60 this->inout_ = new Param_Test::Objref_Struct (*tmp);
62 CORBA::NamedValue_ptr o3 =
63 req->arguments ()->item (2);
64 *o3->value () >>= tmp;
65 this->out_ = new Param_Test::Objref_Struct (*tmp);
68 int
69 Test_Objref_Struct::init_parameters (Param_Test_ptr objref)
71 try
73 Generator *gen = GENERATOR::instance (); // value generator
75 // Set the long member.
76 this->in_.x = gen->gen_long ();
78 this->in_.y = objref->make_coffee ();
80 Coffee::Desc d;
81 d.name = gen->gen_string ();
83 this->in_.y->description (d);
85 this->inout_->x = 0;
87 this->inout_->y = Coffee::_nil ();
89 Coffee::Desc dd;
90 dd.name = CORBA::string_dup ("");
92 return 0;
94 catch (const CORBA::Exception& ex)
96 ex._tao_print_exception ("Test_Objref_Struct::init_parameters\n");
98 return -1;
102 Test_Objref_Struct::reset_parameters ()
104 this->inout_ = new Param_Test::Objref_Struct; // delete the previous ones
105 this->out_ = new Param_Test::Objref_Struct;
106 this->ret_ = new Param_Test::Objref_Struct;
108 this->inout_->x = 0;
110 this->inout_->y = Coffee::_nil ();
112 Coffee::Desc dd;
113 dd.name = CORBA::string_dup ("");
115 return 0;
119 Test_Objref_Struct::run_sii_test (Param_Test_ptr objref)
123 Param_Test::Objref_Struct_out out (this->out_.out ());
125 this->ret_ = objref->test_objref_struct (this->in_,
126 this->inout_.inout (),
127 out);
129 return 0;
131 catch (const CORBA::Exception& ex)
133 ex._tao_print_exception ("Test_Objref_Struct::run_sii_test\n");
135 return -1;
138 CORBA::Boolean
139 Test_Objref_Struct::check_validity ()
141 if (this->in_.x != this->inout_->x
142 || this->in_.x != this->out_->x
143 || this->in_.x != this->ret_->x)
144 return 0;
149 if (CORBA::is_nil (this->in_.y.in ())
150 || CORBA::is_nil (this->out_->y.in ())
151 || CORBA::is_nil (this->ret_->y.in ())
152 || CORBA::is_nil (this->inout_->y.in ()))
154 return 0;
157 Coffee::Desc_var s_in = this->in_.y->description ();
159 Coffee::Desc_var s_out = this->out_->y->description ();
161 Coffee::Desc_var s_inout = this->inout_->y->description ();
163 Coffee::Desc_var s_ret = this->ret_->y->description ();
165 if (ACE_OS::strcmp (s_in->name, s_out->name) != 0
166 || ACE_OS::strcmp (s_in->name, s_inout->name) != 0
167 || ACE_OS::strcmp (s_in->name, s_ret->name) != 0 )
169 return 0;
172 return 1;
174 catch (const CORBA::Exception& ex)
176 ex._tao_print_exception ("Test_Objref_Struct::check_validity\n");
178 return 0;
181 CORBA::Boolean
182 Test_Objref_Struct::check_validity (CORBA::Request_ptr /*req*/)
184 return this->check_validity ();
187 void
188 Test_Objref_Struct::print_values ()
190 ACE_DEBUG ((LM_DEBUG,
191 "\n*=*=*=*=*=*=*=*=*=*=\n"
192 "in_.x = %d\n"
193 "inout_.x = %d\n"
194 "out_.x = %d\n"
195 "ret_.x = %d\n",
196 this->in_.x,
197 this->inout_->x,
198 this->out_->x,
199 this->ret_->x ));
204 Coffee::Desc_var s_in =
205 this->in_.y->description ();
207 Coffee::Desc_var s_inout = new Coffee::Desc;
208 Coffee::Desc_var s_out = new Coffee::Desc;
209 Coffee::Desc_var s_ret = new Coffee::Desc;
210 s_inout->name = CORBA::string_dup ("");
211 s_out->name = CORBA::string_dup ("");
212 s_ret->name = CORBA::string_dup ("");
214 if (!CORBA::is_nil (this->out_->y.in ()))
216 s_out = this->out_->y->description ();
219 if (!CORBA::is_nil (this->inout_->y.in ()))
221 s_inout = this->inout_->y->description ();
224 if (!CORBA::is_nil (this->ret_->y.in ()))
226 s_ret = this->ret_->y->description ();
229 ACE_DEBUG ((LM_DEBUG,
230 "\n*=*=*=*=*=*=*=*=*=*=\n"
231 "in_ name = %C\n"
232 "inout_ name = %C\n"
233 "out_ name = %C\n"
234 "ret_ name = %C\n",
235 s_in->name.in (),
236 s_inout->name.in (),
237 s_out->name.in (),
238 s_ret->name.in () ));
240 catch (const CORBA::Exception& ex)
242 ex._tao_print_exception ("Test_Objref_Struct::print_values\n");