source: trunk/ORBit2-2.14.0/test/everything/unionServer.c

Last change on this file was 92, checked in by cinc, 19 years ago

Orbit2 modified for use with NOM

File size: 5.2 KB
Line 
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Author: Phil Dawes <philipd@users.sourceforge.net>
19 */
20
21#include <stdio.h>
22#include <string.h>
23
24#include "everything.h"
25#include "constants.h"
26
27static
28test_FixedLengthUnion
29UnionServer_opFixed(PortableServer_Servant _servant,
30 const test_FixedLengthUnion *inArg,
31 test_FixedLengthUnion *inoutArg,
32 test_FixedLengthUnion *outArg,
33 CORBA_Environment * ev){
34 test_FixedLengthUnion retval;
35 g_assert(inArg->_d == 'a');
36 g_assert(inArg->_u.x == constants_LONG_IN);
37
38 g_assert(inoutArg->_d == 'b');
39 g_assert(inoutArg->_u.y == 't');
40
41 inoutArg->_u.z = TRUE;
42 inoutArg->_d = 'c';
43
44 outArg->_u.x = constants_LONG_OUT;
45 outArg->_d = 'a';
46
47 retval._u.z = FALSE;
48 retval._d = 'd';
49 return retval;
50}
51
52static
53test_VariableLengthUnion *
54UnionServer_opVariable(PortableServer_Servant _servant,
55 const test_VariableLengthUnion * inArg,
56 test_VariableLengthUnion * inoutArg,
57 test_VariableLengthUnion ** outArg,
58 CORBA_Environment * ev){
59 test_VariableLengthUnion *retval;
60
61 g_assert(inArg->_d == 1);
62 g_assert(inArg->_u.x == constants_LONG_IN);
63
64 g_assert(inoutArg->_d == 2);
65 g_assert(strcmp(inoutArg->_u.y,constants_STRING_INOUT_IN)==0);
66
67 CORBA_free(inoutArg->_u.y);
68 inoutArg->_u.z = TRUE;
69 inoutArg->_d = 3;
70
71 *outArg = test_VariableLengthUnion__alloc();
72 (*outArg)->_u.x = constants_LONG_OUT;
73 (*outArg)->_d = 1;
74
75 retval = test_VariableLengthUnion__alloc();
76 retval->_u.z = FALSE;
77 retval->_d = 4;
78 return retval;
79}
80
81static test_EnumUnion
82UnionServer_opMisc (PortableServer_Servant servant,
83 const test_unionSeq *inSeq,
84 const test_BooleanUnion *inArg,
85 test_ArrayUnion **outArg,
86 CORBA_Environment *ev)
87{
88 test_EnumUnion retval;
89 int i;
90
91 g_assert (inSeq->_length == 3);
92 g_assert (inSeq->_buffer [0]._d == 4);
93 g_assert (inSeq->_buffer [0]._u.z == CORBA_TRUE);
94 g_assert (inSeq->_buffer [1]._d == 2);
95 g_assert (!strcmp (inSeq->_buffer [1]._u.y, "blah"));
96 g_assert (inSeq->_buffer [2]._d == 55);
97 g_assert (inSeq->_buffer [2]._u.w == constants_LONG_IN);
98
99 g_assert (inArg->_d == 1);
100 g_assert (!strcmp (inArg->_u.y, "blah de blah"));
101
102 (*outArg) = test_ArrayUnion__alloc ();
103 (*outArg)->_d = 22;
104 for (i = 0; i < 20; i++) {
105 char *tmp;
106
107 tmp = g_strdup_printf ("Numero %d", i);
108 (*outArg)->_u.d [i] = CORBA_string_dup (tmp);
109 g_free (tmp);
110 }
111
112 retval._d = test_EnumUnion_red;
113 retval._u.x = constants_LONG_IN;
114
115 return retval;
116}
117
118static test_FixedLengthUnionArray_slice *
119UnionServer_opFixedLengthUnionArray(PortableServer_Servant _servant,
120 const test_FixedLengthUnionArray inArg,
121 test_FixedLengthUnionArray inoutArg,
122 test_FixedLengthUnionArray outArg,
123 CORBA_Environment *ev)
124{
125 test_FixedLengthUnionArray_slice *retn;
126
127 g_assert (inArg[0]._d == 'a');
128 g_assert (inArg[0]._u.x == constants_LONG_IN);
129 g_assert (inArg[1]._d == 'b');
130 g_assert (inArg[1]._u.y == constants_CHAR_IN);
131 g_assert (inArg[2]._d == 'c');
132 g_assert (inArg[3]._d == 'e');
133 g_assert (inArg[3]._u.v.a == constants_SHORT_IN);
134
135 g_assert (inoutArg[0]._d == 'a');
136 g_assert (inoutArg[0]._u.x == constants_LONG_INOUT_IN);
137 g_assert (inoutArg[1]._d == 'b');
138 g_assert (inoutArg[1]._u.y == constants_CHAR_INOUT_IN);
139 g_assert (inoutArg[2]._d == 'c');
140 g_assert (inoutArg[3]._d == 'e');
141 g_assert (inoutArg[3]._u.v.a == constants_SHORT_INOUT_IN);
142
143 inoutArg[0]._d = 'a';
144 inoutArg[0]._u.x = constants_LONG_INOUT_OUT;
145 inoutArg[1]._d = 'b';
146 inoutArg[1]._u.y = constants_CHAR_INOUT_OUT;
147 inoutArg[2]._d = 'c';
148 inoutArg[3]._d = 'e';
149 inoutArg[3]._u.v.a = constants_SHORT_INOUT_OUT;
150
151 outArg[0]._d = 'a';
152 outArg[0]._u.x = constants_LONG_OUT;
153 outArg[1]._d = 'b';
154 outArg[1]._u.y = constants_CHAR_OUT;
155 outArg[2]._d = 'c';
156 outArg[3]._d = 'e';
157 outArg[3]._u.v.a = constants_SHORT_OUT;
158
159 retn = test_FixedLengthUnionArray__alloc();
160
161 retn[0]._d = 'a';
162 retn[0]._u.x = constants_LONG_RETN;
163 retn[1]._d = 'b';
164 retn[1]._u.y = constants_CHAR_RETN;
165 retn[2]._d = 'c';
166 retn[3]._d = 'e';
167 retn[3]._u.v.a = constants_SHORT_RETN;
168
169 return retn;
170}
171
172PortableServer_ServantBase__epv UnionServer_base_epv = {NULL, simple_finalize, NULL};
173
174POA_test_UnionServer__epv UnionServer_epv = {
175 NULL,
176 UnionServer_opFixed,
177 UnionServer_opVariable,
178 UnionServer_opMisc,
179 UnionServer_opFixedLengthUnionArray,
180};
181
182POA_test_UnionServer__vepv UnionServer_vepv = {&UnionServer_base_epv, &UnionServer_epv};
183
184POA_test_UnionServer UnionServer_servant = {NULL, &UnionServer_vepv}; /* Singleton */
Note: See TracBrowser for help on using the repository browser.