param: replace P_OCTAL variable setting with s3 version which uses sscanf
[Samba.git] / pidl / tests / ndr_alloc.pl
blob399fbd21d62c5a7854d7f2827348ac84988c2965
1 #!/usr/bin/perl
2 # NDR allocation tests
3 # (C) 2005 Jelmer Vernooij. Published under the GNU GPL
4 use strict;
6 use Test::More tests => 5 * 8;
7 use FindBin qw($RealBin);
8 use lib "$RealBin";
9 use Util qw(test_samba4_ndr);
11 # Check that an outgoing scalar pointer is allocated correctly
13 test_samba4_ndr("alloc-scalar",
15 typedef struct {
16 uint8 *x;
17 } bla;
19 [public] void TestAlloc([in] bla foo);
20 ','
21 uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 };
22 DATA_BLOB b = { data, 5 };
23 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
24 struct TestAlloc r;
26 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
27 return 1;
29 if (r.in.foo.x == NULL)
30 return 2;
32 if (*r.in.foo.x != 0x03)
33 return 3;
37 # Check that an outgoing buffer pointer is allocated correctly
38 test_samba4_ndr("alloc-buffer",
40 typedef struct { uint8 data; } blie;
41 typedef struct { blie *x; } bla;
43 [public] void TestAlloc([in] bla foo);
44 ','
45 uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 };
46 DATA_BLOB b = { data, 5 };
47 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
48 struct TestAlloc r;
50 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
51 return 1;
53 if (r.in.foo.x == NULL)
54 return 2;
56 if (r.in.foo.x->data != 0x03)
57 return 3;
61 # Check that ref pointers aren't allocated by default
62 test_samba4_ndr("ref-noalloc-null",
64 [public] void TestAlloc([in,ref] uint8 *t);
65 ','
66 uint8_t data[] = { 0x03 };
67 DATA_BLOB b = { data, 1 };
68 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
69 struct TestAlloc r;
70 r.in.t = NULL;
72 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
73 return 1;
77 # Check that ref pointers aren't allocated by default
78 test_samba4_ndr("ref-noalloc",
80 [public] void TestAlloc([in,ref] uint8 *t);
81 ','
82 uint8_t data[] = { 0x03 };
83 DATA_BLOB b = { data, 1 };
84 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
85 struct TestAlloc r;
86 uint8_t x;
87 r.in.t = &x;
89 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
90 return 1;
92 if (*r.in.t != 0x03)
93 return 2;
97 # Check that an outgoing ref pointer is allocated correctly
98 test_samba4_ndr("ref-alloc",
100 [public] void TestAlloc([in,ref] uint8 *t);
102 uint8_t data[] = { 0x03 };
103 DATA_BLOB b = { data, 1 };
104 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
105 struct TestAlloc r;
106 ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
107 r.in.t = NULL;
109 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
110 return 1;
112 if (r.in.t == NULL)
113 return 2;
115 if (*r.in.t != 0x03)
116 return 3;