r6862: Add some more tests
[Samba/aatanasov.git] / source / build / pidl / tests / ndr_refptr.pl
blob59ebd295f6913142fe7b1099f27a06a7826e2187
1 #!/usr/bin/perl
2 # Simple tests for pidl's handling of ref pointers, based
3 # on tridge's ref_notes.txt
4 # (C) 2005 Jelmer Vernooij <jelmer@samba.org>.
5 # Published under the GNU General Public License.
6 use strict;
8 use FindBin qw($RealBin);
9 use lib "$RealBin/..";
10 use test;
12 my %settings = Test::GetSettings(@ARGV);
13 $settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
14 $settings{'IncludeFiles'} = ['ndr_test.h'];
15 $settings{'ExtraFiles'} = ['ndr_test.c'];
17 Test::test_idl("noptr-push", \%settings,
18 ' typedef struct {
19 uint16 x;
20 } xstruct;
22 [public] uint16 echo_TestRef([in] xstruct foo);
25 struct ndr_push *ndr = ndr_push_init();
26 uint16_t v = 13;
27 struct echo_TestRef r;
28 r.in.foo.x = v;
30 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r))) {
31 fprintf(stderr, "push failed\n");
32 return 1;
35 if (ndr->offset != 2) {
36 fprintf(stderr, "Offset(%d) != 2\n", ndr->offset);
37 return 2;
40 if (ndr->data[0] != 13 || ndr->data[1] != 0) {
41 fprintf(stderr, "Data incorrect\n");
42 return 3;
44 ');
46 Test::test_idl("ptr-embedded-push", \%settings,
47 ' typedef struct {
48 uint16 *x;
49 } xstruct;
51 [public] uint16 echo_TestRef([in] xstruct foo);
54 uint16_t v = 13;
55 struct ndr_push *ndr = ndr_push_init();
56 struct echo_TestRef r;
57 r.in.foo.x = &v;
59 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
60 return 1;
62 if (ndr->offset != 6)
63 return 2;
65 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
66 ndr->data[2] == 0 && ndr->data[3] == 0)
67 return 3;
69 if (ndr->data[4] != 13 || ndr->data[5] != 0)
70 return 4;
71 ');
73 Test::test_idl("ptr-embedded-push-null", \%settings,
74 ' typedef struct {
75 uint16 *x;
76 } xstruct;
78 [public] uint16 echo_TestRef([in] xstruct foo);
81 struct ndr_push *ndr = ndr_push_init();
82 struct echo_TestRef r;
83 r.in.foo.x = NULL;
85 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
86 return 1;
88 if (ndr->offset != 4)
89 return 2;
91 if (ndr->data[0] != 0 || ndr->data[1] != 0 ||
92 ndr->data[2] != 0 || ndr->data[3] != 0)
93 return 3;
94 ');
96 Test::test_idl("refptr-embedded-push", \%settings,
98 typedef struct {
99 [ref] uint16 *x;
100 } xstruct;
102 [public] uint16 echo_TestRef([in] xstruct foo);
105 uint16_t v = 13;
106 struct ndr_push *ndr = ndr_push_init();
107 struct echo_TestRef r;
108 r.in.foo.x = &v;
110 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
111 return 1;
113 if (ndr->offset != 6)
114 return 2;
116 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
117 ndr->data[2] == 0 && ndr->data[3] == 0)
118 return 3;
120 if (ndr->data[4] != 13 || ndr->data[5] != 0)
121 return 4;
124 Test::test_idl("refptr-embedded-push-null", \%settings,
126 typedef struct {
127 [ref] uint16 *x;
128 } xstruct;
130 [public] uint16 echo_TestRef([in] xstruct foo);
133 struct ndr_push *ndr = ndr_push_init();
134 struct echo_TestRef r;
135 r.in.foo.x = NULL;
137 if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
138 return 1;
139 /* Windows gives [client runtime error 0x6f4] */
142 Test::test_idl("ptr-top-push", \%settings,
144 typedef struct {
145 uint16 x;
146 } xstruct;
148 [public] uint16 echo_TestRef([in] xstruct *foo);
151 struct ndr_push *ndr = ndr_push_init();
152 struct echo_TestRef r;
153 struct xstruct s;
154 s.x = 13;
155 r.in.foo = &s;
157 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
158 return 1;
160 if (ndr->offset != 2)
161 return 2;
163 if (ndr->data[0] != 13 || ndr->data[1] != 0)
164 return 3;
167 Test::test_idl("ptr-top-push-null", \%settings,
169 typedef struct {
170 uint16 x;
171 } xstruct;
173 [public] uint16 echo_TestRef([in] xstruct *foo);
176 struct ndr_push *ndr = ndr_push_init();
177 struct echo_TestRef r;
178 r.in.foo = NULL;
180 if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
181 return 1;
183 /* Windows gives [client runtime error 0x6f4] */
187 Test::test_idl("refptr-top-push", \%settings,
189 typedef struct {
190 uint16 x;
191 } xstruct;
193 [public] uint16 echo_TestRef([in,ref] xstruct *foo);
196 struct ndr_push *ndr = ndr_push_init();
197 struct echo_TestRef r;
198 struct xstruct s;
199 s.x = 13;
200 r.in.foo = &s;
202 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
203 return 1;
205 if (ndr->offset != 2)
206 return 2;
208 if (ndr->data[0] != 13 || ndr->data[1] != 0)
209 return 3;
212 Test::test_idl("refptr-top-push-null", \%settings,
214 typedef struct {
215 uint16 x;
216 } xstruct;
218 [public] uint16 echo_TestRef([in,ref] xstruct *foo);
221 struct ndr_push *ndr = ndr_push_init();
222 struct echo_TestRef r;
223 r.in.foo = NULL;
225 if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
226 return 1;
228 /* Windows gives [client runtime error 0x6f4] */
232 Test::test_idl("uniqueptr-top-push", \%settings,
233 ' typedef struct {
234 uint16 x;
235 } xstruct;
237 [public] uint16 echo_TestRef([in,unique] xstruct *foo);
240 struct ndr_push *ndr = ndr_push_init();
241 struct echo_TestRef r;
242 struct xstruct s;
243 s.x = 13;
244 r.in.foo = &s;
246 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
247 return 1;
249 if (ndr->offset != 6)
250 return 2;
252 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
253 ndr->data[2] == 0 && ndr->data[3] == 0)
254 return 3;
256 if (ndr->data[4] != 13 || ndr->data[5] != 0)
257 return 4;
260 Test::test_idl("uniqueptr-top-push-null", \%settings,
261 ' typedef struct {
262 uint16 x;
263 } xstruct;
265 [public] uint16 echo_TestRef([in,unique] xstruct *foo);
268 struct ndr_push *ndr = ndr_push_init();
269 struct echo_TestRef r;
270 r.in.foo = NULL;
272 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
273 return 1;
275 if (ndr->offset != 4)
276 return 2;
278 if (ndr->data[0] != 0 || ndr->data[1] != 0 ||
279 ndr->data[2] != 0 || ndr->data[3] != 0)
280 return 3;
284 Test::test_idl("ptr-top-out-pull", \%settings,
286 typedef struct {
287 uint16 x;
288 } xstruct;
290 [public] void echo_TestRef([out] xstruct *foo);
293 uint8_t data[] = { 0x0D, 0x00 };
294 DATA_BLOB b = { data, 2 };
295 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
296 struct xstruct s;
297 struct echo_TestRef r;
299 r.out.foo = &s;
301 if (NT_STATUS_IS_ERR(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
302 return 1;
304 if (!r.out.foo)
305 return 2;
307 if (r.out.foo->x != 13)
308 return 3;
309 ');
311 Test::test_idl("ptr-top-out-pull-null", \%settings,
313 typedef struct {
314 uint16 x;
315 } xstruct;
317 [public] void echo_TestRef([out] xstruct *foo);
320 uint8_t data[] = { 0x0D, 0x00 };
321 DATA_BLOB b = { data, 2 };
322 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
323 struct echo_TestRef r;
325 r.out.foo = NULL;
327 if (NT_STATUS_IS_OK(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
328 return 1;
330 /* Windows gives [client runtime error 0x6f4] */
334 Test::test_idl("refptr-top-out-pull", \%settings,
336 typedef struct {
337 uint16 x;
338 } xstruct;
340 [public] void echo_TestRef([out,ref] xstruct *foo);
343 uint8_t data[] = { 0x0D, 0x00 };
344 DATA_BLOB b = { data, 2 };
345 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
346 struct xstruct s;
347 struct echo_TestRef r;
349 r.out.foo = &s;
351 if (NT_STATUS_IS_ERR(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
352 return 1;
354 if (!r.out.foo)
355 return 2;
357 if (r.out.foo->x != 13)
358 return 3;
359 ');
361 Test::test_idl("refptr-top-out-pull-null", \%settings,
363 typedef struct {
364 uint16 x;
365 } xstruct;
367 [public] void echo_TestRef([out,ref] xstruct *foo);
370 uint8_t data[] = { 0x0D, 0x00 };
371 DATA_BLOB b = { data, 2 };
372 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
373 struct echo_TestRef r;
375 r.out.foo = NULL;
377 if (NT_STATUS_IS_OK(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
378 return 1;
380 /* Windows gives [client runtime error 0x6f4] */
384 Test::test_idl("ptr-top-push-double", \%settings,
386 [public] void echo_TestRef([in] uint16 **foo);
388 ' struct ndr_push *ndr = ndr_push_init();
389 struct echo_TestRef r;
390 uint16_t v = 13;
391 uint16_t *pv = &v;
392 r.in.foo = &pv;
394 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
395 return 1;
397 if (ndr->offset != 6)
398 return 2;
400 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
401 ndr->data[2] == 0 && ndr->data[3] == 0)
402 return 3;
404 if (ndr->data[4] != 0x0D || ndr->data[5] != 0x00)
405 return 4;
408 Test::test_idl("ptr-top-push-double-sndnull", \%settings,
410 [public] void echo_TestRef([in] uint16 **foo);
412 ' struct ndr_push *ndr = ndr_push_init();
413 struct echo_TestRef r;
414 uint16_t *pv = NULL;
415 r.in.foo = &pv;
417 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
418 return 1;
420 if (ndr->offset != 4)
421 return 2;
423 if (ndr->data[0] != 0 || ndr->data[1] != 0 ||
424 ndr->data[2] != 0 || ndr->data[3] != 0)
425 return 3;
428 Test::test_idl("ptr-top-push-double-fstnull", \%settings,
430 [public] void echo_TestRef([in] uint16 **foo);
432 ' struct ndr_push *ndr = ndr_push_init();
433 struct echo_TestRef r;
434 r.in.foo = NULL;
436 if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
437 return 1;
439 /* Windows gives [client runtime error 0x6f4] */
444 Test::test_idl("refptr-top-push-double", \%settings,
446 [public] void echo_TestRef([in,ref] uint16 **foo);
448 ' struct ndr_push *ndr = ndr_push_init();
449 struct echo_TestRef r;
450 uint16_t v = 13;
451 uint16_t *pv = &v;
452 r.in.foo = &pv;
454 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
455 return 1;
457 if (ndr->offset != 6)
458 return 2;
460 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
461 ndr->data[2] == 0 && ndr->data[3] == 0)
462 return 3;
464 if (ndr->data[4] != 0x0D || ndr->data[5] != 0x00)
465 return 4;
468 Test::test_idl("refptr-top-push-double-sndnull", \%settings,
470 [public] void echo_TestRef([in,ref] uint16 **foo);
472 ' struct ndr_push *ndr = ndr_push_init();
473 struct echo_TestRef r;
474 uint16_t *pv = NULL;
475 r.in.foo = &pv;
477 if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
478 return 1;
480 if (ndr->offset != 4)
481 return 2;
483 if (ndr->data[0] != 0 || ndr->data[1] != 0 ||
484 ndr->data[2] != 0 || ndr->data[3] != 0)
485 return 3;
488 Test::test_idl("refptr-top-push-double-fstnull", \%settings,
490 [public] void echo_TestRef([in,ref] uint16 **foo);
492 ' struct ndr_push *ndr = ndr_push_init();
493 struct echo_TestRef r;
494 r.in.foo = NULL;
496 if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
497 return 1;
499 /* Windows gives [client runtime error 0x6f4] */