Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Param_Test / driver.cpp
blobc1271859d7fe392cf51e8dff24951e55e3240067
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 ()
56 Driver::~Driver ()
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());
104 catch (const CORBA::Exception& ex)
106 ex._tao_print_exception (exception_string);
107 return -1;
110 return 0;
114 Driver::run ()
116 // serves as a factory of Param_Client objects. It is also responsible to
117 // start the test
119 Options *opt = OPTIONS::instance (); // get the options object
120 int retstatus = -1;
122 switch (opt->test_type ())
124 case Options::TEST_SHORT:
126 Param_Test_Client<Test_Short> *client = new
127 Param_Test_Client<Test_Short> (this->orb_.in (),
128 this->objref_.in(),
129 new Test_Short);
130 if (opt->invoke_type () == Options::SII)
131 retstatus = client->run_sii_test ();
132 else
133 retstatus = client->run_dii_test ();
134 delete client;
136 break;
137 case Options::TEST_ULONGLONG:
139 Param_Test_Client<Test_ULongLong> *client = new
140 Param_Test_Client<Test_ULongLong> (this->orb_.in (),
141 this->objref_.in(),
142 new Test_ULongLong);
143 if (opt->invoke_type () == Options::SII)
144 retstatus = client->run_sii_test ();
145 else
146 retstatus = client->run_dii_test ();
147 delete client;
149 break;
150 case Options::TEST_UB_STRING:
152 Param_Test_Client<Test_Unbounded_String> *client = new
153 Param_Test_Client<Test_Unbounded_String> (this->orb_.in (),
154 this->objref_.in(),
155 new Test_Unbounded_String);
156 if (opt->invoke_type () == Options::SII)
157 retstatus = client->run_sii_test ();
158 else
159 retstatus = client->run_dii_test ();
160 delete client;
162 break;
163 case Options::TEST_BD_STRING:
165 Param_Test_Client<Test_Bounded_String> *client = new
166 Param_Test_Client<Test_Bounded_String> (this->orb_.in (),
167 this->objref_.in(),
168 new Test_Bounded_String);
169 if (opt->invoke_type () == Options::SII)
170 retstatus = client->run_sii_test ();
171 else
172 retstatus = client->run_dii_test ();
173 delete client;
175 break;
176 case Options::TEST_UB_WSTRING:
178 Param_Test_Client<Test_Unbounded_WString> *client = new
179 Param_Test_Client<Test_Unbounded_WString> (this->orb_.in (),
180 this->objref_.in(),
181 new Test_Unbounded_WString);
182 if (opt->invoke_type () == Options::SII)
183 retstatus = client->run_sii_test ();
184 else
185 retstatus = client->run_dii_test ();
186 delete client;
188 break;
189 case Options::TEST_BD_WSTRING:
191 Param_Test_Client<Test_Bounded_WString> *client = new
192 Param_Test_Client<Test_Bounded_WString> (this->orb_.in (),
193 this->objref_.in(),
194 new Test_Bounded_WString);
195 if (opt->invoke_type () == Options::SII)
196 retstatus = client->run_sii_test ();
197 else
198 retstatus = client->run_dii_test ();
199 delete client;
201 break;
202 case Options::TEST_FIXED_STRUCT:
204 Param_Test_Client<Test_Fixed_Struct> *client = new
205 Param_Test_Client<Test_Fixed_Struct> (this->orb_.in (),
206 this->objref_.in(),
207 new Test_Fixed_Struct);
208 if (opt->invoke_type () == Options::SII)
209 retstatus = client->run_sii_test ();
210 else
211 retstatus = client->run_dii_test ();
212 delete client;
214 break;
215 case Options::TEST_UB_STRING_SEQUENCE:
217 Param_Test_Client<Test_String_Sequence> *client = new
218 Param_Test_Client<Test_String_Sequence> (this->orb_.in (),
219 this->objref_.in(),
220 new Test_String_Sequence);
221 if (opt->invoke_type () == Options::SII)
222 retstatus = client->run_sii_test ();
223 else
224 retstatus = client->run_dii_test ();
225 delete client;
227 break;
228 case Options::TEST_BD_STRING_SEQUENCE:
230 Param_Test_Client<Test_Bounded_String_Sequence> *client = new
231 Param_Test_Client<Test_Bounded_String_Sequence> (this->orb_.in (),
232 this->objref_.in(),
233 new Test_Bounded_String_Sequence);
234 if (opt->invoke_type () == Options::SII)
235 retstatus = client->run_sii_test ();
236 else
237 retstatus = client->run_dii_test ();
238 delete client;
240 break;
241 case Options::TEST_UB_WSTRING_SEQUENCE:
243 Param_Test_Client<Test_WString_Sequence> *client = new
244 Param_Test_Client<Test_WString_Sequence> (this->orb_.in (),
245 this->objref_.in(),
246 new Test_WString_Sequence);
247 if (opt->invoke_type () == Options::SII)
248 retstatus = client->run_sii_test ();
249 else
250 retstatus = client->run_dii_test ();
251 delete client;
253 break;
254 case Options::TEST_BD_WSTRING_SEQUENCE:
256 Param_Test_Client<Test_Bounded_WString_Sequence> *client = new
257 Param_Test_Client<Test_Bounded_WString_Sequence> (this->orb_.in (),
258 this->objref_.in(),
259 new Test_Bounded_WString_Sequence);
260 if (opt->invoke_type () == Options::SII)
261 retstatus = client->run_sii_test ();
262 else
263 retstatus = client->run_dii_test ();
264 delete client;
266 break;
267 case Options::TEST_VAR_STRUCT:
269 Param_Test_Client<Test_Var_Struct> *client = new
270 Param_Test_Client<Test_Var_Struct> (this->orb_.in (),
271 this->objref_.in(),
272 new Test_Var_Struct);
273 if (opt->invoke_type () == Options::SII)
274 retstatus = client->run_sii_test ();
275 else
276 retstatus = client->run_dii_test ();
277 delete client;
279 break;
280 case Options::TEST_NESTED_STRUCT:
282 Param_Test_Client<Test_Nested_Struct> *client = new
283 Param_Test_Client<Test_Nested_Struct> (this->orb_.in (),
284 this->objref_.in(),
285 new Test_Nested_Struct);
286 if (opt->invoke_type () == Options::SII)
287 retstatus = client->run_sii_test ();
288 else
289 retstatus = client->run_dii_test ();
290 delete client;
292 break;
293 case Options::TEST_RECURSIVE_STRUCT:
295 Param_Test_Client<Test_Recursive_Struct> *client = new
296 Param_Test_Client<Test_Recursive_Struct> (this->orb_.in (),
297 this->objref_.in(),
298 new Test_Recursive_Struct);
299 if (opt->invoke_type () == Options::SII)
300 retstatus = client->run_sii_test ();
301 else
302 retstatus = client->run_dii_test ();
303 delete client;
305 break;
306 case Options::TEST_OBJREF_STRUCT:
308 Param_Test_Client<Test_Objref_Struct> *client = new
309 Param_Test_Client<Test_Objref_Struct> (this->orb_.in (),
310 this->objref_.in(),
311 new Test_Objref_Struct);
312 if (opt->invoke_type () == Options::SII)
313 retstatus = client->run_sii_test ();
314 else
315 retstatus = client->run_dii_test ();
316 delete client;
318 break;
319 case Options::TEST_UB_STRUCT_SEQUENCE:
321 Param_Test_Client<Test_Struct_Sequence> *client = new
322 Param_Test_Client<Test_Struct_Sequence> (this->orb_.in (),
323 this->objref_.in(),
324 new Test_Struct_Sequence);
325 if (opt->invoke_type () == Options::SII)
326 retstatus = client->run_sii_test ();
327 else
328 retstatus = client->run_dii_test ();
329 delete client;
331 Param_Test_Client<Test_Unbounded_Struct_Sequence> *client2 = new
332 Param_Test_Client<Test_Unbounded_Struct_Sequence>
333 (this->orb_.in (),
334 this->objref_.in(),
335 new Test_Unbounded_Struct_Sequence);
337 if (opt->invoke_type () == Options::SII)
338 retstatus = client2->run_sii_test ();
339 else
340 retstatus = client2->run_dii_test ();
341 delete client2;
343 break;
344 case Options::TEST_BD_STRUCT_SEQUENCE:
346 Param_Test_Client<Test_Bounded_Struct_Sequence> *client = new
347 Param_Test_Client<Test_Bounded_Struct_Sequence> (this->orb_.in (),
348 this->objref_.in (),
349 new Test_Bounded_Struct_Sequence);
350 if (opt->invoke_type () == Options::SII)
351 retstatus = client->run_sii_test ();
352 else
353 retstatus = client->run_dii_test ();
354 delete client;
356 break;
357 case Options::TEST_UB_ARRAY_SEQUENCE:
359 Param_Test_Client<Test_Array_Sequence> *client = new
360 Param_Test_Client<Test_Array_Sequence> (this->orb_.in (),
361 this->objref_.in (),
362 new Test_Array_Sequence);
363 if (opt->invoke_type () == Options::SII)
364 retstatus = client->run_sii_test ();
365 else
366 retstatus = client->run_dii_test ();
367 delete client;
369 break;
370 case Options::TEST_BD_ARRAY_SEQUENCE:
372 Param_Test_Client<Test_Bounded_Array_Sequence> *client = new
373 Param_Test_Client<Test_Bounded_Array_Sequence> (this->orb_.in (),
374 this->objref_.in (),
375 new Test_Bounded_Array_Sequence);
376 if (opt->invoke_type () == Options::SII)
377 retstatus = client->run_sii_test ();
378 else
379 retstatus = client->run_dii_test ();
380 delete client;
382 break;
383 case Options::TEST_OBJREF:
385 Param_Test_Client<Test_ObjRef> *client = new
386 Param_Test_Client<Test_ObjRef> (this->orb_.in (),
387 this->objref_.in (),
388 new Test_ObjRef);
389 if (opt->invoke_type () == Options::SII)
390 retstatus = client->run_sii_test ();
391 else
392 retstatus = client->run_dii_test ();
393 delete client;
395 break;
396 case Options::TEST_TYPECODE:
398 Param_Test_Client<Test_TypeCode> *client = new
399 Param_Test_Client<Test_TypeCode> (this->orb_.in (),
400 this->objref_.in(),
401 new Test_TypeCode);
402 if (opt->invoke_type () == Options::SII)
403 retstatus = client->run_sii_test ();
404 else
405 retstatus = client->run_dii_test ();
406 delete client;
408 break;
409 case Options::TEST_ANY:
411 Param_Test_Client<Test_Any> *client = new
412 Param_Test_Client<Test_Any> (this->orb_.in (),
413 this->objref_.in(),
414 new Test_Any);
415 if (opt->invoke_type () == Options::SII)
416 retstatus = client->run_sii_test ();
417 else
418 retstatus = client->run_dii_test ();
419 delete client;
421 break;
422 case Options::TEST_OBJREF_SEQUENCE:
424 Param_Test_Client<Test_ObjRef_Sequence> *client = new
425 Param_Test_Client<Test_ObjRef_Sequence> (this->orb_.in (),
426 this->objref_.in(),
427 new Test_ObjRef_Sequence);
428 if (opt->invoke_type () == Options::SII)
429 retstatus = client->run_sii_test ();
430 else
431 retstatus = client->run_dii_test ();
432 delete client;
434 break;
435 case Options::TEST_ANYSEQ:
437 Param_Test_Client<Test_AnySeq> *client = new
438 Param_Test_Client<Test_AnySeq> (this->orb_.in (),
439 this->objref_.in(),
440 new Test_AnySeq);
441 if (opt->invoke_type () == Options::SII)
442 retstatus = client->run_sii_test ();
443 else
444 retstatus = client->run_dii_test ();
445 delete client;
447 break;
448 case Options::TEST_UB_SHORTSEQ:
450 Param_Test_Client<Test_Short_Sequence> *client = new
451 Param_Test_Client<Test_Short_Sequence> (this->orb_.in (),
452 this->objref_.in(),
453 new Test_Short_Sequence);
454 if (opt->invoke_type () == Options::SII)
455 retstatus = client->run_sii_test ();
456 else
457 retstatus = client->run_dii_test ();
458 delete client;
460 break;
461 case Options::TEST_BD_SHORTSEQ:
463 Param_Test_Client<Test_Bounded_Short_Sequence> *client = new
464 Param_Test_Client<Test_Bounded_Short_Sequence> (this->orb_.in (),
465 this->objref_.in(),
466 new Test_Bounded_Short_Sequence);
467 if (opt->invoke_type () == Options::SII)
468 retstatus = client->run_sii_test ();
469 else
470 retstatus = client->run_dii_test ();
471 delete client;
473 break;
474 case Options::TEST_UB_LONGSEQ:
476 Param_Test_Client<Test_Long_Sequence> *client = new
477 Param_Test_Client<Test_Long_Sequence> (this->orb_.in (),
478 this->objref_.in(),
479 new Test_Long_Sequence);
480 if (opt->invoke_type () == Options::SII)
481 retstatus = client->run_sii_test ();
482 else
483 retstatus = client->run_dii_test ();
484 delete client;
486 break;
487 case Options::TEST_BD_LONGSEQ:
489 Param_Test_Client<Test_Bounded_Long_Sequence> *client = new
490 Param_Test_Client<Test_Bounded_Long_Sequence> (this->orb_.in (),
491 this->objref_.in(),
492 new Test_Bounded_Long_Sequence);
493 if (opt->invoke_type () == Options::SII)
494 retstatus = client->run_sii_test ();
495 else
496 retstatus = client->run_dii_test ();
497 delete client;
499 break;
500 case Options::TEST_FIXED_ARRAY:
502 Param_Test_Client<Test_Fixed_Array> *client = new
503 Param_Test_Client<Test_Fixed_Array> (this->orb_.in (),
504 this->objref_.in(),
505 new Test_Fixed_Array);
506 if (opt->invoke_type () == Options::SII)
507 retstatus = client->run_sii_test ();
508 else
509 retstatus = client->run_dii_test ();
510 delete client;
512 break;
513 case Options::TEST_VAR_ARRAY:
515 Param_Test_Client<Test_Var_Array> *client = new
516 Param_Test_Client<Test_Var_Array> (this->orb_.in (),
517 this->objref_.in(),
518 new Test_Var_Array);
519 if (opt->invoke_type () == Options::SII)
520 retstatus = client->run_sii_test ();
521 else
522 retstatus = client->run_dii_test ();
523 delete client;
525 break;
526 case Options::TEST_EXCEPTION:
528 Param_Test_Client<Test_Exception> *client = new
529 Param_Test_Client<Test_Exception> (this->orb_.in (),
530 this->objref_.in(),
531 new Test_Exception);
532 if (opt->invoke_type () == Options::SII)
533 retstatus = client->run_sii_test ();
534 else
535 retstatus = client->run_dii_test ();
536 delete client;
538 break;
539 case Options::TEST_BIG_UNION:
541 Param_Test_Client<Test_Big_Union> *client = new
542 Param_Test_Client<Test_Big_Union> (this->orb_.in (),
543 this->objref_.in(),
544 new Test_Big_Union);
545 if (opt->invoke_type () == Options::SII)
546 retstatus = client->run_sii_test ();
547 else
548 retstatus = client->run_dii_test ();
549 delete client;
551 break;
552 case Options::TEST_SMALL_UNION:
554 Param_Test_Client<Test_Small_Union> *client = new
555 Param_Test_Client<Test_Small_Union> (this->orb_.in (),
556 this->objref_.in(),
557 new Test_Small_Union);
558 if (opt->invoke_type () == Options::SII)
559 retstatus = client->run_sii_test ();
560 else
561 retstatus = client->run_dii_test ();
562 delete client;
564 break;
565 case Options::TEST_RECURSIVE_UNION:
567 Param_Test_Client<Test_Recursive_Union> *client = new
568 Param_Test_Client<Test_Recursive_Union> (this->orb_.in (),
569 this->objref_.in(),
570 new Test_Recursive_Union);
571 if (opt->invoke_type () == Options::SII)
572 retstatus = client->run_sii_test ();
573 else
574 retstatus = client->run_dii_test ();
575 delete client;
577 break;
578 case Options::TEST_COMPLEX_ANY:
580 Param_Test_Client<Test_Complex_Any> *client = new
581 Param_Test_Client<Test_Complex_Any> (this->orb_.in (),
582 this->objref_.in(),
583 new Test_Complex_Any);
584 if (opt->invoke_type () == Options::SII)
585 retstatus = client->run_sii_test ();
586 else
587 retstatus = client->run_dii_test ();
588 delete client;
590 break;
591 case Options::TEST_MULTDIM_ARRAY:
593 Param_Test_Client<Test_Multdim_Array> *client = new
594 Param_Test_Client<Test_Multdim_Array> (this->orb_.in (),
595 this->objref_.in(),
596 new Test_Multdim_Array);
597 if (opt->invoke_type () == Options::SII)
598 retstatus = client->run_sii_test ();
599 else
600 retstatus = client->run_dii_test ();
601 delete client;
603 break;
604 default:
605 break;
608 // Get in a new environment variable
611 if (opt->shutdown ())
613 this->objref_->shutdown ();
616 this->objref_ = Param_Test::_nil ();
617 this->orb_->destroy ();
619 catch (const CORBA::Exception& ex)
621 ex._tao_print_exception ("during shutdown");
624 return retstatus;