summaryrefslogtreecommitdiff
path: root/TAO/IIOP/tests/Cubit/TAO/test1.cpp
blob: a27c29ee378bef5b775565224b19c801334e6728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
// @(#)test1.cpp	1.4 95/09/28
// Copyright 1995 by Sun Microsystems, Inc.
// All Rights Reserved
//
// TEST		stubs for "test1"
//

#include <stdio.h>

#include "test1.h"


//
// Define all the stubs ... it's a lot less error prone to do it with
// macros than by hand!
//
// NOTE:  the "calldata" is exported for use by the skeletons.  At some
// point skeletons will probably be fully abstracted; for now they aren't.
//
// Also, for some reason, name mangling is changed by the explicit
// declaration as "extern" -- if it's not done, linking fails.
//
#define	DEFINE_TEST3(typename, truetype, truetypename) \
    static const TAO_Param_Data test1_ ## typename ## _paramdata [4] = { \
    { _tc_CORBA_ ## truetypename, PARAM_RETURN, 0 }, \
    { _tc_CORBA_ ## truetypename, PARAM_IN, 0 }, \
    { _tc_CORBA_ ## truetypename, PARAM_OUT, 0 }, \
    { _tc_CORBA_ ## truetypename, PARAM_INOUT, 0 }, \
    }; \
    \
    extern const TAO_Call_Data test1_ ## typename ## _calldata; \
    \
    const TAO_Call_Data test1_ ## typename ## _calldata = { \
	"test_" #typename, CORBA_B_TRUE, \
	4, &test1_ ## typename ## _paramdata [0], \
	0, 0, \
    }; \
    \
    CORBA_ ## truetype \
    test1_test_ ## typename (test1_ptr target, \
		CORBA_ ## truetype in_a1, \
		CORBA_ ## truetype &out_a2, \
		CORBA_ ## truetype &inout_a3, \
		CORBA_Environment &env) { \
	CORBA_ ## truetype _retval; \
	STUB_Object	*_obj; \
	if (target->QueryInterface (IID_STUB_Object, (void **)&_obj) \
		!= NOERROR) \
	    env.exception (new CORBA_INV_OBJREF (COMPLETED_NO)); \
	else { \
	    _obj->do_call (env, &test1_ ## typename ## _calldata, \
		&_retval, &in_a1, &out_a2, &inout_a3); \
	    _obj->Release (); \
	} \
	return _retval; \
    }

//  changed extern const calldata test1_ ## typename ## _calldata;
//  to     const calldata test1_ ## typename ## _calldata; \

//	changed CORBA_ ## truetype _retval = 0; to changed CORBA_ ## truetype _retval;

#define	DEFINE_TEST(typename, truetype) \
	DEFINE_TEST3(typename, truetype, truetype)


//
// Generate a system exception, passing an operation ID that's
// not allowed by IIOP (much less this interface) and verifying
// that the server returns some kind of system exception.
//
static const TAO_Call_Data illegal_calldata = {
    "+_illegal", CORBA_B_TRUE,
    0, 0,
    0, 0
};

void
test_illegal (test1_ptr target, CORBA_Environment &env)
{
    STUB_Object		*data;

    if (target->QueryInterface (IID_STUB_Object, (void **)&data)
	    != NOERROR)
	env.exception (new CORBA_INV_OBJREF (COMPLETED_NO));
    else {
	data->do_call (env, &illegal_calldata
	    );
	data->Release ();
    }
}


extern const TAO_Call_Data test1_void_calldata;
const TAO_Call_Data test1_void_calldata = {
    "test_void", CORBA_B_TRUE,
    0, 0,
    0, 0
};

void
test1_test_void (test1_ptr target, CORBA_Environment &env)
{
    STUB_Object		*data;

    if (target->QueryInterface (IID_STUB_Object, (void **)&data)
	    != NOERROR)
	env.exception (new CORBA_INV_OBJREF (COMPLETED_NO));
    else {
	data->do_call (env, &test1_void_calldata
	    );
	data->Release ();
    }
}

DEFINE_TEST (short, Short);
DEFINE_TEST (long, Long);
DEFINE_TEST (ushort, UShort);
DEFINE_TEST (ulong, ULong);

#if	defined(MIPS)
//
// NOTE:  C/C++ compilers as a rule pass a "float" in the space that
// a "double" takes up.  Conversions are evidently optional; portability
// forces the following "explicit temporary" hack to work on at least
// one MIPS platform, which converts the parameter to "double" and
// hence changes the binary representation.  (Even if that is a compiler
// bug, it's probably required by now for binary compatibility!)
//
// A "-k ansi" compiler flag may be needed to get correct behaviour;
// passing the "in" parameters by reference apparently works too.  At
// this time, none of these solutions is used by default.
//
// This stub-level hackery seems like it could be replaced inside of the
// stub interpreter, which could just manually convert "float" parameters
// (all of them) as special cases.  But of course, that would slow the
// interpreter down on _every_ call, not just the ones that require it
// (such as this one).  Tradeoffs!
//
static const TAO_Param_Data test1_float_paramdata [4] = {
    { _tc_CORBA_Float , PARAM_RETURN , 0 },
    { _tc_CORBA_Float , PARAM_IN , 0 },
    { _tc_CORBA_Float , PARAM_OUT , 0 },
    { _tc_CORBA_Float , PARAM_INOUT , 0 }
};

extern const TAO_Call_Data test1_float_calldata;

const TAO_Call_Data test1_float_calldata = {
    "test_float", CORBA_B_TRUE,
    4 , &test1_float_paramdata [0],
    0 , 0
};

CORBA_Float
test1_test_float (
    test1_ptr		target,
    CORBA_Float	in_a1,
    CORBA_Float	&out_a2,
    CORBA_Float	&inout_a3,
    CORBA_Environment	&env
)
{
    CORBA_Float	_retval;

    // These three temporaries required due to MIPS compiler bug
    CORBA_Float	_in_a1 = in_a1;
    CORBA_Float	_out_a2 = out_a2;
    CORBA_Float	_inout_a3 = inout_a3;

    target -> data -> do_call (env,
	&test1_float_calldata,
	&_retval,
	&_in_a1,
	&_out_a2,
	&_inout_a3);
    return _retval;
}

#else
DEFINE_TEST (float, Float);
#endif	// MIPS


DEFINE_TEST (double, Double);
DEFINE_TEST (boolean, Boolean);
DEFINE_TEST (char, Char);
DEFINE_TEST (octet, Octet);

/*
CORBA_Any *
test1_test_any (test1_ptr target,
	const CORBA_Any &in_a1,
	CORBA_Any *&out_a2,
	CORBA_Any &inout_a3,
	CORBA_Environment &env)
{
    // XXX implement this stub! ... annoying that C++ mapping
    // calls for so much special casing
}
*/


DEFINE_TEST3 (TypeCode, TypeCode_ptr, TypeCode);
DEFINE_TEST3 (Principal, Principal_ptr, Principal);
DEFINE_TEST3 (Object, Object_ptr, Object);

// NOTE:  C++ mapping has "in" strings as "const", which doesn't
// show up in this macro ...
DEFINE_TEST3 (string, Char *, String);

DEFINE_TEST (longlong, LongLong);
DEFINE_TEST (ulonglong, ULongLong);
DEFINE_TEST (wchar, WChar);

// NOTE:  C++ mapping has "in" strings as "const", which doesn't
// show up in this macro ...
DEFINE_TEST3 (wstring, WChar *, WString);

#if !defined(NONNATIVE_LONGDOUBLE)
DEFINE_TEST (longdouble, LongDouble);
#endif

#undef	DEFINE_TEST


//
// Utility macros used to construct octet codes that are aligned
// on longword boundaries, and with a known byte order.  This
// happens to use big endian encoding since it was convenient.
// (Longword alignment is a happy accident of the specification
// of OMG-IDL ... it could have been much worse!)
//
// It'd be much simpler to lay out such data in assembler!
//

#if	defined (WORDS_BIGENDIAN)
#	define	MAKE_BIG_LONG(a,b,c,d) \
	    ((((a) & 0xff) << 24) | (((b) & 0xff) << 16) \
	     | (((c) & 0xff) <<  8) | ((d) & 0xff))
#	define	BIG_ENDIAN_LONG(x)	(x)

#else	// LITTLE_ENDIAN
#	define	MAKE_BIG_LONG(a,b,c,d) \
	    ((((d) & 0xff) << 24) | (((c) & 0xff) << 16) \
	     | (((b) & 0xff) <<  8) | ((a) & 0xff))
#	define BYTE_FROM(n,integer)    (((integer)>>(8*(n)))&0xff)
#	define BIG_ENDIAN_LONG(integer) \
	    MAKE_BIG_LONG (BYTE_FROM(3,integer), BYTE_FROM(2,integer),\
		BYTE_FROM(1,integer), BYTE_FROM(0,integer))
#endif



//
// "x1" exception typecode ... must be longword aligned
//
static CORBA_Long oc_x1 [] = {
    0,					// big endian flag + padding
    BIG_ENDIAN_LONG (29),		// length of ID string + NUL
    MAKE_BIG_LONG ('I', 'D', 'L', ':'),	// bytes of ID string
    MAKE_BIG_LONG ('E', 'n', 'g', '.'),
    MAKE_BIG_LONG ('S', 'U', 'N', '.'),
    MAKE_BIG_LONG ('C', 'O', 'M', '/'),
    MAKE_BIG_LONG ('t', 'e', 's', 't'),
    MAKE_BIG_LONG ('1', '/', 'x', '1'),
    MAKE_BIG_LONG (':', '1', '.', '0'),
    0,
    BIG_ENDIAN_LONG (1),		// (empty) namelen + NUL
    0,
    BIG_ENDIAN_LONG (1),		// only one struct member
    BIG_ENDIAN_LONG (1),		// (empty) member name + NUL
    0,
    BIG_ENDIAN_LONG (tk_long)
};
static CORBA_TypeCode tc_x1 (tk_except, sizeof oc_x1,
	    (unsigned char *)&oc_x1, CORBA_B_FALSE);
CORBA_TypeCode_ptr	_tc_test1_x1 = &tc_x1;



//
// "x2" exception typecode ... must be longword aligned
//
static CORBA_Long oc_x2 [] = {
    0,					// big endian flag + padding
    BIG_ENDIAN_LONG (29),		// length of ID string + NUL
    MAKE_BIG_LONG ('I', 'D', 'L', ':'),	// bytes of ID string
    MAKE_BIG_LONG ('E', 'n', 'g', '.'),
    MAKE_BIG_LONG ('S', 'U', 'N', '.'),
    MAKE_BIG_LONG ('C', 'O', 'M', '/'),
    MAKE_BIG_LONG ('t', 'e', 's', 't'),
    MAKE_BIG_LONG ('1', '/', 'x', '2'),
    MAKE_BIG_LONG (':', '1', '.', '0'),
    0,
    BIG_ENDIAN_LONG (1),		// (empty) namelen + NUL
    0,
    BIG_ENDIAN_LONG (2),		// two struct members

    BIG_ENDIAN_LONG (1),		// (empty) member name + NUL
    0,
    BIG_ENDIAN_LONG (tk_objref),
    BIG_ENDIAN_LONG (29),		// type ID + NUL
    MAKE_BIG_LONG ('I', 'D', 'L', ':'),	// bytes of ID string
    MAKE_BIG_LONG ('o', 'm', 'g', '.'),
    MAKE_BIG_LONG ('o', 'r', 'g', '/'),
    MAKE_BIG_LONG ('C', 'O', 'R', 'B'),
    MAKE_BIG_LONG ('A', '/', 'O', 'b'),
    MAKE_BIG_LONG ('j', 'e', 'c', 't'),
    MAKE_BIG_LONG (':', '1', '.', '0'),
    0,

    BIG_ENDIAN_LONG (1),		// (empty) member name + NUL
    0,
    BIG_ENDIAN_LONG (tk_long)
};
static CORBA_TypeCode tc_x2 (tk_except, sizeof oc_x2,
	    (unsigned char *)&oc_x2, CORBA_B_FALSE);
CORBA_TypeCode_ptr	_tc_test1_x2 = &tc_x2;


//
// parameter, exception, and call descriptions for "test_throw"
//
static const TAO_Param_Data test1_test_throw_paramdata [1] = {
    { _tc_CORBA_Long, PARAM_IN, 0 }
};

static CORBA_TypeCode_ptr test1_test_throw_excepts [2] = {
    &tc_x1, &tc_x2
};

extern const TAO_Call_Data test1_test_throw_calldata;

const TAO_Call_Data test1_test_throw_calldata = {
    "test_throw", CORBA_B_TRUE,
    1, &test1_test_throw_paramdata [0],
    2, &test1_test_throw_excepts [0]
};

//
// "test_throw" stub
//
void
test1_test_throw (
    test1_ptr		target,
    CORBA_Long	case_num,
    CORBA_Environment	&env		// throw (x1, x2)
)
{
    STUB_Object		*data;

    if (target->QueryInterface (IID_STUB_Object, (void **)&data)
	    != NOERROR)
	env.exception (new CORBA_INV_OBJREF (COMPLETED_NO));
    else {
	data->do_call (env, &test1_test_throw_calldata,
	    &case_num);
	data->Release ();
    }
}

//
// PLEASE EXIT
//

static const TAO_Call_Data test1_please_exit_calldata = {
    "please_exit", CORBA_B_FALSE,
    0, 0,
    0, 0
};

void
test1_please_exit (
    test1_ptr		target,
    CORBA_Environment	&env
)
{
    STUB_Object		*data;

    if (target->QueryInterface (IID_STUB_Object, (void **)&data)
	    != NOERROR)
	env.exception (new CORBA_INV_OBJREF (COMPLETED_NO));
    else {
	data->do_call (env, &test1_please_exit_calldata
	    );
	data->Release ();
    }
}