Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / nested_struct.cpp
blob5d444cae5d23206b41334f9f8077bdcaa1af657f
2 //=============================================================================
3 /**
4 * @file nested_struct.cpp
6 * tests nested structs
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "nested_struct.h"
16 // ************************************************************************
17 // Test_Nested_Struct
18 // ************************************************************************
20 Test_Nested_Struct::Test_Nested_Struct ()
21 : opname_ (CORBA::string_dup ("test_nested_struct")),
22 inout_ (new Param_Test::Nested_Struct),
23 out_ (new Param_Test::Nested_Struct),
24 ret_ (new Param_Test::Nested_Struct)
28 Test_Nested_Struct::~Test_Nested_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_Nested_Struct::opname () const
39 return this->opname_;
42 void
43 Test_Nested_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 ();
48 req->set_return_type (Param_Test::_tc_Nested_Struct);
50 req->invoke ();
52 const Param_Test::Nested_Struct *tmp = 0;
53 req->return_value () >>= tmp;
54 this->ret_ = new Param_Test::Nested_Struct (*tmp);
56 CORBA::NamedValue_ptr arg2 =
57 req->arguments ()->item (1);
58 *arg2->value () >>= tmp;
59 this->inout_ = new Param_Test::Nested_Struct (*tmp);
61 CORBA::NamedValue_ptr arg3 =
62 req->arguments ()->item (2);
63 *arg3->value () >>= tmp;
64 this->out_ = new Param_Test::Nested_Struct (*tmp);
67 int
68 Test_Nested_Struct::init_parameters (Param_Test_ptr)
70 Generator *gen = GENERATOR::instance (); // value generator
72 // get some sequence length (not more than 10)
73 CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 10) + 1;
75 this->in_.vs.dbl = 0.0;
76 this->in_.vs.dummy1 = CORBA::string_dup ("");
77 this->in_.vs.boole = 0;
78 this->in_.vs.dummy2 = CORBA::string_dup ("");
79 this->in_.vs.shrt = 0;
80 // set the length of the sequence
81 this->in_.vs.seq.length (len);
82 // now set each individual element
83 for (CORBA::ULong i = 0; i < len; ++i)
85 // generate some arbitrary string to be filled into the ith location in
86 // the sequence
87 char *str = gen->gen_string ();
88 this->in_.vs.seq[i] = str;
91 this->inout_->vs.dbl = 0.0;
92 this->inout_->vs.dummy1 = CORBA::string_dup ("");
93 this->inout_->vs.boole = 0;
94 this->inout_->vs.dummy2 = CORBA::string_dup ("");
95 this->inout_->vs.shrt = 0;
96 // set the length of the sequence
97 this->inout_->vs.seq.length (0);
99 return 0;
103 Test_Nested_Struct::reset_parameters ()
105 this->inout_ = new Param_Test::Nested_Struct; // delete the previous ones
106 this->out_ = new Param_Test::Nested_Struct;
107 this->ret_ = new Param_Test::Nested_Struct;
109 this->inout_->vs.dbl = 0.0;
110 this->inout_->vs.dummy1 = CORBA::string_dup ("");
111 this->inout_->vs.boole = 0;
112 this->inout_->vs.dummy2 = CORBA::string_dup ("");
113 this->inout_->vs.shrt = 0;
114 // set the length of the sequence
115 this->inout_->vs.seq.length (0);
117 return 0;
121 Test_Nested_Struct::run_sii_test (Param_Test_ptr objref)
125 Param_Test::Nested_Struct_out out (this->out_.out ());
126 this->ret_ = objref->test_nested_struct (this->in_,
127 this->inout_.inout (),
128 out);
130 return 0;
132 catch (const CORBA::Exception& ex)
134 ex._tao_print_exception ("Test_Nested_Struct::run_sii_test\n");
136 return -1;
139 CORBA::Boolean
140 Test_Nested_Struct::check_validity ()
142 CORBA::Boolean flag = 0;
143 if ((this->in_.vs.seq.length () == this->inout_->vs.seq.length ()) &&
144 (this->in_.vs.seq.length () == this->out_->vs.seq.length ()) &&
145 (this->in_.vs.seq.length () == this->ret_->vs.seq.length ()))
147 flag = 1; // assume all are equal
148 // lengths are same. Now compare the contents
149 for (CORBA::ULong i=0; i < this->in_.vs.seq.length () && flag; i++)
151 if (ACE_OS::strcmp (this->in_.vs.seq[i], this->inout_->vs.seq[i]) ||
152 ACE_OS::strcmp (this->in_.vs.seq[i], this->out_->vs.seq[i]) ||
153 ACE_OS::strcmp (this->in_.vs.seq[i], this->ret_->vs.seq[i]))
154 // not equal
155 flag = 0;
158 return flag;
161 CORBA::Boolean
162 Test_Nested_Struct::check_validity (CORBA::Request_ptr /*req*/)
164 //ACE_UNUSED_ARG (req);
165 return this->check_validity ();
168 void
169 Test_Nested_Struct::print_values ()
171 for (CORBA::ULong i=0; i < this->in_.vs.seq.length (); i++)
173 ACE_DEBUG ((LM_DEBUG,
174 "\n*=*=*=*=*=*=*=*=*=*=\n"
175 "Element # %d\n"
176 "in (len = %d): %C\n"
177 "inout (len = %d): %C\n"
178 "out (len = %d): %C\n"
179 "ret (len = %d): %C\n",
181 this->in_.vs.seq.length (),
182 (this->in_.vs.seq.length ()? (const char *)this->in_.vs.seq[i]:"<nul>"),
183 this->inout_->vs.seq.length (),
184 (this->inout_->vs.seq.length ()? (const char *)this->inout_->vs.seq[i]:"<nul>"),
185 this->out_->vs.seq.length (),
186 (this->out_->vs.seq.length ()? (const char *)this->out_->vs.seq[i]:"<nul>"),
187 this->ret_->vs.seq.length (),
188 (this->ret_->vs.seq.length ()? (const char *)this->ret_->vs.seq[i]:"<nul>")));