Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Param_Test / bd_struct_seq.cpp
blobbfdd0a5bb402a3b882ad7a7e4aac864a35fe8e25
2 //=============================================================================
3 /**
4 * @file bd_struct_seq.cpp
6 * tests bounded struct sequences
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "helper.h"
14 #include "bd_struct_seq.h"
16 const CORBA::ULong MAX_STRUCTSEQ_LEN = 1;
18 // ************************************************************************
19 // Test_Bounded_Struct_Sequence
20 // ************************************************************************
22 Test_Bounded_Struct_Sequence::Test_Bounded_Struct_Sequence ()
23 : opname_ (CORBA::string_dup ("test_bounded_struct_sequence")),
24 inout_ (new Param_Test::Bounded_StructSeq),
25 out_ (new Param_Test::Bounded_StructSeq),
26 ret_ (new Param_Test::Bounded_StructSeq)
30 Test_Bounded_Struct_Sequence::~Test_Bounded_Struct_Sequence ()
32 CORBA::string_free (this->opname_);
33 this->opname_ = 0;
34 // the other data members will be freed as they are "_var"s and objects
35 // (rather than pointers to objects)
38 const char *
39 Test_Bounded_Struct_Sequence::opname () const
41 return this->opname_;
44 void
45 Test_Bounded_Struct_Sequence::dii_req_invoke (CORBA::Request *req)
47 req->add_in_arg ("s1") <<= this->in_;
48 req->add_inout_arg ("s2") <<= this->inout_.in ();
49 req->add_out_arg ("s3") <<= this->out_.in ();
50 req->set_return_type (Param_Test::_tc_Bounded_StructSeq);
52 req->invoke ();
54 const Param_Test::Bounded_StructSeq *tmp = 0;
55 req->return_value () >>= tmp;
56 this->ret_ = new Param_Test::Bounded_StructSeq (*tmp);
58 CORBA::NamedValue_ptr arg2 =
59 req->arguments ()->item (1);
60 *arg2->value () >>= tmp;
61 this->inout_ = new Param_Test::Bounded_StructSeq (*tmp);
63 CORBA::NamedValue_ptr arg3 =
64 req->arguments ()->item (2);
65 *arg3->value () >>= tmp;
66 this->out_ = new Param_Test::Bounded_StructSeq (*tmp);
69 int
70 Test_Bounded_Struct_Sequence::init_parameters (Param_Test_ptr /* objref */
71 /* env */)
73 Generator *gen = GENERATOR::instance (); // value generator
75 // set the length of the sequence
76 this->in_.length (MAX_STRUCTSEQ_LEN);
77 // now set each individual element
78 for (CORBA::ULong i = 0; i < this->in_.length (); i++)
80 // generate some arbitrary struct to be filled into the ith location in
81 // the sequence
82 this->in_[i] = gen->gen_fixed_struct ();
85 this->inout_->length (0);
86 this->out_->length (0);
87 this->ret_->length (0);
89 return 0;
92 int
93 Test_Bounded_Struct_Sequence::reset_parameters ()
95 this->inout_ = new Param_Test::Bounded_StructSeq; // delete the previous ones
96 this->out_ = new Param_Test::Bounded_StructSeq;
97 this->ret_ = new Param_Test::Bounded_StructSeq;
99 this->inout_->length (0);
100 this->out_->length (0);
101 this->ret_->length (0);
103 return 0;
107 Test_Bounded_Struct_Sequence::run_sii_test (Param_Test_ptr objref)
111 Param_Test::Bounded_StructSeq_out out (this->out_.out ());
113 this->ret_ = objref->test_bounded_struct_sequence (this->in_,
114 this->inout_.inout (),
115 out);
117 return 0;
119 catch (const CORBA::Exception& ex)
121 ex._tao_print_exception ("Test_Bounded_Struct_Sequence::run_sii_test\n");
123 return -1;
126 CORBA::Boolean
127 Test_Bounded_Struct_Sequence::check_validity ()
129 if (this->compare (this->in_, this->inout_.in ()) &&
130 this->compare (this->in_, this->out_.in ()) &&
131 this->compare (this->in_, this->ret_.in ()))
132 return 1;
133 else
134 return 0;
137 CORBA::Boolean
138 Test_Bounded_Struct_Sequence::check_validity (CORBA::Request_ptr)
140 return this->check_validity ();
143 void
144 Test_Bounded_Struct_Sequence::print_values ()
146 ACE_DEBUG ((LM_DEBUG,
147 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
148 "IN sequence\n"));
149 this->print_sequence (this->in_);
150 ACE_DEBUG ((LM_DEBUG,
151 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
152 "INOUT sequence\n"));
153 this->print_sequence (this->inout_.in ());
154 ACE_DEBUG ((LM_DEBUG,
155 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
156 "OUT sequence\n"));
157 this->print_sequence (this->out_.in ());
158 ACE_DEBUG ((LM_DEBUG,
159 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
160 "RET sequence\n"));
161 this->print_sequence (this->ret_.in ());
164 CORBA::Boolean
165 Test_Bounded_Struct_Sequence::compare (const Param_Test::Bounded_StructSeq &s1,
166 const Param_Test::Bounded_StructSeq &s2)
168 if (s1.maximum () != s2.maximum ())
169 return 0;
170 if (s1.length () != s2.length ())
171 return 0;
173 for (CORBA::ULong i=0; i < s1.length (); i++)
175 const Param_Test::Fixed_Struct& vs1 = s1[i];
176 const Param_Test::Fixed_Struct& vs2 = s2[i];
178 if (vs1.l != vs2.l
179 || vs1.c != vs2.c
180 || vs1.s != vs2.s
181 || vs1.o != vs2.o
182 || !ACE::is_equal (vs1.f, vs2.f)
183 || vs1.b != vs2.b
184 || !ACE::is_equal (vs1.d, vs2.d))
185 return 0;
188 return 1; // success
191 void
192 Test_Bounded_Struct_Sequence::print_sequence (const Param_Test::Bounded_StructSeq &s)
194 ACE_DEBUG ((LM_DEBUG,
195 "maximum = %d\n"
196 "length = %d\n",
197 s.maximum (),
198 s.length ()));
199 ACE_DEBUG ((LM_DEBUG, "Elements -\n"));
200 for (CORBA::ULong i=0; i < s.length (); i++)
202 const Param_Test::Fixed_Struct& vs = s[i];
204 ACE_DEBUG ((LM_DEBUG,
205 "Element #%d\n"
206 "\tl = %d\n"
207 "\tc = %c\n"
208 "\ts = %d\n"
209 "\to = %x\n"
210 "\tf = %f\n"
211 "\tb = %d\n"
212 "\td = %f\n",
214 vs.l, vs.c, vs.s, vs.o, vs.f, vs.b, vs.d));