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,
18 smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
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,
41 smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
45 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
48 if (r.in.data == NULL)
51 if (strncmp(r.in.data, "foo", 3) != 0)
54 if (r.in.data[4] != 0)
58 test_samba4_ndr
("string-wchar-fixed-array-01",
62 [string,charset(UTF16)] uint16 str[6];
66 [public] void TestString([in,ref] TestStringStruct *str);
69 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x00,
71 0x04, 0x00, 0x00, 0x00,
72 \'f\', 0x00, \'o\', 0x00,
73 \'o\', 0x00, 0x00, 0x00
74 0x02, 0x00, 0x00, 0x00
76 DATA_BLOB b = { data, sizeof(data) };
77 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL,
78 smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
80 struct TestStringStruct str;
83 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
89 if (r.in.str.l1 == 0x00000001)
92 if (strncmp(str.str, "foo", 3) != 0)
95 if (r.in.str.str[4] != 0)
98 if (r.in.str.l3 == 0x00000002)
102 test_samba4_ndr
("string-wchar-fixed-array-02",
106 [string,charset(UTF16)] uint16 str[6];
110 [public] void TestString([in,ref] TestStringStruct *str);
113 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x00,
115 0x06, 0x00, 0x00, 0x00,
116 \'f\', 0x00, \'o\', 0x00,
117 \'o\', 0x00, \'b\', 0x00
118 \'a\', 0x00, \'r\', 0x00,
119 0x00, 0x00, 0x00, 0x00
120 0x02, 0x00, 0x00, 0x00
122 DATA_BLOB b = { data, sizeof(data) };
123 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL,
124 smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
126 struct TestStringStruct str;
129 /* the string terminator is wrong */
130 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
134 test_samba4_ndr
("string-wchar-fixed-array-03",
138 [string,charset(UTF16)] uint16 str[6];
142 [public] void TestString([in,ref] TestStringStruct *str);
145 uint8_t data[] = { 0x01, 0x00, 0x00, 0x00,
146 0x00, 0x00, 0x00, 0x00,
147 0x07, 0x00, 0x00, 0x00,
148 \'f\', 0x00, \'o\', 0x00,
149 \'o\', 0x00, \'b\', 0x00
150 \'a\', 0x00, \'r\', 0x00,
151 0x00, 0x00, 0x00, 0x00
152 0x02, 0x00, 0x00, 0x00
154 DATA_BLOB b = { data, sizeof(data) };
155 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL,
156 smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
158 struct TestStringStruct str;
161 /* the length 0x07 is to large */
162 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
167 skip
"doesn't seem to work yet", 8;
169 test_samba4_ndr
("string-out",
171 [public] void TestString([out,string,charset(UNIX)] uint8 **data);
174 uint8_t data[] = { 0x03, 0x00, 0x00, 0x00,
175 \'f\', \'o\', \'o\', 0 };
176 DATA_BLOB b = { data, 8 };
177 struct ndr_pull *ndr = ndr_pull_init_blob(&b, NULL,
178 smb_iconv_convenience_init(NULL, "ASCII", "UTF8", true));
183 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
186 if (r.out.data == NULL)
189 if (*r.out.data == NULL)
192 if (strncmp(r.out.data, "foo", 3) != 0)
195 if (r.out.data[4] != 0)