r6856: Add a couple of tests that test for the behaviour described in
authorJelmer Vernooij <jelmer@samba.org>
Tue, 17 May 2005 12:17:42 +0000 (12:17 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:51 +0000 (13:16 -0500)
tridge's ref_notes.txt document.

source/build/pidl/test.pm
source/build/pidl/tests/ndr_refptr.pl [new file with mode: 0755]

index ba86d8eb10aaedff9442ca13294e8fdc554fffc1..9004d7c4c6f3e66ba66ecf71af653629dfe4da4e 100644 (file)
@@ -20,7 +20,7 @@ sub generate_cfile($$$)
        print OUT '
 /* This file was autogenerated. All changes made will be lost! */
 #include "include/includes.h"
- ';
+';
 
        foreach (@$incfiles) {
                print OUT "#include \"$_\"\n";
@@ -118,6 +118,7 @@ sub test_idl($$$$)
        my $ret = system("./$exe_filename");
        if ($ret != 0) {
                print STDERR "$name failed with return value $ret\n";
+               return $ret;
        }
 
        print "Ok\n";
diff --git a/source/build/pidl/tests/ndr_refptr.pl b/source/build/pidl/tests/ndr_refptr.pl
new file mode 100755 (executable)
index 0000000..38efbed
--- /dev/null
@@ -0,0 +1,375 @@
+#!/usr/bin/perl
+# Simple tests for pidl's handling of ref pointers, based
+# on tridge's ref_notes.txt
+use strict;
+
+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'],
+);
+
+Test::test_idl("noptr-push", \%settings, 
+'      typedef struct {
+               uint16 x;
+       } xstruct;
+
+       [public] uint16 echo_TestRef([in] xstruct foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       uint16_t v = 13;
+       struct echo_TestRef r;
+       r.in.foo.x = v; 
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 2)
+               return 2;
+
+       if (ndr->data[0] != 13 || ndr->data[1] != 0) 
+               return 3;
+');
+
+Test::test_idl("ptr-embedded-push", \%settings,
+'   typedef struct {
+               short *x;
+       } xstruct;
+
+       uint16 echo_TestRef([in] xstruct foo);
+',
+'
+       uint16_t v = 13;
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       r.in.foo.x = &v; 
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 6)
+               return 2;
+
+       if (ndr->data[0] == 0 && ndr->data[1] == 0 && 
+           ndr->data[2] == 0 && ndr->data[3] == 0)
+               return 3;
+
+       if (ndr->data[4] != 13 || ndr->data[5] != 0)
+               return 4;
+');
+
+Test::test_idl("ptr-embedded-push-null", \%settings,
+'   typedef struct {
+               short *x;
+       } xstruct;
+
+       uint16 echo_TestRef([in] xstruct foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       r.in.foo.x = NULL; 
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 4)
+               return 2;
+
+       if (ndr->data[0] != 0 || ndr->data[1] != 0 || 
+           ndr->data[2] != 0 || ndr->data[3] != 0)
+               return 3;
+');
+
+Test::test_idl("refptr-embedded-push", \%settings,
+'
+       typedef struct {
+               [ref] short *x;
+       } xstruct;
+
+       uint16 echo_TestRef([in] xstruct foo);
+',
+'
+       uint16_t v = 13;
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       r.in.foo.x = &v; 
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 6)
+               return 2;
+
+       if (ndr->data[0] == 0 && ndr->data[1] == 0 && 
+           ndr->data[2] == 0 && ndr->data[3] == 0)
+               return 3;
+
+       if (ndr->data[4] != 13 || ndr->data[5] != 0)
+               return 4;
+');
+
+Test::test_idl("refptr-embedded-push-null", \%settings,
+'
+       typedef struct {
+               [ref] short *x;
+       } xstruct;
+
+       uint16 echo_TestRef([in] xstruct foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       r.in.foo.x = NULL; 
+
+       if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+       /* Windows gives [client runtime error 0x6f4] */
+');
+
+Test::test_idl("ptr-top-push", \%settings,
+'
+       typedef struct {
+               short x;
+       } xstruct;
+
+       uint16 echo_TestRef([in] xstruct *foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       struct xstruct s;
+       s.x = 13;
+       r.in.foo = &s;
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 2)
+               return 2;
+
+       if (ndr->data[0] != 13 || ndr->data[1] != 0)
+               return 3;
+');
+
+Test::test_idl("ptr-top-push-null", \%settings,
+'
+       typedef struct {
+               short x;
+       } xstruct;
+
+       uint16 echo_TestRef([in] xstruct *foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       r.in.foo = NULL;
+
+       if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       /* Windows gives [client runtime error 0x6f4] */
+');
+
+
+Test::test_idl("refptr-top-push", \%settings,
+'
+       typedef struct {
+               short x;
+       } xstruct;
+
+       uint16 echo_TestRef([in,ref] xstruct *foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       struct xstruct s;
+       s.x = 13;
+       r.in.foo = &s;
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 2)
+               return 2;
+
+       if (ndr->data[0] != 13 || ndr->data[1] != 0)
+               return 3;
+');
+
+Test::test_idl("refptr-top-push-null", \%settings,
+'
+       typedef struct {
+               short x;
+       } xstruct;
+
+       uint16 echo_TestRef([in,ref] xstruct *foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       r.in.foo = NULL;
+
+       if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       /* Windows gives [client runtime error 0x6f4] */
+');
+
+
+Test::test_idl("uniqueptr-top-push", \%settings,
+'      typedef struct {
+               short x;
+       } xstruct;
+
+       uint16 echo_TestRef([in,unique] xstruct *foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       struct xstruct s;
+       s.x = 13;
+       r.in.foo = &s;
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 6)
+               return 2;
+
+       if (ndr->data[0] == 0 && ndr->data[1] == 0 && 
+           ndr->data[2] == 0 && ndr->data[3] == 0)
+               return 3;
+
+       if (ndr->data[4] != 13 || ndr->data[5] != 0)
+               return 4;
+');
+
+Test::test_idl("uniqueptr-top-push-null", \%settings,
+'      typedef struct {
+               short x;
+       } xstruct;
+
+       uint16 echo_TestRef([in,unique] xstruct *foo);
+',
+'
+       struct ndr_push *ndr = ndr_push_init();
+       struct echo_TestRef r;
+       r.in.foo = NULL;
+
+       if (NT_STATUS_IS_ERR(ndr_push_echo_TestRef(ndr, ndr_flags, &r)))
+               return 1;
+
+       if (ndr->offset != 4)
+               return 2;
+
+       if (ndr->data[0] != 0 || ndr->data[1] != 0 || 
+           ndr->data[2] != 0 || ndr->data[3] != 0)
+               return 3;
+');
+
+
+#----------------------------------------------------
+#      typedef struct {
+#              short x;
+#      } xstruct;
+#
+#      uint16 echo_TestRef([out] xstruct foo);
+#
+#        [idl compiler error]
+#
+#----------------------------------------------------
+#      typedef struct {
+#              short x;
+#      } xstruct;
+#
+#      void echo_TestRef([out] xstruct *foo);
+#
+#      xstruct r;
+#      echo_TestRef(&r);
+#      r.x -> 13;
+#
+#      [0D 00]
+#
+#
+#      echo_TestRef(NULL);
+#
+#      [client runtime error 0x6f4]
+#
+#----------------------------------------------------
+#      typedef struct {
+#              short x;
+#      } xstruct;
+#
+#      void echo_TestRef([out,ref] xstruct *foo);
+#
+#      xstruct r;
+#      echo_TestRef(&r);
+#      r.x -> 13;
+#
+#      [0D 00]
+#
+#
+#      echo_TestRef(NULL);
+#
+#      [client runtime error 0x6f4]
+#
+#----------------------------------------------------
+#      typedef struct {
+#              short x;
+#      } xstruct;
+#
+#      void echo_TestRef([out,unique] xstruct *foo);
+#
+#        [idl compiler error]
+#
+#
+#----------------------------------------------------
+#      void echo_TestRef([in] short **foo);
+#
+#      short v = 13;
+#      short *pv = &v;
+#
+#      echo_TestRef(&pv);
+#
+#      [PP PP PP PP 0D 00]
+#
+#
+#      short *pv = NULL;
+#
+#      echo_TestRef(&pv);
+#
+#      [00 00 00 00]
+#
+#
+#      echo_TestRef(NULL);
+#      
+#      [client runtime error 0x6f4]
+#
+#
+#----------------------------------------------------
+#      void echo_TestRef([in,ref] short **foo);
+#
+#      short v = 13;
+#      short *pv = &v;
+#
+#      echo_TestRef(&pv);
+#
+#      [PP PP PP PP 0D 00]
+#
+#
+#      short *pv = NULL;
+#
+#      echo_TestRef(&pv);
+#
+#      [00 00 00 00]
+#
+#
+#      echo_TestRef(NULL);
+#      
+#      [client runtime error 0x6f4]