Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Param_Test / complex_any.cpp
blobd13c60fb28551df365101534e0321624672412d7
2 //=============================================================================
3 /**
4 * @file complex_any.cpp
6 * tests complex Anys
8 * @author Aniruddha Gokhale
9 * @author Jeff Parsons
10 * @author Frank Buschmann
12 //=============================================================================
15 #include "helper.h"
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 // ************************************************************************
23 // Test_Complex_Any
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),
31 ret_ (new CORBA::Any)
35 Test_Complex_Any::~Test_Complex_Any ()
37 CORBA::string_free (this->opname_);
38 this->opname_ = 0;
41 const char *
42 Test_Complex_Any::opname () const
44 return this->opname_;
47 void
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);
56 req->invoke ();
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);
73 int
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
84 // <- boolean
85 // <- short
86 int
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",
106 l5_str));
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",
119 l9_str));
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",
128 l9_bool));
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",
137 l9_short));
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;
155 return 0;
159 Test_Complex_Any::run_sii_test (Param_Test_ptr objref)
163 this->ret_ = objref->test_complex_any (this->in_,
164 this->inout_,
165 this->out_.out ());
167 catch (const CORBA::Exception&)
169 return -1;
171 return 0;
174 CORBA::Boolean
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))
181 return 0;
183 if (!(this->inout_ >>= level2_test_seq))
184 return 0;
186 if (this->comp_engine (level2_in_seq, level2_test_seq) == 0)
187 return 0;
189 if (!(this->out_.in () >>= level2_test_seq))
190 return 0;
192 if (this->comp_engine (level2_in_seq, level2_test_seq) == 0)
193 return 0;
195 if (!(this->ret_.in () >>= level2_test_seq))
196 return 0;
198 if (this->comp_engine (level2_in_seq, level2_test_seq) == 0)
199 return 0;
201 return 1;
204 // Private helper function for check_validity.
205 CORBA::Boolean
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"));
213 return 0;
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))
222 return 0;
223 if (!((*level2_comp_seq)[i] >>= level3_test_seq))
224 return 0;
226 if (level3_in_seq->length() != level3_test_seq->length())
228 ACE_DEBUG ((LM_DEBUG,
229 "mismatch of level 3 sequence lengths\n"));
230 return 0;
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))
239 return 0;
240 if (!((*level3_test_seq)[j] >>= level4_test_struct))
241 return 0;
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"));
248 return 0;
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))
257 return 0;
258 if (!(level4_test_struct->level5_any >>= level6_test_any))
259 return 0;
261 if (!((*level6_in_any) >>= level7_in_any))
262 return 0;
263 if (!((*level6_test_any) >>= level7_test_any))
264 return 0;
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))
270 return 0;
271 if (!((*level7_test_any) >>= level8_test_struct))
272 return 0;
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"));
279 return 0;
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"));
286 return 0;
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"));
293 return 0;
298 // If we get here, all is correct.
299 return 1;
302 CORBA::Boolean
303 Test_Complex_Any::check_validity (CORBA::Request_ptr /*req*/)
305 return this->check_validity ();
308 void
309 Test_Complex_Any::print_values ()