1 //========================================================================
5 * This program tests the basic functionality of the TAO_Stub in case
8 * @author Frank Rehberger
10 //=========================================================================
13 #include "ace/Log_Msg.h"
14 #include "ace/OS_NS_string.h"
16 #include "tao/Environment.h"
17 #include "tao/SystemException.h"
18 #include "tao/Object.h"
20 #include "tao/Profile.h"
21 #include "tao/IIOP_Profile.h"
24 #define FRANKS_ASSERT(X) \
26 ? static_cast<void>(0) \
27 : ACE_VERSIONED_NAMESPACE_NAME::__ace_assert(__FILE__, __LINE__, ACE_TEXT_CHAR_TO_TCHAR (#X)))
31 is_endpoint (TAO_Profile
*profile
, const char *host
, unsigned short port
)
33 TAO_IIOP_Profile
*iiop
= dynamic_cast<TAO_IIOP_Profile
*> (profile
);
34 TAO_Endpoint
*endpoint
= iiop
->endpoint ();
35 TAO_IIOP_Endpoint
*iiop_endpoint
= dynamic_cast<TAO_IIOP_Endpoint
*> (endpoint
);
36 const char * endpoint_host
= iiop_endpoint
->host();
37 unsigned short endpoint_port
= iiop_endpoint
->port();
40 ACE_OS::strcmp (endpoint_host
, host
)==0
41 && endpoint_port
== port
;
47 equal_endpoint (TAO_Profile
*profile
, TAO_Profile
*other
)
49 TAO_IIOP_Profile
*iiop
= dynamic_cast<TAO_IIOP_Profile
*> (profile
);
50 TAO_Endpoint
*endpoint
= iiop
->endpoint ();
51 TAO_IIOP_Endpoint
*iiop_endpoint
= dynamic_cast<TAO_IIOP_Endpoint
*> (endpoint
);
52 const char * endpoint_host
= iiop_endpoint
->host();
53 unsigned short endpoint_port
= iiop_endpoint
->port();
55 TAO_IIOP_Profile
*other_iiop
= dynamic_cast<TAO_IIOP_Profile
*> (other
);
56 TAO_Endpoint
*other_endpoint
= other_iiop
->endpoint ();
57 TAO_IIOP_Endpoint
*other_iiop_endpoint
= dynamic_cast<TAO_IIOP_Endpoint
*> (other_endpoint
);
58 const char * other_endpoint_host
= other_iiop_endpoint
->host();
59 unsigned short other_endpoint_port
= other_iiop_endpoint
->port();
62 ACE_OS::strcmp (endpoint_host
, other_endpoint_host
)==0
63 && endpoint_port
== other_endpoint_port
;
69 marshaled_equal_to_other (CORBA::ORB_ptr orb
, CORBA::Object_ptr obj
, TAO_MProfile
*other_mprofile
)
71 CORBA::String_var str
= orb
->object_to_string (obj
);
73 CORBA::Object_var obj_copy
= orb
->string_to_object (str
.in ());
75 TAO_Stub
*stub_copy
= obj_copy
->_stubobj ();
76 TAO_MProfile
*copy_mprofile
= &(stub_copy
->base_profiles ());
78 if (copy_mprofile
->size() != other_mprofile
->size())
81 for (size_t i
=0; i
<copy_mprofile
->size(); ++i
)
83 TAO_Profile
*copy_profile
= copy_mprofile
->get_profile (i
);
84 TAO_Profile
*other_profile
= other_mprofile
->get_profile (i
);
86 if (! equal_endpoint (copy_profile
, other_profile
) )
94 test_forward_permanent (CORBA::ORB_ptr orb
)
96 CORBA::Object_var obj1
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:1111,iiop:192.168.1.3:1111/NameService");
98 // the permanent profile
99 CORBA::Object_var obj4
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:4444,iiop:192.168.1.3:4444/NameService");
101 TAO_Stub
*stub1
= obj1
->_stubobj ();
102 TAO_Stub
*stub4
= obj4
->_stubobj ();
104 TAO_Profile
*profile
= 0;
106 profile
= stub1
->profile_in_use ();
108 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 1111));
110 // ----- forward to obj2 permanently
111 stub1
->add_forward_profiles (stub4
->base_profiles(), true /* permanent */);
113 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
115 profile
= stub1
->next_profile ();
117 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 4444));
119 // ----- stringified object reference must be equal to obj4->base_prpfiles().
120 FRANKS_ASSERT (marshaled_equal_to_other (orb
, obj1
.in (), &(stub4
->base_profiles())));
122 // ----- consume second profile of obj2
124 profile
= stub1
->next_profile ();
126 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.3", 4444));
129 // ----- reached end, next_profile() must yield NULL
131 profile
= stub1
->next_profile ();
133 FRANKS_ASSERT (profile
== 0);
135 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
139 test_forward_permanent_mix (CORBA::ORB_ptr orb
)
141 CORBA::Object_var obj1
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:1111,iiop:192.168.1.3:1111/NameService");
143 CORBA::Object_var obj2
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:2222,iiop:192.168.1.3:2222/NameService");
145 CORBA::Object_var obj3
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:3333,iiop:192.168.1.3:3333/NameService");
147 CORBA::Object_var obj4
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:4444,iiop:192.168.1.3:4444/NameService");
149 CORBA::Object_var obj5
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:5555,iiop:192.168.1.3:5555/NameService");
151 TAO_Stub
*stub1
= obj1
->_stubobj ();
152 TAO_Stub
*stub2
= obj2
->_stubobj ();
153 TAO_Stub
*stub3
= obj3
->_stubobj ();
154 TAO_Stub
*stub4
= obj4
->_stubobj ();
155 TAO_Stub
*stub5
= obj5
->_stubobj ();
157 TAO_Profile
*profile
= 0;
159 profile
= stub1
->profile_in_use ();
161 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 1111));
163 // ----- forward to obj2
164 stub1
->add_forward_profiles (stub2
->base_profiles(), false /* permanent */);
166 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
168 profile
= stub1
->next_profile ();
170 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 2222));
172 // ----- forward to obj3
173 stub1
->add_forward_profiles (stub3
->base_profiles(), false /* permanent */);
175 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
177 profile
= stub1
->next_profile ();
179 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 3333));
181 // ----- stringified object reference must be equal to obj1->base_prpfiles().
182 FRANKS_ASSERT (marshaled_equal_to_other (orb
, obj1
.in (), &(stub1
->base_profiles())));
184 // ----- forward to obj4 permanently
185 stub1
->add_forward_profiles (stub4
->base_profiles(), true /* permanent */);
187 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
189 profile
= stub1
->next_profile ();
191 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 4444));
193 // ----- stringified object reference must be equal to obj4->base_prpfiles().
194 FRANKS_ASSERT (marshaled_equal_to_other (orb
, obj1
.in (), &(stub4
->base_profiles())));
196 // ----- consume second profile from obj4
197 profile
= stub1
->next_profile ();
199 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.3", 4444));
201 // ----- forward to obj2
202 stub1
->add_forward_profiles (stub2
->base_profiles(), false /* permanent */);
204 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
206 profile
= stub1
->next_profile ();
208 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 2222));
210 // ----- forward to obj3
211 stub1
->add_forward_profiles (stub3
->base_profiles(), false /* permanent */);
213 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
215 profile
= stub1
->next_profile ();
217 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 3333));
219 // ----- stringified object reference must be equal to obj4->base_prpfiles().
220 FRANKS_ASSERT (marshaled_equal_to_other (orb
, obj1
.in (), &(stub4
->base_profiles())));
222 // ----- forward to obj5 permanently
223 stub1
->add_forward_profiles (stub5
->base_profiles(), true /* permanent */);
225 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
227 profile
= stub1
->next_profile ();
229 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 5555));
231 // ----- stringified object reference must be equal to obj5->base_prpfiles().
232 FRANKS_ASSERT (marshaled_equal_to_other (orb
, obj1
.in (), &(stub5
->base_profiles())));
234 // ----- consume second profile from obj5
235 profile
= stub1
->next_profile ();
237 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.3", 5555));
239 // ----- stringified object reference must be equal to obj1->base_prpfiles().
240 FRANKS_ASSERT (marshaled_equal_to_other (orb
, obj1
.in (), &(stub5
->base_profiles())));
242 // reached end of profiles, next_profile must return NULL
244 profile
= stub1
->next_profile ();
246 FRANKS_ASSERT (profile
== 0);
250 test_forward (CORBA::ORB_ptr orb
)
252 CORBA::Object_var obj1
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:1111,iiop:192.168.1.3:1111/NameService");
254 CORBA::Object_var obj2
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:2222,iiop:192.168.1.3:2222/NameService");
256 CORBA::Object_var obj3
= orb
->string_to_object ("corbaloc:iiop:192.168.1.2:3333,iiop:192.168.1.3:3333/NameService");
258 TAO_Stub
*stub1
= obj1
->_stubobj ();
259 TAO_Stub
*stub2
= obj2
->_stubobj ();
260 TAO_Stub
*stub3
= obj3
->_stubobj ();
262 TAO_Profile
*profile
= 0;
264 profile
= stub1
->profile_in_use ();
266 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 1111));
268 // ----- forward to obj2
269 stub1
->add_forward_profiles (stub2
->base_profiles(), false /* permanent */);
271 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
273 profile
= stub1
->next_profile ();
275 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 2222));
277 // ----- forward to obj3
279 stub1
->add_forward_profiles (stub3
->base_profiles(), false /* permanent */);
281 FRANKS_ASSERT (stub1
->forward_profiles () != 0);
283 profile
= stub1
->next_profile ();
285 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.2", 3333));
287 // ----- stringified object reference must be equal to obj1->base_prpfiles().
288 FRANKS_ASSERT (marshaled_equal_to_other (orb
, obj1
.in (), &(stub1
->base_profiles())));
290 // ----- consume second profile of obj3
292 profile
= stub1
->next_profile ();
294 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.3", 3333));
296 // ----- consume second profile of obj2
298 profile
= stub1
->next_profile ();
300 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.3", 2222));
302 // ----- consume second profile of obj1
304 profile
= stub1
->next_profile ();
306 FRANKS_ASSERT (is_endpoint (profile
, "192.168.1.3", 1111));
308 FRANKS_ASSERT (stub1
->forward_profiles () == 0);
310 // ----- reached end, next_profile() must yield NULL
312 profile
= stub1
->next_profile ();
316 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
318 ACE_DEBUG ((LM_DEBUG
, "---------------------------------------------\n"));
319 ACE_DEBUG ((LM_DEBUG
, "Running the Stub Tests.\n"));
324 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
327 test_forward (orb
.in());
328 test_forward_permanent (orb
.in());
329 test_forward_permanent_mix (orb
.in());
331 catch (const CORBA::SystemException
& sysex
)
333 sysex
._tao_print_exception ("Unexpected system Exception!!\n");
336 catch (const CORBA::Exception
& ex
)
338 ex
._tao_print_exception ("Unexpected CORBA Exception!\n");
342 ACE_DEBUG ((LM_DEBUG
, "Stub Tests Successfully Completed!\n"));
343 ACE_DEBUG ((LM_DEBUG
, "---------------------------------------------\n"));