Rev 11979: Fix tests for Samba3 client generator. in file:///home/jelmer/bzr.samba/SAMBA_4_0/

Jelmer Vernooij jelmer at samba.org
Sun Apr 22 15:18:04 GMT 2007


At file:///home/jelmer/bzr.samba/SAMBA_4_0/

------------------------------------------------------------
revno: 11979
revision-id: jelmer at samba.org-20070422151749-lyirte2r0dtzyy5b
parent: svn-v2:22456 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-04-22 17:17:49 +0200
message:
  Fix tests for Samba3 client generator.
modified:
  source/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm svn-v2:15437 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fSamba3%2fClientNDR.pm
  source/pidl/pidl               svn-v2:9459 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2fpidl
  source/pidl/tests/samba3-cli.pl svn-v2:21338 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2ftests%2fsamba3%2dcli.pl
=== modified file 'source/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm	2007-04-19 01:26:15 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm	2007-04-22 15:17:49 +0000
@@ -20,14 +20,18 @@
 use vars qw($VERSION);
 $VERSION = '0.01';
 
-my $res;
-my $res_hdr;
-my $tabs = "";
-sub indent() { $tabs.="\t"; }
-sub deindent() { $tabs = substr($tabs, 1); }
-sub pidl($) { $res .= $tabs.(shift)."\n"; }
-sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
-sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
+sub indent($) { my ($self) = @_; $self->{tabs}.="\t"; }
+sub deindent($) { my ($self) = @_; $self->{tabs} = substr($self->{tabs}, 1); }
+sub pidl($$) { my ($self,$txt) = @_; $self->{res} .= "$self->{tabs}$txt\n"; }
+sub pidl_hdr($$) { my ($self, $txt) = @_; $self->{res_hdr} .= "$txt\n"; } 
+sub fn_declare($$) { my ($self,$n) = @_; $self->pidl($n); $self->pidl_hdr("$n;"); }
+
+sub new($)
+{
+	my ($class) = shift;
+	my $self = { res => "", res_hdr => "", tabs => "" };
+	bless($self, $class);
+}
 
 sub GenerateFunctionInEnv($)
 {
@@ -43,9 +47,9 @@
 	return \%env;
 }
 
-sub ParseFunction($$)
+sub ParseFunction($$$)
 {
-	my ($uif, $fn) = @_;
+	my ($self, $uif, $fn) = @_;
 
 	my $inargs = "";
 	my $defargs = "";
@@ -54,42 +58,42 @@
 	foreach (@{$fn->{ELEMENTS}}) {
 		$defargs .= ", " . DeclLong($_);
 	}
-	fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)";
-	pidl "{";
-	indent;
-	pidl "struct $fn->{NAME} r;";
-	pidl "NTSTATUS status;";
-	pidl "";
-	pidl "/* In parameters */";
+	$self->fn_declare("NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)");
+	$self->pidl("{");
+	$self->indent;
+	$self->pidl("struct $fn->{NAME} r;");
+	$self->pidl("NTSTATUS status;");
+	$self->pidl("");
+	$self->pidl("/* In parameters */");
 
 	foreach (@{$fn->{ELEMENTS}}) {
 		if (grep(/in/, @{$_->{DIRECTION}})) {
-			pidl "r.in.$_->{NAME} = $_->{NAME};";
+			$self->pidl("r.in.$_->{NAME} = $_->{NAME};");
 		} 
 	}
 
-	pidl "";
-	pidl "if (DEBUGLEVEL >= 10)";
-	pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);";
-	pidl "";
-	pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});";
-	pidl "";
-
-	pidl "if (!NT_STATUS_IS_OK(status)) {";
-	indent;
-	pidl "return status;";
-	deindent;
-	pidl "}";
-
-	pidl "";
-	pidl "if (DEBUGLEVEL >= 10)";
-	pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);";
-	pidl "";
-	pidl "if (NT_STATUS_IS_ERR(status)) {";
-	pidl "\treturn status;";
-	pidl "}";
-	pidl "";
-	pidl "/* Return variables */";
+	$self->pidl("");
+	$self->pidl("if (DEBUGLEVEL >= 10)");
+	$self->pidl("\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);");
+	$self->pidl("");
+	$self->pidl("status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});");
+	$self->pidl("");
+
+	$self->pidl("if (!NT_STATUS_IS_OK(status)) {");
+	$self->indent;
+	$self->pidl("return status;");
+	$self->deindent;
+	$self->pidl("}");
+
+	$self->pidl("");
+	$self->pidl("if (DEBUGLEVEL >= 10)");
+	$self->pidl("\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);");
+	$self->pidl("");
+	$self->pidl("if (NT_STATUS_IS_ERR(status)) {");
+	$self->pidl("\treturn status;");
+	$self->pidl("}");
+	$self->pidl("");
+	$self->pidl("/* Return variables */");
 	foreach my $e (@{$fn->{ELEMENTS}}) {
 		next unless (grep(/out/, @{$e->{DIRECTION}}));
 
@@ -97,8 +101,8 @@
 
 		if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and
 			 ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) {
-			pidl "if ( $e->{NAME} ) {";
-			indent;
+			$self->pidl("if ( $e->{NAME} ) {");
+			$self->indent;
 		}
 
 		if ($e->{LEVELS}[0]->{TYPE} eq "ARRAY") {
@@ -108,70 +112,67 @@
 			# to allocate a structure of the right size.
 			my $env = GenerateFunctionInEnv($fn);
 			my $size_is = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e);
