2 //=============================================================================
4 * @file Excessive_Object_Deactivations.cpp
6 * This program tests for excessive deactivations of a servant.
7 * The test checks excessive deactivations in a POA with SYSTEM_ID
8 * and other POA with USER_ID. The test also check for excessive
9 * deactivations during upcalls.
11 * @author Irfan Pyarali
13 //=============================================================================
18 class test_i
: public POA_test
21 void deactivate_self ();
23 PortableServer::POA_ptr
_default_POA ();
25 PortableServer::POA_var poa_
;
27 PortableServer::ObjectId id_
;
30 PortableServer::POA_ptr
31 test_i::_default_POA ()
33 return PortableServer::POA::_duplicate (this->poa_
.in ());
37 test_i::deactivate_self ()
39 this->poa_
->deactivate_object (this->id_
);
42 int expected_exception_raised
= 0;
46 this->poa_
->deactivate_object (this->id_
);
48 catch (const PortableServer::POA::ObjectNotActive
& )
50 // This is the correct exception! Ignore
51 expected_exception_raised
= 1;
53 catch (const CORBA::Exception
& ex
)
55 ex
._tao_print_exception (
56 "Exception caught of incorrect type");
60 // Make sure an exception was raised and it was of the correct type.
61 ACE_ASSERT (expected_exception_raised
);
63 ACE_UNUSED_ARG (expected_exception_raised
);
67 test_object_deactivation (PortableServer::POA_ptr poa
,
68 const PortableServer::ObjectId
&id
)
71 int expected_exception_raised
= 0;
73 PortableServer::ObjectId_var invalid_id
=
74 PortableServer::string_to_ObjectId ("invalid id");
78 poa
->deactivate_object (invalid_id
.in ());
80 catch (const PortableServer::POA::ObjectNotActive
& )
82 // This is the correct exception! Ignore
83 expected_exception_raised
= 1;
85 catch (const CORBA::Exception
& ex
)
87 ex
._tao_print_exception (
88 "Exception caught of incorrect type");
92 // Make sure an exception was raised and it was of the correct
94 ACE_ASSERT (expected_exception_raised
);
97 poa
->activate_object_with_id (id
,
100 poa
->deactivate_object (id
);
103 expected_exception_raised
= 0;
107 poa
->deactivate_object (id
);
109 catch (const PortableServer::POA::ObjectNotActive
& )
111 // This is the correct exception! Ignore
112 expected_exception_raised
= 1;
114 catch (const CORBA::Exception
& ex
)
116 ex
._tao_print_exception (
117 "Exception caught of incorrect type");
121 // Make sure an exception was raised and it was of the correct
123 ACE_ASSERT (expected_exception_raised
);
125 poa
->activate_object_with_id (id
,
129 PortableServer::POA::_duplicate (poa
);
133 CORBA::Object_var object
= poa
->id_to_reference (id
);
136 test::_narrow (object
.in ());
138 test
->deactivate_self ();
140 // ACE_ASSERT dissappears in non-debug builds
141 ACE_UNUSED_ARG (expected_exception_raised
);
145 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
149 // Initialize the ORB first.
150 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
152 // Obtain the RootPOA.
153 CORBA::Object_var obj
=
154 orb
->resolve_initial_references ("RootPOA");
156 // Get the POA_var object from Object_var.
157 PortableServer::POA_var root_poa
=
158 PortableServer::POA::_narrow (obj
.in ());
160 // Get the POAManager of the RootPOA.
161 PortableServer::POAManager_var poa_manager
=
162 root_poa
->the_POAManager ();
164 CORBA::PolicyList empty_policies
;
165 PortableServer::POA_var child_poa
=
166 root_poa
->create_POA ("child",
170 poa_manager
->activate ();
173 root_poa
->create_reference ("IDL:test:1.0");
175 PortableServer::ObjectId_var id
=
176 root_poa
->reference_to_id (obj
.in ());
178 test_object_deactivation (root_poa
.in (),
181 id
= PortableServer::string_to_ObjectId ("good id");
183 test_object_deactivation (child_poa
.in (),
188 catch (const CORBA::Exception
& ex
)
190 ex
._tao_print_exception ("Exception caught");