2 //=============================================================================
4 * @file ub_objref_seq.cpp
6 * tests unbounded objref sequences
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 #include "ub_objref_seq.h"
16 // ************************************************************************
17 // Test_ObjRef_Sequence
18 // ************************************************************************
20 static const char *Coffee_Flavor
[] = {
26 "Swiss Chocolate Mocha"
29 Test_ObjRef_Sequence::Test_ObjRef_Sequence ()
30 : opname_ (CORBA::string_dup ("test_coffe_mix")),
31 inout_ (new Param_Test::Coffee_Mix
),
32 out_ (new Param_Test::Coffee_Mix
),
33 ret_ (new Param_Test::Coffee_Mix
)
37 Test_ObjRef_Sequence::~Test_ObjRef_Sequence ()
39 CORBA::string_free (this->opname_
);
41 // the other data members will be freed as they are "_var"s and objects
42 // (rather than pointers to objects)
46 Test_ObjRef_Sequence::opname () const
52 Test_ObjRef_Sequence::dii_req_invoke (CORBA::Request
*req
)
54 req
->add_in_arg ("s1") <<= this->in_
;
55 req
->add_inout_arg ("s2") <<= this->inout_
.in ();
56 req
->add_out_arg ("s3") <<= this->out_
.in ();
58 req
->set_return_type (Param_Test::_tc_Coffee_Mix
);
62 const Param_Test::Coffee_Mix
*tmp
= 0;
63 req
->return_value () >>= tmp
;
64 this->ret_
= new Param_Test::Coffee_Mix (*tmp
);
66 CORBA::NamedValue_ptr o2
=
67 req
->arguments ()->item (1);
68 *o2
->value () >>= tmp
;
69 this->inout_
= new Param_Test::Coffee_Mix (*tmp
);
71 CORBA::NamedValue_ptr o3
=
72 req
->arguments ()->item (2);
73 *o3
->value () >>= tmp
;
74 this->out_
= new Param_Test::Coffee_Mix (*tmp
);
78 Test_ObjRef_Sequence::init_parameters (Param_Test_ptr objref
)
83 Generator
*gen
= GENERATOR::instance (); // value generator
85 // get some sequence length (not more than 10)
86 CORBA::ULong len
= (CORBA::ULong
) (gen
->gen_long () % 5) + 5;
88 // set the length of the sequence
89 this->in_
.length (len
);
90 // now set each individual element
92 for (CORBA::ULong i
= 0; i
< this->in_
.length (); i
++)
94 // generate some arbitrary string to be filled into the ith location in
96 this->in_
[i
] = objref
->make_coffee ();
98 // select a Coffee flavor at random
99 CORBA::ULong index
= (CORBA::ULong
) (gen
->gen_long () % 6);
101 desc
.name
= Coffee_Flavor
[index
];
102 // set the attribute for the in object
103 Coffee_ptr tmp
= this->in_
[i
];
105 tmp
->description (desc
);
110 catch (const CORBA::Exception
& ex
)
112 ex
._tao_print_exception ("Test_ObjRef_Sequence::init_parameters\n");
118 Test_ObjRef_Sequence::reset_parameters ()
120 this->inout_
= new Param_Test::Coffee_Mix
; // delete the previous ones
121 this->out_
= new Param_Test::Coffee_Mix
;
122 this->ret_
= new Param_Test::Coffee_Mix
;
127 Test_ObjRef_Sequence::run_sii_test (Param_Test_ptr objref
)
131 Param_Test::Coffee_Mix_out
out (this->out_
.out ());
133 this->ret_
= objref
->test_coffe_mix (this->in_
,
134 this->inout_
.inout (),
139 catch (const CORBA::Exception
& ex
)
141 ex
._tao_print_exception ("Test_ObjRef_Sequence::run_sii_test\n");
147 Test_ObjRef_Sequence::check_validity ()
151 this->compare (this->in_
,
154 this->compare (this->in_
,
157 this->compare (this->in_
,
162 catch (const CORBA::Exception
& ex
)
164 ex
._tao_print_exception ("Test_ObjRef_Sequence::check_validity");
170 Test_ObjRef_Sequence::check_validity (CORBA::Request_ptr
)
172 //ACE_UNUSED_ARG (req);
173 return this->check_validity ();
177 Test_ObjRef_Sequence::print_values ()
179 ACE_DEBUG ((LM_DEBUG
,
180 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
182 this->print_sequence (this->in_
);
183 ACE_DEBUG ((LM_DEBUG
,
184 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
185 "INOUT sequence\n"));
186 this->print_sequence (this->inout_
.in ());
187 ACE_DEBUG ((LM_DEBUG
,
188 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
190 this->print_sequence (this->out_
.in ());
191 ACE_DEBUG ((LM_DEBUG
,
192 "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"
194 this->print_sequence (this->ret_
.in ());
198 Test_ObjRef_Sequence::compare (const Param_Test::Coffee_Mix
&s1
,
199 const Param_Test::Coffee_Mix
&s2
)
203 if (s1
.maximum () != s2
.maximum ())
207 if (s1
.length () != s2
.length ())
212 for (CORBA::ULong i
=0; i
< s1
.length (); i
++)
214 Coffee_ptr vs1
= s1
[i
];
215 Coffee_ptr vs2
= s2
[i
];
217 if (CORBA::is_nil (vs1
) && CORBA::is_nil (vs2
))
222 if (CORBA::is_nil (vs1
) || CORBA::is_nil (vs2
))
227 Coffee::Desc_var desc1
= vs1
->description ();
229 CORBA::String_var n1
= desc1
->name
.in ();
231 Coffee::Desc_var desc2
= vs2
->description ();
233 CORBA::String_var n2
= desc2
->name
.in ();
235 if (ACE_OS::strcmp(n1
.in (), n2
.in ()) != 0)
243 catch (const CORBA::Exception
& ex
)
245 ex
._tao_print_exception ("Test_ObjRef_Sequence::compare");
251 Test_ObjRef_Sequence::print_sequence (const Param_Test::Coffee_Mix
&s
)
253 ACE_DEBUG ((LM_DEBUG
,
258 ACE_DEBUG ((LM_DEBUG
, "Elements -\n"));
259 for (CORBA::ULong i
=0; i
< s
.length (); i
++)
262 if (CORBA::is_nil (c
))
264 ACE_DEBUG ((LM_DEBUG
,
265 "Element #%d is nil\n", i
));
268 ACE_DEBUG ((LM_DEBUG
,
272 c
->_interface_repository_id ()));