xref: /minix3/tests/lib/libbluetooth/t_sdp_set.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: t_sdp_set.c,v 1.2 2011/04/07 08:29:50 plunky Exp $	*/
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*-
4*11be35a1SLionel Sambuc  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5*11be35a1SLionel Sambuc  * All rights reserved.
6*11be35a1SLionel Sambuc  *
7*11be35a1SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
8*11be35a1SLionel Sambuc  * by Iain Hibbert.
9*11be35a1SLionel Sambuc  *
10*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
11*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
12*11be35a1SLionel Sambuc  * are met:
13*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
14*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
15*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
16*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
17*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
18*11be35a1SLionel Sambuc  *
19*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*11be35a1SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*11be35a1SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*11be35a1SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*11be35a1SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*11be35a1SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*11be35a1SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*11be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*11be35a1SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*11be35a1SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*11be35a1SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
30*11be35a1SLionel Sambuc  */
31*11be35a1SLionel Sambuc 
32*11be35a1SLionel Sambuc #include <atf-c.h>
33*11be35a1SLionel Sambuc 
34*11be35a1SLionel Sambuc #include <limits.h>
35*11be35a1SLionel Sambuc #include <sdp.h>
36*11be35a1SLionel Sambuc #include <string.h>
37*11be35a1SLionel Sambuc 
38*11be35a1SLionel Sambuc ATF_TC(check_sdp_set_bool);
39*11be35a1SLionel Sambuc 
ATF_TC_HEAD(check_sdp_set_bool,tc)40*11be35a1SLionel Sambuc ATF_TC_HEAD(check_sdp_set_bool, tc)
41*11be35a1SLionel Sambuc {
42*11be35a1SLionel Sambuc 
43*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_bool results");
44*11be35a1SLionel Sambuc }
45*11be35a1SLionel Sambuc 
ATF_TC_BODY(check_sdp_set_bool,tc)46*11be35a1SLionel Sambuc ATF_TC_BODY(check_sdp_set_bool, tc)
47*11be35a1SLionel Sambuc {
48*11be35a1SLionel Sambuc 	uint8_t data[] = {
49*11be35a1SLionel Sambuc 		0x28, 0x00,	// bool	false
50*11be35a1SLionel Sambuc 		0x00,		// nil
51*11be35a1SLionel Sambuc 		0x28,		// bool <invalid>
52*11be35a1SLionel Sambuc 	};
53*11be35a1SLionel Sambuc 	sdp_data_t test = { data, data + sizeof(data) };
54*11be35a1SLionel Sambuc 	sdp_data_t discard;
55*11be35a1SLionel Sambuc 
56*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_BOOL);
57*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_bool(&test, true));
58*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(test.next[1], 0x01);
59*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_bool(&test, false));
60*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(test.next[1], 0x00);
61*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
62*11be35a1SLionel Sambuc 
63*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_NIL);
64*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_bool(&test, true), false);		/* not bool */
65*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
66*11be35a1SLionel Sambuc 
67*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_BOOL);
68*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_bool(&test, true), false);		/* no value */
69*11be35a1SLionel Sambuc }
70*11be35a1SLionel Sambuc 
71*11be35a1SLionel Sambuc ATF_TC(check_sdp_set_uint);
72*11be35a1SLionel Sambuc 
ATF_TC_HEAD(check_sdp_set_uint,tc)73*11be35a1SLionel Sambuc ATF_TC_HEAD(check_sdp_set_uint, tc)
74*11be35a1SLionel Sambuc {
75*11be35a1SLionel Sambuc 
76*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_uint results");
77*11be35a1SLionel Sambuc }
78*11be35a1SLionel Sambuc 
ATF_TC_BODY(check_sdp_set_uint,tc)79*11be35a1SLionel Sambuc ATF_TC_BODY(check_sdp_set_uint, tc)
80*11be35a1SLionel Sambuc {
81*11be35a1SLionel Sambuc 	uint8_t data[] = {
82*11be35a1SLionel Sambuc 		0x08, 0x00,		// uint8	0x00
83*11be35a1SLionel Sambuc 		0x00,			// nil
84*11be35a1SLionel Sambuc 		0x09, 0x00, 0x00,	// uint16	0x0000
85*11be35a1SLionel Sambuc 		0x0a, 0x00, 0x00, 0x00,	// uint32	0x00000000
86*11be35a1SLionel Sambuc 		0x00,
87*11be35a1SLionel Sambuc 		0x0b, 0x00, 0x00, 0x00,	// uint64	0x0000000000000000
88*11be35a1SLionel Sambuc 		0x00, 0x00, 0x00, 0x00,
89*11be35a1SLionel Sambuc 		0x00,
90*11be35a1SLionel Sambuc 		0x0c, 0x00, 0x44, 0x00,	// uint128	0x00440044004400440044004400440044
91*11be35a1SLionel Sambuc 		0x44, 0x00, 0x44, 0x00,
92*11be35a1SLionel Sambuc 		0x44, 0x00, 0x44, 0x00,
93*11be35a1SLionel Sambuc 		0x44, 0x00, 0x44, 0x00,
94*11be35a1SLionel Sambuc 		0x00,
95*11be35a1SLionel Sambuc 		0x09, 0x00,		// uint16	<invalid>
96*11be35a1SLionel Sambuc 	};
97*11be35a1SLionel Sambuc 	sdp_data_t test = { data, data + sizeof(data) };
98*11be35a1SLionel Sambuc 	sdp_data_t discard;
99*11be35a1SLionel Sambuc 
100*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT8);
101*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_uint(&test, 0x44));
102*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_uint(&test, UINT8_MAX + 1), false);	/* too big */
103*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
104*11be35a1SLionel Sambuc 
105*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_NIL);
106*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_uint(&test, 0x00), false);			/* not uint */
107*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
108*11be35a1SLionel Sambuc 
109*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT16);
110*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_uint(&test, 0xabcd));
111*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_uint(&test, UINT16_MAX + 1), false);	/* too big */
112*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
113*11be35a1SLionel Sambuc 
114*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT32);
115*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_uint(&test, 0xdeadbeef));
116*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_uint(&test, (uintmax_t)UINT32_MAX + 1), false);	/* too big */
117*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
118*11be35a1SLionel Sambuc 
119*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT64);
120*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_uint(&test, 0xc0ffeecafec0ffee));
121*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
122*11be35a1SLionel Sambuc 
123*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT128);
124*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_uint(&test, 0xabcdef0123456789));
125*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
126*11be35a1SLionel Sambuc 
127*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_UINT16);
128*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_uint(&test, 0x3344), false);		/* no value */
129*11be35a1SLionel Sambuc 
130*11be35a1SLionel Sambuc 	const uint8_t expect[] = {
131*11be35a1SLionel Sambuc 		0x08, 0x44,		// uint8	0x44
132*11be35a1SLionel Sambuc 		0x00,			// nil
133*11be35a1SLionel Sambuc 		0x09, 0xab, 0xcd,	// uint16	0xabcd
134*11be35a1SLionel Sambuc 		0x0a, 0xde, 0xad, 0xbe,	// uint32	0xdeadbeef
135*11be35a1SLionel Sambuc 		0xef,
136*11be35a1SLionel Sambuc 		0x0b, 0xc0, 0xff, 0xee,	// uint64	0xc0ffeecafec0ffee
137*11be35a1SLionel Sambuc 		0xca, 0xfe, 0xc0, 0xff,
138*11be35a1SLionel Sambuc 		0xee,
139*11be35a1SLionel Sambuc 		0x0c, 0x00, 0x00, 0x00,	// uint128	0x0000000000000000abcdef0123456789
140*11be35a1SLionel Sambuc 		0x00, 0x00, 0x00, 0x00,
141*11be35a1SLionel Sambuc 		0x00, 0xab, 0xcd, 0xef,
142*11be35a1SLionel Sambuc 		0x01, 0x23, 0x45, 0x67,
143*11be35a1SLionel Sambuc 		0x89,
144*11be35a1SLionel Sambuc 		0x09, 0x00,		// uint16	<invalid>
145*11be35a1SLionel Sambuc 	};
146*11be35a1SLionel Sambuc 
147*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
148*11be35a1SLionel Sambuc 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
149*11be35a1SLionel Sambuc }
150*11be35a1SLionel Sambuc 
151*11be35a1SLionel Sambuc ATF_TC(check_sdp_set_int);
152*11be35a1SLionel Sambuc 
ATF_TC_HEAD(check_sdp_set_int,tc)153*11be35a1SLionel Sambuc ATF_TC_HEAD(check_sdp_set_int, tc)
154*11be35a1SLionel Sambuc {
155*11be35a1SLionel Sambuc 
156*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_int results");
157*11be35a1SLionel Sambuc }
158*11be35a1SLionel Sambuc 
ATF_TC_BODY(check_sdp_set_int,tc)159*11be35a1SLionel Sambuc ATF_TC_BODY(check_sdp_set_int, tc)
160*11be35a1SLionel Sambuc {
161*11be35a1SLionel Sambuc 	uint8_t data[] = {
162*11be35a1SLionel Sambuc 		0x10, 0x00,		// int8		0
163*11be35a1SLionel Sambuc 		0x00,			// nil
164*11be35a1SLionel Sambuc 		0x11, 0x00, 0x00,	// int16	0
165*11be35a1SLionel Sambuc 		0x12, 0x00, 0x00, 0x00,	// int32	0
166*11be35a1SLionel Sambuc 		0x00,
167*11be35a1SLionel Sambuc 		0x13, 0x00, 0x00, 0x00,	// int64	0
168*11be35a1SLionel Sambuc 		0x00, 0x00, 0x00, 0x00,
169*11be35a1SLionel Sambuc 		0x00,
170*11be35a1SLionel Sambuc 		0x14, 0x00, 0x44, 0x00,	// int128	0x00440044004400440044004400440044
171*11be35a1SLionel Sambuc 		0x44, 0x00, 0x44, 0x00,
172*11be35a1SLionel Sambuc 		0x44, 0x00, 0x44, 0x00,
173*11be35a1SLionel Sambuc 		0x44, 0x00, 0x44, 0x00,
174*11be35a1SLionel Sambuc 		0x00,
175*11be35a1SLionel Sambuc 		0x11, 0x00,		// int16	<invalid>
176*11be35a1SLionel Sambuc 	};
177*11be35a1SLionel Sambuc 	sdp_data_t test = { data, data + sizeof(data) };
178*11be35a1SLionel Sambuc 	sdp_data_t discard;
179*11be35a1SLionel Sambuc 
180*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT8);
181*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_int(&test, -1));
182*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_int(&test, INT8_MAX + 1), false);	/* too big */
183*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
184*11be35a1SLionel Sambuc 
185*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_NIL);
186*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_int(&test, 33), false);		/* not int */
187*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
188*11be35a1SLionel Sambuc 
189*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
190*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_int(&test, 789));
191*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_int(&test, INT16_MIN - 1), false);	/* too big */
192*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
193*11be35a1SLionel Sambuc 
194*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT32);
195*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_int(&test, -4567));
196*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_int(&test, (intmax_t)INT32_MAX + 1), false);	/* too big */
197*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
198*11be35a1SLionel Sambuc 
199*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT64);
200*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_int(&test, -3483738234));
201*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
202*11be35a1SLionel Sambuc 
203*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT128);
204*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_int(&test, 3423489463464));
205*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
206*11be35a1SLionel Sambuc 
207*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
208*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_int(&test, 1234), false);		/* no value */
209*11be35a1SLionel Sambuc 
210*11be35a1SLionel Sambuc 	const uint8_t expect[] = {
211*11be35a1SLionel Sambuc 		0x10, 0xff,		// int8		-1
212*11be35a1SLionel Sambuc 		0x00,			// nil
213*11be35a1SLionel Sambuc 		0x11, 0x03, 0x15,	// int16	789
214*11be35a1SLionel Sambuc 		0x12, 0xff, 0xff, 0xee,	// int32	-4567
215*11be35a1SLionel Sambuc 		0x29,
216*11be35a1SLionel Sambuc 		0x13, 0xff, 0xff, 0xff,	// int64	-3483738234
217*11be35a1SLionel Sambuc 		0xff, 0x30, 0x5a, 0x5f,
218*11be35a1SLionel Sambuc 		0x86,
219*11be35a1SLionel Sambuc 		0x14, 0x00, 0x00, 0x00,	// int128	3423489463464
220*11be35a1SLionel Sambuc 		0x00, 0x00, 0x00, 0x00,
221*11be35a1SLionel Sambuc 		0x00, 0x00, 0x00, 0x03,
222*11be35a1SLionel Sambuc 		0x1d, 0x17, 0xdf, 0x94,
223*11be35a1SLionel Sambuc 		0xa8,
224*11be35a1SLionel Sambuc 		0x11, 0x00,		// int16	<invalid>
225*11be35a1SLionel Sambuc 	};
226*11be35a1SLionel Sambuc 
227*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
228*11be35a1SLionel Sambuc 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
229*11be35a1SLionel Sambuc }
230*11be35a1SLionel Sambuc 
231*11be35a1SLionel Sambuc ATF_TC(check_sdp_set_seq);
232*11be35a1SLionel Sambuc 
ATF_TC_HEAD(check_sdp_set_seq,tc)233*11be35a1SLionel Sambuc ATF_TC_HEAD(check_sdp_set_seq, tc)
234*11be35a1SLionel Sambuc {
235*11be35a1SLionel Sambuc 
236*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_seq results");
237*11be35a1SLionel Sambuc }
238*11be35a1SLionel Sambuc 
ATF_TC_BODY(check_sdp_set_seq,tc)239*11be35a1SLionel Sambuc ATF_TC_BODY(check_sdp_set_seq, tc)
240*11be35a1SLionel Sambuc {
241*11be35a1SLionel Sambuc 	uint8_t data[] = {
242*11be35a1SLionel Sambuc 		0x35, 0x03,		// seq8(3)
243*11be35a1SLionel Sambuc 		0x11, 0xff, 0xff,	//   int16	-1
244*11be35a1SLionel Sambuc 		0x36, 0x01, 0x00,	// seq16(256)
245*11be35a1SLionel Sambuc 		0x09, 0xff, 0xff,	// uint16	0xffff
246*11be35a1SLionel Sambuc 		0x37, 0x01, 0x02, 0x03,	// seq32(16909060)
247*11be35a1SLionel Sambuc 		0x04,
248*11be35a1SLionel Sambuc 		0x36, 0x00,		// seq16(<invalid>)
249*11be35a1SLionel Sambuc 	};
250*11be35a1SLionel Sambuc 	sdp_data_t test = { data, data + sizeof(data) };
251*11be35a1SLionel Sambuc 	sdp_data_t discard;
252*11be35a1SLionel Sambuc 
253*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ8);
254*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_seq(&test, 0));
255*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_seq(&test, UINT8_MAX), false);	/* data too big */
256*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_seq(&test, UINT16_MAX), false);	/* size too big */
257*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
258*11be35a1SLionel Sambuc 
259*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
260*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_seq(&test, 33), false);		/* not seq */
261*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
262*11be35a1SLionel Sambuc 
263*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ16);
264*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_seq(&test, 3));
265*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_seq(&test, SSIZE_MAX), false);	/* size too big */
266*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
267*11be35a1SLionel Sambuc 
268*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ32);
269*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_seq(&test, 0));
270*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
271*11be35a1SLionel Sambuc 
272*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_SEQ16);
273*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_seq(&test, 22), false);		/* no size */
274*11be35a1SLionel Sambuc 
275*11be35a1SLionel Sambuc 	const uint8_t expect[] = {
276*11be35a1SLionel Sambuc 		0x35, 0x00,		// seq8(0)
277*11be35a1SLionel Sambuc 		0x11, 0xff, 0xff,	// int16	-1
278*11be35a1SLionel Sambuc 		0x36, 0x00, 0x03,	// seq16(3)
279*11be35a1SLionel Sambuc 		0x09, 0xff, 0xff,	//   uint16	0xffff
280*11be35a1SLionel Sambuc 		0x37, 0x00, 0x00, 0x00,	// seq32(0)
281*11be35a1SLionel Sambuc 		0x00,
282*11be35a1SLionel Sambuc 		0x36, 0x00,		// seq16(<invalid>)
283*11be35a1SLionel Sambuc 	};
284*11be35a1SLionel Sambuc 
285*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
286*11be35a1SLionel Sambuc 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
287*11be35a1SLionel Sambuc }
288*11be35a1SLionel Sambuc 
289*11be35a1SLionel Sambuc ATF_TC(check_sdp_set_alt);
290*11be35a1SLionel Sambuc 
ATF_TC_HEAD(check_sdp_set_alt,tc)291*11be35a1SLionel Sambuc ATF_TC_HEAD(check_sdp_set_alt, tc)
292*11be35a1SLionel Sambuc {
293*11be35a1SLionel Sambuc 
294*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sdp_set_alt results");
295*11be35a1SLionel Sambuc }
296*11be35a1SLionel Sambuc 
ATF_TC_BODY(check_sdp_set_alt,tc)297*11be35a1SLionel Sambuc ATF_TC_BODY(check_sdp_set_alt, tc)
298*11be35a1SLionel Sambuc {
299*11be35a1SLionel Sambuc 	uint8_t data[] = {
300*11be35a1SLionel Sambuc 		0x3d, 0x06,		// alt8(6)
301*11be35a1SLionel Sambuc 		0x11, 0xff, 0xff,	//   int16	-1
302*11be35a1SLionel Sambuc 		0x3e, 0xff, 0xff,	//   alt16(65535)
303*11be35a1SLionel Sambuc 		0x3f, 0x01, 0x02, 0x03,	// alt32(16909060)
304*11be35a1SLionel Sambuc 		0x04,
305*11be35a1SLionel Sambuc 		0x0a, 0x00, 0x00, 0x00,	// uint32	0x00000003
306*11be35a1SLionel Sambuc 		0x03,
307*11be35a1SLionel Sambuc 		0x3e, 0x00,		// alt16(<invalid>)
308*11be35a1SLionel Sambuc 	};
309*11be35a1SLionel Sambuc 	sdp_data_t test = { data, data + sizeof(data) };
310*11be35a1SLionel Sambuc 	sdp_data_t discard;
311*11be35a1SLionel Sambuc 
312*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_ALT8);
313*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_alt(&test, 0));
314*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_alt(&test, UINT8_MAX), false);	/* data too big */
315*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_alt(&test, UINT16_MAX), false);	/* size too big */
316*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
317*11be35a1SLionel Sambuc 
318*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_INT16);
319*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_alt(&test, 27), false);		/* not alt */
320*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_data(&test, &discard));
321*11be35a1SLionel Sambuc 
322*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_ALT16);
323*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_set_alt(&test, 10));
324*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_alt(&test, SSIZE_MAX), false);	/* size too big */
325*11be35a1SLionel Sambuc 	ATF_REQUIRE(sdp_get_alt(&test, &discard));
326*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&discard), SDP_DATA_ALT32);
327*11be35a1SLionel Sambuc 	ATF_CHECK(sdp_set_alt(&discard, -1));			/* end of alt16 */
328*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_alt(&discard, 6), false);		/* data too big */
329*11be35a1SLionel Sambuc 
330*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_data_type(&test), SDP_DATA_ALT16);
331*11be35a1SLionel Sambuc 	ATF_CHECK_EQ(sdp_set_alt(&test, 22), false);		/* no size */
332*11be35a1SLionel Sambuc 
333*11be35a1SLionel Sambuc 	const uint8_t expect[] = {
334*11be35a1SLionel Sambuc 		0x3d, 0x00,		// alt8(0)
335*11be35a1SLionel Sambuc 		0x11, 0xff, 0xff,	// int16	-1
336*11be35a1SLionel Sambuc 		0x3e, 0x00, 0x0a,	// alt16(10)
337*11be35a1SLionel Sambuc 		0x3f, 0x00, 0x00, 0x00,	//   alt32(5)
338*11be35a1SLionel Sambuc 		0x05,
339*11be35a1SLionel Sambuc 		0x0a, 0x00, 0x00, 0x00,	//     uint32	0x00000003
340*11be35a1SLionel Sambuc 		0x03,
341*11be35a1SLionel Sambuc 		0x3e, 0x00,		// alt16(<invalid>)
342*11be35a1SLionel Sambuc 	};
343*11be35a1SLionel Sambuc 
344*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ(sizeof(data), sizeof(expect));
345*11be35a1SLionel Sambuc 	ATF_CHECK(memcmp(expect, data, sizeof(expect)) == 0);
346*11be35a1SLionel Sambuc }
347*11be35a1SLionel Sambuc 
348*11be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)349*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
350*11be35a1SLionel Sambuc {
351*11be35a1SLionel Sambuc 
352*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, check_sdp_set_bool);
353*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, check_sdp_set_uint);
354*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, check_sdp_set_int);
355*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, check_sdp_set_seq);
356*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, check_sdp_set_alt);
357*11be35a1SLionel Sambuc 
358*11be35a1SLionel Sambuc 	return atf_no_error();
359*11be35a1SLionel Sambuc }
360