1 #include "Echo_Handler.h"
2 #include "Client_ORBInitializer.h"
3 #include "Client_Interceptor.h"
5 #include "tao/ORBInitializer_Registry.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Log_Msg.h"
11 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
12 static int exit_status
= 0;
13 const unsigned long ITERATIONS
= 100;
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
21 while ((c
= get_opts ()) != -1)
25 ior
= get_opts
.opt_arg ();
30 ACE_ERROR_RETURN ((LM_ERROR
,
37 // Indicates successful parsing of the command line
41 static void test_synchronous (Test::Echo_ptr echo
);
43 static void test_ami (CORBA::ORB_ptr orb
,
46 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
51 PortableInterceptor::ORBInitializer_var
initializer (
52 new Client_ORBInitializer
);
53 PortableInterceptor::register_orb_initializer (initializer
.in());
57 CORBA::ORB_init (argc
, argv
);
59 if (parse_args (argc
, argv
) != 0)
62 CORBA::Object_var poa_object
=
63 orb
->resolve_initial_references ("RootPOA");
65 PortableServer::POA_var root_poa
=
66 PortableServer::POA::_narrow (poa_object
.in ());
68 if (CORBA::is_nil (root_poa
.in ()))
69 ACE_ERROR_RETURN ((LM_ERROR
,
70 " (%P|%t) Panic: nil RootPOA\n"),
73 PortableServer::POAManager_var poa_manager
=
74 root_poa
->the_POAManager ();
76 CORBA::Object_var tmp
=
77 orb
->string_to_object (ior
);
80 Test::Echo::_narrow (tmp
.in ());
82 poa_manager
->activate ();
84 if (CORBA::is_nil (echo
.in ()))
86 ACE_ERROR_RETURN ((LM_DEBUG
,
87 "Nil Test::Echo reference <%s>\n",
92 test_synchronous (echo
.in ());
101 unsigned long request_count
=
102 Echo_Client_Request_Interceptor::request_count
;
103 unsigned long response_count
=
104 Echo_Client_Request_Interceptor::reply_count
105 + Echo_Client_Request_Interceptor::other_count
106 + Echo_Client_Request_Interceptor::exception_count
;
108 if (request_count
!= response_count
)
110 ACE_ERROR ((LM_ERROR
,
111 "ERROR: Mismatched count of requests and responses "
112 " (request = %d, response = %d)\n",
113 request_count
, response_count
));
116 if (request_count
== 0)
118 ACE_ERROR ((LM_ERROR
,
119 "ERROR: No requests handled "));
122 if (response_count
== 0)
124 ACE_ERROR ((LM_ERROR
,
125 "ERROR: No response handled "));
128 catch (const CORBA::Exception
& ex
)
130 ex
._tao_print_exception ("Exception caught:");
138 test_synchronous (Test::Echo_ptr echo
)
140 unsigned long initial_request_count
=
141 Echo_Client_Request_Interceptor::request_count
;
142 unsigned long initial_reply_count
=
143 Echo_Client_Request_Interceptor::reply_count
;
145 for (unsigned long i
= 0; i
!= ITERATIONS
; ++i
)
147 CORBA::String_var s
=
148 echo
->echo_operation ("dummy message");
151 unsigned long total_request_count
=
152 Echo_Client_Request_Interceptor::request_count
- initial_request_count
;
153 unsigned long total_reply_count
=
154 Echo_Client_Request_Interceptor::reply_count
- initial_reply_count
;
156 if (total_request_count
!= ITERATIONS
157 || total_reply_count
!= ITERATIONS
)
160 "ERROR: Invalid or mismatched request/reply "
161 "count (request = %d, reply = %d)\n",
162 total_request_count
, total_reply_count
));
166 if (total_request_count
== 0)
168 ACE_ERROR ((LM_ERROR
,
169 "ERROR: No synchronouse requests handled "));
172 if (total_reply_count
== 0)
174 ACE_ERROR ((LM_ERROR
,
175 "ERROR: No synchronouse requests handled "));
180 test_ami (CORBA::ORB_ptr orb
,
183 Test::AMI_EchoHandler_var echo_handler
;
184 Echo_Handler
* echo_handler_impl
= new Echo_Handler
;
186 PortableServer::ServantBase_var safe_echo_handler
= echo_handler_impl
;
189 echo_handler_impl
->_this ();
191 unsigned long initial_reply_count
=
192 Echo_Client_Request_Interceptor::reply_count
;
193 unsigned long initial_request_count
=
194 Echo_Client_Request_Interceptor::request_count
;
195 unsigned long initial_other_count
=
196 Echo_Client_Request_Interceptor::other_count
;
198 for (unsigned long i
= 0; i
!= ITERATIONS
; ++i
)
200 echo
->sendc_echo_operation (
205 unsigned long total_reply_count
=
206 Echo_Client_Request_Interceptor::reply_count
- initial_reply_count
;
207 unsigned long total_request_count
=
208 Echo_Client_Request_Interceptor::request_count
-
209 (total_reply_count
+ initial_request_count
);
210 unsigned long total_other_count
=
211 Echo_Client_Request_Interceptor::other_count
- initial_other_count
;
213 if (total_request_count
!= ITERATIONS
214 || total_other_count
!= ITERATIONS
)
217 "ERROR: In test_ami () unexpected request/other "
218 "count (request = %d, other = %d)\n",
219 total_request_count
, total_other_count
));
223 while (echo_handler_impl
->replies () != ITERATIONS
)
225 CORBA::Boolean pending
=
226 orb
->work_pending ();
230 orb
->perform_work ();
235 total_request_count
=
236 Echo_Client_Request_Interceptor::request_count
- initial_request_count
;
238 Echo_Client_Request_Interceptor::reply_count
- initial_reply_count
;
240 // total_request_count is 2*ITERATIONS since it's incremented twice for
241 // each call. Once for Echo and once for Echo_Handler.
242 if (total_request_count
!= 2 * ITERATIONS
243 || total_reply_count
!= ITERATIONS
)
246 "ERROR: In test_ami () unexpected request/reply "
247 "count (request = %d, reply = %d)\n",
248 total_request_count
, total_reply_count
));
255 wait_for_exception (CORBA::ORB_ptr orb
,
258 ACE_Time_Value
tv (1, 0);
261 bool exception_detected
= false;
263 while(!exception_detected
)
267 CORBA::String_var dummy
=
268 echo
->echo_operation ("foo");
270 catch (const CORBA::Exception
& ex
)
272 exception_detected
= true;
276 tv
= ACE_Time_Value (1, 0);