2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
7 use Test
::More tests
=> 47;
8 use FindBin
qw($RealBin);
11 use Parse::Pidl::Util qw(MyDumper);
12 use Parse
::Pidl
::NDR
qw(GetElementLevelTable ParseElement align_type mapToScalar ParseType can_contain_deferred);
22 'PARENT' => { TYPE
=> 'STRUCT' },
25 is_deeply
(GetElementLevelTable
($e, "unique"), [
29 'DATA_TYPE' => 'uint8',
30 'CONTAINS_DEFERRED' => 0,
32 'IS_SURROUNDING' => 0,
36 my $ne = ParseElement
($e, "unique");
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, "unique"), [
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, "unique"), [
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, "unique"), [
136 POINTER_TYPE
=> "ref",
143 'DATA_TYPE' => 'uint8',
144 'CONTAINS_DEFERRED' => 0,
146 'IS_SURROUNDING' => 0,
150 # Case 3 : ref pointers
155 'PROPERTIES' => {"ref" => 1},
158 'PARENT' => { TYPE
=> 'STRUCT' },
161 is_deeply
(GetElementLevelTable
($e, "unique"), [
166 POINTER_TYPE
=> "ref",
174 POINTER_TYPE
=> "unique",
182 POINTER_TYPE
=> "unique",
189 'DATA_TYPE' => 'uint8',
190 'CONTAINS_DEFERRED' => 0,
192 'IS_SURROUNDING' => 0,
196 # Case 3 : ref pointers
201 'PROPERTIES' => {"ref" => 1},
204 'PARENT' => { TYPE
=> 'STRUCT' },
207 is_deeply
(GetElementLevelTable
($e, "ref"), [
212 POINTER_TYPE
=> "ref",
220 POINTER_TYPE
=> "ref",
228 POINTER_TYPE
=> "ref",
235 'DATA_TYPE' => 'uint8',
236 'CONTAINS_DEFERRED' => 0,
238 'IS_SURROUNDING' => 0,
242 # Case 4 : top-level ref pointers
247 'PROPERTIES' => {"ref" => 1},
250 'PARENT' => { TYPE
=> 'FUNCTION' },
253 is_deeply
(GetElementLevelTable
($e, "unique"), [
258 POINTER_TYPE
=> "ref",
265 'DATA_TYPE' => 'uint8',
266 'CONTAINS_DEFERRED' => 0,
268 'IS_SURROUNDING' => 0,
272 # Case 4 : top-level ref pointers, triple with pointer_default("unique")
277 'PROPERTIES' => {"ref" => 1},
280 'PARENT' => { TYPE
=> 'FUNCTION' },
283 is_deeply
(GetElementLevelTable
($e, "unique"), [
288 POINTER_TYPE
=> "ref",
296 POINTER_TYPE
=> "unique",
304 POINTER_TYPE
=> "unique",
311 'DATA_TYPE' => 'uint8',
312 'CONTAINS_DEFERRED' => 0,
314 'IS_SURROUNDING' => 0,
318 # Case 4 : top-level unique pointers, triple with pointer_default("unique")
323 'PROPERTIES' => {"unique" => 1, "in" => 1},
326 'PARENT' => { TYPE
=> 'FUNCTION' },
329 is_deeply
(GetElementLevelTable
($e, "unique"), [
334 POINTER_TYPE
=> "unique",
342 POINTER_TYPE
=> "unique",
350 POINTER_TYPE
=> "unique",
357 'DATA_TYPE' => 'uint8',
358 'CONTAINS_DEFERRED' => 0,
360 'IS_SURROUNDING' => 0,
364 # Case 4 : top-level unique pointers, triple with pointer_default("ref")
369 'PROPERTIES' => {"unique" => 1, "in" => 1},
372 'PARENT' => { TYPE
=> 'FUNCTION' },
375 is_deeply
(GetElementLevelTable
($e, "ref"), [
380 POINTER_TYPE
=> "unique",
388 POINTER_TYPE
=> "ref",
396 POINTER_TYPE
=> "ref",
403 'DATA_TYPE' => 'uint8',
404 'CONTAINS_DEFERRED' => 0,
406 'IS_SURROUNDING' => 0,
410 # Case 4 : top-level ref pointers, triple with pointer_default("ref")
415 'PROPERTIES' => {"ref" => 1},
418 'PARENT' => { TYPE
=> 'FUNCTION' },
421 is_deeply
(GetElementLevelTable
($e, "ref"), [
426 POINTER_TYPE
=> "ref",
434 POINTER_TYPE
=> "ref",
442 POINTER_TYPE
=> "ref",
449 'DATA_TYPE' => 'uint8',
450 'CONTAINS_DEFERRED' => 0,
452 'IS_SURROUNDING' => 0,
456 # representation_type
460 'PROPERTIES' => { represent_as
=> "bar" },
463 'PARENT' => { TYPE
=> 'STRUCT' },
466 $ne = ParseElement
($e, undef);
467 is
($ne->{REPRESENTATION_TYPE
}, "bar");
469 # representation_type
476 'PARENT' => { TYPE
=> 'STRUCT' },
479 $ne = ParseElement
($e, undef);
480 is
($ne->{REPRESENTATION_TYPE
}, "uint8");
482 is
(align_type
("hyper"), 8);
483 is
(align_type
("double"), 8);
484 is
(align_type
("uint32"), 4);
485 is
(align_type
("uint16"), 2);
486 is
(align_type
("uint8"), 1);
487 is
(align_type
({ TYPE
=> "STRUCT", "NAME" => "bla",
488 ELEMENTS
=> [ { TYPE
=> "uint16" } ] }), 4);
489 is
(align_type
({ TYPE
=> "STRUCT",
490 ELEMENTS
=> [ { TYPE
=> "hyper" } ] }), 8);
491 is
(align_type
({ TYPE
=> "TYPEDEF", DATA
=> {
493 ELEMENTS
=> [ { TYPE
=> "hyper" } ] }}), 8);
494 # typedef of struct without body
495 is
(align_type
({ TYPE
=> "TYPEDEF", DATA
=> {
496 TYPE
=> "STRUCT", ELEMENTS
=> undef }}), 4);
497 # struct without body
498 is
(align_type
({ TYPE
=> "STRUCT", ELEMENTS
=> undef }), 4);
500 is
(align_type
({ TYPE
=> "STRUCT", ELEMENTS
=> [] }), 1);
501 is
(align_type
({ TYPE
=> "STRUCT", "NAME" => "bla",
502 ELEMENTS
=> [ { TYPE
=> "uint8" } ] }), 4);
504 is
(mapToScalar
("someverymuchnotexistingtype"), undef);
505 is
(mapToScalar
("uint32"), "uint32");
506 is
(mapToScalar
({TYPE
=> "ENUM", PARENT
=> { PROPERTIES
=> { enum8bit
=> 1 } } }), "uint8");
507 is
(mapToScalar
({TYPE
=> "BITMAP", PROPERTIES
=> { bitmap64bit
=> 1 } }),
509 is
(mapToScalar
({TYPE
=> "TYPEDEF", DATA
=> {TYPE
=> "ENUM", PARENT
=> { PROPERTIES
=> { enum8bit
=> 1 } } }}), "uint8");
515 SURROUNDING_ELEMENT
=> undef,
524 is_deeply
(ParseType
($t->{ORIGINAL
}, "ref"), $t);
529 SWITCH_TYPE
=> "uint32",
538 is_deeply
(ParseType
($t->{ORIGINAL
}, "ref"), $t);
540 ok
(not can_contain_deferred
("uint32"));
541 ok
(can_contain_deferred
("some_unknown_type"));
542 ok
(can_contain_deferred
({ TYPE
=> "STRUCT",
543 ELEMENTS
=> [ { TYPE
=> "uint32", POINTERS
=> 40 } ]}));
544 ok
(can_contain_deferred
({ TYPE
=> "TYPEDEF",
545 DATA
=> { TYPE
=> "STRUCT",
546 ELEMENTS
=> [ { TYPE
=> "uint32", POINTERS
=> 40 } ]}}));
547 ok
(not can_contain_deferred
({ TYPE
=> "STRUCT",
548 ELEMENTS
=> [ { TYPE
=> "uint32" } ]}));
549 ok
(not can_contain_deferred
({ TYPE
=> "TYPEDEF",
550 DATA
=> { TYPE
=> "STRUCT",
551 ELEMENTS
=> [ { TYPE
=> "uint32" } ]}}));
552 ok
(can_contain_deferred
({ TYPE
=> "STRUCT",
553 ELEMENTS
=> [ { TYPE
=> "someunknowntype" } ]}));
554 # Make sure the elements for a enum without body aren't filled in
555 ok
(not defined(ParseType
({TYPE
=> "ENUM", NAME
=> "foo" }, "ref")->{ELEMENTS
}));
556 # Make sure the elements for a bitmap without body aren't filled in
557 ok
(not defined(ParseType
({TYPE
=> "BITMAP", NAME
=> "foo" }, "ref")->{ELEMENTS
}));
558 # Make sure the elements for a union without body aren't filled in
559 ok
(not defined(ParseType
({TYPE
=> "UNION", NAME
=> "foo" }, "ref")->{ELEMENTS
}));