~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to pidl/tests/typelist.pl

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;
 
6
 
 
7
use Test::More tests => 54;
 
8
use FindBin qw($RealBin);
 
9
use lib "$RealBin";
 
10
use Util;
 
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);
 
14
 
 
15
is("foo", expandAlias("foo"));
 
16
is("uint32", expandAlias("DWORD"));
 
17
is("int32", expandAlias("int"));
 
18
is("", expandAlias(""));
 
19
is("int32", expandAlias("int32"));
 
20
 
 
21
is("uint32_t", mapScalarType("uint32"));
 
22
is("void", mapScalarType("void"));
 
23
is("uint64_t", mapScalarType("hyper"));
 
24
 
 
25
my $x = { TYPE => "ENUM", NAME => "foo", EXTRADATA => 1 };
 
26
addType($x);
 
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"), {
 
32
                NAME => "uint16",
 
33
                BASEFILE => "<builtin>",
 
34
                TYPE => "TYPEDEF",
 
35
                DATA => { NAME => "uint16", TYPE => "SCALAR" }});
 
36
 
 
37
is(0, typeIs("someUnknownType", "ENUM"));
 
38
is(0, typeIs("foo", "ENUM"));
 
39
addType({NAME => "mytypedef", TYPE => "TYPEDEF", DATA => { TYPE => "ENUM" }});
 
40
is(1, typeIs("mytypedef", "ENUM"));
 
41
is(0, typeIs("mytypedef", "BITMAP"));
 
42
is(1, typeIs({ TYPE => "ENUM"}, "ENUM"));
 
43
is(0, typeIs({ TYPE => "BITMAP"}, "ENUM"));
 
44
is(1, typeIs("uint32", "SCALAR"));
 
45
is(0, typeIs("uint32", "ENUM"));
 
46
 
 
47
is(1, hasType("foo"));
 
48
is(0, hasType("nonexistant"));
 
49
is(0, hasType({TYPE => "ENUM", NAME => "someUnknownType"}));
 
50
is(1, hasType({TYPE => "ENUM", NAME => "foo"}));
 
51
is(1, hasType({TYPE => "ENUM"}));
 
52
is(1, hasType({TYPE => "STRUCT"}));
 
53
 
 
54
is(1, is_scalar("uint32"));
 
55
is(0, is_scalar("nonexistant"));
 
56
is(1, is_scalar({TYPE => "ENUM"}));
 
57
is(0, is_scalar({TYPE => "STRUCT"}));
 
58
is(1, is_scalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM" }}));
 
59
is(1, is_scalar("mytypedef"));
 
60
 
 
61
is(1, scalar_is_reference("string"));
 
62
is(0, scalar_is_reference("uint32"));
 
63
is(0, scalar_is_reference({TYPE => "STRUCT", NAME => "echo_foobar"}));
 
64
 
 
65
is("uint8", enum_type_fn({TYPE => "ENUM", PARENT=>{PROPERTIES => {enum8bit => 1}}}));
 
66
is("uint32", enum_type_fn({TYPE => "ENUM", PARENT=>{PROPERTIES => {v1_enum => 1}}}));
 
67
is("uint16", enum_type_fn({TYPE => "ENUM", PARENT=>{PROPERTIES => {}}}));
 
68
 
 
69
is("uint8", bitmap_type_fn({TYPE => "BITMAP", PROPERTIES => {bitmap8bit => 1}}));
 
70
is("uint16", bitmap_type_fn({TYPE => "BITMAP", PROPERTIES => {bitmap16bit => 1}}));
 
71
is("hyper", bitmap_type_fn({TYPE => "BITMAP", PROPERTIES => {bitmap64bit => 1}}));
 
72
is("uint32", bitmap_type_fn({TYPE => "BITMAP", PROPERTIES => {}}));
 
73
 
 
74
is("enum foo", mapType({TYPE => "ENUM"}, "foo"));
 
75
is("union foo", mapType({TYPE => "UNION"}, "foo"));
 
76
is("struct foo", mapType({TYPE => "STRUCT"}, "foo"));
 
77
is("uint8_t", mapType({TYPE => "BITMAP", PROPERTIES => {bitmap8bit => 1}}, "foo"));
 
78
is("uint8_t", mapType({TYPE => "SCALAR"}, "uint8"));
 
79
is("uint32_t", mapType({TYPE => "TYPEDEF", DATA => {TYPE => "SCALAR"}}, "uint32"));
 
80
 
 
81
is("void", mapTypeName(undef));
 
82
is("uint32_t", mapTypeName("uint32"));
 
83
is("int32_t", mapTypeName("int"));
 
84
 
 
85
ok(not typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT" }}));
 
86
ok(typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT", ELEMENTS => [] }}));