1272343Sngie/*	$NetBSD: t_sdp_get.c,v 1.2 2011/04/07 08:29:50 plunky Exp $	*/
2272343Sngie
3272343Sngie/*-
4272343Sngie * Copyright (c) 2011 The NetBSD Foundation, Inc.
5272343Sngie * All rights reserved.
6272343Sngie *
7272343Sngie * This code is derived from software contributed to The NetBSD Foundation
8272343Sngie * by Iain Hibbert.
9272343Sngie *
10272343Sngie * Redistribution and use in source and binary forms, with or without
11272343Sngie * modification, are permitted provided that the following conditions
12272343Sngie * are met:
13272343Sngie * 1. Redistributions of source code must retain the above copyright
14272343Sngie *    notice, this list of conditions and the following disclaimer.
15272343Sngie * 2. Redistributions in binary form must reproduce the above copyright
16272343Sngie *    notice, this list of conditions and the following disclaimer in the
17272343Sngie *    documentation and/or other materials provided with the distribution.
18272343Sngie *
19272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20272343Sngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21272343Sngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22272343Sngie * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23272343Sngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24272343Sngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25272343Sngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27272343Sngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28272343Sngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29272343Sngie * POSSIBILITY OF SUCH DAMAGE.
30272343Sngie */
31272343Sngie
32272343Sngie#include <atf-c.h>
33272343Sngie
34272343Sngie#include <limits.h>
35272343Sngie#include <sdp.h>
36272343Sngie#include <string.h>
37272343Sngie
38272343SngieATF_TC(check_sdp_get_data);
39272343Sngie
40272343SngieATF_TC_HEAD(check_sdp_get_data, tc)
41272343Sngie{
42272343Sngie
43272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_data results");
44272343Sngie}
45272343Sngie
46272343SngieATF_TC_BODY(check_sdp_get_data, tc)
47272343Sngie{
48272343Sngie	uint8_t data[] = {
49272343Sngie		0x09, 0x00, 0x00,	// uint16	0x0000
50272343Sngie		0x35, 0x05,		// seq8(5)
51272343Sngie		0x19, 0x00, 0x00,	//   uuid16	0x0000
52272343Sngie		0x08, 0x00,		//   uint8	0x00
53272343Sngie		0x36, 0x00, 0x01,	// seq16(1)
54272343Sngie		0x19,			//   uint16	/* invalid */
55272343Sngie		0x25, 0x04, 0x54, 0x45,	// str8(4)	"TEST"
56272343Sngie		0x53, 0x54,
57272343Sngie	};
58272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
59272343Sngie	sdp_data_t value, seq;
60272343Sngie
61272343Sngie	/*
62272343Sngie	 * sdp_get_data constructs a new sdp_data_t containing
63272343Sngie	 * the next data element, advancing test if successful
64272343Sngie	 */
65272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &value));
66272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT16);
67272343Sngie	ATF_CHECK_EQ(sdp_data_size(&value), 3);
68272343Sngie
69272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &value));
70272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
71272343Sngie	ATF_CHECK_EQ(sdp_data_size(&value), 7);
72272343Sngie
73272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &value));
74272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ16);
75272343Sngie	ATF_CHECK_EQ(sdp_data_size(&value), 4);
76272343Sngie	ATF_REQUIRE_EQ(sdp_get_seq(&value, &seq), true);
77272343Sngie	ATF_REQUIRE_EQ(sdp_get_data(&seq, &value), false);	/* invalid */
78272343Sngie
79272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &value));
80272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_STR8);
81272343Sngie	ATF_CHECK_EQ(sdp_data_size(&value), 6);
82272343Sngie
83272343Sngie	ATF_CHECK_EQ(test.next, test.end);
84272343Sngie}
85272343Sngie
86272343SngieATF_TC(check_sdp_get_attr);
87272343Sngie
88272343SngieATF_TC_HEAD(check_sdp_get_attr, tc)
89272343Sngie{
90272343Sngie
91272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_attr results");
92272343Sngie}
93272343Sngie
94272343SngieATF_TC_BODY(check_sdp_get_attr, tc)
95272343Sngie{
96272343Sngie	uint8_t data[] = {
97272343Sngie		0x09, 0x00, 0x00,	// uint16	0x0000
98272343Sngie		0x35, 0x05,		// seq8(5)
99272343Sngie		0x19, 0x00, 0x00,	//   uuid16	0x0000
100272343Sngie		0x08, 0x00,		//   uint8	0x00
101272343Sngie		0x08, 0x00,		// uint8	0x00
102272343Sngie		0x09, 0x00, 0x01,	// uint16	0x0001
103272343Sngie		0x19, 0x12, 0x34,	// uuid16	0x1234
104272343Sngie	};
105272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
106272343Sngie	sdp_data_t value;
107272343Sngie	uint16_t attr;
108272343Sngie
109272343Sngie	/*
110272343Sngie	 * sdp_get_attr expects a UINT16 followed by any data item
111272343Sngie	 * and advances test if successful
112272343Sngie	 */
113272343Sngie	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
114272343Sngie	ATF_CHECK_EQ(attr, 0x0000);
115272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8);
116272343Sngie	ATF_CHECK_EQ(sdp_data_size(&value), 7);
117272343Sngie
118272343Sngie	ATF_REQUIRE_EQ(sdp_get_attr(&test, &attr, &value), false);
119272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &value));
120272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT8);
121272343Sngie	ATF_CHECK_EQ(sdp_data_size(&value), 2);
122272343Sngie
123272343Sngie	ATF_REQUIRE(sdp_get_attr(&test, &attr, &value));
124272343Sngie	ATF_CHECK_EQ(attr, 0x0001);
125272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UUID16);
126272343Sngie	ATF_CHECK_EQ(sdp_data_size(&value), 3);
127272343Sngie
128272343Sngie	ATF_CHECK_EQ(test.next, test.end);
129272343Sngie}
130272343Sngie
131272343SngieATF_TC(check_sdp_get_uuid);
132272343Sngie
133272343SngieATF_TC_HEAD(check_sdp_get_uuid, tc)
134272343Sngie{
135272343Sngie
136272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uuid results");
137272343Sngie}
138272343Sngie
139272343SngieATF_TC_BODY(check_sdp_get_uuid, tc)
140272343Sngie{
141272343Sngie	uint8_t data[] = {
142272343Sngie		0x19, 0x12, 0x34,	// uuid16	0x1234
143272343Sngie		0x1a, 0x11, 0x22, 0x33,	// uuid32	0x11223344
144272343Sngie		0x44,
145272343Sngie		0x00,			// nil
146272343Sngie		0x1c,			// uuid128	0x00112233-4444--5555-6666-778899aabbcc
147272343Sngie		0x00, 0x11, 0x22, 0x33,
148272343Sngie		0x44, 0x44, 0x55, 0x55,
149272343Sngie		0x66, 0x66, 0x77, 0x88,
150272343Sngie		0x99, 0xaa, 0xbb, 0xcc,
151272343Sngie	};
152272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
153272343Sngie	uuid_t u16 = {
154272343Sngie		0x00001234,
155272343Sngie		0x0000,
156272343Sngie		0x1000,
157272343Sngie		0x80,
158272343Sngie		0x00,
159272343Sngie		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
160272343Sngie	};
161272343Sngie	uuid_t u32 = {
162272343Sngie		0x11223344,
163272343Sngie		0x0000,
164272343Sngie		0x1000,
165272343Sngie		0x80,
166272343Sngie		0x00,
167272343Sngie		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
168272343Sngie	};
169272343Sngie	uuid_t u128 = {
170272343Sngie		0x00112233,
171272343Sngie		0x4444,
172272343Sngie		0x5555,
173272343Sngie		0x66,
174272343Sngie		0x66,
175272343Sngie		{ 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc }
176272343Sngie	};
177272343Sngie	sdp_data_t nil;
178272343Sngie	uuid_t value;
179272343Sngie
180272343Sngie	/*
181272343Sngie	 * sdp_get_uuid expects any UUID type returns the full uuid
182272343Sngie	 * advancing test if successful
183272343Sngie	 */
184272343Sngie	ATF_REQUIRE(sdp_get_uuid(&test, &value));
185272343Sngie	ATF_CHECK(uuid_equal(&value, &u16, NULL));
186272343Sngie
187272343Sngie	ATF_REQUIRE(sdp_get_uuid(&test, &value));
188272343Sngie	ATF_CHECK(uuid_equal(&value, &u32, NULL));
189272343Sngie
190272343Sngie	ATF_REQUIRE_EQ(sdp_get_uuid(&test, &value), false);	/* not uuid */
191272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
192272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
193272343Sngie
194272343Sngie	ATF_REQUIRE(sdp_get_uuid(&test, &value));
195272343Sngie	ATF_CHECK(uuid_equal(&value, &u128, NULL));
196272343Sngie
197272343Sngie	ATF_CHECK_EQ(test.next, test.end);
198272343Sngie}
199272343Sngie
200272343SngieATF_TC(check_sdp_get_bool);
201272343Sngie
202272343SngieATF_TC_HEAD(check_sdp_get_bool, tc)
203272343Sngie{
204272343Sngie
205272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_bool results");
206272343Sngie}
207272343Sngie
208272343SngieATF_TC_BODY(check_sdp_get_bool, tc)
209272343Sngie{
210272343Sngie	uint8_t data[] = {
211272343Sngie		0x28, 0x00,	// bool		false
212272343Sngie		0x00,		// nil
213272343Sngie		0x28, 0x01,	// bool		true
214272343Sngie	};
215272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
216272343Sngie	sdp_data_t nil;
217272343Sngie	bool value;
218272343Sngie
219272343Sngie	/*
220272343Sngie	 * sdp_get_bool expects a BOOL type
221272343Sngie	 * advancing test if successful
222272343Sngie	 */
223272343Sngie	ATF_REQUIRE(sdp_get_bool(&test, &value));
224272343Sngie	ATF_CHECK_EQ(value, false);
225272343Sngie
226272343Sngie	ATF_REQUIRE_EQ(sdp_get_bool(&test, &value), false);	/* not bool */
227272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
228272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
229272343Sngie
230272343Sngie	ATF_REQUIRE(sdp_get_bool(&test, &value));
231272343Sngie	ATF_CHECK_EQ(value, true);
232272343Sngie
233272343Sngie	ATF_CHECK_EQ(test.next, test.end);
234272343Sngie}
235272343Sngie
236272343SngieATF_TC(check_sdp_get_uint);
237272343Sngie
238272343SngieATF_TC_HEAD(check_sdp_get_uint, tc)
239272343Sngie{
240272343Sngie
241272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_uint results");
242272343Sngie}
243272343Sngie
244272343SngieATF_TC_BODY(check_sdp_get_uint, tc)
245272343Sngie{
246272343Sngie	uint8_t data[] = {
247272343Sngie		0x08, 0x00,		// uint8	0x00
248272343Sngie		0x08, 0xff,		// uint8	0xff
249272343Sngie		0x09, 0x01, 0x02,	// uint16	0x0102
250272343Sngie		0x09, 0xff, 0xff,	// uint16	0xffff
251272343Sngie		0x00,			// nil
252272343Sngie		0x0a, 0x01, 0x02, 0x03,	// uint32	0x01020304
253272343Sngie		0x04,
254272343Sngie		0x0a, 0xff, 0xff, 0xff,	// uint32	0xffffffff
255272343Sngie		0xff,
256272343Sngie		0x0b, 0x01, 0x02, 0x03,	// uint64	0x0102030405060708
257272343Sngie		0x04, 0x05, 0x06, 0x07,
258272343Sngie		0x08,
259272343Sngie		0x0b, 0xff, 0xff, 0xff,	// uint64	0xffffffffffffffff
260272343Sngie		0xff, 0xff, 0xff, 0xff,
261272343Sngie		0xff,
262272343Sngie		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000000000000000000000
263272343Sngie		0x00, 0x00, 0x00, 0x00,
264272343Sngie		0x00, 0x00, 0x00, 0x00,
265272343Sngie		0x00, 0x00, 0x00, 0x00,
266272343Sngie		0x00,
267272343Sngie		0x0c, 0x00, 0x00, 0x00,	// uint128	0x00000000000000010000000000000000
268272343Sngie		0x00, 0x00, 0x00, 0x00,
269272343Sngie		0x01, 0x00, 0x00, 0x00,
270272343Sngie		0x00, 0x00, 0x00, 0x00,
271272343Sngie		0x00,
272272343Sngie		0x0c, 0x00, 0x00, 0x00,	// uint128	0x0000000000000000ffffffffffffffff
273272343Sngie		0x00, 0x00, 0x00, 0x00,
274272343Sngie		0x00, 0xff, 0xff, 0xff,
275272343Sngie		0xff, 0xff, 0xff, 0xff,
276272343Sngie		0xff,
277272343Sngie	};
278272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
279272343Sngie	sdp_data_t nil;
280272343Sngie	uintmax_t value;
281272343Sngie
282272343Sngie	/*
283272343Sngie	 * sdp_get_uint expects any UINT type, advancing test if successful
284272343Sngie	 */
285272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
286272343Sngie	ATF_CHECK_EQ(value, 0x00);
287272343Sngie
288272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
289272343Sngie	ATF_CHECK_EQ(value, UINT8_MAX);
290272343Sngie
291272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
292272343Sngie	ATF_CHECK_EQ(value, 0x0102);
293272343Sngie
294272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
295272343Sngie	ATF_CHECK_EQ(value, UINT16_MAX);
296272343Sngie
297272343Sngie	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* not uint */
298272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
299272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
300272343Sngie
301272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
302272343Sngie	ATF_CHECK_EQ(value, 0x01020304);
303272343Sngie
304272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
305272343Sngie	ATF_CHECK_EQ(value, UINT32_MAX);
306272343Sngie
307272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
308272343Sngie	ATF_CHECK_EQ(value, 0x0102030405060708);
309272343Sngie
310272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
311272343Sngie	ATF_CHECK_EQ(value, UINT64_MAX);
312272343Sngie
313272343Sngie	/*
314272343Sngie	 * expected failure is that we cannot decode UINT128 values larger than UINT64
315272343Sngie	 */
316272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
317272343Sngie	ATF_CHECK_EQ(value, 0x00000000000000000000000000000000);
318272343Sngie
319272343Sngie	ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false);	/* overflow */
320272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
321272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_UINT128);
322272343Sngie
323272343Sngie	ATF_REQUIRE(sdp_get_uint(&test, &value));
324272343Sngie	ATF_CHECK_EQ(value, UINT64_MAX);
325272343Sngie
326272343Sngie	ATF_CHECK_EQ(test.next, test.end);
327272343Sngie}
328272343Sngie
329272343SngieATF_TC(check_sdp_get_int);
330272343Sngie
331272343SngieATF_TC_HEAD(check_sdp_get_int, tc)
332272343Sngie{
333272343Sngie
334272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_int results");
335272343Sngie}
336272343Sngie
337272343SngieATF_TC_BODY(check_sdp_get_int, tc)
338272343Sngie{
339272343Sngie	uint8_t data[] = {
340272343Sngie		0x10, 0x00,		// int8		0x00
341272343Sngie		0x10, 0x7f,		// int8		0x7f
342272343Sngie		0x10, 0x80,		// int8		0x80
343272343Sngie		0x11, 0x01, 0x02,	// int16	0x0102
344272343Sngie		0x11, 0x7f, 0xff,	// int16	0x7fff
345272343Sngie		0x11, 0x80, 0x00,	// int16	0x8000
346272343Sngie		0x00,			// nil
347272343Sngie		0x12, 0x01, 0x02, 0x03,	// int32	0x01020304
348272343Sngie		0x04,
349272343Sngie		0x12, 0x7f, 0xff, 0xff,	// int32	0x7fffffff
350272343Sngie		0xff,
351272343Sngie		0x12, 0x80, 0x00, 0x00,	// int32	0x80000000
352272343Sngie		0x00,
353272343Sngie		0x13, 0x01, 0x02, 0x03,	// int64	0x0102030405060708
354272343Sngie		0x04, 0x05, 0x06, 0x07,
355272343Sngie		0x08,
356272343Sngie		0x13, 0x7f, 0xff, 0xff,	// int64	0x7fffffffffffffff
357272343Sngie		0xff, 0xff, 0xff, 0xff,
358272343Sngie		0xff,
359272343Sngie		0x13, 0x80, 0x00, 0x00,	// int64	0x8000000000000000
360272343Sngie		0x00, 0x00, 0x00, 0x00,
361272343Sngie		0x00,
362272343Sngie		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000000000000000000000
363272343Sngie		0x00, 0x00, 0x00, 0x00,
364272343Sngie		0x00, 0x00, 0x00, 0x00,
365272343Sngie		0x00, 0x00, 0x00, 0x00,
366272343Sngie		0x00,
367272343Sngie		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000007fffffffffffffff
368272343Sngie		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX)
369272343Sngie		0x00, 0x7f, 0xff, 0xff,
370272343Sngie		0xff, 0xff, 0xff, 0xff,
371272343Sngie		0xff,
372272343Sngie		0x14, 0x00, 0x00, 0x00,	// int128	0x00000000000000008000000000000000
373272343Sngie		0x00, 0x00, 0x00, 0x00,	//			(INT64_MAX + 1)
374272343Sngie		0x00, 0x80, 0x00, 0x00,
375272343Sngie		0x00, 0x00, 0x00, 0x00,
376272343Sngie		0x00,
377272343Sngie		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff8000000000000000
378272343Sngie		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN)
379272343Sngie		0xff, 0x80, 0x00, 0x00,
380272343Sngie		0x00, 0x00, 0x00, 0x00,
381272343Sngie		0x00,
382272343Sngie		0x14, 0xff, 0xff, 0xff,	// int128	0xffffffffffffffff7fffffffffffffff
383272343Sngie		0xff, 0xff, 0xff, 0xff,	//			(INT64_MIN - 1)
384272343Sngie		0xff, 0x7f, 0xff, 0xff,
385272343Sngie		0xff, 0xff, 0xff, 0xff,
386272343Sngie		0xff,
387272343Sngie	};
388272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
389272343Sngie	sdp_data_t nil;
390272343Sngie	intmax_t value;
391272343Sngie
392272343Sngie	/*
393272343Sngie	 * sdp_get_int expects any INT type, advancing test if successful
394272343Sngie	 */
395272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
396272343Sngie	ATF_CHECK_EQ(value, 0);
397272343Sngie
398272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
399272343Sngie	ATF_CHECK_EQ(value, INT8_MAX);
400272343Sngie
401272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
402272343Sngie	ATF_CHECK_EQ(value, INT8_MIN);
403272343Sngie
404272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
405272343Sngie	ATF_CHECK_EQ(value, 0x0102);
406272343Sngie
407272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
408272343Sngie	ATF_CHECK_EQ(value, INT16_MAX);
409272343Sngie
410272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
411272343Sngie	ATF_CHECK_EQ(value, INT16_MIN);
412272343Sngie
413272343Sngie	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* not int */
414272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
415272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
416272343Sngie
417272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
418272343Sngie	ATF_CHECK_EQ(value, 0x01020304);
419272343Sngie
420272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
421272343Sngie	ATF_CHECK_EQ(value, INT32_MAX);
422272343Sngie
423272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
424272343Sngie	ATF_CHECK_EQ(value, INT32_MIN);
425272343Sngie
426272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
427272343Sngie	ATF_CHECK_EQ(value, 0x0102030405060708);
428272343Sngie
429272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
430272343Sngie	ATF_CHECK_EQ(value, INT64_MAX);
431272343Sngie
432272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
433272343Sngie	ATF_CHECK_EQ(value, INT64_MIN);
434272343Sngie
435272343Sngie	/*
436272343Sngie	 * expected failure is that we cannot decode INT128 values larger than INT64
437272343Sngie	 */
438272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
439272343Sngie	ATF_CHECK_EQ(value, 0);
440272343Sngie
441272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
442272343Sngie	ATF_CHECK_EQ(value, INT64_MAX);
443272343Sngie
444272343Sngie	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* overflow */
445272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
446272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
447272343Sngie
448272343Sngie	ATF_REQUIRE(sdp_get_int(&test, &value));
449272343Sngie	ATF_CHECK_EQ(value, INT64_MIN);
450272343Sngie
451272343Sngie	ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false);	/* underflow */
452272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
453272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128);
454272343Sngie
455272343Sngie	ATF_CHECK_EQ(test.next, test.end);
456272343Sngie}
457272343Sngie
458272343SngieATF_TC(check_sdp_get_seq);
459272343Sngie
460272343SngieATF_TC_HEAD(check_sdp_get_seq, tc)
461272343Sngie{
462272343Sngie
463272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_seq results");
464272343Sngie}
465272343Sngie
466272343SngieATF_TC_BODY(check_sdp_get_seq, tc)
467272343Sngie{
468272343Sngie	uint8_t data[] = {
469272343Sngie		0x35, 0x00,		// seq8(0)
470272343Sngie		0x00,			// nil
471272343Sngie		0x36, 0x00, 0x00,	// seq16(0)
472272343Sngie		0x37, 0x00, 0x00, 0x00,	// seq32(0)
473272343Sngie		0x00,
474272343Sngie	};
475272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
476272343Sngie	sdp_data_t value;
477272343Sngie
478272343Sngie	/*
479272343Sngie	 * sdp_get_seq expects a SEQ type
480272343Sngie	 * advancing test if successful
481272343Sngie	 */
482272343Sngie	ATF_REQUIRE(sdp_get_seq(&test, &value));
483272343Sngie	ATF_CHECK_EQ(value.next, value.end);
484272343Sngie
485272343Sngie	ATF_REQUIRE_EQ(sdp_get_seq(&test, &value), false);	/* not seq */
486272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
487272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
488272343Sngie
489272343Sngie	ATF_REQUIRE(sdp_get_seq(&test, &value));
490272343Sngie	ATF_CHECK_EQ(value.next, value.end);
491272343Sngie
492272343Sngie	ATF_REQUIRE(sdp_get_seq(&test, &value));
493272343Sngie	ATF_CHECK_EQ(value.next, value.end);
494272343Sngie
495272343Sngie	ATF_CHECK_EQ(test.next, test.end);
496272343Sngie}
497272343Sngie
498272343SngieATF_TC(check_sdp_get_alt);
499272343Sngie
500272343SngieATF_TC_HEAD(check_sdp_get_alt, tc)
501272343Sngie{
502272343Sngie
503272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_alt results");
504272343Sngie}
505272343Sngie
506272343SngieATF_TC_BODY(check_sdp_get_alt, tc)
507272343Sngie{
508272343Sngie	uint8_t data[] = {
509272343Sngie		0x3d, 0x00,		// alt8(0)
510272343Sngie		0x00,			// nil
511272343Sngie		0x3e, 0x00, 0x00,	// alt16(0)
512272343Sngie		0x3f, 0x00, 0x00, 0x00,	// alt32(0)
513272343Sngie		0x00,
514272343Sngie	};
515272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
516272343Sngie	sdp_data_t value;
517272343Sngie
518272343Sngie	/*
519272343Sngie	 * sdp_get_alt expects a ALT type
520272343Sngie	 * advancing test if successful
521272343Sngie	 */
522272343Sngie	ATF_REQUIRE(sdp_get_alt(&test, &value));
523272343Sngie	ATF_CHECK_EQ(value.next, value.end);
524272343Sngie
525272343Sngie	ATF_REQUIRE_EQ(sdp_get_alt(&test, &value), false);	/* not alt */
526272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &value));		/* (skip) */
527272343Sngie	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
528272343Sngie
529272343Sngie	ATF_REQUIRE(sdp_get_alt(&test, &value));
530272343Sngie	ATF_CHECK_EQ(value.next, value.end);
531272343Sngie
532272343Sngie	ATF_REQUIRE(sdp_get_alt(&test, &value));
533272343Sngie	ATF_CHECK_EQ(value.next, value.end);
534272343Sngie
535272343Sngie	ATF_CHECK_EQ(test.next, test.end);
536272343Sngie}
537272343Sngie
538272343SngieATF_TC(check_sdp_get_str);
539272343Sngie
540272343SngieATF_TC_HEAD(check_sdp_get_str, tc)
541272343Sngie{
542272343Sngie
543272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_str results");
544272343Sngie}
545272343Sngie
546272343SngieATF_TC_BODY(check_sdp_get_str, tc)
547272343Sngie{
548272343Sngie	uint8_t data[] = {
549272343Sngie		0x25, 0x04, 0x53, 0x54, // str8(4)	"STR8"
550272343Sngie		0x52, 0x38,
551272343Sngie		0x00,			// nil
552272343Sngie		0x26, 0x00, 0x05, 0x53,	// str16(5)	"STR16"
553272343Sngie		0x54, 0x52, 0x31, 0x36,
554272343Sngie		0x27, 0x00, 0x00, 0x00,	// str32(5)	"STR32"
555272343Sngie		0x05, 0x53, 0x54, 0x52,
556272343Sngie		0x33, 0x32,
557272343Sngie	};
558272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
559272343Sngie	sdp_data_t nil;
560272343Sngie	char *str;
561272343Sngie	size_t len;
562272343Sngie
563272343Sngie	/*
564272343Sngie	 * sdp_get_str expects a STR type
565272343Sngie	 * advancing test if successful
566272343Sngie	 */
567272343Sngie	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
568272343Sngie	ATF_CHECK(len == 4 && strncmp(str, "STR8", 4) == 0);
569272343Sngie
570272343Sngie	ATF_REQUIRE_EQ(sdp_get_str(&test, &str, &len), false);	/* not str */
571272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
572272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
573272343Sngie
574272343Sngie	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
575272343Sngie	ATF_CHECK(len == 5 && strncmp(str, "STR16", 5) == 0);
576272343Sngie
577272343Sngie	ATF_REQUIRE(sdp_get_str(&test, &str, &len));
578272343Sngie	ATF_CHECK(len == 5 && strncmp(str, "STR32", 5) == 0);
579272343Sngie
580272343Sngie	ATF_CHECK_EQ(test.next, test.end);
581272343Sngie}
582272343Sngie
583272343SngieATF_TC(check_sdp_get_url);
584272343Sngie
585272343SngieATF_TC_HEAD(check_sdp_get_url, tc)
586272343Sngie{
587272343Sngie
588272343Sngie	atf_tc_set_md_var(tc, "descr", "Test sdp_get_url results");
589272343Sngie}
590272343Sngie
591272343SngieATF_TC_BODY(check_sdp_get_url, tc)
592272343Sngie{
593272343Sngie	uint8_t data[] = {
594272343Sngie		0x45, 0x04, 0x55, 0x52, // url8(4)	"URL8"
595272343Sngie		0x4c, 0x38,
596272343Sngie		0x00,			// nil
597272343Sngie		0x46, 0x00, 0x05, 0x55,	// url16(5)	"URL16"
598272343Sngie		0x52, 0x4c, 0x31, 0x36,
599272343Sngie		0x47, 0x00, 0x00, 0x00,	// url32(5)	"URL32"
600272343Sngie		0x05, 0x55, 0x52, 0x4c,
601272343Sngie		0x33, 0x32,
602272343Sngie	};
603272343Sngie	sdp_data_t test = { data, data + sizeof(data) };
604272343Sngie	sdp_data_t nil;
605272343Sngie	char *url;
606272343Sngie	size_t len;
607272343Sngie
608272343Sngie	/*
609272343Sngie	 * sdp_get_url expects a URL type
610272343Sngie	 * advancing test if successful
611272343Sngie	 */
612272343Sngie	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
613272343Sngie	ATF_CHECK(len == 4 && strncmp(url, "URL8", 4) == 0);
614272343Sngie
615272343Sngie	ATF_REQUIRE_EQ(sdp_get_url(&test, &url, &len), false);	/* not url */
616272343Sngie	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
617272343Sngie	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
618272343Sngie
619272343Sngie	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
620272343Sngie	ATF_CHECK(len == 5 && strncmp(url, "URL16", 5) == 0);
621272343Sngie
622272343Sngie	ATF_REQUIRE(sdp_get_url(&test, &url, &len));
623272343Sngie	ATF_CHECK(len == 5 && strncmp(url, "URL32", 5) == 0);
624272343Sngie
625272343Sngie	ATF_CHECK_EQ(test.next, test.end);
626272343Sngie}
627272343Sngie
628272343SngieATF_TP_ADD_TCS(tp)
629272343Sngie{
630272343Sngie
631272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_data);
632272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_attr);
633272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_uuid);
634272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_bool);
635272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_uint);
636272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_int);
637272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_seq);
638272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_alt);
639272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_str);
640272343Sngie	ATF_TP_ADD_TC(tp, check_sdp_get_url);
641272343Sngie
642272343Sngie	return atf_no_error();
643272343Sngie}
644