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
;
18 use Parse
::Pidl
::Samba4
qw(is_intree);
22 # Generate a Samba4 parser for an IDL fragment and run it with a specified
23 # piece of code to check whether the parser works as expected
24 sub test_samba4_ndr
($$$)
26 my ($name,$idl,$c) = @_;
27 my $pidl = Parse
::Pidl
::IDL
::parse_string
("interface echo { $idl }; ", "<$name>");
29 ok
(defined($pidl), "($name) parse idl");
30 my $header = Parse
::Pidl
::Samba4
::Header
::Parse
($pidl);
31 ok
(defined($header), "($name) generate generic header");
32 my $pndr = Parse
::Pidl
::NDR
::Parse
($pidl);
33 ok
(defined($pndr), "($name) generate NDR tree");
34 my ($ndrheader,$ndrparser) = Parse
::Pidl
::Samba4
::NDR
::Parser
::Parse
($pndr, undef, undef);
35 ok
(defined($ndrparser), "($name) generate NDR parser");
36 ok
(defined($ndrheader), "($name) generate NDR header");
40 my $link = is_intree
() && 0; # FIXME
42 skip
"no samba environment available, skipping compilation", 3
45 skip
"no sane C compiler, skipping compilation", 3
48 my $test_data_prefix = $ENV{TEST_DATA_PREFIX
};
51 if (defined($test_data_prefix)) {
52 $outfile = "$test_data_prefix/test-$name";
54 $outfile = "test-$name";
57 #my $cflags = $ENV{CFLAGS};
58 my $cflags = "-Iinclude -Ilib -I.";
60 if (is_intree
() and $link) {
61 open CC
, "|cc -x c -o $outfile $cflags -";
62 } elsif (is_intree
()) {
63 open CC
, "|cc -x c -c -o $outfile $cflags -";
65 print CC
"#include \"includes.h\"\n";
69 print CC
"int main(int argc, const char **argv)
71 TALLOC_CTX *mem_ctx = talloc_init(NULL);
80 ok
(-f
$outfile, "($name) compile");
83 skip
"no shared libraries of Samba available yet, can't run test", 2;
87 ok
(system($outfile), "($name) run");
89 ok
(unlink($outfile), "($name) remove");
94 my $outfile = "test"; # FIXME: Somewhat more unique name
96 # Test whether CC is sane. The real 'fix' here would be using the
97 # Samba build system, but unfortunately, we have no way of hooking into that
98 # yet so we're running CC directly for now
99 $sanecc = 1 if system('echo "main() {}"'." | cc -I. -x c -c - -o $outfile") == 0;