ACE+TAO-6_5_17
[ACE_TAO.git] / TAO / tests / Param_Test / ub_short_seq.cpp
blob50cf2c2064f86bf752ebd311b7e3ead4d0013acc
2 //=============================================================================
3 /**
4 * @file ub_short_seq.cpp
6 * tests unbounded short sequences
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "ub_short_seq.h"
16 // ************************************************************************
17 // Test_Short_Sequence
18 // ************************************************************************
20 Test_Short_Sequence::Test_Short_Sequence (void)
21 : opname_ (CORBA::string_dup ("test_short_sequence")),
22 in_ (new CORBA::ShortSeq),
23 inout_ (new CORBA::ShortSeq),
24 out_ (new CORBA::ShortSeq),
25 ret_ (new CORBA::ShortSeq)
29 Test_Short_Sequence::~Test_Short_Sequence (void)
31 CORBA::string_free (this->opname_);
32 this->opname_ = 0;
35 const char *
36 Test_Short_Sequence::opname (void) const
38 return this->opname_;
41 void
42 Test_Short_Sequence::dii_req_invoke (CORBA::Request *req)
44 req->add_in_arg ("s1") <<= this->in_.in ();
45 req->add_inout_arg ("s2") <<= this->inout_.in ();
46 req->add_out_arg ("s3") <<= this->out_.in ();
48 req->set_return_type (CORBA::_tc_ShortSeq);
50 req->invoke ();
52 const CORBA::ShortSeq *tmp = 0;
53 req->return_value () >>= tmp;
54 this->ret_ = new CORBA::ShortSeq (*tmp);
56 CORBA::NamedValue_ptr o2 =
57 req->arguments ()->item (1);
58 *o2->value () >>= tmp;
59 this->inout_ = new CORBA::ShortSeq (*tmp);
61 CORBA::NamedValue_ptr o3 =
62 req->arguments ()->item (2);
63 *o3->value () >>= tmp;
64 this->out_ = new CORBA::ShortSeq (*tmp);
67 int
68 Test_Short_Sequence::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 // set the length of the sequence
76 this->in_->length (len);
77 this->inout_->length (len);
78 // now set each individual element
79 for (CORBA::ULong i=0; i < this->in_->length (); i++)
81 // generate some arbitrary string to be filled into the ith location in
82 // the sequence
83 this->in_[i] = i;
84 this->inout_[i] = i+1;
86 return 0;
89 int
90 Test_Short_Sequence::reset_parameters (void)
92 this->inout_ = new CORBA::ShortSeq; // delete the previous ones
93 this->out_ = new CORBA::ShortSeq;
94 this->ret_ = new CORBA::ShortSeq;
95 return 0;
98 int
99 Test_Short_Sequence::run_sii_test (Param_Test_ptr objref)
103 CORBA::ShortSeq_out out (this->out_.out ());
105 this->ret_ = objref->test_short_sequence (this->in_.in (),
106 this->inout_.inout (),
107 out);
109 return 0;
111 catch (const CORBA::Exception& ex)
113 ex._tao_print_exception ("Test_Short_Sequence::run_sii_test\n");
116 return -1;
119 CORBA::Boolean
120 Test_Short_Sequence::check_validity (void)
122 CORBA::Boolean flag = 0;
123 if ((this->in_->length () == this->inout_->length ()) &&
124 (this->in_->length () == this->out_->length ()) &&
125 (this->in_->length () == this->ret_->length ()))
127 flag = 1; // assume all are equal
128 // lengths are same. Now compare the contents
129 for (CORBA::ULong i=0; i < this->in_->length () && flag; i++)
131 if (this->in_[i] != this->inout_[i] ||
132 this->in_[i] != this->out_[i] ||
133 this->in_[i] != this->ret_[i])
134 // not equal
135 flag = 0;
138 return flag;
141 CORBA::Boolean
142 Test_Short_Sequence::check_validity (CORBA::Request_ptr )
144 return this->check_validity ();
147 void
148 Test_Short_Sequence::print_values (void)
150 CORBA::ULong i;
151 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
152 for (i=0; this->in_.ptr () && (i < this->in_->length ()); i++)
154 ACE_DEBUG ((LM_DEBUG,
155 "Element #%d\n"
156 "in : %d\n",
158 this->in_[i]));
160 if (!this->in_.ptr ())
161 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
162 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
163 for (i=0; this->inout_.ptr () && (i < this->inout_->length ()); i++)
165 ACE_DEBUG ((LM_DEBUG,
166 "Element #%d\n"
167 "in : %d\n",
169 this->inout_[i]));
171 if (!this->inout_.ptr ())
172 ACE_DEBUG ((LM_DEBUG, "\ninout sequence is NUL\n"));
173 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
174 for (i=0; this->out_.ptr () && (i < this->out_->length ()); i++)
176 ACE_DEBUG ((LM_DEBUG,
177 "Element #%d\n"
178 "in : %d\n",
180 this->out_[i]));
182 if (!this->out_.ptr ())
183 ACE_DEBUG ((LM_DEBUG, "\nout sequence is NUL\n"));
184 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
185 for (i=0; this->ret_.ptr () && (i < this->ret_->length ()); i++)
187 ACE_DEBUG ((LM_DEBUG,
188 "Element #%d\n"
189 "in : %d\n",
191 this->ret_[i]));
193 if (!this->ret_.ptr ())
194 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
195 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));