xref: /netbsd/tests/lib/libbluetooth/t_sdp_get.c (revision bc7c9260)
1 /*	$NetBSD: t_sdp_get.c,v 1.2 2011/04/07 08:29:50 plunky Exp $	*/
2 
3 /*-
4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Iain Hibbert.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <atf-c.h>
33 
34 #include <limits.h>
35 #include <sdp.h>
36 #include <string.h>
37 
38 ATF_TC(check_sdp_get_data);
39 
ATF_TC_HEAD(check_sdp_get_data,tc)40 ATF_TC_HEAD(check_sdp_get_data, tc)
41 {
42 
43 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_data results");
44 }
45 
ATF_TC_BODY(check_sdp_get_data,tc)46 ATF_TC_BODY(check_sdp_get_data, tc)
47 {
48 	uint8_t data[] = {
49 		0x09, 0x00, 0x00,	// uint16	0x0000
50 		0x35, 0x05,		// seq8(5)
51 		0x19, 0x00, 0x00,	//   uuid16	0x0000
52 		0x08, 0x00,		//   uint8	0x00
53 		0x36, 0x00, 0x01,	// seq16(1)
54 		0x19,			//   uint16	/* invalid */
55 		0x25, 0x04, 0x54, 0x45,	// str8(4)	"TEST"
56 		0x53, 0x54,
57 	};
58 	sdp_data_t test = { data, data + sizeof(data) };
59 	sdp_data_t value, seq;
60 
61 	/*
62 	 * sdp_get_data constructs a new sdp_data_t containing
63 	 * the next data element, advancing test if successful
64 	 */
65 	ATF_REQUIRE(sdp_get_data(&test, &value));
66 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT16);
67 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
68 
69 	ATF_REQUIRE(sdp_get_data(&test, &value));
70 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
71 	ATF_CHECK_EQ(sdp_data_size(&value), 7);
72 
73 	ATF_REQUIRE(sdp_get_data(&test, &value));
74 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ16);
75 	ATF_CHECK_EQ(sdp_data_size(&value), 4);
76 	ATF_REQUIRE_EQ(sdp_get_seq(&value, &seq), true);
77 	ATF_REQUIRE_EQ(sdp_get_data(&seq, &value), false);	/* invalid */
78 
79 	ATF_REQUIRE(sdp_get_data(&test, &value));
80 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_STR8);
81 	ATF_CHECK_EQ(sdp_data_size(&value), 6);
82 
83 	ATF_CHECK_EQ(test.next, test.end);
84 }
85 
86 ATF_TC(check_sdp_get_attr);
87 
ATF_TC_HEAD(check_sdp_get_attr,tc)88 ATF_TC_HEAD(check_sdp_get_attr, tc)
89 {
90 
91 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_attr results");
92 }
93 
ATF_TC_BODY(check_sdp_get_attr,tc)94 ATF_TC_BODY(check_sdp_get_attr, tc)
95 {
96 	uint8_t data[] = {
97 		0x09, 0x00, 0x00,	// uint16	0x0000
98 		0x35, 0x05,		// seq8(5)
99 		0x19, 0x00, 0x00,	//   uuid16	0x0000
100 		0x08, 0x00,		//   uint8	0x00
101 		0x08, 0x00,		// uint8	0x00
102 		0x09, 0x00, 0x01,	// uint16	0x0001
103 		0x19, 0x12, 0x34,	// uuid16	0x1234
104 	};
105 	sdp_data_t test = { data, data + sizeof(data) };
106 	sdp_data_t value;
107 	uint16_t attr;
108 
109 	/*
110 	 * sdp_get_attr expects a UINT16 followed by any data item
111 	 * and advances test if successful
112 	 */
113 	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
114 	ATF_CHECK_EQ(attr, 0x0000);
115 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
116 	ATF_CHECK_EQ(sdp_data_size(&value), 7);
117 
118 	ATF_REQUIRE_EQ(sdp_get_attr(&test, &attr, &value), false);
119 	ATF_REQUIRE(sdp_get_data(&test, &value));
120 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT8);
121 	ATF_CHECK_EQ(sdp_data_size(&value), 2);
122 
123 	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
124 	ATF_CHECK_EQ(attr, 0x0001);
125 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UUID16);
126 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
127 
128 	ATF_CHECK_EQ(test.next, test.end);
129 }
130 
131 ATF_TC(check_sdp_get_uuid);
132 
ATF_TC_HEAD(check_sdp_get_uuid,tc)133 ATF_TC_HEAD(check_sdp_get_uuid, tc)
134 {
135 
136 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uuid results");
137 }
138 
ATF_TC_BODY(check_sdp_get_uuid,tc)139 ATF_TC_BODY(check_sdp_get_uuid, tc)
140 {
141 	uint8_t data[] = {
142 		0x19, 0x12, 0x34,	// uuid16	0x1234
143 		0x1a, 0x11, 0x22, 0x33,	// uuid32	0x11223344
144 		0x44,
145 		0x00,			// nil
146 		0x1c,			// uuid128	0x00112233-4444--5555-6666-778899aabbcc
147 		0x00, 0x11, 0x22, 0x33,
148 		0x44, 0x44, 0x55, 0x55,
149 		0x66, 0x66, 0x77, 0x88,
150 		0x99, 0xaa, 0xbb, 0xcc,
151 	};
152 	sdp_data_t test = { data, data + sizeof(data) };
153 	uuid_t u16 = {
154 		0x00001234,
155 		0x0000,
156 		0x1000,
157 		0x80,
158 		0x00,
159 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
160 	};
161 	uuid_t u32 = {
162 		0x11223344,
163 		0x0000,
164 		0x1000,
165 		0x80,
166 		0x00,
167 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
168 	};
169 	uuid_t u128 = {
170 		0x00112233,
171 		0x4444,
172 		0x5555,
173 		0x66,
174 		0x66,
175 		{ 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc }
176 	};
177 	sdp_data_t nil;
178 	uuid_t value;
179 
180 	/*
181 	 * sdp_get_uuid expects any UUID type returns the full uuid
182 	 * advancing test if successful
183 	 */
184 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
185 	ATF_CHECK(uuid_equal(&value, &u16, NULL));
186 
187 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
188 	ATF_CHECK(uuid_equal(&value, &u32, NULL));
189 
190 	ATF_REQUIRE_EQ(sdp_get_uuid(&test, &value), false);	/* not uuid */
191 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
192 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
193 
194 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
195 	ATF_CHECK(uuid_equal(&value, &u128, NULL));
196 
197 	ATF_CHECK_EQ(test.next, test.end);
198 }
199 
200 ATF_TC(check_sdp_get_bool);
201 
ATF_TC_HEAD(check_sdp_get_bool,tc)202 ATF_TC_HEAD(check_sdp_get_bool, tc)
203 {
204 
205 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_bool results");
206 }
207 
ATF_TC_BODY(check_sdp_get_bool,tc)208 ATF_TC_BODY(check_sdp_get_bool, tc)
209 {
210 	uint8_t data[] = {
211 		0x28, 0x00,	// bool		false
212 		0x00,		// nil
213 		0x28, 0x01,	// bool		true
214 	};
215 	sdp_data_t test = { data, data + sizeof(data) };
216 	sdp_data_t nil;
217 	bool value;
218 
219 	/*
220 	 * sdp_get_bool expects a BOOL type
221 	 * advancing test if successful
222 	 */
223 	ATF_REQUIRE(sdp_get_bool(&test, &value));
224 	ATF_CHECK_EQ(value, false);
225 
226 	ATF_REQUIRE_EQ(sdp_get_bool(&test, &value), false);	/* not bool */
227 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
228 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
229 
230 	ATF_REQUIRE(sdp_get_bool(&test, &value));
231 	ATF_CHECK_EQ(value, true);
232 
233 	ATF_CHECK_EQ(test.next, test.end);
234 }
235 
236 ATF_TC(check_sdp_get_uint);
237 
ATF_TC_HEAD(check_sdp_get_uint,tc)238 ATF_TC_HEAD(check_sdp_get_uint, tc)
239 {
240 
241 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uint results");
242 }
243 
ATF_TC_BODY(check_sdp_get_uint,tc)244 ATF_TC_BODY(check_sdp_get_uint, tc)
245 {
246 	uint8_t data[] = {
247 		0x08, 0x00,		// uint8	0x00
248 		0x08, 0xff,		// uint8	0xff
249 		0x09, 0x01, 0x02,	// uint16	0x0102
250 		0x09, 0xff, 0xff,	// uint16	0xffff
251 		0x00,			// nil
252 		0x0a, 0x01, 0x02, 0x03,	// uint32	0x01020304
253 		0x04,
254 		0x0a, 0xff, 0xff, 0xff,	// uint32	0xffffffff
255 		0xff,
256 		0x0b, 0x01, 0x02, 0x03,	// uint64	0x0102030405060708
257 		0x04, 0x05, 0x06, 0x07,
258 		0x08,
259 		0x0b, 0xff, 0xff, 0xff,	// uint64	0xffffffffffffffff
260 		0xff, 0xff, 0xff, 0xff,
261 		0xff,
262 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000000000000000000000
263 		0x00, 0x00, 0x00, 0x00,
264 		0x00, 0x00, 0x00, 0x00,
265 		0x00, 0x00, 0x00, 0x00,
266 		0x00,
267 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000010000000000000000
268 		0x00, 0x00, 0x00, 0x00,
269 		0x01, 0x00, 0x00, 0x00,
270 		0x00, 0x00, 0x00, 0x00,
271 		0x00,
272 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x0000000000000000ffffffffffffffff
273 		0x00, 0x00, 0x00, 0x00,
274 		0x00, 0xff, 0xff, 0xff,
275 		0xff, 0xff, 0xff, 0xff,
276 		0xff,
277 	};
278 	sdp_data_t test = { data, data + sizeof(data) };
279 	sdp_data_t nil;
280 	uintmax_t value;
281 
282 	/*
283 	 * sdp_get_uint expects any UINT type, advancing test if successful
284 	 */
285 	ATF_REQUIRE(sdp_get_uint(&test, &value));
286 	ATF_CHECK_EQ(value, 0x00);
287 
288 	ATF_REQUIRE(sdp_get_uint(&test, &value));
289 	ATF_CHECK_EQ(value, UINT8_MAX);
290 
291 	ATF_REQUIRE(sdp_get_uint(&test, &value));
292 	ATF_CHECK_EQ(value, 0x0102);
293 
294 	ATF_REQUIRE(sdp_get_uint(&test, &value));
295 	ATF_CHECK_EQ(value, UINT16_MAX);
296 
297 	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* not uint */
298 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
299 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
300 
301 	ATF_REQUIRE(sdp_get_uint(&test, &value));
302 	ATF_CHECK_EQ(value, 0x01020304);
303 
304 	ATF_REQUIRE(sdp_get_uint(&test, &value));
305 	ATF_CHECK_EQ(value, UINT32_MAX);
306 
307 	ATF_REQUIRE(sdp_get_uint(&test, &value));
308 	ATF_CHECK_EQ(value, 0x0102030405060708);
309 
310 	ATF_REQUIRE(sdp_get_uint(&test, &value));
311 	ATF_CHECK_EQ(value, UINT64_MAX);
312 
313 	/*
314 	 * expected failure is that we cannot decode UINT128 values larger than UINT64
315 	 */
316 	ATF_REQUIRE(sdp_get_uint(&test, &value));
317 	ATF_CHECK_EQ(value, 0x00000000000000000000000000000000);
318 
319 	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* overflow */
320 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
321 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_UINT128);
322 
323 	ATF_REQUIRE(sdp_get_uint(&test, &value));
324 	ATF_CHECK_EQ(value, UINT64_MAX);
325 
326 	ATF_CHECK_EQ(test.next, test.end);
327 }
328 
329 ATF_TC(check_sdp_get_int);
330 
ATF_TC_HEAD(check_sdp_get_int,tc)331 ATF_TC_HEAD(check_sdp_get_int, tc)
332 {
333 
334 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_int results");
335 }
336 
ATF_TC_BODY(check_sdp_get_int,tc)337 ATF_TC_BODY(check_sdp_get_int, tc)
338 {
339 	uint8_t data[] = {
340 		0x10, 0x00,		// int8		0x00
341 		0x10, 0x7f,		// int8		0x7f
342 		0x10, 0x80,		// int8		0x80
343 		0x11, 0x01, 0x02,	// int16	0x0102
344 		0x11, 0x7f, 0xff,	// int16	0x7fff
345 		0x11, 0x80, 0x00,	// int16	0x8000
346 		0x00,			// nil
347 		0x12, 0x01, 0x02, 0x03,	// int32	0x01020304
348 		0x04,
349 		0x12, 0x7f, 0xff, 0xff,	// int32	0x7fffffff
350 		0xff,
351 		0x12, 0x80, 0x00, 0x00,	// int32	0x80000000
352 		0x00,
353 		0x13, 0x01, 0x02, 0x03,	// int64	0x0102030405060708
354 		0x04, 0x05, 0x06, 0x07,
355 		0x08,
356 		0x13, 0x7f, 0xff, 0xff,	// int64	0x7fffffffffffffff
357 		0xff, 0xff, 0xff, 0xff,
358 		0xff,
359 		0x13, 0x80, 0x00, 0x00,	// int64	0x8000000000000000
360 		0x00, 0x00, 0x00, 0x00,
361 		0x00,
362 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000000000000000000000
363 		0x00, 0x00, 0x00, 0x00,
364 		0x00, 0x00, 0x00, 0x00,
365 		0x00, 0x00, 0x00, 0x00,
366 		0x00,
367 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000007fffffffffffffff
368 		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX)
369 		0x00, 0x7f, 0xff, 0xff,
370 		0xff, 0xff, 0xff, 0xff,
371 		0xff,
372 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000008000000000000000
373 		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX + 1)
374 		0x00, 0x80, 0x00, 0x00,
375 		0x00, 0x00, 0x00, 0x00,
376 		0x00,
377 		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff8000000000000000
378 		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN)
379 		0xff, 0x80, 0x00, 0x00,
380 		0x00, 0x00, 0x00, 0x00,
381 		0x00,
382 		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff7fffffffffffffff
383 		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN - 1)
384 		0xff, 0x7f, 0xff, 0xff,
385 		0xff, 0xff, 0xff, 0xff,
386 		0xff,
387 	};
388 	sdp_data_t test = { data, data + sizeof(data) };
389 	sdp_data_t nil;
390 	intmax_t value;
391 
392 	/*
393 	 * sdp_get_int expects any INT type, advancing test if successful
394 	 */
395 	ATF_REQUIRE(sdp_get_int(&test, &value));
396 	ATF_CHECK_EQ(value, 0);
397 
398 	ATF_REQUIRE(sdp_get_int(&test, &value));
399 	ATF_CHECK_EQ(value, INT8_MAX);
400 
401 	ATF_REQUIRE(sdp_get_int(&test, &value));
402 	ATF_CHECK_EQ(value, INT8_MIN);
403 
404 	ATF_REQUIRE(sdp_get_int(&test, &value));
405 	ATF_CHECK_EQ(value, 0x0102);
406 
407 	ATF_REQUIRE(sdp_get_int(&test, &value));
408 	ATF_CHECK_EQ(value, INT16_MAX);
409 
410 	ATF_REQUIRE(sdp_get_int(&test, &value));
411 	ATF_CHECK_EQ(value, INT16_MIN);
412 
413 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* not int */
414 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
415 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
416 
417 	ATF_REQUIRE(sdp_get_int(&test, &value));
418 	ATF_CHECK_EQ(value, 0x01020304);
419 
420 	ATF_REQUIRE(sdp_get_int(&test, &value));
421 	ATF_CHECK_EQ(value, INT32_MAX);
422 
423 	ATF_REQUIRE(sdp_get_int(&test, &value));
424 	ATF_CHECK_EQ(value, INT32_MIN);
425 
426 	ATF_REQUIRE(sdp_get_int(&test, &value));
427 	ATF_CHECK_EQ(value, 0x0102030405060708);
428 
429 	ATF_REQUIRE(sdp_get_int(&test, &value));
430 	ATF_CHECK_EQ(value, INT64_MAX);
431 
432 	ATF_REQUIRE(sdp_get_int(&test, &value));
433 	ATF_CHECK_EQ(value, INT64_MIN);
434 
435 	/*
436 	 * expected failure is that we cannot decode INT128 values larger than INT64
437 	 */
438 	ATF_REQUIRE(sdp_get_int(&test, &value));
439 	ATF_CHECK_EQ(value, 0);
440 
441 	ATF_REQUIRE(sdp_get_int(&test, &value));
442 	ATF_CHECK_EQ(value, INT64_MAX);
443 
444 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* overflow */
445 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
446 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
447 
448 	ATF_REQUIRE(sdp_get_int(&test, &value));
449 	ATF_CHECK_EQ(value, INT64_MIN);
450 
451 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* underflow */
452 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
453 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
454 
455 	ATF_CHECK_EQ(test.next, test.end);
456 }
457 
458 ATF_TC(check_sdp_get_seq);
459 
ATF_TC_HEAD(check_sdp_get_seq,tc)460 ATF_TC_HEAD(check_sdp_get_seq, tc)
461 {
462 
463 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_seq results");
464 }
465 
ATF_TC_BODY(check_sdp_get_seq,tc)466 ATF_TC_BODY(check_sdp_get_seq, tc)
467 {
468 	uint8_t data[] = {
469 		0x35, 0x00,		// seq8(0)
470 		0x00,			// nil
471 		0x36, 0x00, 0x00,	// seq16(0)
472 		0x37, 0x00, 0x00, 0x00,	// seq32(0)
473 		0x00,
474 	};
475 	sdp_data_t test = { data, data + sizeof(data) };
476 	sdp_data_t value;
477 
478 	/*
479 	 * sdp_get_seq expects a SEQ type
480 	 * advancing test if successful
481 	 */
482 	ATF_REQUIRE(sdp_get_seq(&test, &value));
483 	ATF_CHECK_EQ(value.next, value.end);
484 
485 	ATF_REQUIRE_EQ(sdp_get_seq(&test, &value), false);	/* not seq */
486 	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
487 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
488 
489 	ATF_REQUIRE(sdp_get_seq(&test, &value));
490 	ATF_CHECK_EQ(value.next, value.end);
491 
492 	ATF_REQUIRE(sdp_get_seq(&test, &value));
493 	ATF_CHECK_EQ(value.next, value.end);
494 
495 	ATF_CHECK_EQ(test.next, test.end);
496 }
497 
498 ATF_TC(check_sdp_get_alt);
499 
ATF_TC_HEAD(check_sdp_get_alt,tc)500 ATF_TC_HEAD(check_sdp_get_alt, tc)
501 {
502 
503 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_alt results");
504 }
505 
ATF_TC_BODY(check_sdp_get_alt,tc)506 ATF_TC_BODY(check_sdp_get_alt, tc)
507 {
508 	uint8_t data[] = {
509 		0x3d, 0x00,		// alt8(0)
510 		0x00,			// nil
511 		0x3e, 0x00, 0x00,	// alt16(0)
512 		0x3f, 0x00, 0x00, 0x00,	// alt32(0)
513 		0x00,
514 	};
515 	sdp_data_t test = { data, data + sizeof(data) };
516 	sdp_data_t value;
517 
518 	/*
519 	 * sdp_get_alt expects a ALT type
520 	 * advancing test if successful
521 	 */
522 	ATF_REQUIRE(sdp_get_alt(&test, &value));
523 	ATF_CHECK_EQ(value.next, value.end);
524 
525 	ATF_REQUIRE_EQ(sdp_get_alt(&test, &value), false);	/* not alt */
526 	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
527 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
528 
529 	ATF_REQUIRE(sdp_get_alt(&test, &value));
530 	ATF_CHECK_EQ(value.next, value.end);
531 
532 	ATF_REQUIRE(sdp_get_alt(&test, &value));
533 	ATF_CHECK_EQ(value.next, value.end);
534 
535 	ATF_CHECK_EQ(test.next, test.end);
536 }
537 
538 ATF_TC(check_sdp_get_str);
539 
ATF_TC_HEAD(check_sdp_get_str,tc)540 ATF_TC_HEAD(check_sdp_get_str, tc)
541 {
542 
543 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_str results");
544 }
545 
ATF_TC_BODY(check_sdp_get_str,tc)546 ATF_TC_BODY(check_sdp_get_str, tc)
547 {
548 	uint8_t data[] = {
549 		0x25, 0x04, 0x53, 0x54, // str8(4)	"STR8"
550 		0x52, 0x38,
551 		0x00,			// nil
552 		0x26, 0x00, 0x05, 0x53,	// str16(5)	"STR16"
553 		0x54, 0x52, 0x31, 0x36,
554 		0x27, 0x00, 0x00, 0x00,	// str32(5)	"STR32"
555 		0x05, 0x53, 0x54, 0x52,
556 		0x33, 0x32,
557 	};
558 	sdp_data_t test = { data, data + sizeof(data) };
559 	sdp_data_t nil;
560 	char *str;
561 	size_t len;
562 
563 	/*
564 	 * sdp_get_str expects a STR type
565 	 * advancing test if successful
566 	 */
567 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
568 	ATF_CHECK(len == 4 && strncmp(str, "STR8", 4) == 0);
569 
570 	ATF_REQUIRE_EQ(sdp_get_str(&test, &str, &len), false);	/* not str */
571 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
572 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
573 
574 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
575 	ATF_CHECK(len == 5 && strncmp(str, "STR16", 5) == 0);
576 
577 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
578 	ATF_CHECK(len == 5 && strncmp(str, "STR32", 5) == 0);
579 
580 	ATF_CHECK_EQ(test.next, test.end);
581 }
582 
583 ATF_TC(check_sdp_get_url);
584 
ATF_TC_HEAD(check_sdp_get_url,tc)585 ATF_TC_HEAD(check_sdp_get_url, tc)
586 {
587 
588 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_url results");
589 }
590 
ATF_TC_BODY(check_sdp_get_url,tc)591 ATF_TC_BODY(check_sdp_get_url, tc)
592 {
593 	uint8_t data[] = {
594 		0x45, 0x04, 0x55, 0x52, // url8(4)	"URL8"
595 		0x4c, 0x38,
596 		0x00,			// nil
597 		0x46, 0x00, 0x05, 0x55,	// url16(5)	"URL16"
598 		0x52, 0x4c, 0x31, 0x36,
599 		0x47, 0x00, 0x00, 0x00,	// url32(5)	"URL32"
600 		0x05, 0x55, 0x52, 0x4c,
601 		0x33, 0x32,
602 	};
603 	sdp_data_t test = { data, data + sizeof(data) };
604 	sdp_data_t nil;
605 	char *url;
606 	size_t len;
607 
608 	/*
609 	 * sdp_get_url expects a URL type
610 	 * advancing test if successful
611 	 */
612 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
613 	ATF_CHECK(len == 4 && strncmp(url, "URL8", 4) == 0);
614 
615 	ATF_REQUIRE_EQ(sdp_get_url(&test, &url, &len), false);	/* not url */
616 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
617 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
618 
619 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
620 	ATF_CHECK(len == 5 && strncmp(url, "URL16", 5) == 0);
621 
622 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
623 	ATF_CHECK(len == 5 && strncmp(url, "URL32", 5) == 0);
624 
625 	ATF_CHECK_EQ(test.next, test.end);
626 }
627 
ATF_TP_ADD_TCS(tp)628 ATF_TP_ADD_TCS(tp)
629 {
630 
631 	ATF_TP_ADD_TC(tp, check_sdp_get_data);
632 	ATF_TP_ADD_TC(tp, check_sdp_get_attr);
633 	ATF_TP_ADD_TC(tp, check_sdp_get_uuid);
634 	ATF_TP_ADD_TC(tp, check_sdp_get_bool);
635 	ATF_TP_ADD_TC(tp, check_sdp_get_uint);
636 	ATF_TP_ADD_TC(tp, check_sdp_get_int);
637 	ATF_TP_ADD_TC(tp, check_sdp_get_seq);
638 	ATF_TP_ADD_TC(tp, check_sdp_get_alt);
639 	ATF_TP_ADD_TC(tp, check_sdp_get_str);
640 	ATF_TP_ADD_TC(tp, check_sdp_get_url);
641 
642 	return atf_no_error();
643 }
644