summaryrefslogtreecommitdiff
path: root/source4/build/pidl/tests/ndr_align.pl
blob: c428dd32bdf8b4d9bfc8b64bbbbd0da1aeca3f77 (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
#!/usr/bin/perl
# NDR alignment tests
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;

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

my %settings = (
	'IDL-Arguments' => ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'],
	'IncludeFiles' => ['ndr_test.h'],
	'ExtraFiles' => ['ndr_test.c'],
);

Test::test_idl('align-uint8-uint16', \%settings,
'
	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::test_idl('align-uint8-uint32', \%settings,
'
	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::test_idl('align-uint8-hyper', \%settings,
'
	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;
');