1 #include "ace/Get_Opt.h"
3 #include "tao/PortableServer/Root_POA.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("ior");
10 throw_exception (void)
20 test_i (CORBA::ORB_ptr orb
);
22 void normal_method (void);
24 void unknown_exception_in_method (void);
26 void unknown_exception_during_deactivation (void);
29 void _remove_ref (void);
36 test_i::test_i (CORBA::ORB_ptr orb
)
37 : orb_ (CORBA::ORB::_duplicate (orb
)),
43 test_i::normal_method (void)
46 "test_i::normal_method() called\n"));
50 test_i::unknown_exception_in_method (void)
53 "test_i::unknown_exception_in_method() called\n"));
56 "Unknown exception being generated: should be propagated to the client\n"));
62 test_i::unknown_exception_during_deactivation (void)
65 "test_i::unknown_exception_during_deactivation() called\n"));
67 PortableServer::POA_var poa
=
68 this->_default_POA ();
70 PortableServer::ObjectId_var id
=
71 poa
->servant_to_id (this);
73 poa
->deactivate_object (id
.in ());
77 test_i::_add_ref (void)
80 "test_i::_add_ref() called; current refcount = %d\n",
81 this->reference_count_
++));
85 test_i::_remove_ref (void)
88 "test_i::_remove_ref() called; current refcount = %d\n",
89 this->reference_count_
--));
91 if (this->reference_count_
== 0)
96 "Unknown exception being generated: should be gobbled up by the POA\n"));
102 //FUZZ: disable check_for_lack_ACE_OS
103 class test_factory_i
:
104 public POA_test_factory
108 test_factory_i (CORBA::ORB_ptr orb
);
110 test_ptr
create_test (void);
112 void shutdown (void);
116 //FUZZ: enable check_for_lack_ACE_OS
118 test_factory_i::test_factory_i (CORBA::ORB_ptr orb
)
119 : orb_ (CORBA::ORB::_duplicate (orb
))
124 test_factory_i::create_test (void)
127 new test_i (this->orb_
.in ());
129 PortableServer::ServantBase_var
safe_servant (servant
);
130 ACE_UNUSED_ARG (safe_servant
);
132 CORBA::Object_var poa_object
=
133 this->orb_
->resolve_initial_references("RootPOA");
135 PortableServer::POA_var root_poa
=
136 PortableServer::POA::_narrow (poa_object
.in ());
138 PortableServer::ObjectId_var id_act
=
139 root_poa
->activate_object (servant
);
141 CORBA::Object_var object
= root_poa
->id_to_reference (id_act
.in ());
144 test::_narrow (object
.in ());
146 return test
._retn ();
150 test_factory_i::shutdown (void)
152 ACE_DEBUG ((LM_DEBUG
,
153 "factory_i::shutdown() called\n"));
156 this->orb_
->shutdown (0);
160 parse_args (int argc
, ACE_TCHAR
*argv
[])
162 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
165 while ((c
= get_opts ()) != -1)
169 ior_output_file
= get_opts
.opt_arg ();
173 ACE_ERROR_RETURN ((LM_ERROR
,
175 "\t-o <ior output file> [defaults to %s]\n"
186 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
191 CORBA::ORB_init (argc
,argv
);
193 CORBA::Object_var poa_object
=
194 orb
->resolve_initial_references ("RootPOA");
196 PortableServer::POA_var root_poa
=
197 PortableServer::POA::_narrow (poa_object
.in ());
199 PortableServer::POAManager_var poa_manager
=
200 root_poa
->the_POAManager ();
202 if (parse_args (argc
, argv
) != 0)
206 test_factory_i
*servant
=
207 new test_factory_i (orb
.in ());
209 PortableServer::ServantBase_var
safe_servant (servant
);
210 ACE_UNUSED_ARG (safe_servant
);
212 PortableServer::ObjectId_var id_act
=
213 root_poa
->activate_object (servant
);
215 CORBA::Object_var object
= root_poa
->id_to_reference (id_act
.in ());
217 test_factory_var test_factory
=
218 test_factory::_narrow (object
.in ());
220 CORBA::String_var ior
=
221 orb
->object_to_string (test_factory
.in ());
223 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
224 if (output_file
== 0)
225 ACE_ERROR_RETURN ((LM_ERROR
,
226 "Cannot open output file for writing IOR: %s",
229 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
230 ACE_OS::fclose (output_file
);
233 poa_manager
->activate ();
235 TAO_Root_POA
*tao_poa
= dynamic_cast <TAO_Root_POA
*> (root_poa
.in ());
239 CORBA::ULong outstanding_requests
=
240 tao_poa
->outstanding_requests ();
242 ACE_DEBUG ((LM_DEBUG
,
243 "Number of outstanding requests before ORB::perform_work(): %d\n",
244 outstanding_requests
));
246 ACE_ASSERT (outstanding_requests
== 0);
248 orb
->perform_work ();
250 // On some systems this loop must yield or else the other threads
251 // will not get a chance to run.
252 ACE_OS::thr_yield ();
257 ACE_ERROR_RETURN ((LM_ERROR
,
258 "Failure: Unexpected exception caught\n"),