1 /*
2 * %CopyrightBegin%
3 *
4 * Copyright Ericsson AB 2001-2016. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * %CopyrightEnd%
19 *
20 */
21 /* C-client for test of IC.
22 *
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #ifndef __WIN32__
29 # include <unistd.h>
30 #endif
31
32 #include <string.h>
33
34 #ifdef __WIN32__
35 # include <time.h>
36 # include <sys/timeb.h>
37 #elif defined VXWORKS
38 #include <time.h>
39 #include <sys/times.h>
40 #else
41 #include <sys/time.h>
42 #endif
43
44 #include <ctype.h>
45
46 #ifdef __WIN32__
47 # include <winsock2.h>
48 # include <windows.h>
49 #else
50 # include <sys/types.h>
51 # include <sys/socket.h>
52 # include <netinet/in.h>
53 # include <arpa/inet.h>
54 # include <netdb.h>
55 #endif
56
57 #include "ei.h"
58 #include "erl_interface.h"
59 #include "m_i.h"
60
61 #define HOSTNAMESZ 255
62 #define NODENAMESZ 512
63
64 #define INBUFSZ 10
65 #define OUTBUFSZ 0
66
67 #define MAXTRIES 5
68
69 #define CHECK_EXCEPTION(x) \
70 if ((x)->_major != CORBA_NO_EXCEPTION) { \
71 fprintf(stderr,"\n\nException: %s\n\n", \
72 (char *)CORBA_exception_value((x))); \
73 CORBA_exception_free((x)); \
74 return -1; \
75 } \
76
77 /* XXX Should free things here too! */
78 #define RETURN_IF_OK(x) \
79 if ((x)) {\
80 fprintf(stdout, "ok\n");\
81 return 0;\
82 }\
83
84 #define cmp_str(x,y) (!strcmp((x),(y)))
85 #define cmp_wstr(x,y) (!ic_wstrcmp((x),(y)))
86
87 typedef CORBA_Environment IC_Env;
88
89 typedef int (*TestFunc)(IC_Env *);
90 typedef struct {
91 char *name;
92 TestFunc func;
93 } TestCase;
94
95 static char longtext[] =
96 "Introduction The IC application is an IDL compiler implemented in Erlang."
97 " The IDL compiler generates client stubs and server skeletons."
98 " Several back-ends are supported, and they fall into three main groups."
99 " For more details on IC compiler options consult the ic(3) manual page."
100 " Argument passing cases 1 Caller allocates all necessary storage,"
101 " except that which may be encapsulated and managed within the parameter itself."
102 " 2 The caller allocates a pointer and passes it by reference to the callee."
103 " The callee sets the pointer to point to a valid instance of the parameter's type."
104 " The caller is responsible for releasing the returned storage."
105 " Following completion of a request, the caller is not allowed to modify any values"
106 " in the returned storage. To do so the caller must first copy the returned instance"
107 " into a new instance, then modify the new instance. 3 The caller allocates a"
108 " pointer to an array slice which has all the same dimensions of the original"
109 " array except the first, and passes it by reference to the callee. The callee sets"
110 " the pointer to point to a valid instance of the array. The caller is responsible for"
111 " releasing the returned storage. Following completion of a request, the caller is not"
112 " allowed to modify any values in the returned storage. To do so the caller must first"
113 " copy the returned instance into a new instance, then modify the new instance."
114 " Generated Files Two files will be generated for each scope. One set of files will be"
115 " generated for each module and each interface scope. An extra set is generated for"
116 " those definitions at top level scope. One of the files is a header file(.h), and the"
117 " other file is a C source code file (.c). In addition to these files a number of C"
118 " source files will be generated for type encodings, they are named according to the "
119 "following template: oe_code_<type>.c.";
120 static char this_node[NODENAMESZ + 1];
121 static char *progname;
122
123 /* Test function prototypes */
124
125 static int void_test(IC_Env *env);
126 static int long_test(IC_Env *env);
127 static int long_long_test(IC_Env *env);
128 static int unsigned_short_test(IC_Env *env);
129 static int unsigned_long_test(IC_Env *env);
130 static int unsigned_long_long_test(IC_Env *env);
131 static int double_test(IC_Env *env);
132 static int char_test(IC_Env *env);
133 static int wchar_test(IC_Env *env);
134 static int octet_test(IC_Env *env);
135 static int bool_test(IC_Env *env);
136 static int struct_test(IC_Env *env);
137 static int struct2_test(IC_Env *env);
138 static int seq1_test(IC_Env *env);
139 static int seq2_test(IC_Env *env);
140 static int seq3_test(IC_Env *env);
141 static int seq4_test(IC_Env *env);
142 static int seq5_test(IC_Env *env);
143 static int array1_test(IC_Env *env);
144 static int array2_test(IC_Env *env);
145 static int enum_test(IC_Env *env);
146 static int string1_test(IC_Env *env);
147 static int string2_test(IC_Env *env);
148 static int string3_test(IC_Env *env);
149 static int string4_test(IC_Env *env);
150 static int pid_test(IC_Env *env);
151 static int port_test(IC_Env *env);
152 static int ref_test(IC_Env *env);
153 static int term_test(IC_Env *env);
154 static int typedef_test(IC_Env *env);
155 static int inline_sequence_test(IC_Env *env);
156 static int term_sequence_test(IC_Env *env);
157 static int term_struct_test(IC_Env *env);
158 static int wstring1_test(IC_Env *env);
159
160 static TestCase test_cases[] = {
161 {"void_test", void_test},
162 {"long_test", long_test},
163 {"long_long_test", long_long_test},
164 {"unsigned_short_test", unsigned_short_test},
165 {"unsigned_long_test", unsigned_long_test},
166 {"unsigned_long_long_test", unsigned_long_long_test},
167 {"double_test", double_test},
168 {"char_test", char_test},
169 {"wchar_test", wchar_test},
170 {"octet_test", octet_test},
171 {"bool_test", bool_test},
172 {"struct_test", struct_test},
173 {"struct2_test", struct2_test},
174 {"seq1_test", seq1_test},
175 {"seq2_test", seq2_test},
176 {"seq3_test", seq3_test},
177 {"seq4_test", seq4_test},
178 {"seq5_test", seq5_test},
179 {"array1_test", array1_test},
180 {"array2_test", array2_test},
181 {"enum_test", enum_test},
182 {"string1_test", string1_test},
183 {"string2_test", string2_test},
184 {"string3_test", string3_test},
185 {"string4_test", string4_test},
186 {"pid_test", pid_test},
187 {"port_test", port_test},
188 {"ref_test", ref_test},
189 {"term_test", term_test},
190 {"typedef_test", typedef_test},
191 {"inline_sequence_test", inline_sequence_test},
192 {"term_sequence_test", term_sequence_test},
193 {"term_struct_test", term_struct_test},
194 {"wstring1_test", wstring1_test},
195 {"", NULL}
196 };
197
198 /* Other prototypes */
199 static int cmp_aseq(m_aseq *a1, m_aseq *a2);
200 static int cmp_a(m_a *a1, m_a *a2);
201 static int cmp_bseq(m_bseq *b1, m_bseq *b2);
202 static int cmp_b(m_b *b1, m_b *b2);
203 static int cmp_lseq(m_lseq *b1, m_lseq *b2);
204 static int cmp_etseq(m_etseq *b1, m_etseq *b2);
205 static int cmp_et(m_et* b1, m_et *b2);
206 static int cmp_es(m_es *b1, m_es *b2);
207 static int cmp_arr1(m_arr1 b1, m_arr1 b2);
208 static int cmp_dd(m_dd b1, m_dd b2);
209 static int cmp_strRec(m_strRec *b1, m_strRec *b2);
210 static int cmp_sseq(m_sseq *b1, m_sseq *b2);
211 static int cmp_pid(erlang_pid *p1, erlang_pid *p2);
212 static int cmp_port(erlang_port *p1, erlang_port *p2);
213 static int cmp_ref(erlang_ref *p1, erlang_ref *p2);
214 static int cmp_s(m_s *b1, m_s *b2);
215 static int cmp_ssstr3(m_ssstr3 *b1, m_ssstr3 *b2);
216 static int cmp_ssarr3(m_ssarr3 *b1, m_ssarr3 *b2);
217 static int cmp_sarr3(m_sarr3 *b1, m_sarr3 *b2);
218 static int cmp_arr3(m_arr3 b1, m_arr3 b2);
219
220 static void print_aseq(m_aseq *a);
221 static void print_a(m_a *a);
222 static void print_bseq(m_bseq *b);
223 static void print_lseq(m_lseq *b);
224 static void print_b(m_b *b);
225 static void print_etseq(m_etseq *b);
226 static void print_et(m_et* b);
227 static void print_es(m_es *b);
228 static void print_arr1(long a[500]);
229 static void print_dd(long a[2][3]);
230 static void print_strRec(m_strRec* sr);
231 static void print_sseq(m_sseq *b);
232 static void print_pid(erlang_pid *p);
233 static void print_port(erlang_port *p);
234 static void print_ref(erlang_ref *p);
235 static void print_term(ETERM *t);
236 static void print_s(m_s *p);
237 static void print_ssstr3(m_ssstr3 *b1);
238 static void print_ssarr3(m_ssarr3 *b1);
239 static void print_sarr3(m_sarr3 *b1);
240 static void print_arr3(m_arr3 b1);
241 static void print_wstr(CORBA_wchar *ws);
242
243 static void free_etseq_buf(m_etseq *b);
244 static void free_et(m_et* b);
245
246 #ifdef __WIN32__
247 typedef struct {
248 long tv_sec;
249 long tv_usec;
250 } MyTimeval;
251 #else
252 typedef struct timeval MyTimeval;
253 #endif
254 static void my_gettimeofday(MyTimeval *tv);
255 static void showtime(MyTimeval *start, MyTimeval *stop);
256 static void usage(void);
257 static void done(int r);
258
259
260
261 /* main */
262
263 #ifdef VXWORKS
client(int argc,char ** argv)264 int client(int argc, char **argv)
265 #else
266 int main(int argc, char **argv)
267 #endif
268 {
269 struct hostent *hp;
270 erlang_pid pid;
271 MyTimeval start, stop;
272 int i, fd, ires, tres;
273 IC_Env *env;
274 int tries = 0;
275 char *this_node_name = NULL;
276 char *peer_node = NULL;
277 char *peer_process_name = NULL;
278 char *cookie = NULL;
279 char host[HOSTNAMESZ + 1];
280 TestFunc test_func = NULL;
281 TestCase *test_case;
282 char *test_case_name = NULL;
283
284 #ifdef __WIN32__
285 WORD wVersionRequested;
286 WSADATA wsaData;
287
288 wVersionRequested = MAKEWORD(2, 0);
289
290 if (WSAStartup(wVersionRequested, &wsaData) != 0) {
291 fprintf(stderr, "Could not load winsock2 v2.0 compatible DLL");
292 exit(1);
293 }
294 #endif
295
296 progname = argv[0];
297 host[HOSTNAMESZ] = '\0';
298 if (gethostname(host, HOSTNAMESZ + 1) < 0) {
299 fprintf(stderr, "Can't find own hostname\n");
300 done(1);
301 }
302 if ((hp = gethostbyname(host)) == 0) {
303 fprintf(stderr, "Can't get ip address for host %s\n", host);
304 done(1);
305 }
306 for (i = 1; i < argc; i++) {
307 if (cmp_str(argv[i], "-help")) {
308 usage();
309 done(0);
310 } else if (cmp_str(argv[i], "-this-node-name")) {
311 i++;
312 this_node_name = argv[i];
313 } else if (cmp_str(argv[i], "-peer-node")) {
314 i++;
315 peer_node = argv[i];
316 } else if (cmp_str(argv[i], "-peer-process-name")) {
317 i++;
318 peer_process_name = argv[i];
319 } else if (cmp_str(argv[i], "-cookie")) {
320 i++;
321 cookie = argv[i];
322 } else if (cmp_str(argv[i], "-test-case")) {
323 i++;
324 test_case_name = argv[i];
325 } else {
326 fprintf(stderr, "Error : invalid argument \"%s\"\n", argv[i]);
327 usage();
328 done(1);
329 }
330 }
331
332 if (this_node_name == NULL || peer_node == NULL || test_case_name == NULL
333 || peer_process_name == NULL || cookie == NULL) {
334 fprintf(stderr, "Error: missing option\n");
335 usage();
336 done(1);
337 }
338
339 test_case = test_cases;
340 while (test_case->func) {
341 if (cmp_str(test_case->name, test_case_name)) {
342 test_func = test_case->func;
343 break;
344 }
345 test_case++;
346 }
347 if (test_func == NULL) {
348 fprintf(stderr, "Error: illegal test case: \"%s\"\n", test_case_name);
349 done(1);
350 }
351
352 /* Behead hostname at first dot */
353 for (i=0; host[i] != '\0'; i++) {
354 if (host[i] == '.') { host[i] = '\0'; break; }
355 }
356 sprintf(this_node, "%s@%s", this_node_name, host);
357 fprintf(stderr, "c_client: this node: \"%s\"\n", this_node);
358 fprintf(stderr, "c_client: peer node: \"%s\"\n", peer_node);
359 fprintf(stderr, "c_client: test case: \"%s\"\n", test_case_name);
360
361 fprintf(stderr, "c_client: starting\n");
362
363 /* initialize erl_interface */
364 erl_init(NULL, 0);
365
366 for (tries = 0; tries < MAXTRIES; tries++) {
367
368 /* connect to erlang node */
369
370 ires = erl_connect_xinit(host, this_node_name, this_node,
371 (struct in_addr *)*hp->h_addr_list,
372 cookie, 0);
373
374 fprintf(stderr, "c_client: erl_connect_xinit(): %d\n", ires);
375
376 fd = erl_connect(peer_node);
377 fprintf(stderr, "c_client: erl_connect(): %d\n", fd);
378
379 if (fd >= 0)
380 break;
381 fprintf(stderr, "c_client: cannot connect, retrying\n");
382 }
383 if (fd < 0) {
384 fprintf(stderr, "c_client: cannot connect, exiting\n");
385 done(1);
386 }
387 env = CORBA_Environment_alloc(INBUFSZ, OUTBUFSZ);
388 env->_fd = fd;
389 strcpy(env->_regname, peer_process_name);
390 env->_to_pid = NULL;
391 env->_from_pid = &pid;
392 env->_memchunk = 32;
393
394 strcpy(pid.node, this_node);
395 pid.num = fd;
396 pid.serial = 0;
397 pid.creation = 0;
398
399 my_gettimeofday(&start);
400 tres = test_func(env); /* Call test case */
401 my_gettimeofday(&stop);
402 showtime(&start, &stop);
403 erl_close_connection(fd);
404
405 printf("c_client: env->_inbuf before : %d\n", INBUFSZ);
406 printf("c_client: env->_outbuf before : %d\n", OUTBUFSZ);
407 printf("c_client: env->_inbuf after : %d\n", env->_inbufsz);
408 printf("c_client: env->_outbuf after : %d\n", env->_outbufsz);
409
410 CORBA_free(env->_inbuf);
411 CORBA_free(env->_outbuf);
412 CORBA_free(env);
413 done(tres);
414 }
415
usage()416 static void usage()
417 {
418 fprintf(stderr, "Usage: %s [-help] -this-node-name <name> "
419 "-peer-node <nodename> -peer-process-name <name> "
420 "-cookie <cookie> -test-case <test case name>\n", progname);
421 fprintf(stderr, "Example:\n %s -this-node-name kalle "
422 "-peer-node olle@home -peer-process-name idltest "
423 "-cookie oa678er -test-case octet_test\n", progname);
424 }
425
done(int r)426 static void done(int r)
427 {
428 #ifdef __WIN32__
429 WSACleanup();
430 #endif
431 exit(r);
432 }
433
434
435 /* TESTS */
436
void_test(IC_Env * env)437 static int void_test(IC_Env *env)
438 {
439 fprintf(stdout, "\n======== m_i_void test ======\n\n");
440 m_i_void_test(NULL,env);
441 CHECK_EXCEPTION(env);
442 RETURN_IF_OK(1);
443 }
444
long_test(IC_Env * env)445 static int long_test(IC_Env *env)
446 {
447 long l = 4711, lo, lr;
448
449 fprintf(stdout, "\n======== m_i_long test ======\n\n");
450 lr = m_i_long_test(NULL, l, &lo, env);
451 CHECK_EXCEPTION(env);
452 RETURN_IF_OK(l == lo && l == lr);
453 if (l != lo)
454 fprintf(stdout, " out parameter error, sent: %ld, got: %ld\n", l, lo);
455 if (l != lr)
456 fprintf(stdout, " result error, sent: %ld, got: %ld\n", l, lr);
457 return -1;
458 }
459
long_long_test(IC_Env * env)460 static int long_long_test(IC_Env *env)
461 {
462 CORBA_long_long ll = 4711, llo, llr;
463
464 fprintf(stdout, "\n======== m_i_longlong test ======\n\n");
465 llr = m_i_longlong_test(NULL, ll, &llo, env);
466 CHECK_EXCEPTION(env);
467 RETURN_IF_OK(ll == llo && ll == llr);
468 if (ll != llo)
469 fprintf(stdout, " out parameter error, sent: %ld, got: %ld\n",
470 ll, llo);
471 if (ll != llr)
472 fprintf(stdout, " result error, sent: %ld, got: %ld\n", ll, llr);
473 return -1;
474 }
475
unsigned_short_test(IC_Env * env)476 static int unsigned_short_test(IC_Env *env)
477 {
478 unsigned short x, y = 2, z;
479
480 fprintf(stdout, "\n======== m_i_ushort test ======\n\n");
481 x = m_i_ushort_test(NULL, y, &z, env);
482 CHECK_EXCEPTION(env);
483 RETURN_IF_OK(y == z && y == x);
484 if (y != z)
485 fprintf(stdout, " out parameter error, sent: %d, got: %d\n", y, z);
486 if (y != x)
487 fprintf(stdout, " result error, sent: %d, got: %d\n", y, x);
488 return -1;
489 }
490
491
unsigned_long_test(IC_Env * env)492 static int unsigned_long_test(IC_Env *env)
493 {
494 unsigned long ul = 5050, ulo, ulr;
495
496 fprintf(stdout, "\n======== m_i_ulong test ======\n\n");
497 ulr = m_i_ulong_test(NULL, ul, &ulo, env);
498 CHECK_EXCEPTION(env);
499 RETURN_IF_OK(ul == ulo && ul == ulr);
500 if (ul != ulo)
501 fprintf(stdout, " out parameter error, sent: %lu, got: %lu\n",
502 ul, ulo);
503 if (ul != ulr)
504 fprintf(stdout, " result error, sent: %lu, got: %lu\n", ul, ulr);
505 return -1;
506 }
507
508 /*
509 * Note: CORBA_unsigned_long_long is in fact a plain long.
510 */
unsigned_long_long_test(IC_Env * env)511 static int unsigned_long_long_test(IC_Env *env)
512 {
513 CORBA_unsigned_long_long ull = 5050, ullo, ullr;
514
515 fprintf(stdout, "\n======== m_i_ulonglong test ======\n\n");
516 ullr = m_i_ulonglong_test(NULL, ull, &ullo, env);
517 CHECK_EXCEPTION(env);
518 RETURN_IF_OK(ull == ullo && ull == ullr);
519 if (ull != ullo)
520 fprintf(stdout, " out parameter error, sent: %lu, got: %lu\n",
521 ull, ullo);
522 if (ull != ullr)
523 fprintf(stdout, " result error, sent: %lu, got: %lu\n",
524 ull, ullr);
525 return -1;
526 }
527
double_test(IC_Env * env)528 static int double_test(IC_Env *env)
529 {
530 double d = 12.1212, db, dr;
531
532 fprintf(stdout, "\n======== m_i_double test ======\n\n");
533 dr = m_i_double_test(NULL, d, &db, env);
534 CHECK_EXCEPTION(env);
535 RETURN_IF_OK(d == db && d == dr);
536 if (d != db)
537 fprintf(stdout, " out parameter error, sent: %f, got: %f\n", d, db);
538 if (d != dr)
539 fprintf(stdout, " result error, sent: %f, got: %f\n", d, dr);
540 return -1;
541 }
542
char_test(IC_Env * env)543 static int char_test(IC_Env *env)
544 {
545 char c = 'g', co, cr;
546
547 /* char test */
548 fprintf(stdout, "\n======== m_i_char test ======\n\n");
549 cr = m_i_char_test(NULL, c, &co, env);
550 CHECK_EXCEPTION(env);
551 RETURN_IF_OK(c == co && c == cr);
552 if (c !=co)
553 fprintf(stdout, " out parameter error, sent: %c, got: %c\n", c, co);
554 if (c != cr)
555 fprintf(stdout, " result error, sent: %c, got: %c\n", c, cr);
556 return -1;
557 }
558
wchar_test(IC_Env * env)559 static int wchar_test(IC_Env *env)
560 {
561 CORBA_wchar wc = 103, wco, wcr;
562
563 fprintf(stdout, "\n======== m_i_wchar test ======\n\n");
564 wcr = m_i_wchar_test(NULL, wc, &wco, env);
565 CHECK_EXCEPTION(env);
566 RETURN_IF_OK(wc == wco && wc == wcr);
567 if (wc != wco)
568 fprintf(stdout, " out parameter error, sent: %lu, got: %lu\n",
569 wc, wco);
570 if (wc != wcr)
571 fprintf(stdout, " result error, sent: %lu, got: %lu\n",
572 wc, wcr);
573 return -1;
574 }
575
octet_test(IC_Env * env)576 static int octet_test(IC_Env *env)
577 {
578 char o ='r', oo, or;
579
580 fprintf(stdout, "\n======== m_i_octet test ======\n\n");
581 or = m_i_octet_test(NULL, o, &oo, env);
582 CHECK_EXCEPTION(env);
583 RETURN_IF_OK(o == oo && o == or);
584 if (o != oo)
585 fprintf(stdout, " out parameter error, sent: %c, got: %c\n", o, oo);
586 if (o != or)
587 fprintf(stdout, " result error, sent: %c, got: %c\n", o, or);
588 return -1;
589 }
590
bool_test(IC_Env * env)591 static int bool_test(IC_Env *env)
592 {
593 unsigned char i = 0, io, ir;
594
595 fprintf(stdout, "\n======== m_i_bool test ======\n\n");
596 ir = m_i_bool_test(NULL, i, &io, env);
597 CHECK_EXCEPTION(env);
598 RETURN_IF_OK(i == io && i == ir);
599 if (i != io)
600 fprintf(stdout, " out parameter error, sent: %d, got: %d\n", i, io);
601 if (i != ir)
602 fprintf(stdout, " result error, sent: %d, got: %d\n", i, ir);
603 return -1;
604 }
605
struct_test(IC_Env * env)606 static int struct_test(IC_Env *env)
607 {
608 m_b b = {4711, 'a'}, bo, br;
609
610 fprintf(stdout, "\n======== m_i_struct test ======\n\n");
611 br = m_i_struct_test(NULL, &b, &bo, env);
612 CHECK_EXCEPTION(env);
613 RETURN_IF_OK(cmp_b(&b, &bo) && cmp_b(&b, &br));
614 if (!cmp_b(&b, &bo)) {
615 fprintf(stdout, " out parameter error, sent:\n");
616 print_b(&b);
617 fprintf(stdout, " got:\n");
618 print_b(&bo);
619 fprintf(stdout, "\n");
620 }
621 if (!cmp_b(&b, &br)) {
622 fprintf(stdout, " result error, sent:\n");
623 print_b(&b);
624 fprintf(stdout, " got:\n");
625 print_b(&br);
626 fprintf(stdout, "\n");
627 }
628 return -1;
629 }
630
struct2_test(IC_Env * env)631 static int struct2_test(IC_Env *env)
632 {
633 m_es esi = {m_peach, 5050}, eso, esr;
634
635 fprintf(stdout, "\n======== m_i_struct2 test ======\n\n");
636 esr = m_i_struct2_test(NULL, &esi, &eso, env);
637 CHECK_EXCEPTION(env);
638 RETURN_IF_OK(cmp_es(&esi, &eso) && cmp_es(&esi, &esr));
639 if (!cmp_es(&esi, &eso)) {
640 fprintf(stdout, " out parameter error, sent:\n");
641 print_es(&esi);
642 fprintf(stdout, " got:\n");
643 print_es(&eso);
644 fprintf(stdout, "\n");
645 }
646 if (!cmp_es(&esi, &esr)) {
647 fprintf(stdout, " result error, sent:\n");
648 print_es(&esi);
649 fprintf(stdout, " got:\n");
650 print_es(&esr);
651 fprintf(stdout, "\n");
652 }
653 return -1;
654 }
655
656
seq1_test(IC_Env * env)657 static int seq1_test(IC_Env *env)
658 {
659 m_bseq bs, *bso, *bsr;
660
661 m_b ba[3] = {{4711, 'a'}, {4712, 'b'}, {4713, 'c'}};
662 bs._length = 3;
663 bs._buffer = ba;
664
665 fprintf(stdout, "\n======== m_i_seq1 test ======\n\n");
666 bsr = m_i_seq1_test(NULL, &bs, &bso, env);
667 CHECK_EXCEPTION(env);
668 RETURN_IF_OK(cmp_bseq(&bs, bso) && cmp_bseq(&bs, bsr));
669 if (!cmp_bseq(&bs, bso)) {
670 fprintf(stdout, " out parameter error, sent:\n");
671 print_bseq(&bs);
672 fprintf(stdout, " got:\n");
673 print_bseq(bso);
674 fprintf(stdout, "\n");
675 }
676 if (!cmp_bseq(&bs, bsr)) {
677 fprintf(stdout, " result error, sent:\n");
678 print_bseq(&bs);
679 fprintf(stdout, " got:\n");
680 print_bseq(bsr);
681 fprintf(stdout, "\n");
682 }
683 CORBA_free(bso);
684 CORBA_free(bsr);
685 return -1;
686 }
687
seq2_test(IC_Env * env)688 static int seq2_test(IC_Env *env)
689 {
690 m_b ba[3] = {{4711, 'a'}, {4712, 'b'}, {4713, 'c'}};
691 m_a a;
692 m_a aa[2];
693 m_aseq as, *aso, *asr;
694
695 a.l = 9999;
696 a.y._length = 3;
697 a.y._buffer = ba;
698 a.d = 66.89898989;
699
700 aa[0] = a;
701 aa[1] = a;
702 as._length = 2;
703 as._buffer = aa;
704
705 fprintf(stdout, "\n======== m_i_seq2 test ======\n\n");
706 asr = m_i_seq2_test(NULL, &as, &aso, env);
707 CHECK_EXCEPTION(env);
708 RETURN_IF_OK(cmp_aseq(&as, aso) && cmp_aseq(&as, asr));
709 if (!cmp_aseq(&as, aso)) {
710 fprintf(stdout, " out parameter error, sent:\n");
711 print_aseq(&as);
712 fprintf(stdout, " got:\n");
713 print_aseq(aso);
714 fprintf(stdout, "\n");
715 }
716 if (!cmp_aseq(&as, asr)) {
717 fprintf(stdout, " result error, sent:\n");
718 print_aseq(&as);
719 fprintf(stdout, " got:\n");
720 print_aseq(asr);
721 fprintf(stdout, "\n");
722 }
723 CORBA_free(aso);
724 CORBA_free(asr);
725 return -1;
726 }
727
seq3_test(IC_Env * env)728 static int seq3_test(IC_Env *env)
729 {
730 m_lseq lsi, *lso, *lsr;
731 long al[500];
732 int i=0;
733
734 for (i = 0; i < 500; i++)
735 al[i]=i;
736 lsi._length = 500;
737 lsi._buffer = al;
738
739 fprintf(stdout, "\n======== m_i_seq3 test ======\n\n");
740 lsr = m_i_seq3_test(NULL, &lsi, &lso, env);
741 CHECK_EXCEPTION(env);
742 RETURN_IF_OK(cmp_lseq(&lsi, lso) && cmp_lseq(&lsi, lsr));
743 if (!cmp_lseq(&lsi, lso)) {
744 fprintf(stdout, " out parameter error, sent:\n");
745 print_lseq(&lsi);
746 fprintf(stdout, " got:\n");
747 print_lseq(lso);
748 fprintf(stdout, "\n");
749 }
750 if (!cmp_lseq(&lsi, lsr)) {
751 fprintf(stdout, " result error, sent:\n");
752 print_lseq(&lsi);
753 fprintf(stdout, " got:\n");
754 print_lseq(lsr);
755 fprintf(stdout, "\n");
756 }
757 CORBA_free(lso);
758 CORBA_free(lsr);
759 return -1;
760 }
761
seq4_test(IC_Env * env)762 static int seq4_test(IC_Env *env)
763 {
764 char *stra0[3] = {"a", "long", "time"};
765 char *stra1[3] = {"ago", "there", "was"};
766 char *stra2[3] = {"a", "buggy", "compiler"};
767 m_sstr3 str3s[3] = {{3, 3, stra0}, {3, 3, stra1}, {3, 3, stra2}};
768 m_ssstr3 str3ssi = {3, 3, str3s};
769 m_ssstr3 *str3sso, *str3ssr;
770
771 fprintf(stdout, "\n======== m_i_seq4 test ======\n\n");
772 str3ssr = m_i_seq4_test(NULL, &str3ssi, &str3sso, env);
773 CHECK_EXCEPTION(env);
774 RETURN_IF_OK(cmp_ssstr3(&str3ssi, str3sso) &&
775 cmp_ssstr3(&str3ssi, str3ssr));
776 if (!cmp_ssstr3(&str3ssi, str3sso)){
777 fprintf(stdout, " out parameter error, sent:\n");
778 print_ssstr3(&str3ssi);
779 fprintf(stdout, " got:\n");
780 print_ssstr3(str3sso);
781 fprintf(stdout, "\n");
782 }
783 if (!cmp_ssstr3(&str3ssi, str3ssr)) {
784 fprintf(stdout, " result error, sent:\n");
785 print_ssstr3(&str3ssi);
786 fprintf(stdout, " got:\n");
787 print_ssstr3(str3ssr);
788 fprintf(stdout, "\n");
789 }
790 CORBA_free(str3sso);
791 CORBA_free(str3ssr);
792 return -1;
793 }
794
seq5_test(IC_Env * env)795 static int seq5_test(IC_Env *env)
796 {
797 m_arr3 arr3a[3] = {
798 {4711, 18931947, 3},
799 {4711, 18931947, 3},
800 {4711, 18931947, 3}};
801 m_sarr3 arr3sa[3] = {{3, 3, arr3a}, {3, 3, arr3a}, {3, 3, arr3a}};
802 m_ssarr3 arr3ssi = {3, 3, arr3sa};
803 m_ssarr3 *arr3sso;
804 m_ssarr3 *arr3ssr;
805
806 fprintf(stdout, "\n======== m_i_seq5 test ======\n\n");
807 arr3ssr = m_i_seq5_test(NULL, &arr3ssi, &arr3sso, env);
808 CHECK_EXCEPTION(env);
809 RETURN_IF_OK(cmp_ssarr3(&arr3ssi, arr3sso) &&
810 cmp_ssarr3(&arr3ssi, arr3ssr));
811 if (!cmp_ssarr3(&arr3ssi, arr3sso)) {
812 fprintf(stdout, " out parameter error, sent:\n");
813 print_ssarr3(&arr3ssi);
814 fprintf(stdout, " got:\n");
815 print_ssarr3(arr3sso);
816 fprintf(stdout, "\n");
817 }
818 if (!cmp_ssarr3(&arr3ssi, arr3ssr)) {
819 fprintf(stdout, " result error, sent:\n");
820 print_ssarr3(&arr3ssi);
821 fprintf(stdout, " got:\n");
822 print_ssarr3(arr3ssr);
823 fprintf(stdout, "\n");
824 }
825 CORBA_free(arr3sso);
826 CORBA_free(arr3ssr);
827 return -1;
828 }
829
array1_test(IC_Env * env)830 static int array1_test(IC_Env *env)
831 {
832 int i;
833 long al[500];
834 m_arr1 alo;
835 m_arr1_slice* alr;
836
837 for (i = 0; i < 500; i++)
838 al[i]=i;
839
840 fprintf(stdout, "\n======== m_i_array1 test ======\n\n");
841 alr = m_i_array1_test(NULL, al, alo, env);
842 CHECK_EXCEPTION(env);
843 RETURN_IF_OK(cmp_arr1(al, alo) && cmp_arr1(al, alr));
844 if (!cmp_arr1(al, alo)) {
845 fprintf(stdout, " out parameter error, sent:\n");
846 print_arr1(al);
847 fprintf(stdout, " got:\n");
848 print_arr1(alo);
849 fprintf(stdout, "\n");
850 }
851 if (!cmp_arr1(al,alr)) {
852 fprintf(stdout, " result error, sent:\n");
853 print_arr1(al);
854 fprintf(stdout, " got:\n");
855 print_arr1(alr);
856 fprintf(stdout, "\n");
857 }
858 free(alr);
859 return -1;
860 }
861
array2_test(IC_Env * env)862 static int array2_test(IC_Env *env)
863 {
864 long dl[2][3] = {{11, 2, 7}, {22, 8 ,13}};
865 m_dd dlo;
866 m_dd_slice* dlr;
867
868 fprintf(stdout, "\n======== m_i_array2 test ======\n\n");
869 dlr = m_i_array2_test(NULL, dl, dlo, env);
870 CHECK_EXCEPTION(env);
871 RETURN_IF_OK(cmp_dd(dl,dlo) && cmp_dd(dl,dlr));
872 if (!cmp_dd(dl,dlo)) {
873 fprintf(stdout, " out parameter error, sent:\n");
874 print_dd(dl);
875 fprintf(stdout, " got:\n");
876 print_dd(dlo);
877 fprintf(stdout, "\n");
878 }
879 if (!cmp_dd(dl,dlr)) {
880 fprintf(stdout, " result error, sent:\n");
881 print_dd(dl);
882 fprintf(stdout, " got:\n");
883 print_dd(dlr);
884 fprintf(stdout, "\n");
885 }
886 free(*dlr);
887 return -1;
888 }
889
enum_test(IC_Env * env)890 static int enum_test(IC_Env *env)
891 {
892 m_fruit ei = m_banana, eo, er;
893
894 fprintf(stdout, "\n======== m_i_enum test ======\n\n");
895 er = m_i_enum_test(NULL, ei, &eo, env);
896 CHECK_EXCEPTION(env);
897 RETURN_IF_OK(ei == eo && ei == er);
898 if (ei != eo)
899 fprintf(stdout, " out parameter error, sent: %d, got: %d\n", ei, eo);
900 if (ei != er)
901 fprintf(stdout, " result error, sent: %d, got: %d\n", ei, er);
902 return -1;
903 }
904
string1_test(IC_Env * env)905 static int string1_test(IC_Env *env)
906 {
907 char* si = longtext;
908 char* so;
909 char* sr;
910
911 fprintf(stdout, "\n======== m_i_string1 test ======\n\n");
912 sr = m_i_string1_test(NULL, si, &so, env);
913 CHECK_EXCEPTION(env);
914 RETURN_IF_OK(cmp_str(si, so) && cmp_str(si, sr));
915 if (!cmp_str(si, so))
916 fprintf(stdout, " out parameter error, sent: %s, got: %s\n", si, so);
917 if (!cmp_str(si, sr))
918 fprintf(stdout, " result error, sent: %s, got: %s\n", si, sr);
919 CORBA_free(so);
920 CORBA_free(sr);
921 return -1;
922 }
923
string2_test(IC_Env * env)924 static int string2_test(IC_Env *env)
925 {
926 char* sa[3] = {"hello", "foo", "bar"};
927 m_sseq ssi = {3, 3, sa};
928 m_sseq *sso, *ssr;
929
930 fprintf(stdout, "\n======== m_i_string2 test ======\n\n");
931 ssr = m_i_string2_test(NULL, &ssi, &sso, env);
932 CHECK_EXCEPTION(env);
933 RETURN_IF_OK(cmp_sseq(&ssi, sso) && cmp_sseq(&ssi, sso));
934 if (!cmp_sseq(&ssi, sso)) {
935 fprintf(stdout, " out parameter error, sent:\n");
936 print_sseq(&ssi);
937 fprintf(stdout, "got:\n");
938 print_sseq(sso);
939 }
940 if (!cmp_sseq(&ssi, ssr)) {
941 fprintf(stdout, " result error, sent:\n");
942 print_sseq(&ssi);
943 fprintf(stdout, "got:\n");
944 print_sseq(ssr);
945 }
946 CORBA_free(sso);
947 CORBA_free(ssr);
948 return -1;
949 }
950
string3_test(IC_Env * env)951 static int string3_test(IC_Env *env)
952 {
953 char* si = longtext;
954 char* so;
955 char* sr;
956
957 fprintf(stdout, "\n======== m_i_string3 test ======\n\n");
958 sr = m_i_string3_test(NULL, si, &so, env);
959 CHECK_EXCEPTION(env);
960 RETURN_IF_OK(cmp_str(si, so) && cmp_str(si, so));
961 if (!cmp_str(si, so))
962 fprintf(stdout, " out parameter error, sent: %s, got: %s\n", si, so);
963 if (!cmp_str(si, sr))
964 fprintf(stdout, " result error, sent: %s, got: %s\n", si, sr);
965 CORBA_free(so);
966 CORBA_free(sr);
967 return -1;
968 }
969
string4_test(IC_Env * env)970 static int string4_test(IC_Env *env)
971 {
972 char as1[100] = "a string", as2[200] = "help", as3[200] = "hello there";
973 m_strRec stri = { 1, /* dd */
974 as1, /* str4 */
975 {{'a', 'k'}, {'z', 'g'}, {'n', 'q'}}, /* str7 */
976 {3, 3, "buf"}, /* str5 */
977 as2, /* str6 */
978 {'m', 'f', 'o'}, /* str8 */
979 as3, /* str9 */
980 {3, 3, "stu"} /* str10 */
981 };
982 m_strRec *stro, *strr;
983
984 fprintf(stdout, "\n======== m_i_string4 test ======\n\n");
985 strr = m_i_string4_test(NULL, &stri, &stro, env);
986 CHECK_EXCEPTION(env);
987 RETURN_IF_OK(cmp_strRec(&stri,stro) && cmp_strRec(&stri,strr));
988 if (!cmp_strRec(&stri,stro)) {
989 fprintf(stdout, " out parameter error, sent:\n");
990 print_strRec(&stri);
991 fprintf(stdout, " got:\n");
992 print_strRec(stro);
993 fprintf(stdout, "\n");
994 }
995 if (!cmp_strRec(&stri,strr)) {
996 fprintf(stdout, " result error, sent:\n");
997 print_strRec(&stri);
998 fprintf(stdout, " got:\n");
999 print_strRec(strr);
1000 fprintf(stdout, "\n");
1001 }
1002 CORBA_free(stro);
1003 CORBA_free(strr);
1004 return -1;
1005 }
1006
1007
pid_test(IC_Env * env)1008 static int pid_test(IC_Env *env)
1009 {
1010 erlang_pid pid = {"", 7, 0, 0}, pido, pidr;
1011
1012 strcpy(pid.node, this_node), /* this currently running node */
1013 fprintf(stdout, "\n======== m_i_pid test ======\n\n");
1014 pidr = m_i_pid_test(NULL, &pid, &pido, env);
1015 CHECK_EXCEPTION(env);
1016 RETURN_IF_OK(cmp_pid(&pid, &pido) && cmp_pid(&pid, &pidr));
1017 if (!cmp_pid(&pid, &pido)) {
1018 fprintf(stdout, " out parameter error, sent:\n");
1019 print_pid(&pid);
1020 fprintf(stdout, "got:\n");
1021 print_pid(&pido);
1022 }
1023 if (!cmp_pid(&pid, &pidr)) {
1024 fprintf(stdout, " result error, sent:\n");
1025 print_pid(&pid);
1026 fprintf(stdout, "got:\n");
1027 print_pid(&pidr);
1028 }
1029 return -1;
1030 }
1031
port_test(IC_Env * env)1032 static int port_test(IC_Env *env)
1033 {
1034 erlang_port porti = {"node", 5, 1}, porto, portr;
1035
1036 fprintf(stdout, "\n======== m_i_port test ======\n\n");
1037 portr = m_i_port_test(NULL, &porti, &porto, env);
1038 CHECK_EXCEPTION(env);
1039 RETURN_IF_OK(cmp_port(&porti, &porto) && cmp_port(&porti, &portr));
1040 if (!cmp_port(&porti, &porto)) {
1041 fprintf(stdout, " out parameter error, sent:\n");
1042 print_port(&porti);
1043 fprintf(stdout, "got:\n");
1044 print_port(&porto);
1045 }
1046 if (!cmp_port(&porti, &portr)) {
1047 fprintf(stdout, " result error, sent:\n");
1048 print_port(&porti);
1049 fprintf(stdout, "got:\n");
1050 print_port(&portr);
1051 }
1052 return -1;
1053 }
1054
ref_test(IC_Env * env)1055 static int ref_test(IC_Env *env)
1056 {
1057 erlang_ref refi = { "node1", 3, {1, 2, 3}, 1},
1058 refo, refr;
1059
1060 fprintf(stdout, "\n======== m_i_ref test ======\n\n");
1061 refr = m_i_ref_test(NULL, &refi, &refo, env);
1062 CHECK_EXCEPTION(env);
1063 RETURN_IF_OK(cmp_ref(&refi, &refo) && cmp_ref(&refi, &refr));
1064 if (!cmp_ref(&refi, &refo)) {
1065 fprintf(stdout, " out parameter error, sent:\n");
1066 print_ref(&refi);
1067 fprintf(stdout, "got:\n");
1068 print_ref(&refo);
1069 }
1070 if (!cmp_ref(&refi, &refr)) {
1071 fprintf(stdout, " result error, sent:\n");
1072 print_ref(&refi);
1073 fprintf(stdout, "got:\n");
1074 print_ref(&refr);
1075 }
1076 return -1;
1077 }
1078
term_test(IC_Env * env)1079 static int term_test(IC_Env *env)
1080 {
1081 ETERM *ti, *to, *tr;
1082
1083 ti = erl_format("[{hej, 1, 23}, \"string\", {1.23, 45}]");
1084
1085 fprintf(stdout, "\n======== m_i_term test ======\n\n");
1086 tr = m_i_term_test(NULL, ti, &to, env);
1087 CHECK_EXCEPTION(env);
1088 RETURN_IF_OK(erl_match(ti, to) && erl_match(ti, tr));
1089 if (!erl_match(ti, to)) {
1090 fprintf(stdout, " out parameter error, sent:\n");
1091 print_term(ti);
1092 fprintf(stdout, "got:\n");
1093 print_term(to);
1094 }
1095 if (!erl_match(ti, tr)) {
1096 fprintf(stdout, " result error, sent:\n");
1097 print_term(ti);
1098 fprintf(stdout, "got:\n");
1099 print_term(tr);
1100 }
1101 erl_free_term(ti);
1102 erl_free_term(to);
1103 erl_free_term(tr);
1104 return -1;
1105 }
1106
typedef_test(IC_Env * env)1107 static int typedef_test(IC_Env *env)
1108 {
1109 m_banan mbi, mbo; /* erlang_port */
1110 m_apa mai; /* ETERM* */
1111 m_apa mao = NULL;
1112 long tl;
1113
1114 strcpy(mbi.node,"node");
1115 mbi.id = 15;
1116 mbi.creation = 1;
1117
1118 fprintf(stdout, "\n======== m_i_typedef test ======\n\n");
1119 mai = erl_format("[{hej, 1, 23}, \"string\", {1.23, 45}]");
1120 tl = m_i_typedef_test(NULL, mai, &mbi, &mao, &mbo, env);
1121 CHECK_EXCEPTION(env);
1122 RETURN_IF_OK(erl_match(mai, mao) && cmp_port(&mbi, &mbo) && tl == 4711);
1123 if (!erl_match(mai, mao)) {
1124 fprintf(stdout, " out parameter error (term), sent:\n");
1125 print_term(mai);
1126 fprintf(stdout, "got:\n");
1127 print_term(mao);
1128 }
1129 if (!cmp_port(&mbi, &mbo)) {
1130 fprintf(stdout, " out parameter error (port), sent:\n");
1131 print_port(&mbi);
1132 fprintf(stdout, "got:\n");
1133 print_port(&mbo);
1134 }
1135 if (tl != 4711) {
1136 fprintf(stdout, " result error, sent: 4711, got %ld\n", tl);
1137 }
1138 erl_free_term(mai);
1139 erl_free_term(mao);
1140 return -1;
1141 }
1142
inline_sequence_test(IC_Env * env)1143 static int inline_sequence_test(IC_Env *env)
1144 {
1145 int i;
1146 long al[500];
1147 m_s isi = {4711, {500, 10, al}},
1148 *iso, *isr;
1149
1150 for (i = 0; i < 500; i++)
1151 al[i]=i;
1152 fprintf(stdout, "\n======== m_i_inline_sequence test ======\n\n");
1153 isr = m_i_inline_sequence_test(NULL, &isi, &iso, env);
1154 CHECK_EXCEPTION(env);
1155 RETURN_IF_OK(cmp_s(&isi, iso) && cmp_s(&isi, isr));
1156 if (!cmp_s(&isi, iso)) {
1157 fprintf(stdout, " out parameter error, sent:\n");
1158 print_s(&isi);
1159 fprintf(stdout, "got:\n");
1160 print_s(iso);
1161 }
1162 if (!cmp_s(&isi, isr)) {
1163 fprintf(stdout, " result error, sent:\n");
1164 print_s(&isi);
1165 fprintf(stdout, "got:\n");
1166 print_s(isr);
1167 }
1168 CORBA_free(iso);
1169 CORBA_free(isr);
1170 return -1;
1171 }
1172
term_sequence_test(IC_Env * env)1173 static int term_sequence_test(IC_Env *env)
1174 {
1175 ETERM* et_array[4] = {
1176 erl_format("[{apa, 1, 23}, \"string\", {1.23, 45}]"),
1177 erl_format("[{banan, 1, 23}, \"string\", {1.23, 45}]"),
1178 erl_format("[{apelsin, 1, 23}, \"string\", {1.23, 45}]"),
1179 erl_format("[{mango, 1, 23}, \"string\", {1.23, 45}]")};
1180 m_etseq etsi = {4, 4, et_array}, *etso, *etsr;
1181
1182 fprintf(stdout, "\n======== m_i_term_sequence test ======\n\n");
1183 etsr = m_i_term_sequence_test(NULL, &etsi, &etso, env);
1184 CHECK_EXCEPTION(env);
1185 RETURN_IF_OK(cmp_etseq(&etsi, etso) && cmp_etseq(&etsi, etsr));
1186 if (!cmp_etseq(&etsi, etso)) {
1187 fprintf(stdout, " out parameter error, sent:\n");
1188 print_etseq(&etsi);
1189 fprintf(stdout, "got:\n");
1190 print_etseq(etso);
1191 }
1192 if (!cmp_etseq(&etsi, etsr)) {
1193 fprintf(stdout, " result error, sent:\n");
1194 print_etseq(&etsi);
1195 fprintf(stdout, "got:\n");
1196 print_etseq(etsr);
1197 }
1198 free_etseq_buf(&etsi);
1199 free_etseq_buf(etso);
1200 free_etseq_buf(etsr);
1201 CORBA_free(etso);
1202 CORBA_free(etsr);
1203 return -1;
1204 }
1205
term_struct_test(IC_Env * env)1206 static int term_struct_test(IC_Env *env)
1207 {
1208 m_et eti = { erl_format("[{hej, 1, 23}, \"string\", {1.23, 45}]"),
1209 121212 };
1210 m_et eto, etr;
1211
1212 fprintf(stdout, "\n======== m_i_term_struct test ======\n\n");
1213 etr = m_i_term_struct_test(NULL, &eti, &eto, env);
1214 CHECK_EXCEPTION(env);
1215 RETURN_IF_OK(cmp_et(&eti, &eto) && cmp_et(&eti, &etr));
1216 if (!cmp_et(&eti, &eto)) {
1217 fprintf(stdout, " out parameter error, sent:\n");
1218 print_et(&eti);
1219 fprintf(stdout, "got:\n");
1220 print_et(&eto);
1221 }
1222 if (!cmp_et(&eti, &etr)) {
1223 fprintf(stdout, " result error, sent:\n");
1224 print_et(&eti);
1225 fprintf(stdout, "got:\n");
1226 print_et(&etr);
1227 }
1228 free_et(&eti);
1229 free_et(&eto);
1230 free_et(&etr);
1231 return -1;
1232 }
1233
wstring1_test(IC_Env * env)1234 static int wstring1_test(IC_Env *env)
1235 {
1236 CORBA_wchar wsi[] = {100, 101, 102, 103, 104, 0}, *wso, *wsr;
1237
1238 fprintf(stdout, "\n======== m_i_wstring1 test ======\n\n");
1239 wsr = m_i_wstring1_test(NULL, wsi, &wso, env);
1240 CHECK_EXCEPTION(env);
1241 RETURN_IF_OK(cmp_wstr(wsi, wso) && cmp_wstr(wsi, wsr));
1242 if (!cmp_wstr(wsi, wso)) {
1243 fprintf(stdout, " out parameter error, sent: \n");
1244 print_wstr(wsi);
1245 fprintf(stdout, "got:\n");
1246 print_wstr(wso);
1247 }
1248 if (!cmp_wstr(wsi, wsr)) {
1249 fprintf(stdout, " result error, sent: \n");
1250 print_wstr(wsi);
1251 fprintf(stdout, "got:\n");
1252 print_wstr(wsr);
1253 }
1254 CORBA_free(wso);
1255 CORBA_free(wsr);
1256 return -1;
1257 }
1258
1259 /* Compare functions */
cmp_aseq(m_aseq * a1,m_aseq * a2)1260 static int cmp_aseq(m_aseq *a1, m_aseq *a2)
1261 {
1262 int i;
1263
1264 if (a1->_length != a2->_length)
1265 return 0;
1266 for (i = 0; i < a1->_length; i++)
1267 if (cmp_a(&(a1->_buffer[i]), &(a2->_buffer[i])) == 0)
1268 return 0;
1269 return 1;
1270 }
1271
cmp_a(m_a * a1,m_a * a2)1272 static int cmp_a(m_a *a1, m_a *a2)
1273 {
1274 return a1->l == a2->l &&
1275 a1->d == a2->d &&
1276 cmp_bseq(&a1->y, &a2->y);
1277 }
1278
cmp_bseq(m_bseq * b1,m_bseq * b2)1279 static int cmp_bseq(m_bseq *b1, m_bseq *b2)
1280 {
1281 int i;
1282
1283 if (b1->_length != b2->_length)
1284 return 0;
1285 for (i = 0; i < b1->_length; i++)
1286 if (cmp_b(&(b1->_buffer[i]), &(b2->_buffer[i])) == 0)
1287 return 0;
1288 return 1;
1289 }
1290
cmp_b(m_b * b1,m_b * b2)1291 static int cmp_b(m_b *b1, m_b *b2)
1292 {
1293 return b1->l == b2->l && b1->c == b2->c;
1294 }
1295
cmp_lseq(m_lseq * b1,m_lseq * b2)1296 static int cmp_lseq(m_lseq *b1, m_lseq *b2)
1297 {
1298 int i;
1299
1300 if (b1->_length != b2->_length)
1301 return 0;
1302 for (i = 0; i < b1->_length; i++)
1303 if (b1->_buffer[i] != b2->_buffer[i])
1304 return 0;
1305 return 1;
1306 }
1307
cmp_etseq(m_etseq * b1,m_etseq * b2)1308 static int cmp_etseq(m_etseq *b1, m_etseq *b2)
1309 {
1310 int i;
1311
1312 if (b1->_length != b2->_length)
1313 return 0;
1314 for (i = 0; i < b1->_length; i++)
1315 if (!erl_match(b1->_buffer[i], b2->_buffer[i]))
1316 return 0;
1317 return 1;
1318 }
1319
cmp_et(m_et * b1,m_et * b2)1320 static int cmp_et(m_et* b1, m_et *b2)
1321 {
1322 return erl_match(b1->e, b2->e) && b1->l == b2->l;
1323 }
1324
cmp_es(m_es * b1,m_es * b2)1325 static int cmp_es(m_es *b1, m_es *b2)
1326 {
1327 return b1->f == b2->f && b1->l == b2->l;
1328 }
1329
cmp_arr1(m_arr1 b1,m_arr1 b2)1330 static int cmp_arr1(m_arr1 b1, m_arr1 b2)
1331 {
1332 int i;
1333
1334 for (i = 0; i < 500; i++)
1335 if (b1[i] != b2[i])
1336 return 0;
1337 return 1;
1338 }
1339
cmp_dd(m_dd b1,m_dd b2)1340 static int cmp_dd(m_dd b1, m_dd b2)
1341 {
1342
1343 int i, j;
1344
1345 for (i = 0; i < 2; i++)
1346 for (j = 0; j < 3; j++)
1347 if (b1[i][j] != b2[i][j])
1348 return 0;
1349 return 1;
1350 }
1351
1352
1353
cmp_strRec(m_strRec * b1,m_strRec * b2)1354 static int cmp_strRec(m_strRec *b1, m_strRec *b2)
1355 {
1356 int i, j;
1357
1358 if (b1->bb != b2->bb)
1359 return 0;
1360 if (!cmp_str(b1->str4,b2->str4))
1361 return 0;
1362 if (b1->str5._length != b2->str5._length)
1363 return 0;
1364 for (j = 0; j < b1->str5._length; j++)
1365 if (b1->str5._buffer[j] != b2->str5._buffer[j])
1366 return 0;
1367 if (!cmp_str(b1->str6,b2->str6))
1368 return 0;
1369 for (i = 0; i < 3; i++)
1370 for (j = 0; j < 2; j++)
1371 if (b1->str7[i][j] != b2->str7[i][j])
1372 return 0;
1373 for (j = 0; j < 3; j++)
1374 if (b1->str8[j] != b2->str8[j])
1375 return 0;
1376 if (!cmp_str(b1->str9,b2->str9))
1377 return 0;
1378 if (b1->str10._length != b2->str10._length)
1379 return 0;
1380 for (j = 0; j < b1->str10._length; j++)
1381 if (b1->str10._buffer[j] != b2->str10._buffer[j])
1382 return 0;
1383 return 1;
1384 }
1385
1386
cmp_sseq(m_sseq * b1,m_sseq * b2)1387 static int cmp_sseq(m_sseq *b1, m_sseq *b2)
1388 {
1389 int i;
1390
1391 if (b1->_length != b2->_length)
1392 return 0;
1393 for (i = 0; i < b1->_length; i++)
1394 if (!cmp_str(b1->_buffer[i], b2->_buffer[i]))
1395 return 0;
1396 return 1;
1397 }
1398
1399
cmp_pid(erlang_pid * p1,erlang_pid * p2)1400 static int cmp_pid(erlang_pid *p1, erlang_pid *p2)
1401 {
1402 return cmp_str(p1->node,p2-> node) &&
1403 p1->num == p2->num &&
1404 p1->serial == p2->serial &&
1405 p1->creation == p2->creation;
1406 }
1407
cmp_port(erlang_port * p1,erlang_port * p2)1408 static int cmp_port(erlang_port *p1, erlang_port *p2)
1409 {
1410 return cmp_str(p1->node,p2-> node) && p1->id == p2->id;
1411 }
1412
cmp_ref(erlang_ref * p1,erlang_ref * p2)1413 static int cmp_ref(erlang_ref *p1, erlang_ref *p2)
1414 {
1415 return cmp_str(p1->node, p2->node) &&
1416 p1->len == p2->len &&
1417 (p1->len < 1 || p1->n[0] == p2->n[0]) &&
1418 (p1->len < 2 || p1->n[1] == p2->n[1]) &&
1419 (p1->len < 3 || p1->n[2] == p2->n[2]);
1420 }
1421
cmp_s(m_s * b1,m_s * b2)1422 static int cmp_s(m_s *b1, m_s *b2)
1423 {
1424 int i;
1425
1426 if (b1->l != b2->l)
1427 return 0;
1428 if (b1->sl._length != b2->sl._length)
1429 return 0;
1430 for (i = 0; i < b1->sl._length; i++)
1431 if (b1->sl._buffer[i] != b2->sl._buffer[i])
1432 return 0;
1433 return 1;
1434 }
1435
1436
cmp_ssstr3(m_ssstr3 * b1,m_ssstr3 * b2)1437 static int cmp_ssstr3(m_ssstr3 *b1, m_ssstr3 *b2)
1438 {
1439 int i,j;
1440
1441 if (b1->_length != b2->_length)
1442 return 0;
1443 for (i = 0; i < b1->_length; i++) {
1444 if (b1->_buffer[i]._length != b2->_buffer[i]._length)
1445 return 0;
1446 for (j = 0; j < b1->_buffer[i]._length; j++)
1447 if (!cmp_str(b1->_buffer[i]._buffer[j],
1448 b2->_buffer[i]._buffer[j]))
1449 return 0;
1450 }
1451 return 1;
1452 }
1453
1454
1455
cmp_ssarr3(m_ssarr3 * b1,m_ssarr3 * b2)1456 static int cmp_ssarr3(m_ssarr3 *b1, m_ssarr3 *b2)
1457 {
1458 int i;
1459
1460 if (b1->_length != b2->_length)
1461 return 0;
1462 for (i = 0; i < b1->_length; i++) {
1463 if (!cmp_sarr3(&b1->_buffer[i], &b2->_buffer[i]))
1464 return 0;
1465 }
1466 return 1;
1467 }
1468
cmp_sarr3(m_sarr3 * b1,m_sarr3 * b2)1469 static int cmp_sarr3(m_sarr3 *b1, m_sarr3 *b2)
1470 {
1471 int i;
1472
1473 if (b1->_length != b2->_length)
1474 return 0;
1475 for (i = 0; i < b1->_length; i++) {
1476 if (!cmp_arr3(b1->_buffer[i], b2->_buffer[i]))
1477 return 0;
1478 }
1479 return 1;
1480 }
1481
cmp_arr3(m_arr3 b1,m_arr3 b2)1482 static int cmp_arr3(m_arr3 b1, m_arr3 b2)
1483 {
1484 int i;
1485
1486 for (i = 0; i < sizeof(m_arr3)/sizeof(CORBA_long); i++) {
1487 if (b1[i] != b2[i])
1488 return 0;
1489 }
1490 return 1;
1491 }
1492
1493 /* Print functions */
print_aseq(m_aseq * a)1494 static void print_aseq(m_aseq *a)
1495 {
1496 int i;
1497 fprintf(stdout, "\nm_aseq size: %ld --------\n", a->_length);
1498 for (i = 0; i < a->_length; i++)
1499 print_a(&(a->_buffer[i]));
1500 }
1501
print_a(m_a * a)1502 static void print_a(m_a *a)
1503 {
1504 fprintf(stdout, "\nm_a --------\n l: %ld\n d:%f\n", a->l, a->d);
1505 print_bseq(&a->y);
1506 }
1507
print_bseq(m_bseq * b)1508 static void print_bseq(m_bseq *b)
1509 {
1510 int i;
1511
1512 fprintf(stdout, "\nm_bseq size: %ld --------\n",b->_length);
1513 for (i = 0; i < b->_length; i++)
1514 print_b(&(b->_buffer[i]));
1515 }
1516
print_lseq(m_lseq * b)1517 static void print_lseq(m_lseq *b)
1518 {
1519 int i;
1520
1521 fprintf(stdout, "\nm_lseq size: %ld --------\n",b->_length);
1522 for (i = 0; i < b->_length; i++)
1523 fprintf(stdout, "[%d]: %ld\n", i, b->_buffer[i]);
1524 }
1525
print_b(m_b * b)1526 static void print_b(m_b *b)
1527 {
1528 fprintf(stdout, "\nm_b --------\n l: %ld\n c: %c\n", b->l, b->c);
1529 }
1530
1531
print_etseq(m_etseq * b)1532 static void print_etseq(m_etseq *b)
1533 {
1534 int i;
1535
1536 for (i = 0; i < b->_length; i++) {
1537 fprintf(stdout, "[%d]:\n", i);
1538 erl_print_term(stdout, b->_buffer[i]);
1539 }
1540 }
1541
1542
print_et(m_et * b)1543 static void print_et(m_et* b)
1544 {
1545 fprintf(stdout, "\net struct --------\n");
1546 erl_print_term(stdout, b->e);
1547 fprintf(stdout, "long: %ld\n", b->l);
1548 fprintf(stdout, "\n--------\n");
1549 }
1550
print_es(m_es * b)1551 static void print_es(m_es *b)
1552 {
1553 fprintf(stdout, "\nm_es --------\n f: %d\n l: %ld\n", b->f, b->l);
1554 }
1555
1556
print_arr1(long a[10])1557 static void print_arr1(long a[10])
1558 {
1559 int i;
1560
1561 for (i = 0; i < 10; i++)
1562 fprintf(stdout, "\n[%d]: %ld\n", i, a[i]);
1563 }
1564
print_dd(long a[2][3])1565 static void print_dd(long a[2][3])
1566 {
1567 int i, j;
1568
1569 fprintf(stdout, "\nlong dd[2][3] --------\n");
1570 for (i = 0; i < 2; i++)
1571 for (j = 0; j < 3; j++)
1572 fprintf(stdout, "\n[%d][%d]: %ld\n", i, j, a[i][j]);
1573 }
1574
1575
print_strRec(m_strRec * sr)1576 static void print_strRec(m_strRec* sr)
1577 {
1578 int i, j;
1579
1580 fprintf(stdout, "\nboolean bb : %d\n",sr->bb);
1581 fprintf(stdout, "string str4 : %s\n",sr->str4);
1582 fprintf(stdout, "str7[2][3] :\n");
1583 for (i = 0; i < 3; i++)
1584 for (j = 0; j < 2; j++)
1585 fprintf(stdout, "str7[%d][%d]: %ld\n", i, j, sr->str7[i][j]);
1586 fprintf(stdout, "str5._length : %ld\n",sr->str5._length);
1587 for (j = 0; j < sr->str5._length; j++)
1588 fprintf(stdout, "str5._buffer[%d]: %c\n", j, sr->str5._buffer[j]);
1589 fprintf(stdout, "string str6 : %s\n",sr->str6);
1590 fprintf(stdout, "str8 :\n");
1591 for (j = 0; j < 3; j++)
1592 fprintf(stdout, "str8[%d]: %c\n", j, sr->str8[j]);
1593 fprintf(stdout, "string str9 : %s\n",sr->str9);
1594 fprintf(stdout, "str10._length : %ld\n",sr->str10._length);
1595 for (j = 0; j < sr->str10._length; j++)
1596 fprintf(stdout, "str10._buffer[%d]: %c\n", j, sr->str10._buffer[j]);
1597 }
1598
print_sseq(m_sseq * b)1599 static void print_sseq(m_sseq *b)
1600 {
1601 int i;
1602
1603 fprintf(stdout, "\nm_sseq size: %ld --------\n",b->_length);
1604 for (i = 0; i < b->_length; i++)
1605 fprintf(stdout, "%s\n", b->_buffer[i]);
1606
1607 }
1608
1609
print_pid(erlang_pid * p)1610 static void print_pid(erlang_pid *p)
1611 {
1612 fprintf(stdout, "\nerlang_pid --------\n node: %s\n num: %d\n "
1613 "serial: %d\n creation: %d\n",
1614 p->node, p->num, p->serial, p->creation);
1615 }
1616
print_port(erlang_port * p)1617 static void print_port(erlang_port *p)
1618 {
1619 fprintf(stdout, "\nerlang_port --------\n node: %s\n id: %d\n "
1620 "creation: %d\n", p->node, p->id, p->creation);
1621 }
1622
print_ref(erlang_ref * p)1623 static void print_ref(erlang_ref *p)
1624 {
1625 fprintf(stdout, "\nerlang_ref --------\n node: %s\n len: %d\n "
1626 "n[0]: %d\n n[1]: %d\n n[2]: %d\n creation: %d\n",
1627 p->node, p->len, p->n[0], p->n[1], p->n[2], p->creation);
1628 }
1629
print_term(ETERM * t)1630 static void print_term(ETERM *t)
1631 {
1632 fprintf(stdout, "\nETERM --------\n");
1633 erl_print_term(stdout, t);
1634 fprintf(stdout, "\n--------\n");
1635 }
1636
print_s(m_s * p)1637 static void print_s(m_s *p)
1638 {
1639 int i;
1640
1641 fprintf(stdout, "\n%ld\n", p->l);
1642 for (i = 0; i < p->sl._length; i++)
1643 fprintf(stdout, "\n[%d]: %ld\n", i, p->sl._buffer[i]);
1644 }
1645
1646
print_ssstr3(m_ssstr3 * b1)1647 static void print_ssstr3(m_ssstr3 *b1)
1648 {
1649 int i,j;
1650
1651 fprintf(stdout, "\nSSSTR3 --------\n");
1652 fprintf(stdout,"b1->_length = %ld\n",b1->_length);
1653 for (i = 0; i < b1->_length; i++) {
1654 fprintf(stdout,"\nb1->_buffer[%d]._length %ld\n",
1655 i, b1->_buffer[i]._length);
1656 for (j = 0; j < b1->_buffer[i]._length; j++)
1657 fprintf(stdout,"b1->_buffer[%d]._buffer[%d] = %s\n",
1658 i, j, b1->_buffer[i]._buffer[j]);
1659 }
1660 fprintf(stdout, "\n--------\n");
1661 }
1662
print_wstr(CORBA_wchar * ws)1663 static void print_wstr(CORBA_wchar *ws)
1664 {
1665 int i = 0;
1666
1667 fprintf(stdout, "\nwstr --------\n");
1668 while (ws[i]) {
1669 fprintf(stdout, "[%d]: %ld\n", i, ws[i]);
1670 i++;
1671 }
1672 fprintf(stdout, "\n--------\n");
1673 }
1674
1675
print_ssarr3(m_ssarr3 * b1)1676 static void print_ssarr3(m_ssarr3 *b1)
1677 {
1678 int i;
1679
1680 fprintf(stdout, "\nssarr3 --------\n");
1681 fprintf(stdout,"length: %ld\n",b1->_length);
1682 fprintf(stdout, "buffer:\n");
1683 for (i = 0; i < b1->_length; i++)
1684 print_sarr3(&b1->_buffer[i]);
1685 fprintf(stdout, "\n--------\n");
1686 }
1687
print_sarr3(m_sarr3 * b1)1688 static void print_sarr3(m_sarr3 *b1)
1689 {
1690 int i;
1691
1692 fprintf(stdout, "\nsarr3 --------\n");
1693 fprintf(stdout,"length: %ld\n",b1->_length);
1694 fprintf(stdout, "buffer:\n");
1695 for (i = 0; i < b1->_length; i++)
1696 print_arr3(b1->_buffer[i]);
1697 fprintf(stdout, "\n--------\n");
1698 }
1699
print_arr3(m_arr3 b1)1700 static void print_arr3(m_arr3 b1)
1701 {
1702 int i;
1703
1704 fprintf(stdout, "\narr3 --------\n");
1705 for (i = 0; i < sizeof(m_arr3)/sizeof(CORBA_long); i++)
1706 fprintf(stdout, "%ld ", b1[i]);
1707 fprintf(stdout, "\n--------\n");
1708 }
1709
free_etseq_buf(m_etseq * b)1710 static void free_etseq_buf(m_etseq *b)
1711 {
1712 int i;
1713
1714 for (i = 0; i < b->_length; i++)
1715 erl_free_term(b->_buffer[i]);
1716 }
1717
free_et(m_et * b)1718 static void free_et(m_et* b)
1719 {
1720 erl_free_term(b->e);
1721 }
1722
showtime(MyTimeval * start,MyTimeval * stop)1723 static void showtime(MyTimeval *start, MyTimeval *stop)
1724 {
1725 MyTimeval elapsed;
1726
1727 elapsed.tv_sec = stop->tv_sec - start->tv_sec;
1728 elapsed.tv_usec = stop->tv_usec - start->tv_usec;
1729 while (elapsed.tv_usec < 0) {
1730 elapsed.tv_sec -= 1;
1731 elapsed.tv_usec += 1000000;
1732 }
1733 fprintf(stderr,"%ld.%06ld seconds\n",elapsed.tv_sec, elapsed.tv_usec);
1734 }
1735
my_gettimeofday(MyTimeval * tv)1736 static void my_gettimeofday(MyTimeval *tv)
1737 #ifdef __WIN32__
1738 #define EPOCH_JULIAN_DIFF 11644473600i64
1739 {
1740 SYSTEMTIME t;
1741 FILETIME ft;
1742 LONGLONG lft;
1743
1744 GetSystemTime(&t);
1745 SystemTimeToFileTime(&t, &ft);
1746 memcpy(&lft, &ft, sizeof(lft));
1747 tv->tv_usec = (long) ((lft / 10i64) % 1000000i64);
1748 tv->tv_sec = (long) ((lft / 10000000i64) - EPOCH_JULIAN_DIFF);
1749 }
1750 #elif defined VXWORKS
1751 {
1752 int rate = sysClkRateGet(); /* Ticks per second */
1753 unsigned long ctick = tickGet();
1754 tv->tv_sec = ctick / rate; /* secs since reboot */
1755 tv->tv_usec = ((ctick - (tv->tv_sec * rate))*1000000)/rate;
1756 }
1757 #else
1758 {
1759 gettimeofday(tv, NULL);
1760 }
1761 #endif
1762