1 | #!/usr/bin/perl
|
---|
2 | # NDR allocation tests
|
---|
3 | # (C) 2005 Jelmer Vernooij. Published under the GNU GPL
|
---|
4 | use strict;
|
---|
5 |
|
---|
6 | use Test::More tests => 5 * 8;
|
---|
7 | use FindBin qw($RealBin);
|
---|
8 | use lib "$RealBin";
|
---|
9 | use Util qw(test_samba4_ndr);
|
---|
10 |
|
---|
11 | # Check that an outgoing scalar pointer is allocated correctly
|
---|
12 |
|
---|
13 | test_samba4_ndr("alloc-scalar",
|
---|
14 | '
|
---|
15 | typedef struct {
|
---|
16 | uint8 *x;
|
---|
17 | } bla;
|
---|
18 |
|
---|
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;
|
---|
25 |
|
---|
26 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
|
---|
27 | return 1;
|
---|
28 |
|
---|
29 | if (r.in.foo.x == NULL)
|
---|
30 | return 2;
|
---|
31 |
|
---|
32 | if (*r.in.foo.x != 0x03)
|
---|
33 | return 3;
|
---|
34 | '
|
---|
35 | );
|
---|
36 |
|
---|
37 | # Check that an outgoing buffer pointer is allocated correctly
|
---|
38 | test_samba4_ndr("alloc-buffer",
|
---|
39 | '
|
---|
40 | typedef struct { uint8 data; } blie;
|
---|
41 | typedef struct { blie *x; } bla;
|
---|
42 |
|
---|
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;
|
---|
49 |
|
---|
50 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
|
---|
51 | return 1;
|
---|
52 |
|
---|
53 | if (r.in.foo.x == NULL)
|
---|
54 | return 2;
|
---|
55 |
|
---|
56 | if (r.in.foo.x->data != 0x03)
|
---|
57 | return 3;
|
---|
58 | '
|
---|
59 | );
|
---|
60 |
|
---|
61 | # Check that ref pointers aren't allocated by default
|
---|
62 | test_samba4_ndr("ref-noalloc-null",
|
---|
63 | '
|
---|
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;
|
---|
71 |
|
---|
72 | if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
|
---|
73 | return 1;
|
---|
74 | '
|
---|
75 | );
|
---|
76 |
|
---|
77 | # Check that ref pointers aren't allocated by default
|
---|
78 | test_samba4_ndr("ref-noalloc",
|
---|
79 | '
|
---|
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;
|
---|
88 |
|
---|
89 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
|
---|
90 | return 1;
|
---|
91 |
|
---|
92 | if (*r.in.t != 0x03)
|
---|
93 | return 2;
|
---|
94 | '
|
---|
95 | );
|
---|
96 |
|
---|
97 | # Check that an outgoing ref pointer is allocated correctly
|
---|
98 | test_samba4_ndr("ref-alloc",
|
---|
99 | '
|
---|
100 | [public] void TestAlloc([in,ref] uint8 *t);
|
---|
101 | ','
|
---|
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;
|
---|
108 |
|
---|
109 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestAlloc(ndr, NDR_IN, &r)))
|
---|
110 | return 1;
|
---|
111 |
|
---|
112 | if (r.in.t == NULL)
|
---|
113 | return 2;
|
---|
114 |
|
---|
115 | if (*r.in.t != 0x03)
|
---|
116 | return 3;
|
---|
117 | '
|
---|
118 | );
|
---|