-			pidl "memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);";
+			$self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);");
 		} else {
-			pidl "*$e->{NAME} = *r.out.$e->{NAME};";
+			$self->pidl("*$e->{NAME} = *r.out.$e->{NAME};");
 		}
 
 		if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and
 			 ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) {
-			deindent;
-			pidl "}";
+			$self->deindent;
+			$self->pidl("}");
 		}
 	}
 
-	pidl"";
-	pidl "/* Return result */";
+	$self->pidl("");
+	$self->pidl("/* Return result */");
 	if (not $fn->{RETURN_TYPE}) {
-		pidl "return NT_STATUS_OK;";
+		$self->pidl("return NT_STATUS_OK;");
 	} elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
-		pidl "return r.out.result;";
+		$self->pidl("return r.out.result;");
 	} elsif ($fn->{RETURN_TYPE} eq "WERROR") {
-		pidl "return werror_to_ntstatus(r.out.result);";
+		$self->pidl("return werror_to_ntstatus(r.out.result);");
 	} else {
 		warning($fn->{ORIGINAL}, "Unable to convert $fn->{RETURN_TYPE} to NTSTATUS");
-		pidl "return NT_STATUS_OK;";
+		$self->pidl("return NT_STATUS_OK;");
 	}
 
-	deindent;
-	pidl "}";
-	pidl "";
+	$self->deindent;
+	$self->pidl("}");
+	$self->pidl("");
 }
 
-sub ParseInterface($)
+sub ParseInterface($$)
 {
-	my $if = shift;
+	my ($self, $if) = @_;
 
 	my $uif = uc($if->{NAME});
 
-	pidl_hdr "#ifndef __CLI_$uif\__";
-	pidl_hdr "#define __CLI_$uif\__";
-	ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}});
-	pidl_hdr "#endif /* __CLI_$uif\__ */";
+	$self->pidl_hdr("#ifndef __CLI_$uif\__");
+	$self->pidl_hdr("#define __CLI_$uif\__");
+	$self->ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}});
+	$self->pidl_hdr("#endif /* __CLI_$uif\__ */");
 }
 
-sub Parse($$$)
+sub Parse($$$$)
 {
-	my($ndr,$header,$ndr_header) = @_;
-
-	$res = "";
-	$res_hdr = "";
-
-	pidl "/*";
-	pidl " * Unix SMB/CIFS implementation.";
-	pidl " * client auto-generated by pidl. DO NOT MODIFY!";
-	pidl " */";
-	pidl "";
-	pidl "#include \"includes.h\"";
-	pidl "#include \"$header\"";
-	pidl_hdr "#include \"$ndr_header\"";
-	pidl "";
+	my($self,$ndr,$header,$ndr_header) = @_;
+
+	$self->pidl("/*");
+	$self->pidl(" * Unix SMB/CIFS implementation.");
+	$self->pidl(" * client auto-generated by pidl. DO NOT MODIFY!");
+	$self->pidl(" */");
+	$self->pidl("");
+	$self->pidl("#include \"includes.h\"");
+	$self->pidl("#include \"$header\"");
+	$self->pidl_hdr("#include \"$ndr_header\"");
+	$self->pidl("");
 	
 	foreach (@$ndr) {
-		ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
+		$self->ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
 	}
 
-	return ($res, $res_hdr);
+	return ($self->{res}, $self->{res_hdr});
 }
 
 1;

=== modified file 'source/pidl/pidl'
--- a/source/pidl/pidl	2007-04-22 13:57:07 +0000
+++ b/source/pidl/pidl	2007-04-22 15:17:49 +0000
@@ -702,7 +702,8 @@
 		my $client = ($opt_samba3_ndr_client or "$outputdir/cli_$basename.c");
 		my $header = $client; $header =~ s/\.c$/\.h/;
 		require Parse::Pidl::Samba3::ClientNDR;
-		my ($c_code,$h_code) = Parse::Pidl::Samba3::ClientNDR::Parse($ndr, $header, $h_filename);
+		my $generator = new Parse::Pidl::Samba3::ClientNDR();
+		my ($c_code,$h_code) = $generator->Parse($ndr, $header, $h_filename);
 		FileSave($client, $c_code);
 		FileSave($header, $h_code);
 	}

=== modified file 'source/pidl/tests/samba3-cli.pl'
--- a/source/pidl/tests/samba3-cli.pl	2007-02-14 14:23:59 +0000
+++ b/source/pidl/tests/samba3-cli.pl	2007-04-22 15:17:49 +0000
@@ -9,8 +9,7 @@
 use lib "$RealBin";
 use Util;
 use Parse::Pidl::Util qw(MyDumper);
-use Parse::Pidl::Samba3::ClientNDR qw(GenerateFunctionInEnv ParseFunction $res 
-    $res_hdr);
+use Parse::Pidl::Samba3::ClientNDR qw(GenerateFunctionInEnv ParseFunction);
 
 # Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
 my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] };
@@ -22,9 +21,11 @@
 $fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] };
 is_deeply({ }, GenerateFunctionInEnv($fn));
 
+my $x = new Parse::Pidl::Samba3::ClientNDR();
+
 $fn = { NAME => "bar", ELEMENTS => [ ] };
-ParseFunction("foo", $fn);
-is($res, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx)
+$x->ParseFunction("foo", $fn);
+is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx)
 {
 \tstruct bar r;
 \tNTSTATUS status;



More information about the samba-cvs mailing list