2 //=============================================================================
4 * @file complex_any.cpp
8 * @author Aniruddha Gokhale
10 * @author Frank Buschmann
12 //=============================================================================
16 #include "complex_any.h"
17 #include "tao/debug.h"
19 const int LEVEL_2_LENGTH
= 5;
20 const int LEVEL_3_LENGTH
= 3;
22 // ************************************************************************
24 // ************************************************************************
26 size_t Test_Complex_Any::counter
= 0;
28 Test_Complex_Any::Test_Complex_Any ()
29 : opname_ (CORBA::string_dup ("test_complex_any")),
30 out_ (new CORBA::Any
),
35 Test_Complex_Any::~Test_Complex_Any ()
37 CORBA::string_free (this->opname_
);
42 Test_Complex_Any::opname () const
48 Test_Complex_Any::dii_req_invoke (CORBA::Request
*req
)
50 req
->add_in_arg ("s1") <<= this->in_
;
51 req
->add_inout_arg ("s2") <<= this->inout_
;
52 req
->add_out_arg ("s3") <<= this->out_
.in ();
54 req
->set_return_type (CORBA::_tc_any
);
58 const CORBA::Any
*tmp
;
59 req
->return_value () >>= tmp
;
60 this->ret_
= new CORBA::Any (*tmp
);
62 CORBA::NamedValue_ptr o2
=
63 req
->arguments ()->item (1);
64 *o2
->value () >>= tmp
;
65 this->inout_
= CORBA::Any (*tmp
);
67 CORBA::NamedValue_ptr o3
=
68 req
->arguments ()->item (2);
69 *o3
->value () >>= tmp
;
70 this->out_
= new CORBA::Any (*tmp
);
74 Test_Complex_Any::init_parameters (Param_Test_ptr
)
76 return this->reset_parameters ();
79 // This Any is a real-world use cases
80 // submitted by Frank Buschmann of Siemens. Here's the structure:
82 // Any <- AnySeq <- AnySeq <- struct <- string
83 // <- Any <- Any <- Any <- struct <- string
87 Test_Complex_Any::reset_parameters ()
89 Generator
*gen
= GENERATOR::instance (); // value generator
91 CORBA::AnySeq level2_seq
, level3_seq
;
92 level2_seq
.length (LEVEL_2_LENGTH
);
93 level3_seq
.length (LEVEL_3_LENGTH
);
95 for (int j
= 0; j
< LEVEL_2_LENGTH
; j
++)
97 for (int i
= 0; i
< LEVEL_3_LENGTH
; i
++)
99 Param_Test::level4 level4_struct
;
101 char *l5_str
= gen
->gen_string ();
103 if (TAO_debug_level
> 0)
104 ACE_DEBUG ((LM_DEBUG
,
105 "setting level 5 string = %C\n",
108 level4_struct
.level5_string
= l5_str
;
110 CORBA::Any level6_any
, level7_any
;
112 Param_Test::level8 level8_struct
;
114 char *l9_str
= gen
->gen_string ();
116 if (TAO_debug_level
> 0)
117 ACE_DEBUG ((LM_DEBUG
,
118 "setting level 9 string = %C\n",
121 level8_struct
.level9_string
= l9_str
;
123 CORBA::Short l9_bool
= ACE_OS::rand () % 2;
125 if (TAO_debug_level
> 0)
126 ACE_DEBUG ((LM_DEBUG
,
127 "setting level 9 boolean = %d\n",
130 level8_struct
.level9_boolean
= (CORBA::Boolean
) l9_bool
;
132 CORBA::Short l9_short
= gen
->gen_short ();
134 if (TAO_debug_level
> 0)
135 ACE_DEBUG ((LM_DEBUG
,
136 "setting level 9 short = %d\n",
139 level8_struct
.level9_short
= l9_short
;
141 level7_any
<<= level8_struct
;
143 level6_any
<<= level7_any
;
145 level4_struct
.level5_any
<<= level6_any
;
147 level3_seq
[i
] <<= level4_struct
;
150 level2_seq
[j
] <<= level3_seq
;
153 this->in_
<<= level2_seq
;
159 Test_Complex_Any::run_sii_test (Param_Test_ptr objref
)
163 this->ret_
= objref
->test_complex_any (this->in_
,
167 catch (const CORBA::Exception
&)
175 Test_Complex_Any::check_validity ()
177 const CORBA::AnySeq
*level2_in_seq
= 0;
178 const CORBA::AnySeq
*level2_test_seq
= 0;
180 if (!(this->in_
>>= level2_in_seq
))
183 if (!(this->inout_
>>= level2_test_seq
))
186 if (this->comp_engine (level2_in_seq
, level2_test_seq
) == 0)
189 if (!(this->out_
.in () >>= level2_test_seq
))
192 if (this->comp_engine (level2_in_seq
, level2_test_seq
) == 0)
195 if (!(this->ret_
.in () >>= level2_test_seq
))
198 if (this->comp_engine (level2_in_seq
, level2_test_seq
) == 0)
204 // Private helper function for check_validity.
206 Test_Complex_Any::comp_engine (const CORBA::AnySeq
*level2_in_seq
,
207 const CORBA::AnySeq
*level2_comp_seq
)
209 if (level2_in_seq
->length() != level2_comp_seq
->length())
211 ACE_DEBUG ((LM_DEBUG
,
212 "mismatch of level 2 sequence lengths\n"));
216 for (CORBA::ULong i
= 0; i
< level2_in_seq
->length (); i
++)
218 const CORBA::AnySeq
*level3_in_seq
= 0;
219 const CORBA::AnySeq
*level3_test_seq
= 0;
221 if (!((*level2_in_seq
)[i
] >>= level3_in_seq
))
223 if (!((*level2_comp_seq
)[i
] >>= level3_test_seq
))
226 if (level3_in_seq
->length() != level3_test_seq
->length())
228 ACE_DEBUG ((LM_DEBUG
,
229 "mismatch of level 3 sequence lengths\n"));
233 for (CORBA::ULong j
= 0; j
< level3_in_seq
->length (); j
++)
235 const Param_Test::level4
*level4_in_struct
= 0;
236 const Param_Test::level4
*level4_test_struct
= 0;
238 if (!((*level3_in_seq
)[j
] >>= level4_in_struct
))
240 if (!((*level3_test_seq
)[j
] >>= level4_test_struct
))
243 if (ACE_OS::strcmp (level4_in_struct
->level5_string
,
244 level4_test_struct
->level5_string
))
246 ACE_DEBUG ((LM_DEBUG
,
247 "mismatch of level 5 string values\n"));
251 const CORBA::Any
*level6_in_any
;
252 const CORBA::Any
*level6_test_any
;
253 const CORBA::Any
*level7_in_any
;
254 const CORBA::Any
*level7_test_any
;
256 if (!(level4_in_struct
->level5_any
>>= level6_in_any
))
258 if (!(level4_test_struct
->level5_any
>>= level6_test_any
))
261 if (!((*level6_in_any
) >>= level7_in_any
))
263 if (!((*level6_test_any
) >>= level7_test_any
))
266 const Param_Test::level8
*level8_in_struct
= 0;
267 const Param_Test::level8
*level8_test_struct
= 0;
269 if (!((*level7_in_any
) >>= level8_in_struct
))
271 if (!((*level7_test_any
) >>= level8_test_struct
))
274 if (ACE_OS::strcmp (level8_in_struct
->level9_string
,
275 level8_test_struct
->level9_string
))
277 ACE_DEBUG ((LM_DEBUG
,
278 "mismatch of level 9 string values\n"));
282 if (level8_in_struct
->level9_boolean
!= level8_test_struct
->level9_boolean
)
284 ACE_DEBUG ((LM_DEBUG
,
285 "mismatch of level 9 boolean values\n"));
289 if (level8_in_struct
->level9_short
!= level8_test_struct
->level9_short
)
291 ACE_DEBUG ((LM_DEBUG
,
292 "mismatch of level 9 short values\n"));
298 // If we get here, all is correct.
303 Test_Complex_Any::check_validity (CORBA::Request_ptr
/*req*/)
305 return this->check_validity ();
309 Test_Complex_Any::print_values ()