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