Rev 11559: Add some tests for the EJS code in
file:///home/jelmer/bzr.samba/SAMBA_4_0/
Jelmer Vernooij
jelmer at samba.org
Wed Feb 21 12:33:08 GMT 2007
At file:///home/jelmer/bzr.samba/SAMBA_4_0/
------------------------------------------------------------
revno: 11559
revision-id: jelmer at samba.org-20070221123127-0131p4yw87krxoif
parent: svn-v2:21489 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Wed 2007-02-21 13:31:27 +0100
message:
Add some tests for the EJS code
More work on supporting nested types in EJS.
added:
source/pidl/tests/samba-ejs.pl sambaejs.pl-20070221122513-gmuxaani7udej08e-1
modified:
source/pidl/lib/Parse/Pidl/Samba4/EJS.pm svn-v2:12463 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fpidl%2flib%2fParse%2fPidl%2fSamba4%2fEJS.pm
=== added file 'source/pidl/tests/samba-ejs.pl'
--- a/source/pidl/tests/samba-ejs.pl 1970-01-01 00:00:00 +0000
+++ b/source/pidl/tests/samba-ejs.pl 2007-02-21 12:31:27 +0000
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+# (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+# Published under the GNU General Public License
+use strict;
+use warnings;
+
+use Test::More tests => 13;
+use FindBin qw($RealBin);
+use lib "$RealBin";
+use Util;
+use Parse::Pidl::Util qw(MyDumper);
+use Parse::Pidl::Samba4::EJS qw(get_pointer_to get_value_of check_null_pointer
+ $res $res_hdr fn_declare);
+
+is("&foo", get_pointer_to("foo"));
+is("&(&foo)", get_pointer_to(get_pointer_to("foo")));
+is("*foo", get_pointer_to("**foo"));
+is("foo", get_pointer_to("*foo"));
+
+is("foo", get_value_of("&foo"));
+is("*foo", get_value_of("foo"));
+is("**foo", get_value_of("*foo"));
+
+$res = "";
+check_null_pointer("bla");
+is($res, "");
+
+$res = "";
+check_null_pointer("*bla");
+is($res, "if (bla == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;\n");
+
+$res = "";
+$res_hdr = "";
+fn_declare({ PROPERTIES => { public => 1 } }, "myproto(int x)");
+is($res, "_PUBLIC_ myproto(int x)\n");
+is($res_hdr, "myproto(int x);\n");
+
+$res = "";
+$res_hdr = "";
+fn_declare({ PROPERTIES => {} }, "mybla(int foo)");
+is($res, "static mybla(int foo)\n");
+is($res_hdr, "");
=== modified file 'source/pidl/lib/Parse/Pidl/Samba4/EJS.pm'
--- a/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm 2007-02-21 11:32:48 +0000
+++ b/source/pidl/lib/Parse/Pidl/Samba4/EJS.pm 2007-02-21 12:31:27 +0000
@@ -6,16 +6,23 @@
package Parse::Pidl::Samba4::EJS;
+use Exporter;
+ at ISA = qw(Exporter);
+ at EXPORT_OK = qw(get_pointer_to get_value_of check_null_pointer $res
+ $res_hdr fn_declare);
+
use strict;
use Parse::Pidl::Typelist;
use Parse::Pidl::Util qw(has_property ParseExpr);
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel);
+use Parse::Pidl::Samba4::NDR::Parser qw(GenerateStructEnv GenerateFunctionInEnv
+ GenerateFunctionOutEnv);
use vars qw($VERSION);
$VERSION = '0.01';
-my $res;
-my $res_hdr;
+our $res;
+our $res_hdr;
my %constants;
@@ -46,52 +53,6 @@
$tabs = substr($tabs, 0, -1);
}
-sub GenerateStructEnv($)
-{
- my $x = shift;
- my %env;
-
- foreach my $e (@{$x->{ELEMENTS}}) {
- if ($e->{NAME}) {
- $env{$e->{NAME}} = "r->$e->{NAME}";
- }
- }
-
- $env{"this"} = "r";
-
- return \%env;
-}
-
-sub GenerateFunctionInEnv($)
-{
- my $fn = shift;
- my %env;
-
- foreach my $e (@{$fn->{ELEMENTS}}) {
- if (grep (/in/, @{$e->{DIRECTION}})) {
- $env{$e->{NAME}} = "r->in.$e->{NAME}";
- }
- }
-
- return \%env;
-}
-
-sub GenerateFunctionOutEnv($)
-{
- my $fn = shift;
- my %env;
-
- foreach my $e (@{$fn->{ELEMENTS}}) {
- if (grep (/out/, @{$e->{DIRECTION}})) {
- $env{$e->{NAME}} = "r->out.$e->{NAME}";
- } elsif (grep (/in/, @{$e->{DIRECTION}})) {
- $env{$e->{NAME}} = "r->in.$e->{NAME}";
- }
- }
-
- return \%env;
-}
-
sub get_pointer_to($)
{
my $var_name = shift;
@@ -127,7 +88,6 @@
}
}
-
#####################################################################
# work out is a parse function should be declared static or not
sub fn_declare($$)
@@ -291,7 +251,7 @@
sub EjsStructPull($$)
{
my ($name, $d) = @_;
- my $env = GenerateStructEnv($d);
+ my $env = GenerateStructEnv($d, "r");
fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, struct $name *r)");
pidl "{";
indent;
@@ -391,7 +351,6 @@
pidl "}";
}
-
###########################
# generate a structure pull
sub EjsTypedefPull($)
@@ -580,7 +539,7 @@
sub EjsStructPush($$)
{
my ($name, $d) = @_;
- my $env = GenerateStructEnv($d);
+ my $env = GenerateStructEnv($d, "r");
fn_declare($d, "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const struct $name *r)");
pidl "{";
indent;
@@ -879,32 +838,25 @@
}
}
-sub NeededTypedef($$)
+sub NeededType($$$)
{
- my ($t,$needed) = @_;
-
- if (has_property($t, "public")) {
- $needed->{"pull_$t->{NAME}"} = not has_property($t, "noejs");
- $needed->{"push_$t->{NAME}"} = not has_property($t, "noejs");
- }
-
- return if (($t->{DATA}->{TYPE} ne "STRUCT") and
- ($t->{DATA}->{TYPE} ne "UNION"));
-
- foreach (@{$t->{DATA}->{ELEMENTS}}) {
+ sub NeededType($$$);
+ my ($t,$needed,$req) = @_;
+
+ NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF");
+
+ return if (($t->{TYPE} ne "STRUCT") and
+ ($t->{TYPE} ne "UNION"));
+
+ foreach (@{$t->{ELEMENTS}}) {
next if (has_property($_, "subcontext")); #FIXME: Support subcontexts
my $n;
- if (ref($_->{TYPE}) eq "HASH") {
- $n = "$_->{TYPE}->{TYPE}_$_->{TYPE}->{NAME}";
- } else {
- $n = $_->{TYPE};
- }
- unless (defined($needed->{"pull_$n"})) {
- $needed->{"pull_$n"} = $needed->{"pull_$t->{NAME}"};
- }
- unless (defined($needed->{"push_$n"})) {
- $needed->{"push_$n"} = $needed->{"push_$t->{NAME}"};
- }
+ if (ref($_->{TYPE}) eq "HASH" and defined($_->{TYPE}->{NAME})) {
+ $needed->{"$req\_$_->{TYPE}->{TYPE}_$_->{TYPE}->{NAME}"} = 1;
+ } elsif (ref($_->{TYPE}) ne "HASH") {
+ $needed->{$req."_".$_->{TYPE}} = 1;
+ }
+ NeededType($_->{TYPE}, $needed, $req) if (ref($_->{TYPE}) eq "HASH");
}
}
@@ -915,7 +867,16 @@
my ($interface,$needed) = @_;
NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}});
- NeededTypedef($_, $needed) foreach (reverse @{$interface->{TYPES}});
+
+ foreach (reverse @{$interface->{TYPES}}) {
+ if (has_property($_, "public")) {
+ $needed->{"pull_$_->{NAME}"} = not has_property($_, "noejs");
+ $needed->{"push_$_->{NAME}"} = not has_property($_, "noejs");
+ }
+
+ NeededType($_, $needed, "pull") if ($needed->{"pull_$_->{NAME}"});
+ NeededType($_, $needed, "push") if ($needed->{"push_$_->{NAME}"});
+ }
}
1;
More information about the samba-cvs
mailing list