ACE+TAO-7_0_8
[ACE_TAO.git] / TAO / tests / RTCORBA / Policies / Policies.cpp
blobe044720eec189e9624205ac6a3c9ce502032e6dc
2 //=============================================================================
3 /**
4 * @file Policies.cpp
6 * This program tests the construction of RTCORBA policies, both
7 * through the generic ORB::create_policy interface and the
8 * RTCORBA specific interfaces.
10 * @author Irfan Pyarali
12 //=============================================================================
15 #include "tao/ORB.h"
16 #include "tao/RTCORBA/RTCORBA.h"
17 #include "tao/AnyTypeCode/Any.h"
19 #include "ace/Log_Msg.h"
21 int
22 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
25 try
27 // Initialize the ORB first.
28 CORBA::ORB_var orb =
29 CORBA::ORB_init (argc, argv);
31 CORBA::Object_var object =
32 orb->resolve_initial_references ("RTORB");
34 RTCORBA::RTORB_var rtorb =
35 RTCORBA::RTORB::_narrow (object.in ());
38 * The following code should be reenabled once the OMG spec has
39 * been fixed such that a RTCORBA::PriorityModelPolicy can be
40 * created by using the ORB::create_policy interface.
43 RTCORBA::PriorityModelPolicy_var policy1 =
44 rtorb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED,
45 RTCORBA::minPriority);
47 CORBA::Any policy_value;
48 policy_value <<= RTCORBA::CLIENT_PROPAGATED;
49 policy_value <<= RTCORBA::minPriority;
51 CORBA::Policy_var policy =
52 orb->create_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
53 policy_value);
55 RTCORBA::PriorityModelPolicy_var policy2 =
56 RTCORBA::PriorityModelPolicy::_narrow (policy.in ());
58 ACE_ASSERT (policy1->priority_model () == policy2->priority_model ());
59 ACE_ASSERT (policy1->server_priority () == policy2->server_priority ());
65 RTCORBA::ThreadpoolId poolid = 0;
67 RTCORBA::ThreadpoolPolicy_var policy1 =
68 rtorb->create_threadpool_policy (poolid);
70 CORBA::Any policy_value;
71 policy_value <<= poolid;
73 CORBA::Policy_var policy =
74 orb->create_policy (RTCORBA::THREADPOOL_POLICY_TYPE,
75 policy_value);
77 RTCORBA::ThreadpoolPolicy_var policy2 =
78 RTCORBA::ThreadpoolPolicy::_narrow (policy.in ());
80 ACE_ASSERT (policy1->threadpool () == policy2->threadpool ());
84 RTCORBA::ProtocolList empty_protocols;
86 RTCORBA::ServerProtocolPolicy_var policy1 =
87 rtorb->create_server_protocol_policy (empty_protocols);
89 CORBA::Any policy_value;
90 policy_value <<= empty_protocols;
92 CORBA::Policy_var policy =
93 orb->create_policy (RTCORBA::SERVER_PROTOCOL_POLICY_TYPE,
94 policy_value);
96 RTCORBA::ServerProtocolPolicy_var policy2 =
97 RTCORBA::ServerProtocolPolicy::_narrow (policy.in ());
99 RTCORBA::ProtocolList_var protocols1 =
100 policy1->protocols ();
101 RTCORBA::ProtocolList_var protocols2 =
102 policy2->protocols ();
104 ACE_ASSERT (protocols1->length () == protocols2->length ());
108 RTCORBA::ProtocolList empty_protocols;
110 RTCORBA::ClientProtocolPolicy_var policy1 =
111 rtorb->create_client_protocol_policy (empty_protocols);
113 CORBA::Any policy_value;
114 policy_value <<= empty_protocols;
116 CORBA::Policy_var policy =
117 orb->create_policy (RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
118 policy_value);
120 RTCORBA::ClientProtocolPolicy_var policy2 =
121 RTCORBA::ClientProtocolPolicy::_narrow (policy.in ());
123 RTCORBA::ProtocolList_var protocols1 =
124 policy1->protocols ();
125 RTCORBA::ProtocolList_var protocols2 =
126 policy2->protocols ();
128 ACE_ASSERT (protocols1->length () == protocols2->length ());
132 RTCORBA::PrivateConnectionPolicy_var policy1 =
133 rtorb->create_private_connection_policy ();
135 CORBA::Any policy_value;
137 CORBA::Policy_var policy =
138 orb->create_policy (RTCORBA::PRIVATE_CONNECTION_POLICY_TYPE,
139 policy_value);
141 RTCORBA::PrivateConnectionPolicy_var policy2 =
142 RTCORBA::PrivateConnectionPolicy::_narrow (policy.in ());
146 RTCORBA::PriorityBands empty_priority_bands;
148 RTCORBA::PriorityBandedConnectionPolicy_var policy1 =
149 rtorb->create_priority_banded_connection_policy (empty_priority_bands);
151 CORBA::Any policy_value;
152 policy_value <<= empty_priority_bands;
154 CORBA::Policy_var policy =
155 orb->create_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE,
156 policy_value);
158 RTCORBA::PriorityBandedConnectionPolicy_var policy2 =
159 RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy.in ());
161 RTCORBA::PriorityBands_var priority_bands1 =
162 policy1->priority_bands ();
163 RTCORBA::PriorityBands_var priority_bands2 =
164 policy2->priority_bands ();
166 ACE_ASSERT (priority_bands1->length () == priority_bands2->length ());
169 ACE_DEBUG ((LM_DEBUG,
170 "%s successful\n",
171 argv[0]));
173 orb->destroy ();
175 catch (const CORBA::Exception& ex)
177 ex._tao_print_exception ("Exception caught");
178 return -1;
181 return 0;