summaryrefslogtreecommitdiff
path: root/tests/DynAny_Test/driver.cpp
blob: e143ff00d6b73a35401d59430dd1152d1ffee347 (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

//=============================================================================
/**
 *  @file    driver.cpp
 *
 *  $Id$
 *
 *  Implementation file for the driver program.
 *
 *
 *  @author Jeff Parsons <parsons@cs.wustl.edu>
 */
//=============================================================================


#include "driver.h"
#include "test_dynany.h"
#include "test_dynarray.h"
#include "test_dynenum.h"
#include "test_dynsequence.h"
#include "test_dynstruct.h"
#include "test_dynunion.h"
#include "test_wrapper.h"
#include "tao/PortableServer/PortableServer.h"
#include "ace/Get_Opt.h"
#include "ace/OS_NS_string.h"

int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int error_count = 0;
  try
    {
      Driver driver;

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

      // run the tests
      error_count = driver.run ();
      if (error_count != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "(%N:%l) driver.cpp - "
                      "%d tests failed\n",
                      error_count));
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught unexpected CORBA exception:");

      ++error_count;
    }

  return error_count;
}

// constructor
Driver::Driver (void)
  : test_type_ (NO_TEST),
    debug_ (0)
{
}

// destructor
Driver::~Driver (void)
{
  if (this->orb_.in () != 0)
    {
      this->orb_->shutdown ();
      this->orb_->destroy ();
    }
}

// initialize the driver
int
Driver::init (int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Retrieve the underlying ORB
      this->orb_ = CORBA::ORB_init (argc, argv, "local");


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

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Driver::init");
      return -1;
    }

  return 0;
}

int
Driver::parse_args (int argc, ACE_TCHAR *argv[])
{
  if (argc == 1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "usage:  %s\n"
                       " -t [dynany|dynarray|dynenum|dynsequence|dynstruct|dynunion]\n"
                       " -d\n",
                       argv [0]),
                      -1);

  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:d"));
  int c;
  const ACE_TCHAR *test_str = 0;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 't':
        test_str = get_opts.opt_arg ();

        if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynany")))
          this->test_type_ = TEST_DYNANY;
        else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynarray")))
          this->test_type_ = TEST_DYNARRAY;
        else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynenum")))
          this->test_type_ = TEST_DYNENUM;
        else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynsequence")))
          this->test_type_ = TEST_DYNSEQUENCE;
        else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynstruct")))
          this->test_type_ = TEST_DYNSTRUCT;
        else if (!ACE_OS::strcmp (test_str, ACE_TEXT ("dynunion")))
          this->test_type_ = TEST_DYNUNION;
        else
          ACE_DEBUG ((LM_DEBUG,
                      "I don't recognize test type %s\n",
                      test_str));
        break;

      case 'd':
        this->debug_ = 1;
        break;

      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s"
                           " -t [dynany|dynarray|dynenum|dynsequence|dynstruct|dynunion]"
                           " -d for debug"
                           "\n",
                           argv [0]),
                          -1);
      }

  // Indicates successful parsing of command line.
  return 0;
}

int
Driver::run (void)
{
  int error_count = 0;

  switch (this->test_type_)
    {
      case TEST_DYNANY:
        {
          Test_Wrapper<Test_DynAny>* wrapper =
            new Test_Wrapper<Test_DynAny> (new Test_DynAny (this->orb_, debug_));
          error_count = wrapper->run_test ();
          delete wrapper;
        }
        break;
      case TEST_DYNARRAY:
        {
          Test_Wrapper<Test_DynArray>* wrapper =
            new Test_Wrapper<Test_DynArray> (new Test_DynArray (this->orb_, debug_));
          error_count = wrapper->run_test ();
          delete wrapper;
        }
        break;
      case TEST_DYNENUM:
        {
          Test_Wrapper<Test_DynEnum>* wrapper =
            new Test_Wrapper<Test_DynEnum> (new Test_DynEnum (this->orb_, debug_));
          error_count = wrapper->run_test ();
          delete wrapper;
        }
        break;
      case TEST_DYNSEQUENCE:
        {
          Test_Wrapper<Test_DynSequence>* wrapper =
            new Test_Wrapper<Test_DynSequence> (new Test_DynSequence (this->orb_, debug_));
          error_count = wrapper->run_test ();
          delete wrapper;
        }
        break;
      case TEST_DYNSTRUCT:
        {
          Test_Wrapper<Test_DynStruct>* wrapper =
            new Test_Wrapper<Test_DynStruct> (new Test_DynStruct (this->orb_, debug_));
          error_count = wrapper->run_test ();
          delete wrapper;
        }
        break;
      case TEST_DYNUNION:
        {
          Test_Wrapper<Test_DynUnion>* wrapper =
            new Test_Wrapper<Test_DynUnion> (new Test_DynUnion (this->orb_, debug_));
          error_count = wrapper->run_test ();
          delete wrapper;
        }
        break;
      default:
        break;
    }

  return error_count;
}