r6862: Add some more tests
authorJelmer Vernooij <jelmer@samba.org>
Tue, 17 May 2005 17:32:25 +0000 (17:32 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:52 +0000 (13:16 -0500)
Accept new command-line options --keep, --outputdir and --idl-compiler.

We're currently at 34 IDL tests (...and counting)

source/build/pidl/test.pm
source/build/pidl/tests/ndr_align.pl
source/build/pidl/tests/ndr_alloc.pl
source/build/pidl/tests/ndr_refptr.pl
source/build/pidl/tests/ndr_simple.pl
source/build/pidl/tests/ndr_string.pl [new file with mode: 0644]
source/script/tests/test_pidl.sh

index a7e3a839be51bd5b5113adc07cd48e4c0f4d5964..5f25d4195c1ed9bb6f3c87a9f210c7e20fc8405b 100644 (file)
@@ -6,8 +6,8 @@ package Test;
 
 use strict;
 use util;
+use Getopt::Long;
 
-my $idl_path = "./build/pidl/pidl.pl";
 my $cc = $ENV{CC};
 my @cflags = split / /, $ENV{CFLAGS};
 my @ldflags = split / /, $ENV{LDFLAGS};
@@ -63,9 +63,9 @@ sub generate_idlfile($$)
        return 0;
 }
 
-sub compile_idl($$)
+sub compile_idl($$$)
 {
-       my ($filename,$idlargs) = @_;
+       my ($filename,$idl_path, $idlargs) = @_;
 
        my @args = @$idlargs;
        push (@args, $filename);
@@ -87,7 +87,7 @@ sub link_files($$)
 {
        my ($exe_name,$objs) = @_;
 
-       return system($cc, @ldflags, '-I.', '-Iinclude', '-Lbin', '-lrpc', '-o', $exe_name, @$objs);
+       return system($cc, @ldflags, '-Lbin', '-lrpc', '-o', $exe_name, @$objs);
 }
 
 sub test_idl($$$$)
@@ -96,17 +96,19 @@ sub test_idl($$$$)
 
        $| = 1;
 
-       print "Running test $name... ";
+       print "Running $name... ";
 
-       my $c_filename = $name."_test.c";
-       my $idl_filename = $name."_idl.idl";
-       my $exe_filename = $name."_exe";
+       my $outputdir = $settings->{OutputDir};
+
+       my $c_filename = $outputdir."/".$name."_test.c";
+       my $idl_filename = $outputdir."/".$name."_idl.idl";
+       my $exe_filename = $outputdir."/".$name."_exe";
 
        return -1 if (generate_cfile($c_filename, $c, $settings->{IncludeFiles}) == -1);
 
        return -1 if (generate_idlfile($idl_filename, $idl) == -1);
 
-       return -1 if (compile_idl($idl_filename, $settings->{'IDL-Arguments'}) == -1);
+       return -1 if (compile_idl($idl_filename, $settings->{'IDL-Compiler'}, $settings->{'IDL-Arguments'}) == -1);
 
        my @srcs = ($c_filename);
        push (@srcs, @{$settings->{'ExtraFiles'}});
@@ -116,17 +118,52 @@ sub test_idl($$$$)
                return -1 if (compile_cfile($_) == -1);
        }
 
-       return -1 if (link_files($exe_filename, \@srcs) == -1);
+       my @objs;
+       foreach (@srcs) {
+               if (/\.c$/) { s/\.c$/\.o/g; }
+               push(@objs, $_);
+       }
+
+       return -1 if (link_files($exe_filename, \@objs) == -1);
 
        my $ret = system("./$exe_filename");
        if ($ret != 0) {
+               $ret = $? >> 8;
                print "failed with return value $ret\n";
                return $ret;
        }
 
+       unless ($settings->{Keep}) {
+               unlink(@srcs, @objs, $exe_filename, $idl_filename);
+       }
+
        print "Ok\n";
 
        return $ret;
 }
 
