build: Make install_with_python.sh more portable
[Samba/gebeck_regimport.git] / pidl / tests / ndr_align.pl
blobcc089eaa1f7aabf1f48266dd31e6613b68d352f4
1 #!/usr/bin/perl
2 # NDR alignment tests
3 # (C) 2005 Jelmer Vernooij. Published under the GNU GPL
4 use strict;
6 use Test::More tests => 5 * 8;
7 use FindBin qw($RealBin);
8 use lib "$RealBin";
9 use Util qw(test_samba4_ndr);
11 test_samba4_ndr('align-uint8-uint16',
13 typedef [public] struct {
14 uint8 x;
15 uint16 y;
16 } bla;
19 struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
20 struct bla r;
21 uint8_t expected[] = { 0x0D, 0x00, 0xef, 0xbe };
22 DATA_BLOB expected_blob = { expected, 4 };
23 DATA_BLOB result_blob;
24 r.x = 13;
25 r.y = 0xbeef;
27 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
28 return 1;
30 result_blob = ndr_push_blob(ndr);
32 if (data_blob_cmp(&result_blob, &expected_blob) != 0)
33 return 2;
34 ');
36 test_samba4_ndr('align-uint8-uint32',
38 typedef [public] struct {
39 uint8 x;
40 uint32 y;
41 } bla;
44 struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
45 struct bla r;
46 uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xef, 0xbe };
47 DATA_BLOB expected_blob = { expected, 8 };
48 DATA_BLOB result_blob;
49 r.x = 13;
50 r.y = 0xbeefbeef;
52 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
53 return 1;
55 result_blob = ndr_push_blob(ndr);
57 if (data_blob_cmp(&result_blob, &expected_blob) != 0)
58 return 2;
59 ');
62 test_samba4_ndr('align-uint8-hyper',
64 typedef [public] struct {
65 uint8 x;
66 hyper y;
67 } bla;
70 struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
71 struct bla r;
72 uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe };
74 DATA_BLOB expected_blob = { expected, 16 };
75 DATA_BLOB result_blob;
76 r.x = 13;
77 r.y = 0xbeefbeefbeefbeefLLU;
79 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
80 return 1;
82 result_blob = ndr_push_blob(ndr);
84 if (data_blob_cmp(&result_blob, &expected_blob) != 0)
85 return 2;
86 ');
88 test_samba4_ndr('noalignflag-uint8-uint16',
90 typedef [public] struct {
91 uint8 x;
92 uint16 y;
93 } bla;
96 struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
97 struct bla r;
98 uint8_t expected[] = { 0x0D, 0xef, 0xbe };
99 DATA_BLOB expected_blob = { expected, 3 };
100 DATA_BLOB result_blob;
101 ndr->flags |= LIBNDR_FLAG_NOALIGN;
103 r.x = 13;
104 r.y = 0xbeef;
106 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
107 return 1;
109 result_blob = ndr_push_blob(ndr);
111 if (data_blob_cmp(&result_blob, &expected_blob) != 0)
112 return 2;
115 test_samba4_ndr('align-blob-align2',
117 typedef [public] struct {
118 uint8 x;
119 [flag(LIBNDR_FLAG_ALIGN2)] DATA_BLOB data;
120 uint8 y;
121 } blie;
124 struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
125 struct blie r;
126 uint8_t data[] = { 0x01, 0x02 };
127 uint8_t expected[] = { 0x0D, 0x00, 0x0E };
128 DATA_BLOB expected_blob = { expected, 3 };
129 DATA_BLOB result_blob;
131 r.x = 13;
132 r.y = 14;
133 r.data.data = data;
134 r.data.length = 2;
136 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_blie(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
137 return 1;
139 result_blob = ndr_push_blob(ndr);
141 if (data_blob_cmp(&result_blob, &expected_blob) != 0)
142 return 2;