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
76 // Caught any exception ?
77 int received_ex_kind () const;
79 // Return number of received exceptions.
80 int num_received_ex () const;
88 // The exceptions caught.
89 int received_ex_kind_
;
90 // The number of received exceptions.
92 // Flag for test completion. The result is
93 // collected before done.
98 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
103 CORBA::ORB_init (argc
, argv
);
105 if (parse_args (argc
, argv
) != 0)
108 Worker
worker (orb
.in ());
110 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 "(%P|%t) Cannot activate worker threads\n"),
119 && ((expect_ex_kind
!= TAO::FOE_NON
120 && worker
.received_ex_kind () != expect_ex_kind
121 && worker
.num_received_ex () != expect_num_ex
)
122 || expect_ex_kind
== TAO::FOE_NON
))
126 ACE_Time_Value
tv (1, 0);
129 std::cout
<< std::endl
;
135 CORBA::Object_var object
=
136 orb
->string_to_object (ior
);
138 Simple_Server_var server
=
139 Simple_Server::_narrow (object
.in ());
148 worker
.thr_mgr ()->wait ();
150 if (worker
.received_ex_kind () != expect_ex_kind
151 || worker
.num_received_ex () != expect_num_ex
)
153 ACE_ERROR_RETURN ((LM_ERROR
,
154 ("(%P|%t)client: test failed - expected is different from received. "
155 "expected %d/%d received %d/%d.\n"),
156 expect_ex_kind
, expect_num_ex
, worker
.received_ex_kind (), worker
.num_received_ex()),
160 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)client: test passed.\n"));
162 catch (const CORBA::Exception
& ex
)
164 ex
._tao_print_exception ("Exception caught in main:");
171 // ****************************************************************
173 Worker::Worker (CORBA::ORB_ptr orb
)
174 : orb_ (CORBA::ORB::_duplicate (orb
)),
175 received_ex_kind_ (TAO::FOE_NON
),
176 num_received_ex_ (0),
186 CORBA::Object_var object
=
187 this->orb_
->string_to_object (ior
);
189 Simple_Server_var server
=
190 Simple_Server::_narrow (object
.in ());
192 if (CORBA::is_nil (server
.in ()))
194 ACE_ERROR ((LM_ERROR
,
195 "Object reference <%s> is nil.\n",
200 for (int i
= 0; i
< num_requests
; ++i
)
204 server
->test_is_a ("IDL:Foo:1.0");
207 ACE_DEBUG ((LM_DEBUG
,
208 "(%P|%t) unexpected result = %d\n",
211 catch (const CORBA::OBJECT_NOT_EXIST
&)
213 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received OBJECT_NOT_EXIST \n"));
216 ++ this->num_received_ex_
;
217 received_ex_kind_
|= TAO::FOE_OBJECT_NOT_EXIST
;
220 catch (const CORBA::COMM_FAILURE
&)
222 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received COMM_FAILURE \n"));
225 ++ this->num_received_ex_
;
226 received_ex_kind_
|= TAO::FOE_COMM_FAILURE
;
229 catch (const CORBA::TRANSIENT
&)
231 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received TRANSIENT \n"));
234 ++ this->num_received_ex_
;
235 received_ex_kind_
|= TAO::FOE_TRANSIENT
;
238 catch (const CORBA::INV_OBJREF
&)
240 //ACE_DEBUG ((LM_DEBUG, "(%P|%t)received INV_OBJREF \n"));
243 ++ this->num_received_ex_
;
244 received_ex_kind_
|= TAO::FOE_INV_OBJREF
;
249 catch (const CORBA::Exception
& ex
)
251 ex
._tao_print_exception (
252 "Unexpected exception caught");
260 Worker::received_ex_kind () const
262 return received_ex_kind_
;
266 Worker::num_received_ex () const
268 return num_received_ex_
;