summaryrefslogtreecommitdiff
path: root/source4/pidl/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-12-25 03:04:13 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:47:43 -0500
commit7717f180ca2f908e1b3258355520719991215050 (patch)
treecca55b2debbe63fdf39d6810ad7987af28ffc04a /source4/pidl/tests
parent620d375320e143abcf6775a392f9bde3146f2baa (diff)
downloadsamba-7717f180ca2f908e1b3258355520719991215050.tar.gz
samba-7717f180ca2f908e1b3258355520719991215050.tar.bz2
samba-7717f180ca2f908e1b3258355520719991215050.zip
r12470: Add helper module for pidl tests
Convert other pidl tests to use Test::More and run them from 'make test' (This used to be commit 3a57d29a62112ab654e290ccc985fba7f67664c5)
Diffstat (limited to 'source4/pidl/tests')
-rw-r--r--source4/pidl/tests/Util.pm94
-rwxr-xr-xsource4/pidl/tests/ndr_align.pl16
-rwxr-xr-xsource4/pidl/tests/ndr_alloc.pl16
-rwxr-xr-xsource4/pidl/tests/ndr_array.pl14
-rwxr-xr-xsource4/pidl/tests/ndr_refptr.pl81
-rwxr-xr-xsource4/pidl/tests/ndr_simple.pl47
-rwxr-xr-xsource4/pidl/tests/ndr_string.pl10
-rwxr-xr-xsource4/pidl/tests/parse_idl.pl2
8 files changed, 177 insertions, 103 deletions
diff --git a/source4/pidl/tests/Util.pm b/source4/pidl/tests/Util.pm
new file mode 100644
index 0000000000..52fde11bf5
--- /dev/null
+++ b/source4/pidl/tests/Util.pm
@@ -0,0 +1,94 @@
+# Some simple utility functions for pidl tests
+# Copyright (C) 2005 Jelmer Vernooij
+# Published under the GNU General Public License
+
+package Util;
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(test_samba4_ndr);
+
+use strict;
+
+use Test::More;
+use Parse::Pidl::IDL;
+use Parse::Pidl::NDR;
+use Parse::Pidl::Samba4::NDR::Parser;
+use Parse::Pidl::Samba4::Header;
+
+my $sanecc = 0;
+
+# Generate a Samba4 parser for an IDL fragment and run it with a specified
+# piece of code to check whether the parser works as expected
+sub test_samba4_ndr($$$)
+{
+ my ($name,$idl,$c) = @_;
+ my $pidl = Parse::Pidl::IDL::parse_string("interface echo { $idl }; ", "<$name>");
+
+ ok (defined($pidl), "($name) parse idl");
+ my $header = Parse::Pidl::Samba4::Header::Parse($pidl);
+ ok(defined($header), "($name) generate generic header");
+ my $pndr = Parse::Pidl::NDR::Parse($pidl);
+ ok(defined($pndr), "($name) generate NDR tree");
+ my ($ndrheader,$ndrparser) = Parse::Pidl::Samba4::NDR::Parser::Parse($pndr, "foo");
+ ok(defined($ndrparser), "($name) generate NDR parser");
+ ok(defined($ndrheader), "($name) generate NDR header");
+
+SKIP: {
+
+ my $insamba = -f "include/includes.h";
+ my $link = $insamba && 0; # FIXME
+
+ skip "no samba environment available, skipping compilation", 3
+ if not $insamba;
+
+ skip "no sane C compiler, skipping compilation", 3
+ if not $sanecc;
+
+ my $outfile = "test-$name";
+
+ #my $cflags = $ENV{CFLAGS};
+ my $cflags = "-Iinclude -I.";
+
+ if ($insamba and $link) {
+ open CC, "|cc -x c -o $outfile $cflags -";
+ } elsif ($insamba) {
+ open CC, "|cc -x c -c -o $outfile $cflags -";
+ }
+ print CC "#include \"includes.h\"\n";
+ print CC $header;
+ print CC $ndrheader;
+ print CC $ndrparser;
+ print CC "int main(int argc, const char **argv)
+{
+ TALLOC_CTX *mem_ctx = talloc_init(NULL);
+
+ $c
+
+ talloc_free(mem_ctx);
+
+ return 0; }\n";
+ close CC;
+
+ ok(-f $outfile, "($name) compile");
+
+ unless ($link) {
+ skip "no shared libraries of Samba available yet, can't run test", 2;
+ unlink($outfile);
+ }
+
+ ok(system($outfile), "($name) run");
+
+ ok(unlink($outfile), "($name) remove");
+
+ }
+}
+
+my $outfile = "test"; # FIXME: Somewhat more unique name
+
+# Test whether CC is sane. The real 'fix' here would be using the
+# Samba build system, but unfortunately, we have no way of hooking into that
+# yet so we're running CC directly for now
+$sanecc = 1 if system('echo "main() {}"'." | cc -I. -x c -c - -o $outfile") == 0;
+
+1;
diff --git a/source4/pidl/tests/ndr_align.pl b/source4/pidl/tests/ndr_align.pl
index 073ce5ce2f..7ca180cf20 100755
--- a/source4/pidl/tests/ndr_align.pl
+++ b/source4/pidl/tests/ndr_align.pl
@@ -3,9 +3,13 @@
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;
-use Test::Simple tests => 1;
+use Test::More tests => 5 * 8;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
+use lib "$RealBin";
+use Util qw(test_samba4_ndr);
-Parse::Pidl::Test::test_idl('align-uint8-uint16', \%settings,
+test_samba4_ndr('align-uint8-uint16',
'
typedef [public] struct {
uint8 x;
@@ -30,7 +34,7 @@ Parse::Pidl::Test::test_idl('align-uint8-uint16', \%settings,
return 2;
');
-Parse::Pidl::Test::test_idl('align-uint8-uint32', \%settings,
+test_samba4_ndr('align-uint8-uint32',
'
typedef [public] struct {
uint8 x;
@@ -56,7 +60,7 @@ Parse::Pidl::Test::test_idl('align-uint8-uint32', \%settings,
');
-Parse::Pidl::Test::test_idl('align-uint8-hyper', \%settings,
+test_samba4_ndr('align-uint8-hyper',
'
typedef [public] struct {
uint8 x;
@@ -82,7 +86,7 @@ Parse::Pidl::Test::test_idl('align-uint8-hyper', \%settings,
return 2;
');
-Parse::Pidl::Test::test_idl('noalignflag-uint8-uint16', \%settings,
+test_samba4_ndr('noalignflag-uint8-uint16',
'
typedef [public] struct {
uint8 x;
@@ -109,7 +113,7 @@ Parse::Pidl::Test::test_idl('noalignflag-uint8-uint16', \%settings,
return 2;
');
-Parse::Pidl::Test::test_idl('align-blob-align2', \%settings,
+test_samba4_ndr('align-blob-align2',
'
typedef [public] struct {
uint8 x;
diff --git a/source4/pidl/tests/ndr_alloc.pl b/source4/pidl/tests/ndr_alloc.pl
index 4786d96971..039826e4ea 100755
--- a/source4/pidl/tests/ndr_alloc.pl
+++ b/source4/pidl/tests/ndr_alloc.pl
@@ -3,11 +3,15 @@
# (C) 2005 Jelmer Vernooij. Published under the GNU GPL
use strict;
-use Test::Simple tests => 1;
+use Test::More tests => 5 * 8;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
+use lib "$RealBin";
+use Util qw(test_samba4_ndr);
# Check that an outgoing scalar pointer is allocated correctly
-Parse::Pidl::Test::test_idl("alloc-scalar", \%settings,
+test_samba4_ndr("alloc-scalar",
'
typedef struct {
uint8 *x;
@@ -32,7 +36,7 @@ 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,
+test_samba4_ndr("alloc-buffer",
'
typedef struct { uint8 data; } blie;
typedef struct { blie *x; } bla;
@@ -56,7 +60,7 @@ Parse::Pidl::Test::test_idl("alloc-buffer", \%settings,
);
# Check that ref pointers aren't allocated by default
-Parse::Pidl::Test::test_idl("ref-noalloc-null", \%settings,
+test_samba4_ndr("ref-noalloc-null",
'
[public] void TestAlloc([in,ref] uint8 *t);
','
@@ -72,7 +76,7 @@ Parse::Pidl::Test::test_idl("ref-noalloc-null", \%settings,
);
# Check that ref pointers aren't allocated by default
-Parse::Pidl::Test::test_idl("ref-noalloc", \%settings,
+test_samba4_ndr("ref-noalloc",
'
[public] void TestAlloc([in,ref] uint8 *t);
','
@@ -92,7 +96,7 @@ Parse::Pidl::Test::test_idl("ref-noalloc", \%settings,
);
# Check that an outgoing ref pointer is allocated correctly
-Parse::Pidl::Test::test_idl("ref-alloc", \%settings,
+test_samba4_ndr("ref-alloc",
'
[public] void TestAlloc([in,ref] uint8 *t);
','
diff --git a/source4/pidl/tests/ndr_array.pl b/source4/pidl/tests/ndr_array.pl
index ad313949c5..b28070536e 100755
--- a/source4/pidl/tests/ndr_array.pl
+++ b/source4/pidl/tests/ndr_array.pl
@@ -4,19 +4,17 @@
# Published under the GNU General Public License
use strict;
-use Test::Simple tests => 1;
+use Test::More tests => 8;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
+use lib "$RealBin";
+use Util qw(test_samba4_ndr);
-Parse::Pidl::Test::test_idl(
- # Name
+test_samba4_ndr(
'Fixed-Array',
- # Settings
- \%settings,
-
- # IDL
'[public] void Test([in] uint8 x[10]);',
- # C Test
'
uint8_t data[] = {1,2,3,4,5,6,7,8,9,10};
int i;
diff --git a/source4/pidl/tests/ndr_refptr.pl b/source4/pidl/tests/ndr_refptr.pl
index 46d74f9b1e..0fd573d51e 100755
--- a/source4/pidl/tests/ndr_refptr.pl
+++ b/source4/pidl/tests/ndr_refptr.pl
@@ -5,9 +5,13 @@
# Published under the GNU General Public License.
use strict;
-use Test::Simple tests => 1;
+use Test::More tests => 21 * 8;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
+use lib "$RealBin";
+use Util qw(test_samba4_ndr);
-Parse::Pidl::Test::test_idl("noptr-push", \%settings,
+test_samba4_ndr("noptr-push",
' typedef struct {
uint16 x;
} xstruct;
@@ -36,7 +40,7 @@ Parse::Pidl::Test::test_idl("noptr-push", \%settings,
}
');
-Parse::Pidl::Test::test_idl("ptr-embedded-push", \%settings,
+test_samba4_ndr("ptr-embedded-push",
' typedef struct {
uint16 *x;
} xstruct;
@@ -63,7 +67,7 @@ Parse::Pidl::Test::test_idl("ptr-embedded-push", \%settings,
return 4;
');
-Parse::Pidl::Test::test_idl("ptr-embedded-push-null", \%settings,
+test_samba4_ndr("ptr-embedded-push-null",
' typedef struct {
uint16 *x;
} xstruct;
@@ -86,7 +90,7 @@ Parse::Pidl::Test::test_idl("ptr-embedded-push-null", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("refptr-embedded-push", \%settings,
+test_samba4_ndr("refptr-embedded-push",
'
typedef struct {
[ref] uint16 *x;
@@ -114,7 +118,7 @@ Parse::Pidl::Test::test_idl("refptr-embedded-push", \%settings,
return 4;
');
-Parse::Pidl::Test::test_idl("refptr-embedded-push-null", \%settings,
+test_samba4_ndr("refptr-embedded-push-null",
'
typedef struct {
[ref] uint16 *x;
@@ -132,7 +136,7 @@ Parse::Pidl::Test::test_idl("refptr-embedded-push-null", \%settings,
/* Windows gives [client runtime error 0x6f4] */
');
-Parse::Pidl::Test::test_idl("ptr-top-push", \%settings,
+test_samba4_ndr("ptr-top-push",
'
typedef struct {
uint16 x;
@@ -157,7 +161,7 @@ Parse::Pidl::Test::test_idl("ptr-top-push", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("ptr-top-push-null", \%settings,
+test_samba4_ndr("ptr-top-push-null",
'
typedef struct {
uint16 x;
@@ -177,7 +181,7 @@ Parse::Pidl::Test::test_idl("ptr-top-push-null", \%settings,
');
-Parse::Pidl::Test::test_idl("refptr-top-push", \%settings,
+test_samba4_ndr("refptr-top-push",
'
typedef struct {
uint16 x;
@@ -202,7 +206,7 @@ Parse::Pidl::Test::test_idl("refptr-top-push", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("refptr-top-push-null", \%settings,
+test_samba4_ndr("refptr-top-push-null",
'
typedef struct {
uint16 x;
@@ -222,7 +226,7 @@ Parse::Pidl::Test::test_idl("refptr-top-push-null", \%settings,
');
-Parse::Pidl::Test::test_idl("uniqueptr-top-push", \%settings,
+test_samba4_ndr("uniqueptr-top-push",
' typedef struct {
uint16 x;
} xstruct;
@@ -250,7 +254,7 @@ Parse::Pidl::Test::test_idl("uniqueptr-top-push", \%settings,
return 4;
');
-Parse::Pidl::Test::test_idl("uniqueptr-top-push-null", \%settings,
+test_samba4_ndr("uniqueptr-top-push-null",
' typedef struct {
uint16 x;
} xstruct;
@@ -274,7 +278,7 @@ Parse::Pidl::Test::test_idl("uniqueptr-top-push-null", \%settings,
');
-Parse::Pidl::Test::test_idl("ptr-top-out-pull", \%settings,
+test_samba4_ndr("ptr-top-out-pull",
'
typedef struct {
uint16 x;
@@ -301,7 +305,7 @@ Parse::Pidl::Test::test_idl("ptr-top-out-pull", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("ptr-top-out-pull-null", \%settings,
+test_samba4_ndr("ptr-top-out-pull-null",
'
typedef struct {
uint16 x;
@@ -324,7 +328,7 @@ Parse::Pidl::Test::test_idl("ptr-top-out-pull-null", \%settings,
');
-Parse::Pidl::Test::test_idl("refptr-top-out-pull", \%settings,
+test_samba4_ndr("refptr-top-out-pull",
'
typedef struct {
uint16 x;
@@ -351,7 +355,7 @@ Parse::Pidl::Test::test_idl("refptr-top-out-pull", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("refptr-top-out-pull-null", \%settings,
+test_samba4_ndr("refptr-top-out-pull-null",
'
typedef struct {
uint16 x;
@@ -374,7 +378,7 @@ Parse::Pidl::Test::test_idl("refptr-top-out-pull-null", \%settings,
');
-Parse::Pidl::Test::test_idl("ptr-top-push-double", \%settings,
+test_samba4_ndr("ptr-top-push-double",
'
[public] void echo_TestRef([in] uint16 **foo);
',
@@ -398,7 +402,7 @@ Parse::Pidl::Test::test_idl("ptr-top-push-double", \%settings,
return 4;
');
-Parse::Pidl::Test::test_idl("ptr-top-push-double-sndnull", \%settings,
+test_samba4_ndr("ptr-top-push-double-sndnull",
'
[public] void echo_TestRef([in] uint16 **foo);
',
@@ -418,7 +422,7 @@ Parse::Pidl::Test::test_idl("ptr-top-push-double-sndnull", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("ptr-top-push-double-fstnull", \%settings,
+test_samba4_ndr("ptr-top-push-double-fstnull",
'
[public] void echo_TestRef([in] uint16 **foo);
',
@@ -434,7 +438,7 @@ Parse::Pidl::Test::test_idl("ptr-top-push-double-fstnull", \%settings,
');
-Parse::Pidl::Test::test_idl("refptr-top-push-double", \%settings,
+test_samba4_ndr("refptr-top-push-double",
'
[public] void echo_TestRef([in,ref] uint16 **foo);
',
@@ -458,7 +462,7 @@ Parse::Pidl::Test::test_idl("refptr-top-push-double", \%settings,
return 4;
');
-Parse::Pidl::Test::test_idl("refptr-top-push-double-sndnull", \%settings,
+test_samba4_ndr("refptr-top-push-double-sndnull",
'
[public] void echo_TestRef([in,ref] uint16 **foo);
',
@@ -478,7 +482,7 @@ Parse::Pidl::Test::test_idl("refptr-top-push-double-sndnull", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("refptr-top-push-double-fstnull", \%settings,
+test_samba4_ndr("refptr-top-push-double-fstnull",
'
[public] void echo_TestRef([in,ref] uint16 **foo);
',
@@ -493,19 +497,20 @@ Parse::Pidl::Test::test_idl("refptr-top-push-double-fstnull", \%settings,
');
-Parse::Pidl::Test::test_idl("ignore-ptr", \%settings,
-'
- [public] void echo_TestRef([in,ignore] uint16 *foo, [in] uint16 *bar);
-',
-' struct ndr_push *ndr = ndr_push_init();
- struct echo_TestRef r;
- uint16_t v = 10;
- r.in.foo = &v;
- r.in.bar = &v;
-
- if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
- return 1;
-
- if (ndr->offset != 4)
- return 2;
-');
+#FIXME: Not supported yet
+#test_samba4_ndr("ignore-ptr",
+#'
+# [public] void echo_TestRef([in,ignore] uint16 *foo, [in] uint16 *bar);
+#',
+#' struct ndr_push *ndr = ndr_push_init();
+# struct echo_TestRef r;
+# uint16_t v = 10;
+# r.in.foo = &v;
+# r.in.bar = &v;
+#
+# if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r)))
+# return 1;
+#
+# if (ndr->offset != 4)
+# return 2;
+#');
diff --git a/source4/pidl/tests/ndr_simple.pl b/source4/pidl/tests/ndr_simple.pl
index 5bdd02b763..9535ee1fae 100755
--- a/source4/pidl/tests/ndr_simple.pl
+++ b/source4/pidl/tests/ndr_simple.pl
@@ -4,45 +4,18 @@
# Published under the GNU General Public License
use strict;
-use Test::Simple tests => 6;
+use Test::More tests => 8;
use FindBin qw($RealBin);
use lib "$RealBin/../lib";
-use Parse::Pidl::IDL;
-use Parse::Pidl::NDR;
-use Parse::Pidl::Samba4::NDR::Parser;
-use Parse::Pidl::Samba4::Header;
+use lib "$RealBin";
+use Util qw(test_samba4_ndr);
-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 = Parse::Pidl::Samba4::Header::Parse($pidl);
-ok(defined($header));
-my ($ndrheader,$parser) = Parse::Pidl::Samba4::NDR::Parser::Parse($pndr, "foo");
-ok(defined($parser));
-ok(defined($ndrheader));
-
-my $outfile = "test";
-
-#my $cflags = $ENV{CFLAGS};
-my $cflags = "-Iinclude -I.";
-
-open CC, "|cc -x c -o $outfile $cflags -";
-#open CC, ">foo";
-print CC "#include \"includes.h\"";
-print CC $header;
-print CC $ndrheader;
-print CC $parser;
-print CC
- '
-int main(int argc, const char **argv)
-{
+test_samba4_ndr("simple", "void Test(); ",
+"
uint8_t data[] = { 0x02 };
uint8_t result;
DATA_BLOB b;
struct ndr_pull *ndr;
- TALLOC_CTX *mem_ctx = talloc_init(NULL);
b.data = data;
b.length = 1;
@@ -53,12 +26,4 @@ int main(int argc, const char **argv)
if (result != 0x02)
return 2;
-
- talloc_free(mem_ctx);
-
- return 0;
-}
-';
-close CC;
-
-ok(-f $outfile);
+");
diff --git a/source4/pidl/tests/ndr_string.pl b/source4/pidl/tests/ndr_string.pl
index 6ece73fb4d..e8e37be8c1 100755
--- a/source4/pidl/tests/ndr_string.pl
+++ b/source4/pidl/tests/ndr_string.pl
@@ -4,9 +4,13 @@
# Published under the GNU General Public License
use strict;
-use Test::Simple tests => 1;
+use Test::More tests => 2 * 8;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
+use lib "$RealBin";
+use Util qw(test_samba4_ndr);
-Parse::Pidl::Test::test_idl("string-pull-empty", \%settings,
+test_samba4_ndr("string-pull-empty",
' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);',
'
uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 };
@@ -25,7 +29,7 @@ Parse::Pidl::Test::test_idl("string-pull-empty", \%settings,
return 3;
');
-Parse::Pidl::Test::test_idl("string-ascii-pull", \%settings,
+test_samba4_ndr("string-ascii-pull",
'
[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
index d4b680d055..7fdd2ddfac 100755
--- a/source4/pidl/tests/parse_idl.pl
+++ b/source4/pidl/tests/parse_idl.pl
@@ -4,7 +4,7 @@
# Published under the GNU General Public License
use strict;
-use Test::Simple tests => 26;
+use Test::More tests => 26;
use FindBin qw($RealBin);
use lib "$RealBin/../lib";
use Parse::Pidl::IDL;