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