| 1 | #!/usr/bin/perl
|
|---|
| 2 | # NDR alignment tests
|
|---|
| 3 | # (C) 2005 Jelmer Vernooij. Published under the GNU GPL
|
|---|
| 4 | use strict;
|
|---|
| 5 |
|
|---|
| 6 | use Test::More tests => 5 * 8;
|
|---|
| 7 | use FindBin qw($RealBin);
|
|---|
| 8 | use lib "$RealBin";
|
|---|
| 9 | use Util qw(test_samba4_ndr);
|
|---|
| 10 |
|
|---|
| 11 | test_samba4_ndr('align-uint8-uint16',
|
|---|
| 12 | '
|
|---|
| 13 | typedef [public] struct {
|
|---|
| 14 | uint8 x;
|
|---|
| 15 | uint16 y;
|
|---|
| 16 | } bla;
|
|---|
| 17 | ',
|
|---|
| 18 | '
|
|---|
| 19 | struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
|
|---|
| 20 | struct bla r;
|
|---|
| 21 | uint8_t expected[] = { 0x0D, 0x00, 0xef, 0xbe };
|
|---|
| 22 | DATA_BLOB expected_blob = { expected, 4 };
|
|---|
| 23 | DATA_BLOB result_blob;
|
|---|
| 24 | r.x = 13;
|
|---|
| 25 | r.y = 0xbeef;
|
|---|
| 26 |
|
|---|
| 27 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
|
|---|
| 28 | return 1;
|
|---|
| 29 |
|
|---|
| 30 | result_blob = ndr_push_blob(ndr);
|
|---|
| 31 |
|
|---|
| 32 | if (data_blob_cmp(&result_blob, &expected_blob) != 0)
|
|---|
| 33 | return 2;
|
|---|
| 34 | ');
|
|---|
| 35 |
|
|---|
| 36 | test_samba4_ndr('align-uint8-uint32',
|
|---|
| 37 | '
|
|---|
| 38 | typedef [public] struct {
|
|---|
| 39 | uint8 x;
|
|---|
| 40 | uint32 y;
|
|---|
| 41 | } bla;
|
|---|
| 42 | ',
|
|---|
| 43 | '
|
|---|
| 44 | struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
|
|---|
| 45 | struct bla r;
|
|---|
| 46 | uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xef, 0xbe };
|
|---|
| 47 | DATA_BLOB expected_blob = { expected, 8 };
|
|---|
| 48 | DATA_BLOB result_blob;
|
|---|
| 49 | r.x = 13;
|
|---|
| 50 | r.y = 0xbeefbeef;
|
|---|
| 51 |
|
|---|
| 52 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
|
|---|
| 53 | return 1;
|
|---|
| 54 |
|
|---|
| 55 | result_blob = ndr_push_blob(ndr);
|
|---|
| 56 |
|
|---|
| 57 | if (data_blob_cmp(&result_blob, &expected_blob) != 0)
|
|---|
| 58 | return 2;
|
|---|
| 59 | ');
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | test_samba4_ndr('align-uint8-hyper',
|
|---|
| 63 | '
|
|---|
| 64 | typedef [public] struct {
|
|---|
| 65 | uint8 x;
|
|---|
| 66 | hyper y;
|
|---|
| 67 | } bla;
|
|---|
| 68 | ',
|
|---|
| 69 | '
|
|---|
| 70 | struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
|
|---|
| 71 | struct bla r;
|
|---|
| 72 | uint8_t expected[] = { 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|---|
| 73 | 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe };
|
|---|
| 74 | DATA_BLOB expected_blob = { expected, 16 };
|
|---|
| 75 | DATA_BLOB result_blob;
|
|---|
| 76 | r.x = 13;
|
|---|
| 77 | r.y = 0xbeefbeefbeefbeefLLU;
|
|---|
| 78 |
|
|---|
| 79 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
|
|---|
| 80 | return 1;
|
|---|
| 81 |
|
|---|
| 82 | result_blob = ndr_push_blob(ndr);
|
|---|
| 83 |
|
|---|
| 84 | if (data_blob_cmp(&result_blob, &expected_blob) != 0)
|
|---|
| 85 | return 2;
|
|---|
| 86 | ');
|
|---|
| 87 |
|
|---|
| 88 | test_samba4_ndr('noalignflag-uint8-uint16',
|
|---|
| 89 | '
|
|---|
| 90 | typedef [public] struct {
|
|---|
| 91 | uint8 x;
|
|---|
| 92 | uint16 y;
|
|---|
| 93 | } bla;
|
|---|
| 94 | ',
|
|---|
| 95 | '
|
|---|
| 96 | struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
|
|---|
| 97 | struct bla r;
|
|---|
| 98 | uint8_t expected[] = { 0x0D, 0xef, 0xbe };
|
|---|
| 99 | DATA_BLOB expected_blob = { expected, 3 };
|
|---|
| 100 | DATA_BLOB result_blob;
|
|---|
| 101 | ndr->flags |= LIBNDR_FLAG_NOALIGN;
|
|---|
| 102 |
|
|---|
| 103 | r.x = 13;
|
|---|
| 104 | r.y = 0xbeef;
|
|---|
| 105 |
|
|---|
| 106 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
|
|---|
| 107 | return 1;
|
|---|
| 108 |
|
|---|
| 109 | result_blob = ndr_push_blob(ndr);
|
|---|
| 110 |
|
|---|
| 111 | if (data_blob_cmp(&result_blob, &expected_blob) != 0)
|
|---|
| 112 | return 2;
|
|---|
| 113 | ');
|
|---|
| 114 |
|
|---|
| 115 | test_samba4_ndr('align-blob-align2',
|
|---|
| 116 | '
|
|---|
| 117 | typedef [public] struct {
|
|---|
| 118 | uint8 x;
|
|---|
| 119 | [flag(LIBNDR_FLAG_ALIGN2)] DATA_BLOB data;
|
|---|
| 120 | uint8 y;
|
|---|
| 121 | } blie;
|
|---|
| 122 | ',
|
|---|
| 123 | '
|
|---|
| 124 | struct ndr_push *ndr = ndr_push_init_ctx(NULL, NULL);
|
|---|
| 125 | struct blie r;
|
|---|
| 126 | uint8_t data[] = { 0x01, 0x02 };
|
|---|
| 127 | uint8_t expected[] = { 0x0D, 0x00, 0x0E };
|
|---|
| 128 | DATA_BLOB expected_blob = { expected, 3 };
|
|---|
| 129 | DATA_BLOB result_blob;
|
|---|
| 130 |
|
|---|
| 131 | r.x = 13;
|
|---|
| 132 | r.y = 14;
|
|---|
| 133 | r.data.data = data;
|
|---|
| 134 | r.data.length = 2;
|
|---|
| 135 |
|
|---|
| 136 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_blie(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
|
|---|
| 137 | return 1;
|
|---|
| 138 |
|
|---|
| 139 | result_blob = ndr_push_blob(ndr);
|
|---|
| 140 |
|
|---|
| 141 | if (data_blob_cmp(&result_blob, &expected_blob) != 0)
|
|---|
| 142 | return 2;
|
|---|
| 143 | ');
|
|---|