xref: /netbsd/tests/lib/libbluetooth/t_sdp_get.c (revision bc7c9260)
1*bc7c9260Splunky /*	$NetBSD: t_sdp_get.c,v 1.2 2011/04/07 08:29:50 plunky Exp $	*/
251b18cb6Splunky 
351b18cb6Splunky /*-
451b18cb6Splunky  * Copyright (c) 2011 The NetBSD Foundation, Inc.
551b18cb6Splunky  * All rights reserved.
651b18cb6Splunky  *
751b18cb6Splunky  * This code is derived from software contributed to The NetBSD Foundation
851b18cb6Splunky  * by Iain Hibbert.
951b18cb6Splunky  *
1051b18cb6Splunky  * Redistribution and use in source and binary forms, with or without
1151b18cb6Splunky  * modification, are permitted provided that the following conditions
1251b18cb6Splunky  * are met:
1351b18cb6Splunky  * 1. Redistributions of source code must retain the above copyright
1451b18cb6Splunky  *    notice, this list of conditions and the following disclaimer.
1551b18cb6Splunky  * 2. Redistributions in binary form must reproduce the above copyright
1651b18cb6Splunky  *    notice, this list of conditions and the following disclaimer in the
1751b18cb6Splunky  *    documentation and/or other materials provided with the distribution.
1851b18cb6Splunky  *
1951b18cb6Splunky  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2051b18cb6Splunky  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2151b18cb6Splunky  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2251b18cb6Splunky  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2351b18cb6Splunky  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2451b18cb6Splunky  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2551b18cb6Splunky  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2651b18cb6Splunky  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2751b18cb6Splunky  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2851b18cb6Splunky  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2951b18cb6Splunky  * POSSIBILITY OF SUCH DAMAGE.
3051b18cb6Splunky  */
3151b18cb6Splunky 
3251b18cb6Splunky #include <atf-c.h>
3351b18cb6Splunky 
3451b18cb6Splunky #include <limits.h>
3551b18cb6Splunky #include <sdp.h>
3651b18cb6Splunky #include <string.h>
3751b18cb6Splunky 
3851b18cb6Splunky ATF_TC(check_sdp_get_data);
3951b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_data,tc)4051b18cb6Splunky ATF_TC_HEAD(check_sdp_get_data, tc)
4151b18cb6Splunky {
4251b18cb6Splunky 
4351b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_data results");
4451b18cb6Splunky }
4551b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_data,tc)4651b18cb6Splunky ATF_TC_BODY(check_sdp_get_data, tc)
4751b18cb6Splunky {
4851b18cb6Splunky 	uint8_t data[] = {
4951b18cb6Splunky 		0x09, 0x00, 0x00,	// uint16	0x0000
5051b18cb6Splunky 		0x35, 0x05,		// seq8(5)
5151b18cb6Splunky 		0x19, 0x00, 0x00,	//   uuid16	0x0000
5251b18cb6Splunky 		0x08, 0x00,		//   uint8	0x00
5351b18cb6Splunky 		0x36, 0x00, 0x01,	// seq16(1)
5451b18cb6Splunky 		0x19,			//   uint16	/* invalid */
5551b18cb6Splunky 		0x25, 0x04, 0x54, 0x45,	// str8(4)	"TEST"
5651b18cb6Splunky 		0x53, 0x54,
5751b18cb6Splunky 	};
5851b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
5951b18cb6Splunky 	sdp_data_t value, seq;
6051b18cb6Splunky 
6151b18cb6Splunky 	/*
6251b18cb6Splunky 	 * sdp_get_data constructs a new sdp_data_t containing
6351b18cb6Splunky 	 * the next data element, advancing test if successful
6451b18cb6Splunky 	 */
6551b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
6651b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT16);
6751b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
6851b18cb6Splunky 
6951b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
7051b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
7151b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 7);
7251b18cb6Splunky 
7351b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
7451b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ16);
7551b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 4);
7651b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_seq(&value, &seq), true);
7751b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_data(&seq, &value), false);	/* invalid */
7851b18cb6Splunky 
7951b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
8051b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_STR8);
8151b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 6);
8251b18cb6Splunky 
8351b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
8451b18cb6Splunky }
8551b18cb6Splunky 
8651b18cb6Splunky ATF_TC(check_sdp_get_attr);
8751b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_attr,tc)8851b18cb6Splunky ATF_TC_HEAD(check_sdp_get_attr, tc)
8951b18cb6Splunky {
9051b18cb6Splunky 
9151b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_attr results");
9251b18cb6Splunky }
9351b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_attr,tc)9451b18cb6Splunky ATF_TC_BODY(check_sdp_get_attr, tc)
9551b18cb6Splunky {
9651b18cb6Splunky 	uint8_t data[] = {
9751b18cb6Splunky 		0x09, 0x00, 0x00,	// uint16	0x0000
9851b18cb6Splunky 		0x35, 0x05,		// seq8(5)
9951b18cb6Splunky 		0x19, 0x00, 0x00,	//   uuid16	0x0000
10051b18cb6Splunky 		0x08, 0x00,		//   uint8	0x00
10151b18cb6Splunky 		0x08, 0x00,		// uint8	0x00
10251b18cb6Splunky 		0x09, 0x00, 0x01,	// uint16	0x0001
10351b18cb6Splunky 		0x19, 0x12, 0x34,	// uuid16	0x1234
10451b18cb6Splunky 	};
10551b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
10651b18cb6Splunky 	sdp_data_t value;
10751b18cb6Splunky 	uint16_t attr;
10851b18cb6Splunky 
10951b18cb6Splunky 	/*
11051b18cb6Splunky 	 * sdp_get_attr expects a UINT16 followed by any data item
11151b18cb6Splunky 	 * and advances test if successful
11251b18cb6Splunky 	 */
11351b18cb6Splunky 	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
11451b18cb6Splunky 	ATF_CHECK_EQ(attr, 0x0000);
11551b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
11651b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 7);
11751b18cb6Splunky 
11851b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_attr(&test, &attr, &value), false);
11951b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
12051b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT8);
12151b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 2);
12251b18cb6Splunky 
12351b18cb6Splunky 	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
12451b18cb6Splunky 	ATF_CHECK_EQ(attr, 0x0001);
12551b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UUID16);
12651b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
12751b18cb6Splunky 
12851b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
12951b18cb6Splunky }
13051b18cb6Splunky 
13151b18cb6Splunky ATF_TC(check_sdp_get_uuid);
13251b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_uuid,tc)13351b18cb6Splunky ATF_TC_HEAD(check_sdp_get_uuid, tc)
13451b18cb6Splunky {
13551b18cb6Splunky 
13651b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uuid results");
13751b18cb6Splunky }
13851b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_uuid,tc)13951b18cb6Splunky ATF_TC_BODY(check_sdp_get_uuid, tc)
14051b18cb6Splunky {
14151b18cb6Splunky 	uint8_t data[] = {
14251b18cb6Splunky 		0x19, 0x12, 0x34,	// uuid16	0x1234
14351b18cb6Splunky 		0x1a, 0x11, 0x22, 0x33,	// uuid32	0x11223344
14451b18cb6Splunky 		0x44,
14551b18cb6Splunky 		0x00,			// nil
14651b18cb6Splunky 		0x1c,			// uuid128	0x00112233-4444--5555-6666-778899aabbcc
14751b18cb6Splunky 		0x00, 0x11, 0x22, 0x33,
14851b18cb6Splunky 		0x44, 0x44, 0x55, 0x55,
14951b18cb6Splunky 		0x66, 0x66, 0x77, 0x88,
15051b18cb6Splunky 		0x99, 0xaa, 0xbb, 0xcc,
15151b18cb6Splunky 	};
15251b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
15351b18cb6Splunky 	uuid_t u16 = {
15451b18cb6Splunky 		0x00001234,
15551b18cb6Splunky 		0x0000,
15651b18cb6Splunky 		0x1000,
15751b18cb6Splunky 		0x80,
15851b18cb6Splunky 		0x00,
15951b18cb6Splunky 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
16051b18cb6Splunky 	};
16151b18cb6Splunky 	uuid_t u32 = {
16251b18cb6Splunky 		0x11223344,
16351b18cb6Splunky 		0x0000,
16451b18cb6Splunky 		0x1000,
16551b18cb6Splunky 		0x80,
16651b18cb6Splunky 		0x00,
16751b18cb6Splunky 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
16851b18cb6Splunky 	};
16951b18cb6Splunky 	uuid_t u128 = {
17051b18cb6Splunky 		0x00112233,
17151b18cb6Splunky 		0x4444,
17251b18cb6Splunky 		0x5555,
17351b18cb6Splunky 		0x66,
17451b18cb6Splunky 		0x66,
17551b18cb6Splunky 		{ 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc }
17651b18cb6Splunky 	};
17751b18cb6Splunky 	sdp_data_t nil;
17851b18cb6Splunky 	uuid_t value;
17951b18cb6Splunky 
18051b18cb6Splunky 	/*
18151b18cb6Splunky 	 * sdp_get_uuid expects any UUID type returns the full uuid
18251b18cb6Splunky 	 * advancing test if successful
18351b18cb6Splunky 	 */
18451b18cb6Splunky 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
18551b18cb6Splunky 	ATF_CHECK(uuid_equal(&value, &u16, NULL));
18651b18cb6Splunky 
18751b18cb6Splunky 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
18851b18cb6Splunky 	ATF_CHECK(uuid_equal(&value, &u32, NULL));
18951b18cb6Splunky 
19051b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_uuid(&test, &value), false);	/* not uuid */
19151b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
19251b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
19351b18cb6Splunky 
19451b18cb6Splunky 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
19551b18cb6Splunky 	ATF_CHECK(uuid_equal(&value, &u128, NULL));
19651b18cb6Splunky 
19751b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
19851b18cb6Splunky }
19951b18cb6Splunky 
20051b18cb6Splunky ATF_TC(check_sdp_get_bool);
20151b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_bool,tc)20251b18cb6Splunky ATF_TC_HEAD(check_sdp_get_bool, tc)
20351b18cb6Splunky {
20451b18cb6Splunky 
20551b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_bool results");
20651b18cb6Splunky }
20751b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_bool,tc)20851b18cb6Splunky ATF_TC_BODY(check_sdp_get_bool, tc)
20951b18cb6Splunky {
21051b18cb6Splunky 	uint8_t data[] = {
21151b18cb6Splunky 		0x28, 0x00,	// bool		false
21251b18cb6Splunky 		0x00,		// nil
21351b18cb6Splunky 		0x28, 0x01,	// bool		true
21451b18cb6Splunky 	};
21551b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
21651b18cb6Splunky 	sdp_data_t nil;
21751b18cb6Splunky 	bool value;
21851b18cb6Splunky 
21951b18cb6Splunky 	/*
22051b18cb6Splunky 	 * sdp_get_bool expects a BOOL type
22151b18cb6Splunky 	 * advancing test if successful
22251b18cb6Splunky 	 */
22351b18cb6Splunky 	ATF_REQUIRE(sdp_get_bool(&test, &value));
22451b18cb6Splunky 	ATF_CHECK_EQ(value, false);
22551b18cb6Splunky 
22651b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_bool(&test, &value), false);	/* not bool */
22751b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
22851b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
22951b18cb6Splunky 
23051b18cb6Splunky 	ATF_REQUIRE(sdp_get_bool(&test, &value));
23151b18cb6Splunky 	ATF_CHECK_EQ(value, true);
23251b18cb6Splunky 
23351b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
23451b18cb6Splunky }
23551b18cb6Splunky 
23651b18cb6Splunky ATF_TC(check_sdp_get_uint);
23751b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_uint,tc)23851b18cb6Splunky ATF_TC_HEAD(check_sdp_get_uint, tc)
23951b18cb6Splunky {
24051b18cb6Splunky 
24151b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uint results");
24251b18cb6Splunky }
24351b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_uint,tc)24451b18cb6Splunky ATF_TC_BODY(check_sdp_get_uint, tc)
24551b18cb6Splunky {
24651b18cb6Splunky 	uint8_t data[] = {
24751b18cb6Splunky 		0x08, 0x00,		// uint8	0x00
24851b18cb6Splunky 		0x08, 0xff,		// uint8	0xff
24951b18cb6Splunky 		0x09, 0x01, 0x02,	// uint16	0x0102
25051b18cb6Splunky 		0x09, 0xff, 0xff,	// uint16	0xffff
25151b18cb6Splunky 		0x00,			// nil
25251b18cb6Splunky 		0x0a, 0x01, 0x02, 0x03,	// uint32	0x01020304
25351b18cb6Splunky 		0x04,
25451b18cb6Splunky 		0x0a, 0xff, 0xff, 0xff,	// uint32	0xffffffff
25551b18cb6Splunky 		0xff,
25651b18cb6Splunky 		0x0b, 0x01, 0x02, 0x03,	// uint64	0x0102030405060708
25751b18cb6Splunky 		0x04, 0x05, 0x06, 0x07,
25851b18cb6Splunky 		0x08,
25951b18cb6Splunky 		0x0b, 0xff, 0xff, 0xff,	// uint64	0xffffffffffffffff
26051b18cb6Splunky 		0xff, 0xff, 0xff, 0xff,
26151b18cb6Splunky 		0xff,
26251b18cb6Splunky 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000000000000000000000
26351b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
26451b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
26551b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
26651b18cb6Splunky 		0x00,
26751b18cb6Splunky 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000010000000000000000
26851b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
26951b18cb6Splunky 		0x01, 0x00, 0x00, 0x00,
27051b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
27151b18cb6Splunky 		0x00,
27251b18cb6Splunky 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x0000000000000000ffffffffffffffff
27351b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
27451b18cb6Splunky 		0x00, 0xff, 0xff, 0xff,
27551b18cb6Splunky 		0xff, 0xff, 0xff, 0xff,
27651b18cb6Splunky 		0xff,
27751b18cb6Splunky 	};
27851b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
27951b18cb6Splunky 	sdp_data_t nil;
28051b18cb6Splunky 	uintmax_t value;
28151b18cb6Splunky 
28251b18cb6Splunky 	/*
28351b18cb6Splunky 	 * sdp_get_uint expects any UINT type, advancing test if successful
28451b18cb6Splunky 	 */
28551b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
28651b18cb6Splunky 	ATF_CHECK_EQ(value, 0x00);
28751b18cb6Splunky 
28851b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
28951b18cb6Splunky 	ATF_CHECK_EQ(value, UINT8_MAX);
29051b18cb6Splunky 
29151b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
29251b18cb6Splunky 	ATF_CHECK_EQ(value, 0x0102);
29351b18cb6Splunky 
29451b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
29551b18cb6Splunky 	ATF_CHECK_EQ(value, UINT16_MAX);
29651b18cb6Splunky 
29751b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* not uint */
29851b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
29951b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
30051b18cb6Splunky 
30151b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
30251b18cb6Splunky 	ATF_CHECK_EQ(value, 0x01020304);
30351b18cb6Splunky 
30451b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
30551b18cb6Splunky 	ATF_CHECK_EQ(value, UINT32_MAX);
30651b18cb6Splunky 
30751b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
30851b18cb6Splunky 	ATF_CHECK_EQ(value, 0x0102030405060708);
30951b18cb6Splunky 
31051b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
31151b18cb6Splunky 	ATF_CHECK_EQ(value, UINT64_MAX);
31251b18cb6Splunky 
31351b18cb6Splunky 	/*
31451b18cb6Splunky 	 * expected failure is that we cannot decode UINT128 values larger than UINT64
31551b18cb6Splunky 	 */
31651b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
31751b18cb6Splunky 	ATF_CHECK_EQ(value, 0x00000000000000000000000000000000);
31851b18cb6Splunky 
31951b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* overflow */
32051b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
32151b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_UINT128);
32251b18cb6Splunky 
32351b18cb6Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
32451b18cb6Splunky 	ATF_CHECK_EQ(value, UINT64_MAX);
32551b18cb6Splunky 
32651b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
32751b18cb6Splunky }
32851b18cb6Splunky 
32951b18cb6Splunky ATF_TC(check_sdp_get_int);
33051b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_int,tc)33151b18cb6Splunky ATF_TC_HEAD(check_sdp_get_int, tc)
33251b18cb6Splunky {
33351b18cb6Splunky 
33451b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_int results");
33551b18cb6Splunky }
33651b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_int,tc)33751b18cb6Splunky ATF_TC_BODY(check_sdp_get_int, tc)
33851b18cb6Splunky {
33951b18cb6Splunky 	uint8_t data[] = {
34051b18cb6Splunky 		0x10, 0x00,		// int8		0x00
34151b18cb6Splunky 		0x10, 0x7f,		// int8		0x7f
34251b18cb6Splunky 		0x10, 0x80,		// int8		0x80
34351b18cb6Splunky 		0x11, 0x01, 0x02,	// int16	0x0102
34451b18cb6Splunky 		0x11, 0x7f, 0xff,	// int16	0x7fff
34551b18cb6Splunky 		0x11, 0x80, 0x00,	// int16	0x8000
34651b18cb6Splunky 		0x00,			// nil
34751b18cb6Splunky 		0x12, 0x01, 0x02, 0x03,	// int32	0x01020304
34851b18cb6Splunky 		0x04,
34951b18cb6Splunky 		0x12, 0x7f, 0xff, 0xff,	// int32	0x7fffffff
35051b18cb6Splunky 		0xff,
35151b18cb6Splunky 		0x12, 0x80, 0x00, 0x00,	// int32	0x80000000
35251b18cb6Splunky 		0x00,
35351b18cb6Splunky 		0x13, 0x01, 0x02, 0x03,	// int64	0x0102030405060708
35451b18cb6Splunky 		0x04, 0x05, 0x06, 0x07,
35551b18cb6Splunky 		0x08,
35651b18cb6Splunky 		0x13, 0x7f, 0xff, 0xff,	// int64	0x7fffffffffffffff
35751b18cb6Splunky 		0xff, 0xff, 0xff, 0xff,
35851b18cb6Splunky 		0xff,
35951b18cb6Splunky 		0x13, 0x80, 0x00, 0x00,	// int64	0x8000000000000000
36051b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
36151b18cb6Splunky 		0x00,
36251b18cb6Splunky 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000000000000000000000
36351b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
36451b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
36551b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
36651b18cb6Splunky 		0x00,
36751b18cb6Splunky 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000007fffffffffffffff
36851b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX)
36951b18cb6Splunky 		0x00, 0x7f, 0xff, 0xff,
37051b18cb6Splunky 		0xff, 0xff, 0xff, 0xff,
37151b18cb6Splunky 		0xff,
37251b18cb6Splunky 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000008000000000000000
37351b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX + 1)
37451b18cb6Splunky 		0x00, 0x80, 0x00, 0x00,
37551b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
37651b18cb6Splunky 		0x00,
37751b18cb6Splunky 		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff8000000000000000
37851b18cb6Splunky 		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN)
37951b18cb6Splunky 		0xff, 0x80, 0x00, 0x00,
38051b18cb6Splunky 		0x00, 0x00, 0x00, 0x00,
38151b18cb6Splunky 		0x00,
38251b18cb6Splunky 		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff7fffffffffffffff
38351b18cb6Splunky 		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN - 1)
38451b18cb6Splunky 		0xff, 0x7f, 0xff, 0xff,
38551b18cb6Splunky 		0xff, 0xff, 0xff, 0xff,
38651b18cb6Splunky 		0xff,
38751b18cb6Splunky 	};
38851b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
38951b18cb6Splunky 	sdp_data_t nil;
39051b18cb6Splunky 	intmax_t value;
39151b18cb6Splunky 
39251b18cb6Splunky 	/*
39351b18cb6Splunky 	 * sdp_get_int expects any INT type, advancing test if successful
39451b18cb6Splunky 	 */
39551b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
39651b18cb6Splunky 	ATF_CHECK_EQ(value, 0);
39751b18cb6Splunky 
39851b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
39951b18cb6Splunky 	ATF_CHECK_EQ(value, INT8_MAX);
40051b18cb6Splunky 
40151b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
40251b18cb6Splunky 	ATF_CHECK_EQ(value, INT8_MIN);
40351b18cb6Splunky 
40451b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
40551b18cb6Splunky 	ATF_CHECK_EQ(value, 0x0102);
40651b18cb6Splunky 
40751b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
40851b18cb6Splunky 	ATF_CHECK_EQ(value, INT16_MAX);
40951b18cb6Splunky 
41051b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
41151b18cb6Splunky 	ATF_CHECK_EQ(value, INT16_MIN);
41251b18cb6Splunky 
41351b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* not int */
41451b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
41551b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
41651b18cb6Splunky 
41751b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
41851b18cb6Splunky 	ATF_CHECK_EQ(value, 0x01020304);
41951b18cb6Splunky 
42051b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
42151b18cb6Splunky 	ATF_CHECK_EQ(value, INT32_MAX);
42251b18cb6Splunky 
42351b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
42451b18cb6Splunky 	ATF_CHECK_EQ(value, INT32_MIN);
42551b18cb6Splunky 
42651b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
42751b18cb6Splunky 	ATF_CHECK_EQ(value, 0x0102030405060708);
42851b18cb6Splunky 
42951b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
43051b18cb6Splunky 	ATF_CHECK_EQ(value, INT64_MAX);
43151b18cb6Splunky 
43251b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
43351b18cb6Splunky 	ATF_CHECK_EQ(value, INT64_MIN);
43451b18cb6Splunky 
43551b18cb6Splunky 	/*
43651b18cb6Splunky 	 * expected failure is that we cannot decode INT128 values larger than INT64
43751b18cb6Splunky 	 */
43851b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
43951b18cb6Splunky 	ATF_CHECK_EQ(value, 0);
44051b18cb6Splunky 
44151b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
44251b18cb6Splunky 	ATF_CHECK_EQ(value, INT64_MAX);
44351b18cb6Splunky 
44451b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* overflow */
44551b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
44651b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
44751b18cb6Splunky 
44851b18cb6Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
44951b18cb6Splunky 	ATF_CHECK_EQ(value, INT64_MIN);
45051b18cb6Splunky 
45151b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* underflow */
45251b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
45351b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
45451b18cb6Splunky 
45551b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
45651b18cb6Splunky }
45751b18cb6Splunky 
45851b18cb6Splunky ATF_TC(check_sdp_get_seq);
45951b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_seq,tc)46051b18cb6Splunky ATF_TC_HEAD(check_sdp_get_seq, tc)
46151b18cb6Splunky {
46251b18cb6Splunky 
46351b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_seq results");
46451b18cb6Splunky }
46551b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_seq,tc)46651b18cb6Splunky ATF_TC_BODY(check_sdp_get_seq, tc)
46751b18cb6Splunky {
46851b18cb6Splunky 	uint8_t data[] = {
46951b18cb6Splunky 		0x35, 0x00,		// seq8(0)
47051b18cb6Splunky 		0x00,			// nil
47151b18cb6Splunky 		0x36, 0x00, 0x00,	// seq16(0)
47251b18cb6Splunky 		0x37, 0x00, 0x00, 0x00,	// seq32(0)
47351b18cb6Splunky 		0x00,
47451b18cb6Splunky 	};
47551b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
47651b18cb6Splunky 	sdp_data_t value;
47751b18cb6Splunky 
47851b18cb6Splunky 	/*
47951b18cb6Splunky 	 * sdp_get_seq expects a SEQ type
48051b18cb6Splunky 	 * advancing test if successful
48151b18cb6Splunky 	 */
48251b18cb6Splunky 	ATF_REQUIRE(sdp_get_seq(&test, &value));
48351b18cb6Splunky 	ATF_CHECK_EQ(value.next, value.end);
48451b18cb6Splunky 
48551b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_seq(&test, &value), false);	/* not seq */
48651b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
48751b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
48851b18cb6Splunky 
48951b18cb6Splunky 	ATF_REQUIRE(sdp_get_seq(&test, &value));
49051b18cb6Splunky 	ATF_CHECK_EQ(value.next, value.end);
49151b18cb6Splunky 
49251b18cb6Splunky 	ATF_REQUIRE(sdp_get_seq(&test, &value));
49351b18cb6Splunky 	ATF_CHECK_EQ(value.next, value.end);
49451b18cb6Splunky 
49551b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
49651b18cb6Splunky }
49751b18cb6Splunky 
49851b18cb6Splunky ATF_TC(check_sdp_get_alt);
49951b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_alt,tc)50051b18cb6Splunky ATF_TC_HEAD(check_sdp_get_alt, tc)
50151b18cb6Splunky {
50251b18cb6Splunky 
50351b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_alt results");
50451b18cb6Splunky }
50551b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_alt,tc)50651b18cb6Splunky ATF_TC_BODY(check_sdp_get_alt, tc)
50751b18cb6Splunky {
50851b18cb6Splunky 	uint8_t data[] = {
50951b18cb6Splunky 		0x3d, 0x00,		// alt8(0)
51051b18cb6Splunky 		0x00,			// nil
51151b18cb6Splunky 		0x3e, 0x00, 0x00,	// alt16(0)
51251b18cb6Splunky 		0x3f, 0x00, 0x00, 0x00,	// alt32(0)
51351b18cb6Splunky 		0x00,
51451b18cb6Splunky 	};
51551b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
51651b18cb6Splunky 	sdp_data_t value;
51751b18cb6Splunky 
51851b18cb6Splunky 	/*
51951b18cb6Splunky 	 * sdp_get_alt expects a ALT type
52051b18cb6Splunky 	 * advancing test if successful
52151b18cb6Splunky 	 */
52251b18cb6Splunky 	ATF_REQUIRE(sdp_get_alt(&test, &value));
52351b18cb6Splunky 	ATF_CHECK_EQ(value.next, value.end);
52451b18cb6Splunky 
52551b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_alt(&test, &value), false);	/* not alt */
52651b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
52751b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
52851b18cb6Splunky 
52951b18cb6Splunky 	ATF_REQUIRE(sdp_get_alt(&test, &value));
53051b18cb6Splunky 	ATF_CHECK_EQ(value.next, value.end);
53151b18cb6Splunky 
53251b18cb6Splunky 	ATF_REQUIRE(sdp_get_alt(&test, &value));
53351b18cb6Splunky 	ATF_CHECK_EQ(value.next, value.end);
53451b18cb6Splunky 
53551b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
53651b18cb6Splunky }
53751b18cb6Splunky 
53851b18cb6Splunky ATF_TC(check_sdp_get_str);
53951b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_str,tc)54051b18cb6Splunky ATF_TC_HEAD(check_sdp_get_str, tc)
54151b18cb6Splunky {
54251b18cb6Splunky 
54351b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_str results");
54451b18cb6Splunky }
54551b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_str,tc)54651b18cb6Splunky ATF_TC_BODY(check_sdp_get_str, tc)
54751b18cb6Splunky {
54851b18cb6Splunky 	uint8_t data[] = {
54951b18cb6Splunky 		0x25, 0x04, 0x53, 0x54, // str8(4)	"STR8"
55051b18cb6Splunky 		0x52, 0x38,
55151b18cb6Splunky 		0x00,			// nil
55251b18cb6Splunky 		0x26, 0x00, 0x05, 0x53,	// str16(5)	"STR16"
55351b18cb6Splunky 		0x54, 0x52, 0x31, 0x36,
55451b18cb6Splunky 		0x27, 0x00, 0x00, 0x00,	// str32(5)	"STR32"
55551b18cb6Splunky 		0x05, 0x53, 0x54, 0x52,
55651b18cb6Splunky 		0x33, 0x32,
55751b18cb6Splunky 	};
55851b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
55951b18cb6Splunky 	sdp_data_t nil;
56051b18cb6Splunky 	char *str;
56151b18cb6Splunky 	size_t len;
56251b18cb6Splunky 
56351b18cb6Splunky 	/*
56451b18cb6Splunky 	 * sdp_get_str expects a STR type
56551b18cb6Splunky 	 * advancing test if successful
56651b18cb6Splunky 	 */
56751b18cb6Splunky 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
56851b18cb6Splunky 	ATF_CHECK(len == 4 && strncmp(str, "STR8", 4) == 0);
56951b18cb6Splunky 
57051b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_str(&test, &str, &len), false);	/* not str */
57151b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
57251b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
57351b18cb6Splunky 
57451b18cb6Splunky 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
57551b18cb6Splunky 	ATF_CHECK(len == 5 && strncmp(str, "STR16", 5) == 0);
57651b18cb6Splunky 
57751b18cb6Splunky 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
57851b18cb6Splunky 	ATF_CHECK(len == 5 && strncmp(str, "STR32", 5) == 0);
57951b18cb6Splunky 
58051b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
58151b18cb6Splunky }
58251b18cb6Splunky 
58351b18cb6Splunky ATF_TC(check_sdp_get_url);
58451b18cb6Splunky 
ATF_TC_HEAD(check_sdp_get_url,tc)58551b18cb6Splunky ATF_TC_HEAD(check_sdp_get_url, tc)
58651b18cb6Splunky {
58751b18cb6Splunky 
58851b18cb6Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_url results");
58951b18cb6Splunky }
59051b18cb6Splunky 
ATF_TC_BODY(check_sdp_get_url,tc)59151b18cb6Splunky ATF_TC_BODY(check_sdp_get_url, tc)
59251b18cb6Splunky {
59351b18cb6Splunky 	uint8_t data[] = {
59451b18cb6Splunky 		0x45, 0x04, 0x55, 0x52, // url8(4)	"URL8"
59551b18cb6Splunky 		0x4c, 0x38,
59651b18cb6Splunky 		0x00,			// nil
59751b18cb6Splunky 		0x46, 0x00, 0x05, 0x55,	// url16(5)	"URL16"
59851b18cb6Splunky 		0x52, 0x4c, 0x31, 0x36,
59951b18cb6Splunky 		0x47, 0x00, 0x00, 0x00,	// url32(5)	"URL32"
60051b18cb6Splunky 		0x05, 0x55, 0x52, 0x4c,
60151b18cb6Splunky 		0x33, 0x32,
60251b18cb6Splunky 	};
60351b18cb6Splunky 	sdp_data_t test = { data, data + sizeof(data) };
60451b18cb6Splunky 	sdp_data_t nil;
60551b18cb6Splunky 	char *url;
60651b18cb6Splunky 	size_t len;
60751b18cb6Splunky 
60851b18cb6Splunky 	/*
60951b18cb6Splunky 	 * sdp_get_url expects a URL type
61051b18cb6Splunky 	 * advancing test if successful
61151b18cb6Splunky 	 */
61251b18cb6Splunky 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
61351b18cb6Splunky 	ATF_CHECK(len == 4 && strncmp(url, "URL8", 4) == 0);
61451b18cb6Splunky 
61551b18cb6Splunky 	ATF_REQUIRE_EQ(sdp_get_url(&test, &url, &len), false);	/* not url */
61651b18cb6Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
61751b18cb6Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
61851b18cb6Splunky 
61951b18cb6Splunky 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
62051b18cb6Splunky 	ATF_CHECK(len == 5 && strncmp(url, "URL16", 5) == 0);
62151b18cb6Splunky 
62251b18cb6Splunky 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
62351b18cb6Splunky 	ATF_CHECK(len == 5 && strncmp(url, "URL32", 5) == 0);
62451b18cb6Splunky 
62551b18cb6Splunky 	ATF_CHECK_EQ(test.next, test.end);
62651b18cb6Splunky }
62751b18cb6Splunky 
ATF_TP_ADD_TCS(tp)62851b18cb6Splunky ATF_TP_ADD_TCS(tp)
62951b18cb6Splunky {
63051b18cb6Splunky 
63151b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_data);
63251b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_attr);
63351b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_uuid);
63451b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_bool);
63551b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_uint);
63651b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_int);
63751b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_seq);
63851b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_alt);
63951b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_str);
64051b18cb6Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_url);
64151b18cb6Splunky 
64251b18cb6Splunky 	return atf_no_error();
64351b18cb6Splunky }
644