Rev 11518: Add tests for Needed*(),
in preparation of refactoring. in
file:///home/jelmer/bzr.samba/SAMBA_4_0/
Jelmer Vernooij
jelmer at samba.org
Sun Feb 18 12:51:34 GMT 2007
At file:///home/jelmer/bzr.samba/SAMBA_4_0/
------------------------------------------------------------
revno: 11518
revision-id: jelmer at samba.org-20070218125126-mq0gsnn6mdt0dr5p
parent: svn-v2:21426 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Sun 2007-02-18 13:51:26 +0100
message:
Add tests for Needed*(), in preparation of refactoring.
modified:
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/lib/Parse/Pidl/Samba4/NDR/Parser.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm 2007-02-14 12:44:50 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm 2007-02-18 12:51:26 +0000
@@ -11,7 +11,8 @@
@ISA = qw(Exporter);
@EXPORT = qw(is_charset_array);
@EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv
- GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv);
+ GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction
+ NeededElement NeededTypedef);
use strict;
use Parse::Pidl::Typelist qw(hasType getType mapType);
@@ -2483,6 +2484,14 @@
return ($res_hdr, $res);
}
+sub NeededElement($$$)
+{
+ my ($e, $dir, $needed) = @_;
+
+ return if (defined($needed->{"$dir\_$e->{TYPE}"}));
+ $needed->{"$dir\_$e->{TYPE}"} = 1;
+}
+
sub NeededFunction($$)
{
my ($fn,$needed) = @_;
@@ -2491,15 +2500,7 @@
$needed->{"print_$fn->{NAME}"} = 1;
foreach my $e (@{$fn->{ELEMENTS}}) {
$e->{PARENT} = $fn;
- unless(defined($needed->{"pull_$e->{TYPE}"})) {
- $needed->{"pull_$e->{TYPE}"} = 1;
- }
- unless(defined($needed->{"push_$e->{TYPE}"})) {
- $needed->{"push_$e->{TYPE}"} = 1;
- }
- unless(defined($needed->{"print_$e->{TYPE}"})) {
- $needed->{"print_$e->{TYPE}"} = 1;
- }
+ NeededElement($e, $_, $needed) foreach ("pull", "push", "print");
}
}
@@ -2522,18 +2523,9 @@
if (has_property($e, "compression")) {
$needed->{"compression"} = 1;
}
- if ($needed->{"pull_$t->{NAME}"} and
- not defined($needed->{"pull_$e->{TYPE}"})) {
- $needed->{"pull_$e->{TYPE}"} = 1;
- }
- if ($needed->{"push_$t->{NAME}"} and
- not defined($needed->{"push_$e->{TYPE}"})) {
- $needed->{"push_$e->{TYPE}"} = 1;
- }
- if ($needed->{"print_$t->{NAME}"} and
- not defined($needed->{"print_$e->{TYPE}"})) {
- $needed->{"print_$e->{TYPE}"} = 1;
- }
+ NeededElement($e, "pull", $needed) if ($needed->{"pull_$t->{NAME}"});
+ NeededElement($e, "push", $needed) if ($needed->{"push_$t->{NAME}"});
+ NeededElement($e, "print", $needed) if ($needed->{"print_$t->{NAME}"});
}
}
}
=== modified file 'source/pidl/tests/samba-ndr.pl'
--- a/source/pidl/tests/samba-ndr.pl 2007-02-14 12:44:50 +0000
+++ b/source/pidl/tests/samba-ndr.pl 2007-02-18 12:51:26 +0000
@@ -4,12 +4,14 @@
use strict;
use warnings;
-use Test::More tests => 20;
+use Test::More tests => 29;
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 GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv EnvSubstituteValue);
+use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer
+ GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
+ EnvSubstituteValue NeededFunction NeededElement NeededTypedef);
my $output;
sub print_fn($) { my $x = shift; $output.=$x; }
@@ -172,3 +174,57 @@
$env = GenerateStructEnv($fn);
EnvSubstituteValue($env, $fn);
is_deeply($env, { foo => 0, this => "r" });
+
+my $needed = {};
+NeededElement({ TYPE => "foo" }, "pull", $needed);
+is_deeply($needed, { pull_foo => 1 });
+
+# old settings should be kept
+$needed = { pull_foo => 0 };
+NeededElement({ TYPE => "foo" }, "pull", $needed);
+is_deeply($needed, { pull_foo => 0 });
+
+# print/pull/push are independent of each other
+$needed = { pull_foo => 0 };
+NeededElement({ TYPE => "foo" }, "print", $needed);
+is_deeply($needed, { pull_foo => 0, print_foo => 1 });
+
+$needed = { };
+NeededFunction({ NAME => "foo", ELEMENTS => [ { TYPE => "bar" } ] }, $needed);
+is_deeply($needed, { pull_foo => 1, print_foo => 1, push_foo => 1,
+ pull_bar => 1, print_bar => 1, push_bar => 1});
+
+# push/pull/print are always set for functions
+$needed = { pull_foo => 0 };
+NeededFunction({ NAME => "foo", ELEMENTS => [ { TYPE => "bar" } ] }, $needed);
+is_deeply($needed, { pull_foo => 1, print_foo => 1, push_foo => 1,
+ pull_bar => 1, push_bar => 1, print_bar => 1});
+
+# public structs are always needed
+$needed = {};
+NeededTypedef({ NAME => "bla", DATA => { TYPE => "STRUCT", ELEMENTS => [] } },
+ $needed);
+is_deeply($needed, { });
+
+$needed = {};
+NeededTypedef({ PROPERTIES => { public => 1 }, NAME => "bla",
+ DATA => { TYPE => "STRUCT", ELEMENTS => [] } },
+ $needed);
+is_deeply($needed, { pull_bla => 1, print_bla => 1, push_bla => 1 });
+
+# make sure types for elements are set too
+$needed = {};
+NeededTypedef({ PROPERTIES => { public => 1 }, NAME => "bla",
+ DATA => { TYPE => "STRUCT",
+ ELEMENTS => [ { TYPE => "bar" } ] } },
+ $needed);
+is_deeply($needed, { pull_bla => 1, print_bla => 1, push_bla => 1,
+ pull_bar => 1, print_bar => 1, push_bar => 1});
+
+$needed = {};
+NeededTypedef({ PROPERTIES => { gensize => 1}, NAME => "bla",
+ DATA => { TYPE => "STRUCT",
+ ELEMENTS => [ { TYPE => "bar" } ] } },
+ $needed);
+is_deeply($needed, { ndr_size_bla => 1 });
+
More information about the samba-cvs
mailing list