summaryrefslogtreecommitdiff
path: root/TAO/tests/OBV/Supports/client.cpp
blob: 076d397dfa49aa3b40978321d373c0e824c1d476 (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
// $Id$

#include "Supports_Test_impl.h"

const char * ior = "file://test.ior";
int num_trials = 1;
int id = 0;

int
parse_args (int argc, char *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "t:i:");
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 't':
        num_trials = atoi (get_opts.optarg);
        break;

      case 'i':
        id = atoi (get_opts.optarg);
        break;

      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s "
                           "-t <trials> "
                           "\n",
                           argv [0]),
                          -1);
      }
  // Indicates sucessful parsing of the command line
  return 0;
}

int
main (int argc, char *argv[])
{

  ACE_TRY_NEW_ENV
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

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

      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (CORBA::is_nil (root_poa.in ()))
        ACE_ERROR_RETURN ((LM_ERROR," (%P|%t) Nil RootPOA\n"), 1);

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      /* Create, register factories */

      Supports_Test::Node_init * node_factory = 0;
  
      ACE_NEW_RETURN (node_factory, node_init_impl, 1);

      CORBA::ValueFactory returned_factory =
        orb->register_value_factory (node_factory->tao_repository_id (),
                                     node_factory
                                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
	
      ACE_ASSERT (returned_factory == 0);

      node_factory->_remove_ref ();


      Supports_Test::vt_graph_init * vt_graph_factory = 0;

      ACE_NEW_RETURN (vt_graph_factory, vt_graph_init_impl, 1);

      returned_factory =
        orb->register_value_factory (vt_graph_factory->tao_repository_id (),
                                     vt_graph_factory
                                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
	
      ACE_ASSERT (returned_factory == 0);

      vt_graph_factory->_remove_ref ();


      /* Check return values for register_value_factory */

      Supports_Test::Node_init * node_factory2 = 0;
  
      ACE_NEW_RETURN (node_factory2, node_init_impl, 1);

      returned_factory =
        orb->register_value_factory (node_factory2->tao_repository_id (),
                                     node_factory2
                                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
	
      ACE_ASSERT (returned_factory == node_factory);

      node_factory2->_remove_ref ();

	
      /* Get test object reference */
	
      CORBA::Object_var tmp = orb->string_to_object (ior ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      Supports_Test::test_var my_test =
        Supports_Test::test::_narrow (tmp.in () ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (CORBA::is_nil (my_test.in ()))
        ACE_ERROR_RETURN ((LM_DEBUG, "Nil Supports_Test::test obj ref <%s>\n", ior), 1);

      my_test->start (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      /* Perform test */

      for (int i = 0; i < num_trials; i++)
        {

          // Create a vt_graph_impl instance and store the reference as a
          // vt_graph_var. Then register the instance with the POA to obtain an
          // object reference, stored as a graph_var. Increment the reference count
          // of the vt_graph_impl instance.
          vt_graph_impl * the_vt_graph = 0;
          ACE_NEW_RETURN (the_vt_graph, vt_graph_impl (3 ACE_ENV_ARG_PARAMETER), 1);
          Supports_Test::vt_graph_var test_vt_graph = the_vt_graph;

          Supports_Test::graph_var test_graph =
            the_vt_graph->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
          ACE_TRY_CHECK;
          if (CORBA::is_nil (test_graph.in ()))
            ACE_ERROR_RETURN ((LM_DEBUG, "Nil Supports_Test::graph obj ref\n"), 1);
          the_vt_graph->DefaultValueRefCountBase::_add_ref ();

          // At this point, test_vt_graph and test_graph refer to the same object.
          ACE_ASSERT (test_vt_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 3);
          ACE_TRY_CHECK;
          my_test->pass_vt_graph_in (test_vt_graph.in () ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
          ACE_ASSERT (test_vt_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 3);
          ACE_TRY_CHECK;

          ACE_ASSERT (test_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 3);
          ACE_TRY_CHECK;
          my_test->pass_obj_graph_in (test_graph.in () ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
          ACE_ASSERT (test_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 4);
          ACE_TRY_CHECK;

          test_vt_graph->add_node ("NEW2" ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          test_graph->add_node ("NEW3" ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          // After the 'pass_vt_graph_out' call returns, test_vt_graph will refer to
          // a new object.
          ACE_ASSERT (test_vt_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 6);
          ACE_TRY_CHECK;
          my_test->pass_vt_graph_out (test_vt_graph.out () ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
          ACE_ASSERT (test_vt_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 5);
          ACE_TRY_CHECK;

          // 'test_graph' still refers to the original object, but after the
          // 'pass_obj_graph_out' call returns, it will refer to a new object,
          // residing on the server.
          ACE_ASSERT (test_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 6);
          ACE_TRY_CHECK;
          my_test->pass_obj_graph_out (test_graph.out () ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
          ACE_ASSERT (test_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 5);
          ACE_TRY_CHECK;

          // test_vt_graph and test_graph now refer to different objects.
          test_vt_graph->add_node ("NEW2" ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          test_graph->add_node ("NEW2" ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_ASSERT (test_vt_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 6);
          ACE_TRY_CHECK;
          my_test->pass_vt_graph_inout (test_vt_graph.inout () ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
          ACE_ASSERT (test_vt_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 7);
          ACE_TRY_CHECK;

          ACE_ASSERT (test_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 6);
          ACE_TRY_CHECK;
          my_test->pass_obj_graph_inout (test_graph.inout () ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
          ACE_ASSERT (test_graph->size (ACE_ENV_SINGLE_ARG_PARAMETER) == 7);
          ACE_TRY_CHECK;

        }

      my_test->finish (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      /* Shut down */

      orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG, "Client (%P.%t) completed test successfully\n", id));

    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Exception caught:");
      return 1;
    }
  ACE_ENDTRY;

  return 0;
}