Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / OBV / Truncatable / client.cpp
blob38e1eba22c5dc751f9a3d6a0bb83f63df9b390a7
1 #include "TruncatableC.h"
2 #include "ExtraC.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
7 int fail = 0;
8 int pretest = 0;
9 int verbose = 0;
11 #if defined (VERIFY)
12 #undef VERIFY
13 #endif /* VERIFY */
15 #define VERIFY(Condition) \
16 { \
17 if ((Condition)==0) \
18 { \
19 fail++; \
20 if (!verbose) \
21 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) client - Failure at line %l\n"))); \
22 } \
25 int
26 parse_args (int argc, ACE_TCHAR *argv[])
28 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("k:v"));
29 int c;
31 while ((c = get_opts ()) != -1)
32 switch (c)
34 case 'k':
35 ior = get_opts.optarg;
36 break;
37 case 'v':
38 verbose = 1;
39 break;
40 case '?':
41 default:
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "usage: %s "
44 "-k <ior> "
45 "\n",
46 argv [0]),
47 -1);
49 // Indicates successful parsing of the command line
50 return 0;
53 int
54 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
56 try
58 CORBA::ORB_var orb =
59 CORBA::ORB_init (argc, argv);
61 if (parse_args (argc, argv) != 0)
62 return 1;
64 // Create factories.
66 OBV_TruncatableTest::BaseValue_init *base_factory = 0;
67 ACE_NEW_RETURN (base_factory,
68 OBV_TruncatableTest::BaseValue_init,
69 1);
71 orb->register_value_factory (base_factory->tao_repository_id (),
72 base_factory);
73 base_factory->_remove_ref (); // release ownership
75 OBV_TruncatableTest::TValue1_init *value1_factory = 0;
76 ACE_NEW_RETURN (value1_factory,
77 OBV_TruncatableTest::TValue1_init,
78 1);
80 orb->register_value_factory (value1_factory->tao_repository_id (),
81 value1_factory);
82 value1_factory->_remove_ref ();
84 OBV_TruncatableTest::TValue2_init *value2_factory = 0;
85 ACE_NEW_RETURN (value2_factory,
86 OBV_TruncatableTest::TValue2_init,
87 1);
89 orb->register_value_factory (value2_factory->tao_repository_id (),
90 value2_factory);
91 value2_factory->_remove_ref ();
93 OBV_TruncatableTest::TValue3_init *value3_factory = 0;
94 ACE_NEW_RETURN (value3_factory,
95 OBV_TruncatableTest::TValue3_init,
96 1);
98 orb->register_value_factory (value3_factory->tao_repository_id (),
99 value3_factory);
100 value3_factory->_remove_ref ();
102 OBV_TruncatableTest::TValue4_init *value4_factory = 0;
103 ACE_NEW_RETURN (value4_factory,
104 OBV_TruncatableTest::TValue4_init,
107 orb->register_value_factory (value4_factory->tao_repository_id (),
108 value4_factory);
109 value4_factory->_remove_ref ();
111 OBV_TruncatableTest::TValue5_init *value5_factory = 0;
112 ACE_NEW_RETURN (value5_factory,
113 OBV_TruncatableTest::TValue5_init,
116 orb->register_value_factory (value5_factory->tao_repository_id (),
117 value5_factory);
118 value5_factory->_remove_ref ();
120 OBV_TruncatableTest::NestedValue_init *nested_value_factory = 0;
121 ACE_NEW_RETURN (nested_value_factory,
122 OBV_TruncatableTest::NestedValue_init,
125 orb->register_value_factory (nested_value_factory->tao_repository_id (),
126 nested_value_factory);
127 nested_value_factory->_remove_ref ();
129 // Obtain reference to the object
130 CORBA::Object_var tmp =
131 orb->string_to_object(ior);
133 OBV_TruncatableTest::Test_var test =
134 OBV_TruncatableTest::Test::_narrow (tmp.in ());
136 if (CORBA::is_nil (test.in ()))
138 ACE_ERROR_RETURN ((LM_DEBUG,
139 "Nil OBV_TruncatableTest::Test reference <%s>\n",
140 ior),
144 CORBA::String_var desc;
145 { //isolate the scope of objects to avoid using wrong values
146 OBV_TruncatableTest::TValue1_var v1 (new OBV_OBV_TruncatableTest::TValue1);
147 v1->basic_data (9);
148 v1->data1 (99);
150 OBV_TruncatableTest::BaseValue_var ov1;
152 desc = CORBA::string_dup ("A<-tB, truncate B to A");
153 if (verbose)
154 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 1: %C: "),
155 desc.in ()));
156 pretest = fail;
158 test->op1 ("case1", v1.in (), ov1.out (), desc.inout ());
161 VERIFY (! ACE_OS::strcmp (desc.in (),
162 "case1: A<-tB, truncate B to A"));
163 VERIFY (v1->basic_data () == ov1->basic_data ());
164 if (verbose)
165 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"),
166 (pretest == fail) ?
167 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
170 { //isolate the scope of objects to avoid using wrong values
171 OBV_TruncatableTest::TValue2_var v2 (new OBV_OBV_TruncatableTest::TValue2);
173 v2->basic_data (9);
174 v2->data1 (99);
175 v2->data2 (99 * 2);
177 OBV_TruncatableTest::BaseValue_var ov2;
178 desc = CORBA::string_dup ("A<-tB<-tC, truncate C to A");
179 if (verbose)
180 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 2: %C: "),
181 desc.in ()));
182 pretest = fail;
184 test->op1 ("case2", v2.in (), ov2.out (), desc.inout ());
186 VERIFY (! ACE_OS::strcmp (desc.in (),
187 "case2: A<-tB<-tC, truncate C to A"));
188 VERIFY (v2->basic_data () == ov2->basic_data ());
189 if (verbose)
190 ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
191 (pretest == fail) ?
192 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
194 OBV_TruncatableTest::TValue1_var otv1;
195 desc = CORBA::string_dup ("A<-tB<-tC, truncate C to B");
196 if (verbose)
197 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Case 3: %C: "),
198 desc.in ()));
199 pretest = fail;
201 test->op2 (v2.in (), "case3", otv1.out (), desc.inout ());
203 VERIFY (! ACE_OS::strcmp (desc.in (),
204 "case3: A<-tB<-tC, truncate C to B"));
205 VERIFY (v2->basic_data () == otv1->basic_data ());
206 VERIFY (v2->data1 () == otv1->data1 ());
207 if (verbose)
208 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"),
209 (pretest == fail) ?
210 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
213 { //isolate the scope of objects to avoid using wrong values
214 OBV_TruncatableTest::TValue1_var itv1b (new OBV_OBV_TruncatableTest::TValue1);
216 itv1b->basic_data(7);
217 itv1b->data1(8);
218 OBV_TruncatableTest::TValue1_var otv1b;
219 desc = CORBA::string_dup ("A<-tB, truncatable but no truncation");
220 if (verbose)
221 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 3b: %C: "),
222 desc.in ()));
223 pretest = fail;
225 test->op2 (itv1b.in (), "case3b", otv1b.out (), desc.inout ());
227 VERIFY (! ACE_OS::strcmp (desc.in (),
228 "case3b: A<-tB, truncatable but no truncation"));
229 VERIFY (itv1b->basic_data () == otv1b->basic_data ());
230 VERIFY (itv1b->data1 () == otv1b->data1 ());
231 if (verbose)
232 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"),
233 (pretest == fail) ?
234 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
237 { //isolate the scope of objects to avoid using wrong values
238 OBV_TruncatableTest::TValue3_var v3 (new OBV_OBV_TruncatableTest::TValue3);
239 v3->basic_data (9);
240 v3->data1 (99);
241 v3->data3 (99 * 3);
243 bool caught_expected_exception = false;
246 OBV_TruncatableTest::BaseValue_var ov3;
247 desc = CORBA::string_dup
248 ("A<-tB<-C, try truncate C to A, MARSHAL exception");
249 if (verbose)
250 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 4: %C: "),
251 desc.in ()));
252 test->op1 ("case4", v3.in (), ov3.out (), desc.inout ());
254 catch (const CORBA::MARSHAL&)
256 if (verbose)
257 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("passed\n")));
258 caught_expected_exception = true;
261 if (!caught_expected_exception)
263 fail++;
264 if (verbose)
265 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("faileded\n")));
267 } //end marshaling exception test.
269 { //isolate the scope of objects to avoid using wrong values
270 OBV_TruncatableTest::NestedValue_var nv (new OBV_OBV_TruncatableTest::NestedValue);
271 nv->data (2);
273 OBV_TruncatableTest::TValue5_var v5 (new OBV_OBV_TruncatableTest::TValue5);
275 v5->basic_data (9);
276 v5->nv4 (nv.in ());
277 v5->data4 (99 * 4);
278 v5->str1 (CORBA::string_dup ("str1"));
279 v5->data5 (99 * 5);
280 v5->nv5 (nv.in ());
281 v5->str2 (CORBA::string_dup ("str2"));
283 OBV_TruncatableTest::BaseValue_var ov5;
284 desc = CORBA::string_dup
285 ("A<-tB<-tC, B & C have nested value type, truncate C to A");
286 if (verbose)
287 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 5: %C: "),
288 desc.in ()));
289 pretest = fail;
290 test->op1 ("case5", v5.in (), ov5.out (), desc.inout ());
292 VERIFY (! ACE_OS::strcmp (desc.in (),
293 "case5: A<-tB<-tC, B & C have nested value type, truncate C to A"));
294 VERIFY (v5->basic_data () == ov5->basic_data ());
295 if (verbose)
296 ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
297 (pretest == fail) ?
298 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
300 OBV_TruncatableTest::TValue4_var otv4;
301 desc = CORBA::string_dup
302 ("A<-tB<-tC, B & C have nested value type, truncate C to B");
303 if (verbose)
304 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 6: %C: "),
305 desc.in ()));
306 pretest = fail;
307 test->op3 ("case6", v5.in (), otv4.out (), desc.inout ());
309 VERIFY (! ACE_OS::strcmp (desc.in (),
310 "case6: A<-tB<-tC, B & C have nested value type, truncate C to B"));
311 VERIFY (v5->basic_data () == otv4->basic_data ());
312 VERIFY (v5->nv4 ()->data () == otv4->nv4 ()->data ());
313 VERIFY (v5->data4 () == otv4->data4 ());
314 if (verbose)
315 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"),
316 (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
319 { //isolate the scope of objects to avoid using wrong values
320 OBV_TruncatableTest::TValue6_var iv (new OBV_OBV_TruncatableTest::TValue6);
321 iv->basic_data (9);
323 OBV_TruncatableTest::BaseValue_var ov;
325 desc = CORBA::string_dup ("A<-tB, B has no data, truncate B to A");
326 if (verbose)
327 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 7: %C: "),
328 desc.in ()));
329 pretest = fail;
330 test->op1 ("case7", iv.in (), ov.out (), desc.inout ());
332 VERIFY (! ACE_OS::strcmp (desc.in (),
333 "case7: A<-tB, B has no data, truncate B to A"));
334 VERIFY (iv->basic_data () == ov->basic_data ());
335 if (verbose)
336 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"),
337 (pretest == fail) ?
338 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
341 { //isolate the scope of objects to avoid using wrong values
342 OBV_TruncatableTest::TValue1_var v1 (new OBV_OBV_TruncatableTest::TValue1);
343 v1->basic_data (8);
344 v1->data1 (88);
346 OBV_TruncatableTest::TValue1_var v4 (new OBV_OBV_TruncatableTest::TValue1);
347 v4->basic_data (9);
348 v4->data1 (99);
350 OBV_TruncatableTest::NestedValue_var nv (new OBV_OBV_TruncatableTest::NestedValue);
351 nv->data (2);
353 OBV_TruncatableTest::TValue4_var v2 (new OBV_OBV_TruncatableTest::TValue4);
355 v2->basic_data (7);
356 v2->nv4 (nv.in ());
357 v2->data4 (77);
359 OBV_TruncatableTest::TValue4_var v3 (new OBV_OBV_TruncatableTest::TValue4);
360 v3->basic_data (6);
361 v3->nv4 (nv.in ());
362 v3->data4 (66);
364 desc = CORBA::string_dup
365 ("multiple IN truncatable valuetype parameters"
366 " and return truncatable valuetype");
367 if (verbose)
368 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 8: %C: "),
369 desc.in ()));
370 pretest = fail;
371 OBV_TruncatableTest::BaseValue_var ov
372 = test->op4 ("case8", v1.in (), 5, v2.in (), v3.in (), v4.in (), desc.inout ());
374 VERIFY (! ACE_OS::strcmp (desc.in (),
375 "case8: multiple IN truncatable valuetype parameters"
376 " and return truncatable valuetype"));
377 CORBA::ULong total = 5 * (v1->basic_data () + v2->basic_data () +
378 v3->basic_data () + v4->basic_data ());
379 VERIFY (ov->basic_data () == total);
380 if (verbose)
381 ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
382 (pretest == fail) ?
383 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
387 OBV_TruncatableTest::Extra1_var v1 (new OBV_OBV_TruncatableTest::Extra1);
388 v1->basic_data (9);
389 v1->data1 (99);
390 v1->edata1 (1234);
392 OBV_TruncatableTest::TValue1_var ov1;
394 desc = CORBA::string_dup ("A<-tB, truncate unknown B to A");
395 if (verbose)
396 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 9: %C: "),
397 desc.in ()));
398 pretest = fail;
400 test->op2 (v1.in (), "case9", ov1.out (), desc.inout ());
402 VERIFY (! ACE_OS::strcmp (desc.in (),
403 "case9: A<-tB, truncate unknown B to A"));
404 VERIFY (v1->basic_data () == ov1->basic_data ()
405 && v1->data1() == ov1->data1());
406 if (verbose)
407 ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
408 (pretest == fail) ?
409 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
413 OBV_TruncatableTest::TValue1_var v1 (new OBV_OBV_TruncatableTest::TValue1);
414 v1->basic_data (9);
415 v1->data1 (99);
417 OBV_TruncatableTest::TValue1_var ov1;
418 CORBA::Any a;
419 a <<= &v1.inout ();
420 desc = CORBA::string_dup ("A<-tB, known truncatable via Any");
421 if (verbose)
422 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 10: %C: "),
423 desc.in ()));
424 pretest = fail;
426 test->op5 (a, "case10", ov1.out (), desc.inout ());
428 VERIFY (! ACE_OS::strcmp (desc.in (),
429 "case10: A<-tB, known truncatable via Any"));
430 VERIFY (v1->basic_data () == ov1->basic_data ()
431 && v1->data1() == ov1->data1());
432 if (verbose)
433 ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
434 (pretest == fail) ?
435 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
439 OBV_TruncatableTest::Extra1_var v1 (new OBV_OBV_TruncatableTest::Extra1);
440 v1->basic_data (9);
441 v1->data1 (99);
442 v1->edata1 (1234);
444 OBV_TruncatableTest::TValue1_var ov1;
445 CORBA::Any a;
446 a <<= &v1.inout ();
447 desc = CORBA::string_dup ("A<-tB, unknown truncatable via Any");
448 if (verbose)
449 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Case 11: %C: "),
450 desc.in ()));
451 pretest = fail;
453 test->op5 (a, "case11", ov1.out (), desc.inout ());
456 VERIFY (! ACE_OS::strcmp (desc.in (),
457 "case11: A<-tB, unknown truncatable via Any"));
458 VERIFY (v1->basic_data () == ov1->basic_data ()
459 && v1->data1() == ov1->data1());
460 if (verbose)
461 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"),
462 (pretest == fail) ?
463 ACE_TEXT ("passed") : ACE_TEXT ("failed")));
466 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - shutdown orb\n"));
468 test->shutdown ();
470 orb->destroy ();
472 if (fail)
474 ACE_ERROR ((LM_ERROR, "(%P|%t) client: test failed\n"));
475 return 1;
477 else
478 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client: test passed\n"));
480 catch (const CORBA::Exception& ex)
482 ex._tao_print_exception ("Exception caught:");
483 return 1;
486 return 0;