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