Author: jelmer Date: 2007-01-05 12:56:15 +0000 (Fri, 05 Jan 2007) New Revision: 20543
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20543 Log: 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. Added: branches/SAMBA_4_0/source/pidl/tests/util.pl Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Util.pm Changeset: Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Util.pm =================================================================== --- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Util.pm 2007-01-05 11:31:28 UTC (rev 20542) +++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Util.pm 2007-01-05 12:56:15 UTC (rev 20543) @@ -26,12 +26,9 @@ # see if a pidl property list contains a given property sub has_property($$) { - my($e) = shift; - my($p) = shift; + my($e, $p) = @_; - if (!defined $e->{PROPERTIES}) { - return undef; - } + return undef if (not defined($e->{PROPERTIES})); return $e->{PROPERTIES}->{$p}; } @@ -40,9 +37,7 @@ # see if a pidl property matches a value sub property_matches($$$) { - my($e) = shift; - my($p) = shift; - my($v) = shift; + my($e,$p,$v) = @_; if (!defined has_property($e, $p)) { return undef; @@ -59,7 +54,7 @@ sub is_constant($) { my $s = shift; - if (defined $s && $s =~ /^\d/) { + if (defined $s && $s =~ /^\d$/) { return 1; } return 0; @@ -72,7 +67,7 @@ if (substr($str, 0, 1) eq "\"") { return $str; } - return "\"" . $str . "\""; + return "\"$str\""; } sub print_uuid($) @@ -80,6 +75,7 @@ my ($uuid) = @_; $uuid =~ s/"//g; my ($time_low,$time_mid,$time_hi,$clock_seq,$node) = split /-/, $uuid; + return undef if not defined($node); my @clock_seq = $clock_seq =~ /(..)/g; my @node = $node =~ /(..)/g; @@ -106,7 +102,7 @@ die("Undefined value in ParseExpr") if not defined($expr); - my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr; + my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+)?)/, $expr; my $ret = ""; foreach my $t (@tokens) { Added: branches/SAMBA_4_0/source/pidl/tests/util.pl =================================================================== --- branches/SAMBA_4_0/source/pidl/tests/util.pl 2007-01-05 11:31:28 UTC (rev 20542) +++ branches/SAMBA_4_0/source/pidl/tests/util.pl 2007-01-05 12:56:15 UTC (rev 20543) @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# (C) 2007 Jelmer Vernooij <[EMAIL PROTECTED]> +# 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"})); Property changes on: branches/SAMBA_4_0/source/pidl/tests/util.pl ___________________________________________________________________ Name: svn:executable + *