VERSION: Disable GIT_SNAPSHOT for the 4.16.0rc3 release.
[Samba.git] / pidl / tests / ndr_alloc.pl
blobc708c3b53936ea4d2ec92a275c1e8212092447bf
1 #!/usr/bin/perl
2 # NDR allocation tests
3 # (C) 2005 Jelmer Vernooij. Published under the GNU GPL
4 use strict;
5 use warnings;
7 use Test::More tests => 5 * 8;
8 use FindBin qw($RealBin);
9 use lib "$RealBin";
10 use Util qw(test_samba4_ndr);
12 # Check that an outgoing scalar pointer is allocated correctly
14 test_samba4_ndr("alloc-scalar",
16 typedef struct {
17 uint8 *x;
18 } bla;
20 [public] void TestAlloc([in] bla foo);
21 ','
22 uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 };
23 DATA_BLOB b = { data, 5 };
24 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
25 struct TestAlloc r;
27 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
28 return 1;
30 if (r.in.foo.x == NULL)
31 return 2;
33 if (*r.in.foo.x != 0x03)
34 return 3;
38 # Check that an outgoing buffer pointer is allocated correctly
39 test_samba4_ndr("alloc-buffer",
41 typedef struct { uint8 data; } blie;
42 typedef struct { blie *x; } bla;
44 [public] void TestAlloc([in] bla foo);
45 ','
46 uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 };
47 DATA_BLOB b = { data, 5 };
48 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
49 struct TestAlloc r;
51 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
52 return 1;
54 if (r.in.foo.x == NULL)
55 return 2;
57 if (r.in.foo.x->data != 0x03)
58 return 3;
62 # Check that ref pointers aren't allocated by default
63 test_samba4_ndr("ref-noalloc-null",
65 [public] void TestAlloc([in,ref] uint8 *t);
66 ','
67 uint8_t data[] = { 0x03 };
68 DATA_BLOB b = { data, 1 };
69 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
70 struct TestAlloc r;
71 r.in.t = NULL;
73 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
74 return 1;
78 # Check that ref pointers aren't allocated by default
79 test_samba4_ndr("ref-noalloc",
81 [public] void TestAlloc([in,ref] uint8 *t);
82 ','
83 uint8_t data[] = { 0x03 };
84 DATA_BLOB b = { data, 1 };
85 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
86 struct TestAlloc r;
87 uint8_t x;
88 r.in.t = &x;
90 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
91 return 1;
93 if (*r.in.t != 0x03)
94 return 2;
98 # Check that an outgoing ref pointer is allocated correctly
99 test_samba4_ndr("ref-alloc",
101 [public] void TestAlloc([in,ref] uint8 *t);
103 uint8_t data[] = { 0x03 };
104 DATA_BLOB b = { data, 1 };
105 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL, NULL);
106 struct TestAlloc r;
107 ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
108 r.in.t = NULL;
110 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
111 return 1;
113 if (r.in.t == NULL)
114 return 2;
116 if (*r.in.t != 0x03)
117 return 3;