More tests update
[ACE_TAO.git] / TAO / tests / Bug_2234_Regression / client.cpp
blobf9c3cab03c476830bf46c6ab28318a665a01d7f6
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[])
43 CORBA::Boolean testFailed= 0;
44 ACE_DEBUG( (LM_INFO, "Regression test for Bug 2234 (Interceptor arg list with var len out params)\n"));
45 try
47 CORBA::ORB_var
48 orb= CORBA::ORB_init (argc, argv);
50 if (parse_args (argc, argv) != 0)
51 return 1;
53 CORBA::Object_var
54 object= orb->string_to_object( ior );
55 Test::Foo_var
56 foo= Test::Foo::_narrow( object.in() );
58 //-----------------------------------------------------------------------
59 CORBA::Long
60 aL= 1,
61 bL,
62 cL= 3,
63 rL= 0;
64 ACE_DEBUG( (LM_INFO, ". Long() ") );
65 rL= foo->TestLong( aL, bL, cL);
66 ACE_DEBUG( (LM_INFO, "a is %d, b is %d, c is %d, r is %d: ", aL, bL, cL, rL) );
67 if (static_cast<CORBA::Long>(1) != aL) {
68 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
69 else if (static_cast<CORBA::Long>(2) != bL) {
70 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
71 else if (static_cast<CORBA::Long>(4) != cL) {
72 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
73 else if (static_cast<CORBA::Long>(7) != rL) {
74 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
75 else
76 ACE_DEBUG( (LM_INFO, "OK\n") );
78 //-----------------------------------------------------------------------
79 CORBA::String_var
80 aS= CORBA::string_dup("1"),
81 bS,
82 cS= CORBA::string_dup("3"),
83 rS;
84 ACE_DEBUG( (LM_INFO, ". String() ") );
85 rS= foo->TestString( aS.in(), bS.out(), cS.inout());
86 ACE_DEBUG( (LM_INFO, "a is %C, b is %C, c is %C, r is %C: ", aS.in (), bS.in (), cS.in (), rS.in ()));
87 if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(aS.in(), "1"))) {
88 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
89 else if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(bS.in(), "2"))) {
90 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
91 else if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(cS.in(), "4"))) {
92 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
93 else if ((0 != *aS.in()) && (0 != ACE_OS::strcmp(rS.in(), "7"))) {
94 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
95 else
96 ACE_DEBUG( (LM_INFO, "OK\n") );
98 //-----------------------------------------------------------------------
99 Test::MyNonVarStruct_var
100 aFS= new Test::MyNonVarStruct(),
101 bFS= new Test::MyNonVarStruct(),
102 cFS= new Test::MyNonVarStruct(),
103 rFS;
104 aFS->val= 1;
105 cFS->val= 3;
106 ACE_DEBUG( (LM_INFO, ". MyNonVarStruct() ") );
107 rFS= foo->TestNonVarStruct( aFS.in(), bFS.out(), cFS.inout());
108 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) );
109 if (static_cast<CORBA::Long>(1) != aFS->val) {
110 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
111 else if (static_cast<CORBA::Long>(2) != bFS->val) {
112 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
113 else if (static_cast<CORBA::Long>(4) != cFS->val) {
114 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
115 else if (static_cast<CORBA::Long>(7) != rFS->val) {
116 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
117 else
118 ACE_DEBUG( (LM_INFO, "OK\n") );
120 //-----------------------------------------------------------------------
121 Test::MyVarStruct_var
122 aVS= new Test::MyVarStruct(),
123 bVS,
124 cVS= new Test::MyVarStruct(),
125 rVS;
126 aVS->val= CORBA::string_dup("1");
127 cVS->val= CORBA::string_dup("3");
128 ACE_DEBUG( (LM_INFO, ". MyVarStruct() ") );
129 rVS= foo->TestVarStruct( aVS.in(), bVS.out(), cVS.inout());
130 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 ()));
131 if ((0 != *aVS->val) && (0 != ACE_OS::strcmp(aVS->val, "1"))) {
132 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
133 else if ((0 != *bVS->val) && (0 != ACE_OS::strcmp(bVS->val, "2"))) {
134 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
135 else if ((0 != *cVS->val) && (0 != ACE_OS::strcmp(cVS->val, "4"))) {
136 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
137 else if ((0 != *rVS->val) && (0 != ACE_OS::strcmp(rVS->val, "7"))) {
138 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
139 else
140 ACE_DEBUG( (LM_INFO, "OK\n") );
142 //-----------------------------------------------------------------------
143 Test::MyNonVarUnion_var
144 aFU= new Test::MyNonVarUnion(),
145 bFU= new Test::MyNonVarUnion(),
146 cFU= new Test::MyNonVarUnion(),
147 rFU;
148 aFU->valLong( static_cast<CORBA::Long>(1) );
149 cFU->valLong( static_cast<CORBA::Long>(3) );
150 ACE_DEBUG( (LM_INFO, ". MyNonVarUnion() ") );
151 rFU= foo->TestNonVarUnion( aFU.in(), bFU.out(), cFU.inout());
152 ACE_DEBUG( (LM_INFO, "a is ") );
153 if (static_cast<CORBA::Short>(1) != aFU->_d())
154 ACE_DEBUG( (LM_INFO, "?") );
155 else
156 ACE_DEBUG( (LM_INFO, "%d", aFU->valLong()) );
157 ACE_DEBUG( (LM_INFO, ", b is ") );
158 if (static_cast<CORBA::Short>(1) != bFU->_d())
159 ACE_DEBUG( (LM_INFO, "?") );
160 else
161 ACE_DEBUG( (LM_INFO, "%d", bFU->valLong()) );
162 ACE_DEBUG( (LM_INFO, ", c is ") );
163 if (static_cast<CORBA::Short>(1) != cFU->_d())
164 ACE_DEBUG( (LM_INFO, "?") );
165 else
166 ACE_DEBUG( (LM_INFO, "%d", cFU->valLong()) );
167 ACE_DEBUG( (LM_INFO, ", r is ") );
168 if (static_cast<CORBA::Short>(1) != rFU->_d())
169 ACE_DEBUG( (LM_INFO, "?") );
170 else
171 ACE_DEBUG( (LM_INFO, "%d", rFU->valLong()) );
172 ACE_DEBUG( (LM_INFO, ": ") );
173 if ((static_cast<CORBA::Short>(1) != aFU->_d()) || (static_cast<CORBA::Long>(1) != aFU->valLong())) {
174 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
175 else if ((static_cast<CORBA::Short>(1) != bFU->_d()) || (static_cast<CORBA::Long>(2) != bFU->valLong())) {
176 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
177 else if ((static_cast<CORBA::Short>(1) != cFU->_d()) || (static_cast<CORBA::Long>(4) != cFU->valLong())) {
178 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
179 else if ((static_cast<CORBA::Short>(1) != rFU->_d()) || (static_cast<CORBA::Long>(7) != rFU->valLong())) {
180 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
181 else
182 ACE_DEBUG( (LM_INFO, "OK\n") );
184 //-----------------------------------------------------------------------
185 Test::MyVarUnion_var
186 aVU= new Test::MyVarUnion(),
187 bVU,
188 cVU= new Test::MyVarUnion(),
189 rVU;
190 aVU->valLong( static_cast<CORBA::Long>(1) );
191 cVU->valLong( static_cast<CORBA::Long>(3) );
192 ACE_DEBUG( (LM_INFO, ". MyVarUnion() ") );
193 rVU= foo->TestVarUnion( aVU.in(), bVU.out(), cVU.inout());
194 ACE_DEBUG( (LM_INFO, "a is ") );
195 if (static_cast<CORBA::Short>(1) != aVU->_d())
196 ACE_DEBUG( (LM_INFO, "?") );
197 else
198 ACE_DEBUG( (LM_INFO, "%d", aVU->valLong()) );
199 ACE_DEBUG( (LM_INFO, ", b is ") );
200 if (static_cast<CORBA::Short>(1) != bVU->_d())
201 ACE_DEBUG( (LM_INFO, "?") );
202 else
203 ACE_DEBUG( (LM_INFO, "%d", bVU->valLong()) );
204 ACE_DEBUG( (LM_INFO, ", c is ") );
205 if (static_cast<CORBA::Short>(1) != cVU->_d())
206 ACE_DEBUG( (LM_INFO, "?") );
207 else
208 ACE_DEBUG( (LM_INFO, "%d", cVU->valLong()) );
209 ACE_DEBUG( (LM_INFO, ", r is ") );
210 if (static_cast<CORBA::Short>(1) != rVU->_d())
211 ACE_DEBUG( (LM_INFO, "?") );
212 else
213 ACE_DEBUG( (LM_INFO, "%d", rVU->valLong()) );
214 ACE_DEBUG( (LM_INFO, ": ") );
215 if ((static_cast<CORBA::Short>(1) != aVU->_d()) || (static_cast<CORBA::Long>(1) != aVU->valLong())) {
216 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
217 else if ((static_cast<CORBA::Short>(1) != bVU->_d()) || (static_cast<CORBA::Long>(2) != bVU->valLong())) {
218 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
219 else if ((static_cast<CORBA::Short>(1) != cVU->_d()) || (static_cast<CORBA::Long>(4) != cVU->valLong())) {
220 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
221 else if ((static_cast<CORBA::Short>(1) != rVU->_d()) || (static_cast<CORBA::Long>(7) != rVU->valLong())) {
222 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
223 else
224 ACE_DEBUG( (LM_INFO, "OK\n") );
226 //-----------------------------------------------------------------------
227 Test::MySeqOfLong_var
228 aSL= new Test::MySeqOfLong(1),
229 bSL,
230 cSL= new Test::MySeqOfLong(1),
231 rSL;
232 aSL->length(1);
233 aSL[0]= static_cast<CORBA::Long>(1);
234 cSL->length(1);
235 cSL[0]= static_cast<CORBA::Long>(3);
236 ACE_DEBUG( (LM_INFO, ". MySeqOfLong() ") );
237 rSL= foo->TestSeqOfLong( aSL.in(), bSL.out(), cSL.inout());
238 ACE_DEBUG( (LM_INFO, "a is ") );
239 if (1u != aSL->length())
240 ACE_DEBUG( (LM_INFO, "?") );
241 else
242 ACE_DEBUG( (LM_INFO, "%d", aSL[0]) );
243 ACE_DEBUG( (LM_INFO, ", b is ") );
244 if (1u != bSL->length())
245 ACE_DEBUG( (LM_INFO, "?") );
246 else
247 ACE_DEBUG( (LM_INFO, "%d", bSL[0]) );
248 ACE_DEBUG( (LM_INFO, ", c is ") );
249 if (1u != cSL->length())
250 ACE_DEBUG( (LM_INFO, "?") );
251 else
252 ACE_DEBUG( (LM_INFO, "%d", cSL[0]) );
253 ACE_DEBUG( (LM_INFO, ", r is ") );
254 if (1u != rSL->length())
255 ACE_DEBUG( (LM_INFO, "?") );
256 else
257 ACE_DEBUG( (LM_INFO, "%d", rSL[0]) );
258 ACE_DEBUG( (LM_INFO, ": ") );
259 if ((1u != aSL->length()) || (static_cast<CORBA::Long>(1) != aSL[0])) {
260 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
261 else if ((1u != bSL->length()) || (static_cast<CORBA::Long>(2) != bSL[0])) {
262 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
263 else if ((1u != cSL->length()) || (static_cast<CORBA::Long>(4) != cSL[0])) {
264 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
265 else if ((1u != rSL->length()) || (static_cast<CORBA::Long>(7) != rSL[0])) {
266 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
267 else
268 ACE_DEBUG( (LM_INFO, "OK\n") );
270 //-----------------------------------------------------------------------
271 CORBA::Any_var
272 aA= new CORBA::Any(),
274 cA= new CORBA::Any(),
276 aA<<= static_cast<CORBA::Long>(1);
277 cA<<= static_cast<CORBA::Long>(3);
278 ACE_DEBUG( (LM_INFO, ". Any() ") );
279 rA= foo->TestAny( aA.in(), bA.out(), cA.inout());
280 CORBA::Boolean
285 ACE_DEBUG( (LM_INFO, "a is ") );
286 if (0 != (aB= (aA>>= aL)))
287 ACE_DEBUG( (LM_INFO, "%d", aL) );
288 else
289 ACE_DEBUG( (LM_INFO, "?") );
290 ACE_DEBUG( (LM_INFO, ", b is ") );
291 if (0 != (bB= (bA>>= bL)))
292 ACE_DEBUG( (LM_INFO, "%d", bL) );
293 else
294 ACE_DEBUG( (LM_INFO, "?") );
295 ACE_DEBUG( (LM_INFO, ", c is ") );
296 if (0 != (cB= (cA>>= cL)))
297 ACE_DEBUG( (LM_INFO, "%d", cL) );
298 else
299 ACE_DEBUG( (LM_INFO, "?") );
300 ACE_DEBUG( (LM_INFO, ", r is ") );
301 if (0 != (rB= (rA>>= rL)))
302 ACE_DEBUG( (LM_INFO, "%d", rL) );
303 else
304 ACE_DEBUG( (LM_INFO, "?") );
305 ACE_DEBUG( (LM_INFO, ": ") );
306 if (!aB || (static_cast<CORBA::Long>(1) != aL)) {
307 ACE_DEBUG( (LM_ERROR, "a is wrong\n") ); testFailed= 1;}
308 else if (!bB || (static_cast<CORBA::Long>(2) != bL)) {
309 ACE_DEBUG( (LM_ERROR, "b is wrong\n") ); testFailed= 1;}
310 else if (!cB || (static_cast<CORBA::Long>(4) != cL)) {
311 ACE_DEBUG( (LM_ERROR, "c is wrong\n") ); testFailed= 1;}
312 else if (!rB || (static_cast<CORBA::Long>(7) != rL)) {
313 ACE_DEBUG( (LM_ERROR, "r is wrong\n") ); testFailed= 1;}
314 else
315 ACE_DEBUG( (LM_INFO, "OK\n") );
317 //-----------------------------------------------------------------------
319 Test::MyArray arr_a;
320 arr_a[0].length (1);
321 arr_a[0][0] = 9;
322 arr_a[1].length (1);
323 arr_a[1][0] = 23;
325 Test::MyArray_var arr_b;
327 Test::MyArray arr_c;
328 arr_c[0].length (1);
329 arr_c[0][0] = 23;
330 arr_c[1].length (1);
331 arr_c[1][0] = 9;
333 ACE_DEBUG( (LM_INFO, ". MyArray() ") );
334 Test::MyArray_var arr_ret = foo->TestArray (arr_a, arr_b.out (), arr_c);
335 CORBA::ULong zero (0), one (1); //Use ULong to avoid ambiguity
336 if (arr_c[0].length () != 1 || arr_c[0][0] != 24)
338 ACE_DEBUG( (LM_ERROR, "arr_c[0] is wrong\n") ); testFailed = 1;
340 else if (arr_c[1].length () != 1 || arr_c[1][0] != 10)
342 ACE_DEBUG( (LM_ERROR, "arr_c[1] is wrong\n") ); testFailed = 1;
344 else if (arr_b[zero].length () != 1 || arr_b[zero][0] != 8)
346 ACE_DEBUG( (LM_ERROR, "arr_b[0] is wrong\n") ); testFailed = 1;
348 else if (arr_b[one].length () != 1 || arr_b[one][0] != 22)
350 ACE_DEBUG( (LM_ERROR, "arr_b[1] is wrong\n") ); testFailed = 1;
352 else if (arr_ret[zero].length () != 1 || arr_ret[zero][0] != 7)
354 ACE_DEBUG( (LM_ERROR, "arr_ret[0] is wrong\n") ); testFailed = 1;
356 else if (arr_ret[one].length () != 1 || arr_ret[one][0] != 21)
358 ACE_DEBUG( (LM_ERROR, "arr_ret[1] is wrong\n") ); testFailed = 1;
360 else
361 ACE_DEBUG( (LM_INFO, "OK\n") );
364 //-----------------------------------------------------------------------
366 CORBA::Object_var a = CORBA::Object::_duplicate (foo.in ());
367 CORBA::Object_var b;
368 CORBA::Object_var c = CORBA::Object::_duplicate (a.in ());
369 CORBA::Object_var ret = foo->TestObject (a.in (), b.out (), c.inout ());
372 //-----------------------------------------------------------------------
373 foo->ShutdownServer( );
375 //-----------------------------------------------------------------------
376 orb->shutdown( true );
377 orb->destroy( );
379 catch (const CORBA::SystemException& ex)
381 ex._tao_print_exception ("CORBA::SystemException: ");
382 testFailed= 1;
384 catch (const CORBA::Exception& ex)
386 ex._tao_print_exception ("CORBA::Exception: ");
387 testFailed= 1;
389 catch (...)
391 ACE_DEBUG( (LM_ERROR, "Unexpected general exception!\n") );
392 testFailed= 1;
395 ACE_DEBUG( (LM_INFO, "Regression test for Bug 2234 ") );
396 if (testFailed)
397 ACE_DEBUG( (LM_ERROR, "Failed\n") );
398 else
399 ACE_DEBUG( (LM_INFO, "Passed\n") );
401 return testFailed? -1 : 0;