1 # Simple system for running tests against pidl
2 # (C) 2005 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
5 package Parse::Pidl::Test;
12 my @cflags = split / /, $ENV{CFLAGS};
13 my @ldflags = split / /, $ENV{LDFLAGS};
15 $cc = "cc" if ($cc eq "");
17 sub generate_cfile($$$)
19 my ($filename, $fragment, $incfiles) = @_;
21 unless (open (OUT, ">$filename")) {
22 print STDERR "Unable to open $filename\n";
26 /* This file was autogenerated. All changes made will be lost! */
27 #include "include/includes.h"
30 foreach (@$incfiles) {
31 print OUT "#include \"$_\"\n";
35 int main(int argc, char **argv)
37 TALLOC_CTX *mem_ctx = talloc_init(NULL);
40 print OUT "\treturn 0;\n}\n";
46 sub generate_idlfile($$)
48 my ($filename,$fragment) = @_;
50 unless (open(OUT, ">$filename")) {
51 print STDERR "Unable to open $filename\n";
56 [uuid("1-2-3-4-5")] interface test_if
68 my ($filename,$idl_path, $idlargs) = @_;
71 push (@args, $filename);
73 unless (system($idl_path, @args) == 0) {
74 print STDERR "Error compiling IDL file $filename: $!\n";
83 return system($cc, @cflags, '-I.', '-Iinclude', '-c', $filename);
88 my ($exe_name,$objs) = @_;
90 return system($cc, @ldflags, '-Lbin', '-lrpc', '-o', $exe_name, @$objs);
95 my ($name,$settings,$idl,$c) = @_;
99 print "Running $name... ";
101 my $outputdir = $settings->{OutputDir};
103 my $c_filename = $outputdir."/".$name."_test.c";
104 my $idl_filename = $outputdir."/".$name."_idl.idl";
105 my $exe_filename = $outputdir."/".$name."_exe";
107 return -1 if (generate_cfile($c_filename, $c, $settings->{IncludeFiles}) == -1);
109 return -1 if (generate_idlfile($idl_filename, $idl) == -1);
111 return -1 if (compile_idl($idl_filename, $settings->{'IDL-Compiler'}, $settings->{'IDL-Arguments'}) == -1);
113 my @srcs = ($c_filename);
114 push (@srcs, @{$settings->{'ExtraFiles'}});
118 return -1 if (compile_cfile($_) == -1);
123 if (/\.c$/) { s/\.c$/\.o/g; }
127 return -1 if (link_files($exe_filename, \@objs) == -1);
129 my $ret = system("./$exe_filename");
132 print "failed with return value $ret\n";
136 unless ($settings->{Keep}) {
137 unlink(@srcs, @objs, $exe_filename, $idl_filename);
149 'IDL-Compiler' => "./pidl"
153 GetOptions('idl-compiler=s' => \$settings->{'IDL-Compiler'},
154 'outputdir=s' => \$settings->{OutputDir},
155 'keep' => \$settings->{Keep},
156 'help' => sub { ShowHelp(); exit 1; } );
163 print " --idl-compiler=PATH-TO-PIDL Override path to IDL compiler\n";
164 print " --outputdir=OUTPUTDIR Write temporary files to OUTPUTDIR rather then .\n";
165 print " --keep Keep intermediate files after running test";
166 print " --help Show this help message\n";