summaryrefslogtreecommitdiff
path: root/source4/pidl/tests/util.pl
blob: 4287d78980d59a14a910672203b283fdf28b10c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
# (C) 2007 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU General Public License
use strict;

use Test::More tests => 41;
use FindBin qw($RealBin);
use lib "$RealBin/../lib";
use Parse::Pidl::Util;

# has_property()
is(undef, has_property({}, "foo"));
is(undef, has_property({PROPERTIES => {}}, "foo"));
is("data", has_property({PROPERTIES => {foo => "data"}}, "foo"));
is(undef, has_property({PROPERTIES => {foo => undef}}, "foo"));

# is_constant()
ok(is_constant("2"));
ok(is_constant("256"));
ok(is_constant("0x400"));
ok(is_constant("0x4BC"));
ok(not is_constant("0x4BGC"));
ok(not is_constant("str"));
ok(not is_constant("2 * expr"));

# make_str()
is("\"bla\"", make_str("bla"));
is("\"bla\"", make_str("\"bla\""));
is("\"\"bla\"\"", make_str("\"\"bla\"\""));
is("\"bla\"\"", make_str("bla\""));
is("\"foo\"bar\"", make_str("foo\"bar"));

# print_uuid()
is(undef, print_uuid("invalid"));
is("{0x12345778,0x1234,0xabcd,{0xef,0x00},{0x01,0x23,0x45,0x67,0x89,0xac}}", 
   print_uuid("12345778-1234-abcd-ef00-0123456789ac"));
is("{0x12345778,0x1234,0xabcd,{0xef,0x00},{0x01,0x23,0x45,0x67,0x89,0xac}}", 
   print_uuid("\"12345778-1234-abcd-ef00-0123456789ac\""));

# property_matches()
# missing property
ok(not property_matches({PROPERTIES => {}}, "x", "data"));
# data not matching
ok(not property_matches({PROPERTIES => {x => "bar"}}, "x", "data"));
# data matching exactly
ok(property_matches({PROPERTIES => {x => "data"}}, "x", "data"));
# regex matching
ok(property_matches({PROPERTIES => {x => "data"}}, "x", "^([dat]+)\$"));

# ParseExpr()
is("", ParseExpr("", {}));
is("a", ParseExpr("a", {"b" => "2"}));
is("2", ParseExpr("a", {"a" => "2"}));
is("2*2", ParseExpr("a*a", {"a" => "2"}));
is("r->length+r->length", 
   ParseExpr("length+length", {"length" => "r->length"}));
is("2/2*(r->length)", 
	ParseExpr("constant/constant*(len)", {"constant" => "2", 
			                              "len" => "r->length"}));
is("2+2-r->length", 
	ParseExpr("constant+constant-len", {"constant" => "2", 
			                              "len" => "r->length"}));
is("*r->length", ParseExpr("*len", { "len" => "r->length"}));
is("**r->length", ParseExpr("**len", { "len" => "r->length"}));
is("r->length&2", ParseExpr("len&2", { "len" => "r->length"}));
is("&r->length", ParseExpr("&len", { "len" => "r->length"}));
is("strlen(\"data\")", ParseExpr("strlen(foo)", { "foo" => "\"data\""}));
is("strlen(\"data\", 4)", ParseExpr("strlen(foo, 4)", { "foo" => "\"data\""}));
is("foo / bar", ParseExpr("foo / bar", { "bla" => "\"data\""}));
is("r->length%2", ParseExpr("len%2", { "len" => "r->length"}));
is("r->length==2", ParseExpr("len==2", { "len" => "r->length"}));
is("r->length!=2", ParseExpr("len!=2", { "len" => "r->length"}));
is("pr->length", ParseExpr("pr->length", { "p" => "r"}));
TODO: {
	todo_skip 1, "Broken at the moment";
	is("r->length", ParseExpr("p->length", { "p" => "r"}));
}