=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / RTCORBA / Explicit_Binding / client.cpp
blob50c3d9ed8a44d024960f3e44e483b9ffbc1668ae
1 #include "testC.h"
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");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior = get_opts.opt_arg ();
22 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-o <ior> "
28 "\n",
29 argv [0]),
30 -1);
33 return 0;
36 int
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",
42 msg),
43 -1);
44 else
45 return 0;
48 int
49 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
51 try
53 // Initialize the ORB, parse arguments, and resolve references.
55 // ORB.
56 CORBA::ORB_var orb =
57 CORBA::ORB_init (argc, argv);
59 // Parse arguments.
60 if (parse_args (argc, argv) != 0)
61 return -1;
63 // RTORB.
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)
68 return -1;
70 // PolicyCurrent.
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")
75 == -1)
76 return -1;
78 // Test object.
79 object = orb->string_to_object (ior);
80 Test_var server = Test::_narrow (object.in ());
81 if (check_for_nil (server.in (), "server") == -1)
82 return -1;
84 // Test 1: Check that <validate_connection> establishes an
85 // appropriate connection for the current set of effective
86 // policies.
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;
91 protocols.length (1);
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);
100 policy_list[0] =
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,
107 "\n Test 1\n"));
109 CORBA::PolicyList_var pols;
110 int status = server->_validate_connection (pols.out ());
112 if (!status)
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,
121 "\n Test 2\n"));
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
130 // override.
131 ACE_DEBUG ((LM_DEBUG,
132 "\n Test 3\n"));
134 protocols[0].protocol_type = TAO_TAG_UIOP_PROFILE;
135 policy_list[0] =
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 ());
143 if (status)
144 ACE_DEBUG ((LM_DEBUG,
145 ACE_TEXT ("<validate_connection> returned TRUE\n")));
148 // This portion of code has been temporarily disabled.
151 if (pols.ptr () != 0
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"));
157 else
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;
165 policy_list[0] =
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"));
173 ACE_OS::sleep (2);
174 server->shutdown ();
176 ACE_OS::sleep (2);
178 catch (const CORBA::Exception& ex)
180 ex._tao_print_exception (
181 "Unexpected exception caught in Explicit_Binding test client:");
182 return -1;
185 return 0;