2 # String tests for pidl
3 # (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU General Public License
8 use Test
::More tests
=> 6 * 8;
9 use FindBin
qw($RealBin);
11 use Util qw(test_samba4_ndr);
13 test_samba4_ndr
("string-pull-empty",
14 ' [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);',
16 uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 };
17 DATA_BLOB b = { data, 4 };
18 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
22 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
25 if (r.in.data == NULL)
28 if (r.in.data[0] != 0)
32 test_samba4_ndr
("string-ascii-pull",
34 [public] void TestString([in,flag(STR_ASCII|LIBNDR_FLAG_STR_SIZE4)] string data);
37 uint8_t data[] = { 0x03, 0x00, 0x00, 0x00,
38 \'f\', \'o\', \'o\', 0 };
39 DATA_BLOB b = { data, 8 };
40 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
44 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
47 if (r.in.data == NULL)
50 if (strncmp(r.in.data, "foo", 3) != 0)
53 if (r.in.data[4] != 0)
57 test_samba4_ndr
("string-wchar-fixed-array-01",
61 [string,charset(UTF16)] uint16 str[6];
65 [public] void TestString([in,ref] TestStringStruct *str);
68 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00,
70 0x04, 0x00, 0x00, 0x00,
71 \'f\', 0x00, \'o\', 0x00,
72 \'o\', 0x00, 0x00, 0x00,
73 0x02, 0x00, 0x00, 0x00
75 DATA_BLOB b = { data, sizeof(data) };
76 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
78 struct TestStringStruct str;
81 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
87 if (r.in.str->l1 != 0x00000001)
90 if (strncmp(str.str, "foo", 3) != 0)
93 if (r.in.str->str[4] != 0)
96 if (r.in.str->l2 != 0x00000002)
100 test_samba4_ndr
("string-wchar-fixed-array-02",
104 [string,charset(UTF16)] uint16 str[6];
108 [public] void TestString([in,ref] TestStringStruct *str);
111 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x00,
113 0x06, 0x00, 0x00, 0x00,
114 \'f\', 0x00, \'o\', 0x00,
115 \'o\', 0x00, \'b\', 0x00,
116 \'a\', 0x00, \'r\', 0x00,
117 0x00, 0x00, 0x00, 0x00,
118 0x02, 0x00, 0x00, 0x00
120 DATA_BLOB b = { data, sizeof(data) };
121 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
123 struct TestStringStruct str;
126 /* the string terminator is wrong */
127 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
131 test_samba4_ndr
("string-wchar-fixed-array-03",
135 [string,charset(UTF16)] uint16 str[6];
139 [public] void TestString([in,ref] TestStringStruct *str);
142 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00,
143 0x00, 0x00, 0x00, 0x00,
144 0x07, 0x00, 0x00, 0x00,
145 \'f\', 0x00, \'o\', 0x00,
146 \'o\', 0x00, \'b\', 0x00,
147 \'a\', 0x00, \'r\', 0x00,
148 0x00, 0x00, 0x00, 0x00,
149 0x02, 0x00, 0x00, 0x00
151 DATA_BLOB b = { data, sizeof(data) };
152 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
154 struct TestStringStruct str;
157 /* the length 0x07 is to large */
158 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
163 skip
"doesn't seem to work yet", 8;
165 test_samba4_ndr
("string-out",
167 [public] void TestString([out,string,charset(UNIX)] uint8 **data);
170 uint8_t data[] = { 0x03, 0x00, 0x00, 0x00,
171 \'f\', \'o\', \'o\', 0 };
172 DATA_BLOB b = { data, 8 };
173 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL);
178 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
181 if (r.out.data == NULL)
184 if (*r.out.data == NULL)
187 if (strncmp(r.out.data, "foo", 3) != 0)
190 if (r.out.data[4] != 0)