summaryrefslogtreecommitdiffstats
path: root/source4/pidl/tests/ndr_align.pl
blob: 55a86861ca1c2ab19f463ae88e44e640b5e55c25 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/perl
# NDR alignment tests
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;

use Test::More tests => 5 * 8;
use FindBin qw($RealBin);
use lib "$RealBin/../lib";
use lib "$RealBin";
use Util qw(test_samba4_ndr);

test_samba4_ndr('align-uint8-uint16', 
'
	typedef [public] struct { 
		uint8 x;
		uint16 y;
	} bla;
',
'
	struct ndr_push *ndr = ndr_push_init();
	struct bla r;
	uint8_t expected[] = { 0x0D, 0x00, 0xef, 0xbe };
	DATA_BLOB expected_blob = { expected, 4 };
	DATA_BLOB result_blob;
	r.x = 13;
	r.y = 0xbeef;

	if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
		return 1;

	result_blob = ndr_push_blob(ndr);
	
	if (!data_blob_equal(&result_blob, &expected_blob)) 
		return 2;
');

test_samba4_ndr('align-uint8-uint32', 
'
	typedef [public] struct { 
		uint8 x;
		uint32 y;
	} bla;
',
'
	struct ndr_push *ndr = ndr_push_init();
	struct bla r;
	uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xef, 0xbe };
	DATA_BLOB expected_blob = { expected, 8 };
	DATA_BLOB result_blob;
	r.x = 13;
	r.y = 0xbeefbeef;

	if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
		return 1;

	result_blob = ndr_push_blob(ndr);
	
	if (!data_blob_equal(&result_blob, &expected_blob)) 
		return 2;
');


test_samba4_ndr('align-uint8-hyper', 
'
	typedef [public] struct { 
		uint8 x;
		hyper y;
	} bla;
',
'
	struct ndr_push *ndr = ndr_push_init();
	struct bla r;
	uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
						   0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe };
	DATA_BLOB expected_blob = { expected, 16 };
	DATA_BLOB result_blob;
	r.x = 13;
	r.y = 0xbeefbeefbeefbeef;

	if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
		return 1;

	result_blob = ndr_push_blob(ndr);
	
	if (!data_blob_equal(&result_blob, &expected_blob)) 
		return 2;
');

test_samba4_ndr('noalignflag-uint8-uint16', 
'
	typedef [public] struct { 
		uint8 x;
		uint16 y;
	} bla;
',
'
	struct ndr_push *ndr = ndr_push_init();
	struct bla r;
	uint8_t expected[] = { 0x0D, 0xef, 0xbe };
	DATA_BLOB expected_blob = { expected, 3 };
	DATA_BLOB result_blob;
	ndr->flags |= LIBNDR_FLAG_NOALIGN;

	r.x = 13;
	r.y = 0xbeef;

	if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
		return 1;

	result_blob = ndr_push_blob(ndr);
	
	if (!data_blob_equal(&result_blob, &expected_blob)) 
		return 2;
');

SKIP: {

skip "align-blob-align2 is known to fail", 8;

test_samba4_ndr('align-blob-align2', 
'
	typedef [public] struct { 
		uint8 x;
		[flag(LIBNDR_FLAG_ALIGN2)] DATA_BLOB data;
	} bla;
',
'
	struct ndr_push *ndr = ndr_push_init();
	struct bla r;
	uint8_t data[] = { 0x01, 0x02 };
	uint8_t expected[] = { 0x0D, 0x00, 0x01, 0x02 };
	DATA_BLOB expected_blob = { expected, 4 };
	DATA_BLOB result_blob;

	r.x = 13;
	r.data.data = data;
	r.data.length = 2;

	if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
		return 1;

	result_blob = ndr_push_blob(ndr);

	printf("%02x%02x%02x%02x\n", result_blob.data[0], result_blob.data[1], result_blob.data[2], result_blob.data[3]);

	if (!data_blob_equal(&result_blob, &expected_blob)) 
		return 2;
');
}