lib/util: move copyright define to copyright.h
[Samba.git] / pidl / tests / ndr_refptr.pl
blob94676a80524ec294572236bacef6ae3e8f9637c6
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;
7 use warnings;
9 use Test::More tests => 22 * 8;
10 use FindBin qw($RealBin);
11 use lib "$RealBin";
12 use Util qw(test_samba4_ndr);
14 test_samba4_ndr("noptr-push",
15 ' typedef struct {
16 uint16 x;
17 } xstruct;
19 [public] uint16 echo_TestRef([in] xstruct foo);
22 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
23 uint16_t v = 13;
24 struct echo_TestRef r;
25 r.in.foo.x = v;
27 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r))) {
28 fprintf(stderr, "push failed\n");
29 return 1;
32 if (ndr->offset != 2) {
33 fprintf(stderr, "Offset(%d) != 2\n", ndr->offset);
34 return 2;
37 if (ndr->data[0] != 13 || ndr->data[1] != 0) {
38 fprintf(stderr, "Data incorrect\n");
39 return 3;
41 ');
43 test_samba4_ndr("ptr-embedded-push",
44 ' typedef struct {
45 uint16 *x;
46 } xstruct;
48 [public] uint16 echo_TestRef([in] xstruct foo);
51 uint16_t v = 13;
52 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
53 struct echo_TestRef r;
54 r.in.foo.x = &v;
56 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
57 return 1;
59 if (ndr->offset != 6)
60 return 2;
62 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
63 ndr->data[2] == 0 && ndr->data[3] == 0)
64 return 3;
66 if (ndr->data[4] != 13 || ndr->data[5] != 0)
67 return 4;
68 ');
70 test_samba4_ndr("ptr-embedded-push-null",
71 ' typedef struct {
72 uint16 *x;
73 } xstruct;
75 [public] uint16 echo_TestRef([in] xstruct foo);
78 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
79 struct echo_TestRef r;
80 r.in.foo.x = NULL;
82 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
83 return 1;
85 if (ndr->offset != 4)
86 return 2;
88 if (ndr->data[0] != 0 || ndr->data[1] != 0 ||
89 ndr->data[2] != 0 || ndr->data[3] != 0)
90 return 3;
91 ');
93 test_samba4_ndr("refptr-embedded-push",
95 typedef struct {
96 [ref] uint16 *x;
97 } xstruct;
99 [public] uint16 echo_TestRef([in] xstruct foo);
102 uint16_t v = 13;
103 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
104 struct echo_TestRef r;
105 r.in.foo.x = &v;
107 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
108 return 1;
110 if (ndr->offset != 6)
111 return 2;
113 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
114 ndr->data[2] == 0 && ndr->data[3] == 0)
115 return 3;
117 if (ndr->data[4] != 13 || ndr->data[5] != 0)
118 return 4;
121 test_samba4_ndr("refptr-embedded-push-null",
123 typedef struct {
124 [ref] uint16 *x;
125 } xstruct;
127 [public] uint16 echo_TestRef([in] xstruct foo);
130 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
131 struct echo_TestRef r;
132 r.in.foo.x = NULL;
134 if (NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
135 return 1;
136 /* Windows gives [client runtime error 0x6f4] */
139 test_samba4_ndr("ptr-top-push",
141 typedef struct {
142 uint16 x;
143 } xstruct;
145 [public] uint16 echo_TestRef([in] xstruct *foo);
148 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
149 struct echo_TestRef r;
150 struct xstruct s;
151 s.x = 13;
152 r.in.foo = &s;
154 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
155 return 1;
157 if (ndr->offset != 2)
158 return 2;
160 if (ndr->data[0] != 13 || ndr->data[1] != 0)
161 return 3;
164 test_samba4_ndr("ptr-top-push-null",
166 typedef struct {
167 uint16 x;
168 } xstruct;
170 [public] uint16 echo_TestRef([in] xstruct *foo);
173 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
174 struct echo_TestRef r;
175 r.in.foo = NULL;
177 if (NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
178 return 1;
180 /* Windows gives [client runtime error 0x6f4] */
184 test_samba4_ndr("refptr-top-push",
186 typedef struct {
187 uint16 x;
188 } xstruct;
190 [public] uint16 echo_TestRef([in,ref] xstruct *foo);
193 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
194 struct echo_TestRef r;
195 struct xstruct s;
196 s.x = 13;
197 r.in.foo = &s;
199 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
200 return 1;
202 if (ndr->offset != 2)
203 return 2;
205 if (ndr->data[0] != 13 || ndr->data[1] != 0)
206 return 3;
209 test_samba4_ndr("refptr-top-push-null",
211 typedef struct {
212 uint16 x;
213 } xstruct;
215 [public] uint16 echo_TestRef([in,ref] xstruct *foo);
218 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
219 struct echo_TestRef r;
220 r.in.foo = NULL;
222 if (NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
223 return 1;
225 /* Windows gives [client runtime error 0x6f4] */
229 test_samba4_ndr("uniqueptr-top-push",
230 ' typedef struct {
231 uint16 x;
232 } xstruct;
234 [public] uint16 echo_TestRef([in,unique] xstruct *foo);
237 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
238 struct echo_TestRef r;
239 struct xstruct s;
240 s.x = 13;
241 r.in.foo = &s;
243 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
244 return 1;
246 if (ndr->offset != 6)
247 return 2;
249 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
250 ndr->data[2] == 0 && ndr->data[3] == 0)
251 return 3;
253 if (ndr->data[4] != 13 || ndr->data[5] != 0)
254 return 4;
257 test_samba4_ndr("uniqueptr-top-push-null",
258 ' typedef struct {
259 uint16 x;
260 } xstruct;
262 [public] uint16 echo_TestRef([in,unique] xstruct *foo);
265 struct ndr_push *ndr = ndr_push_init_ctx(NULL);
266 struct echo_TestRef r;
267 r.in.foo = NULL;
269 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
270 return 1;
272 if (ndr->offset != 4)
273 return 2;
275 if (ndr->data[0] != 0 || ndr->data[1] != 0 ||
276 ndr->data[2] != 0 || ndr->data[3] != 0)
277 return 3;
281 test_samba4_ndr("ptr-top-out-pull",
283 typedef struct {
284 uint16 x;
285 } xstruct;
287 [public] void echo_TestRef([out] xstruct *foo);
290 uint8_t data[] = { 0x0D, 0x00 };
291 DATA_BLOB b = { data, 2 };
292 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
293 struct xstruct s;
294 struct echo_TestRef r;
296 r.out.foo = &s;
298 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
299 return 1;
301 if (!r.out.foo)
302 return 2;
304 if (r.out.foo->x != 13)
305 return 3;
306 ');
308 test_samba4_ndr("ptr-top-out-pull-null",
310 typedef struct {
311 uint16 x;
312 } xstruct;
314 [public] void echo_TestRef([out] xstruct *foo);
317 uint8_t data[] = { 0x0D, 0x00 };
318 DATA_BLOB b = { data, 2 };
319 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
320 struct echo_TestRef r;
322 r.out.foo = NULL;
324 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
325 return 1;
327 /* Windows gives [client runtime error 0x6f4] */
331 test_samba4_ndr("refptr-top-out-pull",
333 typedef struct {
334 uint16 x;
335 } xstruct;
337 [public] void echo_TestRef([out,ref] xstruct *foo);
340 uint8_t data[] = { 0x0D, 0x00 };
341 DATA_BLOB b = { data, 2 };
342 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
343 struct xstruct s;
344 struct echo_TestRef r;
346 r.out.foo = &s;
348 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
349 return 1;
351 if (!r.out.foo)
352 return 2;
354 if (r.out.foo->x != 13)
355 return 3;
356 ');
358 test_samba4_ndr("refptr-top-out-pull-null",
360 typedef struct {
361 uint16 x;
362 } xstruct;
364 [public] void echo_TestRef([out,ref] xstruct *foo);
367 uint8_t data[] = { 0x0D, 0x00 };
368 DATA_BLOB b = { data, 2 };
369 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
370 struct echo_TestRef r;
372 r.out.foo = NULL;
374 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_echo_TestRef(ndr, NDR_OUT, &r)))
375 return 1;
377 /* Windows gives [client runtime error 0x6f4] */
381 test_samba4_ndr("ptr-top-push-double",
383 [public] void echo_TestRef([in] uint16 **foo);
385 ' struct ndr_push *ndr = ndr_push_init_ctx(NULL);
386 struct echo_TestRef r;
387 uint16_t v = 13;
388 uint16_t *pv = &v;
389 r.in.foo = &pv;
391 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
392 return 1;
394 if (ndr->offset != 6)
395 return 2;
397 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
398 ndr->data[2] == 0 && ndr->data[3] == 0)
399 return 3;
401 if (ndr->data[4] != 0x0D || ndr->data[5] != 0x00)
402 return 4;
405 SKIP: {
406 skip "ptr-top-push-double-sndnull is known to fail", 8;
408 test_samba4_ndr("ptr-top-push-double-sndnull",
410 [public] void echo_TestRef([in] uint16 **foo);
412 ' struct ndr_push *ndr = ndr_push_init_ctx(NULL);
413 struct echo_TestRef r;
414 uint16_t *pv = NULL;
415 r.in.foo = &pv;
417 if (!NDR_ERR_CODE_IS_SUCCESS(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;
429 test_samba4_ndr("ptr-top-push-double-fstnull",
431 [public] void echo_TestRef([in] uint16 **foo);
433 ' struct ndr_push *ndr = ndr_push_init_ctx(NULL);
434 struct echo_TestRef r;
435 r.in.foo = NULL;
437 if (NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
438 return 1;
440 /* Windows gives [client runtime error 0x6f4] */
445 test_samba4_ndr("refptr-top-push-double",
447 [public] void echo_TestRef([in,ref] uint16 **foo);
449 ' struct ndr_push *ndr = ndr_push_init_ctx(NULL);
450 struct echo_TestRef r;
451 uint16_t v = 13;
452 uint16_t *pv = &v;
453 r.in.foo = &pv;
455 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
456 return 1;
458 if (ndr->offset != 6)
459 return 2;
461 if (ndr->data[0] == 0 && ndr->data[1] == 0 &&
462 ndr->data[2] == 0 && ndr->data[3] == 0)
463 return 3;
465 if (ndr->data[4] != 0x0D || ndr->data[5] != 0x00)
466 return 4;
469 SKIP: {
471 skip "refptr-top-push-double-sndnull is known to fail", 8;
473 test_samba4_ndr("refptr-top-push-double-sndnull",
475 [public] void echo_TestRef([in,ref] uint16 **foo);
477 ' struct ndr_push *ndr = ndr_push_init_ctx(NULL);
478 struct echo_TestRef r;
479 uint16_t *pv = NULL;
480 r.in.foo = &pv;
482 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
483 return 1;
485 if (ndr->offset != 4)
486 return 2;
488 if (ndr->data[0] != 0 || ndr->data[1] != 0 ||
489 ndr->data[2] != 0 || ndr->data[3] != 0)
490 return 3;
494 test_samba4_ndr("refptr-top-push-double-fstnull",
496 [public] void echo_TestRef([in,ref] uint16 **foo);
498 ' struct ndr_push *ndr = ndr_push_init_ctx(NULL);
499 struct echo_TestRef r;
500 r.in.foo = NULL;
502 if (NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
503 return 1;
505 /* Windows gives [client runtime error 0x6f4] */
509 SKIP: {
510 skip "ignore-ptrs are not supported yet", 8;
511 test_samba4_ndr("ignore-ptr",
513 [public] void echo_TestRef([in,ignore] uint16 *foo, [in] uint16 *bar);
515 ' struct ndr_push *ndr = ndr_push_init_ctx(NULL);
516 struct echo_TestRef r;
517 uint16_t v = 10;
518 r.in.foo = &v;
519 r.in.bar = &v;
521 if (NDR_ERR_CODE_IS_SUCCESS(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
522 return 1;
524 if (ndr->offset != 4)
525 return 2;