summaryrefslogtreecommitdiff
path: root/source4/pidl
diff options
context:
space:
mode:
Diffstat (limited to 'source4/pidl')
-rw-r--r--source4/pidl/idl.yp8
-rw-r--r--source4/pidl/lib/Parse/Pidl/IDL.pm8
-rw-r--r--source4/pidl/lib/Parse/Pidl/NDR.pm24
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm14
-rw-r--r--source4/pidl/lib/Parse/Pidl/Test.pm171
-rwxr-xr-xsource4/pidl/tests/ndr_align.pl8
-rwxr-xr-xsource4/pidl/tests/ndr_alloc.pl16
-rwxr-xr-xsource4/pidl/tests/ndr_array.pl7
-rwxr-xr-xsource4/pidl/tests/ndr_refptr.pl7
-rwxr-xr-xsource4/pidl/tests/ndr_simple.pl68
-rwxr-xr-xsource4/pidl/tests/ndr_string.pl8
-rwxr-xr-xsource4/pidl/tests/parse_idl.pl57
12 files changed, 126 insertions, 270 deletions
diff --git a/source4/pidl/idl.yp b/source4/pidl/idl.yp
index ef0ec203a7..430f7e1b06 100644
--- a/source4/pidl/idl.yp
+++ b/source4/pidl/idl.yp
@@ -330,6 +330,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]);
@@ -416,12 +417,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";
@@ -444,5 +446,5 @@ sub parse_file($)
my $data = `$cpp -D__PIDL__ -xc $filename`;
$/ = $saved_delim;
- return parse_string($data);
+ return parse_string($data, $filename);
}
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;
diff --git a/source4/pidl/tests/ndr_align.pl b/source4/pidl/tests/ndr_align.pl
index da994224eb..073ce5ce2f 100755
--- a/source4/pidl/tests/ndr_align.pl
+++ b/source4/pidl/tests/ndr_align.pl
@@ -3,13 +3,7 @@
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;
-use Parse::Pidl::Test;
-
-my %settings = Parse::Pidl::Test::GetSettings(@ARGV);
-
-$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
-$settings{'IncludeFiles'} = ['ndr_test.h'];
-$settings{'ExtraFiles'} = ['ndr_test.c'];
+use Test::Simple tests => 1;
Parse::Pidl::Test::test_idl('align-uint8-uint16', \%settings,
'
diff --git a/source4/pidl/tests/ndr_alloc.pl b/source4/pidl/tests/ndr_alloc.pl
index 4f6eddbfb9..4786d96971 100755
--- a/source4/pidl/tests/ndr_alloc.pl
+++ b/source4/pidl/tests/ndr_alloc.pl
@@ -3,12 +3,7 @@
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;
-use Parse::Pidl::Test;
-
-my %settings = Parse::Pidl::Test::GetSettings(@ARGV);
-$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
-$settings{'IncludeFiles'} = ['ndr_test.h'];
-$settings{'ExtraFiles'} = ['ndr_test.c'];
+use Test::Simple tests => 1;
# Check that an outgoing scalar pointer is allocated correctly
@@ -39,14 +34,9 @@ Parse::Pidl::Test::test_idl("alloc-scalar", \%settings,
# Check that an outgoing buffer pointer is allocated correctly
Parse::Pidl::Test::test_idl("alloc-buffer", \%settings,
'
- typedef struct {
- uint8 data;
- } blie;
+ typedef struct { uint8 data; } blie;
+ typedef struct { blie *x; } bla;
- typedef struct {
- blie *x;
- } bla;
-
[public] void TestAlloc([in] bla foo);
','
uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 };
diff --git a/source4/pidl/tests/ndr_array.pl b/source4/pidl/tests/ndr_array.pl
index d486308339..ad313949c5 100755
--- a/source4/pidl/tests/ndr_array.pl
+++ b/source4/pidl/tests/ndr_array.pl
@@ -4,12 +4,7 @@
# Published under the GNU General Public License
use strict;
-use Parse::Pidl::Test;
-
-my %settings = Parse::Pidl::Test::GetSettings(@ARGV);
-$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
-$settings{'IncludeFiles'} = ['ndr_test.h'];
-$settings{'ExtraFiles'} = ['ndr_test.c'];
+use Test::Simple tests => 1;
Parse::Pidl::Test::test_idl(
# Name
diff --git a/source4/pidl/tests/ndr_refptr.pl b/source4/pidl/tests/ndr_refptr.pl
index 8344661ad3..46d74f9b1e 100755
--- a/source4/pidl/tests/ndr_refptr.pl
+++ b/source4/pidl/tests/ndr_refptr.pl
@@ -5,12 +5,7 @@
# Published under the GNU General Public License.
use strict;
-use Parse::Pidl::Test;
-
-my %settings = Parse::Pidl::Test::GetSettings(@ARGV);
-$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
-$settings{'IncludeFiles'} = ['ndr_test.h'];
-$settings{'ExtraFiles'} = ['ndr_test.c'];
+use Test::Simple tests => 1;
Parse::Pidl::Test::test_idl("noptr-push", \%settings,
' typedef struct {
diff --git a/source4/pidl/tests/ndr_simple.pl b/source4/pidl/tests/ndr_simple.pl
index 2c2c910a56..96e213ede9 100755
--- a/source4/pidl/tests/ndr_simple.pl
+++ b/source4/pidl/tests/ndr_simple.pl
@@ -4,41 +4,45 @@
# Published under the GNU General Public License
use strict;
-use Parse::Pidl::Test;
+use Test::Simple tests => 4;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
use Parse::Pidl::IDL;
use Parse::Pidl::NDR;
-use Parse::Pidl::Samba::NDR;
+use Parse::Pidl::Samba4::NDR::Parser;
-my %settings = Parse::Pidl::Test::GetSettings(@ARGV);
-$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
-$settings{'IncludeFiles'} = ['ndr_test.h'];
-$settings{'ExtraFiles'} = ['ndr_test.c'];
-
-my $pidl = Parse::Pidl::IDL::parse_string('void Test();');
+my $pidl = Parse::Pidl::IDL::parse_string(
+"interface test { void Test(); }; ", "<test>");
+ok (defined($pidl));
my $pndr = Parse::Pidl::NDR::Parse($pidl);
+ok(defined($pndr));
+my ($header,$parser) = Parse::Pidl::Samba4::NDR::Parser($pndr);
+ok(defined($header));
+ok(defined($parser));
-Parse::Pidl::Test::test_idl(
- # Name
- 'UInt8',
-
- # Settings
- \%settings,
-
-
- # C Test
- '
- uint8_t data[] = { 0x02 };
- uint8_t result;
- DATA_BLOB b;
- struct ndr_pull *ndr;
-
- b.data = data;
- b.length = 1;
- ndr = ndr_pull_init_blob(&b, mem_ctx);
-
- if (NT_STATUS_IS_ERR(ndr_pull_uint8(ndr, NDR_SCALARS, &result)))
- return 1;
- if (result != 0x02)
- return 2;
-');
+#Parse::Pidl::Test::test_idl(
+# # Name
+# 'UInt8',
+#
+# # Settings
+# \%settings,
+#
+#
+# # C Test
+# '
+# uint8_t data[] = { 0x02 };
+# uint8_t result;
+# DATA_BLOB b;
+# struct ndr_pull *ndr;
+#
+# b.data = data;
+# b.length = 1;
+# ndr = ndr_pull_init_blob(&b, mem_ctx);
+#
+# if (NT_STATUS_IS_ERR(ndr_pull_uint8(ndr, NDR_SCALARS, &result)))
+# return 1;
+#
+# if (result != 0x02)
+# return 2;
+#');
diff --git a/source4/pidl/tests/ndr_string.pl b/source4/pidl/tests/ndr_string.pl
index ad8db912d7..6ece73fb4d 100755
--- a/source4/pidl/tests/ndr_string.pl
+++ b/source4/pidl/tests/ndr_string.pl
@@ -4,13 +4,7 @@
# Published under the GNU General Public License
use strict;
-use Parse::Pidl::Test;
-
-my %settings = Parse::Pidl::Test::GetSettings(@ARGV);
-
-$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
-$settings{'IncludeFiles'} = ['ndr_test.h'];
-$settings{'ExtraFiles'} = ['ndr_test.c'];
+use Test::Simple tests => 1;
Parse::Pidl::Test::test_idl("string-pull-empty", \%settings,
' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);',
diff --git a/source4/pidl/tests/parse_idl.pl b/source4/pidl/tests/parse_idl.pl
new file mode 100755
index 0000000000..d4b680d055
--- /dev/null
+++ b/source4/pidl/tests/parse_idl.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+# Some simple tests for pidls parsing routines
+# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU General Public License
+use strict;
+
+use Test::Simple tests => 26;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
+use Parse::Pidl::IDL;
+use Parse::Pidl::NDR;
+
+sub testok($$)
+{
+ my ($name, $data) = @_;
+
+ my $pidl = Parse::Pidl::IDL::parse_string($data, "<$name>");
+
+ ok (defined($pidl), $name);
+ return $pidl
+}
+
+sub testfail($$)
+{
+ my ($name, $data) = @_;
+
+ my $pidl = Parse::Pidl::IDL::parse_string($data, "<$name>");
+
+ ok ((not defined $pidl), $name);
+}
+
+testok "test1", "interface test { void Test(); }; ";
+testok "voidtest", "interface test { int Testx(void); }; ";
+testfail "voidtest", "interface test { Test(); }; ";
+testok "argtest", "interface test { int Test(int a, long b, uint32 c); }; ";
+testok "array1", "interface test { int Test(int a[]); };";
+testok "array2", "interface test { int Test(int a[2]); };";
+testok "array3", "interface test { int Test(int a[b]); };";
+testfail "array4", "interface test { int Test(int[] a); };";
+testok "ptr1", "interface test { int Test(int *a); };";
+testok "ptr2", "interface test { int Test(int **a); };";
+testok "ptr3", "interface test { int Test(int ***a); };";
+testfail "empty1", "interface test { };";
+testfail "empty2", "";
+testok "attr1", "[uuid(\"myuuid\"),attr] interface test { int Test(int ***a); };";
+testok "attr2", "interface test { [public] int Test(); };";
+testok "multfn", "interface test { int test1(); int test2(); };";
+testok "multif", "interface test { int test1(); }; interface test2 { int test2(); };";
+testok "tdstruct1", "interface test { typedef struct { } foo; };";
+testok "tdstruct2", "interface test { typedef struct { int a; } foo; };";
+testok "tdstruct3", "interface test { typedef struct { int a; int b; } foo; };";
+testfail "tdstruct4", "interface test { typedef struct { int a, int b; } foo; };";
+testok "tdunion1", "interface test { typedef union { } a; };";
+testok "tdunion2", "interface test { typedef union { int a; } a; };";
+testok "typedef1", "interface test { typedef int a; };";
+testfail "typedef2", "interface test { typedef x; };";
+testok "tdenum1", "interface test { typedef enum { A=1, B=2, C} a; };";