summaryrefslogtreecommitdiff
path: root/source4/pidl/tests/util.pl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-01-05 12:56:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:36:51 -0500
commit362d4b14aecb32aac5c7c4f6beb3b9a979bf9d5a (patch)
tree4c0b015dd964ef671acb9c29b5832a497e38e452 /source4/pidl/tests/util.pl
parent34040b420a77ac144db99606369d4ed636cdf750 (diff)
downloadsamba-362d4b14aecb32aac5c7c4f6beb3b9a979bf9d5a.tar.gz
samba-362d4b14aecb32aac5c7c4f6beb3b9a979bf9d5a.tar.bz2
samba-362d4b14aecb32aac5c7c4f6beb3b9a979bf9d5a.zip
r20543: Merge some pidl bug fixes:
* C expressions that just started with a constant were erroneously flagged as being a constant. * 1-length variable names in expressions were broken. (This used to be commit 44775a6ac456247fe7ab4da75498bb550c74c854)
Diffstat (limited to 'source4/pidl/tests/util.pl')
-rwxr-xr-xsource4/pidl/tests/util.pl55
1 files changed, 55 insertions, 0 deletions
diff --git a/source4/pidl/tests/util.pl b/source4/pidl/tests/util.pl
new file mode 100755
index 0000000000..7c51b72196
--- /dev/null
+++ b/source4/pidl/tests/util.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+# (C) 2007 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU General Public License
+use strict;
+
+use Test::More tests => 25;
+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(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"}));