Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Param_Test / anyop.cpp
blobfc41d35ef63bb22ac6e90e85778e014ddfb45ce3
2 //=============================================================================
3 /**
4 * @file anyop.cpp
6 * @author Carlos O'Ryan
7 */
8 //=============================================================================
11 #include "param_testC.h"
13 #include "tao/debug.h"
14 #include "ace/OS_NS_string.h"
16 // Not normally needed, but we create an object reference in this test,
17 // and we have to narrow it.
18 #include "tao/Object_T.h"
19 #include "tao/Stub.h"
20 #include "ace/Get_Opt.h"
22 int
23 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
25 int n = 1024;
27 try
29 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
31 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("dn:"));
32 int opt;
34 while ((opt = get_opt ()) != EOF)
36 switch (opt)
38 case 'd':
39 TAO_debug_level++;
40 break;
41 case 'n':
42 n = ACE_OS::atoi (get_opt.opt_arg ());
43 break;
44 case '?':
45 default:
46 ACE_DEBUG ((LM_DEBUG,
47 "Usage: %s "
48 "-d debug"
49 "-n <num> "
50 "\n",
51 argv[0]));
52 return -1;
56 for (int i = 0; i != n; ++i)
58 CORBA::Any any;
61 Param_Test::Var_Array var_array;
62 any <<= Param_Test::Var_Array_forany (var_array);
64 Param_Test::Var_Array_forany forany;
66 if (!(any >>= forany))
68 ACE_DEBUG ((LM_DEBUG,
69 "Failure for Param_Test::Var_Array\n"));
71 Param_Test::Var_Array_var var =
72 Param_Test::Var_Array_dup (forany.in ());
73 any <<= Param_Test::Var_Array_forany (var.inout ());
75 if (!(any >>= forany))
77 ACE_DEBUG ((LM_DEBUG,
78 "Failure for Param_Test::Var_Array[2]\n"));
83 CORBA::Object_var obj =
84 orb->string_to_object ("corbaloc:iiop:localhost:1234/Foo/Bar");
86 Param_Test_var param_test =
87 TAO::Narrow_Utils<Param_Test>::unchecked_narrow (obj.in ());
88 TAO_Stub *stub = param_test->_stubobj ();
89 stub->type_id = CORBA::string_dup ("IDL:Param_Test:1.0");
91 any <<= param_test.in ();
93 Param_Test_ptr o;
95 if (!(any >>= o))
97 ACE_DEBUG ((LM_DEBUG,
98 "Cannot extract Param_Test (oh the horror)\n"));
100 CORBA::Boolean equiv =
101 param_test->_is_equivalent (o);
103 if (!equiv)
105 ACE_DEBUG ((LM_DEBUG,
106 "Mismatched Param_Test extraction\n"));
109 CORBA::Object_var other;
111 if (!(any >>= CORBA::Any::to_object (other.inout ())))
113 ACE_DEBUG ((LM_DEBUG,
114 "Cannot extract Param_Test as Object\n"));
119 CORBA::Short i = 123;
120 any <<= i;
122 CORBA::Short o;
124 if (!(any >>= o)
125 || i != o)
127 ACE_DEBUG ((LM_DEBUG,
128 "Failure for CORBA::Short (%d,%d)\n",
129 i, o));
134 CORBA::Long i = 123;
135 any <<= i;
137 CORBA::Long o;
139 if (!(any >>= o)
140 || i != o)
142 ACE_DEBUG ((LM_DEBUG,
143 "Failure for CORBA::Long (%d,%d)\n",
144 i, o));
149 CORBA::ULongLong i = 123;
150 any <<= i;
152 CORBA::ULongLong o;
154 if (!(any >>= o)
155 || i != o)
157 ACE_DEBUG ((LM_DEBUG,
158 "Failure for CORBA::ULongLong (%Q,%Q)\n",
159 i, o));
164 CORBA::Double i = 123;
165 any <<= i;
167 CORBA::Double o;
169 if (!(any >>= o) || !ACE::is_equal (i, o))
171 ACE_DEBUG ((LM_DEBUG,
172 "Failure for CORBA::Double (%f,%f)\n",
173 i, o));
178 CORBA::Any any;
179 CORBA::Any *i = 0;
180 ACE_NEW_RETURN (i,
181 CORBA::Any,
182 -1);
183 *i <<= CORBA::Short (123);
184 any <<= *i;
186 const CORBA::Any *o;
187 CORBA::Short oo;
189 if (!(any >>= o)
190 || !(*o >>= oo)
191 || 123 != oo)
193 ACE_DEBUG ((LM_DEBUG,
194 "Failure for CORBA::Any "
195 "(copying insertion, %d)\n",
196 oo));
199 any <<= i;
201 if (!(any >>= o)
202 || !(*o >>= oo)
203 || 123 != oo)
205 ACE_DEBUG ((LM_DEBUG,
206 "Failure for CORBA::Any "
207 "(non-copying insertion, %d)\n",
208 oo));
213 const char i[] = "123";
214 any <<= i;
216 const char *o;
218 if (!(any >>= o)
219 || ACE_OS::strcmp (i, o) != 0)
221 ACE_DEBUG ((LM_DEBUG,
222 "Failure for char* (%C,%C)\n",
224 o));
229 CORBA::Any any;
230 Param_Test::Fixed_Struct *i = 0;
231 ACE_NEW_RETURN (i,
232 Param_Test::Fixed_Struct,
233 -1);
234 i->l = -7;
235 i->c = 'c';
236 i->s = 5;
237 i->o = 255;
238 i->f = 2.3f;
239 i->b = 0;
240 i->d = 3.1416;
242 any <<= *i;
243 const Param_Test::Fixed_Struct *o = 0;
245 if (!(any >>= o)
246 || o->l != i->l
247 || o->c != i->c
248 || o->s != i->s
249 || o->o != i->o
250 || !ACE::is_equal (o->f, i->f)
251 || o->b != i->b
252 || !ACE::is_equal (o->d, i->d))
254 ACE_DEBUG ((LM_DEBUG,
255 "Failure for Fixed_Struct "
256 "(copying insertion)\n"));
259 any <<= i;
261 if (!(any >>= o)
262 || o->l != i->l
263 || o->c != i->c
264 || o->s != i->s
265 || o->o != i->o
266 || !ACE::is_equal (o->f, i->f)
267 || o->b != i->b
268 || !ACE::is_equal (o->d, i->d))
270 ACE_DEBUG ((LM_DEBUG,
271 "Failure for Fixed_Struct "
272 "(non-copying insertion)\n"));
277 CORBA::ULong len = 3;
278 CORBA::Any any;
279 CORBA::LongSeq *i = 0;
280 ACE_NEW_RETURN (i,
281 CORBA::LongSeq (len),
282 -1);
283 i->length (len);
285 for (CORBA::ULong k = 0; k < len; ++k)
287 (*i)[k] = k;
290 any <<= *i;
291 const CORBA::LongSeq *o = 0;
293 if (!(any >>= o)
294 || (*i)[0] != (*o)[0]
295 || (*i)[1] != (*o)[1]
296 || (*i)[2] != (*o)[2])
298 ACE_DEBUG ((LM_DEBUG,
299 "Failure for Long_Seq "
300 "(copying insertion)\n"));
303 any <<= i;
305 if (!(any >>= o)
306 || (*i)[0] != (*o)[0]
307 || (*i)[1] != (*o)[1]
308 || (*i)[2] != (*o)[2])
310 ACE_DEBUG ((LM_DEBUG,
311 "Failure for Long_Seq "
312 "(non-copying insertion)\n"));
317 catch (const CORBA::Exception& ex)
319 ex._tao_print_exception ("IDL Types");
320 return 1;
323 return 0;