1#!/usr/bin/perl 2# String tests for pidl 3# (C) 2005 Jelmer Vernooij <jelmer@samba.org> 4# Published under the GNU General Public License 5use strict; 6 7use Test::More tests => 6 * 8; 8use FindBin qw($RealBin); 9use lib "$RealBin"; 10use Util qw(test_samba4_ndr); 11 12test_samba4_ndr("string-pull-empty", 13' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);', 14' 15 uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 }; 16 DATA_BLOB b = { data, 4 }; 17 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); 18 struct TestString r; 19 r.in.data = NULL; 20 21 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r))) 22 return 1; 23 24 if (r.in.data == NULL) 25 return 2; 26 27 if (r.in.data[0] != 0) 28 return 3; 29'); 30 31test_samba4_ndr("string-ascii-pull", 32' 33 [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data); 34', 35' 36 uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, 37 \'f\', \'o\', \'o\', 0 }; 38 DATA_BLOB b = { data, 8 }; 39 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); 40 struct TestString r; 41 r.in.data = NULL; 42 43 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r))) 44 return 1; 45 46 if (r.in.data == NULL) 47 return 2; 48 49 if (strncmp(r.in.data, "foo", 3) != 0) 50 return 3; 51 52 if (r.in.data[4] != 0) 53 return 4; 54'); 55 56test_samba4_ndr("string-wchar-fixed-array-01", 57' 58 typedef struct { 59 uint32 l1; 60 [string,charset(UTF16)] uint16 str[6]; 61 uint32 l2; 62 } TestStringStruct; 63 64 [public] void TestString([in,ref] TestStringStruct *str); 65', 66' 67 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00, 68 0x00, 0x00, 0x00, 0x00, 69 0x04, 0x00, 0x00, 0x00, 70 \'f\', 0x00, \'o\', 0x00, 71 \'o\', 0x00, 0x00, 0x00, 72 0x02, 0x00, 0x00, 0x00 73 }; 74 DATA_BLOB b = { data, sizeof(data) }; 75 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); 76 struct TestString r; 77 struct TestStringStruct str; 78 r.in.str = &str; 79 80 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r))) 81 return 1; 82 83 if (r.in.str == NULL) 84 return 2; 85 86 if (r.in.str->l1 != 0x00000001) 87 return 3; 88 89 if (strncmp(str.str, "foo", 3) != 0) 90 return 4; 91 92 if (r.in.str->str[4] != 0) 93 return 5; 94 95 if (r.in.str->l2 != 0x00000002) 96 return 6; 97'); 98 99test_samba4_ndr("string-wchar-fixed-array-02", 100' 101 typedef struct { 102 uint32 l1; 103 [string,charset(UTF16)] uint16 str[6]; 104 uint32 l2; 105 } TestStringStruct; 106 107 [public] void TestString([in,ref] TestStringStruct *str); 108', 109' 110 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00, 111 0x00, 0x00, 0x00, 0x00, 112 0x06, 0x00, 0x00, 0x00, 113 \'f\', 0x00, \'o\', 0x00, 114 \'o\', 0x00, \'b\', 0x00, 115 \'a\', 0x00, \'r\', 0x00, 116 0x00, 0x00, 0x00, 0x00, 117 0x02, 0x00, 0x00, 0x00 118 }; 119 DATA_BLOB b = { data, sizeof(data) }; 120 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); 121 struct TestString r; 122 struct TestStringStruct str; 123 r.in.str = &str; 124 125 /* the string terminator is wrong */ 126 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r))) 127 return 1; 128'); 129 130test_samba4_ndr("string-wchar-fixed-array-03", 131' 132 typedef struct { 133 uint32 l1; 134 [string,charset(UTF16)] uint16 str[6]; 135 uint32 l2; 136 } TestStringStruct; 137 138 [public] void TestString([in,ref] TestStringStruct *str); 139', 140' 141 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00, 142 0x00, 0x00, 0x00, 0x00, 143 0x07, 0x00, 0x00, 0x00, 144 \'f\', 0x00, \'o\', 0x00, 145 \'o\', 0x00, \'b\', 0x00, 146 \'a\', 0x00, \'r\', 0x00, 147 0x00, 0x00, 0x00, 0x00, 148 0x02, 0x00, 0x00, 0x00 149 }; 150 DATA_BLOB b = { data, sizeof(data) }; 151 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); 152 struct TestString r; 153 struct TestStringStruct str; 154 r.in.str = &str; 155 156 /* the length 0x07 is to large */ 157 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r))) 158 return 1; 159'); 160 161SKIP: { 162 skip "doesn't seem to work yet", 8; 163 164test_samba4_ndr("string-out", 165' 166 [public] void TestString([out,string,charset(UNIX)] uint8 **data); 167', 168' 169 uint8_t data[] = { 0x03, 0x00, 0x00, 0x00, 170 \'f\', \'o\', \'o\', 0 }; 171 DATA_BLOB b = { data, 8 }; 172 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL); 173 struct TestString r; 174 char *str = NULL; 175 r.out.data = &str; 176 177 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r))) 178 return 1; 179 180 if (r.out.data == NULL) 181 return 2; 182 183 if (*r.out.data == NULL) 184 return 3; 185 186 if (strncmp(r.out.data, "foo", 3) != 0) 187 return 4; 188 189 if (r.out.data[4] != 0) 190 return 5; 191'); 192} 193