2 #include "ace/Get_Opt.h"
4 #include "ace/streams.h"
5 #include "tao/Invocation_Utils.h"
6 #include "ace/OS_NS_unistd.h"
8 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
11 static const ACE_TCHAR corbaloc_prefix
[] = ACE_TEXT("corbaloc:");
12 int expect_ex_kind
= TAO::FOE_NON
;
14 int expect_num_ex
= 1;
17 parse_args (int argc
, ACE_TCHAR
*argv
[])
19 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("xk:e:i:n:"));
22 while ((c
= get_opts ()) != -1)
30 ior
= get_opts
.opt_arg ();
34 expect_ex_kind
= ACE_OS::atoi (get_opts
.opt_arg ());
38 num_requests
= ACE_OS::atoi (get_opts
.opt_arg ());
42 expect_num_ex
= ACE_OS::atoi (get_opts
.opt_arg ());
47 ACE_ERROR_RETURN ((LM_ERROR
,
50 "-e <expected exception kind> "
52 "-n <expected number of exceptions> "
58 if (ACE_OS::strncmp (ior
,
60 ACE_OS::strlen(corbaloc_prefix
)) != 0)
63 // Indicates successful parsing of the command line
67 class Worker
: public ACE_Task_Base
70 Worker (CORBA::ORB_ptr orb
);
73 // = The Task_Base methods
74 virtual int svc (void);
76 // Caught any exception ?
77 int received_ex_kind () const;
79 // Return number of received exceptions.
80 int num_received_ex () const;
89 // The exceptions caught.
90 int received_ex_kind_
;
91 // The number of received exceptions.
93 // Flag for test completion. The result is
94 // collected before done.
99 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
104 CORBA::ORB_init (argc
, argv
);
106 if (parse_args (argc
, argv
) != 0)
109 Worker
worker (orb
.in ());
111 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
113 ACE_ERROR_RETURN ((LM_ERROR
,
114 "(%P|%t) Cannot activate worker threads\n"),
120 && ((expect_ex_kind
!= TAO::FOE_NON
121 && worker
.received_ex_kind () != expect_ex_kind
122 && worker
.num_received_ex () != expect_num_ex
)
123 || expect_ex_kind
== TAO::FOE_NON
))
127 ACE_Time_Value
tv (1, 0);
130 std::cout
<< std::endl
;
136 CORBA::Object_var object
=
137 orb
->string_to_object (ior
);
139 Simple_Server_var server
=
140 Simple_Server::_narrow (object
.in ());
149 worker
.thr_mgr ()->wait ();
151 if (worker
.received_ex_kind () != expect_ex_kind
152 || worker
.num_received_ex () != expect_num_ex
)
154 ACE_ERROR_RETURN ((LM_ERROR
,
155 ("(%P|%t)client: test failed - expected is different from received. "
156 "expected %d/%d received %d/%d.\n"),
157 expect_ex_kind
, expect_num_ex
, worker
.received_ex_kind (), worker
.num_received_ex()),
161 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)client: test passed.\n"));
163 catch (const CORBA::Exception
& ex
)
165 ex
._tao_print_exception ("Exception caught in main:");
172 // ****************************************************************
174 Worker::Worker (CORBA::ORB_ptr orb
)
175 : orb_ (CORBA::ORB::_duplicate (orb
)),
176 received_ex_kind_ (TAO::FOE_NON
),
177 num_received_ex_ (0),
187 CORBA::Object_var object
=
188 this->orb_
->string_to_object (ior
);
190 Simple_Server_var server
=
191 Simple_Server::_narrow (object
.in ());
193 if (CORBA::is_nil (server
.in ()))
195 ACE_ERROR ((LM_ERROR
,
196 "Object reference <%s> is nil.\n",
201 for (int i
= 0; i
< num_requests
; ++i
)
205 server
->test_is_a ("IDL:Foo:1.0");
208 ACE_DEBUG ((LM_DEBUG
,
209 "(%P|%t) unexpected result = %d\n",
213 catch (const CORBA::OBJECT_NOT_EXIST
&)
215 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received OBJECT_NOT_EXIST \n"));
218 ++ this->num_received_ex_
;
219 received_ex_kind_
|= TAO::FOE_OBJECT_NOT_EXIST
;
222 catch (const CORBA::COMM_FAILURE
&)
224 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received COMM_FAILURE \n"));
227 ++ this->num_received_ex_
;
228 received_ex_kind_
|= TAO::FOE_COMM_FAILURE
;
231 catch (const CORBA::TRANSIENT
&)
233 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received TRANSIENT \n"));
236 ++ this->num_received_ex_
;
237 received_ex_kind_
|= TAO::FOE_TRANSIENT
;
240 catch (const CORBA::INV_OBJREF
&)
242 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received INV_OBJREF \n"));
245 ++ this->num_received_ex_
;
246 received_ex_kind_
|= TAO::FOE_INV_OBJREF
;
251 catch (const CORBA::Exception
& ex
)
253 ex
._tao_print_exception (
254 "Unexpected exception caught");
262 Worker::received_ex_kind () const
264 return received_ex_kind_
;
268 Worker::num_received_ex () const
270 return num_received_ex_
;