2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "tao/Strategies/advanced_resource.h"
5 #include "tao/RTCORBA/RTCORBA.h"
6 #include "tao/Policy_ManagerC.h"
7 #include "tao/Policy_CurrentC.h"
9 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior
= get_opts
.opt_arg ();
25 ACE_ERROR_RETURN ((LM_ERROR
,
37 check_for_nil (CORBA::Object_ptr obj
, const char *msg
)
39 if (CORBA::is_nil (obj
))
40 ACE_ERROR_RETURN ((LM_ERROR
,
41 "ERROR: Object reference <%C> is nil\n",
49 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
53 // Initialize the ORB, parse arguments, and resolve references.
57 CORBA::ORB_init (argc
, argv
);
60 if (parse_args (argc
, argv
) != 0)
64 CORBA::Object_var object
=
65 orb
->resolve_initial_references ("RTORB");
66 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
67 if (check_for_nil (rt_orb
.in (), "RTORB") == -1)
71 object
= orb
->resolve_initial_references ("PolicyCurrent");
72 CORBA::PolicyCurrent_var policy_current
=
73 CORBA::PolicyCurrent::_narrow (object
.in ());
74 if (check_for_nil (policy_current
.in (), "PolicyCurrent")
79 object
= orb
->string_to_object (ior
);
80 Test_var server
= Test::_narrow (object
.in ());
81 if (check_for_nil (server
.in (), "server") == -1)
84 // Test 1: Check that <validate_connection> establishes an
85 // appropriate connection for the current set of effective
87 // Set ClientProtocolPolicy override to SHMIOP, and invoke
88 // <validate_connection> on the object. This should succeed, and
89 // SHMIOP connection should get established.
90 RTCORBA::ProtocolList protocols
;
92 protocols
[0].protocol_type
= TAO_TAG_SHMEM_PROFILE
;
93 protocols
[0].transport_protocol_properties
=
94 RTCORBA::ProtocolProperties::_nil ();
95 protocols
[0].orb_protocol_properties
=
96 RTCORBA::ProtocolProperties::_nil ();
98 CORBA::PolicyList policy_list
;
99 policy_list
.length (1);
101 rt_orb
->create_client_protocol_policy (protocols
);
103 policy_current
->set_policy_overrides (policy_list
,
104 CORBA::SET_OVERRIDE
);
106 ACE_DEBUG ((LM_DEBUG
,
109 CORBA::PolicyList_var pols
;
110 int status
= server
->_validate_connection (pols
.out ());
113 ACE_DEBUG ((LM_DEBUG
,
114 "ERROR: <validate_connection> returned FALSE\n"));
116 // Test 2: Check that connection established with
117 // <validate_connection> is used for subsequent invocations.
118 // Invoke <test_method> on the object. This should succeed and
119 // NO new connections should get established.
120 ACE_DEBUG ((LM_DEBUG
,
122 server
->test_method ();
124 // Test 3: Check that <validate_connection> detects policy
125 // misconfigurations and reports them through
126 // <inconsistent_policies> argument.
127 // Set ClientProtocolPolicy override to UIOP, call
128 // <validate_connection>. It should return FALSE, and
129 // <inconsistent_policies> should contain the problematic
131 ACE_DEBUG ((LM_DEBUG
,
134 protocols
[0].protocol_type
= TAO_TAG_UIOP_PROFILE
;
136 rt_orb
->create_client_protocol_policy (protocols
);
138 policy_current
->set_policy_overrides (policy_list
,
139 CORBA::SET_OVERRIDE
);
141 status
= server
->_validate_connection (pols
.out ());
144 ACE_DEBUG ((LM_DEBUG
,
145 ACE_TEXT ("<validate_connection> returned TRUE\n")));
148 // This portion of code has been temporarily disabled.
152 && pols->length () == 1
153 && pols[0u]->policy_type () == RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE)
154 ACE_DEBUG ((LM_DEBUG,
155 "Inconsistent policies contain "
156 "ClientProtocolPolicy, as expected.\n"));
158 ACE_DEBUG ((LM_DEBUG,
159 "ERROR: Inconsistent policies do not "
160 "contain what's expected.\n"));
163 // Testing over. Shut down Server ORB.
164 protocols
[0].protocol_type
= TAO_TAG_SHMEM_PROFILE
;
166 rt_orb
->create_client_protocol_policy (protocols
);
168 policy_current
->set_policy_overrides (policy_list
,
169 CORBA::SET_OVERRIDE
);
171 ACE_DEBUG ((LM_DEBUG
,
172 "\n Testing over - shutting down\n"));
178 catch (const CORBA::Exception
& ex
)
180 ex
._tao_print_exception (
181 "Unexpected exception caught in Explicit_Binding test client:");