Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Param_Test / bd_struct_seq.cpp
blob7a4cae63357fe390d82b4cfae583b649bb95f183
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 (void)
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 (void)
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 (void) 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 (void)
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");
124 return -1;
127 CORBA::Boolean
128 Test_Bounded_Struct_Sequence::check_validity (void)
130 if (this->compare (this->in_, this->inout_.in ()) &&
131 this->compare (this->in_, this->out_.in ()) &&
132 this->compare (this->in_, this->ret_.in ()))
133 return 1;
134 else
135 return 0;
138 CORBA::Boolean
139 Test_Bounded_Struct_Sequence::check_validity (CORBA::Request_ptr)
141 return this->check_validity ();
144 void
145 Test_Bounded_Struct_Sequence::print_values (void)
147 ACE_DEBUG ((LM_DEBUG,
148 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
149 "IN sequence\n"));
150 this->print_sequence (this->in_);
151 ACE_DEBUG ((LM_DEBUG,
152 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
153 "INOUT sequence\n"));
154 this->print_sequence (this->inout_.in ());
155 ACE_DEBUG ((LM_DEBUG,
156 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
157 "OUT sequence\n"));
158 this->print_sequence (this->out_.in ());
159 ACE_DEBUG ((LM_DEBUG,
160 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
161 "RET sequence\n"));
162 this->print_sequence (this->ret_.in ());
165 CORBA::Boolean
166 Test_Bounded_Struct_Sequence::compare (const Param_Test::Bounded_StructSeq &s1,
167 const Param_Test::Bounded_StructSeq &s2)
169 if (s1.maximum () != s2.maximum ())
170 return 0;
171 if (s1.length () != s2.length ())
172 return 0;
174 for (CORBA::ULong i=0; i < s1.length (); i++)
176 const Param_Test::Fixed_Struct& vs1 = s1[i];
177 const Param_Test::Fixed_Struct& vs2 = s2[i];
179 if (vs1.l != vs2.l
180 || vs1.c != vs2.c
181 || vs1.s != vs2.s
182 || vs1.o != vs2.o
183 || !ACE::is_equal (vs1.f, vs2.f)
184 || vs1.b != vs2.b
185 || !ACE::is_equal (vs1.d, vs2.d))
186 return 0;
189 return 1; // success
192 void
193 Test_Bounded_Struct_Sequence::print_sequence (const Param_Test::Bounded_StructSeq &s)
195 ACE_DEBUG ((LM_DEBUG,
196 "maximum = %d\n"
197 "length = %d\n",
198 s.maximum (),
199 s.length ()));
200 ACE_DEBUG ((LM_DEBUG, "Elements -\n"));
201 for (CORBA::ULong i=0; i < s.length (); i++)
203 const Param_Test::Fixed_Struct& vs = s[i];
205 ACE_DEBUG ((LM_DEBUG,
206 "Element #%d\n"
207 "\tl = %d\n"
208 "\tc = %c\n"
209 "\ts = %d\n"
210 "\to = %x\n"
211 "\tf = %f\n"
212 "\tb = %d\n"
213 "\td = %f\n",
215 vs.l, vs.c, vs.s, vs.o, vs.f, vs.b, vs.d));