Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / DynAny_Test / driver.cpp
blobc08e10e82bb5fb3b49232a7de69aa9588d443551
2 //=============================================================================
3 /**
4 * @file driver.cpp
6 * Implementation file for the driver program.
8 * @author Jeff Parsons <parsons@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "driver.h"
14 #include "test_dynany.h"
15 #include "test_dynarray.h"
16 #include "test_dynenum.h"
17 #include "test_dynsequence.h"
18 #include "test_dynstruct.h"
19 #include "test_dynunion.h"
20 #include "test_wrapper.h"
21 #include "tao/PortableServer/PortableServer.h"
22 #include "ace/Get_Opt.h"
23 #include "ace/OS_NS_string.h"
25 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
27 int error_count = 0;
28 try
30 Driver driver;
32 // initialize the driver
33 if (driver.init (argc, argv) == -1)
34 ACE_ERROR_RETURN ((LM_ERROR,
35 "(%N:%l) driver.cpp - "
36 "Driver initialization failed\n"),
37 -1);
39 // run the tests
40 error_count = driver.run ();
41 if (error_count != 0)
43 ACE_ERROR ((LM_ERROR,
44 "(%N:%l) driver.cpp - "
45 "%d tests failed\n",
46 error_count));
49 catch (const CORBA::Exception& ex)
51 ex._tao_print_exception ("Caught unexpected CORBA exception:");
53 ++error_count;
56 return error_count;
59 // constructor
60 Driver::Driver ()
61 : test_type_ (NO_TEST),
62 debug_ (0)
66 // destructor
67 Driver::~Driver ()
69 if (this->orb_.in () != 0)
71 this->orb_->shutdown ();
72 this->orb_->destroy ();
76 // initialize the driver
77 int
78 Driver::init (int argc, ACE_TCHAR *argv[])
80 try
82 // Retrieve the underlying ORB
83 this->orb_ = CORBA::ORB_init (argc, argv, "local");
86 // Parse command line and verify parameters.
87 if (this->parse_args (argc, argv) == -1)
88 ACE_ERROR_RETURN ((LM_ERROR,
89 "(%N:%l) driver.cpp - "
90 "parse_args failed\n"),
91 -1);
93 catch (const CORBA::Exception& ex)
95 ex._tao_print_exception ("Driver::init");
96 return -1;
99 return 0;
103 Driver::parse_args (int argc, ACE_TCHAR *argv[])
105 if (argc == 1)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "usage: %s\n"
108 " -t [dynany|dynarray|dynenum|dynsequence|dynstruct|dynunion]\n"
109 " -d\n",
110 argv [0]),
111 -1);
113 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:d"));
114 int c;
115 const ACE_TCHAR *test_str = 0;
117 while ((c = get_opts ()) != -1)
118 switch (c)
120 case 't':
121 test_str = get_opts.opt_arg ();
123 if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynany")))
124 this->test_type_ = TEST_DYNANY;
125 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynarray")))
126 this->test_type_ = TEST_DYNARRAY;
127 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynenum")))
128 this->test_type_ = TEST_DYNENUM;
129 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynsequence")))
130 this->test_type_ = TEST_DYNSEQUENCE;
131 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynstruct")))
132 this->test_type_ = TEST_DYNSTRUCT;
133 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynunion")))
134 this->test_type_ = TEST_DYNUNION;
135 else
136 ACE_DEBUG ((LM_DEBUG,
137 "I don't recognize test type %s\n",
138 test_str));
139 break;
141 case 'd':
142 this->debug_ = 1;
143 break;
145 case '?':
146 default:
147 ACE_ERROR_RETURN ((LM_ERROR,
148 "usage: %s"
149 " -t [dynany|dynarray|dynenum|dynsequence|dynstruct|dynunion]"
150 " -d for debug"
151 "\n",
152 argv [0]),
153 -1);
156 // Indicates successful parsing of command line.
157 return 0;
161 Driver::run ()
163 int error_count = 0;
165 switch (this->test_type_)
167 case TEST_DYNANY:
169 Test_Wrapper<Test_DynAny>* wrapper =
170 new Test_Wrapper<Test_DynAny> (new Test_DynAny (this->orb_, debug_));
171 error_count = wrapper->run_test ();
172 delete wrapper;
174 break;
175 case TEST_DYNARRAY:
177 Test_Wrapper<Test_DynArray>* wrapper =
178 new Test_Wrapper<Test_DynArray> (new Test_DynArray (this->orb_, debug_));
179 error_count = wrapper->run_test ();
180 delete wrapper;
182 break;
183 case TEST_DYNENUM:
185 Test_Wrapper<Test_DynEnum>* wrapper =
186 new Test_Wrapper<Test_DynEnum> (new Test_DynEnum (this->orb_, debug_));
187 error_count = wrapper->run_test ();
188 delete wrapper;
190 break;
191 case TEST_DYNSEQUENCE:
193 Test_Wrapper<Test_DynSequence>* wrapper =
194 new Test_Wrapper<Test_DynSequence> (new Test_DynSequence (this->orb_, debug_));
195 error_count = wrapper->run_test ();
196 delete wrapper;
198 break;
199 case TEST_DYNSTRUCT:
201 Test_Wrapper<Test_DynStruct>* wrapper =
202 new Test_Wrapper<Test_DynStruct> (new Test_DynStruct (this->orb_, debug_));
203 error_count = wrapper->run_test ();
204 delete wrapper;
206 break;
207 case TEST_DYNUNION:
209 Test_Wrapper<Test_DynUnion>* wrapper =
210 new Test_Wrapper<Test_DynUnion> (new Test_DynUnion (this->orb_, debug_));
211 error_count = wrapper->run_test ();
212 delete wrapper;
214 break;
215 default:
216 break;
219 return error_count;