3 //=============================================================================
5 * @file ub_struct_seq.cpp
7 * tests unbounded struct sequences
9 * @author Aniruddha Gokhale
11 //=============================================================================
15 #include "ub_struct_seq.h"
17 // ************************************************************************
18 // Test_Struct_Sequence
19 // ************************************************************************
21 Test_Struct_Sequence::Test_Struct_Sequence ()
22 : opname_ (CORBA::string_dup ("test_struct_sequence")),
23 inout_ (new Param_Test::StructSeq
),
24 out_ (new Param_Test::StructSeq
),
25 ret_ (new Param_Test::StructSeq
)
29 Test_Struct_Sequence::~Test_Struct_Sequence ()
31 CORBA::string_free (this->opname_
);
33 // the other data members will be freed as they are "_var"s and objects
34 // (rather than pointers to objects)
38 Test_Struct_Sequence::opname () const
44 Test_Struct_Sequence::dii_req_invoke (CORBA::Request
*req
)
46 req
->add_in_arg ("s1") <<= this->in_
;
47 req
->add_inout_arg ("s2") <<= this->inout_
.in ();
48 req
->add_out_arg ("s3") <<= this->out_
.in ();
50 req
->set_return_type (Param_Test::_tc_StructSeq
);
54 const Param_Test::StructSeq
*tmp
= 0;
55 req
->return_value () >>= tmp
;
56 this->ret_
= new Param_Test::StructSeq (*tmp
);
58 CORBA::NamedValue_ptr o2
=
59 req
->arguments ()->item (1);
60 *o2
->value () >>= tmp
;
61 this->inout_
= new Param_Test::StructSeq (*tmp
);
63 CORBA::NamedValue_ptr o3
=
64 req
->arguments ()->item (2);
65 *o3
->value () >>= tmp
;
66 this->out_
= new Param_Test::StructSeq (*tmp
);
70 Test_Struct_Sequence::init_parameters (Param_Test_ptr
)
72 Generator
*gen
= GENERATOR::instance (); // value generator
74 // get some sequence length (not more than 10)
75 CORBA::ULong len
= (CORBA::ULong
) (gen
->gen_long () % 10) + 1;
77 // set the length of the sequence
78 this->in_
.length (len
);
79 this->inout_
->length (len
);
80 // now set each individual element
81 for (CORBA::ULong i
= 0; i
< this->in_
.length (); i
++)
83 // generate some arbitrary struct to be filled into the ith location in
85 this->in_
[i
] = gen
->gen_fixed_struct ();
86 this->inout_
[i
] = gen
->gen_fixed_struct ();
92 Test_Struct_Sequence::reset_parameters ()
94 this->inout_
= new Param_Test::StructSeq
; // delete the previous one
95 this->out_
= new Param_Test::StructSeq
;
96 this->ret_
= new Param_Test::StructSeq
;
101 Test_Struct_Sequence::run_sii_test (Param_Test_ptr objref
)
105 Param_Test::StructSeq_out
out (this->out_
.out ());
107 this->ret_
= objref
->test_struct_sequence (this->in_
,
108 this->inout_
.inout (),
113 catch (const CORBA::Exception
& ex
)
115 ex
._tao_print_exception ("Test_Struct_Sequence::run_sii_test\n");
121 Test_Struct_Sequence::check_validity ()
123 if (this->compare (this->in_
, this->inout_
.in ()) &&
124 this->compare (this->in_
, this->out_
.in ()) &&
125 this->compare (this->in_
, this->ret_
.in ()))
132 Test_Struct_Sequence::check_validity (CORBA::Request_ptr
)
134 return this->check_validity ();
138 Test_Struct_Sequence::print_values ()
140 ACE_DEBUG ((LM_DEBUG
,
141 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
143 this->print_sequence (this->in_
);
144 ACE_DEBUG ((LM_DEBUG
,
145 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
146 "INOUT sequence\n"));
147 this->print_sequence (this->inout_
.in ());
148 ACE_DEBUG ((LM_DEBUG
,
149 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
151 this->print_sequence (this->out_
.in ());
152 ACE_DEBUG ((LM_DEBUG
,
153 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
155 this->print_sequence (this->ret_
.in ());
159 Test_Struct_Sequence::compare (const Param_Test::StructSeq
&s1
,
160 const Param_Test::StructSeq
&s2
)
162 if (s1
.maximum () != s2
.maximum ())
164 if (s1
.length () != s2
.length ())
167 for (CORBA::ULong i
=0; i
< s1
.length (); i
++)
169 const Param_Test::Fixed_Struct
& vs1
= s1
[i
];
170 const Param_Test::Fixed_Struct
& vs2
= s2
[i
];
176 || !ACE::is_equal (vs1
.f
, vs2
.f
)
178 || !ACE::is_equal (vs1
.d
, vs2
.d
))
186 Test_Struct_Sequence::print_sequence (const Param_Test::StructSeq
&s
)
188 ACE_DEBUG ((LM_DEBUG
,
193 ACE_DEBUG ((LM_DEBUG
, "Elements -\n"));
194 for (CORBA::ULong i
=0; i
< s
.length (); i
++)
196 const Param_Test::Fixed_Struct
& vs
= s
[i
];
198 ACE_DEBUG ((LM_DEBUG
,
208 vs
.l
, vs
.c
, vs
.s
, vs
.o
, vs
.f
, vs
.b
, vs
.d
));
213 // ************************************************************************
214 // Test_Unbounded_Struct_Sequence
215 // ************************************************************************
217 Test_Unbounded_Struct_Sequence::Test_Unbounded_Struct_Sequence ()
218 : opname_ (CORBA::string_dup ("test_unbounded_struct_sequence")),
219 inout_ (new Param_Test::PathSpec
),
220 out_ (new Param_Test::PathSpec
),
221 ret_ (new Param_Test::PathSpec
)
225 Test_Unbounded_Struct_Sequence::~Test_Unbounded_Struct_Sequence ()
227 CORBA::string_free (this->opname_
);
229 // the other data members will be freed as they are "_var"s and objects
230 // (rather than pointers to objects)
234 Test_Unbounded_Struct_Sequence::opname () const
236 return this->opname_
;
240 Test_Unbounded_Struct_Sequence::dii_req_invoke (CORBA::Request
*req
)
242 req
->add_in_arg ("s1") <<= this->in_
;
243 req
->add_inout_arg ("s2") <<= this->inout_
.in ();
244 req
->add_out_arg ("s3") <<= this->out_
.in ();
246 req
->set_return_type (Param_Test::_tc_PathSpec
);
250 const Param_Test::PathSpec
*tmp
= 0;
251 req
->return_value () >>= tmp
;
252 this->ret_
= new Param_Test::PathSpec (*tmp
);
254 CORBA::NamedValue_ptr o2
=
255 req
->arguments ()->item (1);
256 *o2
->value () >>= tmp
;
257 this->inout_
= new Param_Test::PathSpec (*tmp
);
259 CORBA::NamedValue_ptr o3
=
260 req
->arguments ()->item (2);
261 *o3
->value () >>= tmp
;
262 this->out_
= new Param_Test::PathSpec (*tmp
);
266 Test_Unbounded_Struct_Sequence::init_parameters (Param_Test_ptr
)
268 Generator
*gen
= GENERATOR::instance (); // value generator
270 // get some sequence length (not more than 10)
271 CORBA::ULong len
= (CORBA::ULong
) (gen
->gen_long () % 10) + 1;
273 // set the length of the sequence
274 this->in_
.length (len
);
275 this->inout_
->length (len
);
276 // now set each individual element
278 for (CORBA::ULong i
= 0; i
< this->in_
.length (); i
++)
280 // generate some arbitrary string to be filled into the ith location in
282 this->in_
[i
] = gen
->gen_step ();
283 this->inout_
[i
] = gen
->gen_step ();
289 Test_Unbounded_Struct_Sequence::reset_parameters ()
291 this->inout_
= new Param_Test::PathSpec
; // delete the previous one
292 this->out_
= new Param_Test::PathSpec
;
293 this->ret_
= new Param_Test::PathSpec
;
298 Test_Unbounded_Struct_Sequence::run_sii_test (Param_Test_ptr objref
)
300 Param_Test::PathSpec_out
out (this->out_
.out ());
301 this->ret_
= objref
->test_unbounded_struct_sequence (this->in_
,
302 this->inout_
.inout (),
309 Test_Unbounded_Struct_Sequence::check_validity ()
311 if (this->compare (this->in_
, this->inout_
.in ()) &&
312 this->compare (this->in_
, this->out_
.in ()) &&
313 this->compare (this->in_
, this->ret_
.in ()))
320 Test_Unbounded_Struct_Sequence::check_validity (CORBA::Request_ptr
)
322 return this->check_validity ();
326 Test_Unbounded_Struct_Sequence::print_values ()
328 ACE_DEBUG ((LM_DEBUG
,
329 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
331 this->print_sequence (this->in_
);
332 ACE_DEBUG ((LM_DEBUG
,
333 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
334 "INOUT sequence\n"));
335 this->print_sequence (this->inout_
.in ());
336 ACE_DEBUG ((LM_DEBUG
,
337 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
339 this->print_sequence (this->out_
.in ());
340 ACE_DEBUG ((LM_DEBUG
,
341 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
343 this->print_sequence (this->ret_
.in ());
347 Test_Unbounded_Struct_Sequence::compare (const Param_Test::PathSpec
&s1
,
348 const Param_Test::PathSpec
&s2
)
350 if (s1
.maximum () != s2
.maximum ())
352 if (s1
.length () != s2
.length ())
355 for (CORBA::ULong i
=0; i
< s1
.length (); i
++)
357 const Param_Test::Step
& vs1
= s1
[i
];
358 const Param_Test::Step
& vs2
= s2
[i
];
360 if (ACE_OS::strcmp (vs1
.name
.id
.in (), vs2
.name
.id
.in ())
361 || ACE_OS::strcmp (vs1
.name
.kind
.in (), vs2
.name
.kind
.in ())
362 || vs1
.process
!= vs2
.process
)
369 Test_Unbounded_Struct_Sequence::print_sequence (const Param_Test::PathSpec
&s
)
371 ACE_DEBUG ((LM_DEBUG
,
376 ACE_DEBUG ((LM_DEBUG
, "Elements -\n"));
377 for (CORBA::ULong i
=0; i
< s
.length (); i
++)
379 const Param_Test::Step
& vs
= s
[i
];
381 ACE_DEBUG ((LM_DEBUG
,
387 vs
.name
.id
.in (), vs
.name
.kind
.in (), vs
.process
));