2 # String tests for pidl
3 # (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU General Public License
7 use Test
::More tests
=> 6 * 8;
8 use FindBin
qw($RealBin);
10 use Util qw(test_samba4_ndr);
12 test_samba4_ndr
("string-pull-empty",
13 ' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);',
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);
21 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
24 if (r.in.data == NULL)
27 if (r.in.data[0] != 0)
31 test_samba4_ndr
("string-ascii-pull",
33 [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);
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);
43 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
46 if (r.in.data == NULL)
49 if (strncmp(r.in.data, "foo", 3) != 0)
52 if (r.in.data[4] != 0)
56 test_samba4_ndr
("string-wchar-fixed-array-01",
60 [string,charset(UTF16)] uint16 str[6];
64 [public] void TestString([in,ref] TestStringStruct *str);
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
74 DATA_BLOB b = { data, sizeof(data) };
75 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
77 struct TestStringStruct str;
80 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
86 if (r.in.str->l1 != 0x00000001)
89 if (strncmp(str.str, "foo", 3) != 0)
92 if (r.in.str->str[4] != 0)
95 if (r.in.str->l2 != 0x00000002)
99 test_samba4_ndr
("string-wchar-fixed-array-02",
103 [string,charset(UTF16)] uint16 str[6];
107 [public] void TestString([in,ref] TestStringStruct *str);
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
119 DATA_BLOB b = { data, sizeof(data) };
120 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
122 struct TestStringStruct str;
125 /* the string terminator is wrong */
126 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
130 test_samba4_ndr
("string-wchar-fixed-array-03",
134 [string,charset(UTF16)] uint16 str[6];
138 [public] void TestString([in,ref] TestStringStruct *str);
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
150 DATA_BLOB b = { data, sizeof(data) };
151 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
153 struct TestStringStruct str;
156 /* the length 0x07 is to large */
157 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
162 skip
"doesn't seem to work yet", 8;
164 test_samba4_ndr
("string-out",
166 [public] void TestString([out,string,charset(UNIX)] uint8 **data);
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);
177 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
180 if (r.out.data == NULL)
183 if (*r.out.data == NULL)
186 if (strncmp(r.out.data, "foo", 3) != 0)
189 if (r.out.data[4] != 0)