t_sdp_put.c revision 1.3 1 1.3 plunky /* $NetBSD: t_sdp_put.c,v 1.3 2011/04/16 07:32:27 plunky Exp $ */
2 1.1 plunky
3 1.1 plunky /*-
4 1.1 plunky * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 plunky * All rights reserved.
6 1.1 plunky *
7 1.1 plunky * This code is derived from software contributed to The NetBSD Foundation
8 1.1 plunky * by Iain Hibbert.
9 1.1 plunky *
10 1.1 plunky * Redistribution and use in source and binary forms, with or without
11 1.1 plunky * modification, are permitted provided that the following conditions
12 1.1 plunky * are met:
13 1.1 plunky * 1. Redistributions of source code must retain the above copyright
14 1.1 plunky * notice, this list of conditions and the following disclaimer.
15 1.1 plunky * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 plunky * notice, this list of conditions and the following disclaimer in the
17 1.1 plunky * documentation and/or other materials provided with the distribution.
18 1.1 plunky *
19 1.1 plunky * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 plunky * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 plunky * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 plunky * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 plunky * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 plunky * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 plunky * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 plunky * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 plunky * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 plunky * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 plunky * POSSIBILITY OF SUCH DAMAGE.
30 1.1 plunky */
31 1.1 plunky
32 1.1 plunky #include <atf-c.h>
33 1.1 plunky
34 1.1 plunky #include <limits.h>
35 1.1 plunky #include <sdp.h>
36 1.1 plunky #include <string.h>
37 1.1 plunky
38 1.1 plunky ATF_TC(check_sdp_put_data);
39 1.1 plunky
40 1.1 plunky ATF_TC_HEAD(check_sdp_put_data, tc)
41 1.1 plunky {
42 1.2 plunky
43 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_data results");
44 1.1 plunky }
45 1.2 plunky
46 1.1 plunky ATF_TC_BODY(check_sdp_put_data, tc)
47 1.1 plunky {
48 1.1 plunky uint8_t buf[256];
49 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
50 1.1 plunky uint8_t data[] = {
51 1.1 plunky 0x35, 0x05, // seq8(5)
52 1.1 plunky 0x08, 0x00, // uint8 0x00
53 1.1 plunky 0x09, 0x12, 0x34, // uint16 0x1234
54 1.1 plunky };
55 1.1 plunky sdp_data_t value = { data, data + sizeof(data) };
56 1.1 plunky
57 1.1 plunky ATF_REQUIRE(sdp_put_data(&test, &value));
58 1.1 plunky test.end = test.next;
59 1.1 plunky test.next = buf;
60 1.1 plunky
61 1.1 plunky const uint8_t expect[] = {
62 1.1 plunky 0x35, 0x05, // seq8(5)
63 1.1 plunky 0x08, 0x00, // uint8 0x00
64 1.1 plunky 0x09, 0x12, 0x34, // uint16 0x1234
65 1.1 plunky };
66 1.1 plunky
67 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
68 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
69 1.1 plunky }
70 1.1 plunky
71 1.1 plunky ATF_TC(check_sdp_put_attr);
72 1.1 plunky
73 1.1 plunky ATF_TC_HEAD(check_sdp_put_attr, tc)
74 1.1 plunky {
75 1.2 plunky
76 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_attr results");
77 1.1 plunky }
78 1.2 plunky
79 1.1 plunky ATF_TC_BODY(check_sdp_put_attr, tc)
80 1.1 plunky {
81 1.1 plunky uint8_t buf[256];
82 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
83 1.1 plunky uint8_t data[] = {
84 1.3 plunky 0x00, // nil
85 1.1 plunky 0x19, 0x33, 0x44, // uuid16 0x3344
86 1.1 plunky };
87 1.1 plunky sdp_data_t value = { data, data + sizeof(data) };
88 1.1 plunky
89 1.3 plunky ATF_REQUIRE_EQ(sdp_put_attr(&test, 0xabcd, &value), false);
90 1.3 plunky value.next += 1; // skip "nil"
91 1.1 plunky ATF_REQUIRE(sdp_put_attr(&test, 0x1337, &value));
92 1.1 plunky test.end = test.next;
93 1.1 plunky test.next = buf;
94 1.1 plunky
95 1.1 plunky const uint8_t expect[] = {
96 1.1 plunky 0x09, 0x13, 0x37, // uint16 0x1337
97 1.1 plunky 0x19, 0x33, 0x44, // uuid16 0x3344
98 1.1 plunky };
99 1.1 plunky
100 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
101 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
102 1.1 plunky }
103 1.1 plunky
104 1.1 plunky ATF_TC(check_sdp_put_uuid);
105 1.1 plunky
106 1.1 plunky ATF_TC_HEAD(check_sdp_put_uuid, tc)
107 1.1 plunky {
108 1.2 plunky
109 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid results");
110 1.1 plunky }
111 1.2 plunky
112 1.1 plunky ATF_TC_BODY(check_sdp_put_uuid, tc)
113 1.1 plunky {
114 1.1 plunky uint8_t buf[256];
115 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
116 1.1 plunky const uuid_t u16 = {
117 1.1 plunky 0x00001234,
118 1.1 plunky 0x0000,
119 1.1 plunky 0x1000,
120 1.1 plunky 0x80,
121 1.1 plunky 0x00,
122 1.1 plunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
123 1.1 plunky };
124 1.1 plunky const uuid_t u32 = {
125 1.1 plunky 0x12345678,
126 1.1 plunky 0x0000,
127 1.1 plunky 0x1000,
128 1.1 plunky 0x80,
129 1.1 plunky 0x00,
130 1.1 plunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
131 1.1 plunky };
132 1.1 plunky const uuid_t u128 = {
133 1.1 plunky 0x00112233,
134 1.1 plunky 0x4444,
135 1.1 plunky 0x5555,
136 1.1 plunky 0x66,
137 1.1 plunky 0x77,
138 1.1 plunky { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }
139 1.1 plunky };
140 1.1 plunky
141 1.1 plunky ATF_REQUIRE(sdp_put_uuid(&test, &u16));
142 1.1 plunky ATF_REQUIRE(sdp_put_uuid(&test, &u32));
143 1.1 plunky ATF_REQUIRE(sdp_put_uuid(&test, &u128));
144 1.1 plunky test.end = test.next;
145 1.1 plunky test.next = buf;
146 1.1 plunky
147 1.1 plunky const uint8_t expect[] = {
148 1.1 plunky 0x19, 0x12, 0x34, // uuid16 0x1234
149 1.1 plunky 0x1a, 0x12, 0x34, 0x56, // uuid32 0x12345678
150 1.1 plunky 0x78,
151 1.1 plunky 0x1c, 0x00, 0x11, 0x22, // uuid128 00112233-4444-5555-6677-8899aabbccdd
152 1.1 plunky 0x33, 0x44, 0x44, 0x55,
153 1.1 plunky 0x55, 0x66, 0x77, 0x88,
154 1.1 plunky 0x99, 0xaa, 0xbb, 0xcc,
155 1.1 plunky 0xdd,
156 1.1 plunky };
157 1.1 plunky
158 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
159 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
160 1.1 plunky }
161 1.1 plunky
162 1.1 plunky ATF_TC(check_sdp_put_uuid16);
163 1.1 plunky
164 1.1 plunky ATF_TC_HEAD(check_sdp_put_uuid16, tc)
165 1.1 plunky {
166 1.2 plunky
167 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid16 results");
168 1.1 plunky }
169 1.2 plunky
170 1.1 plunky ATF_TC_BODY(check_sdp_put_uuid16, tc)
171 1.1 plunky {
172 1.1 plunky uint8_t buf[256];
173 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
174 1.1 plunky
175 1.1 plunky ATF_REQUIRE(sdp_put_uuid16(&test, 0x4567));
176 1.1 plunky test.end = test.next;
177 1.1 plunky test.next = buf;
178 1.1 plunky
179 1.1 plunky const uint8_t expect[] = {
180 1.1 plunky 0x19, 0x45, 0x67, // uuid16 0x4567
181 1.1 plunky };
182 1.1 plunky
183 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
184 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
185 1.1 plunky }
186 1.1 plunky
187 1.1 plunky ATF_TC(check_sdp_put_uuid32);
188 1.1 plunky
189 1.1 plunky ATF_TC_HEAD(check_sdp_put_uuid32, tc)
190 1.1 plunky {
191 1.2 plunky
192 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid32 results");
193 1.1 plunky }
194 1.2 plunky
195 1.1 plunky ATF_TC_BODY(check_sdp_put_uuid32, tc)
196 1.1 plunky {
197 1.1 plunky uint8_t buf[256];
198 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
199 1.1 plunky
200 1.1 plunky ATF_REQUIRE(sdp_put_uuid32(&test, 0xabcdef00));
201 1.1 plunky test.end = test.next;
202 1.1 plunky test.next = buf;
203 1.1 plunky
204 1.1 plunky const uint8_t expect[] = {
205 1.1 plunky 0x1a, 0xab, 0xcd, 0xef, // uuid32 0xabcdef00
206 1.1 plunky 0x00,
207 1.1 plunky };
208 1.1 plunky
209 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
210 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
211 1.1 plunky }
212 1.1 plunky
213 1.1 plunky ATF_TC(check_sdp_put_uuid128);
214 1.1 plunky
215 1.1 plunky ATF_TC_HEAD(check_sdp_put_uuid128, tc)
216 1.1 plunky {
217 1.2 plunky
218 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid128 results");
219 1.1 plunky }
220 1.2 plunky
221 1.1 plunky ATF_TC_BODY(check_sdp_put_uuid128, tc)
222 1.1 plunky {
223 1.1 plunky uint8_t buf[256];
224 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
225 1.1 plunky uuid_t value = {
226 1.1 plunky 0x00000100,
227 1.1 plunky 0x0000,
228 1.1 plunky 0x1000,
229 1.1 plunky 0x80,
230 1.1 plunky 0x00,
231 1.1 plunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
232 1.1 plunky };
233 1.1 plunky
234 1.1 plunky ATF_REQUIRE(sdp_put_uuid128(&test, &value));
235 1.1 plunky test.end = test.next;
236 1.1 plunky test.next = buf;
237 1.1 plunky
238 1.1 plunky const uint8_t expect[] = {
239 1.1 plunky 0x1c, 0x00, 0x00, 0x01, // uuid128 0000100-0000-1000-8000-00805f9b34fb
240 1.1 plunky 0x00, 0x00, 0x00, 0x10, // (L2CAP protocol)
241 1.1 plunky 0x00, 0x80, 0x00, 0x00,
242 1.1 plunky 0x80, 0x5f, 0x9b, 0x34,
243 1.1 plunky 0xfb,
244 1.1 plunky };
245 1.1 plunky
246 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
247 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
248 1.1 plunky }
249 1.1 plunky
250 1.1 plunky ATF_TC(check_sdp_put_bool);
251 1.1 plunky
252 1.1 plunky ATF_TC_HEAD(check_sdp_put_bool, tc)
253 1.1 plunky {
254 1.2 plunky
255 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_bool results");
256 1.1 plunky }
257 1.2 plunky
258 1.1 plunky ATF_TC_BODY(check_sdp_put_bool, tc)
259 1.1 plunky {
260 1.1 plunky uint8_t buf[256];
261 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
262 1.1 plunky
263 1.1 plunky ATF_REQUIRE(sdp_put_bool(&test, true));
264 1.1 plunky ATF_REQUIRE(sdp_put_bool(&test, false));
265 1.1 plunky test.end = test.next;
266 1.1 plunky test.next = buf;
267 1.1 plunky
268 1.1 plunky const uint8_t expect[] = {
269 1.1 plunky 0x28, 0x01, // bool true
270 1.1 plunky 0x28, 0x00, // bool false
271 1.1 plunky };
272 1.1 plunky
273 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
274 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
275 1.1 plunky }
276 1.1 plunky
277 1.1 plunky ATF_TC(check_sdp_put_uint);
278 1.1 plunky
279 1.1 plunky ATF_TC_HEAD(check_sdp_put_uint, tc)
280 1.1 plunky {
281 1.2 plunky
282 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint results");
283 1.1 plunky }
284 1.2 plunky
285 1.1 plunky ATF_TC_BODY(check_sdp_put_uint, tc)
286 1.1 plunky {
287 1.1 plunky uint8_t buf[256];
288 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
289 1.1 plunky
290 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)0));
291 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT8_MAX));
292 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT8_MAX + 1));
293 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT16_MAX));
294 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT16_MAX + 1));
295 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT32_MAX));
296 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT32_MAX + 1));
297 1.1 plunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT64_MAX));
298 1.1 plunky test.end = test.next;
299 1.1 plunky test.next = buf;
300 1.1 plunky
301 1.1 plunky const uint8_t expect[] = {
302 1.1 plunky 0x08, 0x00, // uint8 0x00
303 1.1 plunky 0x08, 0xff, // uint8 0xff
304 1.1 plunky 0x09, 0x01, 0x00, // uint16 0x0100
305 1.1 plunky 0x09, 0xff, 0xff, // uint16 0xffff
306 1.1 plunky 0x0a, 0x00, 0x01, 0x00, // uint32 0x00010000
307 1.1 plunky 0x00,
308 1.1 plunky 0x0a, 0xff, 0xff, 0xff, // uint32 0xffffffff
309 1.1 plunky 0xff,
310 1.1 plunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x0000000100000000
311 1.1 plunky 0x01, 0x00, 0x00, 0x00,
312 1.1 plunky 0x00,
313 1.1 plunky 0x0b, 0xff, 0xff, 0xff, // uint64 0xffffffffffffffff
314 1.1 plunky 0xff, 0xff, 0xff, 0xff,
315 1.1 plunky 0xff,
316 1.1 plunky };
317 1.1 plunky
318 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
319 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
320 1.1 plunky }
321 1.1 plunky
322 1.1 plunky ATF_TC(check_sdp_put_uint8);
323 1.1 plunky
324 1.1 plunky ATF_TC_HEAD(check_sdp_put_uint8, tc)
325 1.1 plunky {
326 1.2 plunky
327 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint8 results");
328 1.1 plunky }
329 1.2 plunky
330 1.1 plunky ATF_TC_BODY(check_sdp_put_uint8, tc)
331 1.1 plunky {
332 1.1 plunky uint8_t buf[256];
333 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
334 1.1 plunky
335 1.1 plunky ATF_REQUIRE(sdp_put_uint8(&test, (uint8_t)0));
336 1.1 plunky ATF_REQUIRE(sdp_put_uint8(&test, (uint8_t)UINT8_MAX));
337 1.1 plunky test.end = test.next;
338 1.1 plunky test.next = buf;
339 1.1 plunky
340 1.1 plunky const uint8_t expect[] = {
341 1.1 plunky 0x08, 0x00, // uint8 0x00
342 1.1 plunky 0x08, 0xff, // uint8 0xff
343 1.1 plunky };
344 1.1 plunky
345 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
346 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
347 1.1 plunky }
348 1.1 plunky
349 1.1 plunky ATF_TC(check_sdp_put_uint16);
350 1.1 plunky
351 1.1 plunky ATF_TC_HEAD(check_sdp_put_uint16, tc)
352 1.1 plunky {
353 1.2 plunky
354 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint16 results");
355 1.1 plunky }
356 1.2 plunky
357 1.1 plunky ATF_TC_BODY(check_sdp_put_uint16, tc)
358 1.1 plunky {
359 1.1 plunky uint8_t buf[256];
360 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
361 1.1 plunky
362 1.1 plunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)0));
363 1.1 plunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)UINT8_MAX));
364 1.1 plunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)UINT16_MAX));
365 1.1 plunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)0xabcd));
366 1.1 plunky test.end = test.next;
367 1.1 plunky test.next = buf;
368 1.1 plunky
369 1.1 plunky const uint8_t expect[] = {
370 1.1 plunky 0x09, 0x00, 0x00, // uint16 0x0000
371 1.1 plunky 0x09, 0x00, 0xff, // uint16 0x00ff
372 1.1 plunky 0x09, 0xff, 0xff, // uint16 0xffff
373 1.1 plunky 0x09, 0xab, 0xcd, // uint16 0xabcd
374 1.1 plunky };
375 1.1 plunky
376 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
377 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
378 1.1 plunky }
379 1.1 plunky
380 1.1 plunky ATF_TC(check_sdp_put_uint32);
381 1.1 plunky
382 1.1 plunky ATF_TC_HEAD(check_sdp_put_uint32, tc)
383 1.1 plunky {
384 1.2 plunky
385 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint32 results");
386 1.1 plunky }
387 1.2 plunky
388 1.1 plunky ATF_TC_BODY(check_sdp_put_uint32, tc)
389 1.1 plunky {
390 1.1 plunky uint8_t buf[256];
391 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
392 1.1 plunky
393 1.1 plunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)0));
394 1.1 plunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT8_MAX));
395 1.1 plunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT16_MAX));
396 1.1 plunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT32_MAX));
397 1.1 plunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)0xdeadbeef));
398 1.1 plunky test.end = test.next;
399 1.1 plunky test.next = buf;
400 1.1 plunky
401 1.1 plunky const uint8_t expect[] = {
402 1.1 plunky 0x0a, 0x00, 0x00, 0x00, // uint32 0x00000000
403 1.1 plunky 0x00,
404 1.1 plunky 0x0a, 0x00, 0x00, 0x00, // uint32 0x000000ff
405 1.1 plunky 0xff,
406 1.1 plunky 0x0a, 0x00, 0x00, 0xff, // uint32 0x0000ffff
407 1.1 plunky 0xff,
408 1.1 plunky 0x0a, 0xff, 0xff, 0xff, // uint32 0xffffffff
409 1.1 plunky 0xff,
410 1.1 plunky 0x0a, 0xde, 0xad, 0xbe, // uint32 0xdeadbeef
411 1.1 plunky 0xef,
412 1.1 plunky };
413 1.1 plunky
414 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
415 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
416 1.1 plunky }
417 1.1 plunky
418 1.1 plunky ATF_TC(check_sdp_put_uint64);
419 1.1 plunky
420 1.1 plunky ATF_TC_HEAD(check_sdp_put_uint64, tc)
421 1.1 plunky {
422 1.2 plunky
423 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint64 results");
424 1.1 plunky }
425 1.2 plunky
426 1.1 plunky ATF_TC_BODY(check_sdp_put_uint64, tc)
427 1.1 plunky {
428 1.1 plunky uint8_t buf[256];
429 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
430 1.1 plunky
431 1.1 plunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)0));
432 1.1 plunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT8_MAX));
433 1.1 plunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT16_MAX));
434 1.1 plunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT32_MAX));
435 1.1 plunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT64_MAX));
436 1.1 plunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)0xc0ffeecafec0ffee));
437 1.1 plunky test.end = test.next;
438 1.1 plunky test.next = buf;
439 1.1 plunky
440 1.1 plunky const uint8_t expect[] = {
441 1.1 plunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x0000000000000000
442 1.1 plunky 0x00, 0x00, 0x00, 0x00,
443 1.1 plunky 0x00,
444 1.1 plunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x00000000000000ff
445 1.1 plunky 0x00, 0x00, 0x00, 0x00,
446 1.1 plunky 0xff,
447 1.1 plunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x000000000000ffff
448 1.1 plunky 0x00, 0x00, 0x00, 0xff,
449 1.1 plunky 0xff,
450 1.1 plunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x00000000ffffffff
451 1.1 plunky 0x00, 0xff, 0xff, 0xff,
452 1.1 plunky 0xff,
453 1.1 plunky 0x0b, 0xff, 0xff, 0xff, // uint64 0xffffffffffffffff
454 1.1 plunky 0xff, 0xff, 0xff, 0xff,
455 1.1 plunky 0xff,
456 1.1 plunky 0x0b, 0xc0, 0xff, 0xee, // uint64 0xc0ffeecafec0ffee
457 1.1 plunky 0xca, 0xfe, 0xc0, 0xff,
458 1.1 plunky 0xee,
459 1.1 plunky };
460 1.1 plunky
461 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
462 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
463 1.1 plunky }
464 1.1 plunky
465 1.1 plunky ATF_TC(check_sdp_put_int);
466 1.1 plunky
467 1.1 plunky ATF_TC_HEAD(check_sdp_put_int, tc)
468 1.1 plunky {
469 1.2 plunky
470 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int results");
471 1.1 plunky }
472 1.2 plunky
473 1.1 plunky ATF_TC_BODY(check_sdp_put_int, tc)
474 1.1 plunky {
475 1.1 plunky uint8_t buf[256];
476 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
477 1.2 plunky
478 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)0));
479 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MIN));
480 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MAX));
481 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MIN - 1));
482 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MAX + 1));
483 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MIN));
484 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MAX));
485 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MIN - 1));
486 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MAX + 1));
487 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MIN));
488 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MAX));
489 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MIN - 1));
490 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MAX + 1));
491 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT64_MIN));
492 1.1 plunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT64_MAX));
493 1.1 plunky test.end = test.next;
494 1.1 plunky test.next = buf;
495 1.1 plunky
496 1.1 plunky const uint8_t expect[] = {
497 1.1 plunky 0x10, 0x00, // int8 0
498 1.1 plunky 0x10, 0x80, // int8 -128
499 1.1 plunky 0x10, 0x7f, // int8 127
500 1.1 plunky 0x11, 0xff, 0x7f, // int16 -129
501 1.1 plunky 0x11, 0x00, 0x80, // int16 128
502 1.1 plunky 0x11, 0x80, 0x00, // int16 -32768
503 1.1 plunky 0x11, 0x7f, 0xff, // int16 32767
504 1.1 plunky 0x12, 0xff, 0xff, 0x7f, // int32 -32769
505 1.1 plunky 0xff,
506 1.1 plunky 0x12, 0x00, 0x00, 0x80, // int32 32768
507 1.1 plunky 0x00,
508 1.1 plunky 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
509 1.1 plunky 0x00,
510 1.1 plunky 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
511 1.1 plunky 0xff,
512 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -2147483649
513 1.1 plunky 0xff, 0x7f, 0xff, 0xff,
514 1.1 plunky 0xff,
515 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 2147483648
516 1.1 plunky 0x00, 0x80, 0x00, 0x00,
517 1.1 plunky 0x00,
518 1.1 plunky 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
519 1.1 plunky 0x00, 0x00, 0x00, 0x00,
520 1.1 plunky 0x00,
521 1.1 plunky 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
522 1.1 plunky 0xff, 0xff, 0xff, 0xff,
523 1.1 plunky 0xff,
524 1.1 plunky };
525 1.1 plunky
526 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
527 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
528 1.1 plunky }
529 1.1 plunky
530 1.1 plunky ATF_TC(check_sdp_put_int8);
531 1.1 plunky
532 1.1 plunky ATF_TC_HEAD(check_sdp_put_int8, tc)
533 1.1 plunky {
534 1.2 plunky
535 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int8 results");
536 1.1 plunky }
537 1.2 plunky
538 1.1 plunky ATF_TC_BODY(check_sdp_put_int8, tc)
539 1.1 plunky {
540 1.1 plunky uint8_t buf[256];
541 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
542 1.1 plunky
543 1.1 plunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)0));
544 1.1 plunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MIN));
545 1.1 plunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MAX));
546 1.1 plunky test.end = test.next;
547 1.1 plunky test.next = buf;
548 1.1 plunky
549 1.1 plunky const uint8_t expect[] = {
550 1.1 plunky 0x10, 0x00, // int8 0
551 1.1 plunky 0x10, 0x80, // int8 -128
552 1.1 plunky 0x10, 0x7f, // int8 127
553 1.1 plunky };
554 1.1 plunky
555 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
556 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
557 1.1 plunky }
558 1.1 plunky
559 1.1 plunky ATF_TC(check_sdp_put_int16);
560 1.1 plunky
561 1.1 plunky ATF_TC_HEAD(check_sdp_put_int16, tc)
562 1.1 plunky {
563 1.2 plunky
564 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int16 results");
565 1.1 plunky }
566 1.2 plunky
567 1.1 plunky ATF_TC_BODY(check_sdp_put_int16, tc)
568 1.1 plunky {
569 1.1 plunky uint8_t buf[256];
570 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
571 1.1 plunky
572 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)0));
573 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MIN));
574 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MAX));
575 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MIN));
576 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MAX));
577 1.1 plunky test.end = test.next;
578 1.1 plunky test.next = buf;
579 1.1 plunky
580 1.1 plunky const uint8_t expect[] = {
581 1.1 plunky 0x11, 0x00, 0x00, // int16 0
582 1.1 plunky 0x11, 0xff, 0x80, // int16 -128
583 1.1 plunky 0x11, 0x00, 0x7f, // int16 127
584 1.1 plunky 0x11, 0x80, 0x00, // int16 -32768
585 1.1 plunky 0x11, 0x7f, 0xff, // int16 32767
586 1.1 plunky };
587 1.1 plunky
588 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
589 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
590 1.1 plunky }
591 1.1 plunky
592 1.1 plunky ATF_TC(check_sdp_put_int32);
593 1.1 plunky
594 1.1 plunky ATF_TC_HEAD(check_sdp_put_int32, tc)
595 1.1 plunky {
596 1.2 plunky
597 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int32 results");
598 1.1 plunky }
599 1.2 plunky
600 1.1 plunky ATF_TC_BODY(check_sdp_put_int32, tc)
601 1.1 plunky {
602 1.1 plunky uint8_t buf[256];
603 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
604 1.1 plunky
605 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)0));
606 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MIN));
607 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MAX));
608 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MIN));
609 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MAX));
610 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MIN));
611 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MAX));
612 1.1 plunky test.end = test.next;
613 1.1 plunky test.next = buf;
614 1.1 plunky
615 1.1 plunky const uint8_t expect[] = {
616 1.1 plunky 0x12, 0x00, 0x00, 0x00, // int32 0
617 1.1 plunky 0x00,
618 1.1 plunky 0x12, 0xff, 0xff, 0xff, // int32 -128
619 1.1 plunky 0x80,
620 1.1 plunky 0x12, 0x00, 0x00, 0x00, // int32 127
621 1.1 plunky 0x7f,
622 1.1 plunky 0x12, 0xff, 0xff, 0x80, // int32 -32768
623 1.1 plunky 0x00,
624 1.1 plunky 0x12, 0x00, 0x00, 0x7f, // int32 32767
625 1.1 plunky 0xff,
626 1.1 plunky 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
627 1.1 plunky 0x00,
628 1.1 plunky 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
629 1.1 plunky 0xff,
630 1.1 plunky };
631 1.1 plunky
632 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
633 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
634 1.1 plunky }
635 1.1 plunky
636 1.1 plunky ATF_TC(check_sdp_put_int64);
637 1.1 plunky
638 1.1 plunky ATF_TC_HEAD(check_sdp_put_int64, tc)
639 1.1 plunky {
640 1.2 plunky
641 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int64 results");
642 1.1 plunky }
643 1.2 plunky
644 1.1 plunky ATF_TC_BODY(check_sdp_put_int64, tc)
645 1.1 plunky {
646 1.1 plunky uint8_t buf[256];
647 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
648 1.1 plunky
649 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)0));
650 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MIN));
651 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MAX));
652 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MIN));
653 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MAX));
654 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MIN));
655 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MAX));
656 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MIN));
657 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MAX));
658 1.1 plunky test.end = test.next;
659 1.1 plunky test.next = buf;
660 1.1 plunky
661 1.1 plunky const uint8_t expect[] = {
662 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 0
663 1.1 plunky 0x00, 0x00, 0x00, 0x00,
664 1.1 plunky 0x00,
665 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -128
666 1.1 plunky 0xff, 0xff, 0xff, 0xff,
667 1.1 plunky 0x80,
668 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 127
669 1.1 plunky 0x00, 0x00, 0x00, 0x00,
670 1.1 plunky 0x7f,
671 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -32768
672 1.1 plunky 0xff, 0xff, 0xff, 0x80,
673 1.1 plunky 0x00,
674 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 32767
675 1.1 plunky 0x00, 0x00, 0x00, 0x7f,
676 1.1 plunky 0xff,
677 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -2147483648
678 1.1 plunky 0xff, 0x80, 0x00, 0x00,
679 1.1 plunky 0x00,
680 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 2147483647
681 1.1 plunky 0x00, 0x7f, 0xff, 0xff,
682 1.1 plunky 0xff,
683 1.1 plunky 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
684 1.1 plunky 0x00, 0x00, 0x00, 0x00,
685 1.1 plunky 0x00,
686 1.1 plunky 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
687 1.1 plunky 0xff, 0xff, 0xff, 0xff,
688 1.1 plunky 0xff,
689 1.1 plunky };
690 1.1 plunky
691 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
692 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
693 1.1 plunky }
694 1.1 plunky
695 1.1 plunky ATF_TC(check_sdp_put_seq);
696 1.1 plunky
697 1.1 plunky ATF_TC_HEAD(check_sdp_put_seq, tc)
698 1.1 plunky {
699 1.2 plunky
700 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_seq results");
701 1.1 plunky }
702 1.2 plunky
703 1.1 plunky ATF_TC_BODY(check_sdp_put_seq, tc)
704 1.1 plunky {
705 1.1 plunky uint8_t buf[512];
706 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
707 1.1 plunky
708 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)0));
709 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX));
710 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX + 1));
711 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)-1));
712 1.1 plunky ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)UINT16_MAX), false); /* no room */
713 1.1 plunky ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)SSIZE_MAX), false); /* no room */
714 1.1 plunky test.end = test.next;
715 1.1 plunky test.next = buf;
716 1.1 plunky
717 1.1 plunky /* (not a valid element list) */
718 1.1 plunky const uint8_t expect[] = {
719 1.1 plunky 0x35, 0x00, // seq8(0)
720 1.1 plunky 0x35, 0xff, // seq8(255)
721 1.1 plunky 0x36, 0x01, 0x00, // seq16(256)
722 1.1 plunky 0x36, 0x01, 0xf6, // seq16(502) <- sizeof(buf) - 7 - 3
723 1.1 plunky };
724 1.1 plunky
725 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
726 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
727 1.1 plunky }
728 1.1 plunky
729 1.1 plunky ATF_TC(check_sdp_put_alt);
730 1.1 plunky
731 1.1 plunky ATF_TC_HEAD(check_sdp_put_alt, tc)
732 1.1 plunky {
733 1.2 plunky
734 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_alt results");
735 1.1 plunky }
736 1.2 plunky
737 1.1 plunky ATF_TC_BODY(check_sdp_put_alt, tc)
738 1.1 plunky {
739 1.1 plunky uint8_t buf[512];
740 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
741 1.1 plunky
742 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)0));
743 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX));
744 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX + 1));
745 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)-1));
746 1.1 plunky ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)UINT16_MAX), false); /* no room */
747 1.1 plunky ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)SSIZE_MAX), false); /* no room */
748 1.1 plunky test.end = test.next;
749 1.1 plunky test.next = buf;
750 1.1 plunky
751 1.1 plunky /* (not a valid element list) */
752 1.1 plunky const uint8_t expect[] = {
753 1.1 plunky 0x3d, 0x00, // alt8(0)
754 1.1 plunky 0x3d, 0xff, // alt8(255)
755 1.1 plunky 0x3e, 0x01, 0x00, // alt16(256)
756 1.1 plunky 0x3e, 0x01, 0xf6, // alt16(502) <- sizeof(buf) - 7 - 3
757 1.1 plunky };
758 1.1 plunky
759 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
760 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
761 1.1 plunky }
762 1.1 plunky
763 1.1 plunky ATF_TC(check_sdp_put_str);
764 1.1 plunky
765 1.1 plunky ATF_TC_HEAD(check_sdp_put_str, tc)
766 1.1 plunky {
767 1.2 plunky
768 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_str results");
769 1.1 plunky }
770 1.2 plunky
771 1.1 plunky ATF_TC_BODY(check_sdp_put_str, tc)
772 1.1 plunky {
773 1.1 plunky uint8_t buf[512];
774 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
775 1.1 plunky
776 1.1 plunky /*
777 1.1 plunky * this does not test str16 or str32, but that is
778 1.1 plunky * handled by the same code as sdp_put_seq above..
779 1.1 plunky */
780 1.1 plunky
781 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello World!", 5));
782 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", 11));
783 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello World!", -1));
784 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", -1));
785 1.1 plunky test.end = test.next;
786 1.1 plunky test.next = buf;
787 1.1 plunky
788 1.1 plunky const uint8_t expect[] = {
789 1.1 plunky 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
790 1.1 plunky 0x6c, 0x6c, 0x6f,
791 1.1 plunky 0x25, 0x0b, 0x48, 0x65, // str8 "Hello\0World"
792 1.1 plunky 0x6c, 0x6c, 0x6f, 0x00,
793 1.1 plunky 0x57, 0x6f, 0x72, 0x6c,
794 1.1 plunky 0x64,
795 1.1 plunky 0x25, 0x0c, 0x48, 0x65, // str8 "Hello World!"
796 1.1 plunky 0x6c, 0x6c, 0x6f, 0x20,
797 1.1 plunky 0x57, 0x6f, 0x72, 0x6c,
798 1.1 plunky 0x64, 0x21,
799 1.1 plunky 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
800 1.1 plunky 0x6c, 0x6c, 0x6f,
801 1.1 plunky };
802 1.1 plunky
803 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
804 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
805 1.1 plunky }
806 1.1 plunky
807 1.1 plunky ATF_TC(check_sdp_put_url);
808 1.1 plunky
809 1.1 plunky ATF_TC_HEAD(check_sdp_put_url, tc)
810 1.1 plunky {
811 1.2 plunky
812 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_url results");
813 1.1 plunky }
814 1.2 plunky
815 1.1 plunky ATF_TC_BODY(check_sdp_put_url, tc)
816 1.1 plunky {
817 1.1 plunky uint8_t buf[512];
818 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
819 1.1 plunky
820 1.1 plunky /*
821 1.1 plunky * this does not test url16 or url32, but that is
822 1.1 plunky * handled by the same code as sdp_put_seq above..
823 1.1 plunky */
824 1.1 plunky
825 1.1 plunky ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", 21));
826 1.1 plunky ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", -1));
827 1.1 plunky test.end = test.next;
828 1.1 plunky test.next = buf;
829 1.1 plunky
830 1.1 plunky const uint8_t expect[] = {
831 1.1 plunky 0x45, 0x15, 0x68, 0x74, // url8 "http://www.netbsd.org"
832 1.1 plunky 0x74, 0x70, 0x3a, 0x2f,
833 1.1 plunky 0x2f, 0x77, 0x77, 0x77,
834 1.1 plunky 0x2e, 0x6e, 0x65, 0x74,
835 1.1 plunky 0x62, 0x73, 0x64, 0x2e,
836 1.1 plunky 0x6f, 0x72, 0x67,
837 1.1 plunky 0x45, 0x16, 0x68, 0x74, // url8 "http://www.netbsd.org/"
838 1.1 plunky 0x74, 0x70, 0x3a, 0x2f,
839 1.1 plunky 0x2f, 0x77, 0x77, 0x77,
840 1.1 plunky 0x2e, 0x6e, 0x65, 0x74,
841 1.1 plunky 0x62, 0x73, 0x64, 0x2e,
842 1.1 plunky 0x6f, 0x72, 0x67, 0x2f,
843 1.1 plunky };
844 1.1 plunky
845 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
846 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
847 1.1 plunky }
848 1.1 plunky
849 1.1 plunky ATF_TP_ADD_TCS(tp)
850 1.1 plunky {
851 1.1 plunky
852 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_data);
853 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_attr);
854 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid);
855 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid16);
856 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid32);
857 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid128);
858 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_bool);
859 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint);
860 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint8);
861 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint16);
862 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint32);
863 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint64);
864 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int);
865 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int8);
866 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int16);
867 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int32);
868 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int64);
869 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_seq);
870 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_alt);
871 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_str);
872 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_url);
873 1.1 plunky
874 1.1 plunky return atf_no_error();
875 1.1 plunky }
876