Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Alt_Mapping / driver.cpp
blobfc5f22ee919e4c47833be44d38a0b8edcf82391b
2 //=============================================================================
3 /**
4 * @file driver.cpp
6 * Driver program
8 * @author Jeff Parsons
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 Driver drv;
26 // initialize the driver
27 if (drv.init (argc, argv) == -1)
28 ACE_ERROR_RETURN ((LM_ERROR,
29 "(%N:%l) driver.cpp - "
30 "Driver initialization failed\n"),
31 -1);
33 // run various tests
34 if (drv.run () == -1)
35 ACE_ERROR_RETURN ((LM_ERROR,
36 "(%N:%l) driver.cpp - "
37 "tests failed\n"),
38 -1);
39 return 0;
42 // constructor
43 Driver::Driver ()
47 Driver::~Driver ()
51 // initialize the driver
52 int
53 Driver::init (int argc, ACE_TCHAR **argv)
55 // environment to track exceptions
57 // retrieve the instance of Options
58 Options *opt = OPTIONS::instance ();
60 char exception_string[256];
62 try
64 ACE_OS::strcpy (exception_string, "ORB Initialization");
66 // Retrieve the underlying ORB
67 this->orb_ = CORBA::ORB_init (argc,
68 argv,
69 "internet");
71 // Parse command line and verify parameters.
72 if (opt->parse_args (argc, argv) == -1)
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "(%N:%l) driver.cpp - "
75 "parse_args failed\n"),
76 -1);
77 // Retrieve a Param_Test object reference
78 ACE_OS::strcpy (exception_string,"ORB::string_to_object() failed.");
80 CORBA::Object_var temp =
81 this->orb_->string_to_object (opt->param_test_ior ());
84 if (CORBA::is_nil (temp.in()))
85 ACE_ERROR_RETURN ((LM_ERROR,
86 "ORB::string_to_object() returned null object for IOR <%s>\n",
87 opt->param_test_ior ()),
88 -1);
90 // Get the object reference
91 ACE_OS::strcpy (exception_string,"Param_Test::_narrow () failed.");
93 this->objref_ = Alt_Mapping::_narrow (temp.in());
95 catch (const CORBA::Exception& ex)
97 ex._tao_print_exception (exception_string);
98 return -1;
101 return 0;
105 Driver::run ()
107 // serves as a factory of Param_Client objects. It is also responsible to
108 // start the test
110 Options *opt = OPTIONS::instance (); // get the options object
111 int retstatus = -1;
113 switch (opt->test_type ())
115 case Options::TEST_UB_STRING:
117 Alt_Mapping_Client<Test_Unbounded_String> *client = new
118 Alt_Mapping_Client<Test_Unbounded_String> (this->orb_.in (),
119 this->objref_.in(),
120 new Test_Unbounded_String);
121 retstatus = client->run_sii_test ();
123 delete client;
125 break;
126 case Options::TEST_UB_STRUCT_SEQUENCE:
128 Alt_Mapping_Client<Test_Unbounded_Struct_Sequence> *client = new
129 Alt_Mapping_Client<Test_Unbounded_Struct_Sequence> (
130 this->orb_.in (),
131 this->objref_.in(),
132 new Test_Unbounded_Struct_Sequence);
134 retstatus = client->run_sii_test ();
136 delete client;
138 Alt_Mapping_Client<Test_Unbounded_Struct_Sequence> *client2 = new
139 Alt_Mapping_Client<Test_Unbounded_Struct_Sequence>
140 (this->orb_.in (),
141 this->objref_.in(),
142 new Test_Unbounded_Struct_Sequence);
144 retstatus = client2->run_sii_test ();
146 delete client2;
148 break;
149 default:
150 break;
153 // Get in a new environment variable
156 if (opt->shutdown ())
158 this->objref_->shutdown ();
161 catch (const CORBA::Exception& ex)
163 ex._tao_print_exception ("during shutdown");
166 return retstatus;