summaryrefslogtreecommitdiff
path: root/source4/pidl/tests/Util.pm
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/Util.pm
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/Util.pm')
-rw-r--r--source4/pidl/tests/Util.pm94
1 files changed, 94 insertions, 0 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;