summaryrefslogtreecommitdiff
path: root/source4/build/pidl/tests/ndr_alloc.pl
blob: 7918f312d49a3c3c24d22a69c35bca67d6902fc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl
# NDR allocation tests
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;

use FindBin qw($RealBin);
use lib "$RealBin/..";
use test;

my %settings = Test::GetSettings(@ARGV);
$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
$settings{'IncludeFiles'} = ['ndr_test.h'];
$settings{'ExtraFiles'} = ['ndr_test.c'];

# Check that an outgoing scalar pointer is allocated correctly

Test::test_idl("alloc-scalar", \%settings, 
'	
	typedef struct {
		uint8 *x;
	} bla;
	
	[public] void TestAlloc([in] bla foo);
','
	uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 };
	DATA_BLOB b = { data, 5 };
	struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
	struct TestAlloc r;

	if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) 
		return 1;

	if (r.in.foo.x == NULL)
		return 2;
	
	if (*r.in.foo.x != 0x03)
		return 3;
'
);

# Check that an outgoing buffer pointer is allocated correctly
Test::test_idl("alloc-buffer", \%settings, 
'	
	typedef struct {
		uint8 data;
	} blie;

	typedef struct {
		blie *x;
	} bla;
	
	[public] void TestAlloc([in] bla foo);
','
	uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 };
	DATA_BLOB b = { data, 5 };
	struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
	struct TestAlloc r;

	if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) 
		return 1;

	if (r.in.foo.x == NULL)
		return 2;
	
	if (r.in.foo.x->data != 0x03)
		return 3;
'
);

# Check that ref pointers aren't allocated by default
Test::test_idl("ref-noalloc-null", \%settings, 
'	
	[public] void TestAlloc([in,ref] uint8 *t);
','
	uint8_t data[] = { 0x03 };
	DATA_BLOB b = { data, 1 };
	struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
	struct TestAlloc r;
	r.in.t = NULL;

	if (NT_STATUS_IS_OK(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) 
		return 1;
'
);

# Check that ref pointers aren't allocated by default
Test::test_idl("ref-noalloc", \%settings, 
'	
	[public] void TestAlloc([in,ref] uint8 *t);
','
	uint8_t data[] = { 0x03 };
	DATA_BLOB b = { data, 1 };
	struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
	struct TestAlloc r;
	uint8_t x;
	r.in.t = &x;

	if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) 
		return 1;

	if (*r.in.t != 0x03)
		return 2;
'
);

# Check that an outgoing ref pointer is allocated correctly
Test::test_idl("ref-alloc", \%settings, 
'	
	[public] void TestAlloc([in,ref] uint8 *t);
','
	uint8_t data[] = { 0x03 };
	DATA_BLOB b = { data, 1 };
	struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
	struct TestAlloc r;
	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
	r.in.t = NULL;

	if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) 
		return 1;

	if (r.in.t == NULL)
		return 2;

	if (*r.in.t != 0x03)
		return 3;
'
);