Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Param_Test / bd_str_seq.cpp
blobfc6ef3a15856f171c06ad2d64be8d8de7f9a0d30
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 ()
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 ()
31 CORBA::string_free (this->opname_);
32 this->opname_ = 0;
35 const char *
36 Test_Bounded_String_Sequence::opname () 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 ()
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");
117 return -1;
120 CORBA::Boolean
121 Test_Bounded_String_Sequence::check_validity ()
123 CORBA::Boolean flag = 0;
124 if ((this->in_->length () == this->inout_->length ()) &&
125 (this->in_->length () == this->out_->length ()) &&
126 (this->in_->length () == this->ret_->length ()))
128 flag = 1; // assume all are equal
129 // lengths are same. Now compare the contents
130 for (CORBA::ULong i=0; i < this->in_->length () && flag; i++)
132 if (ACE_OS::strcmp(this->in_[i], this->inout_[i]) ||
133 ACE_OS::strcmp(this->in_[i], this->out_[i]) ||
134 ACE_OS::strcmp(this->in_[i], this->ret_[i]))
135 // not equal
136 flag = 0;
139 return flag;
142 CORBA::Boolean
143 Test_Bounded_String_Sequence::check_validity (CORBA::Request_ptr /*req*/)
145 //ACE_UNUSED_ARG (req);
146 return this->check_validity ();
149 void
150 Test_Bounded_String_Sequence::print_values ()
152 CORBA::ULong i;
153 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
154 for (i=0; this->in_.ptr () && (i < this->in_->length ()); i++)
156 ACE_DEBUG ((LM_DEBUG,
157 "Element #%d\n"
158 "in : %C\n",
160 this->in_[i]? (const char *)this->in_[i]:"<nul>"));
162 if (!this->in_.ptr ())
163 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
164 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
165 for (i=0; this->inout_.ptr () && (i < this->inout_->length ()); i++)
167 ACE_DEBUG ((LM_DEBUG,
168 "Element #%d\n"
169 "in : %C\n",
171 (this->inout_[i]? (const char *)this->inout_[i]:"<nul>")));
173 if (!this->inout_.ptr ())
174 ACE_DEBUG ((LM_DEBUG, "\ninout sequence is NUL\n"));
175 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
176 for (i=0; this->out_.ptr () && (i < this->out_->length ()); i++)
178 ACE_DEBUG ((LM_DEBUG,
179 "Element #%d\n"
180 "in : %C\n",
182 (this->out_[i]? (const char *)this->out_[i]:"<nul>")));
184 if (!this->out_.ptr ())
185 ACE_DEBUG ((LM_DEBUG, "\nout sequence is NUL\n"));
186 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));
187 for (i=0; this->ret_.ptr () && (i < this->ret_->length ()); i++)
189 ACE_DEBUG ((LM_DEBUG,
190 "Element #%d\n"
191 "in : %C\n",
193 (this->ret_[i]? (const char *)this->ret_[i]:"<nul>")));
195 if (!this->ret_.ptr ())
196 ACE_DEBUG ((LM_DEBUG, "\nin sequence is NUL\n"));
197 ACE_DEBUG ((LM_DEBUG, "\n*=*=*=*=*=*=*=*=*=*=\n"));