Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / OBV / Supports / client.cpp
blobbce89aa4c2b32047037a6d20e3258cadb421b9c0
1 #include "Supports_Test_impl.h"
3 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
4 int num_trials = 1;
5 int id = 0;
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:i:k:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 't':
17 num_trials = ACE_OS::atoi (get_opts.opt_arg ());
18 break;
20 case 'i':
21 id = ACE_OS::atoi (get_opts.opt_arg ());
22 break;
24 case 'k':
25 ior = get_opts.opt_arg ();
26 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-t <trials> "
33 "-k <ior> "
34 "-i <id> "
35 "\n",
36 argv [0]),
37 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 int
44 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
46 try
48 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
50 if (parse_args (argc, argv) != 0)
51 return 1;
53 CORBA::Object_var poa_object =
54 orb->resolve_initial_references ("RootPOA");
56 PortableServer::POA_var root_poa =
57 PortableServer::POA::_narrow (poa_object.in ());
59 if (CORBA::is_nil (root_poa.in ()))
60 ACE_ERROR_RETURN ((LM_ERROR," (%P|%t) Nil RootPOA\n"), 1);
62 PortableServer::POAManager_var poa_manager =
63 root_poa->the_POAManager ();
65 poa_manager->activate ();
67 /* Create, register factories */
69 Supports_Test::Node_init * node_factory = 0;
71 ACE_NEW_RETURN (node_factory, node_init_impl, 1);
73 CORBA::ValueFactory returned_factory =
74 orb->register_value_factory (node_factory->tao_repository_id (),
75 node_factory);
77 ACE_ASSERT (returned_factory == 0);
79 node_factory->_remove_ref ();
82 Supports_Test::vt_graph_init * vt_graph_factory = 0;
84 ACE_NEW_RETURN (vt_graph_factory, vt_graph_init_impl, 1);
86 returned_factory =
87 orb->register_value_factory (vt_graph_factory->tao_repository_id (),
88 vt_graph_factory);
90 ACE_ASSERT (returned_factory == 0);
92 vt_graph_factory->_remove_ref ();
95 /* Check return values for register_value_factory */
97 Supports_Test::Node_init * node_factory2 = 0;
99 ACE_NEW_RETURN (node_factory2, node_init_impl, 1);
101 returned_factory =
102 orb->register_value_factory (node_factory2->tao_repository_id (),
103 node_factory2);
105 ACE_ASSERT (returned_factory == node_factory);
107 node_factory2->_remove_ref ();
110 /* Get test object reference */
112 CORBA::Object_var tmp = orb->string_to_object (ior);
114 Supports_Test::test_var my_test =
115 Supports_Test::test::_narrow (tmp.in ());
117 if (CORBA::is_nil (my_test.in ()))
118 ACE_ERROR_RETURN ((LM_DEBUG, "Nil Supports_Test::test obj ref <%s>\n", ior), 1);
120 my_test->start ();
122 /* Perform test */
124 for (int i = 0; i < num_trials; i++)
126 // Create a vt_graph_impl instance and store the reference as a
127 // vt_graph_var. Then register the instance with the POA to obtain an
128 // object reference, stored as a graph_var. Increment the reference count
129 // of the vt_graph_impl instance.
130 vt_graph_impl * the_vt_graph = 0;
131 ACE_NEW_RETURN (the_vt_graph, vt_graph_impl (3), 1);
132 Supports_Test::vt_graph_var test_vt_graph = the_vt_graph;
134 Supports_Test::graph_var test_graph =
135 the_vt_graph->_this ();
136 if (CORBA::is_nil (test_graph.in ()))
137 ACE_ERROR_RETURN ((LM_DEBUG, "Nil Supports_Test::graph obj ref\n"), 1);
138 the_vt_graph->DefaultValueRefCountBase::_add_ref ();
140 // At this point, test_vt_graph and test_graph refer to the same object.
141 ACE_ASSERT (test_vt_graph->size () == 3);
142 my_test->pass_vt_graph_in (test_vt_graph.in ());
143 ACE_ASSERT (test_vt_graph->size () == 3);
145 ACE_ASSERT (test_graph->size () == 3);
146 my_test->pass_obj_graph_in (test_graph.in ());
147 ACE_ASSERT (test_graph->size () == 4);
149 test_vt_graph->add_node ("NEW2");
151 test_graph->add_node ("NEW3");
153 // After the 'pass_vt_graph_out' call returns, test_vt_graph will refer to
154 // a new object.
155 ACE_ASSERT (test_vt_graph->size () == 6);
156 my_test->pass_vt_graph_out (test_vt_graph.out ());
157 ACE_ASSERT (test_vt_graph->size () == 5);
159 // 'test_graph' still refers to the original object, but after the
160 // 'pass_obj_graph_out' call returns, it will refer to a new object,
161 // residing on the server.
162 ACE_ASSERT (test_graph->size () == 6);
163 my_test->pass_obj_graph_out (test_graph.out ());
164 ACE_ASSERT (test_graph->size () == 5);
166 // test_vt_graph and test_graph now refer to different objects.
167 test_vt_graph->add_node ("NEW2");
169 test_graph->add_node ("NEW2");
171 ACE_ASSERT (test_vt_graph->size () == 6);
172 my_test->pass_vt_graph_inout (test_vt_graph.inout ());
173 ACE_ASSERT (test_vt_graph->size () == 7);
175 ACE_ASSERT (test_graph->size () == 6);
176 my_test->pass_obj_graph_inout (test_graph.inout ());
177 ACE_ASSERT (test_graph->size () == 7);
180 my_test->finish ();
182 /* Shut down */
184 orb->destroy ();
186 ACE_DEBUG ((LM_DEBUG, "Client (%P.%t) completed test successfully\n", id));
188 catch (const CORBA::Exception& ex)
190 ex._tao_print_exception ("Exception caught:");
191 return 1;
194 return 0;