~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 * 
 
4
 * Copyright Ericsson AB 2004-2009. All Rights Reserved.
 
5
 * 
 
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/.
 
11
 * 
 
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
 
15
 * under the License.
 
16
 * 
 
17
 * %CopyrightEnd%
 
18
 */
 
19
 
 
20
#ifdef VXWORKS
 
21
#include "reclaim.h"
 
22
#endif
 
23
 
 
24
#include "ei_runner.h"
 
25
 
 
26
/*
 
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
 
30
 */
 
31
 
 
32
#define EI_DECODE_ENCODE(FUNC,TYPE) \
 
33
  { \
 
34
    char *buf; \
 
35
    char buf2[1024]; \
 
36
    TYPE p; \
 
37
    int size1 = 0; \
 
38
    int size2 = 0; \
 
39
    int size3 = 0; \
 
40
    int err; \
 
41
    ei_x_buff arg; \
 
42
\
 
43
    message("ei_decode_" #FUNC ", arg is type " #TYPE); \
 
44
    buf = read_packet(NULL); \
 
45
    err = ei_decode_ ## FUNC(buf+1, &size1, &p); \
 
46
    if (err != 0) { \
 
47
      if (err != -1) { \
 
48
        fail("decode returned non zero but not -1"); \
 
49
      } else { \
 
50
        fail("decode returned non zero"); \
 
51
      } \
 
52
      return; \
 
53
    } \
 
54
    if (size1 < 1) { \
 
55
      fail("size is < 1"); \
 
56
      return; \
 
57
    } \
 
58
\
 
59
    message("ei_encode_" #FUNC " buf is NULL, arg is type " #TYPE); \
 
60
    err = ei_encode_ ## FUNC(NULL, &size2, &p); \
 
61
    if (err != 0) { \
 
62
      if (err != -1) { \
 
63
        fail("size calculation returned non zero but not -1"); \
 
64
        return; \
 
65
      } else { \
 
66
        fail("size calculation returned non zero"); \
 
67
        return; \
 
68
      } \
 
69
    } \
 
70
    if (size1 != size2) { \
 
71
      message("size1 = %d, size2 = %d\n",size1,size2); \
 
72
      fail("decode and encode size differs when buf is NULL"); \
 
73
      return; \
 
74
    } \
 
75
    message("ei_encode_" #FUNC ", arg is type " #TYPE); \
 
76
    err = ei_encode_ ## FUNC(buf2, &size3, &p); \
 
77
    if (err != 0) { \
 
78
      if (err != -1) { \
 
79
        fail("returned non zero but not -1"); \
 
80
      } else { \
 
81
        fail("returned non zero"); \
 
82
      } \
 
83
      return; \
 
84
    } \
 
85
    if (size1 != size3) { \
 
86
      message("size1 = %d, size2 = %d\n",size1,size3); \
 
87
      fail("decode and encode size differs"); \
 
88
      return; \
 
89
    } \
 
90
    send_buffer(buf2, size1); \
 
91
\
 
92
    message("ei_x_encode_" #FUNC ", arg is type " #TYPE); \
 
93
    ei_x_new(&arg); \
 
94
    err = ei_x_encode_ ## FUNC(&arg, &p); \
 
95
    if (err != 0) { \
 
96
      if (err != -1) { \
 
97
        fail("returned non zero but not -1"); \
 
98
      } else { \
 
99
        fail("returned non zero"); \
 
100
      } \
 
101
      ei_x_free(&arg); \
 
102
      return; \
 
103
    } \
 
104
    if (arg.index < 1) { \
 
105
      fail("size is < 1"); \
 
106
      ei_x_free(&arg); \
 
107
      return; \
 
108
    } \
 
109
    send_buffer(arg.buff, arg.index); \
 
110
    ei_x_free(&arg); \
 
111
  }
 
112
 
 
113
#define EI_DECODE_ENCODE_BIG(FUNC,TYPE) \
 
114
  { \
 
115
    char *buf; \
 
116
    char buf2[2048]; \
 
117
    TYPE *p; \
 
118
    int size1 = 0; \
 
119
    int size2 = 0; \
 
120
    int size3 = 0; \
 
121
    int err, index = 0, len, type; \
 
122
    ei_x_buff arg; \
 
123
\
 
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); \
 
129
    if (err != 0) { \
 
130
      if (err != -1) { \
 
131
        fail("decode returned non zero but not -1"); \
 
132
      } else { \
 
133
        fail("decode returned non zero"); \
 
134
      } \
 
135
      return; \
 
136
    } \
 
137
    if (size1 < 1) { \
 
138
      fail("size is < 1"); \
 
139
      return; \
 
140
    } \
 
141
\
 
142
    message("ei_encode_" #FUNC " buf is NULL, arg is type " #TYPE); \
 
143
    err = ei_encode_ ## FUNC(NULL, &size2, p); \
 
144
    if (err != 0) { \
 
145
      if (err != -1) { \
 
146
        fail("size calculation returned non zero but not -1"); \
 
147
        return; \
 
148
      } else { \
 
149
        fail("size calculation returned non zero"); \
 
150
        return; \
 
151
      } \
 
152
    } \
 
153
    if (size1 != size2) { \
 
154
      message("size1 = %d, size2 = %d\n",size1,size2); \
 
155
      fail("decode and encode size differs when buf is NULL"); \
 
156
      return; \
 
157
    } \
 
158
    message("ei_encode_" #FUNC ", arg is type " #TYPE); \
 
159
    err = ei_encode_ ## FUNC(buf2, &size3, p); \
 
160
    if (err != 0) { \
 
161
      if (err != -1) { \
 
162
        fail("returned non zero but not -1"); \
 
163
      } else { \
 
164
        fail("returned non zero"); \
 
165
      } \
 
166
      return; \
 
167
    } \
 
168
    if (size1 != size3) { \
 
169
      message("size1 = %d, size2 = %d\n",size1,size3); \
 
170
      fail("decode and encode size differs"); \
 
171
      return; \
 
172
    } \
 
173
    send_buffer(buf2, size1); \
 
174
\
 
175
    message("ei_x_encode_" #FUNC ", arg is type " #TYPE); \
 
176
    ei_x_new(&arg); \
 
177
    err = ei_x_encode_ ## FUNC(&arg, p); \
 
178
    if (err != 0) { \
 
179
      if (err != -1) { \
 
180
        fail("returned non zero but not -1"); \
 
181
      } else { \
 
182
        fail("returned non zero"); \
 
183
      } \
 
184
      ei_x_free(&arg); \
 
185
      return; \
 
186
    } \
 
187
    if (arg.index < 1) { \
 
188
      fail("size is < 1"); \
 
189
      ei_x_free(&arg); \
 
190
      return; \
 
191
    } \
 
192
    send_buffer(arg.buff, arg.index); \
 
193
    ei_x_free(&arg); \
 
194
    ei_free_big(p); \
 
195
  }
 
196
 
 
197
 
 
198
 
 
199
 
 
200
/* ******************************************************************** */
 
201
 
 
202
TESTCASE(test_ei_decode_encode)
 
203
{
 
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);
 
209
 
 
210
    EI_DECODE_ENCODE_BIG(big  , erlang_big);
 
211
    EI_DECODE_ENCODE_BIG(big  , erlang_big);
 
212
    EI_DECODE_ENCODE_BIG(big  , erlang_big);
 
213
 
 
214
    EI_DECODE_ENCODE_BIG(big  , erlang_big);
 
215
    EI_DECODE_ENCODE_BIG(big  , erlang_big);
 
216
    EI_DECODE_ENCODE_BIG(big  , erlang_big);
 
217
 
 
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);
 
225
 
 
226
    report(1);
 
227
}
 
228
 
 
229
/* ******************************************************************** */