2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
7 use Test
::More tests
=> 26;
8 use FindBin
qw($RealBin);
11 use Parse::Pidl::Util qw(MyDumper);
12 use Parse
::Pidl
::NDR
qw(GetElementLevelTable ParseElement align_type mapToScalar ParseType);
22 'PARENT' => { TYPE
=> 'STRUCT' },
25 is_deeply
(GetElementLevelTable
($e), [
29 'DATA_TYPE' => 'uint8',
30 'CONTAINS_DEFERRED' => 0,
32 'IS_SURROUNDING' => 0,
36 my $ne = ParseElement
($e, undef);
37 is
($ne->{ORIGINAL
}, $e);
40 is
($ne->{TYPE
}, "uint8");
41 is_deeply
($ne->{LEVELS
}, [
45 'DATA_TYPE' => 'uint8',
46 'CONTAINS_DEFERRED' => 0,
48 'IS_SURROUNDING' => 0,
57 'PROPERTIES' => {"unique" => 1},
59 'PARENT' => { TYPE
=> 'STRUCT' },
63 is_deeply
(GetElementLevelTable
($e), [
68 POINTER_TYPE
=> "unique",
75 'DATA_TYPE' => 'uint8',
76 'CONTAINS_DEFERRED' => 0,
78 'IS_SURROUNDING' => 0,
82 # Case 3 : double pointers
87 'PROPERTIES' => {"unique" => 1},
90 'PARENT' => { TYPE
=> 'STRUCT' },
93 is_deeply
(GetElementLevelTable
($e), [
98 POINTER_TYPE
=> "unique",
106 POINTER_TYPE
=> "unique",
113 'DATA_TYPE' => 'uint8',
114 'CONTAINS_DEFERRED' => 0,
116 'IS_SURROUNDING' => 0,
120 # Case 3 : ref pointers
125 'PROPERTIES' => {"ref" => 1},
128 'PARENT' => { TYPE
=> 'STRUCT' },
131 is_deeply
(GetElementLevelTable
($e), [
136 POINTER_TYPE
=> "ref",
143 'DATA_TYPE' => 'uint8',
144 'CONTAINS_DEFERRED' => 0,
146 'IS_SURROUNDING' => 0,
151 # Case 4 : top-level ref pointers
156 'PROPERTIES' => {"ref" => 1},
159 'PARENT' => { TYPE
=> 'FUNCTION' },
162 is_deeply
(GetElementLevelTable
($e), [
167 POINTER_TYPE
=> "ref",
174 'DATA_TYPE' => 'uint8',
175 'CONTAINS_DEFERRED' => 0,
177 'IS_SURROUNDING' => 0,
181 # representation_type
185 'PROPERTIES' => { represent_as
=> "bar" },
188 'PARENT' => { TYPE
=> 'STRUCT' },
191 $ne = ParseElement
($e, undef);
192 is
($ne->{REPRESENTATION_TYPE
}, "bar");
194 # representation_type
201 'PARENT' => { TYPE
=> 'STRUCT' },
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
=> {
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 } }),
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" });