r22457: Fix tests for Samba3 client generator.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 22 Apr 2007 14:19:22 +0000 (14:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:51:23 +0000 (14:51 -0500)
source/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
source/pidl/pidl
source/pidl/tests/samba3-cli.pl

index a2219bdab2b70e39bb395bf7deb0528097e94f54..27b71053fbe3c3a9e64bb34e803b9bf7718f85df 100644 (file)
@@ -20,14 +20,18 @@ use Parse::Pidl::Samba4 qw(DeclLong);
 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 @@ sub GenerateFunctionInEnv($)
        return \%env;
 }
 
-sub ParseFunction($$)
+sub ParseFunction($$$)
 {
-       my ($uif, $fn) = @_;
+       my ($self, $uif, $fn) = @_;
 
        my $inargs = "";
        my $defargs = "";
@@ -54,42 +58,42 @@ sub ParseFunction($$)
        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 @@ sub ParseFunction($$)
 
                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 @@ sub ParseFunction($$)
                        # 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;
index b28e14f0b2d9213ed1b98b78db2f51e4230eee69..e24eec10535e71bea4bdcf2ea3c6be5846077b3d 100755 (executable)
@@ -702,7 +702,8 @@ sub process_file($)
                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);
        }
index 1d1bae8550210f1b89659e3614fc4150a610331b..c5537c145e140dc8f452e459247cdf2326f62968 100755 (executable)
@@ -9,8 +9,7 @@ use FindBin qw($RealBin);
 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 @@ is_deeply({ "foo" => "r.in.foo" }, GenerateFunctionInEnv($fn));
 $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;