xref: /netbsd-src/tests/lib/libbluetooth/t_sdp_get.c (revision 5a4807fa7d17d0c1280be680686b5965edb14b8f)
1*5a4807faSplunky /*	$NetBSD: t_sdp_get.c,v 1.2 2011/04/07 08:29:50 plunky Exp $	*/
238293af7Splunky 
338293af7Splunky /*-
438293af7Splunky  * Copyright (c) 2011 The NetBSD Foundation, Inc.
538293af7Splunky  * All rights reserved.
638293af7Splunky  *
738293af7Splunky  * This code is derived from software contributed to The NetBSD Foundation
838293af7Splunky  * by Iain Hibbert.
938293af7Splunky  *
1038293af7Splunky  * Redistribution and use in source and binary forms, with or without
1138293af7Splunky  * modification, are permitted provided that the following conditions
1238293af7Splunky  * are met:
1338293af7Splunky  * 1. Redistributions of source code must retain the above copyright
1438293af7Splunky  *    notice, this list of conditions and the following disclaimer.
1538293af7Splunky  * 2. Redistributions in binary form must reproduce the above copyright
1638293af7Splunky  *    notice, this list of conditions and the following disclaimer in the
1738293af7Splunky  *    documentation and/or other materials provided with the distribution.
1838293af7Splunky  *
1938293af7Splunky  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2038293af7Splunky  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2138293af7Splunky  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2238293af7Splunky  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2338293af7Splunky  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2438293af7Splunky  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2538293af7Splunky  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2638293af7Splunky  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2738293af7Splunky  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2838293af7Splunky  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2938293af7Splunky  * POSSIBILITY OF SUCH DAMAGE.
3038293af7Splunky  */
3138293af7Splunky 
3238293af7Splunky #include <atf-c.h>
3338293af7Splunky 
3438293af7Splunky #include <limits.h>
3538293af7Splunky #include <sdp.h>
3638293af7Splunky #include <string.h>
3738293af7Splunky 
3838293af7Splunky ATF_TC(check_sdp_get_data);
3938293af7Splunky 
ATF_TC_HEAD(check_sdp_get_data,tc)4038293af7Splunky ATF_TC_HEAD(check_sdp_get_data, tc)
4138293af7Splunky {
4238293af7Splunky 
4338293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_data results");
4438293af7Splunky }
4538293af7Splunky 
ATF_TC_BODY(check_sdp_get_data,tc)4638293af7Splunky ATF_TC_BODY(check_sdp_get_data, tc)
4738293af7Splunky {
4838293af7Splunky 	uint8_t data[] = {
4938293af7Splunky 		0x09, 0x00, 0x00,	// uint16	0x0000
5038293af7Splunky 		0x35, 0x05,		// seq8(5)
5138293af7Splunky 		0x19, 0x00, 0x00,	//   uuid16	0x0000
5238293af7Splunky 		0x08, 0x00,		//   uint8	0x00
5338293af7Splunky 		0x36, 0x00, 0x01,	// seq16(1)
5438293af7Splunky 		0x19,			//   uint16	/* invalid */
5538293af7Splunky 		0x25, 0x04, 0x54, 0x45,	// str8(4)	"TEST"
5638293af7Splunky 		0x53, 0x54,
5738293af7Splunky 	};
5838293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
5938293af7Splunky 	sdp_data_t value, seq;
6038293af7Splunky 
6138293af7Splunky 	/*
6238293af7Splunky 	 * sdp_get_data constructs a new sdp_data_t containing
6338293af7Splunky 	 * the next data element, advancing test if successful
6438293af7Splunky 	 */
6538293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
6638293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT16);
6738293af7Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
6838293af7Splunky 
6938293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
7038293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
7138293af7Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 7);
7238293af7Splunky 
7338293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
7438293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ16);
7538293af7Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 4);
7638293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_seq(&value, &seq), true);
7738293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_data(&seq, &value), false);	/* invalid */
7838293af7Splunky 
7938293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
8038293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_STR8);
8138293af7Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 6);
8238293af7Splunky 
8338293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
8438293af7Splunky }
8538293af7Splunky 
8638293af7Splunky ATF_TC(check_sdp_get_attr);
8738293af7Splunky 
ATF_TC_HEAD(check_sdp_get_attr,tc)8838293af7Splunky ATF_TC_HEAD(check_sdp_get_attr, tc)
8938293af7Splunky {
9038293af7Splunky 
9138293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_attr results");
9238293af7Splunky }
9338293af7Splunky 
ATF_TC_BODY(check_sdp_get_attr,tc)9438293af7Splunky ATF_TC_BODY(check_sdp_get_attr, tc)
9538293af7Splunky {
9638293af7Splunky 	uint8_t data[] = {
9738293af7Splunky 		0x09, 0x00, 0x00,	// uint16	0x0000
9838293af7Splunky 		0x35, 0x05,		// seq8(5)
9938293af7Splunky 		0x19, 0x00, 0x00,	//   uuid16	0x0000
10038293af7Splunky 		0x08, 0x00,		//   uint8	0x00
10138293af7Splunky 		0x08, 0x00,		// uint8	0x00
10238293af7Splunky 		0x09, 0x00, 0x01,	// uint16	0x0001
10338293af7Splunky 		0x19, 0x12, 0x34,	// uuid16	0x1234
10438293af7Splunky 	};
10538293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
10638293af7Splunky 	sdp_data_t value;
10738293af7Splunky 	uint16_t attr;
10838293af7Splunky 
10938293af7Splunky 	/*
11038293af7Splunky 	 * sdp_get_attr expects a UINT16 followed by any data item
11138293af7Splunky 	 * and advances test if successful
11238293af7Splunky 	 */
11338293af7Splunky 	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
11438293af7Splunky 	ATF_CHECK_EQ(attr, 0x0000);
11538293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
11638293af7Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 7);
11738293af7Splunky 
11838293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_attr(&test, &attr, &value), false);
11938293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));
12038293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT8);
12138293af7Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 2);
12238293af7Splunky 
12338293af7Splunky 	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
12438293af7Splunky 	ATF_CHECK_EQ(attr, 0x0001);
12538293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UUID16);
12638293af7Splunky 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
12738293af7Splunky 
12838293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
12938293af7Splunky }
13038293af7Splunky 
13138293af7Splunky ATF_TC(check_sdp_get_uuid);
13238293af7Splunky 
ATF_TC_HEAD(check_sdp_get_uuid,tc)13338293af7Splunky ATF_TC_HEAD(check_sdp_get_uuid, tc)
13438293af7Splunky {
13538293af7Splunky 
13638293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uuid results");
13738293af7Splunky }
13838293af7Splunky 
ATF_TC_BODY(check_sdp_get_uuid,tc)13938293af7Splunky ATF_TC_BODY(check_sdp_get_uuid, tc)
14038293af7Splunky {
14138293af7Splunky 	uint8_t data[] = {
14238293af7Splunky 		0x19, 0x12, 0x34,	// uuid16	0x1234
14338293af7Splunky 		0x1a, 0x11, 0x22, 0x33,	// uuid32	0x11223344
14438293af7Splunky 		0x44,
14538293af7Splunky 		0x00,			// nil
14638293af7Splunky 		0x1c,			// uuid128	0x00112233-4444--5555-6666-778899aabbcc
14738293af7Splunky 		0x00, 0x11, 0x22, 0x33,
14838293af7Splunky 		0x44, 0x44, 0x55, 0x55,
14938293af7Splunky 		0x66, 0x66, 0x77, 0x88,
15038293af7Splunky 		0x99, 0xaa, 0xbb, 0xcc,
15138293af7Splunky 	};
15238293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
15338293af7Splunky 	uuid_t u16 = {
15438293af7Splunky 		0x00001234,
15538293af7Splunky 		0x0000,
15638293af7Splunky 		0x1000,
15738293af7Splunky 		0x80,
15838293af7Splunky 		0x00,
15938293af7Splunky 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
16038293af7Splunky 	};
16138293af7Splunky 	uuid_t u32 = {
16238293af7Splunky 		0x11223344,
16338293af7Splunky 		0x0000,
16438293af7Splunky 		0x1000,
16538293af7Splunky 		0x80,
16638293af7Splunky 		0x00,
16738293af7Splunky 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
16838293af7Splunky 	};
16938293af7Splunky 	uuid_t u128 = {
17038293af7Splunky 		0x00112233,
17138293af7Splunky 		0x4444,
17238293af7Splunky 		0x5555,
17338293af7Splunky 		0x66,
17438293af7Splunky 		0x66,
17538293af7Splunky 		{ 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc }
17638293af7Splunky 	};
17738293af7Splunky 	sdp_data_t nil;
17838293af7Splunky 	uuid_t value;
17938293af7Splunky 
18038293af7Splunky 	/*
18138293af7Splunky 	 * sdp_get_uuid expects any UUID type returns the full uuid
18238293af7Splunky 	 * advancing test if successful
18338293af7Splunky 	 */
18438293af7Splunky 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
18538293af7Splunky 	ATF_CHECK(uuid_equal(&value, &u16, NULL));
18638293af7Splunky 
18738293af7Splunky 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
18838293af7Splunky 	ATF_CHECK(uuid_equal(&value, &u32, NULL));
18938293af7Splunky 
19038293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_uuid(&test, &value), false);	/* not uuid */
19138293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
19238293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
19338293af7Splunky 
19438293af7Splunky 	ATF_REQUIRE(sdp_get_uuid(&test, &value));
19538293af7Splunky 	ATF_CHECK(uuid_equal(&value, &u128, NULL));
19638293af7Splunky 
19738293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
19838293af7Splunky }
19938293af7Splunky 
20038293af7Splunky ATF_TC(check_sdp_get_bool);
20138293af7Splunky 
ATF_TC_HEAD(check_sdp_get_bool,tc)20238293af7Splunky ATF_TC_HEAD(check_sdp_get_bool, tc)
20338293af7Splunky {
20438293af7Splunky 
20538293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_bool results");
20638293af7Splunky }
20738293af7Splunky 
ATF_TC_BODY(check_sdp_get_bool,tc)20838293af7Splunky ATF_TC_BODY(check_sdp_get_bool, tc)
20938293af7Splunky {
21038293af7Splunky 	uint8_t data[] = {
21138293af7Splunky 		0x28, 0x00,	// bool		false
21238293af7Splunky 		0x00,		// nil
21338293af7Splunky 		0x28, 0x01,	// bool		true
21438293af7Splunky 	};
21538293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
21638293af7Splunky 	sdp_data_t nil;
21738293af7Splunky 	bool value;
21838293af7Splunky 
21938293af7Splunky 	/*
22038293af7Splunky 	 * sdp_get_bool expects a BOOL type
22138293af7Splunky 	 * advancing test if successful
22238293af7Splunky 	 */
22338293af7Splunky 	ATF_REQUIRE(sdp_get_bool(&test, &value));
22438293af7Splunky 	ATF_CHECK_EQ(value, false);
22538293af7Splunky 
22638293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_bool(&test, &value), false);	/* not bool */
22738293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
22838293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
22938293af7Splunky 
23038293af7Splunky 	ATF_REQUIRE(sdp_get_bool(&test, &value));
23138293af7Splunky 	ATF_CHECK_EQ(value, true);
23238293af7Splunky 
23338293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
23438293af7Splunky }
23538293af7Splunky 
23638293af7Splunky ATF_TC(check_sdp_get_uint);
23738293af7Splunky 
ATF_TC_HEAD(check_sdp_get_uint,tc)23838293af7Splunky ATF_TC_HEAD(check_sdp_get_uint, tc)
23938293af7Splunky {
24038293af7Splunky 
24138293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uint results");
24238293af7Splunky }
24338293af7Splunky 
ATF_TC_BODY(check_sdp_get_uint,tc)24438293af7Splunky ATF_TC_BODY(check_sdp_get_uint, tc)
24538293af7Splunky {
24638293af7Splunky 	uint8_t data[] = {
24738293af7Splunky 		0x08, 0x00,		// uint8	0x00
24838293af7Splunky 		0x08, 0xff,		// uint8	0xff
24938293af7Splunky 		0x09, 0x01, 0x02,	// uint16	0x0102
25038293af7Splunky 		0x09, 0xff, 0xff,	// uint16	0xffff
25138293af7Splunky 		0x00,			// nil
25238293af7Splunky 		0x0a, 0x01, 0x02, 0x03,	// uint32	0x01020304
25338293af7Splunky 		0x04,
25438293af7Splunky 		0x0a, 0xff, 0xff, 0xff,	// uint32	0xffffffff
25538293af7Splunky 		0xff,
25638293af7Splunky 		0x0b, 0x01, 0x02, 0x03,	// uint64	0x0102030405060708
25738293af7Splunky 		0x04, 0x05, 0x06, 0x07,
25838293af7Splunky 		0x08,
25938293af7Splunky 		0x0b, 0xff, 0xff, 0xff,	// uint64	0xffffffffffffffff
26038293af7Splunky 		0xff, 0xff, 0xff, 0xff,
26138293af7Splunky 		0xff,
26238293af7Splunky 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000000000000000000000
26338293af7Splunky 		0x00, 0x00, 0x00, 0x00,
26438293af7Splunky 		0x00, 0x00, 0x00, 0x00,
26538293af7Splunky 		0x00, 0x00, 0x00, 0x00,
26638293af7Splunky 		0x00,
26738293af7Splunky 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000010000000000000000
26838293af7Splunky 		0x00, 0x00, 0x00, 0x00,
26938293af7Splunky 		0x01, 0x00, 0x00, 0x00,
27038293af7Splunky 		0x00, 0x00, 0x00, 0x00,
27138293af7Splunky 		0x00,
27238293af7Splunky 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x0000000000000000ffffffffffffffff
27338293af7Splunky 		0x00, 0x00, 0x00, 0x00,
27438293af7Splunky 		0x00, 0xff, 0xff, 0xff,
27538293af7Splunky 		0xff, 0xff, 0xff, 0xff,
27638293af7Splunky 		0xff,
27738293af7Splunky 	};
27838293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
27938293af7Splunky 	sdp_data_t nil;
28038293af7Splunky 	uintmax_t value;
28138293af7Splunky 
28238293af7Splunky 	/*
28338293af7Splunky 	 * sdp_get_uint expects any UINT type, advancing test if successful
28438293af7Splunky 	 */
28538293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
28638293af7Splunky 	ATF_CHECK_EQ(value, 0x00);
28738293af7Splunky 
28838293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
28938293af7Splunky 	ATF_CHECK_EQ(value, UINT8_MAX);
29038293af7Splunky 
29138293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
29238293af7Splunky 	ATF_CHECK_EQ(value, 0x0102);
29338293af7Splunky 
29438293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
29538293af7Splunky 	ATF_CHECK_EQ(value, UINT16_MAX);
29638293af7Splunky 
29738293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* not uint */
29838293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
29938293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
30038293af7Splunky 
30138293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
30238293af7Splunky 	ATF_CHECK_EQ(value, 0x01020304);
30338293af7Splunky 
30438293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
30538293af7Splunky 	ATF_CHECK_EQ(value, UINT32_MAX);
30638293af7Splunky 
30738293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
30838293af7Splunky 	ATF_CHECK_EQ(value, 0x0102030405060708);
30938293af7Splunky 
31038293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
31138293af7Splunky 	ATF_CHECK_EQ(value, UINT64_MAX);
31238293af7Splunky 
31338293af7Splunky 	/*
31438293af7Splunky 	 * expected failure is that we cannot decode UINT128 values larger than UINT64
31538293af7Splunky 	 */
31638293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
31738293af7Splunky 	ATF_CHECK_EQ(value, 0x00000000000000000000000000000000);
31838293af7Splunky 
31938293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* overflow */
32038293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
32138293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_UINT128);
32238293af7Splunky 
32338293af7Splunky 	ATF_REQUIRE(sdp_get_uint(&test, &value));
32438293af7Splunky 	ATF_CHECK_EQ(value, UINT64_MAX);
32538293af7Splunky 
32638293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
32738293af7Splunky }
32838293af7Splunky 
32938293af7Splunky ATF_TC(check_sdp_get_int);
33038293af7Splunky 
ATF_TC_HEAD(check_sdp_get_int,tc)33138293af7Splunky ATF_TC_HEAD(check_sdp_get_int, tc)
33238293af7Splunky {
33338293af7Splunky 
33438293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_int results");
33538293af7Splunky }
33638293af7Splunky 
ATF_TC_BODY(check_sdp_get_int,tc)33738293af7Splunky ATF_TC_BODY(check_sdp_get_int, tc)
33838293af7Splunky {
33938293af7Splunky 	uint8_t data[] = {
34038293af7Splunky 		0x10, 0x00,		// int8		0x00
34138293af7Splunky 		0x10, 0x7f,		// int8		0x7f
34238293af7Splunky 		0x10, 0x80,		// int8		0x80
34338293af7Splunky 		0x11, 0x01, 0x02,	// int16	0x0102
34438293af7Splunky 		0x11, 0x7f, 0xff,	// int16	0x7fff
34538293af7Splunky 		0x11, 0x80, 0x00,	// int16	0x8000
34638293af7Splunky 		0x00,			// nil
34738293af7Splunky 		0x12, 0x01, 0x02, 0x03,	// int32	0x01020304
34838293af7Splunky 		0x04,
34938293af7Splunky 		0x12, 0x7f, 0xff, 0xff,	// int32	0x7fffffff
35038293af7Splunky 		0xff,
35138293af7Splunky 		0x12, 0x80, 0x00, 0x00,	// int32	0x80000000
35238293af7Splunky 		0x00,
35338293af7Splunky 		0x13, 0x01, 0x02, 0x03,	// int64	0x0102030405060708
35438293af7Splunky 		0x04, 0x05, 0x06, 0x07,
35538293af7Splunky 		0x08,
35638293af7Splunky 		0x13, 0x7f, 0xff, 0xff,	// int64	0x7fffffffffffffff
35738293af7Splunky 		0xff, 0xff, 0xff, 0xff,
35838293af7Splunky 		0xff,
35938293af7Splunky 		0x13, 0x80, 0x00, 0x00,	// int64	0x8000000000000000
36038293af7Splunky 		0x00, 0x00, 0x00, 0x00,
36138293af7Splunky 		0x00,
36238293af7Splunky 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000000000000000000000
36338293af7Splunky 		0x00, 0x00, 0x00, 0x00,
36438293af7Splunky 		0x00, 0x00, 0x00, 0x00,
36538293af7Splunky 		0x00, 0x00, 0x00, 0x00,
36638293af7Splunky 		0x00,
36738293af7Splunky 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000007fffffffffffffff
36838293af7Splunky 		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX)
36938293af7Splunky 		0x00, 0x7f, 0xff, 0xff,
37038293af7Splunky 		0xff, 0xff, 0xff, 0xff,
37138293af7Splunky 		0xff,
37238293af7Splunky 		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000008000000000000000
37338293af7Splunky 		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX + 1)
37438293af7Splunky 		0x00, 0x80, 0x00, 0x00,
37538293af7Splunky 		0x00, 0x00, 0x00, 0x00,
37638293af7Splunky 		0x00,
37738293af7Splunky 		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff8000000000000000
37838293af7Splunky 		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN)
37938293af7Splunky 		0xff, 0x80, 0x00, 0x00,
38038293af7Splunky 		0x00, 0x00, 0x00, 0x00,
38138293af7Splunky 		0x00,
38238293af7Splunky 		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff7fffffffffffffff
38338293af7Splunky 		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN - 1)
38438293af7Splunky 		0xff, 0x7f, 0xff, 0xff,
38538293af7Splunky 		0xff, 0xff, 0xff, 0xff,
38638293af7Splunky 		0xff,
38738293af7Splunky 	};
38838293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
38938293af7Splunky 	sdp_data_t nil;
39038293af7Splunky 	intmax_t value;
39138293af7Splunky 
39238293af7Splunky 	/*
39338293af7Splunky 	 * sdp_get_int expects any INT type, advancing test if successful
39438293af7Splunky 	 */
39538293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
39638293af7Splunky 	ATF_CHECK_EQ(value, 0);
39738293af7Splunky 
39838293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
39938293af7Splunky 	ATF_CHECK_EQ(value, INT8_MAX);
40038293af7Splunky 
40138293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
40238293af7Splunky 	ATF_CHECK_EQ(value, INT8_MIN);
40338293af7Splunky 
40438293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
40538293af7Splunky 	ATF_CHECK_EQ(value, 0x0102);
40638293af7Splunky 
40738293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
40838293af7Splunky 	ATF_CHECK_EQ(value, INT16_MAX);
40938293af7Splunky 
41038293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
41138293af7Splunky 	ATF_CHECK_EQ(value, INT16_MIN);
41238293af7Splunky 
41338293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* not int */
41438293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
41538293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
41638293af7Splunky 
41738293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
41838293af7Splunky 	ATF_CHECK_EQ(value, 0x01020304);
41938293af7Splunky 
42038293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
42138293af7Splunky 	ATF_CHECK_EQ(value, INT32_MAX);
42238293af7Splunky 
42338293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
42438293af7Splunky 	ATF_CHECK_EQ(value, INT32_MIN);
42538293af7Splunky 
42638293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
42738293af7Splunky 	ATF_CHECK_EQ(value, 0x0102030405060708);
42838293af7Splunky 
42938293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
43038293af7Splunky 	ATF_CHECK_EQ(value, INT64_MAX);
43138293af7Splunky 
43238293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
43338293af7Splunky 	ATF_CHECK_EQ(value, INT64_MIN);
43438293af7Splunky 
43538293af7Splunky 	/*
43638293af7Splunky 	 * expected failure is that we cannot decode INT128 values larger than INT64
43738293af7Splunky 	 */
43838293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
43938293af7Splunky 	ATF_CHECK_EQ(value, 0);
44038293af7Splunky 
44138293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
44238293af7Splunky 	ATF_CHECK_EQ(value, INT64_MAX);
44338293af7Splunky 
44438293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* overflow */
44538293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
44638293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
44738293af7Splunky 
44838293af7Splunky 	ATF_REQUIRE(sdp_get_int(&test, &value));
44938293af7Splunky 	ATF_CHECK_EQ(value, INT64_MIN);
45038293af7Splunky 
45138293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* underflow */
45238293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
45338293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
45438293af7Splunky 
45538293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
45638293af7Splunky }
45738293af7Splunky 
45838293af7Splunky ATF_TC(check_sdp_get_seq);
45938293af7Splunky 
ATF_TC_HEAD(check_sdp_get_seq,tc)46038293af7Splunky ATF_TC_HEAD(check_sdp_get_seq, tc)
46138293af7Splunky {
46238293af7Splunky 
46338293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_seq results");
46438293af7Splunky }
46538293af7Splunky 
ATF_TC_BODY(check_sdp_get_seq,tc)46638293af7Splunky ATF_TC_BODY(check_sdp_get_seq, tc)
46738293af7Splunky {
46838293af7Splunky 	uint8_t data[] = {
46938293af7Splunky 		0x35, 0x00,		// seq8(0)
47038293af7Splunky 		0x00,			// nil
47138293af7Splunky 		0x36, 0x00, 0x00,	// seq16(0)
47238293af7Splunky 		0x37, 0x00, 0x00, 0x00,	// seq32(0)
47338293af7Splunky 		0x00,
47438293af7Splunky 	};
47538293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
47638293af7Splunky 	sdp_data_t value;
47738293af7Splunky 
47838293af7Splunky 	/*
47938293af7Splunky 	 * sdp_get_seq expects a SEQ type
48038293af7Splunky 	 * advancing test if successful
48138293af7Splunky 	 */
48238293af7Splunky 	ATF_REQUIRE(sdp_get_seq(&test, &value));
48338293af7Splunky 	ATF_CHECK_EQ(value.next, value.end);
48438293af7Splunky 
48538293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_seq(&test, &value), false);	/* not seq */
48638293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
48738293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
48838293af7Splunky 
48938293af7Splunky 	ATF_REQUIRE(sdp_get_seq(&test, &value));
49038293af7Splunky 	ATF_CHECK_EQ(value.next, value.end);
49138293af7Splunky 
49238293af7Splunky 	ATF_REQUIRE(sdp_get_seq(&test, &value));
49338293af7Splunky 	ATF_CHECK_EQ(value.next, value.end);
49438293af7Splunky 
49538293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
49638293af7Splunky }
49738293af7Splunky 
49838293af7Splunky ATF_TC(check_sdp_get_alt);
49938293af7Splunky 
ATF_TC_HEAD(check_sdp_get_alt,tc)50038293af7Splunky ATF_TC_HEAD(check_sdp_get_alt, tc)
50138293af7Splunky {
50238293af7Splunky 
50338293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_alt results");
50438293af7Splunky }
50538293af7Splunky 
ATF_TC_BODY(check_sdp_get_alt,tc)50638293af7Splunky ATF_TC_BODY(check_sdp_get_alt, tc)
50738293af7Splunky {
50838293af7Splunky 	uint8_t data[] = {
50938293af7Splunky 		0x3d, 0x00,		// alt8(0)
51038293af7Splunky 		0x00,			// nil
51138293af7Splunky 		0x3e, 0x00, 0x00,	// alt16(0)
51238293af7Splunky 		0x3f, 0x00, 0x00, 0x00,	// alt32(0)
51338293af7Splunky 		0x00,
51438293af7Splunky 	};
51538293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
51638293af7Splunky 	sdp_data_t value;
51738293af7Splunky 
51838293af7Splunky 	/*
51938293af7Splunky 	 * sdp_get_alt expects a ALT type
52038293af7Splunky 	 * advancing test if successful
52138293af7Splunky 	 */
52238293af7Splunky 	ATF_REQUIRE(sdp_get_alt(&test, &value));
52338293af7Splunky 	ATF_CHECK_EQ(value.next, value.end);
52438293af7Splunky 
52538293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_alt(&test, &value), false);	/* not alt */
52638293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
52738293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
52838293af7Splunky 
52938293af7Splunky 	ATF_REQUIRE(sdp_get_alt(&test, &value));
53038293af7Splunky 	ATF_CHECK_EQ(value.next, value.end);
53138293af7Splunky 
53238293af7Splunky 	ATF_REQUIRE(sdp_get_alt(&test, &value));
53338293af7Splunky 	ATF_CHECK_EQ(value.next, value.end);
53438293af7Splunky 
53538293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
53638293af7Splunky }
53738293af7Splunky 
53838293af7Splunky ATF_TC(check_sdp_get_str);
53938293af7Splunky 
ATF_TC_HEAD(check_sdp_get_str,tc)54038293af7Splunky ATF_TC_HEAD(check_sdp_get_str, tc)
54138293af7Splunky {
54238293af7Splunky 
54338293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_str results");
54438293af7Splunky }
54538293af7Splunky 
ATF_TC_BODY(check_sdp_get_str,tc)54638293af7Splunky ATF_TC_BODY(check_sdp_get_str, tc)
54738293af7Splunky {
54838293af7Splunky 	uint8_t data[] = {
54938293af7Splunky 		0x25, 0x04, 0x53, 0x54, // str8(4)	"STR8"
55038293af7Splunky 		0x52, 0x38,
55138293af7Splunky 		0x00,			// nil
55238293af7Splunky 		0x26, 0x00, 0x05, 0x53,	// str16(5)	"STR16"
55338293af7Splunky 		0x54, 0x52, 0x31, 0x36,
55438293af7Splunky 		0x27, 0x00, 0x00, 0x00,	// str32(5)	"STR32"
55538293af7Splunky 		0x05, 0x53, 0x54, 0x52,
55638293af7Splunky 		0x33, 0x32,
55738293af7Splunky 	};
55838293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
55938293af7Splunky 	sdp_data_t nil;
56038293af7Splunky 	char *str;
56138293af7Splunky 	size_t len;
56238293af7Splunky 
56338293af7Splunky 	/*
56438293af7Splunky 	 * sdp_get_str expects a STR type
56538293af7Splunky 	 * advancing test if successful
56638293af7Splunky 	 */
56738293af7Splunky 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
56838293af7Splunky 	ATF_CHECK(len == 4 && strncmp(str, "STR8", 4) == 0);
56938293af7Splunky 
57038293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_str(&test, &str, &len), false);	/* not str */
57138293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
57238293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
57338293af7Splunky 
57438293af7Splunky 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
57538293af7Splunky 	ATF_CHECK(len == 5 && strncmp(str, "STR16", 5) == 0);
57638293af7Splunky 
57738293af7Splunky 	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
57838293af7Splunky 	ATF_CHECK(len == 5 && strncmp(str, "STR32", 5) == 0);
57938293af7Splunky 
58038293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
58138293af7Splunky }
58238293af7Splunky 
58338293af7Splunky ATF_TC(check_sdp_get_url);
58438293af7Splunky 
ATF_TC_HEAD(check_sdp_get_url,tc)58538293af7Splunky ATF_TC_HEAD(check_sdp_get_url, tc)
58638293af7Splunky {
58738293af7Splunky 
58838293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_get_url results");
58938293af7Splunky }
59038293af7Splunky 
ATF_TC_BODY(check_sdp_get_url,tc)59138293af7Splunky ATF_TC_BODY(check_sdp_get_url, tc)
59238293af7Splunky {
59338293af7Splunky 	uint8_t data[] = {
59438293af7Splunky 		0x45, 0x04, 0x55, 0x52, // url8(4)	"URL8"
59538293af7Splunky 		0x4c, 0x38,
59638293af7Splunky 		0x00,			// nil
59738293af7Splunky 		0x46, 0x00, 0x05, 0x55,	// url16(5)	"URL16"
59838293af7Splunky 		0x52, 0x4c, 0x31, 0x36,
59938293af7Splunky 		0x47, 0x00, 0x00, 0x00,	// url32(5)	"URL32"
60038293af7Splunky 		0x05, 0x55, 0x52, 0x4c,
60138293af7Splunky 		0x33, 0x32,
60238293af7Splunky 	};
60338293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
60438293af7Splunky 	sdp_data_t nil;
60538293af7Splunky 	char *url;
60638293af7Splunky 	size_t len;
60738293af7Splunky 
60838293af7Splunky 	/*
60938293af7Splunky 	 * sdp_get_url expects a URL type
61038293af7Splunky 	 * advancing test if successful
61138293af7Splunky 	 */
61238293af7Splunky 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
61338293af7Splunky 	ATF_CHECK(len == 4 && strncmp(url, "URL8", 4) == 0);
61438293af7Splunky 
61538293af7Splunky 	ATF_REQUIRE_EQ(sdp_get_url(&test, &url, &len), false);	/* not url */
61638293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
61738293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
61838293af7Splunky 
61938293af7Splunky 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
62038293af7Splunky 	ATF_CHECK(len == 5 && strncmp(url, "URL16", 5) == 0);
62138293af7Splunky 
62238293af7Splunky 	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
62338293af7Splunky 	ATF_CHECK(len == 5 && strncmp(url, "URL32", 5) == 0);
62438293af7Splunky 
62538293af7Splunky 	ATF_CHECK_EQ(test.next, test.end);
62638293af7Splunky }
62738293af7Splunky 
ATF_TP_ADD_TCS(tp)62838293af7Splunky ATF_TP_ADD_TCS(tp)
62938293af7Splunky {
63038293af7Splunky 
63138293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_data);
63238293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_attr);
63338293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_uuid);
63438293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_bool);
63538293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_uint);
63638293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_int);
63738293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_seq);
63838293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_alt);
63938293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_str);
64038293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_get_url);
64138293af7Splunky 
64238293af7Splunky 	return atf_no_error();
64338293af7Splunky }
644