1 # Some simple utility functions for pidl tests
2 # Copyright (C) 2005 Jelmer Vernooij
3 # Published under the GNU General Public License
9 @EXPORT_OK = qw(test_samba4_ndr);
16 use Parse::Pidl::Samba4::NDR::Parser;
17 use Parse::Pidl::Samba4::Header;
21 # Generate a Samba4 parser for an IDL fragment and run it with a specified
22 # piece of code to check whether the parser works as expected
23 sub test_samba4_ndr($$$)
25 my ($name,$idl,$c) = @_;
26 my $pidl = Parse::Pidl::IDL::parse_string("interface echo { $idl }; ", "<$name>");
28 ok (defined($pidl), "($name) parse idl");
29 my $header = Parse::Pidl::Samba4::Header::Parse($pidl);
30 ok(defined($header), "($name) generate generic header");
31 my $pndr = Parse::Pidl::NDR::Parse($pidl);
32 ok(defined($pndr), "($name) generate NDR tree");
33 my ($ndrheader,$ndrparser) = Parse::Pidl::Samba4::NDR::Parser::Parse($pndr, "foo");
34 ok(defined($ndrparser), "($name) generate NDR parser");
35 ok(defined($ndrheader), "($name) generate NDR header");
39 my $insamba = -f "include/includes.h";
40 my $link = $insamba && 0; # FIXME
42 skip "no samba environment available, skipping compilation", 3
45 skip "no sane C compiler, skipping compilation", 3
48 my $outfile = "test-$name";
50 #my $cflags = $ENV{CFLAGS};
51 my $cflags = "-Iinclude -Ilib -I.";
53 if ($insamba and $link) {
54 open CC, "|cc -x c -o $outfile $cflags -";
56 open CC, "|cc -x c -c -o $outfile $cflags -";
58 print CC "#include \"includes.h\"\n";
62 print CC "int main(int argc, const char **argv)
64 TALLOC_CTX *mem_ctx = talloc_init(NULL);
73 ok(-f $outfile, "($name) compile");
76 skip "no shared libraries of Samba available yet, can't run test", 2;
80 ok(system($outfile), "($name) run");
82 ok(unlink($outfile), "($name) remove");
87 my $outfile = "test"; # FIXME: Somewhat more unique name
89 # Test whether CC is sane. The real 'fix' here would be using the
90 # Samba build system, but unfortunately, we have no way of hooking into that
91 # yet so we're running CC directly for now
92 $sanecc = 1 if system('echo "main() {}"'." | cc -I. -x c -c - -o $outfile") == 0;