| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  | # NDR allocation tests | 
| 3 |  |  |  |  |  |  | # (C) 2005 Jelmer Vernooij. Published under the GNU GPL | 
| 4 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 48 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 1210 | use Test::More tests => 5 * 8; | 
|  | 1 |  |  |  |  | 27544 |  | 
|  | 1 |  |  |  |  | 11 |  | 
| 7 | 1 |  |  | 1 |  | 1859 | use FindBin qw($RealBin); | 
|  | 1 |  |  |  |  | 1063 |  | 
|  | 1 |  |  |  |  | 116 |  | 
| 8 | 1 |  |  | 1 |  | 1602 | use lib "$RealBin/../lib"; | 
|  | 1 |  |  |  |  | 1052 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 9 | 1 |  |  | 1 |  | 135 | use lib "$RealBin"; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 10 | 1 |  |  | 1 |  | 656 | use Util qw(test_samba4_ndr); | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # Check that an outgoing scalar pointer is allocated correctly | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | test_samba4_ndr("alloc-scalar", | 
| 15 |  |  |  |  |  |  | ' | 
| 16 |  |  |  |  |  |  | typedef struct { | 
| 17 |  |  |  |  |  |  | uint8 *x; | 
| 18 |  |  |  |  |  |  | } bla; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | [public] void TestAlloc([in] bla foo); | 
| 21 |  |  |  |  |  |  | ',' | 
| 22 |  |  |  |  |  |  | uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 }; | 
| 23 |  |  |  |  |  |  | DATA_BLOB b = { data, 5 }; | 
| 24 |  |  |  |  |  |  | struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); | 
| 25 |  |  |  |  |  |  | struct TestAlloc r; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) | 
| 28 |  |  |  |  |  |  | return 1; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | if (r.in.foo.x == NULL) | 
| 31 |  |  |  |  |  |  | return 2; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | if (*r.in.foo.x != 0x03) | 
| 34 |  |  |  |  |  |  | return 3; | 
| 35 |  |  |  |  |  |  | ' | 
| 36 |  |  |  |  |  |  | ); | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | # Check that an outgoing buffer pointer is allocated correctly | 
| 39 |  |  |  |  |  |  | test_samba4_ndr("alloc-buffer", | 
| 40 |  |  |  |  |  |  | ' | 
| 41 |  |  |  |  |  |  | typedef struct { uint8 data; } blie; | 
| 42 |  |  |  |  |  |  | typedef struct { blie *x; } bla; | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | [public] void TestAlloc([in] bla foo); | 
| 45 |  |  |  |  |  |  | ',' | 
| 46 |  |  |  |  |  |  | uint8_t data[] = { 0xde, 0xad, 0xbe, 0xef, 0x03 }; | 
| 47 |  |  |  |  |  |  | DATA_BLOB b = { data, 5 }; | 
| 48 |  |  |  |  |  |  | struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); | 
| 49 |  |  |  |  |  |  | struct TestAlloc r; | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) | 
| 52 |  |  |  |  |  |  | return 1; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | if (r.in.foo.x == NULL) | 
| 55 |  |  |  |  |  |  | return 2; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | if (r.in.foo.x->data != 0x03) | 
| 58 |  |  |  |  |  |  | return 3; | 
| 59 |  |  |  |  |  |  | ' | 
| 60 |  |  |  |  |  |  | ); | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | # Check that ref pointers aren't allocated by default | 
| 63 |  |  |  |  |  |  | test_samba4_ndr("ref-noalloc-null", | 
| 64 |  |  |  |  |  |  | ' | 
| 65 |  |  |  |  |  |  | [public] void TestAlloc([in,ref] uint8 *t); | 
| 66 |  |  |  |  |  |  | ',' | 
| 67 |  |  |  |  |  |  | uint8_t data[] = { 0x03 }; | 
| 68 |  |  |  |  |  |  | DATA_BLOB b = { data, 1 }; | 
| 69 |  |  |  |  |  |  | struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); | 
| 70 |  |  |  |  |  |  | struct TestAlloc r; | 
| 71 |  |  |  |  |  |  | r.in.t = NULL; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | if (NT_STATUS_IS_OK(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) | 
| 74 |  |  |  |  |  |  | return 1; | 
| 75 |  |  |  |  |  |  | ' | 
| 76 |  |  |  |  |  |  | ); | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | # Check that ref pointers aren't allocated by default | 
| 79 |  |  |  |  |  |  | test_samba4_ndr("ref-noalloc", | 
| 80 |  |  |  |  |  |  | ' | 
| 81 |  |  |  |  |  |  | [public] void TestAlloc([in,ref] uint8 *t); | 
| 82 |  |  |  |  |  |  | ',' | 
| 83 |  |  |  |  |  |  | uint8_t data[] = { 0x03 }; | 
| 84 |  |  |  |  |  |  | DATA_BLOB b = { data, 1 }; | 
| 85 |  |  |  |  |  |  | struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); | 
| 86 |  |  |  |  |  |  | struct TestAlloc r; | 
| 87 |  |  |  |  |  |  | uint8_t x; | 
| 88 |  |  |  |  |  |  | r.in.t = &x; | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) | 
| 91 |  |  |  |  |  |  | return 1; | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | if (*r.in.t != 0x03) | 
| 94 |  |  |  |  |  |  | return 2; | 
| 95 |  |  |  |  |  |  | ' | 
| 96 |  |  |  |  |  |  | ); | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | # Check that an outgoing ref pointer is allocated correctly | 
| 99 |  |  |  |  |  |  | test_samba4_ndr("ref-alloc", | 
| 100 |  |  |  |  |  |  | ' | 
| 101 |  |  |  |  |  |  | [public] void TestAlloc([in,ref] uint8 *t); | 
| 102 |  |  |  |  |  |  | ',' | 
| 103 |  |  |  |  |  |  | uint8_t data[] = { 0x03 }; | 
| 104 |  |  |  |  |  |  | DATA_BLOB b = { data, 1 }; | 
| 105 |  |  |  |  |  |  | struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); | 
| 106 |  |  |  |  |  |  | struct TestAlloc r; | 
| 107 |  |  |  |  |  |  | ndr->flags |= LIBNDR_FLAG_REF_ALLOC; | 
| 108 |  |  |  |  |  |  | r.in.t = NULL; | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | if (NT_STATUS_IS_ERR(ndr_pull_TestAlloc(ndr, NDR_IN, &r))) | 
| 111 |  |  |  |  |  |  | return 1; | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | if (r.in.t == NULL) | 
| 114 |  |  |  |  |  |  | return 2; | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | if (*r.in.t != 0x03) | 
| 117 |  |  |  |  |  |  | return 3; | 
| 118 |  |  |  |  |  |  | ' | 
| 119 |  |  |  |  |  |  | ); |