r22476: The OID match is used very oddly in AD, as it is often used for fields
[Samba.git] / source / pidl / tests / ndr.pl
blob8245f768e8463a1d86487567bf430187631ca05a
1 #!/usr/bin/perl
2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
4 use strict;
5 use warnings;
7 use Test::More tests => 26;
8 use FindBin qw($RealBin);
9 use lib "$RealBin";
10 use Util;
11 use Parse::Pidl::Util qw(MyDumper);
12 use Parse::Pidl::NDR qw(GetElementLevelTable ParseElement align_type mapToScalar ParseType);
14 # Case 1
16 my $e = {
17 'FILE' => 'foo.idl',
18 'NAME' => 'v',
19 'PROPERTIES' => {},
20 'POINTERS' => 0,
21 'TYPE' => 'uint8',
22 'PARENT' => { TYPE => 'STRUCT' },
23 'LINE' => 42 };
25 is_deeply(GetElementLevelTable($e), [
27 'IS_DEFERRED' => 0,
28 'LEVEL_INDEX' => 0,
29 'DATA_TYPE' => 'uint8',
30 'CONTAINS_DEFERRED' => 0,
31 'TYPE' => 'DATA',
32 'IS_SURROUNDING' => 0,
34 ]);
36 my $ne = ParseElement($e, undef);
37 is($ne->{ORIGINAL}, $e);
38 is($ne->{NAME}, "v");
39 is($ne->{ALIGN}, 1);
40 is($ne->{TYPE}, "uint8");
41 is_deeply($ne->{LEVELS}, [
43 'IS_DEFERRED' => 0,
44 'LEVEL_INDEX' => 0,
45 'DATA_TYPE' => 'uint8',
46 'CONTAINS_DEFERRED' => 0,
47 'TYPE' => 'DATA',
48 'IS_SURROUNDING' => 0,
50 ]);
52 # Case 2 : pointers
54 $e = {
55 'FILE' => 'foo.idl',
56 'NAME' => 'v',
57 'PROPERTIES' => {"unique" => 1},
58 'POINTERS' => 1,
59 'PARENT' => { TYPE => 'STRUCT' },
60 'TYPE' => 'uint8',
61 'LINE' => 42 };
63 is_deeply(GetElementLevelTable($e), [
65 LEVEL_INDEX => 0,
66 IS_DEFERRED => 0,
67 TYPE => 'POINTER',
68 POINTER_TYPE => "unique",
69 POINTER_INDEX => 0,
70 LEVEL => 'EMBEDDED'
73 'IS_DEFERRED' => 1,
74 'LEVEL_INDEX' => 1,
75 'DATA_TYPE' => 'uint8',
76 'CONTAINS_DEFERRED' => 0,
77 'TYPE' => 'DATA',
78 'IS_SURROUNDING' => 0,
80 ]);
82 # Case 3 : double pointers
84 $e = {
85 'FILE' => 'foo.idl',
86 'NAME' => 'v',
87 'PROPERTIES' => {"unique" => 1},
88 'POINTERS' => 2,
89 'TYPE' => 'uint8',
90 'PARENT' => { TYPE => 'STRUCT' },
91 'LINE' => 42 };
93 is_deeply(GetElementLevelTable($e), [
95 LEVEL_INDEX => 0,
96 IS_DEFERRED => 0,
97 TYPE => 'POINTER',
98 POINTER_TYPE => "unique",
99 POINTER_INDEX => 0,
100 LEVEL => 'EMBEDDED'
103 LEVEL_INDEX => 1,
104 IS_DEFERRED => 1,
105 TYPE => 'POINTER',
106 POINTER_TYPE => "unique",
107 POINTER_INDEX => 1,
108 LEVEL => 'EMBEDDED'
111 'IS_DEFERRED' => 1,
112 'LEVEL_INDEX' => 2,
113 'DATA_TYPE' => 'uint8',
114 'CONTAINS_DEFERRED' => 0,
115 'TYPE' => 'DATA',
116 'IS_SURROUNDING' => 0,
120 # Case 3 : ref pointers
122 $e = {
123 'FILE' => 'foo.idl',
124 'NAME' => 'v',
125 'PROPERTIES' => {"ref" => 1},
126 'POINTERS' => 1,
127 'TYPE' => 'uint8',
128 'PARENT' => { TYPE => 'STRUCT' },
129 'LINE' => 42 };
131 is_deeply(GetElementLevelTable($e), [
133 LEVEL_INDEX => 0,
134 IS_DEFERRED => 0,
135 TYPE => 'POINTER',
136 POINTER_TYPE => "ref",
137 POINTER_INDEX => 0,
138 LEVEL => 'EMBEDDED'
141 'IS_DEFERRED' => 1,
142 'LEVEL_INDEX' => 1,
143 'DATA_TYPE' => 'uint8',
144 'CONTAINS_DEFERRED' => 0,
145 'TYPE' => 'DATA',
146 'IS_SURROUNDING' => 0,
151 # Case 4 : top-level ref pointers
153 $e = {
154 'FILE' => 'foo.idl',
155 'NAME' => 'v',
156 'PROPERTIES' => {"ref" => 1},
157 'POINTERS' => 1,
158 'TYPE' => 'uint8',
159 'PARENT' => { TYPE => 'FUNCTION' },
160 'LINE' => 42 };
162 is_deeply(GetElementLevelTable($e), [
164 LEVEL_INDEX => 0,
165 IS_DEFERRED => 0,
166 TYPE => 'POINTER',
167 POINTER_TYPE => "ref",
168 POINTER_INDEX => 0,
169 LEVEL => 'TOP'
172 'IS_DEFERRED' => 0,
173 'LEVEL_INDEX' => 1,
174 'DATA_TYPE' => 'uint8',
175 'CONTAINS_DEFERRED' => 0,
176 'TYPE' => 'DATA',
177 'IS_SURROUNDING' => 0,
181 # representation_type
182 $e = {
183 'FILE' => 'foo.idl',
184 'NAME' => 'v',
185 'PROPERTIES' => { represent_as => "bar" },
186 'POINTERS' => 0,
187 'TYPE' => 'uint8',
188 'PARENT' => { TYPE => 'STRUCT' },
189 'LINE' => 42 };
191 $ne = ParseElement($e, undef);
192 is($ne->{REPRESENTATION_TYPE}, "bar");
194 # representation_type
195 $e = {
196 'FILE' => 'foo.idl',
197 'NAME' => 'v',
198 'PROPERTIES' => { },
199 'POINTERS' => 0,
200 'TYPE' => 'uint8',
201 'PARENT' => { TYPE => 'STRUCT' },
202 'LINE' => 42 };
204 $ne = ParseElement($e, undef);
205 is($ne->{REPRESENTATION_TYPE}, "uint8");
207 is(align_type("hyper"), 8);
208 is(align_type("uint32"), 4);
209 is(align_type("uint16"), 2);
210 is(align_type("uint8"), 1);
211 is(align_type({ TYPE => "STRUCT", "NAME" => "bla",
212 ELEMENTS => [ { TYPE => "uint16" } ] }), 4);
213 is(align_type({ TYPE => "STRUCT",
214 ELEMENTS => [ { TYPE => "hyper" } ] }), 8);
215 is(align_type({ TYPE => "DECLARE", DATA => {
216 TYPE => "STRUCT",
217 ELEMENTS => [ { TYPE => "hyper" } ] }}), 8);
218 is(align_type({ TYPE => "STRUCT", "NAME" => "bla",
219 ELEMENTS => [ { TYPE => "uint8" } ] }), 4);
221 is(mapToScalar("someverymuchnotexistingtype"), undef);
222 is(mapToScalar("uint32"), "uint32");
223 is(mapToScalar({TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }), "uint8");
224 is(mapToScalar({TYPE => "BITMAP", PROPERTIES => { bitmap64bit => 1 } }),
225 "hyper");
226 is(mapToScalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }}), "uint8");
228 is_deeply(ParseType({TYPE => "STRUCT", NAME => "foo" }, "ref"),
229 {TYPE => "STRUCT", NAME => "foo" });