More tests update
[ACE_TAO.git] / TAO / tests / DynAny_Test / driver.cpp
blob22f195a796196d77d8b414bcebcb47430483655f
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 (void)
61 : test_type_ (NO_TEST),
62 debug_ (0)
66 // destructor
67 Driver::~Driver (void)
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);
94 catch (const CORBA::Exception& ex)
96 ex._tao_print_exception ("Driver::init");
97 return -1;
100 return 0;
104 Driver::parse_args (int argc, ACE_TCHAR *argv[])
106 if (argc == 1)
107 ACE_ERROR_RETURN ((LM_ERROR,
108 "usage: %s\n"
109 " -t [dynany|dynarray|dynenum|dynsequence|dynstruct|dynunion]\n"
110 " -d\n",
111 argv [0]),
112 -1);
114 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:d"));
115 int c;
116 const ACE_TCHAR *test_str = 0;
118 while ((c = get_opts ()) != -1)
119 switch (c)
121 case 't':
122 test_str = get_opts.opt_arg ();
124 if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynany")))
125 this->test_type_ = TEST_DYNANY;
126 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynarray")))
127 this->test_type_ = TEST_DYNARRAY;
128 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynenum")))
129 this->test_type_ = TEST_DYNENUM;
130 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynsequence")))
131 this->test_type_ = TEST_DYNSEQUENCE;
132 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynstruct")))
133 this->test_type_ = TEST_DYNSTRUCT;
134 else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynunion")))
135 this->test_type_ = TEST_DYNUNION;
136 else
137 ACE_DEBUG ((LM_DEBUG,
138 "I don't recognize test type %s\n",
139 test_str));
140 break;
142 case 'd':
143 this->debug_ = 1;
144 break;
146 case '?':
147 default:
148 ACE_ERROR_RETURN ((LM_ERROR,
149 "usage: %s"
150 " -t [dynany|dynarray|dynenum|dynsequence|dynstruct|dynunion]"
151 " -d for debug"
152 "\n",
153 argv [0]),
154 -1);
157 // Indicates successful parsing of command line.
158 return 0;
162 Driver::run (void)
164 int error_count = 0;
166 switch (this->test_type_)
168 case TEST_DYNANY:
170 Test_Wrapper<Test_DynAny>* wrapper =
171 new Test_Wrapper<Test_DynAny> (new Test_DynAny (this->orb_, debug_));
172 error_count = wrapper->run_test ();
173 delete wrapper;
175 break;
176 case TEST_DYNARRAY:
178 Test_Wrapper<Test_DynArray>* wrapper =
179 new Test_Wrapper<Test_DynArray> (new Test_DynArray (this->orb_, debug_));
180 error_count = wrapper->run_test ();
181 delete wrapper;
183 break;
184 case TEST_DYNENUM:
186 Test_Wrapper<Test_DynEnum>* wrapper =
187 new Test_Wrapper<Test_DynEnum> (new Test_DynEnum (this->orb_, debug_));
188 error_count = wrapper->run_test ();
189 delete wrapper;
191 break;
192 case TEST_DYNSEQUENCE:
194 Test_Wrapper<Test_DynSequence>* wrapper =
195 new Test_Wrapper<Test_DynSequence> (new Test_DynSequence (this->orb_, debug_));
196 error_count = wrapper->run_test ();
197 delete wrapper;
199 break;
200 case TEST_DYNSTRUCT:
202 Test_Wrapper<Test_DynStruct>* wrapper =
203 new Test_Wrapper<Test_DynStruct> (new Test_DynStruct (this->orb_, debug_));
204 error_count = wrapper->run_test ();
205 delete wrapper;
207 break;
208 case TEST_DYNUNION:
210 Test_Wrapper<Test_DynUnion>* wrapper =
211 new Test_Wrapper<Test_DynUnion> (new Test_DynUnion (this->orb_, debug_));
212 error_count = wrapper->run_test ();
213 delete wrapper;
215 break;
216 default:
217 break;
220 return error_count;