Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / ub_array_seq.cpp
blob2b4370ab015d58c9b1d2fbff97f85fc6e901b86c
2 //=============================================================================
3 /**
4 * @file ub_array_seq.cpp
6 * tests unbounded array sequences
8 * @author Jeff Parsons <parsons@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "ub_array_seq.h"
16 // ************************************************************************
17 // Test_Array_Sequence
18 // ************************************************************************
20 Test_Array_Sequence::Test_Array_Sequence ()
21 : opname_ (CORBA::string_dup ("test_array_sequence")),
22 inout_ (new Param_Test::ArraySeq),
23 out_ (new Param_Test::ArraySeq),
24 ret_ (new Param_Test::ArraySeq)
28 Test_Array_Sequence::~Test_Array_Sequence ()
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_Array_Sequence::opname () const
39 return this->opname_;
42 void
43 Test_Array_Sequence::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_ArraySeq);
51 req->invoke ();
53 const Param_Test::ArraySeq *tmp = 0;
54 req->return_value () >>= tmp;
55 this->ret_ = new Param_Test::ArraySeq (*tmp);
57 CORBA::NamedValue_ptr o2 =
58 req->arguments ()->item (1);
59 *o2->value () >>= tmp;
60 this->inout_ = new Param_Test::ArraySeq (*tmp);
62 CORBA::NamedValue_ptr o3 =
63 req->arguments ()->item (2);
64 *o3->value () >>= tmp;
65 this->out_ = new Param_Test::ArraySeq (*tmp);
68 int
69 Test_Array_Sequence::init_parameters (Param_Test_ptr)
71 Generator *gen = GENERATOR::instance (); // value generator
73 // get some sequence length (not more than 10)
74 CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 10) + 1;
76 // set the length of the in sequence
77 this->in_.length (len);
78 // different from in_.
79 this->inout_->length (1);
81 // now set each individual element
82 Param_Test::Fixed_Array tmp;
84 for (CORBA::ULong j = 0; j < Param_Test::DIM1; j++)
86 tmp[j] = gen->gen_long ();
89 Param_Test::Fixed_Array_copy (this->inout_[0], tmp);
91 for (CORBA::ULong i = 0; i < this->in_.length (); i++)
93 // Generate some arbitrary array to be filled into the ith
94 // location in the sequence.
95 for (CORBA::ULong j = 0; j < Param_Test::DIM1; j++)
97 tmp[j] = gen->gen_long ();
100 Param_Test::Fixed_Array_copy (this->in_[i], tmp);
103 return 0;
107 Test_Array_Sequence::reset_parameters ()
109 // Delete the previous ones.
110 this->inout_ = new Param_Test::ArraySeq;
111 this->out_ = new Param_Test::ArraySeq;
112 this->ret_ = new Param_Test::ArraySeq;
113 return 0;
117 Test_Array_Sequence::run_sii_test (Param_Test_ptr objref)
121 Param_Test::ArraySeq_out out (this->out_.out ());
123 this->ret_ = objref->test_array_sequence (this->in_,
124 this->inout_.inout (),
125 out);
127 return 0;
129 catch (const CORBA::Exception& ex)
131 ex._tao_print_exception ("Test_Array_Sequence::run_sii_test\n");
133 return -1;
136 CORBA::Boolean
137 Test_Array_Sequence::check_validity ()
139 if (this->compare (this->in_, this->inout_.in ()) &&
140 this->compare (this->in_, this->out_.in ()) &&
141 this->compare (this->in_, this->ret_.in ()))
142 return 1;
143 else
144 return 0;
147 CORBA::Boolean
148 Test_Array_Sequence::check_validity (CORBA::Request_ptr )
150 return this->check_validity ();
153 void
154 Test_Array_Sequence::print_values ()
156 ACE_DEBUG ((LM_DEBUG,
157 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
158 "IN array\n"));
159 this->print_sequence (this->in_);
160 ACE_DEBUG ((LM_DEBUG,
161 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
162 "INOUT array\n"));
163 this->print_sequence (this->inout_.in ());
164 ACE_DEBUG ((LM_DEBUG,
165 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
166 "OUT array\n"));
167 this->print_sequence (this->out_.in ());
168 ACE_DEBUG ((LM_DEBUG,
169 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
170 "RET array\n"));
171 this->print_sequence (this->ret_.in ());
174 CORBA::Boolean
175 Test_Array_Sequence::compare (const Param_Test::ArraySeq &s1,
176 const Param_Test::ArraySeq &s2)
178 if (s1.maximum () != s2.maximum ())
180 return 0;
183 if (s1.length () != s2.length ())
185 return 0;
188 for (CORBA::ULong i = 0; i < s1.length (); i++)
190 const Param_Test::Fixed_Array& vs1 = s1[i];
191 const Param_Test::Fixed_Array& vs2 = s2[i];
193 for (CORBA::ULong j = 0; j < Param_Test::DIM1; j++)
195 if (vs1[j] != vs2[j])
197 return 0;
202 return 1; // success
205 void
206 Test_Array_Sequence::print_sequence (const Param_Test::ArraySeq &s)
208 ACE_DEBUG ((LM_DEBUG,
209 "maximum = %d\n"
210 "length = %d\n",
211 s.maximum (),
212 s.length ()));
213 ACE_DEBUG ((LM_DEBUG, "Elements -\n"));
215 for (CORBA::ULong i=0; i < s.length (); i++)
217 ACE_DEBUG ((LM_DEBUG,
218 "Element #%d --\n",
219 i));
221 const Param_Test::Fixed_Array& vs = s[i];
223 for (CORBA::ULong j = 0; j < Param_Test::DIM1; j++)
225 ACE_DEBUG ((LM_DEBUG,
226 "Element%d[%d] = %d\n",
229 vs[j]));