Continued changes from peer review
[ACE_TAO.git] / TAO / tests / Param_Test / driver.cpp
blob4679ef3e155757ace63cc1a07fd020f44faa7bee
2 //=============================================================================
3 /**
4 * @file driver.cpp
6 * Driver program
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "client.h"
14 #include "driver.h"
15 #include "results.h"
16 #include "tests.h"
17 #include "ace/Get_Opt.h"
19 // This function runs the test (main program)
20 int
21 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
23 // get an instance of the driver object
24 try
26 Driver drv;
28 // initialize the driver
29 if (drv.init (argc, argv) == -1)
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "(%N:%l) driver.cpp - "
32 "Driver initialization failed\n"),
33 -1);
35 // run various tests
36 if (drv.run () == -1)
37 ACE_ERROR_RETURN ((LM_ERROR,
38 "(%N:%l) driver.cpp - "
39 "tests failed\n"),
40 -1);
42 catch (const CORBA::Exception& ex)
44 ex._tao_print_exception ("Caught unexpected CORBA exception:");
46 return 1;
48 return 0;
51 // constructor
52 Driver::Driver (void)
56 Driver::~Driver (void)
60 // initialize the driver
61 int
62 Driver::init (int argc, ACE_TCHAR **argv)
64 // environment to track exceptions
66 // retrieve the instance of Options
67 Options *opt = OPTIONS::instance ();
69 char exception_string[256];
71 try
73 ACE_OS::strcpy (exception_string, "ORB Initialization");
75 // Retrieve the underlying ORB
76 this->orb_ = CORBA::ORB_init (argc,
77 argv,
78 "internet");
80 // Parse command line and verify parameters.
81 if (opt->parse_args (argc, argv) == -1)
82 ACE_ERROR_RETURN ((LM_ERROR,
83 "(%N:%l) driver.cpp - "
84 "parse_args failed\n"),
85 -1);
86 // Retrieve a Param_Test object reference
87 ACE_OS::strcpy (exception_string,"ORB::string_to_object() failed.");
89 CORBA::Object_var temp =
90 this->orb_->string_to_object (opt->param_test_ior ());
93 if (CORBA::is_nil (temp.in()))
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "ORB::string_to_object() returned null object for IOR <%s>\n",
96 opt->param_test_ior ()),
97 -1);
99 // Get the object reference
100 ACE_OS::strcpy (exception_string,"Param_Test::_narrow () failed.");
102 this->objref_ = Param_Test::_narrow (temp.in());
105 catch (const CORBA::Exception& ex)
107 ex._tao_print_exception (exception_string);
108 return -1;
111 return 0;
115 Driver::run (void)
117 // serves as a factory of Param_Client objects. It is also responsible to
118 // start the test
120 Options *opt = OPTIONS::instance (); // get the options object
121 int retstatus = -1;
123 switch (opt->test_type ())
125 case Options::TEST_SHORT:
127 Param_Test_Client<Test_Short> *client = new
128 Param_Test_Client<Test_Short> (this->orb_.in (),
129 this->objref_.in(),
130 new Test_Short);
131 if (opt->invoke_type () == Options::SII)
132 retstatus = client->run_sii_test ();
133 else
134 retstatus = client->run_dii_test ();
135 delete client;
137 break;
138 case Options::TEST_ULONGLONG:
140 Param_Test_Client<Test_ULongLong> *client = new
141 Param_Test_Client<Test_ULongLong> (this->orb_.in (),
142 this->objref_.in(),
143 new Test_ULongLong);
144 if (opt->invoke_type () == Options::SII)
145 retstatus = client->run_sii_test ();
146 else
147 retstatus = client->run_dii_test ();
148 delete client;
150 break;
151 case Options::TEST_UB_STRING:
153 Param_Test_Client<Test_Unbounded_String> *client = new
154 Param_Test_Client<Test_Unbounded_String> (this->orb_.in (),
155 this->objref_.in(),
156 new Test_Unbounded_String);
157 if (opt->invoke_type () == Options::SII)
158 retstatus = client->run_sii_test ();
159 else
160 retstatus = client->run_dii_test ();
161 delete client;
163 break;
164 case Options::TEST_BD_STRING:
166 Param_Test_Client<Test_Bounded_String> *client = new
167 Param_Test_Client<Test_Bounded_String> (this->orb_.in (),
168 this->objref_.in(),
169 new Test_Bounded_String);
170 if (opt->invoke_type () == Options::SII)
171 retstatus = client->run_sii_test ();
172 else
173 retstatus = client->run_dii_test ();
174 delete client;
176 break;
177 case Options::TEST_UB_WSTRING:
179 Param_Test_Client<Test_Unbounded_WString> *client = new
180 Param_Test_Client<Test_Unbounded_WString> (this->orb_.in (),
181 this->objref_.in(),
182 new Test_Unbounded_WString);
183 if (opt->invoke_type () == Options::SII)
184 retstatus = client->run_sii_test ();
185 else
186 retstatus = client->run_dii_test ();
187 delete client;
189 break;
190 case Options::TEST_BD_WSTRING:
192 Param_Test_Client<Test_Bounded_WString> *client = new
193 Param_Test_Client<Test_Bounded_WString> (this->orb_.in (),
194 this->objref_.in(),
195 new Test_Bounded_WString);
196 if (opt->invoke_type () == Options::SII)
197 retstatus = client->run_sii_test ();
198 else
199 retstatus = client->run_dii_test ();
200 delete client;
202 break;
203 case Options::TEST_FIXED_STRUCT:
205 Param_Test_Client<Test_Fixed_Struct> *client = new
206 Param_Test_Client<Test_Fixed_Struct> (this->orb_.in (),
207 this->objref_.in(),
208 new Test_Fixed_Struct);
209 if (opt->invoke_type () == Options::SII)
210 retstatus = client->run_sii_test ();
211 else
212 retstatus = client->run_dii_test ();
213 delete client;
215 break;
216 case Options::TEST_UB_STRING_SEQUENCE:
218 Param_Test_Client<Test_String_Sequence> *client = new
219 Param_Test_Client<Test_String_Sequence> (this->orb_.in (),
220 this->objref_.in(),
221 new Test_String_Sequence);
222 if (opt->invoke_type () == Options::SII)
223 retstatus = client->run_sii_test ();
224 else
225 retstatus = client->run_dii_test ();
226 delete client;
228 break;
229 case Options::TEST_BD_STRING_SEQUENCE:
231 Param_Test_Client<Test_Bounded_String_Sequence> *client = new
232 Param_Test_Client<Test_Bounded_String_Sequence> (this->orb_.in (),
233 this->objref_.in(),
234 new Test_Bounded_String_Sequence);
235 if (opt->invoke_type () == Options::SII)
236 retstatus = client->run_sii_test ();
237 else
238 retstatus = client->run_dii_test ();
239 delete client;
241 break;
242 case Options::TEST_UB_WSTRING_SEQUENCE:
244 Param_Test_Client<Test_WString_Sequence> *client = new
245 Param_Test_Client<Test_WString_Sequence> (this->orb_.in (),
246 this->objref_.in(),
247 new Test_WString_Sequence);
248 if (opt->invoke_type () == Options::SII)
249 retstatus = client->run_sii_test ();
250 else
251 retstatus = client->run_dii_test ();
252 delete client;
254 break;
255 case Options::TEST_BD_WSTRING_SEQUENCE:
257 Param_Test_Client<Test_Bounded_WString_Sequence> *client = new
258 Param_Test_Client<Test_Bounded_WString_Sequence> (this->orb_.in (),
259 this->objref_.in(),
260 new Test_Bounded_WString_Sequence);
261 if (opt->invoke_type () == Options::SII)
262 retstatus = client->run_sii_test ();
263 else
264 retstatus = client->run_dii_test ();
265 delete client;
267 break;
268 case Options::TEST_VAR_STRUCT:
270 Param_Test_Client<Test_Var_Struct> *client = new
271 Param_Test_Client<Test_Var_Struct> (this->orb_.in (),
272 this->objref_.in(),
273 new Test_Var_Struct);
274 if (opt->invoke_type () == Options::SII)
275 retstatus = client->run_sii_test ();
276 else
277 retstatus = client->run_dii_test ();
278 delete client;
280 break;
281 case Options::TEST_NESTED_STRUCT:
283 Param_Test_Client<Test_Nested_Struct> *client = new
284 Param_Test_Client<Test_Nested_Struct> (this->orb_.in (),
285 this->objref_.in(),
286 new Test_Nested_Struct);
287 if (opt->invoke_type () == Options::SII)
288 retstatus = client->run_sii_test ();
289 else
290 retstatus = client->run_dii_test ();
291 delete client;
293 break;
294 case Options::TEST_RECURSIVE_STRUCT:
296 Param_Test_Client<Test_Recursive_Struct> *client = new
297 Param_Test_Client<Test_Recursive_Struct> (this->orb_.in (),
298 this->objref_.in(),
299 new Test_Recursive_Struct);
300 if (opt->invoke_type () == Options::SII)
301 retstatus = client->run_sii_test ();
302 else
303 retstatus = client->run_dii_test ();
304 delete client;
306 break;
307 case Options::TEST_OBJREF_STRUCT:
309 Param_Test_Client<Test_Objref_Struct> *client = new
310 Param_Test_Client<Test_Objref_Struct> (this->orb_.in (),
311 this->objref_.in(),
312 new Test_Objref_Struct);
313 if (opt->invoke_type () == Options::SII)
314 retstatus = client->run_sii_test ();
315 else
316 retstatus = client->run_dii_test ();
317 delete client;
319 break;
320 case Options::TEST_UB_STRUCT_SEQUENCE:
322 Param_Test_Client<Test_Struct_Sequence> *client = new
323 Param_Test_Client<Test_Struct_Sequence> (this->orb_.in (),
324 this->objref_.in(),
325 new Test_Struct_Sequence);
326 if (opt->invoke_type () == Options::SII)
327 retstatus = client->run_sii_test ();
328 else
329 retstatus = client->run_dii_test ();
330 delete client;
332 Param_Test_Client<Test_Unbounded_Struct_Sequence> *client2 = new
333 Param_Test_Client<Test_Unbounded_Struct_Sequence>
334 (this->orb_.in (),
335 this->objref_.in(),
336 new Test_Unbounded_Struct_Sequence);
338 if (opt->invoke_type () == Options::SII)
339 retstatus = client2->run_sii_test ();
340 else
341 retstatus = client2->run_dii_test ();
342 delete client2;
344 break;
345 case Options::TEST_BD_STRUCT_SEQUENCE:
347 Param_Test_Client<Test_Bounded_Struct_Sequence> *client = new
348 Param_Test_Client<Test_Bounded_Struct_Sequence> (this->orb_.in (),
349 this->objref_.in (),
350 new Test_Bounded_Struct_Sequence);
351 if (opt->invoke_type () == Options::SII)
352 retstatus = client->run_sii_test ();
353 else
354 retstatus = client->run_dii_test ();
355 delete client;
357 break;
358 case Options::TEST_UB_ARRAY_SEQUENCE:
360 Param_Test_Client<Test_Array_Sequence> *client = new
361 Param_Test_Client<Test_Array_Sequence> (this->orb_.in (),
362 this->objref_.in (),
363 new Test_Array_Sequence);
364 if (opt->invoke_type () == Options::SII)
365 retstatus = client->run_sii_test ();
366 else
367 retstatus = client->run_dii_test ();
368 delete client;
370 break;
371 case Options::TEST_BD_ARRAY_SEQUENCE:
373 Param_Test_Client<Test_Bounded_Array_Sequence> *client = new
374 Param_Test_Client<Test_Bounded_Array_Sequence> (this->orb_.in (),
375 this->objref_.in (),
376 new Test_Bounded_Array_Sequence);
377 if (opt->invoke_type () == Options::SII)
378 retstatus = client->run_sii_test ();
379 else
380 retstatus = client->run_dii_test ();
381 delete client;
383 break;
384 case Options::TEST_OBJREF:
386 Param_Test_Client<Test_ObjRef> *client = new
387 Param_Test_Client<Test_ObjRef> (this->orb_.in (),
388 this->objref_.in (),
389 new Test_ObjRef);
390 if (opt->invoke_type () == Options::SII)
391 retstatus = client->run_sii_test ();
392 else
393 retstatus = client->run_dii_test ();
394 delete client;
396 break;
397 case Options::TEST_TYPECODE:
399 Param_Test_Client<Test_TypeCode> *client = new
400 Param_Test_Client<Test_TypeCode> (this->orb_.in (),
401 this->objref_.in(),
402 new Test_TypeCode);
403 if (opt->invoke_type () == Options::SII)
404 retstatus = client->run_sii_test ();
405 else
406 retstatus = client->run_dii_test ();
407 delete client;
409 break;
410 case Options::TEST_ANY:
412 Param_Test_Client<Test_Any> *client = new
413 Param_Test_Client<Test_Any> (this->orb_.in (),
414 this->objref_.in(),
415 new Test_Any);
416 if (opt->invoke_type () == Options::SII)
417 retstatus = client->run_sii_test ();
418 else
419 retstatus = client->run_dii_test ();
420 delete client;
422 break;
423 case Options::TEST_OBJREF_SEQUENCE:
425 Param_Test_Client<Test_ObjRef_Sequence> *client = new
426 Param_Test_Client<Test_ObjRef_Sequence> (this->orb_.in (),
427 this->objref_.in(),
428 new Test_ObjRef_Sequence);
429 if (opt->invoke_type () == Options::SII)
430 retstatus = client->run_sii_test ();
431 else
432 retstatus = client->run_dii_test ();
433 delete client;
435 break;
436 case Options::TEST_ANYSEQ:
438 Param_Test_Client<Test_AnySeq> *client = new
439 Param_Test_Client<Test_AnySeq> (this->orb_.in (),
440 this->objref_.in(),
441 new Test_AnySeq);
442 if (opt->invoke_type () == Options::SII)
443 retstatus = client->run_sii_test ();
444 else
445 retstatus = client->run_dii_test ();
446 delete client;
448 break;
449 case Options::TEST_UB_SHORTSEQ:
451 Param_Test_Client<Test_Short_Sequence> *client = new
452 Param_Test_Client<Test_Short_Sequence> (this->orb_.in (),
453 this->objref_.in(),
454 new Test_Short_Sequence);
455 if (opt->invoke_type () == Options::SII)
456 retstatus = client->run_sii_test ();
457 else
458 retstatus = client->run_dii_test ();
459 delete client;
461 break;
462 case Options::TEST_BD_SHORTSEQ:
464 Param_Test_Client<Test_Bounded_Short_Sequence> *client = new
465 Param_Test_Client<Test_Bounded_Short_Sequence> (this->orb_.in (),
466 this->objref_.in(),
467 new Test_Bounded_Short_Sequence);
468 if (opt->invoke_type () == Options::SII)
469 retstatus = client->run_sii_test ();
470 else
471 retstatus = client->run_dii_test ();
472 delete client;
474 break;
475 case Options::TEST_UB_LONGSEQ:
477 Param_Test_Client<Test_Long_Sequence> *client = new
478 Param_Test_Client<Test_Long_Sequence> (this->orb_.in (),
479 this->objref_.in(),
480 new Test_Long_Sequence);
481 if (opt->invoke_type () == Options::SII)
482 retstatus = client->run_sii_test ();
483 else
484 retstatus = client->run_dii_test ();
485 delete client;
487 break;
488 case Options::TEST_BD_LONGSEQ:
490 Param_Test_Client<Test_Bounded_Long_Sequence> *client = new
491 Param_Test_Client<Test_Bounded_Long_Sequence> (this->orb_.in (),
492 this->objref_.in(),
493 new Test_Bounded_Long_Sequence);
494 if (opt->invoke_type () == Options::SII)
495 retstatus = client->run_sii_test ();
496 else
497 retstatus = client->run_dii_test ();
498 delete client;
500 break;
501 case Options::TEST_FIXED_ARRAY:
503 Param_Test_Client<Test_Fixed_Array> *client = new
504 Param_Test_Client<Test_Fixed_Array> (this->orb_.in (),
505 this->objref_.in(),
506 new Test_Fixed_Array);
507 if (opt->invoke_type () == Options::SII)
508 retstatus = client->run_sii_test ();
509 else
510 retstatus = client->run_dii_test ();
511 delete client;
513 break;
514 case Options::TEST_VAR_ARRAY:
516 Param_Test_Client<Test_Var_Array> *client = new
517 Param_Test_Client<Test_Var_Array> (this->orb_.in (),
518 this->objref_.in(),
519 new Test_Var_Array);
520 if (opt->invoke_type () == Options::SII)
521 retstatus = client->run_sii_test ();
522 else
523 retstatus = client->run_dii_test ();
524 delete client;
526 break;
527 case Options::TEST_EXCEPTION:
529 Param_Test_Client<Test_Exception> *client = new
530 Param_Test_Client<Test_Exception> (this->orb_.in (),
531 this->objref_.in(),
532 new Test_Exception);
533 if (opt->invoke_type () == Options::SII)
534 retstatus = client->run_sii_test ();
535 else
536 retstatus = client->run_dii_test ();
537 delete client;
539 break;
540 case Options::TEST_BIG_UNION:
542 Param_Test_Client<Test_Big_Union> *client = new
543 Param_Test_Client<Test_Big_Union> (this->orb_.in (),
544 this->objref_.in(),
545 new Test_Big_Union);
546 if (opt->invoke_type () == Options::SII)
547 retstatus = client->run_sii_test ();
548 else
549 retstatus = client->run_dii_test ();
550 delete client;
552 break;
553 case Options::TEST_SMALL_UNION:
555 Param_Test_Client<Test_Small_Union> *client = new
556 Param_Test_Client<Test_Small_Union> (this->orb_.in (),
557 this->objref_.in(),
558 new Test_Small_Union);
559 if (opt->invoke_type () == Options::SII)
560 retstatus = client->run_sii_test ();
561 else
562 retstatus = client->run_dii_test ();
563 delete client;
565 break;
566 case Options::TEST_RECURSIVE_UNION:
568 Param_Test_Client<Test_Recursive_Union> *client = new
569 Param_Test_Client<Test_Recursive_Union> (this->orb_.in (),
570 this->objref_.in(),
571 new Test_Recursive_Union);
572 if (opt->invoke_type () == Options::SII)
573 retstatus = client->run_sii_test ();
574 else
575 retstatus = client->run_dii_test ();
576 delete client;
578 break;
579 case Options::TEST_COMPLEX_ANY:
581 Param_Test_Client<Test_Complex_Any> *client = new
582 Param_Test_Client<Test_Complex_Any> (this->orb_.in (),
583 this->objref_.in(),
584 new Test_Complex_Any);
585 if (opt->invoke_type () == Options::SII)
586 retstatus = client->run_sii_test ();
587 else
588 retstatus = client->run_dii_test ();
589 delete client;
591 break;
592 case Options::TEST_MULTDIM_ARRAY:
594 Param_Test_Client<Test_Multdim_Array> *client = new
595 Param_Test_Client<Test_Multdim_Array> (this->orb_.in (),
596 this->objref_.in(),
597 new Test_Multdim_Array);
598 if (opt->invoke_type () == Options::SII)
599 retstatus = client->run_sii_test ();
600 else
601 retstatus = client->run_dii_test ();
602 delete client;
604 break;
605 default:
606 break;
609 // Get in a new environment variable
612 if (opt->shutdown ())
614 this->objref_->shutdown ();
617 this->objref_ = Param_Test::_nil ();
618 this->orb_->destroy ();
621 catch (const CORBA::Exception& ex)
623 ex._tao_print_exception ("during shutdown");
626 return retstatus;