1 //========================================================================
5 * This program tests the basic functionality of the IORManipulation
10 //=========================================================================
12 #include "ace/Log_Msg.h"
14 #include "tao/Environment.h"
15 #include "tao/IORManipulation/IORManip_Loader.h"
18 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
22 ACE_DEBUG ((LM_DEBUG
, "---------------------------------------------\n"));
23 ACE_DEBUG ((LM_DEBUG
, "Running the IORManipulation Tests.\n"));
28 CORBA::ORB_var orb_
= CORBA::ORB_init (argc
,
31 // **********************************************************************
33 // Get an object reference for the ORBs IORManipulation object!
34 CORBA::Object_var IORM
=
35 orb_
->resolve_initial_references ("IORManipulation");
37 TAO_IOP::TAO_IOR_Manipulation_var iorm
=
38 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in ());
40 // **********************************************************************
42 // Create a few fictitious IORs
43 CORBA::Object_var name1
=
44 orb_
->string_to_object ("corbaloc:iiop:macarena.cs.wustl.edu:6060/xyz");
45 CORBA::Object_var name2
=
46 orb_
->string_to_object ("corbaloc:iiop:tango.cs.wustl.edu:7070/xyz");
48 // **********************************************************************
50 CORBA::String_var name1_ior
=
51 orb_
->object_to_string (name1
.in ());
52 ACE_DEBUG ((LM_DEBUG
, "\tFirst made up IOR = %C\n", name1_ior
.in ()));
54 CORBA::String_var name2_ior
=
55 orb_
->object_to_string (name2
.in ());
56 ACE_DEBUG ((LM_DEBUG
, "\tSecond made up IOR = %C\n", name2_ior
.in ()));
58 // **********************************************************************
60 // Create IOR list for use with merge_iors.
61 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (2);
66 CORBA::Object_var merged
= iorm
->merge_iors (iors
);
68 CORBA::String_var merged_ior
=
69 orb_
->object_to_string (merged
.in ());
71 CORBA::ULong count1
= iorm
->get_profile_count (iors
[0]);
73 CORBA::ULong count2
= iorm
->get_profile_count (iors
[1]);
75 CORBA::ULong count
= iorm
->get_profile_count (merged
.in ());
77 if (count
!= (count1
+ count2
))
79 "**ERROR (merge_profiles): "
80 "Merged profile count incorrect!\n"));
82 ACE_DEBUG ((LM_DEBUG
, "\tMerged IOR(%d) = %C\n",
86 // is_in_ior throws an exception if the intersection of the two
88 CORBA::ULong in_count
= iorm
->is_in_ior (merged
.in (),
91 if (count1
!= in_count
)
93 "**ERROR (merge_iors): name1 is_in_ior returned profile "
97 in_count
= iorm
->is_in_ior (merged
.in (),
100 if (count2
!= in_count
)
101 ACE_DEBUG ((LM_ERROR
,
102 "**ERROR (merge_iors): name2 is_in_ior returned profile "
106 // **********************************************************************
108 // Verify ability to remove profiles from an IOR
109 // First remove the second IOR from the merged IOR
110 CORBA::Object_var just1
=
111 iorm
->remove_profiles (merged
.in (), name2
.in ());
113 CORBA::String_var just1_ior
=
114 orb_
->object_to_string (just1
.in ());
116 count
= iorm
->get_profile_count (just1
.in ());
119 ACE_DEBUG ((LM_ERROR
,
120 "**ERROR (merge_profiles): "
121 "removing last IOR after a merge_iors ()\n"));
123 ACE_DEBUG ((LM_DEBUG
,
124 "\tJust 1 IOR(%d) = %C\n",
128 in_count
= iorm
->is_in_ior (just1
.in (), name1
.in ());
130 if (count1
!= in_count
)
131 ACE_DEBUG ((LM_ERROR
,
132 "**ERROR (merge_profiles): incorrect count returned for "
134 "\nafter removal (%d)\n",
136 // **********************************************************************
138 // Now try the add_profiles interface.
139 CORBA::Object_var merged2
=
140 iorm
->add_profiles (just1
.in (), name2
.in ());
142 count
= iorm
->get_profile_count (merged2
.in ());
144 if (count
!= (count1
+ count2
))
145 ACE_DEBUG ((LM_ERROR
,
146 "**ERROR: add_profile failed profile count test!\n"));
148 CORBA::String_var merged2_ior
=
149 orb_
->object_to_string (merged2
.in ());
151 ACE_DEBUG ((LM_DEBUG
,
152 "\tAdding 2 back in IOR(%d) = %C\n",
156 // is_in_ior throws an exception if the intersection of the two
158 in_count
= iorm
->is_in_ior (merged2
.in (), name1
. in ());
160 if (count1
!= in_count
)
161 ACE_DEBUG ((LM_ERROR
,
162 "**ERROR (add_profiles): is_in_ior returned profile "
166 in_count
= iorm
->is_in_ior (merged2
.in (), name2
.in ());
168 if (count2
!= in_count
)
169 ACE_DEBUG ((LM_ERROR
,
170 "**ERROR (add_profiles): is_in_ior returned "
171 "profile count bad!\n"));
173 // **********************************************************************
175 CORBA::Object_var just2
=
176 iorm
->remove_profiles (merged2
.in (), name1
.in ());
178 CORBA::String_var just2_ior
=
179 orb_
->object_to_string (just2
.in ());
181 count
= iorm
->get_profile_count (just2
.in ());
184 ACE_DEBUG ((LM_ERROR
,
185 "ERROR removing last IOR after a merge_iors ()\n"));
187 ACE_DEBUG ((LM_DEBUG
, "\tJust 2 IOR(%d) = %C\n",
191 in_count
= iorm
->is_in_ior (just2
.in (), name2
.in ());
193 if (count2
!= in_count
)
194 ACE_DEBUG ((LM_ERROR
,
195 "**ERROR (add_profiles): incorrect count (%d) "
196 "returned for is_in_ior after removal\n",
199 // all the primary tests worked, set status to 1
201 // Finally generate an exception and quit.
202 // This will generate a NotFound exception.
203 in_count
= iorm
->is_in_ior (just2
.in (), name1
.in ());
205 catch (const TAO_IOP::EmptyProfileList
& userex
)
207 userex
._tao_print_exception ("Unexpected EmptyProfileList Exception!\n");
210 catch (const TAO_IOP::NotFound
& userex
)
216 // @@ Don't use ACE_PRINT_EXCEPTION here since it will print
217 // "EXCEPTION" somewhere in the output which will make
218 // our auto-compile/test scripts think that an unexpected
219 // exception occurred. Instead, simply print the
222 ACE_DEBUG ((LM_DEBUG
,
223 "Caught <TAO_IOP::TAO_IOR_Manipulation::NotFound> exception.\n"
224 "This exception was expected.\n\n"));
228 userex
._tao_print_exception ("Unexpected NotFound Exception!\n");
232 catch (const TAO_IOP::Duplicate
& userex
)
234 userex
._tao_print_exception ("Unexpected Duplicate Exception!\n");
237 catch (const TAO_IOP::Invalid_IOR
& userex
)
239 userex
._tao_print_exception ("Unexpected Invalid_IOR Exception!\n");
242 catch (const CORBA::SystemException
& sysex
)
244 sysex
._tao_print_exception ("Unexpected system Exception!!\n");
247 catch (const CORBA::Exception
& ex
)
249 ex
._tao_print_exception ("Unexpected CORBA Exception!\n");
255 // then exception didn't work!
256 ACE_DEBUG ((LM_ERROR
,
257 "**ERROR: Unable to generate the NotFound exception!\n"));
262 ACE_DEBUG ((LM_DEBUG
, "An ERROR occurred during the tests!\n"));
266 ACE_DEBUG ((LM_DEBUG
, "IORManipulation Tests Successfully Completed!\n"));
267 ACE_DEBUG ((LM_DEBUG
, "---------------------------------------------\n"));