2 //=============================================================================
8 * @author Carlos O'Ryan
10 //=============================================================================
15 #include "tao/debug.h"
17 #include "tao/DynamicInterface/Unknown_User_Exception.h"
19 // ************************************************************************
21 // ************************************************************************
23 Test_Exception::Test_Exception ()
24 : opname_ (CORBA::string_dup ("test_exception")),
29 Test_Exception::~Test_Exception ()
31 CORBA::string_free (this->opname_
);
36 Test_Exception::opname () const
42 Test_Exception::dii_req_invoke (CORBA::Request_ptr req
)
47 req
->add_in_arg ("s1") <<= this->in_
;
48 req
->add_inout_arg ("s2") <<= this->inout_
;
49 req
->add_out_arg ("s3") <<= this->out_
;
51 req
->set_return_type (CORBA::_tc_ulong
);
53 req
->exceptions ()->add (CORBA::TypeCode::_duplicate (Param_Test::_tc_Ooops
));
57 req
->return_value () >>= this->ret_
;
59 CORBA::NamedValue_ptr o2
=
60 req
->arguments ()->item (1);
62 *o2
->value () >>= this->inout_
;
64 CORBA::NamedValue_ptr o3
=
65 req
->arguments ()->item (2);
67 *o3
->value () >>= this->out_
;
69 catch (CORBA::UnknownUserException
& user_ex
)
71 const Param_Test::Ooops
* oops
= 0;
72 const Param_Test::BadBoy
* bad_boy
= 0;
74 if (user_ex
.exception () >>= oops
)
76 const char *reason
= oops
->reason
.in ();
77 CORBA::ULong mod_value
= oops
->input
;
79 if (TAO_debug_level
> 0)
82 "Test_Exception::dii_req_invoke - "
83 "expected user exception"
89 if (reason
!= 0 && mod_value
== 1)
91 this->inout_
= this->in_
* 2;
92 this->out_
= this->in_
* 3;
93 this->ret_
= this->in_
* 4;
96 else if (user_ex
.exception () >>= bad_boy
)
98 (*bad_boy
)._tao_print_exception (
99 "Test_Exception::dii_req_invoke - "
100 "unexpected (but known) user exception\n");
102 // Since 'BadBoy' is not in the exception list the DII request,
103 // it should not be caught explicitly. See comment below.
104 this->inout_
= this->in_
* 5;
105 this->out_
= this->in_
* 5;
106 this->ret_
= this->in_
* 5;
110 ACE_ERROR ((LM_ERROR
,
111 "ERROR Test_Exception::dii_req_invoke - "
112 "unexpected (and unknown) user exception\n"));
117 // Catch the SystemException type CORBA::NO_MEMORY thrown by the
118 // server to test the system exception.
119 catch (const CORBA::NO_MEMORY
&)
121 // 'NO_MEMORY' system exception should be caught here. This
122 // happens when the IN arg == 2.
123 // Otherwise we don't set the other arg values so the validity
124 // check will flag the error.
125 if (this->in_
% 4 == 2)
127 this->inout_
= this->in_
* 2;
128 this->out_
= this->in_
* 3;
129 this->ret_
= this->in_
* 4;
131 if (TAO_debug_level
> 0)
133 ACE_DEBUG ((LM_DEBUG
,
134 "Test_Exception::dii_req_invoke - "
135 "expected CORBA::NO_MEMORY system exception\n"));
138 else if (this->in_
% 4 == 1)
140 // We caught NO_MEMORY system exception when we should have caught Ooops.
141 if (TAO_debug_level
> 0)
143 ACE_DEBUG ((LM_DEBUG
,
144 "Test_Exception::dii_req_invoke - "
145 "caught NO_MEMORY system exception - "
146 "expected known user exception\n"));
149 else if (this->in_
% 4 == 3)
151 // We caught NO_MEMORY system exception when we should have caught UNKNOWN.
152 if (TAO_debug_level
> 0)
154 ACE_DEBUG ((LM_DEBUG
,
155 "Test_Exception::dii_req_invoke - "
156 "caught NO_MEMORY system exception - "
157 "expected UNKNOWN exception\n"));
162 // We caught NO_MEMORY system exception when we should have caught nothing.
163 if (TAO_debug_level
> 0)
165 ACE_DEBUG ((LM_DEBUG
,
166 "Test_Exception::dii_req_invoke - "
167 "caught unexpected unknown exception\n"));
171 catch (const CORBA::UNKNOWN
&)
173 // 'BadBoy' should be caught here. This happens when the IN arg == 3.
174 // Otherwise we don't set the other arg values so the validity
175 // check will flag the error.
176 if (this->in_
% 4 == 3)
178 this->inout_
= this->in_
* 2;
179 this->out_
= this->in_
* 3;
180 this->ret_
= this->in_
* 4;
182 if (TAO_debug_level
> 0)
184 ACE_DEBUG ((LM_DEBUG
,
185 "Test_Exception::dii_req_invoke - "
186 "expected CORBA::UNKNOWN\n"));
189 else if (this->in_
% 4 == 1)
191 // We caught UNKNOWN when we should have caught Ooops.
192 if (TAO_debug_level
> 0)
194 ACE_DEBUG ((LM_DEBUG
,
195 "Test_Exception::dii_req_invoke - "
196 "caught unknown exception - "
197 "expected known user exception\n"));
200 else if (this->in_
% 4 == 2)
202 // We caught UNKNOWN exception when we should have caught NO_MEMORY.
203 if (TAO_debug_level
> 0)
205 ACE_DEBUG ((LM_DEBUG
,
206 "Test_Exception::dii_req_invoke - "
207 "caught unknown exception - "
208 "expected NO_MEMORY system exception\n"));
213 // We caught UNKNOWN when we should have caught nothing.
214 if (TAO_debug_level
> 0)
216 ACE_DEBUG ((LM_DEBUG
,
217 "Test_Exception::dii_req_invoke - "
218 "caught unexpected unknown exception\n"));
225 Test_Exception::init_parameters (Param_Test_ptr
)
233 Test_Exception::reset_parameters ()
242 Test_Exception::run_sii_test (Param_Test_ptr objref
)
247 this->ret_
= objref
->test_exception (this->in_
,
251 catch (const Param_Test::Ooops
& ex
)
253 const char *reason
= ex
.reason
.in ();
260 CORBA::ULong
const mod_value
= ex
.input
;
262 // We should be catching Ooops only when this is true.
268 if (TAO_debug_level
> 0)
270 ACE_DEBUG ((LM_DEBUG
,
271 "Test_Exception::run_sii_test - "
272 "expected user exception"
278 // These weren't passed back because of the exception. We
279 // set them here to the 'correct' values so the validity
280 // check won't return an error.
281 this->inout_
= this->in_
* 2;
282 this->out_
= this->in_
* 3;
283 this->ret_
= this->in_
* 4;
286 catch (const CORBA::NO_MEMORY
& ex
)
288 // 'SystemException' should be caught here, 'CORBA::NO_MEMORY'
289 // system exception is thrown by the servant when the
291 int d
= this->in_
% 4;
295 if (d
== 1 && TAO_debug_level
> 0)
297 ACE_DEBUG ((LM_DEBUG
,
298 "Test_Exception::run_sii_test - "
299 "caught system exception - "
300 "expected known user exception\n"));
302 else if (d
== 3 && TAO_debug_level
> 0)
304 ACE_DEBUG ((LM_DEBUG
,
305 "Test_Exception::run_sii_test - "
306 "caught system exception - "
307 "expected unknown exception\n"));
313 if (TAO_debug_level
> 0)
315 ex
._tao_print_exception (
316 "Test_Exception::run_sii_test - ""expected system exception\n");
319 // These weren't passed back because of the exception. We
320 // set them here to the 'correct' values so the validity
321 // check won't return an error.
322 this->inout_
= this->in_
* 2;
323 this->out_
= this->in_
* 3;
324 this->ret_
= this->in_
* 4;
327 catch (const CORBA::UNKNOWN
& ex
)
329 // 'BadBoy' should be caught here, since generated code for
330 // Param_Test::test_exception() knows nothing about it.
331 // 'Ooops' however, should not be caught here. 'BadBoy'
332 // is thrown by the servant when the IN argument == 3.
333 int d
= this->in_
% 4;
337 if (d
== 1 && TAO_debug_level
> 0)
339 ACE_DEBUG ((LM_DEBUG
,
340 "Test_Exception::run_sii_test - "
341 "caught unknown exception - "
342 "expected known user exception\n"));
344 else if (d
== 2 && TAO_debug_level
> 0)
346 ACE_DEBUG ((LM_DEBUG
,
347 "Test_Exception::run_sii_test - "
348 "caught unknown exception - "
349 "expected known system exception\n"));
355 if (TAO_debug_level
> 0)
357 ex
._tao_print_exception (
358 "Test_Exception::run_sii_test - ""expected unknown exception\n");
361 // These weren't passed back because of the exception. We
362 // set them here to the 'correct' values so the validity
363 // check won't return an error.
364 this->inout_
= this->in_
* 2;
365 this->out_
= this->in_
* 3;
366 this->ret_
= this->in_
* 4;
369 catch (const Param_Test::BadBoy
& ex
)
371 // We shouldn't end up here. See comment above.
372 ex
._tao_print_exception (
373 "Test_Exception::run_sii_test - ""unexpected user exception\n");
378 // Normal reply - no exception thrown.
383 Test_Exception::check_validity ()
385 if (this->inout_
== this->in_
* 2 &&
386 this->out_
== this->in_
* 3 &&
387 this->ret_
== this->in_
* 4)
396 Test_Exception::check_validity (CORBA::Request_ptr
)
398 return this->check_validity ();
402 Test_Exception::print_values ()
404 ACE_DEBUG ((LM_DEBUG
,