ACE+TAO-6_5_17
[ACE_TAO.git] / TAO / tests / Param_Test / ub_long_seq.cpp
blob96b1429e91c1bb7bd1db1047a49db74f2d9da411
2 //=============================================================================
3 /**
4 * @file ub_long_seq.cpp
6 * tests unbounded long sequences
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "ub_long_seq.h"
16 // ************************************************************************
17 // Test_Long_Sequence
18 // ************************************************************************
20 Test_Long_Sequence::Test_Long_Sequence (void)
21 : opname_ (CORBA::string_dup ("test_long_sequence")),
22 in_ (new CORBA::LongSeq),
23 inout_ (new CORBA::LongSeq),
24 out_ (new CORBA::LongSeq),
25 ret_ (new CORBA::LongSeq)
29 Test_Long_Sequence::~Test_Long_Sequence (void)
31 CORBA::string_free (this->opname_);
32 this->opname_ = 0;
35 const char *
36 Test_Long_Sequence::opname (void) const
38 return this->opname_;
41 void
42 Test_Long_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_LongSeq);
50 req->invoke ();
52 const CORBA::LongSeq *tmp = 0;
53 req->return_value () >>= tmp;
54 this->ret_ = CORBA::LongSeq (*tmp);
56 CORBA::NamedValue_ptr o2 =
57 req->arguments ()->item (1);
58 *o2->value () >>= tmp;
59 this->inout_ = CORBA::LongSeq (*tmp);
61 CORBA::NamedValue_ptr o3 =
62 req->arguments ()->item (2);
63 *o3->value () >>= tmp;
64 this->out_ = CORBA::LongSeq (*tmp);
67 int
68 Test_Long_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 this->in_[i] = i;
82 this->inout_[i] = i+1;
84 return 0;
87 int
88 Test_Long_Sequence::reset_parameters (void)
90 this->inout_ = new CORBA::LongSeq; // delete the previous ones
91 this->out_ = new CORBA::LongSeq;
92 this->ret_ = new CORBA::LongSeq;
93 return 0;
96 int
97 Test_Long_Sequence::run_sii_test (Param_Test_ptr objref)
99 try
101 CORBA::LongSeq_out out (this->out_.out ());
103 this->ret_ = objref->test_long_sequence (this->in_.in (),
104 this->inout_.inout (),
105 out);
107 return 0;
109 catch (const CORBA::Exception& ex)
111 ex._tao_print_exception ("Test_Long_Sequence::run_sii_test\n");
114 return -1;
117 CORBA::Boolean
118 Test_Long_Sequence::check_validity (void)
120 CORBA::Boolean flag = 0;
121 if ((this->in_->length () == this->inout_->length ()) &&
122 (this->in_->length () == this->out_->length ()) &&
123 (this->in_->length () == this->ret_->length ()))
125 flag = 1; // assume all are equal
126 // lengths are same. Now compare the contents
127 for (CORBA::ULong i=0; i < this->in_->length () && flag; i++)
129 if (this->in_[i] != this->inout_[i] ||
130 this->in_[i] != this->out_[i] ||
131 this->in_[i] != this->ret_[i])
132 // not equal
133 flag = 0;
136 return flag;
139 CORBA::Boolean
140 Test_Long_Sequence::check_validity (CORBA::Request_ptr )
142 return this->check_validity ();
145 void
146 Test_Long_Sequence::print_values (void)
148 CORBA::ULong i;
149 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
150 for (i=0; this->in_.ptr () && (i < this->in_->length ()); i++)
152 ACE_DEBUG ((LM_DEBUG,
153 "Element #%d\n"
154 "in : %d\n",
156 this->in_[i]));
158 if (!this->in_.ptr ())
159 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
160 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
161 for (i=0; this->inout_.ptr () && (i < this->inout_->length ()); i++)
163 ACE_DEBUG ((LM_DEBUG,
164 "Element #%d\n"
165 "in : %d\n",
167 this->inout_[i]));
169 if (!this->inout_.ptr ())
170 ACE_DEBUG ((LM_DEBUG, "\ninout sequence is NUL\n"));
171 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
172 for (i=0; this->out_.ptr () && (i < this->out_->length ()); i++)
174 ACE_DEBUG ((LM_DEBUG,
175 "Element #%d\n"
176 "in : %d\n",
178 this->out_[i]));
180 if (!this->out_.ptr ())
181 ACE_DEBUG ((LM_DEBUG, "\nout sequence is NUL\n"));
182 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
183 for (i=0; this->ret_.ptr () && (i < this->ret_->length ()); i++)
185 ACE_DEBUG ((LM_DEBUG,
186 "Element #%d\n"
187 "in : %d\n",
189 this->ret_[i]));
191 if (!this->ret_.ptr ())
192 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
193 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));