1 # Some simple utility functions for pidl tests
2 # Copyright (C) 2005-2006 Jelmer Vernooij
3 # Published under the GNU General Public License
9 @EXPORT = qw(test_samba4_ndr test_warnings test_errors);
13 use FindBin
qw($RealBin);
14 use lib "$RealBin/../lib";
16 use Parse::Pidl::Samba4 qw(is_intree);
20 undef &Parse
::Pidl
::warning
;
21 *Parse
::Pidl
::warning
= sub {
24 $warnings .= "$e->{FILE}:$e->{LINE}: $l\n";
31 undef &Parse
::Pidl
::error
;
32 *Parse
::Pidl
::error
= sub {
35 $errors .= "$e->{FILE}:$e->{LINE}: $l\n";
44 use Parse
::Pidl
::Samba4
::NDR
::Parser
;
45 use Parse
::Pidl
::Samba4
::Header
;
47 # Generate a Samba4 parser for an IDL fragment and run it with a specified
48 # piece of code to check whether the parser works as expected
51 my ($name,$idl,$c,$extra) = @_;
53 $extra = "" unless defined($extra);
55 my $pidl = Parse
::Pidl
::IDL
::parse_string
("interface echo { $idl }; ", "<$name>");
56 ok
(defined($pidl), "($name) parse idl");
58 my $pndr = Parse
::Pidl
::NDR
::Parse
($pidl);
59 ok
(defined($pndr), "($name) generate NDR tree");
61 my $header = Parse
::Pidl
::Samba4
::Header
::Parse
($pndr);
62 ok
(defined($header), "($name) generate generic header");
64 my $generator = new Parse
::Pidl
::Samba4
::NDR
::Parser
();
65 my ($ndrheader,$ndrparser) = $generator->Parse($pndr, undef, undef);
66 ok
(defined($ndrparser), "($name) generate NDR parser");
67 ok
(defined($ndrheader), "($name) generate NDR header");
72 if (system("pkg-config --exists ndr") == 0 and !is_intree
()) {
73 $flags = `pkg-config --libs --cflags ndr`;
75 skip
"no samba environment available, skipping compilation", 3;
79 #define uint_t unsigned int
85 #include <util/data_blob.h>
104 int main(int argc, const char **argv)
106 TALLOC_CTX *mem_ctx = talloc_init(NULL);
110 talloc_free(mem_ctx);
117 my $main_debug = "# ".join("\n# ", split("\n", $main));
119 my $test_data_prefix = $ENV{TEST_DATA_PREFIX
};
121 if (defined($test_data_prefix)) {
122 $outfile = "$test_data_prefix/test-$name";
124 $outfile = "./test-$name";
127 my $cflags = $ENV{CFLAGS
};
128 unless (defined($cflags)) {
132 my $ldflags = $ENV{LDFLAGS
};
133 unless (defined($ldflags)) {
138 unless (defined($cc)) {
142 my $cmd = "$cc $cflags -x c - -o $outfile $flags $ldflags";
148 ok
(-f
$outfile, "($name) compile");
150 my $ret = system($outfile, ()) >> 8;
151 print "# code:\n#\n$main_debug\n" if ($ret != 0);
152 print "# cmd: $cmd\n" if ($ret != 0);
153 print "# return code: $ret\n" if ($ret != 0);
155 ok
($ret == 0, "($name) run");
157 ok
(unlink($outfile), "($name) remove");
162 sub test_warnings
($$)
164 my ($exp, $code) = @_;
175 my ($exp, $code) = @_;