1 /* $NetBSD: t_sdp_set.c,v 1.2 2011/04/07 08:29:50 plunky Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
38 ATF_TC(check_sdp_set_bool
);
40 ATF_TC_HEAD(check_sdp_set_bool
, tc
)
43 atf_tc_set_md_var(tc
, "descr", "Test sdp_set_bool results");
46 ATF_TC_BODY(check_sdp_set_bool
, tc
)
49 0x28, 0x00, // bool false
51 0x28, // bool <invalid>
53 sdp_data_t test
= { data
, data
+ sizeof(data
) };
56 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_BOOL
);
57 ATF_REQUIRE(sdp_set_bool(&test
, true));
58 ATF_CHECK_EQ(test
.next
[1], 0x01);
59 ATF_REQUIRE(sdp_set_bool(&test
, false));
60 ATF_CHECK_EQ(test
.next
[1], 0x00);
61 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
63 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_NIL
);
64 ATF_CHECK_EQ(sdp_set_bool(&test
, true), false); /* not bool */
65 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
67 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_BOOL
);
68 ATF_CHECK_EQ(sdp_set_bool(&test
, true), false); /* no value */
71 ATF_TC(check_sdp_set_uint
);
73 ATF_TC_HEAD(check_sdp_set_uint
, tc
)
76 atf_tc_set_md_var(tc
, "descr", "Test sdp_set_uint results");
79 ATF_TC_BODY(check_sdp_set_uint
, tc
)
82 0x08, 0x00, // uint8 0x00
84 0x09, 0x00, 0x00, // uint16 0x0000
85 0x0a, 0x00, 0x00, 0x00, // uint32 0x00000000
87 0x0b, 0x00, 0x00, 0x00, // uint64 0x0000000000000000
88 0x00, 0x00, 0x00, 0x00,
90 0x0c, 0x00, 0x44, 0x00, // uint128 0x00440044004400440044004400440044
91 0x44, 0x00, 0x44, 0x00,
92 0x44, 0x00, 0x44, 0x00,
93 0x44, 0x00, 0x44, 0x00,
95 0x09, 0x00, // uint16 <invalid>
97 sdp_data_t test
= { data
, data
+ sizeof(data
) };
100 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_UINT8
);
101 ATF_REQUIRE(sdp_set_uint(&test
, 0x44));
102 ATF_CHECK_EQ(sdp_set_uint(&test
, UINT8_MAX
+ 1), false); /* too big */
103 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
105 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_NIL
);
106 ATF_CHECK_EQ(sdp_set_uint(&test
, 0x00), false); /* not uint */
107 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
109 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_UINT16
);
110 ATF_REQUIRE(sdp_set_uint(&test
, 0xabcd));
111 ATF_CHECK_EQ(sdp_set_uint(&test
, UINT16_MAX
+ 1), false); /* too big */
112 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
114 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_UINT32
);
115 ATF_REQUIRE(sdp_set_uint(&test
, 0xdeadbeef));
116 ATF_CHECK_EQ(sdp_set_uint(&test
, (uintmax_t)UINT32_MAX
+ 1), false); /* too big */
117 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
119 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_UINT64
);
120 ATF_REQUIRE(sdp_set_uint(&test
, 0xc0ffeecafec0ffee));
121 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
123 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_UINT128
);
124 ATF_REQUIRE(sdp_set_uint(&test
, 0xabcdef0123456789));
125 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
127 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_UINT16
);
128 ATF_CHECK_EQ(sdp_set_uint(&test
, 0x3344), false); /* no value */
130 const uint8_t expect
[] = {
131 0x08, 0x44, // uint8 0x44
133 0x09, 0xab, 0xcd, // uint16 0xabcd
134 0x0a, 0xde, 0xad, 0xbe, // uint32 0xdeadbeef
136 0x0b, 0xc0, 0xff, 0xee, // uint64 0xc0ffeecafec0ffee
137 0xca, 0xfe, 0xc0, 0xff,
139 0x0c, 0x00, 0x00, 0x00, // uint128 0x0000000000000000abcdef0123456789
140 0x00, 0x00, 0x00, 0x00,
141 0x00, 0xab, 0xcd, 0xef,
142 0x01, 0x23, 0x45, 0x67,
144 0x09, 0x00, // uint16 <invalid>
147 ATF_REQUIRE_EQ(sizeof(data
), sizeof(expect
));
148 ATF_CHECK(memcmp(expect
, data
, sizeof(expect
)) == 0);
151 ATF_TC(check_sdp_set_int
);
153 ATF_TC_HEAD(check_sdp_set_int
, tc
)
156 atf_tc_set_md_var(tc
, "descr", "Test sdp_set_int results");
159 ATF_TC_BODY(check_sdp_set_int
, tc
)
162 0x10, 0x00, // int8 0
164 0x11, 0x00, 0x00, // int16 0
165 0x12, 0x00, 0x00, 0x00, // int32 0
167 0x13, 0x00, 0x00, 0x00, // int64 0
168 0x00, 0x00, 0x00, 0x00,
170 0x14, 0x00, 0x44, 0x00, // int128 0x00440044004400440044004400440044
171 0x44, 0x00, 0x44, 0x00,
172 0x44, 0x00, 0x44, 0x00,
173 0x44, 0x00, 0x44, 0x00,
175 0x11, 0x00, // int16 <invalid>
177 sdp_data_t test
= { data
, data
+ sizeof(data
) };
180 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT8
);
181 ATF_REQUIRE(sdp_set_int(&test
, -1));
182 ATF_CHECK_EQ(sdp_set_int(&test
, INT8_MAX
+ 1), false); /* too big */
183 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
185 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_NIL
);
186 ATF_CHECK_EQ(sdp_set_int(&test
, 33), false); /* not int */
187 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
189 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT16
);
190 ATF_REQUIRE(sdp_set_int(&test
, 789));
191 ATF_CHECK_EQ(sdp_set_int(&test
, INT16_MIN
- 1), false); /* too big */
192 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
194 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT32
);
195 ATF_REQUIRE(sdp_set_int(&test
, -4567));
196 ATF_CHECK_EQ(sdp_set_int(&test
, (intmax_t)INT32_MAX
+ 1), false); /* too big */
197 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
199 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT64
);
200 ATF_REQUIRE(sdp_set_int(&test
, -3483738234));
201 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
203 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT128
);
204 ATF_REQUIRE(sdp_set_int(&test
, 3423489463464));
205 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
207 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT16
);
208 ATF_CHECK_EQ(sdp_set_int(&test
, 1234), false); /* no value */
210 const uint8_t expect
[] = {
211 0x10, 0xff, // int8 -1
213 0x11, 0x03, 0x15, // int16 789
214 0x12, 0xff, 0xff, 0xee, // int32 -4567
216 0x13, 0xff, 0xff, 0xff, // int64 -3483738234
217 0xff, 0x30, 0x5a, 0x5f,
219 0x14, 0x00, 0x00, 0x00, // int128 3423489463464
220 0x00, 0x00, 0x00, 0x00,
221 0x00, 0x00, 0x00, 0x03,
222 0x1d, 0x17, 0xdf, 0x94,
224 0x11, 0x00, // int16 <invalid>
227 ATF_REQUIRE_EQ(sizeof(data
), sizeof(expect
));
228 ATF_CHECK(memcmp(expect
, data
, sizeof(expect
)) == 0);
231 ATF_TC(check_sdp_set_seq
);
233 ATF_TC_HEAD(check_sdp_set_seq
, tc
)
236 atf_tc_set_md_var(tc
, "descr", "Test sdp_set_seq results");
239 ATF_TC_BODY(check_sdp_set_seq
, tc
)
242 0x35, 0x03, // seq8(3)
243 0x11, 0xff, 0xff, // int16 -1
244 0x36, 0x01, 0x00, // seq16(256)
245 0x09, 0xff, 0xff, // uint16 0xffff
246 0x37, 0x01, 0x02, 0x03, // seq32(16909060)
248 0x36, 0x00, // seq16(<invalid>)
250 sdp_data_t test
= { data
, data
+ sizeof(data
) };
253 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_SEQ8
);
254 ATF_REQUIRE(sdp_set_seq(&test
, 0));
255 ATF_CHECK_EQ(sdp_set_seq(&test
, UINT8_MAX
), false); /* data too big */
256 ATF_CHECK_EQ(sdp_set_seq(&test
, UINT16_MAX
), false); /* size too big */
257 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
259 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT16
);
260 ATF_CHECK_EQ(sdp_set_seq(&test
, 33), false); /* not seq */
261 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
263 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_SEQ16
);
264 ATF_REQUIRE(sdp_set_seq(&test
, 3));
265 ATF_CHECK_EQ(sdp_set_seq(&test
, SSIZE_MAX
), false); /* size too big */
266 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
268 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_SEQ32
);
269 ATF_REQUIRE(sdp_set_seq(&test
, 0));
270 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
272 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_SEQ16
);
273 ATF_CHECK_EQ(sdp_set_seq(&test
, 22), false); /* no size */
275 const uint8_t expect
[] = {
276 0x35, 0x00, // seq8(0)
277 0x11, 0xff, 0xff, // int16 -1
278 0x36, 0x00, 0x03, // seq16(3)
279 0x09, 0xff, 0xff, // uint16 0xffff
280 0x37, 0x00, 0x00, 0x00, // seq32(0)
282 0x36, 0x00, // seq16(<invalid>)
285 ATF_REQUIRE_EQ(sizeof(data
), sizeof(expect
));
286 ATF_CHECK(memcmp(expect
, data
, sizeof(expect
)) == 0);
289 ATF_TC(check_sdp_set_alt
);
291 ATF_TC_HEAD(check_sdp_set_alt
, tc
)
294 atf_tc_set_md_var(tc
, "descr", "Test sdp_set_alt results");
297 ATF_TC_BODY(check_sdp_set_alt
, tc
)
300 0x3d, 0x06, // alt8(6)
301 0x11, 0xff, 0xff, // int16 -1
302 0x3e, 0xff, 0xff, // alt16(65535)
303 0x3f, 0x01, 0x02, 0x03, // alt32(16909060)
305 0x0a, 0x00, 0x00, 0x00, // uint32 0x00000003
307 0x3e, 0x00, // alt16(<invalid>)
309 sdp_data_t test
= { data
, data
+ sizeof(data
) };
312 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_ALT8
);
313 ATF_REQUIRE(sdp_set_alt(&test
, 0));
314 ATF_CHECK_EQ(sdp_set_alt(&test
, UINT8_MAX
), false); /* data too big */
315 ATF_CHECK_EQ(sdp_set_alt(&test
, UINT16_MAX
), false); /* size too big */
316 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
318 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_INT16
);
319 ATF_CHECK_EQ(sdp_set_alt(&test
, 27), false); /* not alt */
320 ATF_REQUIRE(sdp_get_data(&test
, &discard
));
322 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_ALT16
);
323 ATF_REQUIRE(sdp_set_alt(&test
, 10));
324 ATF_CHECK_EQ(sdp_set_alt(&test
, SSIZE_MAX
), false); /* size too big */
325 ATF_REQUIRE(sdp_get_alt(&test
, &discard
));
326 ATF_CHECK_EQ(sdp_data_type(&discard
), SDP_DATA_ALT32
);
327 ATF_CHECK(sdp_set_alt(&discard
, -1)); /* end of alt16 */
328 ATF_CHECK_EQ(sdp_set_alt(&discard
, 6), false); /* data too big */
330 ATF_CHECK_EQ(sdp_data_type(&test
), SDP_DATA_ALT16
);
331 ATF_CHECK_EQ(sdp_set_alt(&test
, 22), false); /* no size */
333 const uint8_t expect
[] = {
334 0x3d, 0x00, // alt8(0)
335 0x11, 0xff, 0xff, // int16 -1
336 0x3e, 0x00, 0x0a, // alt16(10)
337 0x3f, 0x00, 0x00, 0x00, // alt32(5)
339 0x0a, 0x00, 0x00, 0x00, // uint32 0x00000003
341 0x3e, 0x00, // alt16(<invalid>)
344 ATF_REQUIRE_EQ(sizeof(data
), sizeof(expect
));
345 ATF_CHECK(memcmp(expect
, data
, sizeof(expect
)) == 0);
352 ATF_TP_ADD_TC(tp
, check_sdp_set_bool
);
353 ATF_TP_ADD_TC(tp
, check_sdp_set_uint
);
354 ATF_TP_ADD_TC(tp
, check_sdp_set_int
);
355 ATF_TP_ADD_TC(tp
, check_sdp_set_seq
);
356 ATF_TP_ADD_TC(tp
, check_sdp_set_alt
);
358 return atf_no_error();