Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / Excessive_Object_Deactivations / Excessive_Object_Deactivations.cpp
blobb40a5a546cc67a4e8503a383c5192595ae4b2b79
2 //=============================================================================
3 /**
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 //=============================================================================
16 #include "testS.h"
18 class test_i : public POA_test
20 public:
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 ());
36 void
37 test_i::deactivate_self ()
39 this->poa_->deactivate_object (this->id_);
41 // Exception flag
42 int expected_exception_raised = 0;
44 try
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");
57 ACE_ASSERT (0);
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);
66 void
67 test_object_deactivation (PortableServer::POA_ptr poa,
68 const PortableServer::ObjectId &id)
70 test_i servant;
71 int expected_exception_raised = 0;
73 PortableServer::ObjectId_var invalid_id =
74 PortableServer::string_to_ObjectId ("invalid id");
76 try
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");
89 ACE_ASSERT (0);
92 // Make sure an exception was raised and it was of the correct
93 // type.
94 ACE_ASSERT (expected_exception_raised);
97 poa->activate_object_with_id (id,
98 &servant);
100 poa->deactivate_object (id);
102 // Reset flag
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");
118 ACE_ASSERT (0);
121 // Make sure an exception was raised and it was of the correct
122 // type.
123 ACE_ASSERT (expected_exception_raised);
125 poa->activate_object_with_id (id,
126 &servant);
128 servant.poa_ =
129 PortableServer::POA::_duplicate (poa);
131 servant.id_ = id;
133 CORBA::Object_var object = poa->id_to_reference (id);
135 test_var test =
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",
167 poa_manager.in (),
168 empty_policies);
170 poa_manager->activate ();
172 obj =
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 (),
179 id.in ());
181 id = PortableServer::string_to_ObjectId ("good id");
183 test_object_deactivation (child_poa.in (),
184 id.in ());
186 orb->destroy ();
188 catch (const CORBA::Exception& ex)
190 ex._tao_print_exception ("Exception caught");
191 return -1;
194 return 0;