2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
7 use Test
::More tests
=> 58;
8 use FindBin
qw($RealBin);
11 use Parse::Pidl::Typelist qw(hasType typeHasBody getType mapTypeName expandAlias
12 mapScalarType addType typeIs is_scalar scalar_is_reference
13 enum_type_fn bitmap_type_fn mapType);
15 is
("foo", expandAlias
("foo"));
16 is
("uint32", expandAlias
("DWORD"));
17 is
("int32", expandAlias
("int"));
18 is
("", expandAlias
(""));
19 is
("int32", expandAlias
("int32"));
21 is
("uint32_t", mapScalarType
("uint32"));
22 is
("void", mapScalarType
("void"));
23 is
("uint64_t", mapScalarType
("hyper"));
24 is
("int64_t", mapScalarType
("int64"));
25 is
("double", mapScalarType
("double"));
27 my $x = { TYPE
=> "ENUM", NAME
=> "foo", EXTRADATA
=> 1 };
29 is_deeply
($x, getType
("foo"));
30 is
(undef, getType
("bloebla"));
31 is_deeply
(getType
({ TYPE
=> "STRUCT" }), { TYPE
=> "STRUCT" });
32 is_deeply
(getType
({ TYPE
=> "ENUM", NAME
=> "foo" }), $x);
33 is_deeply
(getType
("uint16"), {
35 BASEFILE
=> "<builtin>",
37 DATA
=> { NAME
=> "uint16", TYPE
=> "SCALAR" }});
39 is_deeply
(getType
("double"), {
41 BASEFILE
=> "<builtin>",
43 DATA
=> { NAME
=> "double", TYPE
=> "SCALAR" }});
45 is
(0, typeIs
("someUnknownType", "ENUM"));
46 is
(0, typeIs
("foo", "ENUM"));
47 addType
({NAME
=> "mytypedef", TYPE
=> "TYPEDEF", DATA
=> { TYPE
=> "ENUM" }});
48 is
(1, typeIs
("mytypedef", "ENUM"));
49 is
(0, typeIs
("mytypedef", "BITMAP"));
50 is
(1, typeIs
({ TYPE
=> "ENUM"}, "ENUM"));
51 is
(0, typeIs
({ TYPE
=> "BITMAP"}, "ENUM"));
52 is
(1, typeIs
("uint32", "SCALAR"));
53 is
(0, typeIs
("uint32", "ENUM"));
55 is
(1, hasType
("foo"));
56 is
(0, hasType
("nonexistent"));
57 is
(0, hasType
({TYPE
=> "ENUM", NAME
=> "someUnknownType"}));
58 is
(1, hasType
({TYPE
=> "ENUM", NAME
=> "foo"}));
59 is
(1, hasType
({TYPE
=> "ENUM"}));
60 is
(1, hasType
({TYPE
=> "STRUCT"}));
62 is
(1, is_scalar
("uint32"));
63 is
(0, is_scalar
("nonexistent"));
64 is
(1, is_scalar
({TYPE
=> "ENUM"}));
65 is
(0, is_scalar
({TYPE
=> "STRUCT"}));
66 is
(1, is_scalar
({TYPE
=> "TYPEDEF", DATA
=> {TYPE
=> "ENUM" }}));
67 is
(1, is_scalar
("mytypedef"));
69 is
(1, scalar_is_reference
("string"));
70 is
(1, scalar_is_reference
("u16string"));
71 is
(0, scalar_is_reference
("uint32"));
72 is
(0, scalar_is_reference
({TYPE
=> "STRUCT", NAME
=> "echo_foobar"}));
74 is
("uint8", enum_type_fn
({TYPE
=> "ENUM", PARENT
=>{PROPERTIES
=> {enum8bit
=> 1}}}));
75 is
("uint32", enum_type_fn
({TYPE
=> "ENUM", PARENT
=>{PROPERTIES
=> {v1_enum
=> 1}}}));
76 is
("uint1632", enum_type_fn
({TYPE
=> "ENUM", PARENT
=>{PROPERTIES
=> {}}}));
78 is
("uint8", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap8bit
=> 1}}));
79 is
("uint16", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap16bit
=> 1}}));
80 is
("hyper", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap64bit
=> 1}}));
81 is
("uint32", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {}}));
83 is
("enum foo", mapType
({TYPE
=> "ENUM"}, "foo"));
84 is
("union foo", mapType
({TYPE
=> "UNION"}, "foo"));
85 is
("struct foo", mapType
({TYPE
=> "STRUCT"}, "foo"));
86 is
("uint8_t", mapType
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap8bit
=> 1}}, "foo"));
87 is
("uint8_t", mapType
({TYPE
=> "SCALAR"}, "uint8"));
88 is
("uint32_t", mapType
({TYPE
=> "TYPEDEF", DATA
=> {TYPE
=> "SCALAR"}}, "uint32"));
90 is
("void", mapTypeName
(undef));
91 is
("uint32_t", mapTypeName
("uint32"));
92 is
("int32_t", mapTypeName
("int"));
94 ok
(not typeHasBody
({TYPE
=> "TYPEDEF", DATA
=> { TYPE
=> "STRUCT" }}));
95 ok
(typeHasBody
({TYPE
=> "TYPEDEF", DATA
=> { TYPE
=> "STRUCT", ELEMENTS
=> [] }}));