Rev 11393: Add some more tests,
reduce number of locations where "absolute" variable in
file:///home/jelmer/bzr.samba/pidl-fixes/
Jelmer Vernooij
jelmer at samba.org
Thu Feb 8 14:17:53 GMT 2007
At file:///home/jelmer/bzr.samba/pidl-fixes/
------------------------------------------------------------
revno: 11393
revision-id: jelmer at samba.org-20070208141706-afd7md02c83t939w
parent: jelmer at samba.org-20070208112519-x9ru04sml0g8wq4x
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: pidl-fixes
timestamp: Thu 2007-02-08 15:17:06 +0100
message:
Add some more tests, reduce number of locations where "absolute" variable
names are used.
modified:
source/pidl/TODO svn-v2:9459 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2fTODO
source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm svn-v2:12463 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fSamba4%2fNDR%2fParser.pm
source/pidl/tests/samba-ndr.pl svn-v2:20637 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fsamba%2dndr.pl
=== modified file 'source/pidl/TODO'
--- a/source/pidl/TODO 2007-02-08 10:42:00 +0000
+++ b/source/pidl/TODO 2007-02-08 14:17:06 +0000
@@ -26,3 +26,5 @@
- add inout
- make NULL to mean "allocate me"
- remove NDR_AUTO_REF_ALLOC flag
+
+- automatic test generator based on IDL pointer types
=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm 2007-02-07 19:03:19 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm 2007-02-08 14:17:06 +0000
@@ -10,7 +10,7 @@
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(is_charset_array);
- at EXPORT_OK = qw(check_null_pointer);
+ at EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv);
use strict;
use Parse::Pidl::Typelist qw(hasType getType mapType);
@@ -451,7 +451,9 @@
if ($l->{IS_VARYING} and not $l->{IS_ZERO_TERMINATED}) {
defer "if ($var_name) {";
defer_indent;
- my $length = ParseExprExt($l->{LENGTH_IS}, $env, $e->{ORIGINAL}, check_null_pointer($e, $env, \&defer, "return NT_STATUS_INVALID_PARAMETER_MIX;"), check_fully_dereferenced($e, $env));
+ my $length = ParseExprExt($l->{LENGTH_IS}, $env, $e->{ORIGINAL},
+ check_null_pointer($e, $env, \&defer, "return NT_STATUS_INVALID_PARAMETER_MIX;"),
+ check_fully_dereferenced($e, $env));
defer "NDR_CHECK(ndr_check_array_length(ndr, (void*)" . get_pointer_to($var_name) . ", $length));";
defer_deindent;
defer "}"
@@ -689,12 +691,12 @@
#####################################################################
# parse scalars in a structure element
-sub ParseElementPush($$$$$$)
+sub ParseElementPush($$$$$)
{
- my ($e,$ndr,$var_prefix,$env,$primitives,$deferred) = @_;
+ my ($e,$ndr,$env,$primitives,$deferred) = @_;
my $subndr = undef;
- my $var_name = $var_prefix.$e->{NAME};
+ my $var_name = $env->{$e->{NAME}};
return unless $primitives or ($deferred and ContainsDeferred($e, $e->{LEVELS}[0]));
@@ -1096,11 +1098,11 @@
#####################################################################
# parse scalars in a structure element - pull size
-sub ParseElementPull($$$$$$)
+sub ParseElementPull($$$$$)
{
- my($e,$ndr,$var_prefix,$env,$primitives,$deferred) = @_;
+ my($e,$ndr,$env,$primitives,$deferred) = @_;
- my $var_name = $var_prefix.$e->{NAME};
+ my $var_name = $env->{$e->{NAME}};
my $represent_name;
my $transmit_name;
@@ -1247,7 +1249,7 @@
}
foreach my $e (@{$struct->{ELEMENTS}}) {
- ParseElementPush($e, "ndr", "r->", $env, 1, 0);
+ ParseElementPush($e, "ndr", $env, 1, 0);
}
deindent;
@@ -1261,7 +1263,7 @@
pidl "NDR_CHECK(ndr_push_setup_relative_base_offset2(ndr, r));";
}
foreach my $e (@{$struct->{ELEMENTS}}) {
- ParseElementPush($e, "ndr", "r->", $env, 0, 1);
+ ParseElementPush($e, "ndr", $env, 0, 1);
}
deindent;
@@ -1547,7 +1549,7 @@
}
foreach my $e (@{$struct->{ELEMENTS}}) {
- ParseElementPull($e, "ndr", "r->", $env, 1, 0);
+ ParseElementPull($e, "ndr", $env, 1, 0);
}
add_deferred();
@@ -1562,7 +1564,7 @@
pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset2(ndr, r));";
}
foreach my $e (@{$struct->{ELEMENTS}}) {
- ParseElementPull($e, "ndr", "r->", $env, 0, 1);
+ ParseElementPull($e, "ndr", $env, 0, 1);
}
add_deferred();
@@ -1662,7 +1664,7 @@
pidl "NDR_CHECK(ndr_push_setup_relative_base_offset1(ndr, r, ndr->offset));";
}
DeclareArrayVariables($el);
- ParseElementPush($el, "ndr", "r->", {}, 1, 0);
+ ParseElementPush($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 1, 0);
deindent;
}
pidl "break;";
@@ -1689,7 +1691,7 @@
pidl "$el->{CASE}:";
if ($el->{TYPE} ne "EMPTY") {
indent;
- ParseElementPush($el, "ndr", "r->", {}, 0, 1);
+ ParseElementPush($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 0, 1);
deindent;
}
pidl "break;";
@@ -1810,7 +1812,7 @@
# and store it based on the toplevel struct/union
pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset1(ndr, r, ndr->offset));";
}
- ParseElementPull($el, "ndr", "r->", {}, 1, 0);
+ ParseElementPull($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 1, 0);
deindent;
}
pidl "break; }";
@@ -1837,7 +1839,7 @@
pidl "$el->{CASE}:";
if ($el->{TYPE} ne "EMPTY") {
indent;
- ParseElementPull($el, "ndr", "r->", {}, 0, 1);
+ ParseElementPull($el, "ndr", {$el->{NAME} => "r->$el->{NAME}"}, 0, 1);
deindent;
}
pidl "break;";
@@ -1993,7 +1995,7 @@
foreach my $e (@{$fn->{ELEMENTS}}) {
if (grep(/in/,@{$e->{DIRECTION}})) {
- ParseElementPrint($e, "r->in.$e->{NAME}", $env);
+ ParseElementPrint($e, $env->{$e->{NAME}}, $env);
}
}
pidl "ndr->depth--;";
@@ -2008,7 +2010,7 @@
$env = GenerateFunctionOutEnv($fn);
foreach my $e (@{$fn->{ELEMENTS}}) {
if (grep(/out/,@{$e->{DIRECTION}})) {
- ParseElementPrint($e, "r->out.$e->{NAME}", $env);
+ ParseElementPrint($e, $env->{$e->{NAME}}, $env);
}
}
if ($fn->{RETURN_TYPE}) {
@@ -2050,7 +2052,7 @@
foreach my $e (@{$fn->{ELEMENTS}}) {
if (grep(/in/,@{$e->{DIRECTION}})) {
- ParseElementPush($e, "ndr", "r->in.", $env, 1, 1);
+ ParseElementPush($e, "ndr", $env, 1, 1);
}
}
@@ -2063,7 +2065,7 @@
$env = GenerateFunctionOutEnv($fn);
foreach my $e (@{$fn->{ELEMENTS}}) {
if (grep(/out/,@{$e->{DIRECTION}})) {
- ParseElementPush($e, "ndr", "r->out.", $env, 1, 1);
+ ParseElementPush($e, "ndr", $env, 1, 1);
}
}
@@ -2147,7 +2149,7 @@
foreach my $e (@{$fn->{ELEMENTS}}) {
next unless (grep(/in/, @{$e->{DIRECTION}}));
- ParseElementPull($e, "ndr", "r->in.", $env, 1, 1);
+ ParseElementPull($e, "ndr", $env, 1, 1);
}
# allocate the "simple" out ref variables. FIXME: Shouldn't this have it's
@@ -2194,7 +2196,7 @@
$env = GenerateFunctionOutEnv($fn);
foreach my $e (@{$fn->{ELEMENTS}}) {
next unless grep(/out/, @{$e->{DIRECTION}});
- ParseElementPull($e, "ndr", "r->out.", $env, 1, 1);
+ ParseElementPull($e, "ndr", $env, 1, 1);
}
if ($fn->{RETURN_TYPE}) {
=== modified file 'source/pidl/tests/samba-ndr.pl'
--- a/source/pidl/tests/samba-ndr.pl 2007-01-10 00:37:30 +0000
+++ b/source/pidl/tests/samba-ndr.pl 2007-02-08 14:17:06 +0000
@@ -4,12 +4,12 @@
use strict;
use warnings;
-use Test::More tests => 10;
+use Test::More tests => 16;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer);
+use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv);
my $output;
sub print_fn($) { my $x = shift; $output.=$x; }
@@ -133,3 +133,22 @@
sub { $fn->("r->in.bla"); });
is($output, "if (r->in.bla == NULL) return;");
+
+# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
+$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
+is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionOutEnv($fn));
+
+$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
+is_deeply({ }, GenerateFunctionInEnv($fn));
More information about the samba-cvs
mailing list