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");
10 static const ACE_TCHAR corbaloc_prefix
[] = ACE_TEXT("corbaloc:");
11 int expect_ex_kind
= TAO::FOE_NON
;
15 parse_args (int argc
, ACE_TCHAR
*argv
[])
17 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:e:"));
20 while ((c
= get_opts ()) != -1)
24 ior
= get_opts
.opt_arg ();
28 expect_ex_kind
= ACE_OS::atoi (get_opts
.opt_arg ());
33 ACE_ERROR_RETURN ((LM_ERROR
,
36 "-e <expected exception kind> "
42 if (ACE_OS::strncmp (ior
,
44 ACE_OS::strlen(corbaloc_prefix
)) != 0)
47 // Indicates successful parsing of the command line
51 class Worker
: public ACE_Task_Base
54 Worker (CORBA::ORB_ptr orb
);
57 // = The Task_Base methods
60 // Caught any exception ?
61 int received_ex_kind () const;
63 // Return number of received exceptions.
64 int num_received_ex () const;
66 // Indicate if the invocation completed.
67 bool invocation_completed () const;
75 // The exceptions caught.
76 int received_ex_kind_
;
77 // The number of received exceptions.
79 // Flag indicating that the invocation was completed.
80 bool invocation_completed_
;
81 // Flag for test completion. The result is
82 // collected before done.
87 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
92 CORBA::ORB_init (argc
, argv
);
94 if (parse_args (argc
, argv
) != 0)
97 Worker
worker (orb
.in ());
99 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
101 ACE_ERROR_RETURN ((LM_ERROR
,
102 "(%P|%t) Cannot activate worker threads\n"),
107 while (now
< timeout
&&
108 ((expect_ex_kind
== 0 && !worker
.invocation_completed ()) ||
109 (expect_ex_kind
!= 0 && expect_ex_kind
!= worker
.received_ex_kind ()))
112 std::cout
<< "." << std::flush
;
114 ACE_Time_Value
tv (1, 0);
117 ACE_ASSERT (now
!= 0);
120 std::cout
<< std::endl
;
124 CORBA::Object_var object
=
125 orb
->string_to_object (ior
);
127 Simple_Server_var server
=
128 Simple_Server::_narrow (object
.in ());
136 worker
.thr_mgr ()->wait ();
140 expect_ex_kind
== TAO::FOE_NON
&& worker
.num_received_ex () == 0 && worker
.invocation_completed ();
141 bool expect_ex_received
=
142 expect_ex_kind
== worker
.received_ex_kind () && worker
.num_received_ex () > 0 && !worker
.invocation_completed ();
143 if (expect_no_ex
|| expect_ex_received
)
145 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)client: test passed.\n"));
150 ACE_DEBUG ((LM_ERROR
, "(%P|%t)client: test failed.\n"));
155 catch (const CORBA::Exception
& ex
)
157 ex
._tao_print_exception ("Exception caught in main:");
164 // ****************************************************************
166 Worker::Worker (CORBA::ORB_ptr orb
)
167 : orb_ (CORBA::ORB::_duplicate (orb
)),
168 received_ex_kind_ (TAO::FOE_NON
),
169 num_received_ex_ (0),
170 invocation_completed_ (false),
180 CORBA::Object_var object
=
181 this->orb_
->string_to_object (ior
);
183 Simple_Server_var server
=
184 Simple_Server::_narrow (object
.in ());
186 if (CORBA::is_nil (server
.in ()))
188 ACE_ERROR ((LM_ERROR
,
189 "Object reference <%s> is nil.\n",
196 server
->test_is_a ("IDL:Foo:1.0");
198 this->invocation_completed_
= true;
201 ACE_DEBUG ((LM_DEBUG
,
202 "(%P|%t) unexpected result = %d\n",
205 catch (const CORBA::OBJECT_NOT_EXIST
&)
207 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received OBJECT_NOT_EXIST \n"));
210 ++ this->num_received_ex_
;
211 received_ex_kind_
|= TAO::FOE_OBJECT_NOT_EXIST
;
214 catch (const CORBA::COMM_FAILURE
&)
216 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received COMM_FAILURE \n"));
219 ++ this->num_received_ex_
;
220 received_ex_kind_
|= TAO::FOE_COMM_FAILURE
;
223 catch (const CORBA::TRANSIENT
&)
225 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received TRANSIENT \n"));
228 ++ this->num_received_ex_
;
229 received_ex_kind_
|= TAO::FOE_TRANSIENT
;
232 catch (const CORBA::INV_OBJREF
&)
234 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received INV_OBJREF \n"));
237 ++ this->num_received_ex_
;
238 received_ex_kind_
|= TAO::FOE_INV_OBJREF
;
242 catch (const CORBA::Exception
& ex
)
244 ex
._tao_print_exception ("Unexpected exception caught");
252 Worker::received_ex_kind () const
254 return received_ex_kind_
;
258 Worker::num_received_ex () const
260 return num_received_ex_
;
264 Worker::invocation_completed () const
266 return invocation_completed_
;