summaryrefslogtreecommitdiff
path: root/TAO/tests/Param_Test/driver.cpp
blob: f4ea0b14d75a52816f441054f8ad13359e9c6145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Param_Test
//
// = FILENAME
//    driver.cpp
//
// = DESCRIPTION
//    Driver program
//
// = AUTHORS
//      Aniruddha Gokhale
//
// ============================================================================

#include "options.h"
#include "results.h"
#include "client.h"
#include "tests.h"
#include "driver.h"

// This function runs the test (main program)
int
main (int argc, char **argv)
{
  // get an instance of the driver object
  Driver *drv = DRIVER::instance ();

  // initialize the driver
  if (drv->init (argc, argv) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%N:%l) driver.cpp - "
                       "Driver initialization failed\n"),
                      -1);

  // run various tests
  if (drv->run () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%N:%l) driver.cpp - "
                       "tests failed\n"),
                      -1);
  return 0;
}

// constructor
Driver::Driver (void)
  : orb_ptr_ (0)
{
}

Driver::~Driver (void)
{
}

// initialize the driver
int
Driver::init (int argc, char **argv)
{
  // environment to track exceptions
  CORBA::Environment env;

  // retrieve the instance of Options
  Options *opt = OPTIONS::instance ();

  // Retrieve the underlying ORB
  this->orb_ptr_ = CORBA::ORB_init (argc,
                                    argv,
                                    "internet",
                                    env);

  if (env.exception () != 0)
    {
      env.print_exception ("ORB initialization");
      return -1;
    }

  // Parse command line and verify parameters.
  if (opt->parse_args (argc, argv) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%N:%l) driver.cpp - "
                       "parse_args failed\n"),
                      -1);

  // Retrieve a Param_Test object reference
  CORBA::Object_var temp =
    this->orb_ptr_->string_to_object (opt->param_test_ior (), env);
  if (env.exception () != 0)
    {
      env.print_exception ("ORB::string_to_object() failed.");
      return -1;
    }

  if (CORBA::is_nil (temp.in()))
    ACE_ERROR_RETURN ((LM_ERROR,
                       "ORB::string_to_object() returned null object for IOR <%s>\n",
                       opt->param_test_ior ()),
                      -1);

  this->objref_ = Param_Test::_narrow (temp.in(), env);
  if (env.exception () != 0)
    {
      env.print_exception ("Param_Test::_narrow failed");
      return -1;
    }

  return 0;
}

int
Driver::run (void)
{
  // serves as a factory of Param_Client objects. It is also responsible to
  // start the test

  Options *opt = OPTIONS::instance ();  // get the options object
  int retstatus = -1;

  switch (opt->test_type ())
    {
    case Options::TEST_SHORT:
      {
        Param_Test_Client<Test_Short> *client = new
          Param_Test_Client<Test_Short> (this->orb_ptr_,
                                         this->objref_.in(),
                                         new Test_Short);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_UNBOUNDED_STRING:
      {
        Param_Test_Client<Test_Unbounded_String> *client = new
          Param_Test_Client<Test_Unbounded_String> (this->orb_ptr_,
                                                    this->objref_.in(),
                                                    new Test_Unbounded_String);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_FIXED_STRUCT:
      {
        Param_Test_Client<Test_Fixed_Struct> *client = new
          Param_Test_Client<Test_Fixed_Struct> (this->orb_ptr_,
                                                this->objref_.in(),
                                                new Test_Fixed_Struct);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_STRING_SEQUENCE:
      {
        Param_Test_Client<Test_String_Sequence> *client = new
          Param_Test_Client<Test_String_Sequence> (this->orb_ptr_,
                                                   this->objref_.in(),
                                                   new Test_String_Sequence);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_VAR_STRUCT:
      {
        Param_Test_Client<Test_Var_Struct> *client = new
          Param_Test_Client<Test_Var_Struct> (this->orb_ptr_,
                                              this->objref_.in(),
                                              new Test_Var_Struct);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_NESTED_STRUCT:
      {
        Param_Test_Client<Test_Nested_Struct> *client = new
          Param_Test_Client<Test_Nested_Struct> (this->orb_ptr_,
                                                 this->objref_.in(),
                                                 new Test_Nested_Struct);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_STRUCT_SEQUENCE:
      {
        Param_Test_Client<Test_Struct_Sequence> *client = new
          Param_Test_Client<Test_Struct_Sequence> (this->orb_ptr_,
                                                 this->objref_.in(),
                                                 new Test_Struct_Sequence);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_OBJREF:
      {
        Param_Test_Client<Test_ObjRef> *client = new
          Param_Test_Client<Test_ObjRef> (this->orb_ptr_,
                                          this->objref_.in(),
                                          new Test_ObjRef);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    case Options::TEST_ANY:
      {
        Param_Test_Client<Test_Any> *client = new
          Param_Test_Client<Test_Any> (this->orb_ptr_,
                                       this->objref_.in(),
                                       new Test_Any);
        if (opt->invoke_type () == Options::SII)
          retstatus = client->run_sii_test ();
        else
          retstatus = client->run_dii_test ();
        delete client;
      }
      break;
    default:
      break;
    }
  return retstatus;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Singleton<Driver, ACE_SYNCH_RECURSIVE_MUTEX>;
template class Param_Test_Client<Test_Short>;
template class Param_Test_Client<Test_Unbounded_String>;
template class Param_Test_Client<Test_Fixed_Struct>;
template class Param_Test_Client<Test_String_Sequence>;
template class Param_Test_Client<Test_Var_Struct>;
template class Param_Test_Client<Test_Nested_Struct>;
template class Param_Test_Client<Test_Struct_Sequence>;
template class Param_Test_Client<Test_ObjRef>;
template class Param_Test_Client<Test_Any>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Singleton<Driver, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate Param_Test_Client<Test_Short>
#pragma instantiate Param_Test_Client<Test_Unbounded_String>
#pragma instantiate Param_Test_Client<Test_Fixed_Struct>
#pragma instantiate Param_Test_Client<Test_String_Sequence>
#pragma instantiate Param_Test_Client<Test_Var_Struct>
#pragma instantiate Param_Test_Client<Test_Nested_Struct>
#pragma instantiate Param_Test_Client<Test_Struct_Sequence>
#pragma instantiate Param_Test_Client<Test_ObjRef>
#pragma instantiate Param_Test_Client<Test_Any>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */