4
* Copyright Ericsson AB 2004-2009. All Rights Reserved.
6
* The contents of this file are subject to the Erlang Public License,
7
* Version 1.1, (the "License"); you may not use this file except in
8
* compliance with the License. You should have received a copy of the
9
* Erlang Public License along with this software. If not, it can be
10
* retrieved online at http://www.erlang.org/.
12
* Software distributed under the License is distributed on an "AS IS"
13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
* the License for the specific language governing rights and limitations
24
#include "ei_runner.h"
27
* Purpose: Read pids, funs and others without real meaning on the C side
28
* and pass it back to Erlang to test that it is still the same.
29
* Author: kent@erix.ericsson.se
32
#define EI_DECODE_ENCODE(FUNC,TYPE) \
43
message("ei_decode_" #FUNC ", arg is type " #TYPE); \
44
buf = read_packet(NULL); \
45
err = ei_decode_ ## FUNC(buf+1, &size1, &p); \
48
fail("decode returned non zero but not -1"); \
50
fail("decode returned non zero"); \
55
fail("size is < 1"); \
59
message("ei_encode_" #FUNC " buf is NULL, arg is type " #TYPE); \
60
err = ei_encode_ ## FUNC(NULL, &size2, &p); \
63
fail("size calculation returned non zero but not -1"); \
66
fail("size calculation returned non zero"); \
70
if (size1 != size2) { \
71
message("size1 = %d, size2 = %d\n",size1,size2); \
72
fail("decode and encode size differs when buf is NULL"); \
75
message("ei_encode_" #FUNC ", arg is type " #TYPE); \
76
err = ei_encode_ ## FUNC(buf2, &size3, &p); \
79
fail("returned non zero but not -1"); \
81
fail("returned non zero"); \
85
if (size1 != size3) { \
86
message("size1 = %d, size2 = %d\n",size1,size3); \
87
fail("decode and encode size differs"); \
90
send_buffer(buf2, size1); \
92
message("ei_x_encode_" #FUNC ", arg is type " #TYPE); \
94
err = ei_x_encode_ ## FUNC(&arg, &p); \
97
fail("returned non zero but not -1"); \
99
fail("returned non zero"); \
104
if (arg.index < 1) { \
105
fail("size is < 1"); \
109
send_buffer(arg.buff, arg.index); \
113
#define EI_DECODE_ENCODE_BIG(FUNC,TYPE) \
121
int err, index = 0, len, type; \
124
message("ei_decode_" #FUNC ", arg is type " #TYPE); \
125
buf = read_packet(NULL); \
126
ei_get_type(buf+1, &index, &type, &len); \
127
p = ei_alloc_big(len); \
128
err = ei_decode_ ## FUNC(buf+1, &size1, p); \
131
fail("decode returned non zero but not -1"); \
133
fail("decode returned non zero"); \
138
fail("size is < 1"); \
142
message("ei_encode_" #FUNC " buf is NULL, arg is type " #TYPE); \
143
err = ei_encode_ ## FUNC(NULL, &size2, p); \
146
fail("size calculation returned non zero but not -1"); \
149
fail("size calculation returned non zero"); \
153
if (size1 != size2) { \
154
message("size1 = %d, size2 = %d\n",size1,size2); \
155
fail("decode and encode size differs when buf is NULL"); \
158
message("ei_encode_" #FUNC ", arg is type " #TYPE); \
159
err = ei_encode_ ## FUNC(buf2, &size3, p); \
162
fail("returned non zero but not -1"); \
164
fail("returned non zero"); \
168
if (size1 != size3) { \
169
message("size1 = %d, size2 = %d\n",size1,size3); \
170
fail("decode and encode size differs"); \
173
send_buffer(buf2, size1); \
175
message("ei_x_encode_" #FUNC ", arg is type " #TYPE); \
177
err = ei_x_encode_ ## FUNC(&arg, p); \
180
fail("returned non zero but not -1"); \
182
fail("returned non zero"); \
187
if (arg.index < 1) { \
188
fail("size is < 1"); \
192
send_buffer(arg.buff, arg.index); \
200
/* ******************************************************************** */
202
TESTCASE(test_ei_decode_encode)
204
EI_DECODE_ENCODE(fun , erlang_fun);
205
EI_DECODE_ENCODE(pid , erlang_pid);
206
EI_DECODE_ENCODE(port , erlang_port);
207
EI_DECODE_ENCODE(ref , erlang_ref);
208
EI_DECODE_ENCODE(trace, erlang_trace);
210
EI_DECODE_ENCODE_BIG(big , erlang_big);
211
EI_DECODE_ENCODE_BIG(big , erlang_big);
212
EI_DECODE_ENCODE_BIG(big , erlang_big);
214
EI_DECODE_ENCODE_BIG(big , erlang_big);
215
EI_DECODE_ENCODE_BIG(big , erlang_big);
216
EI_DECODE_ENCODE_BIG(big , erlang_big);
218
/* Test large node containers... */
219
EI_DECODE_ENCODE(pid , erlang_pid);
220
EI_DECODE_ENCODE(port , erlang_port);
221
EI_DECODE_ENCODE(ref , erlang_ref);
222
EI_DECODE_ENCODE(pid , erlang_pid);
223
EI_DECODE_ENCODE(port , erlang_port);
224
EI_DECODE_ENCODE(ref , erlang_ref);
229
/* ******************************************************************** */