+sub GetSettings($)
+{
+       my $settings = { 
+               OutputDir => ".",
+               'IDL-Compiler' => "./build/pidl/pidl.pl"
+       };
+
+       my %opts = ();
+       GetOptions('idl-compiler=s' => \$settings->{'IDL-Compiler'},
+               'outputdir=s' => \$settings->{OutputDir},
+               'keep' => \$settings->{Keep},
+               'help' => sub { ShowHelp(); exit 1; } );
+
+       return %$settings;
+}
+
+sub ShowHelp()
+{
+       print " --idl-compiler=PATH-TO-PIDL  Override path to IDL compiler\n";
+       print " --outputdir=OUTPUTDIR        Write temporary files to OUTPUTDIR rather then .\n";
+       print " --keep                       Keep intermediate files after running test";
+       print " --help                       Show this help message\n";
+}
+
 1;
index c428dd32bdf8b4d9bfc8b64bbbbd0da1aeca3f77..03b09e875887ca0e97afed761776872b365d6027 100755 (executable)
@@ -7,11 +7,11 @@ use FindBin qw($RealBin);
 use lib "$RealBin/..";
 use test;
 
-my %settings = (
-       'IDL-Arguments' => ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'],
-       'IncludeFiles' => ['ndr_test.h'],
-       'ExtraFiles' => ['ndr_test.c'],
-);
+my %settings = Test::GetSettings(@ARGV);
+
+$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
+$settings{'IncludeFiles'} = ['ndr_test.h'];
+$settings{'ExtraFiles'} = ['ndr_test.c'];
 
 Test::test_idl('align-uint8-uint16', \%settings,
 '
@@ -89,3 +89,58 @@ Test::test_idl('align-uint8-hyper', \%settings,
        if (!data_blob_equal(&result_blob, &expected_blob)) 
                return 2;
 ');
+
+Test::test_idl('noalignflag-uint8-uint16', \%settings,
+'
+       typedef [public] struct { 
+               uint8 x;
+               uint16 y;
+       } bla;
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct bla r;
+       uint8_t expected[] = { 0x0D, 0xef, 0xbe };
+       DATA_BLOB expected_blob = { expected, 3 };
+       DATA_BLOB result_blob;
+       ndr->flags |= LIBNDR_FLAG_NOALIGN;
+
+       r.x = 13;
+       r.y = 0xbeef;
+
+       if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
+               return 1;
+
+       result_blob = ndr_push_blob(ndr);
+       
+       if (!data_blob_equal(&result_blob, &expected_blob)) 
+               return 2;
+');
+
+Test::test_idl('align-blob-align2', \%settings,
+'
+       typedef [public] struct { 
+               uint8 x;
+               [flag(LIBNDR_FLAG_ALIGN2)] DATA_BLOB data;
+       } bla;
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct bla r;
+       uint8_t data[] = { 0x01, 0x02 };
+       uint8_t expected[] = { 0x0D, 0x00, 0x01, 0x02 };
+       DATA_BLOB expected_blob = { expected, 4 };
+       DATA_BLOB result_blob;
+
+       r.x = 13;
+       r.data.data = data;
+       r.data.length = 2;
+
+       if (NT_STATUS_IS_ERR(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
+               return 1;
+
+       result_blob = ndr_push_blob(ndr);
+
+       if (!data_blob_equal(&result_blob, &expected_blob)) 
+               return 2;
+');
index 86f3ec153caabf59b013be27283f46a2bb3e462e..7918f312d49a3c3c24d22a69c35bca67d6902fc0 100755 (executable)
@@ -7,11 +7,10 @@ use FindBin qw($RealBin);
 use lib "$RealBin/..";
 use test;
 
-my %settings = (
-       'IDL-Arguments' => ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'],
-       'IncludeFiles' => ['ndr_test.h'],
-       'ExtraFiles' => ['ndr_test.c'],
-);
+my %settings = Test::GetSettings(@ARGV);
+$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
+$settings{'IncludeFiles'} = ['ndr_test.h'];
+$settings{'ExtraFiles'} = ['ndr_test.c'];
 
 # Check that an outgoing scalar pointer is allocated correctly
 
index 72698a78bd1c611adab8fb863a3e432f7b604a5d..59ebd295f6913142fe7b1099f27a06a7826e2187 100755 (executable)
@@ -9,11 +9,10 @@ use FindBin qw($RealBin);
 use lib "$RealBin/..";
 use test;
 
-my %settings = (
-       'IDL-Arguments' => ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'],
-       'IncludeFiles' => ['ndr_test.h'],
-       'ExtraFiles' => ['ndr_test.c'],
-);
+my %settings = Test::GetSettings(@ARGV);
+$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
+$settings{'IncludeFiles'} = ['ndr_test.h'];
+$settings{'ExtraFiles'} = ['ndr_test.c'];
 
 Test::test_idl("noptr-push", \%settings, 
 '      typedef struct {
index 29b4784e52045bed487c33d01dc2b75600232202..7049dfa68d64cf63343400490be32902b973e78b 100755 (executable)
@@ -8,11 +8,10 @@ use FindBin qw($RealBin);
 use lib "$RealBin/..";
 use test;
 
-my %settings = (
-       'IDL-Arguments' => ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'],
-       'IncludeFiles' => ['ndr_test.h'],
-       'ExtraFiles' => ['ndr_test.c'],
-);
+my %settings = Test::GetSettings(@ARGV);
+$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
+$settings{'IncludeFiles'} = ['ndr_test.h'];
+$settings{'ExtraFiles'} = ['ndr_test.c'];
 
 Test::test_idl(
        # Name
diff --git a/source/build/pidl/tests/ndr_string.pl b/source/build/pidl/tests/ndr_string.pl
new file mode 100644 (file)
index 0000000..9ea4ca4
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+# String tests for pidl
+# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU General Public License
+use strict;
+
+use FindBin qw($RealBin);
+use lib "$RealBin/..";
+use test;
+
+my %settings = Test::GetSettings(@ARGV);
+
+$settings{'IDL-Arguments'} = ['--quiet', '--parse', '--parser=ndr_test.c', '--header=ndr_test.h'];
+$settings{'IncludeFiles'} = ['ndr_test.h'];
+$settings{'ExtraFiles'} = ['ndr_test.c'];
+
+Test::test_idl("string-pull-empty", \%settings,
+' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);',
+'
+       uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 };
+       DATA_BLOB b = { data, 4 };
+       struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
+       struct TestString r;
+       r.in.data = NULL;
+
+       if (NT_STATUS_IS_ERR(ndr_pull_TestString(ndr, NDR_IN, &r))) 
+               return 1;
+       
+       if (r.in.data == NULL)
+               return 2;
+
+       if (r.in.data[0] != 0)
+               return 3;
+');
+
+Test::test_idl("string-ascii-pull", \%settings,
+'
+       [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);
+',
+'
+       uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, 
+                                          \'f\', \'o\', \'o\', 0 };
+       DATA_BLOB b = { data, 8 };
+       struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
+       struct TestString r;
+       r.in.data = NULL;
+
+       if (NT_STATUS_IS_ERR(ndr_pull_TestString(ndr, NDR_IN, &r))) 
+               return 1;
+       
+       if (r.in.data == NULL)
+               return 2;
+
+       if (strncmp(r.in.data, "foo", 3) != 0)
+               return 3;
+
+       if (r.in.data[4] != 0)
+               return 4;
+');
index 8c57f10ffe7db3ea8bf1a8f4c18c22df2fcc32e5..07c144a65fe39822079382e317e8d6767e643a53 100755 (executable)
@@ -3,3 +3,4 @@
 ./build/pidl/tests/ndr_align.pl
 ./build/pidl/tests/ndr_alloc.pl
 ./build/pidl/tests/ndr_refptr.pl
+./build/pidl/tests/ndr_string.pl