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
58 virtual int svc (void);
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;
76 // The exceptions caught.
77 int received_ex_kind_
;
78 // The number of received exceptions.
80 // Flag indicating that the invocation was completed.
81 bool invocation_completed_
;
82 // Flag for test completion. The result is
83 // collected before done.
88 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
93 CORBA::ORB_init (argc
, argv
);
95 if (parse_args (argc
, argv
) != 0)
98 Worker
worker (orb
.in ());
100 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
102 ACE_ERROR_RETURN ((LM_ERROR
,
103 "(%P|%t) Cannot activate worker threads\n"),
108 while (now
< timeout
&&
109 ((expect_ex_kind
== 0 && !worker
.invocation_completed ()) ||
110 (expect_ex_kind
!= 0 && expect_ex_kind
!= worker
.received_ex_kind ()))
113 std::cout
<< "." << std::flush
;
115 ACE_Time_Value
tv (1, 0);
118 ACE_ASSERT (now
!= 0);
121 std::cout
<< std::endl
;
125 CORBA::Object_var object
=
126 orb
->string_to_object (ior
);
128 Simple_Server_var server
=
129 Simple_Server::_narrow (object
.in ());
137 worker
.thr_mgr ()->wait ();
141 expect_ex_kind
== TAO::FOE_NON
&& worker
.num_received_ex () == 0 && worker
.invocation_completed ();
142 bool expect_ex_received
=
143 expect_ex_kind
== worker
.received_ex_kind () && worker
.num_received_ex () > 0 && !worker
.invocation_completed ();
144 if (expect_no_ex
|| expect_ex_received
)
146 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)client: test passed.\n"));
151 ACE_DEBUG ((LM_ERROR
, "(%P|%t)client: test failed.\n"));
156 catch (const CORBA::Exception
& ex
)
158 ex
._tao_print_exception ("Exception caught in main:");
165 // ****************************************************************
167 Worker::Worker (CORBA::ORB_ptr orb
)
168 : orb_ (CORBA::ORB::_duplicate (orb
)),
169 received_ex_kind_ (TAO::FOE_NON
),
170 num_received_ex_ (0),
171 invocation_completed_ (false),
181 CORBA::Object_var object
=
182 this->orb_
->string_to_object (ior
);
184 Simple_Server_var server
=
185 Simple_Server::_narrow (object
.in ());
187 if (CORBA::is_nil (server
.in ()))
189 ACE_ERROR ((LM_ERROR
,
190 "Object reference <%s> is nil.\n",
197 server
->test_is_a ("IDL:Foo:1.0");
199 this->invocation_completed_
= true;
202 ACE_DEBUG ((LM_DEBUG
,
203 "(%P|%t) unexpected result = %d\n",
207 catch (const CORBA::OBJECT_NOT_EXIST
&)
209 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received OBJECT_NOT_EXIST \n"));
212 ++ this->num_received_ex_
;
213 received_ex_kind_
|= TAO::FOE_OBJECT_NOT_EXIST
;
216 catch (const CORBA::COMM_FAILURE
&)
218 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received COMM_FAILURE \n"));
221 ++ this->num_received_ex_
;
222 received_ex_kind_
|= TAO::FOE_COMM_FAILURE
;
225 catch (const CORBA::TRANSIENT
&)
227 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received TRANSIENT \n"));
230 ++ this->num_received_ex_
;
231 received_ex_kind_
|= TAO::FOE_TRANSIENT
;
234 catch (const CORBA::INV_OBJREF
&)
236 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)received INV_OBJREF \n"));
239 ++ this->num_received_ex_
;
240 received_ex_kind_
|= TAO::FOE_INV_OBJREF
;
244 catch (const CORBA::Exception
& ex
)
246 ex
._tao_print_exception ("Unexpected exception caught");
254 Worker::received_ex_kind () const
256 return received_ex_kind_
;
260 Worker::num_received_ex () const
262 return num_received_ex_
;
266 Worker::invocation_completed () const
268 return invocation_completed_
;