xref: /netbsd-src/tests/lib/libbluetooth/t_sdp_set.c (revision 5a4807fa7d17d0c1280be680686b5965edb14b8f)
1*5a4807faSplunky /*	$NetBSD: t_sdp_set.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_set_bool);
3938293af7Splunky 
ATF_TC_HEAD(check_sdp_set_bool,tc)4038293af7Splunky ATF_TC_HEAD(check_sdp_set_bool, tc)
4138293af7Splunky {
4238293af7Splunky 
4338293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_bool results");
4438293af7Splunky }
4538293af7Splunky 
ATF_TC_BODY(check_sdp_set_bool,tc)4638293af7Splunky ATF_TC_BODY(check_sdp_set_bool, tc)
4738293af7Splunky {
4838293af7Splunky 	uint8_t data[] = {
4938293af7Splunky 		0x28, 0x00,	// bool	false
5038293af7Splunky 		0x00,		// nil
5138293af7Splunky 		0x28,		// bool <invalid>
5238293af7Splunky 	};
5338293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
5438293af7Splunky 	sdp_data_t discard;
5538293af7Splunky 
5638293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_BOOL);
5738293af7Splunky 	ATF_REQUIRE(sdp_set_bool(&test, true));
5838293af7Splunky 	ATF_CHECK_EQ(test.next[1], 0x01);
5938293af7Splunky 	ATF_REQUIRE(sdp_set_bool(&test, false));
6038293af7Splunky 	ATF_CHECK_EQ(test.next[1], 0x00);
6138293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
6238293af7Splunky 
6338293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_NIL);
6438293af7Splunky 	ATF_CHECK_EQ(sdp_set_bool(&test, true), false);		/* not bool */
6538293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
6638293af7Splunky 
6738293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_BOOL);
6838293af7Splunky 	ATF_CHECK_EQ(sdp_set_bool(&test, true), false);		/* no value */
6938293af7Splunky }
7038293af7Splunky 
7138293af7Splunky ATF_TC(check_sdp_set_uint);
7238293af7Splunky 
ATF_TC_HEAD(check_sdp_set_uint,tc)7338293af7Splunky ATF_TC_HEAD(check_sdp_set_uint, tc)
7438293af7Splunky {
7538293af7Splunky 
7638293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_uint results");
7738293af7Splunky }
7838293af7Splunky 
ATF_TC_BODY(check_sdp_set_uint,tc)7938293af7Splunky ATF_TC_BODY(check_sdp_set_uint, tc)
8038293af7Splunky {
8138293af7Splunky 	uint8_t data[] = {
8238293af7Splunky 		0x08, 0x00,		// uint8	0x00
8338293af7Splunky 		0x00,			// nil
8438293af7Splunky 		0x09, 0x00, 0x00,	// uint16	0x0000
8538293af7Splunky 		0x0a, 0x00, 0x00, 0x00,	// uint32	0x00000000
8638293af7Splunky 		0x00,
8738293af7Splunky 		0x0b, 0x00, 0x00, 0x00,	// uint64	0x0000000000000000
8838293af7Splunky 		0x00, 0x00, 0x00, 0x00,
8938293af7Splunky 		0x00,
9038293af7Splunky 		0x0c, 0x00, 0x44, 0x00,	// uint128	0x00440044004400440044004400440044
9138293af7Splunky 		0x44, 0x00, 0x44, 0x00,
9238293af7Splunky 		0x44, 0x00, 0x44, 0x00,
9338293af7Splunky 		0x44, 0x00, 0x44, 0x00,
9438293af7Splunky 		0x00,
9538293af7Splunky 		0x09, 0x00,		// uint16	<invalid>
9638293af7Splunky 	};
9738293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
9838293af7Splunky 	sdp_data_t discard;
9938293af7Splunky 
10038293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT8);
10138293af7Splunky 	ATF_REQUIRE(sdp_set_uint(&test, 0x44));
10238293af7Splunky 	ATF_CHECK_EQ(sdp_set_uint(&test, UINT8_MAX + 1), false);	/* too big */
10338293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
10438293af7Splunky 
10538293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_NIL);
10638293af7Splunky 	ATF_CHECK_EQ(sdp_set_uint(&test, 0x00), false);			/* not uint */
10738293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
10838293af7Splunky 
10938293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT16);
11038293af7Splunky 	ATF_REQUIRE(sdp_set_uint(&test, 0xabcd));
11138293af7Splunky 	ATF_CHECK_EQ(sdp_set_uint(&test, UINT16_MAX + 1), false);	/* too big */
11238293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
11338293af7Splunky 
11438293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT32);
11538293af7Splunky 	ATF_REQUIRE(sdp_set_uint(&test, 0xdeadbeef));
11638293af7Splunky 	ATF_CHECK_EQ(sdp_set_uint(&test, (uintmax_t)UINT32_MAX + 1), false);	/* too big */
11738293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
11838293af7Splunky 
11938293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT64);
12038293af7Splunky 	ATF_REQUIRE(sdp_set_uint(&test, 0xc0ffeecafec0ffee));
12138293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
12238293af7Splunky 
12338293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT128);
12438293af7Splunky 	ATF_REQUIRE(sdp_set_uint(&test, 0xabcdef0123456789));
12538293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
12638293af7Splunky 
12738293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT16);
12838293af7Splunky 	ATF_CHECK_EQ(sdp_set_uint(&test, 0x3344), false);		/* no value */
12938293af7Splunky 
13038293af7Splunky 	const uint8_t expect[] = {
13138293af7Splunky 		0x08, 0x44,		// uint8	0x44
13238293af7Splunky 		0x00,			// nil
13338293af7Splunky 		0x09, 0xab, 0xcd,	// uint16	0xabcd
13438293af7Splunky 		0x0a, 0xde, 0xad, 0xbe,	// uint32	0xdeadbeef
13538293af7Splunky 		0xef,
13638293af7Splunky 		0x0b, 0xc0, 0xff, 0xee,	// uint64	0xc0ffeecafec0ffee
13738293af7Splunky 		0xca, 0xfe, 0xc0, 0xff,
13838293af7Splunky 		0xee,
13938293af7Splunky 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x0000000000000000abcdef0123456789
14038293af7Splunky 		0x00, 0x00, 0x00, 0x00,
14138293af7Splunky 		0x00, 0xab, 0xcd, 0xef,
14238293af7Splunky 		0x01, 0x23, 0x45, 0x67,
14338293af7Splunky 		0x89,
14438293af7Splunky 		0x09, 0x00,		// uint16	<invalid>
14538293af7Splunky 	};
14638293af7Splunky 
14738293af7Splunky 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
14838293af7Splunky 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
14938293af7Splunky }
15038293af7Splunky 
15138293af7Splunky ATF_TC(check_sdp_set_int);
15238293af7Splunky 
ATF_TC_HEAD(check_sdp_set_int,tc)15338293af7Splunky ATF_TC_HEAD(check_sdp_set_int, tc)
15438293af7Splunky {
15538293af7Splunky 
15638293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_int results");
15738293af7Splunky }
15838293af7Splunky 
ATF_TC_BODY(check_sdp_set_int,tc)15938293af7Splunky ATF_TC_BODY(check_sdp_set_int, tc)
16038293af7Splunky {
16138293af7Splunky 	uint8_t data[] = {
16238293af7Splunky 		0x10, 0x00,		// int8		0
16338293af7Splunky 		0x00,			// nil
16438293af7Splunky 		0x11, 0x00, 0x00,	// int16	0
16538293af7Splunky 		0x12, 0x00, 0x00, 0x00,	// int32	0
16638293af7Splunky 		0x00,
16738293af7Splunky 		0x13, 0x00, 0x00, 0x00,	// int64	0
16838293af7Splunky 		0x00, 0x00, 0x00, 0x00,
16938293af7Splunky 		0x00,
17038293af7Splunky 		0x14, 0x00, 0x44, 0x00,	// int128	0x00440044004400440044004400440044
17138293af7Splunky 		0x44, 0x00, 0x44, 0x00,
17238293af7Splunky 		0x44, 0x00, 0x44, 0x00,
17338293af7Splunky 		0x44, 0x00, 0x44, 0x00,
17438293af7Splunky 		0x00,
17538293af7Splunky 		0x11, 0x00,		// int16	<invalid>
17638293af7Splunky 	};
17738293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
17838293af7Splunky 	sdp_data_t discard;
17938293af7Splunky 
18038293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT8);
18138293af7Splunky 	ATF_REQUIRE(sdp_set_int(&test, -1));
18238293af7Splunky 	ATF_CHECK_EQ(sdp_set_int(&test, INT8_MAX + 1), false);	/* too big */
18338293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
18438293af7Splunky 
18538293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_NIL);
18638293af7Splunky 	ATF_CHECK_EQ(sdp_set_int(&test, 33), false);		/* not int */
18738293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
18838293af7Splunky 
18938293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
19038293af7Splunky 	ATF_REQUIRE(sdp_set_int(&test, 789));
19138293af7Splunky 	ATF_CHECK_EQ(sdp_set_int(&test, INT16_MIN - 1), false);	/* too big */
19238293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
19338293af7Splunky 
19438293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT32);
19538293af7Splunky 	ATF_REQUIRE(sdp_set_int(&test, -4567));
19638293af7Splunky 	ATF_CHECK_EQ(sdp_set_int(&test, (intmax_t)INT32_MAX + 1), false);	/* too big */
19738293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
19838293af7Splunky 
19938293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT64);
20038293af7Splunky 	ATF_REQUIRE(sdp_set_int(&test, -3483738234));
20138293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
20238293af7Splunky 
20338293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT128);
20438293af7Splunky 	ATF_REQUIRE(sdp_set_int(&test, 3423489463464));
20538293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
20638293af7Splunky 
20738293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
20838293af7Splunky 	ATF_CHECK_EQ(sdp_set_int(&test, 1234), false);		/* no value */
20938293af7Splunky 
21038293af7Splunky 	const uint8_t expect[] = {
21138293af7Splunky 		0x10, 0xff,		// int8		-1
21238293af7Splunky 		0x00,			// nil
21338293af7Splunky 		0x11, 0x03, 0x15,	// int16	789
21438293af7Splunky 		0x12, 0xff, 0xff, 0xee,	// int32	-4567
21538293af7Splunky 		0x29,
21638293af7Splunky 		0x13, 0xff, 0xff, 0xff,	// int64	-3483738234
21738293af7Splunky 		0xff, 0x30, 0x5a, 0x5f,
21838293af7Splunky 		0x86,
21938293af7Splunky 		0x14, 0x00, 0x00, 0x00,	// int128	3423489463464
22038293af7Splunky 		0x00, 0x00, 0x00, 0x00,
22138293af7Splunky 		0x00, 0x00, 0x00, 0x03,
22238293af7Splunky 		0x1d, 0x17, 0xdf, 0x94,
22338293af7Splunky 		0xa8,
22438293af7Splunky 		0x11, 0x00,		// int16	<invalid>
22538293af7Splunky 	};
22638293af7Splunky 
22738293af7Splunky 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
22838293af7Splunky 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
22938293af7Splunky }
23038293af7Splunky 
23138293af7Splunky ATF_TC(check_sdp_set_seq);
23238293af7Splunky 
ATF_TC_HEAD(check_sdp_set_seq,tc)23338293af7Splunky ATF_TC_HEAD(check_sdp_set_seq, tc)
23438293af7Splunky {
23538293af7Splunky 
23638293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_seq results");
23738293af7Splunky }
23838293af7Splunky 
ATF_TC_BODY(check_sdp_set_seq,tc)23938293af7Splunky ATF_TC_BODY(check_sdp_set_seq, tc)
24038293af7Splunky {
24138293af7Splunky 	uint8_t data[] = {
24238293af7Splunky 		0x35, 0x03,		// seq8(3)
24338293af7Splunky 		0x11, 0xff, 0xff,	//   int16	-1
24438293af7Splunky 		0x36, 0x01, 0x00,	// seq16(256)
24538293af7Splunky 		0x09, 0xff, 0xff,	// uint16	0xffff
24638293af7Splunky 		0x37, 0x01, 0x02, 0x03,	// seq32(16909060)
24738293af7Splunky 		0x04,
24838293af7Splunky 		0x36, 0x00,		// seq16(<invalid>)
24938293af7Splunky 	};
25038293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
25138293af7Splunky 	sdp_data_t discard;
25238293af7Splunky 
25338293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ8);
25438293af7Splunky 	ATF_REQUIRE(sdp_set_seq(&test, 0));
25538293af7Splunky 	ATF_CHECK_EQ(sdp_set_seq(&test, UINT8_MAX), false);	/* data too big */
25638293af7Splunky 	ATF_CHECK_EQ(sdp_set_seq(&test, UINT16_MAX), false);	/* size too big */
25738293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
25838293af7Splunky 
25938293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
26038293af7Splunky 	ATF_CHECK_EQ(sdp_set_seq(&test, 33), false);		/* not seq */
26138293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
26238293af7Splunky 
26338293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ16);
26438293af7Splunky 	ATF_REQUIRE(sdp_set_seq(&test, 3));
26538293af7Splunky 	ATF_CHECK_EQ(sdp_set_seq(&test, SSIZE_MAX), false);	/* size too big */
26638293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
26738293af7Splunky 
26838293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ32);
26938293af7Splunky 	ATF_REQUIRE(sdp_set_seq(&test, 0));
27038293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
27138293af7Splunky 
27238293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ16);
27338293af7Splunky 	ATF_CHECK_EQ(sdp_set_seq(&test, 22), false);		/* no size */
27438293af7Splunky 
27538293af7Splunky 	const uint8_t expect[] = {
27638293af7Splunky 		0x35, 0x00,		// seq8(0)
27738293af7Splunky 		0x11, 0xff, 0xff,	// int16	-1
27838293af7Splunky 		0x36, 0x00, 0x03,	// seq16(3)
27938293af7Splunky 		0x09, 0xff, 0xff,	//   uint16	0xffff
28038293af7Splunky 		0x37, 0x00, 0x00, 0x00,	// seq32(0)
28138293af7Splunky 		0x00,
28238293af7Splunky 		0x36, 0x00,		// seq16(<invalid>)
28338293af7Splunky 	};
28438293af7Splunky 
28538293af7Splunky 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
28638293af7Splunky 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
28738293af7Splunky }
28838293af7Splunky 
28938293af7Splunky ATF_TC(check_sdp_set_alt);
29038293af7Splunky 
ATF_TC_HEAD(check_sdp_set_alt,tc)29138293af7Splunky ATF_TC_HEAD(check_sdp_set_alt, tc)
29238293af7Splunky {
29338293af7Splunky 
29438293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_alt results");
29538293af7Splunky }
29638293af7Splunky 
ATF_TC_BODY(check_sdp_set_alt,tc)29738293af7Splunky ATF_TC_BODY(check_sdp_set_alt, tc)
29838293af7Splunky {
29938293af7Splunky 	uint8_t data[] = {
30038293af7Splunky 		0x3d, 0x06,		// alt8(6)
30138293af7Splunky 		0x11, 0xff, 0xff,	//   int16	-1
30238293af7Splunky 		0x3e, 0xff, 0xff,	//   alt16(65535)
30338293af7Splunky 		0x3f, 0x01, 0x02, 0x03,	// alt32(16909060)
30438293af7Splunky 		0x04,
30538293af7Splunky 		0x0a, 0x00, 0x00, 0x00,	// uint32	0x00000003
30638293af7Splunky 		0x03,
30738293af7Splunky 		0x3e, 0x00,		// alt16(<invalid>)
30838293af7Splunky 	};
30938293af7Splunky 	sdp_data_t test = { data, data + sizeof(data) };
31038293af7Splunky 	sdp_data_t discard;
31138293af7Splunky 
31238293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_ALT8);
31338293af7Splunky 	ATF_REQUIRE(sdp_set_alt(&test, 0));
31438293af7Splunky 	ATF_CHECK_EQ(sdp_set_alt(&test, UINT8_MAX), false);	/* data too big */
31538293af7Splunky 	ATF_CHECK_EQ(sdp_set_alt(&test, UINT16_MAX), false);	/* size too big */
31638293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
31738293af7Splunky 
31838293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
31938293af7Splunky 	ATF_CHECK_EQ(sdp_set_alt(&test, 27), false);		/* not alt */
32038293af7Splunky 	ATF_REQUIRE(sdp_get_data(&test, &discard));
32138293af7Splunky 
32238293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_ALT16);
32338293af7Splunky 	ATF_REQUIRE(sdp_set_alt(&test, 10));
32438293af7Splunky 	ATF_CHECK_EQ(sdp_set_alt(&test, SSIZE_MAX), false);	/* size too big */
32538293af7Splunky 	ATF_REQUIRE(sdp_get_alt(&test, &discard));
32638293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&discard), SDP_DATA_ALT32);
32738293af7Splunky 	ATF_CHECK(sdp_set_alt(&discard, -1));			/* end of alt16 */
32838293af7Splunky 	ATF_CHECK_EQ(sdp_set_alt(&discard, 6), false);		/* data too big */
32938293af7Splunky 
33038293af7Splunky 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_ALT16);
33138293af7Splunky 	ATF_CHECK_EQ(sdp_set_alt(&test, 22), false);		/* no size */
33238293af7Splunky 
33338293af7Splunky 	const uint8_t expect[] = {
33438293af7Splunky 		0x3d, 0x00,		// alt8(0)
33538293af7Splunky 		0x11, 0xff, 0xff,	// int16	-1
33638293af7Splunky 		0x3e, 0x00, 0x0a,	// alt16(10)
33738293af7Splunky 		0x3f, 0x00, 0x00, 0x00,	//   alt32(5)
33838293af7Splunky 		0x05,
33938293af7Splunky 		0x0a, 0x00, 0x00, 0x00,	//     uint32	0x00000003
34038293af7Splunky 		0x03,
34138293af7Splunky 		0x3e, 0x00,		// alt16(<invalid>)
34238293af7Splunky 	};
34338293af7Splunky 
34438293af7Splunky 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
34538293af7Splunky 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
34638293af7Splunky }
34738293af7Splunky 
34838293af7Splunky 
ATF_TP_ADD_TCS(tp)34938293af7Splunky ATF_TP_ADD_TCS(tp)
35038293af7Splunky {
35138293af7Splunky 
35238293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_set_bool);
35338293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_set_uint);
35438293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_set_int);
35538293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_set_seq);
35638293af7Splunky 	ATF_TP_ADD_TC(tp, check_sdp_set_alt);
35738293af7Splunky 
35838293af7Splunky 	return atf_no_error();
35938293af7Splunky }
360