t_sdp_put.c revision 1.2 1 1.2 plunky /* $NetBSD: t_sdp_put.c,v 1.2 2011/04/07 08:29:50 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.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.2 plunky
106 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid results");
107 1.1 plunky }
108 1.2 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.2 plunky
164 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid16 results");
165 1.1 plunky }
166 1.2 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.2 plunky
189 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid32 results");
190 1.1 plunky }
191 1.2 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.2 plunky
215 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid128 results");
216 1.1 plunky }
217 1.2 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.2 plunky
252 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_bool results");
253 1.1 plunky }
254 1.2 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.2 plunky
279 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint results");
280 1.1 plunky }
281 1.2 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.2 plunky
324 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint8 results");
325 1.1 plunky }
326 1.2 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.2 plunky
351 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint16 results");
352 1.1 plunky }
353 1.2 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.2 plunky
382 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint32 results");
383 1.1 plunky }
384 1.2 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.2 plunky
420 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint64 results");
421 1.1 plunky }
422 1.2 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.2 plunky
467 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int results");
468 1.1 plunky }
469 1.2 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.2 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 const uint8_t expect[] = {
494 1.1 plunky 0x10, 0x00, // int8 0
495 1.1 plunky 0x10, 0x80, // int8 -128
496 1.1 plunky 0x10, 0x7f, // int8 127
497 1.1 plunky 0x11, 0xff, 0x7f, // int16 -129
498 1.1 plunky 0x11, 0x00, 0x80, // int16 128
499 1.1 plunky 0x11, 0x80, 0x00, // int16 -32768
500 1.1 plunky 0x11, 0x7f, 0xff, // int16 32767
501 1.1 plunky 0x12, 0xff, 0xff, 0x7f, // int32 -32769
502 1.1 plunky 0xff,
503 1.1 plunky 0x12, 0x00, 0x00, 0x80, // int32 32768
504 1.1 plunky 0x00,
505 1.1 plunky 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
506 1.1 plunky 0x00,
507 1.1 plunky 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
508 1.1 plunky 0xff,
509 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -2147483649
510 1.1 plunky 0xff, 0x7f, 0xff, 0xff,
511 1.1 plunky 0xff,
512 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 2147483648
513 1.1 plunky 0x00, 0x80, 0x00, 0x00,
514 1.1 plunky 0x00,
515 1.1 plunky 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
516 1.1 plunky 0x00, 0x00, 0x00, 0x00,
517 1.1 plunky 0x00,
518 1.1 plunky 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
519 1.1 plunky 0xff, 0xff, 0xff, 0xff,
520 1.1 plunky 0xff,
521 1.1 plunky };
522 1.1 plunky
523 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
524 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
525 1.1 plunky }
526 1.1 plunky
527 1.1 plunky ATF_TC(check_sdp_put_int8);
528 1.1 plunky
529 1.1 plunky ATF_TC_HEAD(check_sdp_put_int8, tc)
530 1.1 plunky {
531 1.2 plunky
532 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int8 results");
533 1.1 plunky }
534 1.2 plunky
535 1.1 plunky ATF_TC_BODY(check_sdp_put_int8, tc)
536 1.1 plunky {
537 1.1 plunky uint8_t buf[256];
538 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
539 1.1 plunky
540 1.1 plunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)0));
541 1.1 plunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MIN));
542 1.1 plunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MAX));
543 1.1 plunky test.end = test.next;
544 1.1 plunky test.next = buf;
545 1.1 plunky
546 1.1 plunky const uint8_t expect[] = {
547 1.1 plunky 0x10, 0x00, // int8 0
548 1.1 plunky 0x10, 0x80, // int8 -128
549 1.1 plunky 0x10, 0x7f, // int8 127
550 1.1 plunky };
551 1.1 plunky
552 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
553 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
554 1.1 plunky }
555 1.1 plunky
556 1.1 plunky ATF_TC(check_sdp_put_int16);
557 1.1 plunky
558 1.1 plunky ATF_TC_HEAD(check_sdp_put_int16, tc)
559 1.1 plunky {
560 1.2 plunky
561 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int16 results");
562 1.1 plunky }
563 1.2 plunky
564 1.1 plunky ATF_TC_BODY(check_sdp_put_int16, tc)
565 1.1 plunky {
566 1.1 plunky uint8_t buf[256];
567 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
568 1.1 plunky
569 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)0));
570 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MIN));
571 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MAX));
572 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MIN));
573 1.1 plunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MAX));
574 1.1 plunky test.end = test.next;
575 1.1 plunky test.next = buf;
576 1.1 plunky
577 1.1 plunky const uint8_t expect[] = {
578 1.1 plunky 0x11, 0x00, 0x00, // int16 0
579 1.1 plunky 0x11, 0xff, 0x80, // int16 -128
580 1.1 plunky 0x11, 0x00, 0x7f, // int16 127
581 1.1 plunky 0x11, 0x80, 0x00, // int16 -32768
582 1.1 plunky 0x11, 0x7f, 0xff, // int16 32767
583 1.1 plunky };
584 1.1 plunky
585 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
586 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
587 1.1 plunky }
588 1.1 plunky
589 1.1 plunky ATF_TC(check_sdp_put_int32);
590 1.1 plunky
591 1.1 plunky ATF_TC_HEAD(check_sdp_put_int32, tc)
592 1.1 plunky {
593 1.2 plunky
594 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int32 results");
595 1.1 plunky }
596 1.2 plunky
597 1.1 plunky ATF_TC_BODY(check_sdp_put_int32, tc)
598 1.1 plunky {
599 1.1 plunky uint8_t buf[256];
600 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
601 1.1 plunky
602 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)0));
603 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MIN));
604 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MAX));
605 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MIN));
606 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MAX));
607 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MIN));
608 1.1 plunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MAX));
609 1.1 plunky test.end = test.next;
610 1.1 plunky test.next = buf;
611 1.1 plunky
612 1.1 plunky const uint8_t expect[] = {
613 1.1 plunky 0x12, 0x00, 0x00, 0x00, // int32 0
614 1.1 plunky 0x00,
615 1.1 plunky 0x12, 0xff, 0xff, 0xff, // int32 -128
616 1.1 plunky 0x80,
617 1.1 plunky 0x12, 0x00, 0x00, 0x00, // int32 127
618 1.1 plunky 0x7f,
619 1.1 plunky 0x12, 0xff, 0xff, 0x80, // int32 -32768
620 1.1 plunky 0x00,
621 1.1 plunky 0x12, 0x00, 0x00, 0x7f, // int32 32767
622 1.1 plunky 0xff,
623 1.1 plunky 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
624 1.1 plunky 0x00,
625 1.1 plunky 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
626 1.1 plunky 0xff,
627 1.1 plunky };
628 1.1 plunky
629 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
630 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
631 1.1 plunky }
632 1.1 plunky
633 1.1 plunky ATF_TC(check_sdp_put_int64);
634 1.1 plunky
635 1.1 plunky ATF_TC_HEAD(check_sdp_put_int64, tc)
636 1.1 plunky {
637 1.2 plunky
638 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int64 results");
639 1.1 plunky }
640 1.2 plunky
641 1.1 plunky ATF_TC_BODY(check_sdp_put_int64, tc)
642 1.1 plunky {
643 1.1 plunky uint8_t buf[256];
644 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
645 1.1 plunky
646 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)0));
647 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MIN));
648 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MAX));
649 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MIN));
650 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MAX));
651 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MIN));
652 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MAX));
653 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MIN));
654 1.1 plunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MAX));
655 1.1 plunky test.end = test.next;
656 1.1 plunky test.next = buf;
657 1.1 plunky
658 1.1 plunky const uint8_t expect[] = {
659 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 0
660 1.1 plunky 0x00, 0x00, 0x00, 0x00,
661 1.1 plunky 0x00,
662 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -128
663 1.1 plunky 0xff, 0xff, 0xff, 0xff,
664 1.1 plunky 0x80,
665 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 127
666 1.1 plunky 0x00, 0x00, 0x00, 0x00,
667 1.1 plunky 0x7f,
668 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -32768
669 1.1 plunky 0xff, 0xff, 0xff, 0x80,
670 1.1 plunky 0x00,
671 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 32767
672 1.1 plunky 0x00, 0x00, 0x00, 0x7f,
673 1.1 plunky 0xff,
674 1.1 plunky 0x13, 0xff, 0xff, 0xff, // int64 -2147483648
675 1.1 plunky 0xff, 0x80, 0x00, 0x00,
676 1.1 plunky 0x00,
677 1.1 plunky 0x13, 0x00, 0x00, 0x00, // int64 2147483647
678 1.1 plunky 0x00, 0x7f, 0xff, 0xff,
679 1.1 plunky 0xff,
680 1.1 plunky 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
681 1.1 plunky 0x00, 0x00, 0x00, 0x00,
682 1.1 plunky 0x00,
683 1.1 plunky 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
684 1.1 plunky 0xff, 0xff, 0xff, 0xff,
685 1.1 plunky 0xff,
686 1.1 plunky };
687 1.1 plunky
688 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
689 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
690 1.1 plunky }
691 1.1 plunky
692 1.1 plunky ATF_TC(check_sdp_put_seq);
693 1.1 plunky
694 1.1 plunky ATF_TC_HEAD(check_sdp_put_seq, tc)
695 1.1 plunky {
696 1.2 plunky
697 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_seq results");
698 1.1 plunky }
699 1.2 plunky
700 1.1 plunky ATF_TC_BODY(check_sdp_put_seq, tc)
701 1.1 plunky {
702 1.1 plunky uint8_t buf[512];
703 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
704 1.1 plunky
705 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)0));
706 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX));
707 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX + 1));
708 1.1 plunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)-1));
709 1.1 plunky ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)UINT16_MAX), false); /* no room */
710 1.1 plunky ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)SSIZE_MAX), false); /* no room */
711 1.1 plunky test.end = test.next;
712 1.1 plunky test.next = buf;
713 1.1 plunky
714 1.1 plunky /* (not a valid element list) */
715 1.1 plunky const uint8_t expect[] = {
716 1.1 plunky 0x35, 0x00, // seq8(0)
717 1.1 plunky 0x35, 0xff, // seq8(255)
718 1.1 plunky 0x36, 0x01, 0x00, // seq16(256)
719 1.1 plunky 0x36, 0x01, 0xf6, // seq16(502) <- sizeof(buf) - 7 - 3
720 1.1 plunky };
721 1.1 plunky
722 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
723 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
724 1.1 plunky }
725 1.1 plunky
726 1.1 plunky ATF_TC(check_sdp_put_alt);
727 1.1 plunky
728 1.1 plunky ATF_TC_HEAD(check_sdp_put_alt, tc)
729 1.1 plunky {
730 1.2 plunky
731 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_alt results");
732 1.1 plunky }
733 1.2 plunky
734 1.1 plunky ATF_TC_BODY(check_sdp_put_alt, tc)
735 1.1 plunky {
736 1.1 plunky uint8_t buf[512];
737 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
738 1.1 plunky
739 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)0));
740 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX));
741 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX + 1));
742 1.1 plunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)-1));
743 1.1 plunky ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)UINT16_MAX), false); /* no room */
744 1.1 plunky ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)SSIZE_MAX), false); /* no room */
745 1.1 plunky test.end = test.next;
746 1.1 plunky test.next = buf;
747 1.1 plunky
748 1.1 plunky /* (not a valid element list) */
749 1.1 plunky const uint8_t expect[] = {
750 1.1 plunky 0x3d, 0x00, // alt8(0)
751 1.1 plunky 0x3d, 0xff, // alt8(255)
752 1.1 plunky 0x3e, 0x01, 0x00, // alt16(256)
753 1.1 plunky 0x3e, 0x01, 0xf6, // alt16(502) <- sizeof(buf) - 7 - 3
754 1.1 plunky };
755 1.1 plunky
756 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
757 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
758 1.1 plunky }
759 1.1 plunky
760 1.1 plunky ATF_TC(check_sdp_put_str);
761 1.1 plunky
762 1.1 plunky ATF_TC_HEAD(check_sdp_put_str, tc)
763 1.1 plunky {
764 1.2 plunky
765 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_str results");
766 1.1 plunky }
767 1.2 plunky
768 1.1 plunky ATF_TC_BODY(check_sdp_put_str, tc)
769 1.1 plunky {
770 1.1 plunky uint8_t buf[512];
771 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
772 1.1 plunky
773 1.1 plunky /*
774 1.1 plunky * this does not test str16 or str32, but that is
775 1.1 plunky * handled by the same code as sdp_put_seq above..
776 1.1 plunky */
777 1.1 plunky
778 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello World!", 5));
779 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", 11));
780 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello World!", -1));
781 1.1 plunky ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", -1));
782 1.1 plunky test.end = test.next;
783 1.1 plunky test.next = buf;
784 1.1 plunky
785 1.1 plunky const uint8_t expect[] = {
786 1.1 plunky 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
787 1.1 plunky 0x6c, 0x6c, 0x6f,
788 1.1 plunky 0x25, 0x0b, 0x48, 0x65, // str8 "Hello\0World"
789 1.1 plunky 0x6c, 0x6c, 0x6f, 0x00,
790 1.1 plunky 0x57, 0x6f, 0x72, 0x6c,
791 1.1 plunky 0x64,
792 1.1 plunky 0x25, 0x0c, 0x48, 0x65, // str8 "Hello World!"
793 1.1 plunky 0x6c, 0x6c, 0x6f, 0x20,
794 1.1 plunky 0x57, 0x6f, 0x72, 0x6c,
795 1.1 plunky 0x64, 0x21,
796 1.1 plunky 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
797 1.1 plunky 0x6c, 0x6c, 0x6f,
798 1.1 plunky };
799 1.1 plunky
800 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
801 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
802 1.1 plunky }
803 1.1 plunky
804 1.1 plunky ATF_TC(check_sdp_put_url);
805 1.1 plunky
806 1.1 plunky ATF_TC_HEAD(check_sdp_put_url, tc)
807 1.1 plunky {
808 1.2 plunky
809 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_url results");
810 1.1 plunky }
811 1.2 plunky
812 1.1 plunky ATF_TC_BODY(check_sdp_put_url, tc)
813 1.1 plunky {
814 1.1 plunky uint8_t buf[512];
815 1.1 plunky sdp_data_t test = { buf, buf + sizeof(buf) };
816 1.1 plunky
817 1.1 plunky /*
818 1.1 plunky * this does not test url16 or url32, but that is
819 1.1 plunky * handled by the same code as sdp_put_seq above..
820 1.1 plunky */
821 1.1 plunky
822 1.1 plunky ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", 21));
823 1.1 plunky ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", -1));
824 1.1 plunky test.end = test.next;
825 1.1 plunky test.next = buf;
826 1.1 plunky
827 1.1 plunky const uint8_t expect[] = {
828 1.1 plunky 0x45, 0x15, 0x68, 0x74, // url8 "http://www.netbsd.org"
829 1.1 plunky 0x74, 0x70, 0x3a, 0x2f,
830 1.1 plunky 0x2f, 0x77, 0x77, 0x77,
831 1.1 plunky 0x2e, 0x6e, 0x65, 0x74,
832 1.1 plunky 0x62, 0x73, 0x64, 0x2e,
833 1.1 plunky 0x6f, 0x72, 0x67,
834 1.1 plunky 0x45, 0x16, 0x68, 0x74, // url8 "http://www.netbsd.org/"
835 1.1 plunky 0x74, 0x70, 0x3a, 0x2f,
836 1.1 plunky 0x2f, 0x77, 0x77, 0x77,
837 1.1 plunky 0x2e, 0x6e, 0x65, 0x74,
838 1.1 plunky 0x62, 0x73, 0x64, 0x2e,
839 1.1 plunky 0x6f, 0x72, 0x67, 0x2f,
840 1.1 plunky };
841 1.1 plunky
842 1.1 plunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
843 1.1 plunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
844 1.1 plunky }
845 1.1 plunky
846 1.1 plunky ATF_TP_ADD_TCS(tp)
847 1.1 plunky {
848 1.1 plunky
849 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_data);
850 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_attr);
851 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid);
852 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid16);
853 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid32);
854 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid128);
855 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_bool);
856 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint);
857 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint8);
858 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint16);
859 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint32);
860 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_uint64);
861 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int);
862 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int8);
863 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int16);
864 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int32);
865 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_int64);
866 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_seq);
867 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_alt);
868 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_str);
869 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_put_url);
870 1.1 plunky
871 1.1 plunky return atf_no_error();
872 1.1 plunky }
873