Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / IORManipulation / IORTest.cpp
blob0ae36756d03bae0d3fba8175d9784b27cd467df8
1 //========================================================================
2 /**
3 * @file IORTest.cpp
5 * This program tests the basic functionality of the IORManipulation
6 * interface.
8 * @author Fred Kuhns
9 */
10 //=========================================================================
12 #include "ace/Log_Msg.h"
13 #include "tao/ORB.h"
14 #include "tao/Environment.h"
15 #include "tao/IORManipulation/IORManip_Loader.h"
17 int
18 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
20 int Status = 0;
22 ACE_DEBUG ((LM_DEBUG, "---------------------------------------------\n"));
23 ACE_DEBUG ((LM_DEBUG, "Running the IORManipulation Tests.\n"));
25 try
27 // Retrieve the ORB.
28 CORBA::ORB_var orb_ = CORBA::ORB_init (argc,
29 argv);
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);
62 iors.length (2);
63 iors [0] = name1;
64 iors [1] = name2;
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))
78 ACE_DEBUG ((LM_ERROR,
79 "**ERROR (merge_profiles): "
80 "Merged profile count incorrect!\n"));
82 ACE_DEBUG ((LM_DEBUG, "\tMerged IOR(%d) = %C\n",
83 count,
84 merged_ior.in ()));
86 // is_in_ior throws an exception if the intersection of the two
87 // IORs is NULL.
88 CORBA::ULong in_count = iorm->is_in_ior (merged.in (),
89 name1.in ());
91 if (count1 != in_count)
92 ACE_DEBUG ((LM_ERROR,
93 "**ERROR (merge_iors): name1 is_in_ior returned profile "
94 "count bad (%d)!\n",
95 in_count));
97 in_count = iorm->is_in_ior (merged.in (),
98 name2.in ());
100 if (count2 != in_count)
101 ACE_DEBUG ((LM_ERROR,
102 "**ERROR (merge_iors): name2 is_in_ior returned profile "
103 "count bad (%d)!\n",
104 in_count));
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 ());
118 if (count1 != count)
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",
125 count,
126 just1_ior.in ()));
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 "
133 "is_in_ior"
134 "\nafter removal (%d)\n",
135 in_count));
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",
153 count,
154 merged2_ior.in ()));
156 // is_in_ior throws an exception if the intersection of the two
157 // IORs is NULL.
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 "
163 "count bad (%d)!\n",
164 in_count));
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 ());
183 if (count2 != count)
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",
188 count,
189 just2_ior.in ()));
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",
197 in_count));
199 // all the primary tests worked, set status to 1
200 Status = 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");
208 return -1;
210 catch (const TAO_IOP::NotFound& userex)
212 if (Status == 1)
214 Status = 2;
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
220 // exception ID.
221 // -Ossama
222 ACE_DEBUG ((LM_DEBUG,
223 "Caught <TAO_IOP::TAO_IOR_Manipulation::NotFound> exception.\n"
224 "This exception was expected.\n\n"));
226 else
228 userex._tao_print_exception ("Unexpected NotFound Exception!\n");
229 return -1;
232 catch (const TAO_IOP::Duplicate& userex)
234 userex._tao_print_exception ("Unexpected Duplicate Exception!\n");
235 return -1;
237 catch (const TAO_IOP::Invalid_IOR& userex)
239 userex._tao_print_exception ("Unexpected Invalid_IOR Exception!\n");
240 return -1;
242 catch (const CORBA::SystemException& sysex)
244 sysex._tao_print_exception ("Unexpected system Exception!!\n");
245 return -1;
247 catch (const CORBA::Exception& ex)
249 ex._tao_print_exception ("Unexpected CORBA Exception!\n");
250 return -1;
253 if (Status == 1)
255 // then exception didn't work!
256 ACE_DEBUG ((LM_ERROR,
257 "**ERROR: Unable to generate the NotFound exception!\n"));
258 Status = 0;
260 if (Status == 0)
262 ACE_DEBUG ((LM_DEBUG, "An ERROR occurred during the tests!\n"));
263 return -1;
265 else
266 ACE_DEBUG ((LM_DEBUG, "IORManipulation Tests Successfully Completed!\n"));
267 ACE_DEBUG ((LM_DEBUG, "---------------------------------------------\n"));
269 return 0;