diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-12-24 23:32:50 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:47:42 -0500 |
commit | 68ef82aac72c351f6e166b92bbb4573e8bcdbc86 (patch) | |
tree | b4a7b5518eb5f525f17990b240f121a62283ec29 /source4/pidl/lib/Parse/Pidl | |
parent | ebfbb2a7abe33e47af48d69164c37f4c24b7f8ed (diff) | |
download | samba-68ef82aac72c351f6e166b92bbb4573e8bcdbc86.tar.gz samba-68ef82aac72c351f6e166b92bbb4573e8bcdbc86.tar.bz2 samba-68ef82aac72c351f6e166b92bbb4573e8bcdbc86.zip |
r12464: Add simple IDL parsing tests for pidl using the standard perl
testing framework (Test::Simple, distributed with perl itself).
Run these tests from 'make test'
(This used to be commit 975d8816db6697dab828941b69a740e3a0a2c272)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/IDL.pm | 8 | ||||
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/NDR.pm | 24 | ||||
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm | 14 | ||||
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Test.pm | 171 |
4 files changed, 21 insertions, 196 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/IDL.pm b/source4/pidl/lib/Parse/Pidl/IDL.pm index c948f1af33..4988ae572a 100644 --- a/source4/pidl/lib/Parse/Pidl/IDL.pm +++ b/source4/pidl/lib/Parse/Pidl/IDL.pm @@ -2690,6 +2690,7 @@ sub CleanData($) { sub CleanData($); my($v) = shift; + return undef if (not defined($v)); if (ref($v) eq "ARRAY") { foreach my $i (0 .. $#{$v}) { CleanData($v->[$i]); @@ -2776,12 +2777,13 @@ again: } } -sub parse_string($) +sub parse_string { - my ($data) = @_; + my ($data,$filename) = @_; my $self = new Parse::Pidl::IDL; + $self->YYData->{INPUT_FILENAME} = $filename; $self->YYData->{INPUT} = $data; $self->YYData->{LINE} = 0; $self->YYData->{LAST_TOKEN} = "NONE"; @@ -2804,7 +2806,7 @@ sub parse_file($) my $data = `$cpp -D__PIDL__ -xc $filename`; $/ = $saved_delim; - return parse_string($data); + return parse_string($data, $filename); } 1; diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index 9ff69f8757..4b7a753fa5 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -13,15 +13,18 @@ Parse::Pidl::NDR - NDR parsing information generator =head1 DESCRIPTION -##################################################################### -# return a table describing the order in which the parts of an element -# should be parsed -# Possible level types: -# - POINTER -# - ARRAY -# - SUBCONTEXT -# - SWITCH -# - DATA +Return a table describing the order in which the parts of an element +should be parsed +Possible level types: + - POINTER + - ARRAY + - SUBCONTEXT + - SWITCH + - DATA + +=head1 AUTHOR + +Jelmer Vernooij <jelmer@samba.org> =cut @@ -629,6 +632,9 @@ sub ParseInterface($) sub Parse($) { my $idl = shift; + + return undef unless (defined($idl)); + my @ndr = (); push(@ndr, ParseInterface($_)) foreach (@{$idl}); diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm index d55a7a12af..1480b42971 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm @@ -16,19 +16,8 @@ use vars qw($VERSION); $VERSION = '0.01'; my($res); -my($tab_depth); -sub pidl ($) -{ - $res .= shift; -} - -sub tabs() -{ - my $res = ""; - $res .="\t" foreach (1..$tab_depth); - return $res; -} +sub pidl ($) { $res .= shift; } ##################################################################### # prototype a typedef @@ -154,7 +143,6 @@ sub HeaderInterface($) sub Parse($$) { my($idl,$basename) = @_; - $tab_depth = 0; $res = ""; pidl "/* header auto-generated by pidl */\n"; diff --git a/source4/pidl/lib/Parse/Pidl/Test.pm b/source4/pidl/lib/Parse/Pidl/Test.pm deleted file mode 100644 index 66f5c73595..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Test.pm +++ /dev/null @@ -1,171 +0,0 @@ -# Simple system for running tests against pidl -# (C) 2005 Jelmer Vernooij <jelmer@samba.org> -# Published under the GNU General Public License - -package Parse::Pidl::Test; - -use strict; -use Parse::Pidl::Util; -use Getopt::Long; - -use vars qw($VERSION); -$VERSION = '0.01'; -my $cc = $ENV{CC}; -my @cflags = split / /, $ENV{CFLAGS}; -my @ldflags = split / /, $ENV{LDFLAGS}; - -$cc = "cc" if ($cc eq ""); - -sub generate_cfile($$$) -{ - my ($filename, $fragment, $incfiles) = @_; - - unless (open (OUT, ">$filename")) { - print STDERR "Unable to open $filename\n"; - return -1; - } - print OUT ' -/* This file was autogenerated. All changes made will be lost! */ -#include "include/includes.h" -'; - - foreach (@$incfiles) { - print OUT "#include \"$_\"\n"; - } - - print OUT ' -int main(int argc, char **argv) -{ - TALLOC_CTX *mem_ctx = talloc_init(NULL); - '; - print OUT $fragment; - print OUT "\treturn 0;\n}\n"; - close OUT; - - return 0; -} - -sub generate_idlfile($$) -{ - my ($filename,$fragment) = @_; - - unless (open(OUT, ">$filename")) { - print STDERR "Unable to open $filename\n"; - return -1; - } - - print OUT ' -[uuid("1-2-3-4-5")] interface test_if -{ -'; - print OUT $fragment; - print OUT "\n}\n"; - close OUT; - - return 0; -} - -sub compile_idl($$$) -{ - my ($filename,$idl_path, $idlargs) = @_; - - my @args = @$idlargs; - push (@args, $filename); - - unless (system($idl_path, @args) == 0) { - print STDERR "Error compiling IDL file $filename: $!\n"; - return -1; - } -} - -sub compile_cfile($) -{ - my ($filename) = @_; - - return system($cc, @cflags, '-I.', '-Iinclude', '-c', $filename); -} - -sub link_files($$) -{ - my ($exe_name,$objs) = @_; - - return system($cc, @ldflags, '-Lbin', '-lrpc', '-o', $exe_name, @$objs); -} - -sub test_idl($$$$) -{ - my ($name,$settings,$idl,$c) = @_; - - $| = 1; - - print "Running $name... "; - - my $outputdir = $settings->{OutputDir}; - - my $c_filename = $outputdir."/".$name."_test.c"; - my $idl_filename = $outputdir."/".$name."_idl.idl"; - my $exe_filename = $outputdir."/".$name."_exe"; - - return -1 if (generate_cfile($c_filename, $c, $settings->{IncludeFiles}) == -1); - - return -1 if (generate_idlfile($idl_filename, $idl) == -1); - - return -1 if (compile_idl($idl_filename, $settings->{'IDL-Compiler'}, $settings->{'IDL-Arguments'}) == -1); - - my @srcs = ($c_filename); - push (@srcs, @{$settings->{'ExtraFiles'}}); - - foreach (@srcs) { - next unless /\.c$/; - return -1 if (compile_cfile($_) == -1); - } - - my @objs; - foreach (@srcs) { - if (/\.c$/) { s/\.c$/\.o/g; } - push(@objs, $_); - } - - return -1 if (link_files($exe_filename, \@objs) == -1); - - my $ret = system("./$exe_filename"); - if ($ret != 0) { - $ret = $? >> 8; - print "failed with return value $ret\n"; - return $ret; - } - - unless ($settings->{Keep}) { - unlink(@srcs, @objs, $exe_filename, $idl_filename); - } - - print "Ok\n"; - - return $ret; -} - -sub GetSettings($) -{ - my $settings = { - OutputDir => ".", - 'IDL-Compiler' => "./pidl" - }; - - my %opts = (); - GetOptions('idl-compiler=s' => \$settings->{'IDL-Compiler'}, - 'outputdir=s' => \$settings->{OutputDir}, - 'keep' => \$settings->{Keep}, - 'help' => sub { ShowHelp(); exit 1; } ); - - return %$settings; -} - -sub ShowHelp() -{ - print " --idl-compiler=PATH-TO-PIDL Override path to IDL compiler\n"; - print " --outputdir=OUTPUTDIR Write temporary files to OUTPUTDIR rather then .\n"; - print " --keep Keep intermediate files after running test"; - print " --help Show this help message\n"; -} - -1; |