1 /*
2  * CORBA C language mapping tests
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2, or (at your option) any
7  * later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Author: Phil Dawes <philipd@users.sourceforge.net>
19  */
20 
21 #include <glib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 
26 #include "everything.h"
27 #include "constants.h"
28 #include "orb-core/orb-core-private.h"
29 #include "orbit-imodule.h"
30 #include "orbit/orbit.h"
31 
32 #define NUM_RUNS 1
33 #define NUM_THREADS 8
34 
35 #undef TIMING_RUN
36 
37 #ifdef TIMING_RUN
38 #  define d_print(a)
39 #else
40 #  define d_print(a) if (!thread_tests && a != NULL) g_print(a)
41 #endif
42 
43 extern CORBA_ORB global_orb;
44 gboolean         in_proc;
45 gboolean         thread_safe = FALSE;
46 gboolean         thread_tests = FALSE;
47 
48 /* Ugly- but hey */
49 #define _IN_CLIENT_
50 #include "server.c"
51 #undef  _IN_CLIENT_
52 
53 static void
testConst(void)54 testConst (void)
55 {
56 	d_print ("Testing constants...\n");
57 	g_assert (test_CONST_CHAR == 't');
58 	g_assert (test_CONST_LONG == 0x12345678);
59 	g_assert (test_CONST_LONG_LONG == 0x12345678);
60 	g_assert (!strcmp (test_CONST_STRING, "ConstString"));
61 	g_assert (test_CONST_FLOAT == 1234.56);
62 	g_assert (test_CONST_DOUBLE == 1234.5678);
63 	g_assert (test_CONST_LONG_DOUBLE == 1234.567891);
64 	g_assert (test_FAVORITE_SOUP == test_veggie);
65 	g_assert (test_HORRIBLE_SOUP == test_oxtail);
66 }
67 
68 static void
testSequenceHelpers(void)69 testSequenceHelpers (void)
70 {
71 	CORBA_long           l    = 0;
72 	test_BoundedLongSeq *lseq = NULL;
73 
74 	d_print ("Testing ORBit_sequence helpers...\n");
75 
76 	lseq = ORBit_sequence_alloc (TC_test_BoundedLongSeq, 2);
77 	g_assert (lseq != NULL);
78 	g_assert (lseq->_length ==  2);
79 	g_assert (lseq->_maximum >= 2);
80 
81 	ORBit_sequence_index (lseq, 0) = 0;
82 	ORBit_sequence_index (lseq, 1) = 0;
83 
84 	l = 1;
85 	ORBit_sequence_append (lseq, &l);
86 	l++;
87 	ORBit_sequence_append (lseq, &l);
88 
89 	g_assert (lseq->_length == 4);
90 	g_assert (ORBit_sequence_index (lseq, 2) == 1);
91 	g_assert (ORBit_sequence_index (lseq, 3) == 2);
92 
93         ORBit_sequence_remove(lseq, 2);
94 	g_assert (lseq->_length == 3);
95 	g_assert (ORBit_sequence_index (lseq, 2) == 2);
96 
97 	ORBit_sequence_set_size (lseq, 100);
98 	ORBit_sequence_set_size (lseq, 0);
99 
100 	CORBA_free (lseq);
101 
102 	/* test incremental reallocation of memory */
103 	{
104 		CORBA_long i = 0;
105 		CORBA_long j = 0;
106 
107 		/* 16 times double capacity of buffer */
108 		CORBA_long MAX_APPEND = 1<<16;
109 		/* generic sequence<octet> test */
110 		CORBA_sequence_CORBA_octet *oseq = NULL;
111 
112 		oseq = ORBit_sequence_alloc (TC_CORBA_sequence_CORBA_octet, 0);
113 
114 		g_assert (oseq != NULL);
115 		g_assert (oseq->_length == 0);
116 		g_assert (oseq->_maximum >= 0);
117 
118 		for (i = 0; i < MAX_APPEND; ++i)
119 		{
120 			CORBA_octet oct = (CORBA_octet) (i % 109);
121 			/* _append does shallow copy */
122 			ORBit_sequence_append (oseq, &oct); /* realloc */
123 			g_assert (i+1==oseq->_length);
124 
125 			/* infrequent validation sequence values have
126 			 * been re-located correctly */
127 			if (i % 367 == 0)
128 			for (j = 0; j < oseq->_length; ++j /* prim */ )
129 			{
130 				CORBA_octet j_check = (CORBA_octet) (j % 109);
131 				CORBA_octet j_value = ORBit_sequence_index (oseq, j);
132 				g_assert (j_value==j_check);
133 			}
134 		}
135 
136 		CORBA_free (oseq);
137 	}
138 
139 	/* test concat operation: concat two sequences of different
140 	 * size. The concatinated sequence must contain values of both
141 	 * in correct order. */
142 	{
143 		CORBA_octet oct = 0;
144 		CORBA_long i = 0;
145 		CORBA_long j = 0;
146 		CORBA_long a = 0;
147 		CORBA_long b = 0;
148 		CORBA_sequence_CORBA_octet *aseq = NULL;
149 		CORBA_sequence_CORBA_octet *bseq = NULL;
150 
151 		aseq = ORBit_sequence_alloc (TC_CORBA_sequence_CORBA_octet, 0);
152 		bseq = ORBit_sequence_alloc (TC_CORBA_sequence_CORBA_octet, 0);
153 
154 		for (b = 0; b < 200; ++b) {
155 			ORBit_sequence_concat (aseq, bseq);
156 
157 			a = 0;
158 			for (i = 0; i < b; ++i)
159 				for (j = 0; j < i; ++j, ++a)
160 					g_assert (ORBit_sequence_index (aseq, a) == j % 128);
161 
162 			oct = b % 128;
163 			ORBit_sequence_append (bseq, &oct);
164 		}
165 
166 		CORBA_free (aseq);
167 		CORBA_free (bseq);
168 	}
169 
170 }
171 
172 static void
testAttribute(test_BasicServer objref,CORBA_Environment * ev)173 testAttribute (test_BasicServer   objref,
174 	       CORBA_Environment *ev)
175 {
176 	CORBA_char *val;
177 	CORBA_long  lval;
178 
179 	d_print ("Testing attributes...\n");
180 
181 	val = test_BasicServer__get_foo (objref, ev);
182 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
183 	g_assert (strcmp (val, constants_STRING_RETN)==0);
184 	CORBA_free (val);
185 
186 	test_BasicServer__set_foo (objref, constants_STRING_IN, ev);
187 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
188 
189 	lval = test_BasicServer__get_bah (objref, ev);
190 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
191 	g_assert (lval == constants_LONG_RETN);
192 }
193 
194 static void
testString(test_BasicServer objref,CORBA_Environment * ev)195 testString (test_BasicServer   objref,
196 	    CORBA_Environment *ev)
197 {
198 	const CORBA_char *in;
199 	CORBA_char *inout, *out, *retn;
200 
201 	d_print ("Testing strings...\n");
202 
203 	in = constants_STRING_IN;
204 	inout = CORBA_string_dup (constants_STRING_INOUT_IN);
205 	retn = test_BasicServer_opString (objref, in, &inout, &out, ev);
206 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
207 
208 	g_assert (strcmp (out, constants_STRING_OUT)==0);
209 	g_assert (strcmp (retn, constants_STRING_RETN)==0);
210 	g_assert (strcmp (in, constants_STRING_IN)==0);
211 	g_assert (strcmp (inout, constants_STRING_INOUT_OUT)==0);
212 
213 	test_BasicServer_opOneWay (objref, constants_STRING_IN, ev);
214 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
215 
216 	CORBA_free (inout);
217 	CORBA_free (out);
218 	CORBA_free (retn);
219 }
220 
221 static void
testLong(test_BasicServer objref,CORBA_Environment * ev)222 testLong (test_BasicServer   objref,
223 	  CORBA_Environment *ev)
224 {
225 	CORBA_long inArg, inoutArg, outArg, retn;
226 
227 	d_print ("Testing longs...\n");
228 
229 	inArg = constants_LONG_IN;
230 	inoutArg = constants_LONG_INOUT_IN;
231 	retn = test_BasicServer_opLong (objref, inArg, &inoutArg, &outArg, ev);
232 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
233 	g_assert (inArg == constants_LONG_IN);
234 	g_assert (inoutArg == constants_LONG_INOUT_OUT);
235 	g_assert (outArg == constants_LONG_OUT);
236 	g_assert (retn == constants_LONG_RETN);
237 }
238 
239 static void
testLongLong(test_BasicServer objref,CORBA_Environment * ev)240 testLongLong (test_BasicServer   objref,
241 	      CORBA_Environment *ev)
242 {
243 	CORBA_long_long inArg, inoutArg, outArg, retn;
244 
245 	d_print ("Testing long longs...\n");
246 
247 	inArg = constants_LONG_LONG_IN;
248 	inoutArg = constants_LONG_LONG_INOUT_IN;
249 	retn = test_BasicServer_opLongLong (objref, inArg, &inoutArg, &outArg, ev);
250 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
251 	g_assert (inArg == constants_LONG_LONG_IN);
252 	g_assert (inoutArg == constants_LONG_LONG_INOUT_OUT);
253 	g_assert (outArg == constants_LONG_LONG_OUT);
254 	g_assert (retn == constants_LONG_LONG_RETN);
255 }
256 
257 static void
testFloat(test_BasicServer objref,CORBA_Environment * ev)258 testFloat (test_BasicServer   objref,
259 	   CORBA_Environment *ev)
260 {
261 	CORBA_float inArg, inoutArg, outArg, retn;
262 
263 	d_print ("Testing floats...\n");
264 
265 	inArg = constants_FLOAT_IN;
266 	inoutArg = constants_FLOAT_INOUT_IN;
267 	retn = test_BasicServer_opFloat (objref, inArg, &inoutArg, &outArg, ev);
268 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
269 	g_assert (inArg == constants_FLOAT_IN);
270 	g_assert (inoutArg == constants_FLOAT_INOUT_OUT);
271 	g_assert (outArg == constants_FLOAT_OUT);
272 	g_assert (retn == constants_FLOAT_RETN);
273 }
274 
275 static void
testDouble(test_BasicServer objref,CORBA_Environment * ev)276 testDouble (test_BasicServer   objref,
277 	    CORBA_Environment *ev)
278 {
279 	CORBA_double inArg, inoutArg, outArg, retn;
280 
281 	d_print ("Testing doubles...\n");
282 
283 	inArg = constants_DOUBLE_IN;
284 	inoutArg = constants_DOUBLE_INOUT_IN;
285 	retn = test_BasicServer_opDouble (objref, inArg, &inoutArg, &outArg, ev);
286 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
287 	g_assert (inArg == constants_DOUBLE_IN);
288 	g_assert (inoutArg == constants_DOUBLE_INOUT_OUT);
289 	g_assert (outArg == constants_DOUBLE_OUT);
290 	g_assert (retn == constants_DOUBLE_RETN);
291 }
292 
293 static void
testLongDouble(test_BasicServer objref,CORBA_Environment * ev)294 testLongDouble (test_BasicServer   objref,
295 		CORBA_Environment *ev)
296 {
297 	CORBA_long_double inArg, inoutArg, outArg, retn;
298 
299 	d_print ("Testing long doubles...\n");
300 
301 	inArg = constants_LONG_DOUBLE_IN;
302 	inoutArg = constants_LONG_DOUBLE_INOUT_IN;
303 	retn = test_BasicServer_opLongDouble (objref, inArg, &inoutArg, &outArg, ev);
304 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
305 	g_assert (inArg == constants_LONG_DOUBLE_IN);
306 	g_assert (inoutArg == constants_LONG_DOUBLE_INOUT_OUT);
307 	g_assert (outArg == constants_LONG_DOUBLE_OUT);
308 	g_assert (retn == constants_LONG_DOUBLE_RETN);
309 }
310 
311 static void
testEnum(test_BasicServer objref,CORBA_Environment * ev)312 testEnum (test_BasicServer   objref,
313 	  CORBA_Environment *ev)
314 {
315 	test_AnEnum inArg, inoutArg, outArg, retn;
316 
317 	d_print ("Testing enums...\n");
318 
319 	inArg = test_ENUM_IN;
320 	inoutArg = test_ENUM_INOUT_IN;
321 	retn = test_BasicServer_opEnum (objref, inArg, &inoutArg, &outArg, ev);
322 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
323 	g_assert (inArg == test_ENUM_IN);
324 	g_assert (inoutArg == test_ENUM_INOUT_OUT);
325 	g_assert (outArg == test_ENUM_OUT);
326 	g_assert (retn == test_ENUM_RETN);
327 }
328 
329 static void
testException(test_BasicServer objref,CORBA_Environment * ev)330 testException (test_BasicServer   objref,
331 	       CORBA_Environment *ev)
332 {
333 	test_TestException *ex;
334 	CORBA_Environment  *cpyev;
335 
336 	d_print ("Testing exceptions...\n");
337 
338 	test_BasicServer_opException (CORBA_OBJECT_NIL, ev);
339 	g_assert (ev->_major == CORBA_SYSTEM_EXCEPTION);
340 	g_assert (strcmp (CORBA_exception_id (ev), ex_CORBA_INV_OBJREF) == 0);
341 	CORBA_exception_free (ev);
342 
343 	test_BasicServer_opException (objref, ev);
344 
345 	g_assert (ev->_major == CORBA_USER_EXCEPTION);
346 	g_assert (strcmp (CORBA_exception_id (ev), ex_test_TestException) == 0);
347 	ex = CORBA_exception_value (ev);
348 	g_assert (strcmp (ex->reason, constants_STRING_IN) == 0);
349 	g_assert (ex->number == constants_LONG_IN);
350 	g_assert (ex->aseq._length == 1);
351 	g_assert (ex->aseq._buffer[0] == constants_LONG_IN);
352 
353 	cpyev = CORBA_exception__copy (ev);
354 	CORBA_exception_free (ev);
355 	ev = cpyev;
356 
357 	g_assert (ev->_major == CORBA_USER_EXCEPTION);
358 	g_assert (strcmp (CORBA_exception_id (ev), ex_test_TestException) == 0);
359 /*	FIXME: we can't do this until we get exception data from
360 	the typelib - and make sure we register all system types
361 	there too */
362 /*	ex = CORBA_exception_value (ev);
363 	g_assert (strcmp (ex->reason, constants_STRING_IN) == 0);
364 	g_assert (ex->number == constants_LONG_IN);
365 	g_assert (ex->aseq._length == 1);
366 	g_assert (ex->aseq._buffer[0] == constants_LONG_IN);*/
367 
368 	CORBA_free (cpyev);
369 }
370 
371 static void
testBoolAlign(test_BasicServer objref,CORBA_Environment * ev)372 testBoolAlign (test_BasicServer   objref,
373 	       CORBA_Environment *ev)
374 {
375 	char *inoutArg;
376 
377 	d_print ("Testing bool arg. alignment ...\n");
378 
379 	inoutArg = CORBA_string_dup("foo");
380 	test_BasicServer_testBoolString (objref, TRUE, "retout", &inoutArg, ev);
381 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
382 }
383 
384 static CORBA_TypeCode
find_tc(CORBA_sequence_CORBA_TypeCode * tcs,const char * repo_id)385 find_tc (CORBA_sequence_CORBA_TypeCode *tcs,
386 	 const char                    *repo_id)
387 {
388 	int i;
389 
390 	for (i = 0; i < tcs->_length; i++)
391 		if (!strcmp (tcs->_buffer [i]->repo_id, repo_id))
392 			return tcs->_buffer [i];
393 
394 	return NULL;
395 }
396 
397 static void
testIInterface(test_TestFactory factory,CORBA_Environment * ev)398 testIInterface (test_TestFactory   factory,
399 		CORBA_Environment *ev)
400 {
401 	CORBA_TypeCode    tc;
402 	test_StructServer objref;
403 	CORBA_char       *type_id;
404 	ORBit_IInterface *iinterface;
405 	CORBA_sequence_CORBA_TypeCode *tcs;
406 
407 	d_print ("Testing IInterface code...\n");
408 	objref = test_TestFactory_getStructServer (factory, ev);
409 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
410 
411 	/* Check nil check is working ! */
412 	g_assert (CORBA_Object_is_nil  (CORBA_OBJECT_NIL, ev));
413 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
414 	g_assert (!CORBA_Object_is_nil (objref, ev));
415 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
416 
417 	/* Check non_existant is working ! */
418 	g_assert (!CORBA_Object_non_existent (objref, ev));
419 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
420 
421 	/* Ensure that we go over the wire at least once */
422 	g_assert (CORBA_Object_is_a (objref, "IDL:orbit/test/StructServer:1.0", ev));
423 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
424 	g_assert (CORBA_Object_is_a (objref, "IDL:orbit/test/BasicServer:1.0", ev));
425 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
426 
427 	/* Scripting stuff */
428 
429 	/* Get real type id */
430 	g_assert ( (type_id = ORBit_small_get_type_id (objref, ev)));
431 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
432 	g_assert (!strcmp (type_id, "IDL:orbit/test/StructServer:1.0"));
433 	CORBA_free (type_id);
434 
435 	/* Get interface data */
436 	iinterface = ORBit_small_get_iinterface (
437 		objref, "foo_bar_jelly", ev);
438 	g_assert (ev->_major != CORBA_NO_EXCEPTION);
439 	g_assert (iinterface == NULL);
440 	g_assert (!strcmp (ev->_id, ex_ORBit_NoIInterface));
441 	CORBA_exception_free (ev);
442 
443 	iinterface = ORBit_small_get_iinterface (
444 		objref, "IDL:orbit/test/StructServer:1.0", ev);
445 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
446 	g_assert (iinterface != NULL);
447 	g_assert (!strcmp (iinterface->tc->repo_id, "IDL:orbit/test/StructServer:1.0"));
448 	CORBA_free (iinterface);
449 
450 	CORBA_Object_release (objref, ev);
451 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
452 
453 #define TYPELIB_NAME "./Everything_module"
454 
455 	if (!ORBit_small_load_typelib (TYPELIB_NAME))
456 		g_warning ("Failed to load '" TYPELIB_NAME "'");
457 	iinterface = ORBit_small_get_iinterface (
458 		objref, "IDL:orbit/test/StructServer:1.0", ev);
459 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
460 	g_assert (iinterface != NULL);
461 	CORBA_free (iinterface);
462 
463 	tcs = ORBit_small_get_types (TYPELIB_NAME);
464 	g_assert (find_tc (tcs, "IDL:orbit/test/Soup:1.0"));
465 	g_assert (find_tc (tcs, "IDL:orbit/test/EnumUnion/Colour:1.0"));
466 	g_assert (find_tc (tcs, "IDL:orbit/test/ArrayUnion:1.0"));
467 
468 	tc = find_tc (tcs, "IDL:orbit/test/StrSeq:1.0");
469 	g_assert (!strcmp (tc->repo_id, "IDL:orbit/test/StrSeq:1.0"));
470 	g_assert (tc->kind == CORBA_tk_alias);
471 	g_assert (tc->subtypes[0]->kind);
472 
473 	CORBA_free (tcs);
474 
475 	/* test subnames for unions correctly handle multiple case
476 	 * labels pointing at the same sub type. */
477 	tc = TC_test_FixedLengthUnion;
478 	g_assert(tc->sub_parts == 5);
479 	g_assert(!strcmp(tc->subnames[0], "x"));
480 	g_assert(!strcmp(tc->subnames[1], "y"));
481 	g_assert(!strcmp(tc->subnames[2], "z"));
482 	g_assert(!strcmp(tc->subnames[3], "z"));
483 	g_assert(!strcmp(tc->subnames[4], "v"));
484 }
485 
486 static void
testIsA(test_TestFactory factory,CORBA_Environment * ev)487 testIsA (test_TestFactory   factory,
488 	 CORBA_Environment *ev)
489 {
490 	test_DerivedServer ds;
491 
492 	d_print ("Testing is_a ...\n");
493 
494 	g_assert (CORBA_Object_is_a (factory, "IDL:CORBA/Object:1.0", ev));
495 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
496 	g_assert (CORBA_Object_is_a (factory, "IDL:omg.org/CORBA/Object:1.0", ev));
497 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
498 
499 	ds = test_TestFactory_getDerivedServer (factory, ev);
500 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
501 
502 	g_assert (CORBA_Object_is_a (ds, "IDL:orbit/test/DerivedServer:1.0", ev));
503 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
504 	g_assert (CORBA_Object_is_a (ds, "IDL:orbit/test/C1:1.0", ev));
505 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
506 	g_assert (CORBA_Object_is_a (ds, "IDL:orbit/test/B1:1.0", ev));
507 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
508 	g_assert (CORBA_Object_is_a (ds, "IDL:orbit/test/B2:1.0", ev));
509 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
510 	g_assert (CORBA_Object_is_a (ds, "IDL:orbit/test/BaseServer:1.0", ev));
511 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
512 	g_assert (CORBA_Object_is_a (factory, "IDL:CORBA/Object:1.0", ev));
513 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
514 
515 	CORBA_Object_release (ds, ev);
516 }
517 
518 static void
testFixedLengthStruct(test_TestFactory factory,CORBA_Environment * ev)519 testFixedLengthStruct (test_TestFactory   factory,
520 		       CORBA_Environment *ev)
521 {
522 	test_StructServer objref;
523 	test_FixedLengthStruct inArg, inoutArg, outArg, retn;
524 	CORBA_char *ior;
525 
526 	d_print ("Testing struct code ...\n");
527 	ior = test_TestFactory_getStructServerIOR (factory, ev);
528 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
529 
530 	objref = CORBA_ORB_string_to_object (global_orb, ior, ev);
531 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
532 	g_assert (objref != CORBA_OBJECT_NIL);
533 	CORBA_free (ior);
534 
535 
536 	inArg.a = constants_SHORT_IN;
537 	inoutArg.a = constants_SHORT_INOUT_IN;
538 
539 	retn = test_StructServer_opFixed (objref, &inArg, &inoutArg, &outArg, ev);
540 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
541 
542 	g_assert (inArg.a == constants_SHORT_IN);
543 	g_assert (inoutArg.a == constants_SHORT_INOUT_OUT);
544 	g_assert (outArg.a == constants_SHORT_OUT);
545 	g_assert (retn.a == constants_SHORT_RETN);
546 	CORBA_Object_release (objref, ev);
547 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
548 }
549 
550 static void
testVariableLengthStruct(test_TestFactory factory,CORBA_Environment * ev)551 testVariableLengthStruct (test_TestFactory   factory,
552 			  CORBA_Environment *ev)
553 {
554   test_StructServer objref;
555   test_VariableLengthStruct inArg, inoutArg, *outArg, *retn;
556   d_print ("Testing variable length structs...\n");
557   objref = test_TestFactory_getStructServer (factory, ev);
558   g_assert (ev->_major == CORBA_NO_EXCEPTION);
559 
560   inArg.a = (CORBA_char*)constants_STRING_IN;  /* const cast */
561   inoutArg.a = CORBA_string_dup (constants_STRING_INOUT_IN);
562 
563   retn = test_StructServer_opVariable (objref, &inArg, &inoutArg, &outArg, ev);
564   g_assert (ev->_major == CORBA_NO_EXCEPTION);
565 
566   g_assert (strcmp (inArg.a, constants_STRING_IN)==0);
567   g_assert (strcmp (inoutArg.a, constants_STRING_INOUT_OUT)==0);
568   g_assert (strcmp (outArg->a, constants_STRING_OUT)==0);
569   g_assert (strcmp (retn->a, constants_STRING_RETN)==0);
570 
571   CORBA_free (inoutArg.a);
572   CORBA_free (outArg);
573   CORBA_free (retn);
574   CORBA_Object_release (objref, ev);
575   g_assert (ev->_major == CORBA_NO_EXCEPTION);
576 }
577 
578 
579 static void
testCompoundStruct(test_TestFactory factory,CORBA_Environment * ev)580 testCompoundStruct (test_TestFactory   factory,
581 		    CORBA_Environment *ev)
582 {
583   test_StructServer objref;
584   test_CompoundStruct inArg, inoutArg, *outArg, *retn;
585   d_print ("Testing compound structs...\n");
586   objref = test_TestFactory_getStructServer (factory, ev);
587   g_assert (ev->_major == CORBA_NO_EXCEPTION);
588 
589   inArg.a.a = CORBA_string_dup (constants_STRING_IN);
590   inoutArg.a.a = CORBA_string_dup (constants_STRING_INOUT_IN);
591 
592   retn = test_StructServer_opCompound (objref, &inArg, &inoutArg, &outArg, ev);
593   g_assert (ev->_major == CORBA_NO_EXCEPTION);
594 
595   g_assert (strcmp (inArg.a.a, constants_STRING_IN)==0);
596   g_assert (strcmp (inoutArg.a.a, constants_STRING_INOUT_OUT)==0);
597   g_assert (strcmp (outArg->a.a, constants_STRING_OUT)==0);
598   g_assert (strcmp (retn->a.a, constants_STRING_RETN)==0);
599 
600   CORBA_free (inArg.a.a);
601   CORBA_free (inoutArg.a.a);
602   CORBA_free (outArg);
603   CORBA_free (retn);
604   CORBA_Object_release (objref, ev);
605   g_assert (ev->_major == CORBA_NO_EXCEPTION);
606 }
607 
608 static void
testAlignHoleStruct(test_TestFactory factory,CORBA_Environment * ev)609 testAlignHoleStruct (test_TestFactory   factory,
610 		    CORBA_Environment *ev)
611 {
612   test_StructServer objref;
613   test_AlignHoleStruct inArg, inoutArg, outArg, retn;
614   d_print ("Testing structs with aligning holes...\n");
615   objref = test_TestFactory_getStructServer (factory, ev);
616   g_assert (ev->_major == CORBA_NO_EXCEPTION);
617 
618   inArg.a.a = constants_DOUBLE_IN;
619   inArg.a.b = constants_OCTET_IN;
620   inArg.b = constants_CHAR_IN;
621 
622   inoutArg.a.a = constants_DOUBLE_INOUT_IN;
623   inoutArg.a.b = constants_OCTET_INOUT_IN;
624   inoutArg.b = constants_CHAR_INOUT_IN;
625 
626   memset(&outArg, 0, sizeof(outArg));
627 
628   retn = test_StructServer_opAlignHole (objref, &inArg, &inoutArg, &outArg, ev);
629   g_assert (ev->_major == CORBA_NO_EXCEPTION);
630 
631   g_assert (inArg.a.a == constants_DOUBLE_IN);
632   g_assert (inArg.a.b == constants_OCTET_IN);
633   g_assert (inArg.b == constants_CHAR_IN);
634 
635   g_assert (inoutArg.a.a == constants_DOUBLE_INOUT_OUT);
636   g_assert (inoutArg.a.b == constants_OCTET_INOUT_OUT);
637   g_assert (inoutArg.b == constants_CHAR_INOUT_OUT);
638 
639   g_assert (outArg.a.a == constants_DOUBLE_OUT);
640   g_assert (outArg.a.b == constants_OCTET_OUT);
641   g_assert (outArg.b == constants_CHAR_OUT);
642 
643   g_assert (retn.a.a == constants_DOUBLE_RETN);
644   g_assert (retn.a.b == constants_OCTET_RETN);
645   g_assert (retn.b == constants_CHAR_RETN);
646 
647   CORBA_Object_release (objref, ev);
648   g_assert (ev->_major == CORBA_NO_EXCEPTION);
649 }
650 
651 static void
testObjectStruct(test_TestFactory factory,CORBA_Environment * ev)652 testObjectStruct (test_TestFactory   factory,
653 		  CORBA_Environment *ev)
654 {
655   test_StructServer objref;
656   test_ObjectStruct inArg;
657 
658   d_print ("Testing object structs...\n");
659   objref = test_TestFactory_getStructServer (factory, ev);
660   g_assert (ev->_major == CORBA_NO_EXCEPTION);
661 
662   inArg.serv = objref;
663 
664   test_StructServer_opObjectStruct (objref, &inArg, ev);
665   g_assert (ev->_major == CORBA_NO_EXCEPTION);
666 
667   CORBA_Object_release (objref, ev);
668   g_assert (ev->_major == CORBA_NO_EXCEPTION);
669 
670 }
671 
672 static void
testStructAny(test_TestFactory factory,CORBA_Environment * ev)673 testStructAny (test_TestFactory   factory,
674 	       CORBA_Environment *ev)
675 {
676 	test_StructServer objref;
677 	test_StructAny   *a;
678 
679 	d_print ("Testing 'any' structs...\n");
680 	objref = test_TestFactory_getStructServer (factory, ev);
681 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
682 
683 	a = test_StructServer_opStructAny (objref, ev);
684 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
685 
686 	g_assert (!strcmp (a->a, constants_STRING_IN));
687 	g_assert (* (CORBA_long *)a->b._value == constants_LONG_IN);
688 
689 	CORBA_free (a);
690 
691 	CORBA_Object_release (objref, ev);
692 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
693 }
694 
695 static void
testUnboundedSequence(test_TestFactory factory,CORBA_Environment * ev)696 testUnboundedSequence (test_TestFactory   factory,
697 		       CORBA_Environment *ev)
698 {
699   test_SequenceServer objref;
700   test_StrSeq *outArg = NULL, inArg, inoutArg, *retn;
701   /*  test_LongSeq *long_retn; */
702   guint i;
703   d_print ("Testing unbounded sequences...\n");
704   objref = test_TestFactory_getSequenceServer (factory, ev);
705   g_assert (ev->_major == CORBA_NO_EXCEPTION);
706 
707   inArg._buffer = CORBA_sequence_CORBA_string_allocbuf (2);
708   inArg._length = 2;
709   CORBA_sequence_set_release (&inArg, CORBA_TRUE);
710 
711   for (i=0;i<inArg._length;i++){
712 	inArg._buffer[i] = CORBA_string_dup (constants_SEQ_STRING_IN[i]);
713   }
714 
715   inoutArg._buffer = CORBA_sequence_CORBA_string_allocbuf (2);
716   inoutArg._length = 2;
717   CORBA_sequence_set_release (&inoutArg, CORBA_TRUE);
718 
719   for (i=0;i<inoutArg._length;i++){
720 	inoutArg._buffer[i] = CORBA_string_dup (constants_SEQ_STRING_INOUT_IN[i]);
721   }
722 
723   retn = test_SequenceServer_opStrSeq (objref, &inArg, &inoutArg, &outArg, ev);
724   g_assert (ev->_major == CORBA_NO_EXCEPTION);
725 
726   for (i=0;i<inArg._length;i++)
727 	g_assert (strcmp (inArg._buffer[i], constants_SEQ_STRING_IN[i]) == 0);
728 
729   for (i=0;i<inoutArg._length;i++)
730 	g_assert (strcmp (inoutArg._buffer[i], constants_SEQ_STRING_INOUT_OUT[i]) == 0);
731 
732   for (i=0;i<outArg->_length;i++)
733 	g_assert (strcmp (outArg->_buffer[i], constants_SEQ_STRING_OUT[i]) == 0);
734 
735   for (i=0;i<retn->_length;i++)
736 	g_assert (strcmp (retn->_buffer[i], constants_SEQ_STRING_RETN[i]) == 0);
737 
738   g_warning ("FIXME: opMassiveSeq fails - due to max. size check");
739   /*  long_retn = test_SequenceServer_opMassiveSeq(objref, ev);
740       g_assert (ev->_major == CORBA_NO_EXCEPTION);
741       CORBA_free (long_retn); */
742 
743   CORBA_free (inArg._buffer);
744   CORBA_free (inoutArg._buffer);
745   CORBA_free (outArg);
746   CORBA_free (retn);
747 
748   CORBA_Object_release (objref, ev);
749   g_assert (ev->_major == CORBA_NO_EXCEPTION);
750 }
751 
752 static void
testAnySequence(test_TestFactory factory,CORBA_Environment * ev)753 testAnySequence (test_TestFactory   factory,
754                  CORBA_Environment *ev)
755 {
756     test_AnySeq *any_retn, *copy;
757     test_SequenceServer objref;
758 
759     d_print ("Testing sequence<any>...\n");
760     objref = test_TestFactory_getSequenceServer (factory, ev);
761     g_assert (ev->_major == CORBA_NO_EXCEPTION);
762 
763     any_retn = test_SequenceServer_opAnySeq (objref, ev);
764     g_assert (ev->_major == CORBA_NO_EXCEPTION);
765     copy = ORBit_copy_value (any_retn, TC_test_AnySeq);
766     CORBA_free (any_retn);
767 
768     CORBA_Object_release (objref, ev);
769     g_assert (ev->_major == CORBA_NO_EXCEPTION);
770 }
771 
772 static void
testBoundedSequence(test_TestFactory factory,CORBA_Environment * ev)773 testBoundedSequence (test_TestFactory   factory,
774 		     CORBA_Environment *ev)
775 {
776   test_SequenceServer objref;
777   test_BoundedStructSeq inArg, inoutArg, *outArg, *retn;
778   guint i;
779   d_print ("Testing bounded sequences...\n");
780   objref = test_TestFactory_getSequenceServer (factory, ev);
781   g_assert (ev->_major == CORBA_NO_EXCEPTION);
782 
783 
784   inArg._buffer  = CORBA_sequence_test_CompoundStruct_allocbuf (2);
785   inArg._length  = 2;
786   inArg._maximum = 2;
787   CORBA_sequence_set_release (&inoutArg, CORBA_TRUE);
788 
789   for (i=0;i<inArg._length;i++){
790 	inArg._buffer[i].a.a = CORBA_string_dup (constants_SEQ_STRING_IN[i]);
791   }
792 
793   inoutArg._buffer  = CORBA_sequence_test_CompoundStruct_allocbuf (2);
794   inoutArg._length  = 2;
795   inoutArg._maximum = 2;
796   CORBA_sequence_set_release (&inoutArg, CORBA_TRUE);
797 
798   for (i=0;i<inoutArg._length;i++){
799 	inoutArg._buffer[i].a.a = CORBA_string_dup (constants_SEQ_STRING_INOUT_IN[i]);
800   }
801 
802   retn = test_SequenceServer_opBoundedStructSeq (objref, &inArg, &inoutArg, &outArg, ev);
803   g_assert (ev->_major == CORBA_NO_EXCEPTION);
804 
805 
806   for (i=0;i<inArg._length;i++){
807 	g_assert (strcmp (inArg._buffer[i].a.a, constants_SEQ_STRING_IN[i]) == 0);
808   }
809 
810   for (i=0;i<inoutArg._length;i++){
811 	g_assert (strcmp (inoutArg._buffer[i].a.a, constants_SEQ_STRING_INOUT_OUT[i]) == 0);
812   }
813 
814   for (i=0;i<outArg->_length;i++){
815 	g_assert (strcmp (outArg->_buffer[i].a.a, constants_SEQ_STRING_OUT[i]) == 0);
816   }
817 
818   for (i=0;i<retn->_length;i++){
819 	g_assert (strcmp (retn->_buffer[i].a.a, constants_SEQ_STRING_RETN[i]) == 0);
820   }
821 
822   CORBA_free (inArg._buffer);
823   CORBA_free (inoutArg._buffer);
824   CORBA_free (outArg);
825   CORBA_free (retn);
826   CORBA_Object_release (objref, ev);
827   g_assert (ev->_major == CORBA_NO_EXCEPTION);
828 }
829 
830 static void
testFixedLengthUnion(test_TestFactory factory,CORBA_Environment * ev)831 testFixedLengthUnion (test_TestFactory   factory,
832 		      CORBA_Environment *ev)
833 {
834   test_UnionServer objref;
835   test_FixedLengthUnion inArg, inoutArg, outArg, retn;
836   d_print ("Testing fixed length unions...\n");
837   objref = test_TestFactory_getUnionServer (factory, ev);
838   g_assert (ev->_major == CORBA_NO_EXCEPTION);
839 
840   inArg._u.x = constants_LONG_IN;
841   inArg._d = 'a';
842 
843   inoutArg._u.y = 't';
844   inoutArg._d = 'b';
845 
846   retn = test_UnionServer_opFixed (objref, &inArg, &inoutArg, &outArg, ev);
847   g_assert (ev->_major == CORBA_NO_EXCEPTION);
848 
849   g_assert (inArg._d == 'a');
850   g_assert (inArg._u.x == constants_LONG_IN);
851   g_assert (inoutArg._d == 'c');
852   g_assert (inoutArg._u.z == TRUE);
853   g_assert (outArg._d == 'a');
854   g_assert (outArg._u.x == constants_LONG_OUT);
855   g_assert (retn._d == 'd');
856   g_assert (retn._u.z == FALSE);
857 
858   CORBA_Object_release (objref, ev);
859   g_assert (ev->_major == CORBA_NO_EXCEPTION);
860 }
861 
862 static void
testVariableLengthUnion(test_TestFactory factory,CORBA_Environment * ev)863 testVariableLengthUnion (test_TestFactory   factory,
864 			 CORBA_Environment *ev)
865 {
866   test_UnionServer objref;
867   test_VariableLengthUnion inArg, inoutArg, *outArg, *retn;
868   d_print ("Testing variable length unions...\n");
869   objref = test_TestFactory_getUnionServer (factory, ev);
870   g_assert (ev->_major == CORBA_NO_EXCEPTION);
871 
872   inArg._u.x = constants_LONG_IN;
873   inArg._d = 1;
874 
875   inoutArg._u.y = CORBA_string_dup (constants_STRING_INOUT_IN);
876   inoutArg._d = 2;
877 
878   retn = test_UnionServer_opVariable (objref, &inArg, &inoutArg, &outArg, ev);
879   g_assert (ev->_major == CORBA_NO_EXCEPTION);
880 
881   g_assert (inArg._d == 1);
882   g_assert (inArg._u.x == constants_LONG_IN);
883   g_assert (inoutArg._d == 3);
884   g_assert (inoutArg._u.z == TRUE);
885   g_assert (outArg->_d == 1);
886   g_assert (outArg->_u.x == constants_LONG_OUT);
887   g_assert (retn->_d == 4);
888   g_assert (retn->_u.z == FALSE);
889 
890   CORBA_free (outArg);
891   CORBA_free (retn);
892 
893   CORBA_Object_release (objref, ev);
894   g_assert (ev->_major == CORBA_NO_EXCEPTION);
895 }
896 
897 static void
testMiscUnions(test_TestFactory factory,CORBA_Environment * ev)898 testMiscUnions (test_TestFactory   factory,
899 	        CORBA_Environment *ev)
900 {
901 	test_UnionServer   obj;
902 	test_EnumUnion     retn;
903 	test_unionSeq      inSeq;
904 	test_VariableLengthUnion inSeq_buffer[3];
905 	test_BooleanUnion  inArg;
906 	test_ArrayUnion   *outArg;
907 	int                i;
908 
909 	d_print ("Testing misc type unions...\n");
910 	obj = test_TestFactory_getUnionServer (factory, ev);
911 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
912 
913 	inSeq._length  = inSeq._maximum = 3;
914 	inSeq._buffer  = inSeq_buffer;
915 	inSeq._release = CORBA_FALSE;
916 	inSeq._buffer [0]._d   = 4;
917 	inSeq._buffer [0]._u.z = CORBA_TRUE;
918 	inSeq._buffer [1]._d   = 2;
919 	inSeq._buffer [1]._u.y = "blah";
920 	inSeq._buffer [2]._d   = 55;
921 	inSeq._buffer [2]._u.w = constants_LONG_IN;
922 
923 	inArg._d   = 1;
924 	inArg._u.y = "blah de blah";
925 
926 	retn = test_UnionServer_opMisc (obj, &inSeq, &inArg, &outArg, ev);
927 
928 	g_assert (inSeq._length == 3);
929 	g_assert (inSeq._buffer [0]._d == 4);
930 	g_assert (inSeq._buffer [0]._u.z == CORBA_TRUE);
931 	g_assert (inSeq._buffer [1]._d == 2);
932 	g_assert (!strcmp (inSeq._buffer [1]._u.y, "blah"));
933 	g_assert (inSeq._buffer [2]._d == 55);
934 	g_assert (inSeq._buffer [2]._u.w == constants_LONG_IN);
935 	g_assert (inArg._d == 1);
936 	g_assert (!strcmp (inArg._u.y, "blah de blah"));
937 
938 	g_assert (outArg->_d == 22);
939 	for (i = 0; i < 20; i++) {
940 		char *tmp;
941 
942 		tmp = g_strdup_printf ("Numero %d", i);
943 		g_assert (!strcmp (outArg->_u.d [i], tmp));
944 		g_free (tmp);
945 	}
946 
947 	g_assert (retn._d == test_EnumUnion_red);
948 	g_assert (retn._u.x == constants_LONG_IN);
949 
950 	CORBA_free (outArg);
951 
952 	CORBA_Object_release (obj, ev);
953   	g_assert (ev->_major == CORBA_NO_EXCEPTION);
954 }
955 
956 static void
testUnionArray(test_TestFactory factory,CORBA_Environment * ev)957 testUnionArray (test_TestFactory   factory,
958 	        CORBA_Environment *ev)
959 {
960 	test_UnionServer                  obj;
961 	test_FixedLengthUnionArray_slice *retn;
962 	test_FixedLengthUnionArray        inArg;
963 	test_FixedLengthUnionArray        inoutArg;
964 	test_FixedLengthUnionArray        outArg;
965 
966 	d_print ("Testing union array...\n");
967 	obj = test_TestFactory_getUnionServer (factory, ev);
968 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
969 
970 	inArg[0]._d = 'a';
971 	inArg[0]._u.x = constants_LONG_IN;
972 	inArg[1]._d = 'b';
973 	inArg[1]._u.y = constants_CHAR_IN;
974 	inArg[2]._d = 'c';
975 	inArg[3]._d = 'e';
976 	inArg[3]._u.v.a = constants_SHORT_IN;
977 
978 	inoutArg[0]._d = 'a';
979 	inoutArg[0]._u.x = constants_LONG_INOUT_IN;
980 	inoutArg[1]._d = 'b';
981 	inoutArg[1]._u.y = constants_CHAR_INOUT_IN;
982 	inoutArg[2]._d = 'c';
983 	inoutArg[3]._d = 'e';
984 	inoutArg[3]._u.v.a = constants_SHORT_INOUT_IN;
985 
986 	retn = test_UnionServer_opFixedLengthUnionArray (obj, inArg, inoutArg, outArg, ev);
987 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
988 
989 	g_assert (inArg[0]._d == 'a');
990 	g_assert (inArg[0]._u.x == constants_LONG_IN);
991 	g_assert (inArg[1]._d == 'b');
992 	g_assert (inArg[1]._u.y == constants_CHAR_IN);
993 	g_assert (inArg[2]._d == 'c');
994 	g_assert (inArg[3]._d == 'e');
995 	g_assert (inArg[3]._u.v.a == constants_SHORT_IN);
996 
997 	g_assert (inoutArg[0]._d == 'a');
998 	g_assert (inoutArg[0]._u.x == constants_LONG_INOUT_OUT);
999 	g_assert (inoutArg[1]._d == 'b');
1000 	g_assert (inoutArg[1]._u.y == constants_CHAR_INOUT_OUT);
1001 	g_assert (inoutArg[2]._d == 'c');
1002 	g_assert (inoutArg[3]._d == 'e');
1003 	g_assert (inoutArg[3]._u.v.a == constants_SHORT_INOUT_OUT);
1004 
1005 	g_assert (outArg[0]._d == 'a');
1006 	g_assert (outArg[0]._u.x == constants_LONG_OUT);
1007 	g_assert (outArg[1]._d == 'b');
1008 	g_assert (outArg[1]._u.y == constants_CHAR_OUT);
1009 	g_assert (outArg[2]._d == 'c');
1010 	g_assert (outArg[3]._d == 'e');
1011 	g_assert (outArg[3]._u.v.a == constants_SHORT_OUT);
1012 
1013 	g_assert (retn[0]._d == 'a');
1014 	g_assert (retn[0]._u.x == constants_LONG_RETN);
1015 	g_assert (retn[1]._d == 'b');
1016 	g_assert (retn[1]._u.y == constants_CHAR_RETN);
1017 	g_assert (retn[2]._d == 'c');
1018 	g_assert (retn[3]._d == 'e');
1019 	g_assert (retn[3]._u.v.a == constants_SHORT_RETN);
1020 
1021 	CORBA_free (retn);
1022 
1023 	CORBA_Object_release (obj, ev);
1024   	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1025 }
1026 
1027 static void
testLongArray(test_ArrayServer objref,CORBA_Environment * ev)1028 testLongArray (test_ArrayServer   objref,
1029 	       CORBA_Environment *ev)
1030 {
1031   int i;
1032   test_LongArray inArg, inoutArg, outArg;
1033   test_LongArray_slice *retn;
1034 
1035   for (i=0;i<test_SequenceLen;i++)
1036 	inArg[i] = constants_SEQ_LONG_IN[i];
1037 
1038   for (i=0;i<test_SequenceLen;i++)
1039 	inoutArg[i] = constants_SEQ_LONG_INOUT_IN[i];
1040 
1041   retn = test_ArrayServer_opLongArray (objref, inArg, inoutArg, outArg, ev);
1042   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1043 
1044   for (i=0;i<test_SequenceLen;i++)
1045 	g_assert (inArg[i]==constants_SEQ_LONG_IN[i]);
1046   for (i=0;i<test_SequenceLen;i++)
1047 	g_assert (inoutArg[i]==constants_SEQ_LONG_INOUT_OUT[i]);
1048   for (i=0;i<test_SequenceLen;i++)
1049 	g_assert (outArg[i]==constants_SEQ_LONG_OUT[i]);
1050   for (i=0;i<test_SequenceLen;i++)
1051 	g_assert (retn[i]==constants_SEQ_LONG_RETN[i]);
1052 
1053   CORBA_free (retn);
1054 }
1055 
1056 static void
testOctetArray(test_ArrayServer objref,CORBA_Environment * ev)1057 testOctetArray (test_ArrayServer   objref,
1058 		CORBA_Environment *ev)
1059 {
1060   int i;
1061   test_OctetArray inArg, inoutArg, outArg;
1062   test_OctetArray_slice *retn;
1063 
1064   for (i=0;i<test_SequenceLen;i++)
1065 	inArg[i] = constants_SEQ_OCTET_IN[i];
1066 
1067   for (i=0;i<test_SequenceLen;i++)
1068 	inoutArg[i] = constants_SEQ_OCTET_INOUT_IN[i];
1069 
1070   retn = test_ArrayServer_opOctetArray (objref, inArg, inoutArg, outArg, ev);
1071   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1072 
1073   for (i=0;i<test_SequenceLen;i++)
1074 	g_assert (inArg[i]==constants_SEQ_OCTET_IN[i]);
1075   for (i=0;i<test_SequenceLen;i++)
1076 	g_assert (inoutArg[i]==constants_SEQ_OCTET_INOUT_OUT[i]);
1077   for (i=0;i<test_SequenceLen;i++)
1078 	g_assert (outArg[i]==constants_SEQ_OCTET_OUT[i]);
1079   for (i=0;i<test_SequenceLen;i++)
1080 	g_assert (retn[i]==constants_SEQ_OCTET_RETN[i]);
1081 
1082   CORBA_free (retn);
1083 }
1084 
1085 static void
testFixedLengthStructArray(test_ArrayServer objref,CORBA_Environment * ev)1086 testFixedLengthStructArray (test_ArrayServer   objref,
1087 			    CORBA_Environment *ev)
1088 {
1089   int i;
1090   test_FixedLengthStructArray inArg, inoutArg, outArg;
1091   test_FixedLengthStructArray_slice *retn;
1092 
1093   for (i=0;i<test_SequenceLen;i++)
1094 	inArg[i].a = constants_SEQ_OCTET_IN[i];
1095 
1096   for (i=0;i<test_SequenceLen;i++)
1097 	inoutArg[i].a = constants_SEQ_OCTET_INOUT_IN[i];
1098 
1099   retn = test_ArrayServer_opFixedLengthStructArray (objref, inArg, inoutArg, outArg, ev);
1100   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1101 
1102   for (i=0;i<test_SequenceLen;i++)
1103 	g_assert (inArg[i].a==constants_SEQ_OCTET_IN[i]);
1104   for (i=0;i<test_SequenceLen;i++)
1105 	g_assert (inoutArg[i].a==constants_SEQ_OCTET_INOUT_OUT[i]);
1106   for (i=0;i<test_SequenceLen;i++)
1107 	g_assert (outArg[i].a==constants_SEQ_OCTET_OUT[i]);
1108   for (i=0;i<test_SequenceLen;i++)
1109 	g_assert (retn[i].a==constants_SEQ_OCTET_RETN[i]);
1110 
1111   CORBA_free (retn);
1112 }
1113 
1114 static void
testFixedLengthArray(test_TestFactory factory,CORBA_Environment * ev)1115 testFixedLengthArray (test_TestFactory   factory,
1116 		      CORBA_Environment *ev)
1117 {
1118 
1119   test_ArrayServer objref;
1120   d_print ("Testing arrays with fixed length members...\n");
1121   objref = test_TestFactory_getArrayServer (factory, ev);
1122   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1123 
1124   testLongArray (objref, ev);
1125   testOctetArray (objref, ev);
1126   testFixedLengthStructArray (objref, ev);
1127 
1128   CORBA_Object_release (objref, ev);
1129   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1130 }
1131 
1132 static void
testStrArray(test_ArrayServer objref,CORBA_Environment * ev)1133 testStrArray (test_ArrayServer   objref,
1134 	      CORBA_Environment *ev)
1135 {
1136   test_StrArray inArg, inoutArg;
1137   test_StrArray_slice *outArg, *retn;
1138   test_StrArrayMultiDimensional_slice *multidim;
1139   int i, n0, n1, n2;
1140 
1141   for (i=0;i<test_SequenceLen;i++)
1142 	inArg[i] = CORBA_string_dup (constants_SEQ_STRING_IN[i]);
1143 
1144   for (i=0;i<test_SequenceLen;i++)
1145 	inoutArg[i] = CORBA_string_dup (constants_SEQ_STRING_INOUT_IN[i]);
1146 
1147   retn = test_ArrayServer_opStrArray (objref, inArg, inoutArg, &outArg, ev);
1148   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1149 
1150   for (i=0;i<test_SequenceLen;i++)
1151 	CORBA_free (inArg[i]);
1152 
1153   for (i=0;i<test_SequenceLen;i++)
1154         CORBA_free (inoutArg[i]);
1155 
1156   CORBA_free (outArg);
1157   CORBA_free (retn);
1158 
1159   multidim = test_StrArrayMultiDimensional__alloc ();
1160   for (n0 = 0; n0 < 2; n0++) {
1161 	for (n1 = 0; n1 < 3; n1++) {
1162 	  for (n2 = 0; n2 < 5; n2++) {
1163 		multidim[n0][n1][n2] = CORBA_string_dup (constants_SEQ_STRING_INOUT_IN[0]);
1164 	  }
1165 	}
1166   }
1167   CORBA_free (multidim);
1168 
1169 }
1170 
1171 static void
testAlignHoleStructArray(test_ArrayServer objref,CORBA_Environment * ev)1172 testAlignHoleStructArray (test_ArrayServer   objref,
1173 			  CORBA_Environment *ev)
1174 {
1175   int i;
1176   test_AlignHoleStructArray inArg, inoutArg, outArg;
1177   test_AlignHoleStructArray_slice *retn;
1178 
1179   for (i=0;i<test_SequenceLen;i++)
1180 	inArg[i].a.a = constants_SEQ_OCTET_IN[i];
1181   for (i=0;i<test_SequenceLen;i++)
1182 	inArg[i].a.b = constants_SEQ_OCTET_IN[i];
1183   for (i=0;i<test_SequenceLen;i++)
1184 	inArg[i].b = constants_SEQ_OCTET_IN[i];
1185 
1186   for (i=0;i<test_SequenceLen;i++)
1187 	inoutArg[i].a.a = constants_SEQ_OCTET_INOUT_IN[i];
1188   for (i=0;i<test_SequenceLen;i++)
1189 	inoutArg[i].a.b = constants_SEQ_OCTET_INOUT_IN[i];
1190   for (i=0;i<test_SequenceLen;i++)
1191 	inoutArg[i].b = constants_SEQ_OCTET_INOUT_IN[i];
1192 
1193   retn = test_ArrayServer_opAlignHoleStructArray (objref, inArg, inoutArg, outArg, ev);
1194   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1195 
1196   for (i=0;i<test_SequenceLen;i++)
1197 	g_assert (inArg[i].a.a==constants_SEQ_OCTET_IN[i]);
1198   for (i=0;i<test_SequenceLen;i++)
1199 	g_assert (inArg[i].a.b==constants_SEQ_OCTET_IN[i]);
1200   for (i=0;i<test_SequenceLen;i++)
1201 	g_assert (inArg[i].b==(CORBA_char)constants_SEQ_OCTET_IN[i]);
1202 
1203   for (i=0;i<test_SequenceLen;i++)
1204 	g_assert (inoutArg[i].a.a==constants_SEQ_OCTET_INOUT_OUT[i]);
1205   for (i=0;i<test_SequenceLen;i++)
1206 	g_assert (inoutArg[i].a.b==constants_SEQ_OCTET_INOUT_OUT[i]);
1207   for (i=0;i<test_SequenceLen;i++)
1208 	g_assert (inoutArg[i].b==(CORBA_char)constants_SEQ_OCTET_INOUT_OUT[i]);
1209 
1210   for (i=0;i<test_SequenceLen;i++)
1211 	g_assert (outArg[i].a.a==constants_SEQ_OCTET_OUT[i]);
1212   for (i=0;i<test_SequenceLen;i++)
1213 	g_assert (outArg[i].a.b==constants_SEQ_OCTET_OUT[i]);
1214   for (i=0;i<test_SequenceLen;i++)
1215 	g_assert (outArg[i].b==(CORBA_char)constants_SEQ_OCTET_OUT[i]);
1216 
1217   for (i=0;i<test_SequenceLen;i++)
1218 	g_assert (retn[i].a.a==constants_SEQ_OCTET_RETN[i]);
1219   for (i=0;i<test_SequenceLen;i++)
1220 	g_assert (retn[i].a.b==constants_SEQ_OCTET_RETN[i]);
1221   for (i=0;i<test_SequenceLen;i++)
1222 	g_assert (retn[i].b==(CORBA_char)constants_SEQ_OCTET_RETN[i]);
1223 
1224   CORBA_free (retn);
1225 }
1226 
1227 static void
testVariableLengthArray(test_TestFactory factory,CORBA_Environment * ev)1228 testVariableLengthArray (test_TestFactory   factory,
1229 			 CORBA_Environment *ev)
1230 {
1231   test_ArrayServer objref;
1232 
1233   d_print ("Testing arrays with variable length members...\n");
1234   objref = test_TestFactory_getArrayServer (factory, ev);
1235   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1236 
1237   testStrArray (objref, ev);
1238   testAlignHoleStructArray (objref, ev);
1239 
1240   CORBA_Object_release (objref, ev);
1241   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1242 }
1243 
1244 static void
testAnyLong(test_TestFactory factory,CORBA_Environment * ev)1245 testAnyLong (test_TestFactory   factory,
1246 	     CORBA_Environment *ev)
1247 {
1248   test_AnyServer objref;
1249   CORBA_any inArg, inoutArg, *outArg, *retn;
1250   CORBA_long tmp, tmp1;
1251 
1252   d_print ("Testing any with longs...\n");
1253   objref = test_TestFactory_getAnyServer (factory, ev);
1254   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1255 
1256   tmp = constants_LONG_IN;
1257   inArg._type = (CORBA_TypeCode)TC_CORBA_long;
1258   inArg._value = &tmp;
1259   CORBA_any_set_release (&inArg, CORBA_FALSE);
1260 
1261   inoutArg._type = (CORBA_TypeCode)TC_CORBA_long;
1262   tmp1 = constants_LONG_INOUT_IN;
1263   inoutArg._value = &tmp1;
1264   CORBA_any_set_release (&inoutArg, CORBA_FALSE);
1265 
1266   retn = test_AnyServer_opAnyLong (objref, &inArg, &inoutArg, &outArg, ev);
1267   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1268 
1269   g_assert ( CORBA_TypeCode_equal (inArg._type, TC_CORBA_long, ev) );
1270   g_assert (* (CORBA_long*)inArg._value == constants_LONG_IN);
1271 
1272   g_assert ( CORBA_TypeCode_equal (inoutArg._type, TC_CORBA_long, ev) );
1273   g_assert (* (CORBA_long*)inoutArg._value == constants_LONG_INOUT_OUT);
1274 
1275   g_assert ( CORBA_TypeCode_equal (outArg->_type, TC_CORBA_long, ev) );
1276   g_assert (* (CORBA_long*)outArg->_value == constants_LONG_OUT);
1277 
1278   g_assert ( CORBA_TypeCode_equal (retn->_type, TC_CORBA_long, ev) );
1279   g_assert (* (CORBA_long*)retn->_value == constants_LONG_RETN);
1280 
1281   if (CORBA_any_get_release (&inArg)){
1282 	CORBA_free (inArg._value);
1283 	CORBA_Object_release ((CORBA_Object)inArg._type, ev);
1284   }
1285 
1286   if (CORBA_any_get_release (&inoutArg)){
1287 	CORBA_free (inoutArg._value);
1288 	CORBA_Object_release ((CORBA_Object)inoutArg._type, ev);
1289   }
1290 
1291   CORBA_free (outArg);
1292   CORBA_free (retn);
1293 
1294   CORBA_Object_release (objref, ev);
1295   g_assert (ev->_major == CORBA_NO_EXCEPTION);
1296 }
1297 
1298 static void
testAnyString(test_TestFactory factory,CORBA_Environment * ev)1299 testAnyString (test_TestFactory   factory,
1300 	       CORBA_Environment *ev)
1301 {
1302 	test_AnyServer objref;
1303 	CORBA_any inArg, inoutArg, *outArg, *retn;
1304 
1305 	d_print ("Testing any with strings...\n");
1306 	objref = test_TestFactory_getAnyServer (factory, ev);
1307 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1308 
1309 	inArg._type = (CORBA_TypeCode)TC_CORBA_string;
1310 	inArg._value = &constants_STRING_IN;
1311 	CORBA_any_set_release (&inArg, CORBA_FALSE);
1312 
1313 	inoutArg._type = (CORBA_TypeCode)TC_CORBA_string;
1314 	inoutArg._value = &constants_STRING_INOUT_IN;
1315 	CORBA_any_set_release (&inoutArg, CORBA_FALSE);
1316 
1317 	retn = test_AnyServer_opAnyString (objref, &inArg, &inoutArg, &outArg, ev);
1318 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1319 
1320 	g_assert (CORBA_TypeCode_equal (inArg._type, TC_CORBA_string, ev));
1321 	g_assert (strcmp (* (CORBA_char **)inArg._value, constants_STRING_IN) == 0);
1322 
1323 	g_assert (CORBA_TypeCode_equal (inoutArg._type, TC_CORBA_string, ev) );
1324 	g_assert (strcmp (* (CORBA_char **)inoutArg._value, constants_STRING_INOUT_OUT) == 0);
1325 
1326 	g_assert (CORBA_TypeCode_equal (outArg->_type, TC_CORBA_string, ev) );
1327 	g_assert (strcmp (* (CORBA_char **)outArg->_value, constants_STRING_OUT) == 0);
1328 
1329 	g_assert (CORBA_TypeCode_equal (retn->_type, TC_CORBA_string, ev) );
1330 	g_assert (strcmp (* (CORBA_char **)retn->_value, constants_STRING_RETN) == 0);
1331 
1332 	if (CORBA_any_get_release (&inArg)){
1333 		CORBA_free (inArg._value);
1334 		CORBA_Object_release ((CORBA_Object)inArg._type, ev);
1335 	}
1336 
1337 	if (CORBA_any_get_release (&inoutArg)){
1338 		CORBA_free (inoutArg._value);
1339 		CORBA_Object_release ((CORBA_Object)inoutArg._type, ev);
1340 	}
1341 
1342 	CORBA_free (outArg);
1343 	CORBA_free (retn);
1344 
1345 	CORBA_Object_release (objref, ev);
1346 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1347 }
1348 
1349 static void
testAnyStrSeq(test_TestFactory factory,CORBA_Environment * ev)1350 testAnyStrSeq (test_TestFactory   factory,
1351 	       CORBA_Environment *ev)
1352 {
1353 	test_AnyServer objref;
1354 	CORBA_any     *retn;
1355 
1356 	d_print ("Testing any with string sequences ...\n");
1357 
1358 	objref = test_TestFactory_getAnyServer(factory,ev);
1359 	g_assert(ev->_major == CORBA_NO_EXCEPTION);
1360 
1361 	retn = test_AnyServer_opAnyStrSeq (objref, ev);
1362 	g_assert(ev->_major == CORBA_NO_EXCEPTION);
1363 
1364 	CORBA_free (retn);
1365 
1366 	CORBA_Object_release (objref, ev);
1367 }
1368 
1369 static void
testAnyStruct(test_TestFactory factory,CORBA_Environment * ev)1370 testAnyStruct (test_TestFactory   factory,
1371 	       CORBA_Environment *ev)
1372 {
1373 	test_AnyServer objref;
1374 	CORBA_any inArg, inoutArg, *outArg, *retn;
1375 	test_VariableLengthStruct inArgStruct;
1376 	test_VariableLengthStruct * inoutArgStruct;
1377 
1378 	d_print ("Testing any with structs...\n");
1379 
1380 	objref = test_TestFactory_getAnyServer (factory, ev);
1381 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1382 
1383 	inoutArgStruct = test_VariableLengthStruct__alloc ();
1384 	inArgStruct.a= (CORBA_char*)constants_STRING_IN; /* const cast */
1385 	inArg._type = (CORBA_TypeCode)TC_test_VariableLengthStruct;
1386 	inArg._value = &inArgStruct;
1387 	CORBA_any_set_release (&inArg, CORBA_FALSE);
1388 
1389 
1390 	inoutArgStruct->a = CORBA_string_dup (constants_STRING_INOUT_IN);
1391 	inoutArg._type = (CORBA_TypeCode)TC_test_VariableLengthStruct;
1392 	inoutArg._value = inoutArgStruct;
1393 	CORBA_any_set_release (&inoutArg, CORBA_TRUE);
1394 
1395 	retn = test_AnyServer_opAnyStruct (objref, &inArg, &inoutArg, &outArg, ev);
1396 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1397 
1398 
1399 	g_assert (CORBA_TypeCode_equal (inArg._type, TC_test_VariableLengthStruct, ev));
1400 	g_assert (strcmp ((* (test_VariableLengthStruct*)inArg._value).a, constants_STRING_IN) == 0);
1401 
1402 	g_assert (CORBA_TypeCode_equal (inoutArg._type, TC_test_VariableLengthStruct, ev) );
1403 	g_assert (strcmp ((* (test_VariableLengthStruct*)inoutArg._value).a, constants_STRING_INOUT_OUT) == 0);
1404 
1405 	g_assert (CORBA_TypeCode_equal (outArg->_type, TC_test_VariableLengthStruct, ev) );
1406 	g_assert (strcmp ((* (test_VariableLengthStruct*)outArg->_value).a, constants_STRING_OUT) == 0);
1407 
1408 	g_assert (CORBA_TypeCode_equal (retn->_type, TC_test_VariableLengthStruct, ev) );
1409 	g_assert (strcmp ((* (test_VariableLengthStruct*)retn->_value).a, constants_STRING_RETN) == 0);
1410 
1411 
1412 	if (CORBA_any_get_release (&inArg)){
1413 		/* This shouldn't be called */
1414 		CORBA_free (inArg._value);
1415 		CORBA_Object_release ((CORBA_Object)inArg._type, ev);
1416 	}
1417 
1418 	if (CORBA_any_get_release (&inoutArg)){
1419 		CORBA_free (inoutArg._value);
1420 		CORBA_Object_release ((CORBA_Object)inoutArg._type, ev);
1421 	}
1422 
1423 	CORBA_free (outArg);
1424 	CORBA_free (retn);
1425 
1426 	CORBA_Object_release (objref, ev);
1427 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1428 
1429 }
1430 
1431 static void
testSequenceOfAny(test_TestFactory factory,CORBA_Environment * ev)1432 testSequenceOfAny (test_TestFactory   factory,
1433 		   CORBA_Environment *ev)
1434 {
1435 	/* this test just checks the memory management for seq of any */
1436 
1437 	test_AnySeq anyseq;
1438 	int i;
1439 
1440 	d_print ("Testing Sequence of Any...\n");
1441 
1442 	anyseq._buffer  = CORBA_sequence_CORBA_any_allocbuf (2);
1443 	anyseq._length  = 2;
1444 	CORBA_sequence_set_release (&anyseq, CORBA_TRUE);
1445 
1446 	for (i = 0; i < anyseq._length; i++) {
1447 		anyseq._buffer [i]._type = (CORBA_TypeCode) TC_CORBA_string;
1448 		anyseq._buffer [i]._value = &constants_STRING_IN;
1449 		CORBA_any_set_release (
1450 			&anyseq._buffer[i], CORBA_FALSE);
1451 	}
1452 
1453 	CORBA_free (anyseq._buffer);
1454 }
1455 
1456 static void
testAnyException(test_TestFactory factory,CORBA_Environment * ev)1457 testAnyException (test_TestFactory   factory,
1458 		  CORBA_Environment *ev)
1459 {
1460 	CORBA_any *inArg;
1461 	test_TestException *testex;
1462 
1463 	d_print ("Testing Any with exception...\n");
1464 
1465 	inArg = CORBA_any__alloc ();
1466 	testex = test_TestException__alloc ();
1467 	inArg->_type = (CORBA_TypeCode) TC_test_TestException;
1468 	inArg->_value = testex;
1469 	CORBA_any_set_release (inArg, CORBA_TRUE);
1470 
1471 	CORBA_free (inArg);
1472 }
1473 
1474 static void
testAnyEquivalence(test_TestFactory factory,CORBA_Environment * ev)1475 testAnyEquivalence (test_TestFactory   factory,
1476 		    CORBA_Environment *ev)
1477 {
1478 	test_unionSeq *aseq, *bseq;
1479 	CORBA_any     *a, *b;
1480 
1481 	d_print ("Testing Anys equivalence...\n");
1482 
1483 	a = CORBA_any__alloc ();
1484 	b = CORBA_any__alloc ();
1485 
1486 	a->_type = b->_type = (CORBA_TypeCode) TC_test_unionSeq;
1487 
1488 	aseq = test_unionSeq__alloc ();
1489 	bseq = test_unionSeq__alloc ();
1490 	aseq->_length  = aseq->_maximum = 3;
1491 	bseq->_length  = bseq->_maximum = 3;
1492 	aseq->_buffer  = test_unionSeq_allocbuf (3);
1493 	bseq->_buffer  = test_unionSeq_allocbuf (3);
1494 	bseq->_release = aseq->_release = CORBA_TRUE;
1495 	bseq->_buffer [0]._d   = aseq->_buffer [0]._d   = 4;
1496 	bseq->_buffer [0]._u.z = aseq->_buffer [0]._u.z = CORBA_TRUE;
1497 	bseq->_buffer [1]._d   = aseq->_buffer [1]._d   = 2;
1498 	aseq->_buffer [1]._u.y = CORBA_string_dup ("blah");
1499 	bseq->_buffer [1]._u.y = CORBA_string_dup ("blah");
1500 
1501 	bseq->_buffer [2]._d   = aseq->_buffer [2]._d   = 55;
1502 	bseq->_buffer [2]._u.w = aseq->_buffer [2]._u.w = constants_LONG_IN;
1503 
1504 	a->_value = aseq;
1505 	b->_value = bseq;
1506 
1507 	CORBA_any_set_release (a, CORBA_TRUE);
1508 	CORBA_any_set_release (b, CORBA_TRUE);
1509 
1510 	g_assert (ORBit_any_equivalent (a, b, ev));
1511 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1512 
1513 	bseq->_buffer [0]._u.z = CORBA_FALSE;
1514 
1515 	g_assert (!ORBit_any_equivalent (a, b, ev));
1516 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1517 
1518 	CORBA_free (b);
1519 	b = NULL;
1520 	bseq = NULL;
1521 
1522 	b = ORBit_copy_value (a, TC_CORBA_any);
1523 
1524 	g_assert (b != NULL);
1525 	g_assert (ORBit_any_equivalent (a, b, ev));
1526 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1527 
1528 	bseq = (test_unionSeq *) b->_value;
1529 	bseq->_buffer [0]._u.z = CORBA_FALSE;
1530 
1531 	g_assert (!ORBit_any_equivalent (a, b, ev));
1532 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1533 
1534 	CORBA_free (a);
1535 	CORBA_free (b);
1536 }
1537 
1538 static void
testTypeCode(test_TestFactory factory,CORBA_Environment * ev)1539 testTypeCode (test_TestFactory   factory,
1540 	      CORBA_Environment *ev)
1541 {
1542 	test_AnyServer objref;
1543 	CORBA_TypeCode inArg, inoutArg, outArg, retn;
1544 
1545 	d_print ("Testing TypeCodes...\n");
1546 	objref = test_TestFactory_getAnyServer (factory, ev);
1547 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1548 
1549 	inArg = TC_test_ArrayUnion;
1550 	inoutArg = TC_test_AnyServer;
1551 
1552 	retn = test_AnyServer_opTypeCode (objref, inArg, &inoutArg, &outArg, ev);
1553 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1554 
1555 	g_assert (CORBA_TypeCode_equal (inArg, TC_test_ArrayUnion, ev));
1556 	g_assert (CORBA_TypeCode_equal (inoutArg, TC_test_TestException, ev));
1557 	g_assert (CORBA_TypeCode_equal (outArg, TC_test_AnEnum, ev));
1558 	g_assert (CORBA_TypeCode_equal (retn, TC_test_VariableLengthStruct, ev));
1559 
1560 	CORBA_Object_release ((CORBA_Object)inArg, ev);
1561 	CORBA_Object_release ((CORBA_Object)inoutArg, ev);
1562 	CORBA_Object_release ((CORBA_Object)outArg, ev);
1563 	CORBA_Object_release ((CORBA_Object)retn, ev);
1564 
1565 	CORBA_Object_release (objref, ev);
1566 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1567 }
1568 
1569 static void
testContext(test_TestFactory factory,CORBA_Environment * ev)1570 testContext (test_TestFactory   factory,
1571 	     CORBA_Environment *ev)
1572 {
1573 	test_ContextServer objref;
1574 	CORBA_Object inArg, inoutArg, outArg, retn;
1575 	CORBA_Context ctx;
1576 
1577 	d_print ("Testing Contexts...\n");
1578 
1579 	objref = test_TestFactory_getContextServer (factory, ev);
1580 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1581 
1582 	inArg = inoutArg = outArg = retn = CORBA_OBJECT_NIL;
1583 
1584 	CORBA_Context_create_child (CORBA_OBJECT_NIL, "Whatever", &ctx, ev);
1585 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1586 
1587 	CORBA_Context_set_one_value (ctx, "foo", "foo1", ev);
1588 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1589 	CORBA_Context_set_one_value (ctx, "foo", "foo2", ev);
1590 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1591 	CORBA_Context_set_one_value (ctx, "bar", "baaaa", ev);
1592 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1593 
1594 	retn = test_ContextServer_opWithContext (
1595 		objref, inArg, &inoutArg, &outArg, ctx, ev);
1596 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1597 
1598 	CORBA_Object_release (retn, ev);
1599 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1600 	CORBA_Object_release (inArg, ev);
1601 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1602 	CORBA_Object_release (inoutArg, ev);
1603 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1604 	CORBA_Object_release (outArg, ev);
1605 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1606 
1607 	CORBA_Object_release ( (CORBA_Object)ctx, ev);
1608 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1609 
1610 	CORBA_Object_release (objref, ev);
1611 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1612 }
1613 
1614 #define SEQ_SIZE 4096
1615 static test_StrSeq *
make_large_str_seq(void)1616 make_large_str_seq (void)
1617 {
1618 	test_StrSeq *seq = test_StrSeq__alloc ();
1619 	int i;
1620 	static const char base_data[] = "This is a longish test string it could go on for ever and ever";
1621 
1622 	seq->_buffer = test_StrSeq_allocbuf (SEQ_SIZE);
1623 
1624 	for (i = 0; i < SEQ_SIZE; i++) {
1625 		int len = 3 + (int) ((sizeof (base_data) - 3.0) * rand () / (RAND_MAX + 1.0));
1626 		seq->_buffer [i] = CORBA_string_dup (base_data);
1627 		seq->_buffer [i] [len] = '\0';
1628 	}
1629 
1630 	seq->_length = seq->_maximum = SEQ_SIZE;
1631 	seq->_release = CORBA_TRUE;
1632 
1633 	return seq;
1634 }
1635 
1636 static void
testMisc(test_TestFactory factory,CORBA_Environment * ev)1637 testMisc (test_TestFactory   factory,
1638 	  CORBA_Environment *ev)
1639 {
1640 	CORBA_char       *foo;
1641 	CORBA_Context     ctx;
1642 	test_BasicServer  objref;
1643 
1644 	d_print ("Testing Misc bits...\n");
1645 
1646 	if (!in_proc) {
1647 		/* Invoke a BasicServer method on a TestFactory */
1648 		foo = test_BasicServer__get_foo (factory, ev);
1649 		g_assert (ev->_major == CORBA_SYSTEM_EXCEPTION);
1650 		g_assert (!strcmp (ev->_id, "IDL:omg.org/CORBA/BAD_OPERATION:1.0"));
1651 		CORBA_exception_free (ev);
1652 	}
1653 
1654 	g_assert (ORBit_copy_value (NULL, TC_CORBA_boolean) == NULL);
1655 
1656 	objref = test_TestFactory_getBasicServer (factory, ev);
1657 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1658 	g_assert (objref != CORBA_OBJECT_NIL);
1659 	g_assert (CORBA_Object_is_a (objref, "IDL:orbit/test/BasicServer:1.0", ev));
1660 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1661 
1662 	{ /* IOR stringification */
1663 		CORBA_char *ior;
1664 		CORBA_Object o2;
1665 
1666 		ior = CORBA_ORB_object_to_string (global_orb, factory, ev);
1667 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1668 
1669 		o2 = CORBA_ORB_string_to_object (global_orb, ior, ev);
1670 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1671 
1672 		CORBA_free (ior);
1673 
1674 		g_assert (o2 == factory);
1675 		CORBA_Object_release (o2, ev);
1676 	}
1677 
1678 	test_BasicServer_noImplement (objref, ev);
1679 	g_assert (ev->_major == CORBA_SYSTEM_EXCEPTION);
1680 	g_assert (!strcmp (ev->_id, "IDL:omg.org/CORBA/NO_IMPLEMENT:1.0"));
1681 	CORBA_exception_free (ev);
1682 
1683 	if (!in_proc) {
1684 		test_StrSeq *seq;
1685 
1686 		seq = make_large_str_seq ();
1687 		test_BasicServer_testLargeStringSeq (objref, seq, ev);
1688 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1689 		CORBA_free (seq);
1690 	}
1691 
1692 	CORBA_Object_release (objref, ev);
1693 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1694 
1695 	/* Check we are building full type data */
1696 	if (strcmp (TC_test_ObjectStruct->subtypes [0]->repo_id,
1697 		    "IDL:orbit/test/DerivedServer:1.0"))
1698 		g_warning ("Martin's bug needs fixing");
1699 
1700 	/* Check a daft one seen in CORBA_exception_free */
1701 	CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
1702 			     ex_test_SimpleException, NULL);
1703 	CORBA_exception_free (ev);
1704 	g_assert (ev->_id == NULL);
1705 	g_assert (ev->_any._value == NULL);
1706 
1707 	/* TypeCode equal */
1708 	g_assert (CORBA_TypeCode_equal (
1709 		TC_CORBA_string, TC_CORBA_string, ev));
1710 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1711 	g_assert (!CORBA_TypeCode_equal (
1712 		TC_test_StrSeq, TC_test_AnotherStrSeq, ev));
1713 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1714 
1715 	/* TypeCode equivalent */
1716 	g_assert (CORBA_TypeCode_equivalent (
1717 		TC_CORBA_string, TC_CORBA_string, ev));
1718 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1719 	g_assert (CORBA_TypeCode_equivalent (
1720 		TC_test_StrSeq, TC_test_AnotherStrSeq, ev));
1721 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1722 
1723 	/*
1724 	 * dead reference check
1725 	 */
1726 	if (!in_proc) {
1727 		test_DeadReferenceObj obj;
1728 
1729 		obj = test_TestFactory_createDeadReferenceObj (factory, ev);
1730 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1731 		g_assert (obj != CORBA_OBJECT_NIL);
1732 
1733 		test_DeadReferenceObj_test (obj, ev);
1734 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1735 
1736 		CORBA_Object_release (obj, ev);
1737 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1738 	} else { /* Lets do some things on a de-activated ref */
1739 		test_BasicServer         obj;
1740 		PortableServer_ObjectId *oid;
1741 		POA_test_BasicServer    *servant;
1742 
1743 		servant = SIMPLE_SERVANT_NEW (BasicServer);
1744 		obj = create_object (global_poa, servant, ev);
1745 
1746 		oid = PortableServer_POA_servant_to_id (
1747 			global_poa, servant, ev);
1748 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1749 		PortableServer_POA_deactivate_object (
1750 			global_poa, oid, ev);
1751 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1752 
1753 		CORBA_free (oid);
1754 
1755 		test_BasicServer_opException (obj, ev);
1756 		g_assert (ev->_major == CORBA_SYSTEM_EXCEPTION);
1757 		g_assert (!strcmp (ev->_id, ex_CORBA_OBJECT_NOT_EXIST));
1758 		CORBA_exception_free (ev);
1759 
1760 		test_BasicServer_opOneWay (obj, "Foo", ev);
1761 		g_assert (ev->_major == CORBA_SYSTEM_EXCEPTION);
1762 		g_assert (!strcmp (ev->_id, ex_CORBA_OBJECT_NOT_EXIST));
1763 		CORBA_exception_free (ev);
1764 
1765 		CORBA_Object_release (obj, ev);
1766 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
1767 	}
1768 
1769 	/* Check the ORB cleans up contexts properly */
1770 	CORBA_ORB_get_default_context (
1771 		global_orb, &ctx, ev);
1772 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1773 	g_assert (ctx != CORBA_OBJECT_NIL);
1774 	CORBA_Object_release ((CORBA_Object) ctx, ev);
1775 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1776 
1777 	/* Check that various bonobo hooks work */
1778 	g_assert (ORBit_small_get_servant (NULL) == NULL);
1779 	if (in_proc) {
1780 		g_assert (ORBit_small_get_servant (factory));
1781 		g_assert (ORBit_small_get_connection_status (factory) ==
1782 			  ORBIT_CONNECTION_IN_PROC);
1783 	} else {
1784 		g_assert (!ORBit_small_get_servant (factory));
1785 		g_assert (ORBit_small_get_connection_status (factory) ==
1786 			  ORBIT_CONNECTION_CONNECTED);
1787 	}
1788 }
1789 
1790 static void
testIOR(test_TestFactory factory,CORBA_Environment * ev)1791 testIOR (test_TestFactory   factory,
1792 	 CORBA_Environment *ev)
1793 {
1794 	int i, count;
1795 	CORBA_Object objref;
1796 
1797 	d_print ("Testing IOR marshalling ...\n");
1798 
1799 	objref = test_TestFactory_getBasicServer (factory, ev);
1800 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1801 
1802 	/* Check to see that the ORB correctly marshals various obj references */
1803 	count = test_BasicServer_getObjectCount (objref, ev);
1804 	for (i = 0; i < count; i++)
1805 	{
1806 		CORBA_Object test_obj;
1807 		test_obj = test_BasicServer_getObject (objref, i, ev);
1808 		if (ev->_major != CORBA_NO_EXCEPTION)
1809 			g_error ("Error demarshalling object number %d: %s",
1810 				 i, CORBA_exception_id (ev));
1811 	}
1812 
1813 	CORBA_Object_release (objref, ev);
1814 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1815 }
1816 
1817 static void
testLifeCycle(test_TestFactory factory,CORBA_Environment * ev)1818 testLifeCycle (test_TestFactory   factory,
1819 	       CORBA_Environment *ev)
1820 {
1821 	test_LifeCycleServer objref;
1822 	ORBit_IMethod       *method;
1823 
1824 	d_print ("Testing LifeCycle bits...\n");
1825 
1826 	objref = test_TestFactory_createLifeCycleServer (factory, ev);
1827 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1828 
1829 	d_print (" pre gnome 2.4 stubs ...\n");
1830 
1831 	if (in_proc) {
1832 		method = &test_LifeCycleServer__iinterface.methods._buffer[1];
1833 		g_assert (!strcmp (method->name, "deactivateUnrefOnReturn"));
1834 	} else {
1835 		method = &test_LifeCycleServer__iinterface.methods._buffer[0];
1836 		g_assert (!strcmp (method->name, "deactivateOnReturn"));
1837 	}
1838 
1839 	ORBit_small_invoke_stub (objref, method, NULL, NULL, NULL, ev);
1840 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1841 
1842 	if (!in_proc)
1843 		CORBA_Object_release (objref, ev);
1844 
1845 	d_print (" post gnome 2.4 stubs ...\n");
1846 
1847 	objref = test_TestFactory_createLifeCycleServer (factory, ev);
1848 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1849 
1850 	test_LifeCycleServer_deactivateOnReturn (objref, ev);
1851 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1852 
1853 	CORBA_Object_release (objref, ev);
1854 }
1855 
1856 static volatile int done = 0;
1857 
1858 static void
test_BasicServer_opExceptionA_cb(CORBA_Object object,ORBit_IMethod * m_data,ORBitAsyncQueueEntry * aqe,gpointer user_data,CORBA_Environment * ev)1859 test_BasicServer_opExceptionA_cb (CORBA_Object          object,
1860 				  ORBit_IMethod        *m_data,
1861 				  ORBitAsyncQueueEntry *aqe,
1862 				  gpointer              user_data,
1863 				  CORBA_Environment    *ev)
1864 {
1865 	test_TestException *ex;
1866 
1867 	/* Not a broken connection */
1868 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1869 
1870 	ORBit_small_demarshal_async (aqe, NULL, NULL, ev);
1871 
1872 	g_assert (ev->_major == CORBA_USER_EXCEPTION);
1873 	g_assert (strcmp (CORBA_exception_id (ev), ex_test_TestException) == 0);
1874 
1875 	ex = CORBA_exception_value (ev);
1876 	g_assert (strcmp (ex->reason, constants_STRING_IN) == 0);
1877 	g_assert (ex->number == constants_LONG_IN);
1878 	g_assert (ex->aseq._length == 1);
1879 	g_assert (ex->aseq._buffer[0] == constants_LONG_IN);
1880 
1881 	done = 1;
1882 }
1883 
1884 
1885 static void
test_BasicServer_opExceptionA(CORBA_Object obj,CORBA_Environment * ev)1886 test_BasicServer_opExceptionA (CORBA_Object       obj,
1887 			       CORBA_Environment *ev)
1888 {
1889 	ORBit_IMethod *m_data;
1890 
1891 	m_data = &test_BasicServer__iinterface.methods._buffer [ORBIT_IMETHODS_INDEX(test_BasicServer_opException)];
1892 	/* if this failed, we re-ordered the IDL ... */
1893 	g_assert (!strcmp (m_data->name, "opException"));
1894 
1895 	ORBit_small_invoke_async (
1896 		obj, m_data, test_BasicServer_opExceptionA_cb,
1897 		NULL, NULL, NULL, ev);
1898 }
1899 
1900 static void
test_BasicServer_opStringA_cb(CORBA_Object object,ORBit_IMethod * m_data,ORBitAsyncQueueEntry * aqe,gpointer user_data,CORBA_Environment * ev)1901 test_BasicServer_opStringA_cb (CORBA_Object          object,
1902 			       ORBit_IMethod        *m_data,
1903 			       ORBitAsyncQueueEntry *aqe,
1904 			       gpointer              user_data,
1905 			       CORBA_Environment    *ev)
1906 {
1907 	CORBA_char  *inout_str = NULL, *out_str, *ret_str;
1908 	CORBA_char **out_str_shim = &out_str;
1909 
1910 	gpointer args[3];
1911 	gpointer ret    = &ret_str;
1912 
1913 	args[0] = NULL;
1914 	args[1] = &inout_str;
1915 	args[2] = &out_str_shim;
1916 
1917 	/* Not a broken connection */
1918 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1919 
1920 	ORBit_small_demarshal_async (aqe, ret, args, ev);
1921 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1922 
1923 	g_assert (!strcmp (inout_str, constants_STRING_INOUT_OUT));
1924 	g_assert (!strcmp (out_str, constants_STRING_OUT));
1925 	g_assert (!strcmp (ret_str, constants_STRING_RETN));
1926 
1927 	CORBA_free (inout_str);
1928 	CORBA_free (out_str);
1929 	CORBA_free (ret_str);
1930 
1931 	done = 1;
1932 }
1933 
1934 static void
test_BasicServer_opStringA(CORBA_Object obj,const CORBA_char * in_str,const CORBA_char * inout_str,CORBA_Environment * ev)1935 test_BasicServer_opStringA (CORBA_Object       obj,
1936 			    const CORBA_char  *in_str,
1937 			    const CORBA_char  *inout_str,
1938 			    CORBA_Environment *ev)
1939 {
1940 	gpointer args[3];
1941 	ORBit_IMethod *m_data;
1942 
1943 	args[0] = &in_str;
1944 	args[1] = &inout_str;
1945 	args[2] = NULL;
1946 
1947 	m_data = &test_BasicServer__iinterface.methods._buffer[ORBIT_IMETHODS_INDEX(test_BasicServer_opString)];
1948 	/* if this failed, we re-ordered the IDL ... */
1949 	g_assert (!strcmp (m_data->name, "opString"));
1950 
1951 	ORBit_small_invoke_async (
1952 		obj, m_data, test_BasicServer_opStringA_cb,
1953 		NULL, args, NULL, ev);
1954 }
1955 
1956 static void
wait_until_done(void)1957 wait_until_done (void)
1958 {
1959 	while (!done)
1960 		g_main_context_iteration (NULL, TRUE);
1961 }
1962 
1963 static void
testAsync(test_TestFactory factory,CORBA_Environment * ev)1964 testAsync (test_TestFactory   factory,
1965 	   CORBA_Environment *ev)
1966 {
1967 	test_BasicServer objref;
1968 
1969 	d_print ("Testing Async invocations ...\n");
1970 	objref = test_TestFactory_getBasicServer (factory, ev);
1971 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1972 
1973 	if (in_proc) {
1974 		g_assert (objref->profile_list == NULL);
1975 		g_assert (ORBit_small_get_connection_ref (objref) == NULL);
1976 	}
1977 
1978 	done = 0;
1979 	test_BasicServer_opStringA (
1980 		objref, constants_STRING_IN,
1981 		constants_STRING_INOUT_IN, ev);
1982 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1983 
1984 	/* While waiting do some normal methods */
1985 	testString (objref, ev);
1986 
1987 	wait_until_done ();
1988 
1989 	done = 0;
1990 	test_BasicServer_opExceptionA (objref, ev);
1991 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1992 
1993 	wait_until_done ();
1994 
1995 	CORBA_Object_release (objref, ev);
1996 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
1997 }
1998 
1999 static void
broken_cb(LinkConnection * connection,gboolean * broken)2000 broken_cb (LinkConnection *connection, gboolean *broken)
2001 {
2002 	*broken = TRUE;
2003 }
2004 
2005 static void
testPingPong(test_TestFactory factory,gboolean thread_tests,CORBA_Environment * ev)2006 testPingPong (test_TestFactory   factory,
2007 	      gboolean           thread_tests,
2008 	      CORBA_Environment *ev)
2009 {
2010 	test_PingPongServer r_objref, l_objref, objref;
2011 	CORBA_unsigned_long before_remote_hash;
2012 	CORBA_unsigned_long after_remote_hash;
2013 
2014 #if NUM_THREADS > 0
2015 	if (thread_tests) {
2016 		static volatile int warned = 0;
2017 		if (!warned++)
2018 			g_warning ("No thread available to handle incoming requests");
2019 		return;
2020 	}
2021 #endif
2022 
2023 	d_print ("Testing ping pong invocations ...\n");
2024 	r_objref = test_TestFactory_createPingPongServer (factory, ev);
2025 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2026 
2027 	l_objref = TestFactory_createPingPongServer (NULL, ev);
2028 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2029 	CORBA_Object_release (l_objref, ev); /* only want 1 ref */
2030 	g_assert (ORBit_small_get_servant (l_objref) != NULL);
2031 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2032 
2033 	before_remote_hash = CORBA_Object_hash (l_objref, 0, ev);
2034 
2035 
2036 	test_PingPongServer_pingPong (r_objref, l_objref, 64, ev);
2037 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2038 
2039 	d_print ("Testing ping pong reg / lookup ...\n");
2040 	test_PingPongServer_set (r_objref, l_objref, "Foo", ev);
2041 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2042 
2043 	objref = test_PingPongServer_get (r_objref, "Foo", ev);
2044 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2045 	g_assert (ORBit_small_get_servant (objref) != NULL);
2046 	g_assert (l_objref == objref);
2047 
2048 	after_remote_hash = CORBA_Object_hash (l_objref, 0, ev);
2049 
2050 	d_print ("Testing hashing\n");
2051 	g_assert (before_remote_hash == after_remote_hash);
2052 
2053 	d_print ("Testing equivalence\n");
2054 	g_assert (CORBA_Object_is_equivalent (
2055 		l_objref, objref, ev));
2056 	g_assert (CORBA_Object_is_equivalent (
2057 		CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, ev));
2058 	g_assert (CORBA_Object_is_equivalent (
2059 		l_objref, l_objref, ev));
2060 	g_assert (CORBA_Object_is_equivalent (
2061 		r_objref, r_objref, ev));
2062 	g_assert (!CORBA_Object_is_equivalent (
2063 		r_objref, l_objref, ev));
2064 	g_assert (!CORBA_Object_is_equivalent (
2065 		l_objref, r_objref, ev));
2066 	g_assert (!CORBA_Object_is_equivalent (
2067 		l_objref, CORBA_OBJECT_NIL, ev));
2068 	g_assert (!CORBA_Object_is_equivalent (
2069 		CORBA_OBJECT_NIL, l_objref, ev));
2070 
2071 #if 0
2072 	/* Test blocking bits - try to blow the remote guy's stack */
2073 	if (!in_proc) {
2074 		int i;
2075 
2076 		d_print ("Testing client limiting of stack smash on remote server\n");
2077 		for (i = 0; i < 10000; i++) {
2078 			test_PingPongServer_opOneWayCallback (r_objref, l_objref, ev);
2079 			g_assert (ev->_major == CORBA_NO_EXCEPTION);
2080 		}
2081 		test_PingPongServer_opRoundTrip (r_objref, ev);
2082 	}
2083 #endif
2084 
2085 	if (!in_proc) {
2086 		int i;
2087 		ORBitConnection *cnx = ORBit_small_get_connection_ref (r_objref);
2088 		const char *base =
2089 			"This string is in order to provide some "
2090 			"more bulky data on the wire, the larger "
2091 			"the better. When the socket buffer fills "
2092 			"we start exercising the linc buffering code "
2093 			"and hopefully we get an exception somewhere "
2094 			"indicating that the buffer is full and that "
2095 			"the write has failed & that the connection is "
2096 			"now saturated ";
2097 		char *str;
2098 		gboolean broken = FALSE;
2099 
2100 		g_assert (cnx != NULL);
2101 		ORBit_connection_set_max_buffer (cnx, 10000);
2102 
2103 		str = g_strdup (base);
2104 		for (i = 0; i < 4; i++) {
2105 			char *new;
2106 			new = g_strconcat (str, str, NULL);
2107 			g_free (str);
2108 			str = new;
2109 		}
2110 
2111 		d_print ("Testing non blocking IO ...\n");
2112 
2113 		ORBit_small_listen_for_broken (
2114 			r_objref, G_CALLBACK (broken_cb),
2115 			&broken);
2116 
2117 		for (i = 0; i < 100; i++) {
2118 			test_PingPongServer_opSleep (
2119 				r_objref, str, ev);
2120 			if (broken)
2121 				break;
2122 		}
2123 
2124 		g_free (str);
2125 
2126 		/* If this blows - perhaps you just have a strange
2127 		 * system scheduler */
2128 /*		g_assert (broken); */
2129 		CORBA_exception_free (ev);
2130 		ORBit_small_connection_unref (cnx);
2131 
2132 		ORBit_connection_set_max_buffer (cnx, 0);
2133 	}
2134 
2135 	CORBA_Object_release (objref, ev);
2136 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2137 
2138 	CORBA_Object_release (l_objref, ev);
2139 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2140 
2141 	CORBA_Object_release (r_objref, ev);
2142 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2143 }
2144 
2145 static void
testPolicy(test_TestFactory factory,gboolean thread_tests,CORBA_Environment * ev)2146 testPolicy (test_TestFactory   factory,
2147 	    gboolean           thread_tests,
2148 	    CORBA_Environment *ev)
2149 {
2150 	ORBitPolicy *policy;
2151 	test_PingPongServer r_objref, l_objref;
2152 
2153 	if (thread_tests || !thread_safe)
2154 		return;
2155 
2156 	d_print ("Testing policy code ...\n");
2157 	r_objref = test_TestFactory_createPingPongServer (factory, ev);
2158 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2159 
2160 	l_objref = TestFactory_createPingPongServer (NULL, ev);
2161 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2162 	CORBA_Object_release (l_objref, ev); /* only want 1 ref */
2163 	g_assert (ORBit_small_get_servant (l_objref) != NULL);
2164 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2165 
2166 	policy = ORBit_policy_new (ORBIT_TYPE_POLICY_EX,
2167 				   "allow", global_poa, NULL);
2168 	ORBit_object_set_policy (r_objref, policy);
2169 	test_PingPongServer_pingPong (r_objref, l_objref, 64, ev);
2170 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2171 	ORBit_object_set_policy (r_objref, NULL);
2172 	ORBit_policy_unref (policy);
2173 
2174 	CORBA_Object_release (l_objref, ev);
2175 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2176 
2177 	CORBA_Object_release (r_objref, ev);
2178 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2179 }
2180 
2181 static void
dummy_cb(LinkConnection * connection,gboolean * invoked)2182 dummy_cb (LinkConnection *connection, gboolean *invoked)
2183 {
2184 	*invoked = TRUE;
2185 }
2186 
2187 static void
testSegv(test_TestFactory factory,CORBA_Environment * ev)2188 testSegv (test_TestFactory   factory,
2189 	  CORBA_Environment *ev)
2190 {
2191 	gboolean broken = FALSE;
2192 	gboolean invoked = FALSE;
2193 
2194 	if (in_proc)
2195 		return;
2196 
2197 	d_print ("Testing Fatal invocations ...\n");
2198 
2199 	g_assert (ORBit_small_listen_for_broken (
2200 						 factory, G_CALLBACK (broken_cb), &broken) ==
2201 		  ORBIT_CONNECTION_CONNECTED);
2202 
2203 	g_assert (ORBit_small_listen_for_broken (
2204 						 factory, G_CALLBACK (dummy_cb), &invoked) ==
2205 		  ORBIT_CONNECTION_CONNECTED);
2206 
2207 	g_assert (ORBit_small_unlisten_for_broken (
2208 						   factory, G_CALLBACK (dummy_cb)) ==
2209 		  ORBIT_CONNECTION_CONNECTED);
2210 	g_assert (!CORBA_Object_non_existent (factory, ev));
2211 
2212 	test_TestFactory_segv (factory, "do it!", ev);
2213 
2214 #ifdef DO_HARDER_SEGV // unusual
2215 	g_assert (ev->_major == CORBA_SYSTEM_EXCEPTION);
2216 	g_assert (!strcmp (ev->_id, "IDL:omg.org/CORBA/COMM_FAILURE:1.0"));
2217 	CORBA_exception_free (ev);
2218 
2219 	g_assert (ORBit_small_get_connection_status (factory) ==
2220 		  ORBIT_CONNECTION_DISCONNECTED);
2221 	g_assert (broken);
2222 	g_assert (!invoked);
2223 #else
2224 	if (ORBit_small_unlisten_for_broken (factory, G_CALLBACK (broken_cb)) !=
2225 	    ORBIT_CONNECTION_CONNECTED)
2226 		g_warning ("Unusual race in unlisten");
2227 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2228 #endif
2229 }
2230 
2231 static void
test_initial_references(CORBA_ORB orb,CORBA_Environment * ev)2232 test_initial_references (CORBA_ORB          orb,
2233 			 CORBA_Environment *ev)
2234 {
2235 	CORBA_ORB_ObjectIdList *list;
2236 	int                     i;
2237 
2238 	fprintf (stderr, "\nInitial References:\n");
2239 
2240 	list = CORBA_ORB_list_initial_services (orb, ev);
2241 
2242 	g_assert (ev->_major == CORBA_NO_EXCEPTION && list && list->_length);
2243 
2244 	for (i = 0; i < list->_length; i++) {
2245 		CORBA_ORB_ObjectId id;
2246 		CORBA_Object       obj;
2247 
2248 		id = list->_buffer [i];
2249 
2250 		g_assert (id);
2251 
2252 		fprintf (stderr, "\t%s ... ", id);
2253 
2254 		obj = CORBA_ORB_resolve_initial_references (orb, id, ev);
2255 
2256 		g_assert (ev->_major == CORBA_NO_EXCEPTION && obj != CORBA_OBJECT_NIL);
2257 
2258 		CORBA_Object_release (obj, ev);
2259 
2260 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
2261 
2262 		fprintf (stderr, "okay\n");
2263 	}
2264 
2265 	CORBA_free (list);
2266 }
2267 
2268 #define TIME_TEST_RUNS 1000
2269 
2270 static void
test_time_noop(test_TestFactory factory,CORBA_Environment * ev)2271 test_time_noop (test_TestFactory   factory,
2272 		CORBA_Environment *ev)
2273 {
2274 	int i;
2275 	int old_flags;
2276 	GTimer *timer;
2277 
2278 	timer = g_timer_new ();
2279 	g_timer_start (timer);
2280 	for (i = 0; i < TIME_TEST_RUNS; i++)
2281 		test_TestFactory_noOp (factory, ev);
2282 	g_timer_stop (timer);
2283 	fprintf (stderr, "In proc (fast) took %g msecs\n",
2284 	g_timer_elapsed (timer, NULL) * 1000);
2285 
2286 	old_flags = ORBit_small_flags;
2287 	ORBit_small_flags |= ORBIT_SMALL_FORCE_GENERIC_MARSHAL;
2288 	g_timer_reset (timer);
2289 	g_timer_start (timer);
2290 	for (i = 0; i < TIME_TEST_RUNS; i++)
2291 		test_TestFactory_noOp (factory, ev);
2292 	g_timer_stop (timer);
2293 	fprintf (stderr, "In proc (slow) took %g msecs\n",
2294 		 g_timer_elapsed (timer, NULL) * 1000);
2295 	ORBit_small_flags = old_flags;
2296 
2297 	g_timer_destroy (timer);
2298 }
2299 
2300 static void
test_basic_server(test_TestFactory factory,CORBA_Environment * ev)2301 test_basic_server (test_TestFactory   factory,
2302 		   CORBA_Environment *ev)
2303 {
2304 	test_BasicServer objref;
2305 
2306 	objref = test_TestFactory_getBasicServer (factory, ev);
2307 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2308 	g_assert (objref != CORBA_OBJECT_NIL);
2309 	g_assert (CORBA_Object_is_a (objref, "IDL:orbit/test/BasicServer:1.0", ev));
2310 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2311 
2312 	testAttribute  (objref, ev);
2313 	testString     (objref, ev);
2314 	testLong       (objref, ev);
2315 	testLongLong   (objref, ev);
2316 	testFloat      (objref, ev);
2317 	testDouble     (objref, ev);
2318 	testLongDouble (objref, ev);
2319 	testEnum       (objref, ev);
2320 	testException  (objref, ev);
2321 	testBoolAlign  (objref, ev);
2322 
2323 	CORBA_Object_release (objref, ev);
2324 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2325 }
2326 
2327 static void
testDerivedServer(test_TestFactory factory,CORBA_Environment * ev)2328 testDerivedServer (test_TestFactory   factory,
2329 		   CORBA_Environment *ev)
2330 {
2331 	CORBA_Object            obj;
2332 	PortableServer_ServantBase *servant;
2333 	PortableServer_ObjectId *oid;
2334 	ORBit_POAObject             pobj;
2335 	PortableServer_ServantBase__epv DerivedServer_base_epv = {NULL, simple_finalize, NULL};
2336 	POA_test_BasicServer__vepv      DerivedServer_vepv = { &DerivedServer_base_epv, NULL };
2337 
2338 	d_print ("Testing DerivedServer ...\n");
2339 
2340 	servant = SIMPLE_SERVANT_NEW (DerivedServer);
2341 	obj = create_object (global_poa, servant, ev);
2342 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2343 
2344 	g_assert (test_C1__classid != 0);
2345 	g_assert (test_B1__classid != 0);
2346 	g_assert (test_B2__classid != 0);
2347 	g_assert (test_DerivedServer__classid != 0);
2348 
2349 	pobj = (ORBit_POAObject) obj->adaptor_obj;
2350 	g_assert (pobj->vepvmap_cache [test_DerivedServer__classid] != 0);
2351 	g_assert (pobj->vepvmap_cache [test_C1__classid] != 0);
2352 	g_assert (pobj->vepvmap_cache [test_B1__classid] != 0);
2353 	g_assert (pobj->vepvmap_cache [test_B2__classid] != 0);
2354 
2355 	CORBA_Object_release (obj, ev);
2356 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2357 
2358 	oid = PortableServer_POA_servant_to_id (global_poa, servant, ev);
2359 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2360 	PortableServer_POA_deactivate_object (global_poa, oid, ev);
2361 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2362 
2363 	CORBA_free (oid);
2364 }
2365 
2366 static void
testNonExistent(test_TestFactory factory,CORBA_Environment * ev)2367 testNonExistent (test_TestFactory factory, CORBA_Environment *ev)
2368 {
2369 	CORBA_Object non_existent;
2370 	const char *non_existent_ior =
2371 		"IOR:010000001f00000049444c3a6f726269742f746573742f54657"
2372 		"374466163746f72793a312e300000030000000054424f6400000001"
2373 		"01020005000000554e495800000000160000006c6f63616c686f737"
2374 		"42e6c6f63616c646f6d61696e0000002d0000002f746d702f6f7262"
2375 		"69742d6d69636861656c2f6c696e632d363733322d302d373362323"
2376 		"966373333316662390000000000000000caaedfba58000000010102"
2377 		"002d0000002f746d702f6f726269742d6d69636861656c2f6c696e6"
2378 		"32d363733322d302d37336232396637333331666239000000001c00"
2379 		"000000000000331c40f8ba0fa828dc2928282828282808000000db7"
2380 		"e269601000000480000000100000002000000050000001c00000000"
2381 		"000000331c40f8ba0fa828dc2928282828282808000000db7e26960"
2382 		"1000000140000000100000001000105000000000901010000000000";
2383 
2384 	if (!in_proc)
2385 		return;
2386 	d_print ("Testing CORBA_Object_non_existent ...\n");
2387 
2388 	non_existent = CORBA_ORB_string_to_object
2389 		(global_orb, non_existent_ior, ev);
2390 	g_assert (CORBA_Object_non_existent (non_existent, ev));
2391 	CORBA_Object_release (non_existent, NULL);
2392 }
2393 
2394 static void
testWithException(test_TestFactory factory,CORBA_Environment * ev)2395 testWithException (test_TestFactory factory, CORBA_Environment *ev)
2396 {
2397 	int old_flags;
2398 	CORBA_Object objref;
2399 
2400 	CORBA_exception_set (ev, CORBA_SYSTEM_EXCEPTION,
2401 			     ex_CORBA_OBJECT_NOT_EXIST, NULL);
2402 	objref = test_TestFactory_getBasicServer (factory, ev);
2403 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2404 	CORBA_Object_release (objref, ev);
2405 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2406 
2407 	old_flags = ORBit_small_flags;
2408 	ORBit_small_flags |= ORBIT_SMALL_FORCE_GENERIC_MARSHAL;
2409 
2410 	CORBA_exception_set (ev, CORBA_SYSTEM_EXCEPTION,
2411 			     ex_CORBA_OBJECT_NOT_EXIST, NULL);
2412 	objref = test_TestFactory_getBasicServer (factory, ev);
2413 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2414 	CORBA_Object_release (objref, ev);
2415 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2416 
2417 	ORBit_small_flags = old_flags;
2418 }
2419 
2420 static void
run_tests(test_TestFactory factory,gboolean thread_tests,CORBA_Environment * ev)2421 run_tests (test_TestFactory   factory,
2422 	   gboolean           thread_tests,
2423 	   CORBA_Environment *ev)
2424 {
2425 	int i;
2426 
2427 	for (i = 0; i < NUM_RUNS; i++) {
2428 		testSequenceHelpers ();
2429 		testConst ();
2430 		test_basic_server (factory, ev);
2431 		testIsA (factory, ev);
2432 		testFixedLengthStruct (factory, ev);
2433 		testVariableLengthStruct (factory, ev);
2434 		testCompoundStruct (factory, ev);
2435 		testAlignHoleStruct (factory, ev);
2436 		testObjectStruct (factory, ev);
2437 		testStructAny (factory, ev);
2438 		testUnboundedSequence (factory, ev);
2439 		testBoundedSequence (factory, ev);
2440 		testAnySequence (factory, ev);
2441 		testFixedLengthUnion (factory, ev);
2442 		testVariableLengthUnion (factory, ev);
2443 		testMiscUnions (factory, ev);
2444 		testUnionArray (factory, ev);
2445 		testFixedLengthArray (factory, ev);
2446 		testVariableLengthArray (factory, ev);
2447 		testAnyStrSeq (factory, ev);
2448 		testAnyLong (factory, ev);
2449 		testAnyString (factory, ev);
2450 		testAnyStruct (factory, ev);
2451 		testAnyException (factory, ev);
2452 		testAnyEquivalence (factory, ev);
2453 		testSequenceOfAny (factory, ev);
2454 		testTypeCode (factory, ev);
2455 		testContext (factory, ev);
2456 		testIInterface (factory, ev);
2457 		testDerivedServer (factory, ev);
2458 		testNonExistent (factory, ev);
2459 #ifndef TIMING_RUN
2460 		if (!thread_tests)
2461 			testAsync (factory, ev);
2462 #endif
2463 		if (!in_proc) {
2464 			testPingPong (factory, thread_tests, ev);
2465 			testPolicy (factory, thread_tests, ev);
2466 		}
2467 		testMisc (factory, ev);
2468 		testIOR (factory, ev);
2469 		testWithException (factory, ev);
2470 		testLifeCycle (factory, ev);
2471 	}
2472 
2473 #if NUM_RUNS > 1
2474 	g_warning ("Did '%d' iterations", i);
2475 #endif
2476 }
2477 
2478 static gpointer
test_thread(gpointer data)2479 test_thread (gpointer data)
2480 {
2481 	CORBA_Environment ev[1];
2482 	test_TestFactory factory = data;
2483 
2484 	CORBA_exception_init (ev);
2485 	run_tests (factory, TRUE, ev);
2486 	CORBA_exception_free (ev);
2487 
2488 	return data;
2489 }
2490 
2491 static void
run_threaded_tests(test_TestFactory factory,CORBA_Environment * ev)2492 run_threaded_tests (test_TestFactory   factory,
2493 		    CORBA_Environment *ev)
2494 {
2495 	int i;
2496 	GError *error = NULL;
2497 	GThread **threads;
2498 
2499 	if (!NUM_THREADS)
2500 		return;
2501 
2502 	fprintf (stderr, "Testing with %d threads\n", NUM_THREADS);
2503 
2504 	threads = g_new0 (GThread *, NUM_THREADS);
2505 
2506 	for (i = 0; i < NUM_THREADS; i++) {
2507 		threads [i] = g_thread_create
2508 			( test_thread, factory, TRUE, &error);
2509 		g_assert (!error);
2510 	}
2511 
2512 	for (i = 0; i < NUM_THREADS; i++) {
2513 		if (!(g_thread_join (threads [i]) == factory))
2514 			g_error ("Wierd thread join problem '%d'", i);
2515 	}
2516 }
2517 
2518 static void
dump_protos(void)2519 dump_protos (void)
2520 {
2521 	int enabled_count = 0;
2522 	LinkProtocolInfo *info;
2523 
2524 	for (info = link_protocol_all (); info->name; info++) {
2525 		gboolean enabled;
2526 
2527 		if ((enabled = ORBit_proto_use (info->name)))
2528 			enabled_count++;
2529 
2530 		fprintf (stderr, "Protocol %8s: %s\n",
2531 			 info->name,
2532 			 enabled ? "enabled" : "disabled");
2533 	}
2534 
2535 	g_assert (enabled_count > 0);
2536 }
2537 
2538 static void
test_init(CORBA_Environment * ev)2539 test_init (CORBA_Environment *ev)
2540 {
2541 	g_assert (CORBA_ORB_init (NULL, NULL, "", ev) == global_orb);
2542 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2543 
2544 	CORBA_ORB_destroy (global_orb, ev);
2545 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2546 	CORBA_Object_release ((CORBA_Object)global_orb, ev);
2547 }
2548 
2549 int
main(int argc,char * argv[])2550 main (int argc, char *argv [])
2551 {
2552 	CORBA_Environment  ev[1];
2553 	test_TestFactory   factory;
2554 	ORBit_IInterfaces *interfaces = NULL;
2555 	gboolean           gen_imodule = FALSE;
2556 	char              *orb_name;
2557 	int                i;
2558 
2559 	g_thread_init (NULL);
2560 
2561 	CORBA_exception_init (ev);
2562 
2563 /* FIXME - make this work nicely sometime.
2564 	global_orb = CORBA_ORB_init (&argc, argv, "", ev);
2565 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2566 	CORBA_Object_release (global_orb, ev);
2567 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2568 */
2569 	for (i = 0; i < argc; i++) {
2570 		if (!strcmp (argv [i], "--gen-imodule"))
2571 			gen_imodule = TRUE;
2572 		if (!strcmp (argv [i], "--thread-safe"))
2573 			thread_safe = TRUE;
2574 		if (!strcmp (argv [i], "--thread-tests")) {
2575 			thread_safe = TRUE;
2576 			thread_tests = TRUE;
2577 		}
2578 	}
2579 
2580 	if (thread_safe)
2581 		orb_name = "orbit-local-orb";
2582 	else
2583 		orb_name = "orbit-local-non-threaded-orb";
2584 
2585 	global_orb = CORBA_ORB_init (&argc, argv, orb_name, ev);
2586 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2587 
2588 	/*	if (thread_tests) {
2589 		g_warning ("FIXME: testing only");
2590 		link_set_io_thread (TRUE);
2591 		} */
2592 
2593 	if (gen_imodule) {
2594 		CORBA_sequence_CORBA_TypeCode *typecodes = NULL;
2595 
2596 		interfaces = ORBit_iinterfaces_from_file (
2597 				TEST_SRCDIR "/everything.idl", NULL, &typecodes);
2598 		g_assert (interfaces != NULL);
2599 		g_assert (typecodes != NULL);
2600 
2601 		CORBA_free (typecodes);
2602 
2603 		init_iinterfaces (interfaces, ev);
2604 	}
2605 
2606 	test_init (ev);
2607 	test_initial_references (global_orb, ev);
2608 
2609 	free (malloc (8)); /* -lefence */
2610 
2611 	dump_protos ();
2612 
2613 	/* In Proc ... */
2614 	in_proc = TRUE;
2615 
2616 	fprintf (stderr, "\n --- In proc ---\n\n\n");
2617 	factory = get_server (global_orb, ev);
2618 	g_assert (factory->profile_list == NULL);
2619 	g_assert (ORBit_object_get_connection (factory) == NULL);
2620 
2621 	test_time_noop (factory, ev);
2622 	run_tests (factory, FALSE, ev);
2623 	if (thread_tests)
2624 		g_warning ("FIXME: disabled in-proc threaded tests for now");
2625 /*		run_threaded_tests (factory, ev); */
2626 
2627 	CORBA_Object_release (factory, ev);
2628 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2629 	factory = CORBA_OBJECT_NIL;
2630 
2631 	fprintf (stderr, "\n\n --- Out of proc ---\n\n\n");
2632 	in_proc = FALSE;
2633 
2634 	{ /* read the ior from iorfile, and swizzle to an objref*/
2635 		int   size;
2636 		char  ior [1024];
2637 		FILE *infile = fopen ("iorfile", "rb");
2638 
2639 		if (!infile)
2640 			g_error ("Start the server before running the client");
2641 
2642 		size = fread (ior, 1, 1024, infile);
2643 		fclose (infile);
2644 		ior [size] = '\0';   /* insure that string is terminated correctly */
2645 
2646 		factory = CORBA_ORB_string_to_object (global_orb, ior, ev);
2647 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
2648 
2649 		if (CORBA_Object_non_existent (factory, ev))
2650 			g_error  ("Can't contact the server");
2651 		g_assert (ev->_major == CORBA_NO_EXCEPTION);
2652 	}
2653 	run_tests (factory, FALSE, ev);
2654 	if (thread_tests)
2655 		run_threaded_tests (factory, ev);
2656 	testSegv (factory, ev);
2657 
2658 	CORBA_Object_release (factory, ev);
2659 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2660 
2661 	if (gen_imodule)
2662 		CORBA_free (interfaces);
2663 
2664 	CORBA_Object_release ((CORBA_Object) global_poa, ev);
2665 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2666 
2667 	CORBA_ORB_destroy (global_orb, ev);
2668 	CORBA_exception_free (ev);
2669 
2670 	CORBA_Object_release ((CORBA_Object) global_orb, ev);
2671 	g_assert (ev->_major == CORBA_NO_EXCEPTION);
2672 
2673 	CORBA_exception_free (ev);
2674 
2675 	d_print ("All tests passed successfully\n");
2676 
2677 	return 0;
2678 }
2679