Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / Policies / Policies.cpp
blob9913ecb6ec3143ce66e349955bc722d8ac555069
2 //=============================================================================
3 /**
4 * @file Policies.cpp
6 * This program tests the construction of POA policies, both
7 * through the generic ORB::create_policy interface and the
8 * PortableServer specific interfaces.
10 * @author Irfan Pyarali
12 //=============================================================================
15 #include "tao/ORB.h"
16 #include "tao/AnyTypeCode/Any.h"
17 #include "tao/PortableServer/PortableServer.h"
18 #include "tao/PI_Server/PI_Server.h"
20 #include "ace/Log_Msg.h"
22 int
23 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
25 try
27 // Initialize the ORB first.
28 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
30 // Obtain the RootPOA.
31 CORBA::Object_var obj =
32 orb->resolve_initial_references ("RootPOA");
34 // Narrow to POA.
35 PortableServer::POA_var root_poa =
36 PortableServer::POA::_narrow (obj.in ());
38 // Get the POAManager of the POA.
39 PortableServer::POAManager_var poa_manager =
40 root_poa->the_POAManager ();
42 poa_manager->activate ();
44 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
47 PortableServer::ThreadPolicy_var policy1 =
48 root_poa->create_thread_policy (PortableServer::ORB_CTRL_MODEL);
50 CORBA::Any policy_value;
51 policy_value <<= PortableServer::ORB_CTRL_MODEL;
53 CORBA::Policy_var policy =
54 orb->create_policy (PortableServer::THREAD_POLICY_ID,
55 policy_value);
57 PortableServer::ThreadPolicy_var policy2 =
58 PortableServer::ThreadPolicy::_narrow (policy.in ());
60 ACE_ASSERT (policy1->value () == policy2->value ());
63 #endif /* TAO_HAS_MINIMUM_POA == 0 */
66 PortableServer::LifespanPolicy_var policy1 =
67 root_poa->create_lifespan_policy (PortableServer::TRANSIENT);
69 CORBA::Any policy_value;
70 policy_value <<= PortableServer::TRANSIENT;
72 CORBA::Policy_var policy =
73 orb->create_policy (PortableServer::LIFESPAN_POLICY_ID,
74 policy_value);
76 PortableServer::LifespanPolicy_var policy2 =
77 PortableServer::LifespanPolicy::_narrow (policy.in ());
79 ACE_ASSERT (policy1->value () == policy2->value ());
83 PortableServer::IdUniquenessPolicy_var policy1 =
84 root_poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID);
86 CORBA::Any policy_value;
87 policy_value <<= PortableServer::UNIQUE_ID;
89 CORBA::Policy_var policy =
90 orb->create_policy (PortableServer::ID_UNIQUENESS_POLICY_ID,
91 policy_value);
93 PortableServer::IdUniquenessPolicy_var policy2 =
94 PortableServer::IdUniquenessPolicy::_narrow (policy.in ());
96 ACE_ASSERT (policy1->value () == policy2->value ());
100 PortableServer::IdAssignmentPolicy_var policy1 =
101 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
103 CORBA::Any policy_value;
104 policy_value <<= PortableServer::USER_ID;
106 CORBA::Policy_var policy =
107 orb->create_policy (PortableServer::ID_ASSIGNMENT_POLICY_ID,
108 policy_value);
110 PortableServer::IdAssignmentPolicy_var policy2 =
111 PortableServer::IdAssignmentPolicy::_narrow (policy.in ());
113 ACE_ASSERT (policy1->value () == policy2->value ());
116 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
119 PortableServer::ImplicitActivationPolicy_var policy1 =
120 root_poa->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION);
122 CORBA::Any policy_value;
123 policy_value <<= PortableServer::IMPLICIT_ACTIVATION;
125 CORBA::Policy_var policy =
126 orb->create_policy (PortableServer::IMPLICIT_ACTIVATION_POLICY_ID,
127 policy_value);
129 PortableServer::ImplicitActivationPolicy_var policy2 =
130 PortableServer::ImplicitActivationPolicy::_narrow (policy.in ());
132 ACE_ASSERT (policy1->value () == policy2->value ());
136 PortableServer::ServantRetentionPolicy_var policy1 =
137 root_poa->create_servant_retention_policy (PortableServer::RETAIN);
139 CORBA::Any policy_value;
140 policy_value <<= PortableServer::RETAIN;
142 CORBA::Policy_var policy =
143 orb->create_policy (PortableServer::SERVANT_RETENTION_POLICY_ID,
144 policy_value);
146 PortableServer::ServantRetentionPolicy_var policy2 =
147 PortableServer::ServantRetentionPolicy::_narrow (policy.in ());
149 ACE_ASSERT (policy1->value () == policy2->value ());
153 PortableServer::RequestProcessingPolicy_var policy1 =
154 root_poa->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY);
156 CORBA::Any policy_value;
157 policy_value <<= PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY;
159 CORBA::Policy_var policy =
160 orb->create_policy (PortableServer::REQUEST_PROCESSING_POLICY_ID,
161 policy_value);
163 PortableServer::RequestProcessingPolicy_var policy2 =
164 PortableServer::RequestProcessingPolicy::_narrow (policy.in ());
166 ACE_ASSERT (policy1->value () == policy2->value ());
169 #endif /* TAO_HAS_MINIMUM_POA == 0 */
171 orb->destroy ();
173 ACE_DEBUG ((LM_DEBUG,
174 "%s successful\n",
175 argv[0]));
177 catch (const CORBA::Exception& ex)
179 ex._tao_print_exception ("Exception caught");
180 return -1;
183 return 0;