1*57718be8SEnji Cooper /*	$NetBSD: t_sdp_put.c,v 1.3 2011/04/16 07:32:27 plunky Exp $	*/
2*57718be8SEnji Cooper 
3*57718be8SEnji Cooper /*-
4*57718be8SEnji Cooper  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5*57718be8SEnji Cooper  * All rights reserved.
6*57718be8SEnji Cooper  *
7*57718be8SEnji Cooper  * This code is derived from software contributed to The NetBSD Foundation
8*57718be8SEnji Cooper  * by Iain Hibbert.
9*57718be8SEnji Cooper  *
10*57718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
11*57718be8SEnji Cooper  * modification, are permitted provided that the following conditions
12*57718be8SEnji Cooper  * are met:
13*57718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
14*57718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
15*57718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
16*57718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
17*57718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
18*57718be8SEnji Cooper  *
19*57718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*57718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*57718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*57718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*57718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*57718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*57718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*57718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*57718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*57718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*57718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
30*57718be8SEnji Cooper  */
31*57718be8SEnji Cooper 
32*57718be8SEnji Cooper #include <atf-c.h>
33*57718be8SEnji Cooper 
34*57718be8SEnji Cooper #include <limits.h>
35*57718be8SEnji Cooper #include <sdp.h>
36*57718be8SEnji Cooper #include <string.h>
37*57718be8SEnji Cooper 
38*57718be8SEnji Cooper ATF_TC(check_sdp_put_data);
39*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_data,tc)40*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_data, tc)
41*57718be8SEnji Cooper {
42*57718be8SEnji Cooper 
43*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_data results");
44*57718be8SEnji Cooper }
45*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_data,tc)46*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_data, tc)
47*57718be8SEnji Cooper {
48*57718be8SEnji Cooper 	uint8_t buf[256];
49*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
50*57718be8SEnji Cooper 	uint8_t data[] = {
51*57718be8SEnji Cooper 		0x35, 0x05,		// seq8(5)
52*57718be8SEnji Cooper 		0x08, 0x00,		//   uint8	0x00
53*57718be8SEnji Cooper 		0x09, 0x12, 0x34,	//   uint16	0x1234
54*57718be8SEnji Cooper 	};
55*57718be8SEnji Cooper 	sdp_data_t value = { data, data + sizeof(data) };
56*57718be8SEnji Cooper 
57*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_data(&test, &value));
58*57718be8SEnji Cooper 	test.end = test.next;
59*57718be8SEnji Cooper 	test.next = buf;
60*57718be8SEnji Cooper 
61*57718be8SEnji Cooper 	const uint8_t expect[] = {
62*57718be8SEnji Cooper 		0x35, 0x05,		// seq8(5)
63*57718be8SEnji Cooper 		0x08, 0x00,		//   uint8	0x00
64*57718be8SEnji Cooper 		0x09, 0x12, 0x34,	//   uint16	0x1234
65*57718be8SEnji Cooper 	};
66*57718be8SEnji Cooper 
67*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
68*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
69*57718be8SEnji Cooper }
70*57718be8SEnji Cooper 
71*57718be8SEnji Cooper ATF_TC(check_sdp_put_attr);
72*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_attr,tc)73*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_attr, tc)
74*57718be8SEnji Cooper {
75*57718be8SEnji Cooper 
76*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_attr results");
77*57718be8SEnji Cooper }
78*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_attr,tc)79*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_attr, tc)
80*57718be8SEnji Cooper {
81*57718be8SEnji Cooper 	uint8_t buf[256];
82*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
83*57718be8SEnji Cooper 	uint8_t data[] = {
84*57718be8SEnji Cooper 		0x00,			// nil
85*57718be8SEnji Cooper 		0x19, 0x33, 0x44,	// uuid16	0x3344
86*57718be8SEnji Cooper 	};
87*57718be8SEnji Cooper 	sdp_data_t value = { data, data + sizeof(data) };
88*57718be8SEnji Cooper 
89*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(sdp_put_attr(&test, 0xabcd, &value), false);
90*57718be8SEnji Cooper 	value.next += 1; // skip "nil"
91*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_attr(&test, 0x1337, &value));
92*57718be8SEnji Cooper 	test.end = test.next;
93*57718be8SEnji Cooper 	test.next = buf;
94*57718be8SEnji Cooper 
95*57718be8SEnji Cooper 	const uint8_t expect[] = {
96*57718be8SEnji Cooper 		0x09, 0x13, 0x37,	// uint16	0x1337
97*57718be8SEnji Cooper 		0x19, 0x33, 0x44,	// uuid16	0x3344
98*57718be8SEnji Cooper 	};
99*57718be8SEnji Cooper 
100*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
101*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
102*57718be8SEnji Cooper }
103*57718be8SEnji Cooper 
104*57718be8SEnji Cooper ATF_TC(check_sdp_put_uuid);
105*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uuid,tc)106*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uuid, tc)
107*57718be8SEnji Cooper {
108*57718be8SEnji Cooper 
109*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid results");
110*57718be8SEnji Cooper }
111*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uuid,tc)112*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uuid, tc)
113*57718be8SEnji Cooper {
114*57718be8SEnji Cooper 	uint8_t buf[256];
115*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
116*57718be8SEnji Cooper 	const uuid_t u16 = {
117*57718be8SEnji Cooper 		0x00001234,
118*57718be8SEnji Cooper 		0x0000,
119*57718be8SEnji Cooper 		0x1000,
120*57718be8SEnji Cooper 		0x80,
121*57718be8SEnji Cooper 		0x00,
122*57718be8SEnji Cooper 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
123*57718be8SEnji Cooper 	};
124*57718be8SEnji Cooper 	const uuid_t u32 = {
125*57718be8SEnji Cooper 		0x12345678,
126*57718be8SEnji Cooper 		0x0000,
127*57718be8SEnji Cooper 		0x1000,
128*57718be8SEnji Cooper 		0x80,
129*57718be8SEnji Cooper 		0x00,
130*57718be8SEnji Cooper 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
131*57718be8SEnji Cooper 	};
132*57718be8SEnji Cooper 	const uuid_t u128 = {
133*57718be8SEnji Cooper 		0x00112233,
134*57718be8SEnji Cooper 		0x4444,
135*57718be8SEnji Cooper 		0x5555,
136*57718be8SEnji Cooper 		0x66,
137*57718be8SEnji Cooper 		0x77,
138*57718be8SEnji Cooper 		{ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }
139*57718be8SEnji Cooper 	};
140*57718be8SEnji Cooper 
141*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uuid(&test, &u16));
142*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uuid(&test, &u32));
143*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uuid(&test, &u128));
144*57718be8SEnji Cooper 	test.end = test.next;
145*57718be8SEnji Cooper 	test.next = buf;
146*57718be8SEnji Cooper 
147*57718be8SEnji Cooper 	const uint8_t expect[] = {
148*57718be8SEnji Cooper 		0x19, 0x12, 0x34,	// uuid16	0x1234
149*57718be8SEnji Cooper 		0x1a, 0x12, 0x34, 0x56, // uuid32	0x12345678
150*57718be8SEnji Cooper 		0x78,
151*57718be8SEnji Cooper 		0x1c, 0x00, 0x11, 0x22,	// uuid128	00112233-4444-5555-6677-8899aabbccdd
152*57718be8SEnji Cooper 		0x33, 0x44, 0x44, 0x55,
153*57718be8SEnji Cooper 		0x55, 0x66, 0x77, 0x88,
154*57718be8SEnji Cooper 		0x99, 0xaa, 0xbb, 0xcc,
155*57718be8SEnji Cooper 		0xdd,
156*57718be8SEnji Cooper 	};
157*57718be8SEnji Cooper 
158*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
159*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
160*57718be8SEnji Cooper }
161*57718be8SEnji Cooper 
162*57718be8SEnji Cooper ATF_TC(check_sdp_put_uuid16);
163*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uuid16,tc)164*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uuid16, tc)
165*57718be8SEnji Cooper {
166*57718be8SEnji Cooper 
167*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid16 results");
168*57718be8SEnji Cooper }
169*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uuid16,tc)170*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uuid16, tc)
171*57718be8SEnji Cooper {
172*57718be8SEnji Cooper 	uint8_t buf[256];
173*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
174*57718be8SEnji Cooper 
175*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uuid16(&test, 0x4567));
176*57718be8SEnji Cooper 	test.end = test.next;
177*57718be8SEnji Cooper 	test.next = buf;
178*57718be8SEnji Cooper 
179*57718be8SEnji Cooper 	const uint8_t expect[] = {
180*57718be8SEnji Cooper 		0x19, 0x45, 0x67,	// uuid16	0x4567
181*57718be8SEnji Cooper 	};
182*57718be8SEnji Cooper 
183*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
184*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
185*57718be8SEnji Cooper }
186*57718be8SEnji Cooper 
187*57718be8SEnji Cooper ATF_TC(check_sdp_put_uuid32);
188*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uuid32,tc)189*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uuid32, tc)
190*57718be8SEnji Cooper {
191*57718be8SEnji Cooper 
192*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid32 results");
193*57718be8SEnji Cooper }
194*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uuid32,tc)195*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uuid32, tc)
196*57718be8SEnji Cooper {
197*57718be8SEnji Cooper 	uint8_t buf[256];
198*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
199*57718be8SEnji Cooper 
200*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uuid32(&test, 0xabcdef00));
201*57718be8SEnji Cooper 	test.end = test.next;
202*57718be8SEnji Cooper 	test.next = buf;
203*57718be8SEnji Cooper 
204*57718be8SEnji Cooper 	const uint8_t expect[] = {
205*57718be8SEnji Cooper 		0x1a, 0xab, 0xcd, 0xef, // uuid32	0xabcdef00
206*57718be8SEnji Cooper 		0x00,
207*57718be8SEnji Cooper 	};
208*57718be8SEnji Cooper 
209*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
210*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
211*57718be8SEnji Cooper }
212*57718be8SEnji Cooper 
213*57718be8SEnji Cooper ATF_TC(check_sdp_put_uuid128);
214*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uuid128,tc)215*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uuid128, tc)
216*57718be8SEnji Cooper {
217*57718be8SEnji Cooper 
218*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid128 results");
219*57718be8SEnji Cooper }
220*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uuid128,tc)221*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uuid128, tc)
222*57718be8SEnji Cooper {
223*57718be8SEnji Cooper 	uint8_t buf[256];
224*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
225*57718be8SEnji Cooper 	uuid_t value = {
226*57718be8SEnji Cooper 		0x00000100,
227*57718be8SEnji Cooper 		0x0000,
228*57718be8SEnji Cooper 		0x1000,
229*57718be8SEnji Cooper 		0x80,
230*57718be8SEnji Cooper 		0x00,
231*57718be8SEnji Cooper 		{ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
232*57718be8SEnji Cooper 	};
233*57718be8SEnji Cooper 
234*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uuid128(&test, &value));
235*57718be8SEnji Cooper 	test.end = test.next;
236*57718be8SEnji Cooper 	test.next = buf;
237*57718be8SEnji Cooper 
238*57718be8SEnji Cooper 	const uint8_t expect[] = {
239*57718be8SEnji Cooper 		0x1c, 0x00, 0x00, 0x01,	// uuid128	0000100-0000-1000-8000-00805f9b34fb
240*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x10,	//			(L2CAP protocol)
241*57718be8SEnji Cooper 		0x00, 0x80, 0x00, 0x00,
242*57718be8SEnji Cooper 		0x80, 0x5f, 0x9b, 0x34,
243*57718be8SEnji Cooper 		0xfb,
244*57718be8SEnji Cooper 	};
245*57718be8SEnji Cooper 
246*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
247*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
248*57718be8SEnji Cooper }
249*57718be8SEnji Cooper 
250*57718be8SEnji Cooper ATF_TC(check_sdp_put_bool);
251*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_bool,tc)252*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_bool, tc)
253*57718be8SEnji Cooper {
254*57718be8SEnji Cooper 
255*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_bool results");
256*57718be8SEnji Cooper }
257*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_bool,tc)258*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_bool, tc)
259*57718be8SEnji Cooper {
260*57718be8SEnji Cooper 	uint8_t buf[256];
261*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
262*57718be8SEnji Cooper 
263*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_bool(&test, true));
264*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_bool(&test, false));
265*57718be8SEnji Cooper 	test.end = test.next;
266*57718be8SEnji Cooper 	test.next = buf;
267*57718be8SEnji Cooper 
268*57718be8SEnji Cooper 	const uint8_t expect[] = {
269*57718be8SEnji Cooper 		0x28, 0x01,		// bool	true
270*57718be8SEnji Cooper 		0x28, 0x00,		// bool	false
271*57718be8SEnji Cooper 	};
272*57718be8SEnji Cooper 
273*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
274*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
275*57718be8SEnji Cooper }
276*57718be8SEnji Cooper 
277*57718be8SEnji Cooper ATF_TC(check_sdp_put_uint);
278*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uint,tc)279*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uint, tc)
280*57718be8SEnji Cooper {
281*57718be8SEnji Cooper 
282*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint results");
283*57718be8SEnji Cooper }
284*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uint,tc)285*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uint, tc)
286*57718be8SEnji Cooper {
287*57718be8SEnji Cooper 	uint8_t buf[256];
288*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
289*57718be8SEnji Cooper 
290*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)0));
291*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT8_MAX));
292*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT8_MAX + 1));
293*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT16_MAX));
294*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT16_MAX + 1));
295*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT32_MAX));
296*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT32_MAX + 1));
297*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT64_MAX));
298*57718be8SEnji Cooper 	test.end = test.next;
299*57718be8SEnji Cooper 	test.next = buf;
300*57718be8SEnji Cooper 
301*57718be8SEnji Cooper 	const uint8_t expect[] = {
302*57718be8SEnji Cooper 		0x08, 0x00,		// uint8	0x00
303*57718be8SEnji Cooper 		0x08, 0xff,		// uint8	0xff
304*57718be8SEnji Cooper 		0x09, 0x01, 0x00,	// uint16	0x0100
305*57718be8SEnji Cooper 		0x09, 0xff, 0xff,	// uint16	0xffff
306*57718be8SEnji Cooper 		0x0a, 0x00, 0x01, 0x00,	// uint32	0x00010000
307*57718be8SEnji Cooper 		0x00,
308*57718be8SEnji Cooper 		0x0a, 0xff, 0xff, 0xff,	// uint32	0xffffffff
309*57718be8SEnji Cooper 		0xff,
310*57718be8SEnji Cooper 		0x0b, 0x00, 0x00, 0x00,	// uint64	0x0000000100000000
311*57718be8SEnji Cooper 		0x01, 0x00, 0x00, 0x00,
312*57718be8SEnji Cooper 		0x00,
313*57718be8SEnji Cooper 		0x0b, 0xff, 0xff, 0xff,	// uint64	0xffffffffffffffff
314*57718be8SEnji Cooper 		0xff, 0xff, 0xff, 0xff,
315*57718be8SEnji Cooper 		0xff,
316*57718be8SEnji Cooper 	};
317*57718be8SEnji Cooper 
318*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
319*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
320*57718be8SEnji Cooper }
321*57718be8SEnji Cooper 
322*57718be8SEnji Cooper ATF_TC(check_sdp_put_uint8);
323*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uint8,tc)324*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uint8, tc)
325*57718be8SEnji Cooper {
326*57718be8SEnji Cooper 
327*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint8 results");
328*57718be8SEnji Cooper }
329*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uint8,tc)330*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uint8, tc)
331*57718be8SEnji Cooper {
332*57718be8SEnji Cooper 	uint8_t buf[256];
333*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
334*57718be8SEnji Cooper 
335*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint8(&test, (uint8_t)0));
336*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint8(&test, (uint8_t)UINT8_MAX));
337*57718be8SEnji Cooper 	test.end = test.next;
338*57718be8SEnji Cooper 	test.next = buf;
339*57718be8SEnji Cooper 
340*57718be8SEnji Cooper 	const uint8_t expect[] = {
341*57718be8SEnji Cooper 		0x08, 0x00,		// uint8	0x00
342*57718be8SEnji Cooper 		0x08, 0xff,		// uint8	0xff
343*57718be8SEnji Cooper 	};
344*57718be8SEnji Cooper 
345*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
346*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
347*57718be8SEnji Cooper }
348*57718be8SEnji Cooper 
349*57718be8SEnji Cooper ATF_TC(check_sdp_put_uint16);
350*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uint16,tc)351*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uint16, tc)
352*57718be8SEnji Cooper {
353*57718be8SEnji Cooper 
354*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint16 results");
355*57718be8SEnji Cooper }
356*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uint16,tc)357*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uint16, tc)
358*57718be8SEnji Cooper {
359*57718be8SEnji Cooper 	uint8_t buf[256];
360*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
361*57718be8SEnji Cooper 
362*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)0));
363*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)UINT8_MAX));
364*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)UINT16_MAX));
365*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)0xabcd));
366*57718be8SEnji Cooper 	test.end = test.next;
367*57718be8SEnji Cooper 	test.next = buf;
368*57718be8SEnji Cooper 
369*57718be8SEnji Cooper 	const uint8_t expect[] = {
370*57718be8SEnji Cooper 		0x09, 0x00, 0x00,	// uint16	0x0000
371*57718be8SEnji Cooper 		0x09, 0x00, 0xff,	// uint16	0x00ff
372*57718be8SEnji Cooper 		0x09, 0xff, 0xff,	// uint16	0xffff
373*57718be8SEnji Cooper 		0x09, 0xab, 0xcd,	// uint16	0xabcd
374*57718be8SEnji Cooper 	};
375*57718be8SEnji Cooper 
376*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
377*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
378*57718be8SEnji Cooper }
379*57718be8SEnji Cooper 
380*57718be8SEnji Cooper ATF_TC(check_sdp_put_uint32);
381*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uint32,tc)382*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uint32, tc)
383*57718be8SEnji Cooper {
384*57718be8SEnji Cooper 
385*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint32 results");
386*57718be8SEnji Cooper }
387*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uint32,tc)388*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uint32, tc)
389*57718be8SEnji Cooper {
390*57718be8SEnji Cooper 	uint8_t buf[256];
391*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
392*57718be8SEnji Cooper 
393*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)0));
394*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT8_MAX));
395*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT16_MAX));
396*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT32_MAX));
397*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)0xdeadbeef));
398*57718be8SEnji Cooper 	test.end = test.next;
399*57718be8SEnji Cooper 	test.next = buf;
400*57718be8SEnji Cooper 
401*57718be8SEnji Cooper 	const uint8_t expect[] = {
402*57718be8SEnji Cooper 		0x0a, 0x00, 0x00, 0x00,	// uint32	0x00000000
403*57718be8SEnji Cooper 		0x00,
404*57718be8SEnji Cooper 		0x0a, 0x00, 0x00, 0x00,	// uint32	0x000000ff
405*57718be8SEnji Cooper 		0xff,
406*57718be8SEnji Cooper 		0x0a, 0x00, 0x00, 0xff,	// uint32	0x0000ffff
407*57718be8SEnji Cooper 		0xff,
408*57718be8SEnji Cooper 		0x0a, 0xff, 0xff, 0xff,	// uint32	0xffffffff
409*57718be8SEnji Cooper 		0xff,
410*57718be8SEnji Cooper 		0x0a, 0xde, 0xad, 0xbe,	// uint32	0xdeadbeef
411*57718be8SEnji Cooper 		0xef,
412*57718be8SEnji Cooper 	};
413*57718be8SEnji Cooper 
414*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
415*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
416*57718be8SEnji Cooper }
417*57718be8SEnji Cooper 
418*57718be8SEnji Cooper ATF_TC(check_sdp_put_uint64);
419*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_uint64,tc)420*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_uint64, tc)
421*57718be8SEnji Cooper {
422*57718be8SEnji Cooper 
423*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint64 results");
424*57718be8SEnji Cooper }
425*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_uint64,tc)426*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_uint64, tc)
427*57718be8SEnji Cooper {
428*57718be8SEnji Cooper 	uint8_t buf[256];
429*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
430*57718be8SEnji Cooper 
431*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)0));
432*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT8_MAX));
433*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT16_MAX));
434*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT32_MAX));
435*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT64_MAX));
436*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)0xc0ffeecafec0ffee));
437*57718be8SEnji Cooper 	test.end = test.next;
438*57718be8SEnji Cooper 	test.next = buf;
439*57718be8SEnji Cooper 
440*57718be8SEnji Cooper 	const uint8_t expect[] = {
441*57718be8SEnji Cooper 		0x0b, 0x00, 0x00, 0x00,	// uint64	0x0000000000000000
442*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x00,
443*57718be8SEnji Cooper 		0x00,
444*57718be8SEnji Cooper 		0x0b, 0x00, 0x00, 0x00,	// uint64	0x00000000000000ff
445*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x00,
446*57718be8SEnji Cooper 		0xff,
447*57718be8SEnji Cooper 		0x0b, 0x00, 0x00, 0x00,	// uint64	0x000000000000ffff
448*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0xff,
449*57718be8SEnji Cooper 		0xff,
450*57718be8SEnji Cooper 		0x0b, 0x00, 0x00, 0x00,	// uint64	0x00000000ffffffff
451*57718be8SEnji Cooper 		0x00, 0xff, 0xff, 0xff,
452*57718be8SEnji Cooper 		0xff,
453*57718be8SEnji Cooper 		0x0b, 0xff, 0xff, 0xff,	// uint64	0xffffffffffffffff
454*57718be8SEnji Cooper 		0xff, 0xff, 0xff, 0xff,
455*57718be8SEnji Cooper 		0xff,
456*57718be8SEnji Cooper 		0x0b, 0xc0, 0xff, 0xee,	// uint64	0xc0ffeecafec0ffee
457*57718be8SEnji Cooper 		0xca, 0xfe, 0xc0, 0xff,
458*57718be8SEnji Cooper 		0xee,
459*57718be8SEnji Cooper 	};
460*57718be8SEnji Cooper 
461*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
462*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
463*57718be8SEnji Cooper }
464*57718be8SEnji Cooper 
465*57718be8SEnji Cooper ATF_TC(check_sdp_put_int);
466*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_int,tc)467*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_int, tc)
468*57718be8SEnji Cooper {
469*57718be8SEnji Cooper 
470*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_int results");
471*57718be8SEnji Cooper }
472*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_int,tc)473*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_int, tc)
474*57718be8SEnji Cooper {
475*57718be8SEnji Cooper 	uint8_t buf[256];
476*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
477*57718be8SEnji Cooper 
478*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)0));
479*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MIN));
480*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MAX));
481*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MIN - 1));
482*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MAX + 1));
483*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MIN));
484*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MAX));
485*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MIN - 1));
486*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MAX + 1));
487*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MIN));
488*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MAX));
489*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MIN - 1));
490*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MAX + 1));
491*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT64_MIN));
492*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT64_MAX));
493*57718be8SEnji Cooper 	test.end = test.next;
494*57718be8SEnji Cooper 	test.next = buf;
495*57718be8SEnji Cooper 
496*57718be8SEnji Cooper 	const uint8_t expect[] = {
497*57718be8SEnji Cooper 		0x10, 0x00,		// int8		0
498*57718be8SEnji Cooper 		0x10, 0x80,		// int8		-128
499*57718be8SEnji Cooper 		0x10, 0x7f,		// int8		127
500*57718be8SEnji Cooper 		0x11, 0xff, 0x7f,	// int16	-129
501*57718be8SEnji Cooper 		0x11, 0x00, 0x80,	// int16	128
502*57718be8SEnji Cooper 		0x11, 0x80, 0x00,	// int16	-32768
503*57718be8SEnji Cooper 		0x11, 0x7f, 0xff,	// int16	32767
504*57718be8SEnji Cooper 		0x12, 0xff, 0xff, 0x7f,	// int32	-32769
505*57718be8SEnji Cooper 		0xff,
506*57718be8SEnji Cooper 		0x12, 0x00, 0x00, 0x80,	// int32	32768
507*57718be8SEnji Cooper 		0x00,
508*57718be8SEnji Cooper 		0x12, 0x80, 0x00, 0x00,	// int32	-2147483648
509*57718be8SEnji Cooper 		0x00,
510*57718be8SEnji Cooper 		0x12, 0x7f, 0xff, 0xff,	// int32	2147483647
511*57718be8SEnji Cooper 		0xff,
512*57718be8SEnji Cooper 		0x13, 0xff, 0xff, 0xff,	// int64	-2147483649
513*57718be8SEnji Cooper 		0xff, 0x7f, 0xff, 0xff,
514*57718be8SEnji Cooper 		0xff,
515*57718be8SEnji Cooper 		0x13, 0x00, 0x00, 0x00,	// int64	2147483648
516*57718be8SEnji Cooper 		0x00, 0x80, 0x00, 0x00,
517*57718be8SEnji Cooper 		0x00,
518*57718be8SEnji Cooper 		0x13, 0x80, 0x00, 0x00,	// int64	-9223372036854775808
519*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x00,
520*57718be8SEnji Cooper 		0x00,
521*57718be8SEnji Cooper 		0x13, 0x7f, 0xff, 0xff,	// int64	9223372036854775807
522*57718be8SEnji Cooper 		0xff, 0xff, 0xff, 0xff,
523*57718be8SEnji Cooper 		0xff,
524*57718be8SEnji Cooper 	};
525*57718be8SEnji Cooper 
526*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
527*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
528*57718be8SEnji Cooper }
529*57718be8SEnji Cooper 
530*57718be8SEnji Cooper ATF_TC(check_sdp_put_int8);
531*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_int8,tc)532*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_int8, tc)
533*57718be8SEnji Cooper {
534*57718be8SEnji Cooper 
535*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_int8 results");
536*57718be8SEnji Cooper }
537*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_int8,tc)538*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_int8, tc)
539*57718be8SEnji Cooper {
540*57718be8SEnji Cooper 	uint8_t buf[256];
541*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
542*57718be8SEnji Cooper 
543*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int8(&test, (int8_t)0));
544*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MIN));
545*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MAX));
546*57718be8SEnji Cooper 	test.end = test.next;
547*57718be8SEnji Cooper 	test.next = buf;
548*57718be8SEnji Cooper 
549*57718be8SEnji Cooper 	const uint8_t expect[] = {
550*57718be8SEnji Cooper 		0x10, 0x00,		// int8		0
551*57718be8SEnji Cooper 		0x10, 0x80,		// int8		-128
552*57718be8SEnji Cooper 		0x10, 0x7f,		// int8		127
553*57718be8SEnji Cooper 	};
554*57718be8SEnji Cooper 
555*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
556*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
557*57718be8SEnji Cooper }
558*57718be8SEnji Cooper 
559*57718be8SEnji Cooper ATF_TC(check_sdp_put_int16);
560*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_int16,tc)561*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_int16, tc)
562*57718be8SEnji Cooper {
563*57718be8SEnji Cooper 
564*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_int16 results");
565*57718be8SEnji Cooper }
566*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_int16,tc)567*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_int16, tc)
568*57718be8SEnji Cooper {
569*57718be8SEnji Cooper 	uint8_t buf[256];
570*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
571*57718be8SEnji Cooper 
572*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int16(&test, (int16_t)0));
573*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MIN));
574*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MAX));
575*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MIN));
576*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MAX));
577*57718be8SEnji Cooper 	test.end = test.next;
578*57718be8SEnji Cooper 	test.next = buf;
579*57718be8SEnji Cooper 
580*57718be8SEnji Cooper 	const uint8_t expect[] = {
581*57718be8SEnji Cooper 		0x11, 0x00, 0x00,	// int16	0
582*57718be8SEnji Cooper 		0x11, 0xff, 0x80,	// int16	-128
583*57718be8SEnji Cooper 		0x11, 0x00, 0x7f,	// int16	127
584*57718be8SEnji Cooper 		0x11, 0x80, 0x00,	// int16	-32768
585*57718be8SEnji Cooper 		0x11, 0x7f, 0xff,	// int16	32767
586*57718be8SEnji Cooper 	};
587*57718be8SEnji Cooper 
588*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
589*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
590*57718be8SEnji Cooper }
591*57718be8SEnji Cooper 
592*57718be8SEnji Cooper ATF_TC(check_sdp_put_int32);
593*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_int32,tc)594*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_int32, tc)
595*57718be8SEnji Cooper {
596*57718be8SEnji Cooper 
597*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_int32 results");
598*57718be8SEnji Cooper }
599*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_int32,tc)600*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_int32, tc)
601*57718be8SEnji Cooper {
602*57718be8SEnji Cooper 	uint8_t buf[256];
603*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
604*57718be8SEnji Cooper 
605*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int32(&test, (int32_t)0));
606*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MIN));
607*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MAX));
608*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MIN));
609*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MAX));
610*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MIN));
611*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MAX));
612*57718be8SEnji Cooper 	test.end = test.next;
613*57718be8SEnji Cooper 	test.next = buf;
614*57718be8SEnji Cooper 
615*57718be8SEnji Cooper 	const uint8_t expect[] = {
616*57718be8SEnji Cooper 		0x12, 0x00, 0x00, 0x00,	// int32	0
617*57718be8SEnji Cooper 		0x00,
618*57718be8SEnji Cooper 		0x12, 0xff, 0xff, 0xff,	// int32	-128
619*57718be8SEnji Cooper 		0x80,
620*57718be8SEnji Cooper 		0x12, 0x00, 0x00, 0x00,	// int32	127
621*57718be8SEnji Cooper 		0x7f,
622*57718be8SEnji Cooper 		0x12, 0xff, 0xff, 0x80,	// int32	-32768
623*57718be8SEnji Cooper 		0x00,
624*57718be8SEnji Cooper 		0x12, 0x00, 0x00, 0x7f,	// int32	32767
625*57718be8SEnji Cooper 		0xff,
626*57718be8SEnji Cooper 		0x12, 0x80, 0x00, 0x00,	// int32	-2147483648
627*57718be8SEnji Cooper 		0x00,
628*57718be8SEnji Cooper 		0x12, 0x7f, 0xff, 0xff,	// int32	2147483647
629*57718be8SEnji Cooper 		0xff,
630*57718be8SEnji Cooper 	};
631*57718be8SEnji Cooper 
632*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
633*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
634*57718be8SEnji Cooper }
635*57718be8SEnji Cooper 
636*57718be8SEnji Cooper ATF_TC(check_sdp_put_int64);
637*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_int64,tc)638*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_int64, tc)
639*57718be8SEnji Cooper {
640*57718be8SEnji Cooper 
641*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_int64 results");
642*57718be8SEnji Cooper }
643*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_int64,tc)644*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_int64, tc)
645*57718be8SEnji Cooper {
646*57718be8SEnji Cooper 	uint8_t buf[256];
647*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
648*57718be8SEnji Cooper 
649*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)0));
650*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MIN));
651*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MAX));
652*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MIN));
653*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MAX));
654*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MIN));
655*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MAX));
656*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MIN));
657*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MAX));
658*57718be8SEnji Cooper 	test.end = test.next;
659*57718be8SEnji Cooper 	test.next = buf;
660*57718be8SEnji Cooper 
661*57718be8SEnji Cooper 	const uint8_t expect[] = {
662*57718be8SEnji Cooper 		0x13, 0x00, 0x00, 0x00,	// int64	0
663*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x00,
664*57718be8SEnji Cooper 		0x00,
665*57718be8SEnji Cooper 		0x13, 0xff, 0xff, 0xff,	// int64	-128
666*57718be8SEnji Cooper 		0xff, 0xff, 0xff, 0xff,
667*57718be8SEnji Cooper 		0x80,
668*57718be8SEnji Cooper 		0x13, 0x00, 0x00, 0x00,	// int64	127
669*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x00,
670*57718be8SEnji Cooper 		0x7f,
671*57718be8SEnji Cooper 		0x13, 0xff, 0xff, 0xff,	// int64	-32768
672*57718be8SEnji Cooper 		0xff, 0xff, 0xff, 0x80,
673*57718be8SEnji Cooper 		0x00,
674*57718be8SEnji Cooper 		0x13, 0x00, 0x00, 0x00,	// int64	32767
675*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x7f,
676*57718be8SEnji Cooper 		0xff,
677*57718be8SEnji Cooper 		0x13, 0xff, 0xff, 0xff,	// int64	-2147483648
678*57718be8SEnji Cooper 		0xff, 0x80, 0x00, 0x00,
679*57718be8SEnji Cooper 		0x00,
680*57718be8SEnji Cooper 		0x13, 0x00, 0x00, 0x00,	// int64	2147483647
681*57718be8SEnji Cooper 		0x00, 0x7f, 0xff, 0xff,
682*57718be8SEnji Cooper 		0xff,
683*57718be8SEnji Cooper 		0x13, 0x80, 0x00, 0x00,	// int64	-9223372036854775808
684*57718be8SEnji Cooper 		0x00, 0x00, 0x00, 0x00,
685*57718be8SEnji Cooper 		0x00,
686*57718be8SEnji Cooper 		0x13, 0x7f, 0xff, 0xff,	// int64	9223372036854775807
687*57718be8SEnji Cooper 		0xff, 0xff, 0xff, 0xff,
688*57718be8SEnji Cooper 		0xff,
689*57718be8SEnji Cooper 	};
690*57718be8SEnji Cooper 
691*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
692*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
693*57718be8SEnji Cooper }
694*57718be8SEnji Cooper 
695*57718be8SEnji Cooper ATF_TC(check_sdp_put_seq);
696*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_seq,tc)697*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_seq, tc)
698*57718be8SEnji Cooper {
699*57718be8SEnji Cooper 
700*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_seq results");
701*57718be8SEnji Cooper }
702*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_seq,tc)703*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_seq, tc)
704*57718be8SEnji Cooper {
705*57718be8SEnji Cooper 	uint8_t buf[512];
706*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
707*57718be8SEnji Cooper 
708*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)0));
709*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX));
710*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX + 1));
711*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)-1));
712*57718be8SEnji Cooper 	ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)UINT16_MAX), false);	/* no room */
713*57718be8SEnji Cooper 	ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)SSIZE_MAX), false);	/* no room */
714*57718be8SEnji Cooper 	test.end = test.next;
715*57718be8SEnji Cooper 	test.next = buf;
716*57718be8SEnji Cooper 
717*57718be8SEnji Cooper 	/* (not a valid element list) */
718*57718be8SEnji Cooper 	const uint8_t expect[] = {
719*57718be8SEnji Cooper 		0x35, 0x00,		// seq8(0)
720*57718be8SEnji Cooper 		0x35, 0xff,		// seq8(255)
721*57718be8SEnji Cooper 		0x36, 0x01, 0x00,	// seq16(256)
722*57718be8SEnji Cooper 		0x36, 0x01, 0xf6,	// seq16(502)	<- sizeof(buf) - 7 - 3
723*57718be8SEnji Cooper 	};
724*57718be8SEnji Cooper 
725*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
726*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
727*57718be8SEnji Cooper }
728*57718be8SEnji Cooper 
729*57718be8SEnji Cooper ATF_TC(check_sdp_put_alt);
730*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_alt,tc)731*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_alt, tc)
732*57718be8SEnji Cooper {
733*57718be8SEnji Cooper 
734*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_alt results");
735*57718be8SEnji Cooper }
736*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_alt,tc)737*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_alt, tc)
738*57718be8SEnji Cooper {
739*57718be8SEnji Cooper 	uint8_t buf[512];
740*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
741*57718be8SEnji Cooper 
742*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)0));
743*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX));
744*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX + 1));
745*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)-1));
746*57718be8SEnji Cooper 	ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)UINT16_MAX), false);	/* no room */
747*57718be8SEnji Cooper 	ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)SSIZE_MAX), false);	/* no room */
748*57718be8SEnji Cooper 	test.end = test.next;
749*57718be8SEnji Cooper 	test.next = buf;
750*57718be8SEnji Cooper 
751*57718be8SEnji Cooper 	/* (not a valid element list) */
752*57718be8SEnji Cooper 	const uint8_t expect[] = {
753*57718be8SEnji Cooper 		0x3d, 0x00,		// alt8(0)
754*57718be8SEnji Cooper 		0x3d, 0xff,		// alt8(255)
755*57718be8SEnji Cooper 		0x3e, 0x01, 0x00,	// alt16(256)
756*57718be8SEnji Cooper 		0x3e, 0x01, 0xf6,	// alt16(502)	<- sizeof(buf) - 7 - 3
757*57718be8SEnji Cooper 	};
758*57718be8SEnji Cooper 
759*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
760*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
761*57718be8SEnji Cooper }
762*57718be8SEnji Cooper 
763*57718be8SEnji Cooper ATF_TC(check_sdp_put_str);
764*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_str,tc)765*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_str, tc)
766*57718be8SEnji Cooper {
767*57718be8SEnji Cooper 
768*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_str results");
769*57718be8SEnji Cooper }
770*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_str,tc)771*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_str, tc)
772*57718be8SEnji Cooper {
773*57718be8SEnji Cooper 	uint8_t buf[512];
774*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
775*57718be8SEnji Cooper 
776*57718be8SEnji Cooper 	/*
777*57718be8SEnji Cooper 	 * this does not test str16 or str32, but that is
778*57718be8SEnji Cooper 	 * handled by the same code as sdp_put_seq above..
779*57718be8SEnji Cooper 	 */
780*57718be8SEnji Cooper 
781*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_str(&test, "Hello World!", 5));
782*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", 11));
783*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_str(&test, "Hello World!", -1));
784*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", -1));
785*57718be8SEnji Cooper 	test.end = test.next;
786*57718be8SEnji Cooper 	test.next = buf;
787*57718be8SEnji Cooper 
788*57718be8SEnji Cooper 	const uint8_t expect[] = {
789*57718be8SEnji Cooper 		0x25, 0x05, 0x48, 0x65,	// str8		"Hello"
790*57718be8SEnji Cooper 		0x6c, 0x6c, 0x6f,
791*57718be8SEnji Cooper 		0x25, 0x0b, 0x48, 0x65,	// str8		"Hello\0World"
792*57718be8SEnji Cooper 		0x6c, 0x6c, 0x6f, 0x00,
793*57718be8SEnji Cooper 		0x57, 0x6f, 0x72, 0x6c,
794*57718be8SEnji Cooper 		0x64,
795*57718be8SEnji Cooper 		0x25, 0x0c, 0x48, 0x65,	// str8		"Hello World!"
796*57718be8SEnji Cooper 		0x6c, 0x6c, 0x6f, 0x20,
797*57718be8SEnji Cooper 		0x57, 0x6f, 0x72, 0x6c,
798*57718be8SEnji Cooper 		0x64, 0x21,
799*57718be8SEnji Cooper 		0x25, 0x05, 0x48, 0x65,	// str8		"Hello"
800*57718be8SEnji Cooper 		0x6c, 0x6c, 0x6f,
801*57718be8SEnji Cooper 	};
802*57718be8SEnji Cooper 
803*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
804*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
805*57718be8SEnji Cooper }
806*57718be8SEnji Cooper 
807*57718be8SEnji Cooper ATF_TC(check_sdp_put_url);
808*57718be8SEnji Cooper 
ATF_TC_HEAD(check_sdp_put_url,tc)809*57718be8SEnji Cooper ATF_TC_HEAD(check_sdp_put_url, tc)
810*57718be8SEnji Cooper {
811*57718be8SEnji Cooper 
812*57718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test sdp_put_url results");
813*57718be8SEnji Cooper }
814*57718be8SEnji Cooper 
ATF_TC_BODY(check_sdp_put_url,tc)815*57718be8SEnji Cooper ATF_TC_BODY(check_sdp_put_url, tc)
816*57718be8SEnji Cooper {
817*57718be8SEnji Cooper 	uint8_t buf[512];
818*57718be8SEnji Cooper 	sdp_data_t test = { buf, buf + sizeof(buf) };
819*57718be8SEnji Cooper 
820*57718be8SEnji Cooper 	/*
821*57718be8SEnji Cooper 	 * this does not test url16 or url32, but that is
822*57718be8SEnji Cooper 	 * handled by the same code as sdp_put_seq above..
823*57718be8SEnji Cooper 	 */
824*57718be8SEnji Cooper 
825*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", 21));
826*57718be8SEnji Cooper 	ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", -1));
827*57718be8SEnji Cooper 	test.end = test.next;
828*57718be8SEnji Cooper 	test.next = buf;
829*57718be8SEnji Cooper 
830*57718be8SEnji Cooper 	const uint8_t expect[] = {
831*57718be8SEnji Cooper 		0x45, 0x15, 0x68, 0x74,	// url8	"http://www.netbsd.org"
832*57718be8SEnji Cooper 		0x74, 0x70, 0x3a, 0x2f,
833*57718be8SEnji Cooper 		0x2f, 0x77, 0x77, 0x77,
834*57718be8SEnji Cooper 		0x2e, 0x6e, 0x65, 0x74,
835*57718be8SEnji Cooper 		0x62, 0x73, 0x64, 0x2e,
836*57718be8SEnji Cooper 		0x6f, 0x72, 0x67,
837*57718be8SEnji Cooper 		0x45, 0x16, 0x68, 0x74,	// url8	"http://www.netbsd.org/"
838*57718be8SEnji Cooper 		0x74, 0x70, 0x3a, 0x2f,
839*57718be8SEnji Cooper 		0x2f, 0x77, 0x77, 0x77,
840*57718be8SEnji Cooper 		0x2e, 0x6e, 0x65, 0x74,
841*57718be8SEnji Cooper 		0x62, 0x73, 0x64, 0x2e,
842*57718be8SEnji Cooper 		0x6f, 0x72, 0x67, 0x2f,
843*57718be8SEnji Cooper 	};
844*57718be8SEnji Cooper 
845*57718be8SEnji Cooper 	ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
846*57718be8SEnji Cooper 	ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
847*57718be8SEnji Cooper }
848*57718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)849*57718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
850*57718be8SEnji Cooper {
851*57718be8SEnji Cooper 
852*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_data);
853*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_attr);
854*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uuid);
855*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uuid16);
856*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uuid32);
857*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uuid128);
858*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_bool);
859*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uint);
860*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uint8);
861*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uint16);
862*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uint32);
863*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_uint64);
864*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_int);
865*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_int8);
866*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_int16);
867*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_int32);
868*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_int64);
869*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_seq);
870*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_alt);
871*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_str);
872*57718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, check_sdp_put_url);
873*57718be8SEnji Cooper 
874*57718be8SEnji Cooper 	return atf_no_error();
875*57718be8SEnji Cooper }
876