Ensure get_nt_acl_internal() only looks at the ACL blobs, not
[Samba/fernandojvsilva.git] / pidl / tests / ndr_string.pl
blob7b76c7b29508fae1db12aab32939ade7b1e92d15
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
5 use strict;
7 use Test::More tests => 6 * 8;
8 use FindBin qw($RealBin);
9 use lib "$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));
19 struct TestString r;
20 r.in.data = NULL;
22 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
23 return 1;
25 if (r.in.data == NULL)
26 return 2;
28 if (r.in.data[0] != 0)
29 return 3;
30 ');
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));
42 struct TestString r;
43 r.in.data = NULL;
45 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
46 return 1;
48 if (r.in.data == NULL)
49 return 2;
51 if (strncmp(r.in.data, "foo", 3) != 0)
52 return 3;
54 if (r.in.data[4] != 0)
55 return 4;
56 ');
58 test_samba4_ndr("string-wchar-fixed-array-01",
60 typedef struct {
61 uint32 l1;
62 [string,charset(UTF16)] uint16 str[6];
63 uint32 l2;
64 } TestStringStruct;
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));
79 struct TestString r;
80 struct TestStringStruct str;
81 r.in.str = &str;
83 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
84 return 1;
86 if (r.in.str == NULL)
87 return 2;
89 if (r.in.str->l1 != 0x00000001)
90 return 3;
92 if (strncmp(str.str, "foo", 3) != 0)
93 return 4;
95 if (r.in.str->str[4] != 0)
96 return 5;
98 if (r.in.str->l2 != 0x00000002)
99 return 6;
102 test_samba4_ndr("string-wchar-fixed-array-02",
104 typedef struct {
105 uint32 l1;
106 [string,charset(UTF16)] uint16 str[6];
107 uint32 l2;
108 } TestStringStruct;
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));
125 struct TestString r;
126 struct TestStringStruct str;
127 r.in.str = &str;
129 /* the string terminator is wrong */
130 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
131 return 1;
134 test_samba4_ndr("string-wchar-fixed-array-03",
136 typedef struct {
137 uint32 l1;
138 [string,charset(UTF16)] uint16 str[6];
139 uint32 l2;
140 } TestStringStruct;
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));
157 struct TestString r;
158 struct TestStringStruct str;
159 r.in.str = &str;
161 /* the length 0x07 is to large */
162 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
163 return 1;
166 SKIP: {
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));
179 struct TestString r;
180 char *str = NULL;
181 r.out.data = &str;
183 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
184 return 1;
186 if (r.out.data == NULL)
187 return 2;
189 if (*r.out.data == NULL)
190 return 3;
192 if (strncmp(r.out.data, "foo", 3) != 0)
193 return 4;
195 if (r.out.data[4] != 0)
196 return 5;