Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_2234_Regression / client.cpp
blob427849d9a12d2035efcc00694c17399c722ccf16
1 // Regression test Bug 2234
2 //
3 // The bug manifests itself in the server.
5 #include "TestC.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_string.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("k:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-k <ior> "
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN (
39 int argc,
40 ACE_TCHAR *argv[])
42 CORBA::Boolean testFailed= 0;
43 ACE_DEBUG( (LM_INFO, "Regression test for Bug 2234 (Interceptor arg list with var len out params)\n"));
44 try
46 CORBA::ORB_var
47 orb= CORBA::ORB_init (argc, argv);
49 if (parse_args (argc, argv) != 0)
50 return 1;
52 CORBA::Object_var
53 object= orb->string_to_object(ior);
54 Test::Foo_var
55 foo= Test::Foo::_narrow( object.in());
57 //-----------------------------------------------------------------------
58 CORBA::Long
59 aL= 1,
60 bL,
61 cL= 3,
62 rL= 0;
63 ACE_DEBUG( (LM_INFO, ". Long() "));
64 rL= foo->TestLong( aL, bL, cL);
65 ACE_DEBUG( (LM_INFO, "a is %d, b is %d, c is %d, r is %d: ", aL, bL, cL, rL));
66 if (static_cast<CORBA::Long>(1) != aL) {
67 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
68 else if (static_cast<CORBA::Long>(2) != bL) {
69 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
70 else if (static_cast<CORBA::Long>(4) != cL) {
71 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
72 else if (static_cast<CORBA::Long>(7) != rL) {
73 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
74 else
75 ACE_DEBUG( (LM_INFO, "OK\n"));
77 //-----------------------------------------------------------------------
78 CORBA::String_var
79 aS= CORBA::string_dup("1"),
80 bS,
81 cS= CORBA::string_dup("3"),
82 rS;
83 ACE_DEBUG( (LM_INFO, ". String() "));
84 rS= foo->TestString( aS.in(), bS.out(), cS.inout());
85 ACE_DEBUG( (LM_INFO, "a is %C, b is %C, c is %C, r is %C: ", aS.in (), bS.in (), cS.in (), rS.in ()));
86 if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(aS.in(), "1"))) {
87 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
88 else if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(bS.in(), "2"))) {
89 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
90 else if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(cS.in(), "4"))) {
91 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
92 else if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(rS.in(), "7"))) {
93 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
94 else
95 ACE_DEBUG( (LM_INFO, "OK\n"));
97 //-----------------------------------------------------------------------
98 Test::MyNonVarStruct_var
99 aFS= new Test::MyNonVarStruct(),
100 bFS= new Test::MyNonVarStruct(),
101 cFS= new Test::MyNonVarStruct(),
102 rFS;
103 aFS->val= 1;
104 cFS->val= 3;
105 ACE_DEBUG( (LM_INFO, ". MyNonVarStruct() "));
106 rFS= foo->TestNonVarStruct( aFS.in(), bFS.out(), cFS.inout());
107 ACE_DEBUG( (LM_INFO, "a is %d, b is %d, c is %d, r is %d: ", aFS.in().val, bFS.in().val, cFS.in().val, rFS.in().val));
108 if (static_cast<CORBA::Long>(1) != aFS->val) {
109 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
110 else if (static_cast<CORBA::Long>(2) != bFS->val) {
111 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
112 else if (static_cast<CORBA::Long>(4) != cFS->val) {
113 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
114 else if (static_cast<CORBA::Long>(7) != rFS->val) {
115 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
116 else
117 ACE_DEBUG( (LM_INFO, "OK\n"));
119 //-----------------------------------------------------------------------
120 Test::MyVarStruct_var
121 aVS= new Test::MyVarStruct(),
122 bVS,
123 cVS= new Test::MyVarStruct(),
124 rVS;
125 aVS->val= CORBA::string_dup("1");
126 cVS->val= CORBA::string_dup("3");
127 ACE_DEBUG( (LM_INFO, ". MyVarStruct() "));
128 rVS= foo->TestVarStruct( aVS.in(), bVS.out(), cVS.inout());
129 ACE_DEBUG( (LM_INFO, "a is %C, b is %C, c is %C, r is %C: ", aVS->val.in(), bVS->val.in (), cVS->val.in (), rVS->val.in ()));
130 if ((0 != *aVS->val) && (0 != ACE_OS::strcmp(aVS->val, "1"))) {
131 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
132 else if ((0 != *bVS->val) && (0 != ACE_OS::strcmp(bVS->val, "2"))) {
133 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
134 else if ((0 != *cVS->val) && (0 != ACE_OS::strcmp(cVS->val, "4"))) {
135 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
136 else if ((0 != *rVS->val) && (0 != ACE_OS::strcmp(rVS->val, "7"))) {
137 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
138 else
139 ACE_DEBUG( (LM_INFO, "OK\n"));
141 //-----------------------------------------------------------------------
142 Test::MyNonVarUnion_var
143 aFU= new Test::MyNonVarUnion(),
144 bFU= new Test::MyNonVarUnion(),
145 cFU= new Test::MyNonVarUnion(),
146 rFU;
147 aFU->valLong( static_cast<CORBA::Long>(1));
148 cFU->valLong( static_cast<CORBA::Long>(3));
149 ACE_DEBUG( (LM_INFO, ". MyNonVarUnion() "));
150 rFU= foo->TestNonVarUnion( aFU.in(), bFU.out(), cFU.inout());
151 ACE_DEBUG( (LM_INFO, "a is "));
152 if (static_cast<CORBA::Short>(1) != aFU->_d())
153 ACE_DEBUG( (LM_INFO, "?"));
154 else
155 ACE_DEBUG( (LM_INFO, "%d", aFU->valLong()));
156 ACE_DEBUG( (LM_INFO, ", b is "));
157 if (static_cast<CORBA::Short>(1) != bFU->_d())
158 ACE_DEBUG( (LM_INFO, "?"));
159 else
160 ACE_DEBUG( (LM_INFO, "%d", bFU->valLong()));
161 ACE_DEBUG( (LM_INFO, ", c is "));
162 if (static_cast<CORBA::Short>(1) != cFU->_d())
163 ACE_DEBUG( (LM_INFO, "?"));
164 else
165 ACE_DEBUG( (LM_INFO, "%d", cFU->valLong()));
166 ACE_DEBUG( (LM_INFO, ", r is "));
167 if (static_cast<CORBA::Short>(1) != rFU->_d())
168 ACE_DEBUG( (LM_INFO, "?"));
169 else
170 ACE_DEBUG( (LM_INFO, "%d", rFU->valLong()));
171 ACE_DEBUG( (LM_INFO, ": "));
172 if ((static_cast<CORBA::Short>(1) != aFU->_d()) || (static_cast<CORBA::Long>(1) != aFU->valLong())) {
173 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
174 else if ((static_cast<CORBA::Short>(1) != bFU->_d()) || (static_cast<CORBA::Long>(2) != bFU->valLong())) {
175 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
176 else if ((static_cast<CORBA::Short>(1) != cFU->_d()) || (static_cast<CORBA::Long>(4) != cFU->valLong())) {
177 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
178 else if ((static_cast<CORBA::Short>(1) != rFU->_d()) || (static_cast<CORBA::Long>(7) != rFU->valLong())) {
179 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
180 else
181 ACE_DEBUG( (LM_INFO, "OK\n"));
183 //-----------------------------------------------------------------------
184 Test::MyVarUnion_var
185 aVU= new Test::MyVarUnion(),
186 bVU,
187 cVU= new Test::MyVarUnion(),
188 rVU;
189 aVU->valLong( static_cast<CORBA::Long>(1));
190 cVU->valLong( static_cast<CORBA::Long>(3));
191 ACE_DEBUG( (LM_INFO, ". MyVarUnion() "));
192 rVU= foo->TestVarUnion( aVU.in(), bVU.out(), cVU.inout());
193 ACE_DEBUG( (LM_INFO, "a is "));
194 if (static_cast<CORBA::Short>(1) != aVU->_d())
195 ACE_DEBUG( (LM_INFO, "?"));
196 else
197 ACE_DEBUG( (LM_INFO, "%d", aVU->valLong()));
198 ACE_DEBUG( (LM_INFO, ", b is "));
199 if (static_cast<CORBA::Short>(1) != bVU->_d())
200 ACE_DEBUG( (LM_INFO, "?"));
201 else
202 ACE_DEBUG( (LM_INFO, "%d", bVU->valLong()));
203 ACE_DEBUG( (LM_INFO, ", c is "));
204 if (static_cast<CORBA::Short>(1) != cVU->_d())
205 ACE_DEBUG( (LM_INFO, "?"));
206 else
207 ACE_DEBUG( (LM_INFO, "%d", cVU->valLong()));
208 ACE_DEBUG( (LM_INFO, ", r is "));
209 if (static_cast<CORBA::Short>(1) != rVU->_d())
210 ACE_DEBUG( (LM_INFO, "?"));
211 else
212 ACE_DEBUG( (LM_INFO, "%d", rVU->valLong()));
213 ACE_DEBUG( (LM_INFO, ": "));
214 if ((static_cast<CORBA::Short>(1) != aVU->_d()) || (static_cast<CORBA::Long>(1) != aVU->valLong())) {
215 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
216 else if ((static_cast<CORBA::Short>(1) != bVU->_d()) || (static_cast<CORBA::Long>(2) != bVU->valLong())) {
217 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
218 else if ((static_cast<CORBA::Short>(1) != cVU->_d()) || (static_cast<CORBA::Long>(4) != cVU->valLong())) {
219 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
220 else if ((static_cast<CORBA::Short>(1) != rVU->_d()) || (static_cast<CORBA::Long>(7) != rVU->valLong())) {
221 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
222 else
223 ACE_DEBUG( (LM_INFO, "OK\n"));
225 //-----------------------------------------------------------------------
226 Test::MySeqOfLong_var
227 aSL= new Test::MySeqOfLong(1),
228 bSL,
229 cSL= new Test::MySeqOfLong(1),
230 rSL;
231 aSL->length(1);
232 aSL[0]= static_cast<CORBA::Long>(1);
233 cSL->length(1);
234 cSL[0]= static_cast<CORBA::Long>(3);
235 ACE_DEBUG( (LM_INFO, ". MySeqOfLong() "));
236 rSL= foo->TestSeqOfLong( aSL.in(), bSL.out(), cSL.inout());
237 ACE_DEBUG( (LM_INFO, "a is "));
238 if (1u != aSL->length())
239 ACE_DEBUG( (LM_INFO, "?"));
240 else
241 ACE_DEBUG( (LM_INFO, "%d", aSL[0]));
242 ACE_DEBUG( (LM_INFO, ", b is "));
243 if (1u != bSL->length())
244 ACE_DEBUG( (LM_INFO, "?"));
245 else
246 ACE_DEBUG( (LM_INFO, "%d", bSL[0]));
247 ACE_DEBUG( (LM_INFO, ", c is "));
248 if (1u != cSL->length())
249 ACE_DEBUG( (LM_INFO, "?"));
250 else
251 ACE_DEBUG( (LM_INFO, "%d", cSL[0]));
252 ACE_DEBUG( (LM_INFO, ", r is "));
253 if (1u != rSL->length())
254 ACE_DEBUG( (LM_INFO, "?"));
255 else
256 ACE_DEBUG( (LM_INFO, "%d", rSL[0]));
257 ACE_DEBUG( (LM_INFO, ": "));
258 if ((1u != aSL->length()) || (static_cast<CORBA::Long>(1) != aSL[0])) {
259 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
260 else if ((1u != bSL->length()) || (static_cast<CORBA::Long>(2) != bSL[0])) {
261 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
262 else if ((1u != cSL->length()) || (static_cast<CORBA::Long>(4) != cSL[0])) {
263 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
264 else if ((1u != rSL->length()) || (static_cast<CORBA::Long>(7) != rSL[0])) {
265 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
266 else
267 ACE_DEBUG( (LM_INFO, "OK\n"));
269 //-----------------------------------------------------------------------
270 CORBA::Any_var
271 aA= new CORBA::Any(),
273 cA= new CORBA::Any(),
275 aA<<= static_cast<CORBA::Long>(1);
276 cA<<= static_cast<CORBA::Long>(3);
277 ACE_DEBUG( (LM_INFO, ". Any() "));
278 rA= foo->TestAny( aA.in(), bA.out(), cA.inout());
279 CORBA::Boolean
284 ACE_DEBUG( (LM_INFO, "a is "));
285 if (0 != (aB= (aA>>= aL)))
286 ACE_DEBUG( (LM_INFO, "%d", aL));
287 else
288 ACE_DEBUG( (LM_INFO, "?"));
289 ACE_DEBUG( (LM_INFO, ", b is "));
290 if (0 != (bB= (bA>>= bL)))
291 ACE_DEBUG( (LM_INFO, "%d", bL));
292 else
293 ACE_DEBUG( (LM_INFO, "?"));
294 ACE_DEBUG( (LM_INFO, ", c is "));
295 if (0 != (cB= (cA>>= cL)))
296 ACE_DEBUG( (LM_INFO, "%d", cL));
297 else
298 ACE_DEBUG( (LM_INFO, "?"));
299 ACE_DEBUG( (LM_INFO, ", r is "));
300 if (0 != (rB= (rA>>= rL)))
301 ACE_DEBUG( (LM_INFO, "%d", rL));
302 else
303 ACE_DEBUG( (LM_INFO, "?"));
304 ACE_DEBUG( (LM_INFO, ": "));
305 if (!aB || (static_cast<CORBA::Long>(1) != aL)) {
306 ACE_DEBUG( (LM_ERROR, "a is wrong\n")); testFailed= 1;}
307 else if (!bB || (static_cast<CORBA::Long>(2) != bL)) {
308 ACE_DEBUG( (LM_ERROR, "b is wrong\n")); testFailed= 1;}
309 else if (!cB || (static_cast<CORBA::Long>(4) != cL)) {
310 ACE_DEBUG( (LM_ERROR, "c is wrong\n")); testFailed= 1;}
311 else if (!rB || (static_cast<CORBA::Long>(7) != rL)) {
312 ACE_DEBUG( (LM_ERROR, "r is wrong\n")); testFailed= 1;}
313 else
314 ACE_DEBUG( (LM_INFO, "OK\n"));
316 //-----------------------------------------------------------------------
318 Test::MyArray arr_a;
319 arr_a[0].length (1);
320 arr_a[0][0] = 9;
321 arr_a[1].length (1);
322 arr_a[1][0] = 23;
324 Test::MyArray_var arr_b;
326 Test::MyArray arr_c;
327 arr_c[0].length (1);
328 arr_c[0][0] = 23;
329 arr_c[1].length (1);
330 arr_c[1][0] = 9;
332 ACE_DEBUG( (LM_INFO, ". MyArray() "));
333 Test::MyArray_var arr_ret = foo->TestArray (arr_a, arr_b.out (), arr_c);
334 CORBA::ULong zero (0), one (1); //Use ULong to avoid ambiguity
335 if (arr_c[0].length () != 1 || arr_c[0][0] != 24)
337 ACE_DEBUG( (LM_ERROR, "arr_c[0] is wrong\n")); testFailed = 1;
339 else if (arr_c[1].length () != 1 || arr_c[1][0] != 10)
341 ACE_DEBUG( (LM_ERROR, "arr_c[1] is wrong\n")); testFailed = 1;
343 else if (arr_b[zero].length () != 1 || arr_b[zero][0] != 8)
345 ACE_DEBUG( (LM_ERROR, "arr_b[0] is wrong\n")); testFailed = 1;
347 else if (arr_b[one].length () != 1 || arr_b[one][0] != 22)
349 ACE_DEBUG( (LM_ERROR, "arr_b[1] is wrong\n")); testFailed = 1;
351 else if (arr_ret[zero].length () != 1 || arr_ret[zero][0] != 7)
353 ACE_DEBUG( (LM_ERROR, "arr_ret[0] is wrong\n")); testFailed = 1;
355 else if (arr_ret[one].length () != 1 || arr_ret[one][0] != 21)
357 ACE_DEBUG( (LM_ERROR, "arr_ret[1] is wrong\n")); testFailed = 1;
359 else
360 ACE_DEBUG( (LM_INFO, "OK\n"));
363 //-----------------------------------------------------------------------
365 CORBA::Object_var a = CORBA::Object::_duplicate (foo.in ());
366 CORBA::Object_var b;
367 CORBA::Object_var c = CORBA::Object::_duplicate (a.in ());
368 CORBA::Object_var ret = foo->TestObject (a.in (), b.out (), c.inout ());
371 //-----------------------------------------------------------------------
372 foo->ShutdownServer();
374 //-----------------------------------------------------------------------
375 orb->shutdown(true);
376 orb->destroy();
378 catch (const CORBA::SystemException& ex)
380 ex._tao_print_exception ("CORBA::SystemException: ");
381 testFailed= 1;
383 catch (const CORBA::Exception& ex)
385 ex._tao_print_exception ("CORBA::Exception: ");
386 testFailed= 1;
388 catch (...)
390 ACE_DEBUG( (LM_ERROR, "Unexpected general exception!\n"));
391 testFailed= 1;
394 ACE_DEBUG( (LM_INFO, "Regression test for Bug 2234 "));
395 if (testFailed)
396 ACE_DEBUG( (LM_ERROR, "Failed\n"));
397 else
398 ACE_DEBUG( (LM_INFO, "Passed\n"));
400 return testFailed? -1 : 0;