summaryrefslogtreecommitdiff
path: root/trunk/TAO/tests/Portable_Interceptors/Request_Interceptor_Flow/client.cpp
blob: 035b3959bd2c4126f255676d7bb3cde36b9f09d1 (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
// -*- C++ -*-

#include "ace/Get_Opt.h"

#include "testC.h"
#include "Client_ORBInitializer.h"

#include "tao/ORBInitializer_Registry.h"

ACE_RCSID (Request_Interceptor_Flow,
           client,
           "$Id$")

const char *ior = 0;

int
parse_args (int argc, char *argv[])
{
  if (argc != 3)  // foo -k IOR
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Wrong number of arguments.\n"),
                      -1);

  ACE_Get_Opt get_opts (argc, argv, "k:");
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'k':
        if (ior == 0)
          ior = get_opts.opt_arg ();
        break;
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Usage:  %s "
                           "-k IOR\n",
                           argv[0]),
                          -1);
      }

  return 0;
}

void
client_test (Test_ptr server)
{
  // Currently, there are only four scenarios for the client side
  // tests.
  const Test::TestScenario MAX_CLIENT_SCENARIO = 4;

  for (Test::TestScenario i = 1; i <= MAX_CLIENT_SCENARIO; ++i)
    {
      ACE_DEBUG ((LM_INFO,
                  "\nCLIENT SCENARIO %d\n"
                  "------------------\n",
                  i));

      try
        {
          server->client_test (i);

          if (i == 1)
            {
              ACE_ERROR ((LM_ERROR,
              "\nERROR: No exception has been thrown from client_test() "
              "operation.\n"));
            }
        }
      catch (const Test::X&)
        {
          // Expected exception.  Ignore it.
        }
      catch (const CORBA::NO_PERMISSION&)
        {
          // Expected exception.  Ignore it.
        }
      catch (const Test::UnknownScenario& ex)
        {
          ACE_ERROR ((LM_ERROR,
                      "\nERROR: Unknown scenario <%d> condition "
                      "returned from client_test() "
                      "operation.\n",
                      ex.scenario));
          throw;
        }
      catch (const CORBA::Exception&)
        {
          ACE_ERROR ((LM_ERROR,
                      "\nERROR: Exception thrown from client_test() "
                      "operation.\n"));
          throw;
        }
    }
}

void
server_test (Test_ptr server)
{
  // Currently, there are only four scenarios for the server side
  // tests.
  const Test::TestScenario MAX_SERVER_SCENARIO = 4;

  for (Test::TestScenario i = 1; i <= MAX_SERVER_SCENARIO; ++i)
    {
      ACE_DEBUG ((LM_INFO,
                  "\nSERVER SCENARIO %d\n"
                  "------------------\n",
                  i));

      try
        {
          CORBA::ULongSeq_var ulongseq;
          server->server_test (i, ulongseq.out ());

          if (i == 1)
            {
              ACE_ERROR ((LM_ERROR,
                          "\nERROR: No exception has been thrown from server_test() "
                          "operation.\n"));
            }
        }
      catch (const Test::X&)
        {
          // Expected exception.  Ignore it.
        }
      catch (const CORBA::NO_PERMISSION&)
        {
          // Expected exception.  Ignore it.
        }
      catch (const Test::UnknownScenario& ex)
        {
          ACE_ERROR ((LM_ERROR,
                      "\nERROR: Unknown scenario <%d> condition "
                      "returned from server_test() "
                      "operation.\n",
                      ex.scenario));
          throw;
        }
      catch (const CORBA::Exception&)
        {
          ACE_ERROR ((LM_ERROR,
                      "\nERROR: Exception thrown from server_test() "
                      "operation.\n"));
          throw;
        }
    }
}

int
main (int argc, char *argv[])
{
  try
    {
      PortableInterceptor::ORBInitializer_ptr temp_initializer =
        PortableInterceptor::ORBInitializer::_nil ();

      ACE_NEW_RETURN (temp_initializer,
                      Client_ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());

      CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                            argv,
                                            "Client ORB");

      if (::parse_args (argc, argv) != 0)
        return -1;

      CORBA::Object_var object =
        orb->string_to_object (ior);

      Test_var server =
        Test::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil\n",
                             ior),
                            1);
        }

      ::client_test (server.in ());

      ::server_test (server.in ());

      server->shutdown ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return -1;
    }

  ACE_DEBUG ((LM_INFO,
              "Request interceptor flow test passed.\n"));

  return 0;
}