s3:lib/events: make use of samba_tevent_set_debug()
[Samba/gebeck_regimport.git] / pidl / tests / ndr_string.pl
blob8e8b8ecbad6c46f4ff428549b67381f60f1dd307
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 struct TestString r;
19 r.in.data = NULL;
21 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
22 return 1;
24 if (r.in.data == NULL)
25 return 2;
27 if (r.in.data[0] != 0)
28 return 3;
29 ');
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);
40 struct TestString r;
41 r.in.data = NULL;
43 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
44 return 1;
46 if (r.in.data == NULL)
47 return 2;
49 if (strncmp(r.in.data, "foo", 3) != 0)
50 return 3;
52 if (r.in.data[4] != 0)
53 return 4;
54 ');
56 test_samba4_ndr("string-wchar-fixed-array-01",
58 typedef struct {
59 uint32 l1;
60 [string,charset(UTF16)] uint16 str[6];
61 uint32 l2;
62 } TestStringStruct;
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);
76 struct TestString r;
77 struct TestStringStruct str;
78 r.in.str = &str;
80 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
81 return 1;
83 if (r.in.str == NULL)
84 return 2;
86 if (r.in.str->l1 != 0x00000001)
87 return 3;
89 if (strncmp(str.str, "foo", 3) != 0)
90 return 4;
92 if (r.in.str->str[4] != 0)
93 return 5;
95 if (r.in.str->l2 != 0x00000002)
96 return 6;
97 ');
99 test_samba4_ndr("string-wchar-fixed-array-02",
101 typedef struct {
102 uint32 l1;
103 [string,charset(UTF16)] uint16 str[6];
104 uint32 l2;
105 } TestStringStruct;
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);
121 struct TestString r;
122 struct TestStringStruct str;
123 r.in.str = &str;
125 /* the string terminator is wrong */
126 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
127 return 1;
130 test_samba4_ndr("string-wchar-fixed-array-03",
132 typedef struct {
133 uint32 l1;
134 [string,charset(UTF16)] uint16 str[6];
135 uint32 l2;
136 } TestStringStruct;
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);
152 struct TestString r;
153 struct TestStringStruct str;
154 r.in.str = &str;
156 /* the length 0x07 is to large */
157 if (NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
158 return 1;
161 SKIP: {
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);
173 struct TestString r;
174 char *str = NULL;
175 r.out.data = &str;
177 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_pull_TestString(ndr, NDR_IN, &r)))
178 return 1;
180 if (r.out.data == NULL)
181 return 2;
183 if (*r.out.data == NULL)
184 return 3;
186 if (strncmp(r.out.data, "foo", 3) != 0)
187 return 4;
189 if (r.out.data[4] != 0)
190 return 5;