2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
7 use Test
::More tests
=> 52;
8 use FindBin
qw($RealBin);
11 use Parse::Pidl::Typelist qw(hasType 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"));
25 my $x = { TYPE
=> "ENUM", NAME
=> "foo", EXTRADATA
=> 1 };
27 is_deeply
($x, getType
("foo"));
28 is
(undef, getType
("bloebla"));
29 is_deeply
(getType
({ TYPE
=> "STRUCT" }), { TYPE
=> "STRUCT" });
30 is_deeply
(getType
({ TYPE
=> "ENUM", NAME
=> "foo" }), $x);
31 is_deeply
(getType
("uint16"), {
34 DATA
=> { NAME
=> "uint16", TYPE
=> "SCALAR" }});
36 is
(0, typeIs
("someUnknownType", "ENUM"));
37 is
(0, typeIs
("foo", "ENUM"));
38 addType
({NAME
=> "mytypedef", TYPE
=> "TYPEDEF", DATA
=> { TYPE
=> "ENUM" }});
39 is
(1, typeIs
("mytypedef", "ENUM"));
40 is
(0, typeIs
("mytypedef", "BITMAP"));
41 is
(1, typeIs
({ TYPE
=> "ENUM"}, "ENUM"));
42 is
(0, typeIs
({ TYPE
=> "BITMAP"}, "ENUM"));
43 is
(1, typeIs
("uint32", "SCALAR"));
44 is
(0, typeIs
("uint32", "ENUM"));
46 is
(1, hasType
("foo"));
47 is
(0, hasType
("nonexistant"));
48 is
(0, hasType
({TYPE
=> "ENUM", NAME
=> "someUnknownType"}));
49 is
(1, hasType
({TYPE
=> "ENUM", NAME
=> "foo"}));
50 is
(1, hasType
({TYPE
=> "ENUM"}));
51 is
(1, hasType
({TYPE
=> "STRUCT"}));
53 is
(1, is_scalar
("uint32"));
54 is
(0, is_scalar
("nonexistant"));
55 is
(1, is_scalar
({TYPE
=> "ENUM"}));
56 is
(0, is_scalar
({TYPE
=> "STRUCT"}));
57 is
(1, is_scalar
({TYPE
=> "TYPEDEF", DATA
=> {TYPE
=> "ENUM" }}));
58 is
(1, is_scalar
("mytypedef"));
59 is
(1, is_scalar
({TYPE
=> "DECLARE", DATA
=> {TYPE
=> "ENUM" }}));
61 is
(1, scalar_is_reference
("string"));
62 is
(0, scalar_is_reference
("uint32"));
64 is
("uint8", enum_type_fn
({TYPE
=> "ENUM", PARENT
=>{PROPERTIES
=> {enum8bit
=> 1}}}));
65 is
("uint32", enum_type_fn
({TYPE
=> "ENUM", PARENT
=>{PROPERTIES
=> {v1_enum
=> 1}}}));
66 is
("uint16", enum_type_fn
({TYPE
=> "ENUM", PARENT
=>{PROPERTIES
=> {}}}));
68 is
("uint8", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap8bit
=> 1}}));
69 is
("uint16", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap16bit
=> 1}}));
70 is
("hyper", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap64bit
=> 1}}));
71 is
("uint32", bitmap_type_fn
({TYPE
=> "BITMAP", PROPERTIES
=> {}}));
73 is
("enum foo", mapType
({TYPE
=> "ENUM"}, "foo"));
74 is
("union foo", mapType
({TYPE
=> "UNION"}, "foo"));
75 is
("struct foo", mapType
({TYPE
=> "STRUCT"}, "foo"));
76 is
("uint8_t", mapType
({TYPE
=> "BITMAP", PROPERTIES
=> {bitmap8bit
=> 1}}, "foo"));
77 is
("uint8_t", mapType
({TYPE
=> "SCALAR"}, "uint8"));
78 is
("uint32_t", mapType
({TYPE
=> "TYPEDEF", DATA
=> {TYPE
=> "SCALAR"}}, "uint32"));
80 is
("void", mapTypeName
(undef));
81 is
("uint32_t", mapTypeName
("uint32"));
82 is
("int32_t", mapTypeName
("int"));