Continued changes from peer review
[ACE_TAO.git] / TAO / tests / Param_Test / bd_str_seq.cpp
blobfc9dd8cce6173cb6d3ef7bb7f8897cdbe9c1ae34
2 //=============================================================================
3 /**
4 * @file bd_str_seq.cpp
6 * tests bounded string sequences
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "bd_str_seq.h"
16 // ************************************************************************
17 // Test_Bounded_String_Sequence
18 // ************************************************************************
20 Test_Bounded_String_Sequence::Test_Bounded_String_Sequence (void)
21 : opname_ (CORBA::string_dup ("test_bounded_strseq")),
22 in_ (new Param_Test::Bounded_StrSeq),
23 inout_ (new Param_Test::Bounded_StrSeq),
24 out_ (new Param_Test::Bounded_StrSeq),
25 ret_ (new Param_Test::Bounded_StrSeq)
29 Test_Bounded_String_Sequence::~Test_Bounded_String_Sequence (void)
31 CORBA::string_free (this->opname_);
32 this->opname_ = 0;
35 const char *
36 Test_Bounded_String_Sequence::opname (void) const
38 return this->opname_;
41 void
42 Test_Bounded_String_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 (Param_Test::_tc_Bounded_StrSeq);
50 req->invoke ();
52 const Param_Test::Bounded_StrSeq *tmp;
53 req->return_value () >>= tmp;
54 this->ret_ = new Param_Test::Bounded_StrSeq (*tmp);
56 CORBA::NamedValue_ptr arg2 =
57 req->arguments ()->item (1);
58 *arg2->value () >>= tmp;
59 this->inout_ = new Param_Test::Bounded_StrSeq (*tmp);
61 CORBA::NamedValue_ptr arg3 =
62 req->arguments ()->item (2);
63 *arg3->value () >>= tmp;
64 this->out_ = new Param_Test::Bounded_StrSeq (*tmp);
67 int
68 Test_Bounded_String_Sequence::init_parameters (Param_Test_ptr)
70 const char *choiceList[] =
72 "one",
73 "two",
74 "three"
77 CORBA::ULong len = this->in_->maximum ();
79 // set the length of the sequence
80 this->in_->length (len);
81 this->inout_->length (len);
82 // now set each individual element
83 for (CORBA::ULong i=0; i < this->in_->length (); i++)
85 this->in_[i] = choiceList[i%3];
86 this->inout_[i] = choiceList[(i+1)%3]; // different from in_
88 return 0;
91 int
92 Test_Bounded_String_Sequence::reset_parameters (void)
94 this->inout_ = new Param_Test::Bounded_StrSeq; // delete the previous ones
95 this->out_ = new Param_Test::Bounded_StrSeq;
96 this->ret_ = new Param_Test::Bounded_StrSeq;
97 return 0;
101 Test_Bounded_String_Sequence::run_sii_test (Param_Test_ptr objref)
105 Param_Test::Bounded_StrSeq_out out (this->out_.out ());
107 this->ret_ = objref->test_bounded_strseq (this->in_.in (),
108 this->inout_.inout (),
109 out);
111 return 0;
113 catch (const CORBA::Exception& ex)
115 ex._tao_print_exception ("Test_Bounded_String_Sequence::run_sii_test\n");
118 return -1;
121 CORBA::Boolean
122 Test_Bounded_String_Sequence::check_validity (void)
124 CORBA::Boolean flag = 0;
125 if ((this->in_->length () == this->inout_->length ()) &&
126 (this->in_->length () == this->out_->length ()) &&
127 (this->in_->length () == this->ret_->length ()))
129 flag = 1; // assume all are equal
130 // lengths are same. Now compare the contents
131 for (CORBA::ULong i=0; i < this->in_->length () && flag; i++)
133 if (ACE_OS::strcmp(this->in_[i], this->inout_[i]) ||
134 ACE_OS::strcmp(this->in_[i], this->out_[i]) ||
135 ACE_OS::strcmp(this->in_[i], this->ret_[i]))
136 // not equal
137 flag = 0;
140 return flag;
143 CORBA::Boolean
144 Test_Bounded_String_Sequence::check_validity (CORBA::Request_ptr /*req*/)
146 //ACE_UNUSED_ARG (req);
147 return this->check_validity ();
150 void
151 Test_Bounded_String_Sequence::print_values (void)
153 CORBA::ULong i;
154 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
155 for (i=0; this->in_.ptr () && (i < this->in_->length ()); i++)
157 ACE_DEBUG ((LM_DEBUG,
158 "Element #%d\n"
159 "in : %s\n",
161 this->in_[i]? (const char *)this->in_[i]:"<nul>"));
163 if (!this->in_.ptr ())
164 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
165 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
166 for (i=0; this->inout_.ptr () && (i < this->inout_->length ()); i++)
168 ACE_DEBUG ((LM_DEBUG,
169 "Element #%d\n"
170 "in : %s\n",
172 (this->inout_[i]? (const char *)this->inout_[i]:"<nul>")));
174 if (!this->inout_.ptr ())
175 ACE_DEBUG ((LM_DEBUG, "\ninout sequence is NUL\n"));
176 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
177 for (i=0; this->out_.ptr () && (i < this->out_->length ()); i++)
179 ACE_DEBUG ((LM_DEBUG,
180 "Element #%d\n"
181 "in : %s\n",
183 (this->out_[i]? (const char *)this->out_[i]:"<nul>")));
185 if (!this->out_.ptr ())
186 ACE_DEBUG ((LM_DEBUG, "\nout sequence is NUL\n"));
187 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
188 for (i=0; this->ret_.ptr () && (i < this->ret_->length ()); i++)
190 ACE_DEBUG ((LM_DEBUG,
191 "Element #%d\n"
192 "in : %s\n",
194 (this->ret_[i]? (const char *)this->ret_[i]:"<nul>")));
196 if (!this->ret_.ptr ())
197 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
198 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));