2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "tao/RTCORBA/RTCORBA.h"
5 #include "tao/Policy_ManagerC.h"
6 #include "tao/Policy_CurrentC.h"
8 #include "tao/Strategies/advanced_resource.h"
10 const ACE_TCHAR
*ior1
= ACE_TEXT("file://test1.ior");
11 const ACE_TCHAR
*ior2
= ACE_TEXT("file://test2.ior");
12 CORBA::ULong protocol_type
= 0;
15 parse_args (int argc
, ACE_TCHAR
*argv
[])
17 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("s:c:p:"));
20 while ((c
= get_opts ()) != -1)
24 ior1
= get_opts
.opt_arg ();
27 ior2
= get_opts
.opt_arg ();
30 result
= ::sscanf (ACE_TEXT_ALWAYS_CHAR (get_opts
.opt_arg ()),
33 if (result
== 0 || result
== EOF
)
34 ACE_ERROR_RETURN ((LM_ERROR
,
35 "Unable to process <-p> option"),
40 ACE_ERROR_RETURN ((LM_ERROR
,
54 check_for_nil (CORBA::Object_ptr obj
, const char *msg
)
56 if (CORBA::is_nil (obj
))
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 "ERROR: Object reference <%C> is nil\n",
66 exception_test (Test_ptr server
,
71 server
->test_method ();
73 catch (const CORBA::INV_POLICY
& )
76 "INV_POLICY exception is caught as expected.\n"));
78 catch (const CORBA::Exception
&)
80 ACE_DEBUG ((LM_DEBUG
, msg
));
86 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
90 // Initialize the ORB, resolve references and parse arguments.
94 CORBA::ORB_init (argc
, argv
);
97 if (parse_args (argc
, argv
) != 0)
101 CORBA::Object_var object
=
102 orb
->resolve_initial_references ("RTORB");
103 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
104 if (check_for_nil (rt_orb
.in (), "RTORB") == -1)
108 object
= orb
->resolve_initial_references ("ORBPolicyManager");
109 CORBA::PolicyManager_var policy_manager
=
110 CORBA::PolicyManager::_narrow (object
.in ());
111 if (check_for_nil (policy_manager
.in (), "PolicyManager")
116 object
= orb
->resolve_initial_references ("PolicyCurrent");
117 CORBA::PolicyCurrent_var policy_current
=
118 CORBA::PolicyCurrent::_narrow (object
.in ());
119 if (check_for_nil (policy_current
.in (), "PolicyCurrent")
123 // Test object 1 (ClientProtocolPolicy set on server).
124 object
= orb
->string_to_object (ior1
);
125 Test_var server1
= Test::_narrow (object
.in ());
126 if (check_for_nil (server1
.in (), "server1") == -1)
129 // Test object 2 (no client-exposed ClientProtocolPolicy).
130 object
= orb
->string_to_object (ior2
);
131 Test_var server2
= Test::_narrow (object
.in ());
132 if (check_for_nil (server2
.in (), "server2") == -1)
137 // Test 1: Invoke operation on the object that has
138 // ClientProtocolPolicy set on the server side.
139 ACE_DEBUG ((LM_DEBUG
,
141 server1
->test_method ();
143 // Test 2: Set the ORB-level ClientProtocolPolicy override, and
144 // attempt the same invocation again. Should get
145 // CORBA::INV_POLICY exception since the policy is set on both
146 // client and server sides.
147 ACE_DEBUG ((LM_DEBUG
,
149 RTCORBA::ProtocolList protocols
;
150 protocols
.length (1);
151 protocols
[0].protocol_type
= protocol_type
;
152 protocols
[0].transport_protocol_properties
=
153 RTCORBA::ProtocolProperties::_nil ();
154 protocols
[0].orb_protocol_properties
=
155 RTCORBA::ProtocolProperties::_nil ();
157 CORBA::PolicyList policy_list
;
158 policy_list
.length (1);
160 rt_orb
->create_client_protocol_policy (protocols
);
162 policy_manager
->set_policy_overrides (policy_list
,
163 CORBA::SET_OVERRIDE
);
165 exception_test (server1
.in (),
166 "ERROR: Test 2 failed\n");
168 // Test 3: Attempt the invocation on the second object reference
169 // (the one that didn't have ClientProtocolPolicy set on the
170 // server side). This should succeed since there are no
172 ACE_DEBUG ((LM_DEBUG
,
174 server2
->test_method ();
176 // Test 4: Override ClientProtocolPolicy on the Current level.
177 // For the override value, use the sequence of protocols, none
178 // of which are available in the server ORB. Attempt an
179 // invocation on the second object. Should get
180 // CORBA::INV_POLICY exception since none of the protocols
181 // specified in the policy are available.
182 ACE_DEBUG ((LM_DEBUG
,
184 // Hardcode a sequence of nonexistent protocols.
185 protocols
.length (3);
186 protocols
[0].protocol_type
= 3;
187 protocols
[1].protocol_type
= 4;
188 protocols
[2].protocol_type
= 5;
190 rt_orb
->create_client_protocol_policy (protocols
);
192 policy_current
->set_policy_overrides (policy_list
,
193 CORBA::SET_OVERRIDE
);
195 exception_test (server2
.in (),
196 "ERROR: Test 4 failed\n");
198 // Test 5: Override ClientProtocolPolicy on the Current level
199 // again. This time use the sequence in which the first
200 // protocol isn't available and the second one is. The
201 // invocation should succeed through using the second protocol.
202 ACE_DEBUG ((LM_DEBUG
,
204 protocols
.length (2);
205 protocols
[0].protocol_type
= 3;
206 protocols
[1].protocol_type
= protocol_type
;
208 rt_orb
->create_client_protocol_policy (protocols
);
210 policy_current
->set_policy_overrides (policy_list
,
211 CORBA::SET_OVERRIDE
);
213 server2
->test_method ();
215 // Testing over. Shut down server ORB.
216 ACE_DEBUG ((LM_DEBUG
,
217 "\n Testing over\n"));
218 server2
->shutdown ();
220 // Needed for SHMIOP to work fine. Please dont remove. Please
221 // see Bug 1197 for details.
224 catch (const CORBA::Exception
& ex
)
226 ex
._tao_print_exception (
227 "Unexpected exception caught in ClientProtocolPolicy test client:");