r6856: Add a couple of tests that test for the behaviour described in
[samba.git] / source / build / pidl / tests / ndr_refptr.pl
1 #!/usr/bin/perl
2 # Simple tests for pidl's handling of ref pointers, based
3 # on tridge's ref_notes.txt
4 use strict;
5
6 use FindBin qw($RealBin);
7 use lib "$RealBin/..";
8 use test;
9
10 my %settings = (
11         'IDL-Arguments' => ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'],
12         'IncludeFiles' => ['ndr_test.h'],
13         'ExtraFiles' => ['ndr_test.c'],
14 );
15
16 Test::test_idl("noptr-push", \%settings, 
17 '       typedef struct {
18                 uint16 x;
19         } xstruct;
20
21         [public] uint16 echo_TestRef([in] xstruct foo);
22 ',
23 '
24         struct ndr_push *ndr = ndr_push_init();
25         uint16_t v = 13;
26         struct echo_TestRef r;
27         r.in.foo.x = v; 
28
29         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
30                 return 1;
31
32         if (ndr->offset != 2)
33                 return 2;
34
35         if (ndr->data[0] != 13 || ndr->data[1] != 0) 
36                 return 3;
37 ');
38
39 Test::test_idl("ptr-embedded-push", \%settings,
40 '   typedef struct {
41                 short *x;
42         } xstruct;
43
44         uint16 echo_TestRef([in] xstruct foo);
45 ',
46 '
47         uint16_t v = 13;
48         struct ndr_push *ndr = ndr_push_init();
49         struct echo_TestRef r;
50         r.in.foo.x = &v; 
51
52         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
53                 return 1;
54
55         if (ndr->offset != 6)
56                 return 2;
57
58         if (ndr->data[0] == 0 && ndr->data[1] == 0 && 
59             ndr->data[2] == 0 && ndr->data[3] == 0)
60                 return 3;
61
62         if (ndr->data[4] != 13 || ndr->data[5] != 0)
63                 return 4;
64 ');
65
66 Test::test_idl("ptr-embedded-push-null", \%settings,
67 '   typedef struct {
68                 short *x;
69         } xstruct;
70
71         uint16 echo_TestRef([in] xstruct foo);
72 ',
73 '
74         struct ndr_push *ndr = ndr_push_init();
75         struct echo_TestRef r;
76         r.in.foo.x = NULL; 
77
78         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
79                 return 1;
80
81         if (ndr->offset != 4)
82                 return 2;
83
84         if (ndr->data[0] != 0 || ndr->data[1] != 0 || 
85             ndr->data[2] != 0 || ndr->data[3] != 0)
86                 return 3;
87 ');
88
89 Test::test_idl("refptr-embedded-push", \%settings,
90 '
91         typedef struct {
92                 [ref] short *x;
93         } xstruct;
94
95         uint16 echo_TestRef([in] xstruct foo);
96 ',
97 '
98         uint16_t v = 13;
99         struct ndr_push *ndr = ndr_push_init();
100         struct echo_TestRef r;
101         r.in.foo.x = &v; 
102
103         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
104                 return 1;
105
106         if (ndr->offset != 6)
107                 return 2;
108
109         if (ndr->data[0] == 0 && ndr->data[1] == 0 && 
110             ndr->data[2] == 0 && ndr->data[3] == 0)
111                 return 3;
112
113         if (ndr->data[4] != 13 || ndr->data[5] != 0)
114                 return 4;
115 ');
116
117 Test::test_idl("refptr-embedded-push-null", \%settings,
118 '
119         typedef struct {
120                 [ref] short *x;
121         } xstruct;
122
123         uint16 echo_TestRef([in] xstruct foo);
124 ',
125 '
126         struct ndr_push *ndr = ndr_push_init();
127         struct echo_TestRef r;
128         r.in.foo.x = NULL; 
129
130         if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
131                 return 1;
132         /* Windows gives [client runtime error 0x6f4] */
133 ');
134
135 Test::test_idl("ptr-top-push", \%settings,
136 '
137         typedef struct {
138                 short x;
139         } xstruct;
140
141         uint16 echo_TestRef([in] xstruct *foo);
142 ',
143 '
144         struct ndr_push *ndr = ndr_push_init();
145         struct echo_TestRef r;
146         struct xstruct s;
147         s.x = 13;
148         r.in.foo = &s;
149
150         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
151                 return 1;
152
153         if (ndr->offset != 2)
154                 return 2;
155
156         if (ndr->data[0] != 13 || ndr->data[1] != 0)
157                 return 3;
158 ');
159
160 Test::test_idl("ptr-top-push-null", \%settings,
161 '
162         typedef struct {
163                 short x;
164         } xstruct;
165
166         uint16 echo_TestRef([in] xstruct *foo);
167 ',
168 '
169         struct ndr_push *ndr = ndr_push_init();
170         struct echo_TestRef r;
171         r.in.foo = NULL;
172
173         if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
174                 return 1;
175
176         /* Windows gives [client runtime error 0x6f4] */
177 ');
178
179
180 Test::test_idl("refptr-top-push", \%settings,
181 '
182         typedef struct {
183                 short x;
184         } xstruct;
185
186         uint16 echo_TestRef([in,ref] xstruct *foo);
187 ',
188 '
189         struct ndr_push *ndr = ndr_push_init();
190         struct echo_TestRef r;
191         struct xstruct s;
192         s.x = 13;
193         r.in.foo = &s;
194
195         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
196                 return 1;
197
198         if (ndr->offset != 2)
199                 return 2;
200
201         if (ndr->data[0] != 13 || ndr->data[1] != 0)
202                 return 3;
203 ');
204
205 Test::test_idl("refptr-top-push-null", \%settings,
206 '
207         typedef struct {
208                 short x;
209         } xstruct;
210
211         uint16 echo_TestRef([in,ref] xstruct *foo);
212 ',
213 '
214         struct ndr_push *ndr = ndr_push_init();
215         struct echo_TestRef r;
216         r.in.foo = NULL;
217
218         if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
219                 return 1;
220
221         /* Windows gives [client runtime error 0x6f4] */
222 ');
223
224
225 Test::test_idl("uniqueptr-top-push", \%settings,
226 '       typedef struct {
227                 short x;
228         } xstruct;
229
230         uint16 echo_TestRef([in,unique] xstruct *foo);
231 ',
232 '
233         struct ndr_push *ndr = ndr_push_init();
234         struct echo_TestRef r;
235         struct xstruct s;
236         s.x = 13;
237         r.in.foo = &s;
238
239         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
240                 return 1;
241
242         if (ndr->offset != 6)
243                 return 2;
244
245         if (ndr->data[0] == 0 && ndr->data[1] == 0 && 
246             ndr->data[2] == 0 && ndr->data[3] == 0)
247                 return 3;
248
249         if (ndr->data[4] != 13 || ndr->data[5] != 0)
250                 return 4;
251 ');
252
253 Test::test_idl("uniqueptr-top-push-null", \%settings,
254 '       typedef struct {
255                 short x;
256         } xstruct;
257
258         uint16 echo_TestRef([in,unique] xstruct *foo);
259 ',
260 '
261         struct ndr_push *ndr = ndr_push_init();
262         struct echo_TestRef r;
263         r.in.foo = NULL;
264
265         if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
266                 return 1;
267
268         if (ndr->offset != 4)
269                 return 2;
270
271         if (ndr->data[0] != 0 || ndr->data[1] != 0 || 
272             ndr->data[2] != 0 || ndr->data[3] != 0)
273                 return 3;
274 ');
275
276
277 #----------------------------------------------------
278 #       typedef struct {
279 #               short x;
280 #       } xstruct;
281 #
282 #       uint16 echo_TestRef([out] xstruct foo);
283 #
284 #        [idl compiler error]
285 #
286 #----------------------------------------------------
287 #       typedef struct {
288 #               short x;
289 #       } xstruct;
290 #
291 #       void echo_TestRef([out] xstruct *foo);
292 #
293 #       xstruct r;
294 #       echo_TestRef(&r);
295 #       r.x -> 13;
296 #
297 #       [0D 00]
298 #
299 #
300 #       echo_TestRef(NULL);
301 #
302 #       [client runtime error 0x6f4]
303 #
304 #----------------------------------------------------
305 #       typedef struct {
306 #               short x;
307 #       } xstruct;
308 #
309 #       void echo_TestRef([out,ref] xstruct *foo);
310 #
311 #       xstruct r;
312 #       echo_TestRef(&r);
313 #       r.x -> 13;
314 #
315 #       [0D 00]
316 #
317 #
318 #       echo_TestRef(NULL);
319 #
320 #       [client runtime error 0x6f4]
321 #
322 #----------------------------------------------------
323 #       typedef struct {
324 #               short x;
325 #       } xstruct;
326 #
327 #       void echo_TestRef([out,unique] xstruct *foo);
328 #
329 #        [idl compiler error]
330 #
331 #
332 #----------------------------------------------------
333 #       void echo_TestRef([in] short **foo);
334 #
335 #       short v = 13;
336 #       short *pv = &v;
337 #
338 #       echo_TestRef(&pv);
339 #
340 #       [PP PP PP PP 0D 00]
341 #
342 #
343 #       short *pv = NULL;
344 #
345 #       echo_TestRef(&pv);
346 #
347 #       [00 00 00 00]
348 #
349 #
350 #       echo_TestRef(NULL);
351 #       
352 #       [client runtime error 0x6f4]
353 #
354 #
355 #----------------------------------------------------
356 #       void echo_TestRef([in,ref] short **foo);
357 #
358 #       short v = 13;
359 #       short *pv = &v;
360 #
361 #       echo_TestRef(&pv);
362 #
363 #       [PP PP PP PP 0D 00]
364 #
365 #
366 #       short *pv = NULL;
367 #
368 #       echo_TestRef(&pv);
369 #
370 #       [00 00 00 00]
371 #
372 #
373 #       echo_TestRef(NULL);
374 #       
375 #       [client runtime error 0x6f4]