1 /* $NetBSD: t_sdp_put.c,v 1.3 2011/04/16 07:32:27 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_put_data
);
40 ATF_TC_HEAD(check_sdp_put_data
, tc
)
43 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_data results");
46 ATF_TC_BODY(check_sdp_put_data
, tc
)
49 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
51 0x35, 0x05, // seq8(5)
52 0x08, 0x00, // uint8 0x00
53 0x09, 0x12, 0x34, // uint16 0x1234
55 sdp_data_t value
= { data
, data
+ sizeof(data
) };
57 ATF_REQUIRE(sdp_put_data(&test
, &value
));
61 const uint8_t expect
[] = {
62 0x35, 0x05, // seq8(5)
63 0x08, 0x00, // uint8 0x00
64 0x09, 0x12, 0x34, // uint16 0x1234
67 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
68 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
71 ATF_TC(check_sdp_put_attr
);
73 ATF_TC_HEAD(check_sdp_put_attr
, tc
)
76 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_attr results");
79 ATF_TC_BODY(check_sdp_put_attr
, tc
)
82 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
85 0x19, 0x33, 0x44, // uuid16 0x3344
87 sdp_data_t value
= { data
, data
+ sizeof(data
) };
89 ATF_REQUIRE_EQ(sdp_put_attr(&test
, 0xabcd, &value
), false);
90 value
.next
+= 1; // skip "nil"
91 ATF_REQUIRE(sdp_put_attr(&test
, 0x1337, &value
));
95 const uint8_t expect
[] = {
96 0x09, 0x13, 0x37, // uint16 0x1337
97 0x19, 0x33, 0x44, // uuid16 0x3344
100 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
101 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
104 ATF_TC(check_sdp_put_uuid
);
106 ATF_TC_HEAD(check_sdp_put_uuid
, tc
)
109 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uuid results");
112 ATF_TC_BODY(check_sdp_put_uuid
, tc
)
115 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
122 { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
130 { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
132 const uuid_t u128
= {
138 { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }
141 ATF_REQUIRE(sdp_put_uuid(&test
, &u16
));
142 ATF_REQUIRE(sdp_put_uuid(&test
, &u32
));
143 ATF_REQUIRE(sdp_put_uuid(&test
, &u128
));
144 test
.end
= test
.next
;
147 const uint8_t expect
[] = {
148 0x19, 0x12, 0x34, // uuid16 0x1234
149 0x1a, 0x12, 0x34, 0x56, // uuid32 0x12345678
151 0x1c, 0x00, 0x11, 0x22, // uuid128 00112233-4444-5555-6677-8899aabbccdd
152 0x33, 0x44, 0x44, 0x55,
153 0x55, 0x66, 0x77, 0x88,
154 0x99, 0xaa, 0xbb, 0xcc,
158 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
159 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
162 ATF_TC(check_sdp_put_uuid16
);
164 ATF_TC_HEAD(check_sdp_put_uuid16
, tc
)
167 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uuid16 results");
170 ATF_TC_BODY(check_sdp_put_uuid16
, tc
)
173 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
175 ATF_REQUIRE(sdp_put_uuid16(&test
, 0x4567));
176 test
.end
= test
.next
;
179 const uint8_t expect
[] = {
180 0x19, 0x45, 0x67, // uuid16 0x4567
183 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
184 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
187 ATF_TC(check_sdp_put_uuid32
);
189 ATF_TC_HEAD(check_sdp_put_uuid32
, tc
)
192 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uuid32 results");
195 ATF_TC_BODY(check_sdp_put_uuid32
, tc
)
198 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
200 ATF_REQUIRE(sdp_put_uuid32(&test
, 0xabcdef00));
201 test
.end
= test
.next
;
204 const uint8_t expect
[] = {
205 0x1a, 0xab, 0xcd, 0xef, // uuid32 0xabcdef00
209 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
210 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
213 ATF_TC(check_sdp_put_uuid128
);
215 ATF_TC_HEAD(check_sdp_put_uuid128
, tc
)
218 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uuid128 results");
221 ATF_TC_BODY(check_sdp_put_uuid128
, tc
)
224 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
231 { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
234 ATF_REQUIRE(sdp_put_uuid128(&test
, &value
));
235 test
.end
= test
.next
;
238 const uint8_t expect
[] = {
239 0x1c, 0x00, 0x00, 0x01, // uuid128 0000100-0000-1000-8000-00805f9b34fb
240 0x00, 0x00, 0x00, 0x10, // (L2CAP protocol)
241 0x00, 0x80, 0x00, 0x00,
242 0x80, 0x5f, 0x9b, 0x34,
246 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
247 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
250 ATF_TC(check_sdp_put_bool
);
252 ATF_TC_HEAD(check_sdp_put_bool
, tc
)
255 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_bool results");
258 ATF_TC_BODY(check_sdp_put_bool
, tc
)
261 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
263 ATF_REQUIRE(sdp_put_bool(&test
, true));
264 ATF_REQUIRE(sdp_put_bool(&test
, false));
265 test
.end
= test
.next
;
268 const uint8_t expect
[] = {
269 0x28, 0x01, // bool true
270 0x28, 0x00, // bool false
273 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
274 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
277 ATF_TC(check_sdp_put_uint
);
279 ATF_TC_HEAD(check_sdp_put_uint
, tc
)
282 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uint results");
285 ATF_TC_BODY(check_sdp_put_uint
, tc
)
288 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
290 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)0));
291 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)UINT8_MAX
));
292 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)UINT8_MAX
+ 1));
293 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)UINT16_MAX
));
294 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)UINT16_MAX
+ 1));
295 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)UINT32_MAX
));
296 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)UINT32_MAX
+ 1));
297 ATF_REQUIRE(sdp_put_uint(&test
, (uintmax_t)UINT64_MAX
));
298 test
.end
= test
.next
;
301 const uint8_t expect
[] = {
302 0x08, 0x00, // uint8 0x00
303 0x08, 0xff, // uint8 0xff
304 0x09, 0x01, 0x00, // uint16 0x0100
305 0x09, 0xff, 0xff, // uint16 0xffff
306 0x0a, 0x00, 0x01, 0x00, // uint32 0x00010000
308 0x0a, 0xff, 0xff, 0xff, // uint32 0xffffffff
310 0x0b, 0x00, 0x00, 0x00, // uint64 0x0000000100000000
311 0x01, 0x00, 0x00, 0x00,
313 0x0b, 0xff, 0xff, 0xff, // uint64 0xffffffffffffffff
314 0xff, 0xff, 0xff, 0xff,
318 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
319 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
322 ATF_TC(check_sdp_put_uint8
);
324 ATF_TC_HEAD(check_sdp_put_uint8
, tc
)
327 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uint8 results");
330 ATF_TC_BODY(check_sdp_put_uint8
, tc
)
333 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
335 ATF_REQUIRE(sdp_put_uint8(&test
, (uint8_t)0));
336 ATF_REQUIRE(sdp_put_uint8(&test
, (uint8_t)UINT8_MAX
));
337 test
.end
= test
.next
;
340 const uint8_t expect
[] = {
341 0x08, 0x00, // uint8 0x00
342 0x08, 0xff, // uint8 0xff
345 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
346 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
349 ATF_TC(check_sdp_put_uint16
);
351 ATF_TC_HEAD(check_sdp_put_uint16
, tc
)
354 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uint16 results");
357 ATF_TC_BODY(check_sdp_put_uint16
, tc
)
360 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
362 ATF_REQUIRE(sdp_put_uint16(&test
, (uint16_t)0));
363 ATF_REQUIRE(sdp_put_uint16(&test
, (uint16_t)UINT8_MAX
));
364 ATF_REQUIRE(sdp_put_uint16(&test
, (uint16_t)UINT16_MAX
));
365 ATF_REQUIRE(sdp_put_uint16(&test
, (uint16_t)0xabcd));
366 test
.end
= test
.next
;
369 const uint8_t expect
[] = {
370 0x09, 0x00, 0x00, // uint16 0x0000
371 0x09, 0x00, 0xff, // uint16 0x00ff
372 0x09, 0xff, 0xff, // uint16 0xffff
373 0x09, 0xab, 0xcd, // uint16 0xabcd
376 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
377 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
380 ATF_TC(check_sdp_put_uint32
);
382 ATF_TC_HEAD(check_sdp_put_uint32
, tc
)
385 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uint32 results");
388 ATF_TC_BODY(check_sdp_put_uint32
, tc
)
391 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
393 ATF_REQUIRE(sdp_put_uint32(&test
, (uint32_t)0));
394 ATF_REQUIRE(sdp_put_uint32(&test
, (uint32_t)UINT8_MAX
));
395 ATF_REQUIRE(sdp_put_uint32(&test
, (uint32_t)UINT16_MAX
));
396 ATF_REQUIRE(sdp_put_uint32(&test
, (uint32_t)UINT32_MAX
));
397 ATF_REQUIRE(sdp_put_uint32(&test
, (uint32_t)0xdeadbeef));
398 test
.end
= test
.next
;
401 const uint8_t expect
[] = {
402 0x0a, 0x00, 0x00, 0x00, // uint32 0x00000000
404 0x0a, 0x00, 0x00, 0x00, // uint32 0x000000ff
406 0x0a, 0x00, 0x00, 0xff, // uint32 0x0000ffff
408 0x0a, 0xff, 0xff, 0xff, // uint32 0xffffffff
410 0x0a, 0xde, 0xad, 0xbe, // uint32 0xdeadbeef
414 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
415 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
418 ATF_TC(check_sdp_put_uint64
);
420 ATF_TC_HEAD(check_sdp_put_uint64
, tc
)
423 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_uint64 results");
426 ATF_TC_BODY(check_sdp_put_uint64
, tc
)
429 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
431 ATF_REQUIRE(sdp_put_uint64(&test
, (uint64_t)0));
432 ATF_REQUIRE(sdp_put_uint64(&test
, (uint64_t)UINT8_MAX
));
433 ATF_REQUIRE(sdp_put_uint64(&test
, (uint64_t)UINT16_MAX
));
434 ATF_REQUIRE(sdp_put_uint64(&test
, (uint64_t)UINT32_MAX
));
435 ATF_REQUIRE(sdp_put_uint64(&test
, (uint64_t)UINT64_MAX
));
436 ATF_REQUIRE(sdp_put_uint64(&test
, (uint64_t)0xc0ffeecafec0ffee));
437 test
.end
= test
.next
;
440 const uint8_t expect
[] = {
441 0x0b, 0x00, 0x00, 0x00, // uint64 0x0000000000000000
442 0x00, 0x00, 0x00, 0x00,
444 0x0b, 0x00, 0x00, 0x00, // uint64 0x00000000000000ff
445 0x00, 0x00, 0x00, 0x00,
447 0x0b, 0x00, 0x00, 0x00, // uint64 0x000000000000ffff
448 0x00, 0x00, 0x00, 0xff,
450 0x0b, 0x00, 0x00, 0x00, // uint64 0x00000000ffffffff
451 0x00, 0xff, 0xff, 0xff,
453 0x0b, 0xff, 0xff, 0xff, // uint64 0xffffffffffffffff
454 0xff, 0xff, 0xff, 0xff,
456 0x0b, 0xc0, 0xff, 0xee, // uint64 0xc0ffeecafec0ffee
457 0xca, 0xfe, 0xc0, 0xff,
461 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
462 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
465 ATF_TC(check_sdp_put_int
);
467 ATF_TC_HEAD(check_sdp_put_int
, tc
)
470 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_int results");
473 ATF_TC_BODY(check_sdp_put_int
, tc
)
476 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
478 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)0));
479 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT8_MIN
));
480 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT8_MAX
));
481 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT8_MIN
- 1));
482 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT8_MAX
+ 1));
483 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT16_MIN
));
484 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT16_MAX
));
485 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT16_MIN
- 1));
486 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT16_MAX
+ 1));
487 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT32_MIN
));
488 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT32_MAX
));
489 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT32_MIN
- 1));
490 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT32_MAX
+ 1));
491 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT64_MIN
));
492 ATF_REQUIRE(sdp_put_int(&test
, (intmax_t)INT64_MAX
));
493 test
.end
= test
.next
;
496 const uint8_t expect
[] = {
497 0x10, 0x00, // int8 0
498 0x10, 0x80, // int8 -128
499 0x10, 0x7f, // int8 127
500 0x11, 0xff, 0x7f, // int16 -129
501 0x11, 0x00, 0x80, // int16 128
502 0x11, 0x80, 0x00, // int16 -32768
503 0x11, 0x7f, 0xff, // int16 32767
504 0x12, 0xff, 0xff, 0x7f, // int32 -32769
506 0x12, 0x00, 0x00, 0x80, // int32 32768
508 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
510 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
512 0x13, 0xff, 0xff, 0xff, // int64 -2147483649
513 0xff, 0x7f, 0xff, 0xff,
515 0x13, 0x00, 0x00, 0x00, // int64 2147483648
516 0x00, 0x80, 0x00, 0x00,
518 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
519 0x00, 0x00, 0x00, 0x00,
521 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
522 0xff, 0xff, 0xff, 0xff,
526 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
527 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
530 ATF_TC(check_sdp_put_int8
);
532 ATF_TC_HEAD(check_sdp_put_int8
, tc
)
535 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_int8 results");
538 ATF_TC_BODY(check_sdp_put_int8
, tc
)
541 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
543 ATF_REQUIRE(sdp_put_int8(&test
, (int8_t)0));
544 ATF_REQUIRE(sdp_put_int8(&test
, (int8_t)INT8_MIN
));
545 ATF_REQUIRE(sdp_put_int8(&test
, (int8_t)INT8_MAX
));
546 test
.end
= test
.next
;
549 const uint8_t expect
[] = {
550 0x10, 0x00, // int8 0
551 0x10, 0x80, // int8 -128
552 0x10, 0x7f, // int8 127
555 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
556 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
559 ATF_TC(check_sdp_put_int16
);
561 ATF_TC_HEAD(check_sdp_put_int16
, tc
)
564 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_int16 results");
567 ATF_TC_BODY(check_sdp_put_int16
, tc
)
570 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
572 ATF_REQUIRE(sdp_put_int16(&test
, (int16_t)0));
573 ATF_REQUIRE(sdp_put_int16(&test
, (int16_t)INT8_MIN
));
574 ATF_REQUIRE(sdp_put_int16(&test
, (int16_t)INT8_MAX
));
575 ATF_REQUIRE(sdp_put_int16(&test
, (int16_t)INT16_MIN
));
576 ATF_REQUIRE(sdp_put_int16(&test
, (int16_t)INT16_MAX
));
577 test
.end
= test
.next
;
580 const uint8_t expect
[] = {
581 0x11, 0x00, 0x00, // int16 0
582 0x11, 0xff, 0x80, // int16 -128
583 0x11, 0x00, 0x7f, // int16 127
584 0x11, 0x80, 0x00, // int16 -32768
585 0x11, 0x7f, 0xff, // int16 32767
588 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
589 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
592 ATF_TC(check_sdp_put_int32
);
594 ATF_TC_HEAD(check_sdp_put_int32
, tc
)
597 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_int32 results");
600 ATF_TC_BODY(check_sdp_put_int32
, tc
)
603 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
605 ATF_REQUIRE(sdp_put_int32(&test
, (int32_t)0));
606 ATF_REQUIRE(sdp_put_int32(&test
, (int32_t)INT8_MIN
));
607 ATF_REQUIRE(sdp_put_int32(&test
, (int32_t)INT8_MAX
));
608 ATF_REQUIRE(sdp_put_int32(&test
, (int32_t)INT16_MIN
));
609 ATF_REQUIRE(sdp_put_int32(&test
, (int32_t)INT16_MAX
));
610 ATF_REQUIRE(sdp_put_int32(&test
, (int32_t)INT32_MIN
));
611 ATF_REQUIRE(sdp_put_int32(&test
, (int32_t)INT32_MAX
));
612 test
.end
= test
.next
;
615 const uint8_t expect
[] = {
616 0x12, 0x00, 0x00, 0x00, // int32 0
618 0x12, 0xff, 0xff, 0xff, // int32 -128
620 0x12, 0x00, 0x00, 0x00, // int32 127
622 0x12, 0xff, 0xff, 0x80, // int32 -32768
624 0x12, 0x00, 0x00, 0x7f, // int32 32767
626 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
628 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
632 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
633 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
636 ATF_TC(check_sdp_put_int64
);
638 ATF_TC_HEAD(check_sdp_put_int64
, tc
)
641 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_int64 results");
644 ATF_TC_BODY(check_sdp_put_int64
, tc
)
647 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
649 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)0));
650 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT8_MIN
));
651 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT8_MAX
));
652 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT16_MIN
));
653 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT16_MAX
));
654 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT32_MIN
));
655 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT32_MAX
));
656 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT64_MIN
));
657 ATF_REQUIRE(sdp_put_int64(&test
, (int64_t)INT64_MAX
));
658 test
.end
= test
.next
;
661 const uint8_t expect
[] = {
662 0x13, 0x00, 0x00, 0x00, // int64 0
663 0x00, 0x00, 0x00, 0x00,
665 0x13, 0xff, 0xff, 0xff, // int64 -128
666 0xff, 0xff, 0xff, 0xff,
668 0x13, 0x00, 0x00, 0x00, // int64 127
669 0x00, 0x00, 0x00, 0x00,
671 0x13, 0xff, 0xff, 0xff, // int64 -32768
672 0xff, 0xff, 0xff, 0x80,
674 0x13, 0x00, 0x00, 0x00, // int64 32767
675 0x00, 0x00, 0x00, 0x7f,
677 0x13, 0xff, 0xff, 0xff, // int64 -2147483648
678 0xff, 0x80, 0x00, 0x00,
680 0x13, 0x00, 0x00, 0x00, // int64 2147483647
681 0x00, 0x7f, 0xff, 0xff,
683 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
684 0x00, 0x00, 0x00, 0x00,
686 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
687 0xff, 0xff, 0xff, 0xff,
691 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
692 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
695 ATF_TC(check_sdp_put_seq
);
697 ATF_TC_HEAD(check_sdp_put_seq
, tc
)
700 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_seq results");
703 ATF_TC_BODY(check_sdp_put_seq
, tc
)
706 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
708 ATF_REQUIRE(sdp_put_seq(&test
, (ssize_t
)0));
709 ATF_REQUIRE(sdp_put_seq(&test
, (ssize_t
)UINT8_MAX
));
710 ATF_REQUIRE(sdp_put_seq(&test
, (ssize_t
)UINT8_MAX
+ 1));
711 ATF_REQUIRE(sdp_put_seq(&test
, (ssize_t
)-1));
712 ATF_CHECK_EQ(sdp_put_seq(&test
, (ssize_t
)UINT16_MAX
), false); /* no room */
713 ATF_CHECK_EQ(sdp_put_seq(&test
, (ssize_t
)SSIZE_MAX
), false); /* no room */
714 test
.end
= test
.next
;
717 /* (not a valid element list) */
718 const uint8_t expect
[] = {
719 0x35, 0x00, // seq8(0)
720 0x35, 0xff, // seq8(255)
721 0x36, 0x01, 0x00, // seq16(256)
722 0x36, 0x01, 0xf6, // seq16(502) <- sizeof(buf) - 7 - 3
725 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
726 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
729 ATF_TC(check_sdp_put_alt
);
731 ATF_TC_HEAD(check_sdp_put_alt
, tc
)
734 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_alt results");
737 ATF_TC_BODY(check_sdp_put_alt
, tc
)
740 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
742 ATF_REQUIRE(sdp_put_alt(&test
, (ssize_t
)0));
743 ATF_REQUIRE(sdp_put_alt(&test
, (ssize_t
)UINT8_MAX
));
744 ATF_REQUIRE(sdp_put_alt(&test
, (ssize_t
)UINT8_MAX
+ 1));
745 ATF_REQUIRE(sdp_put_alt(&test
, (ssize_t
)-1));
746 ATF_CHECK_EQ(sdp_put_alt(&test
, (ssize_t
)UINT16_MAX
), false); /* no room */
747 ATF_CHECK_EQ(sdp_put_alt(&test
, (ssize_t
)SSIZE_MAX
), false); /* no room */
748 test
.end
= test
.next
;
751 /* (not a valid element list) */
752 const uint8_t expect
[] = {
753 0x3d, 0x00, // alt8(0)
754 0x3d, 0xff, // alt8(255)
755 0x3e, 0x01, 0x00, // alt16(256)
756 0x3e, 0x01, 0xf6, // alt16(502) <- sizeof(buf) - 7 - 3
759 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
760 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
763 ATF_TC(check_sdp_put_str
);
765 ATF_TC_HEAD(check_sdp_put_str
, tc
)
768 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_str results");
771 ATF_TC_BODY(check_sdp_put_str
, tc
)
774 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
777 * this does not test str16 or str32, but that is
778 * handled by the same code as sdp_put_seq above..
781 ATF_REQUIRE(sdp_put_str(&test
, "Hello World!", 5));
782 ATF_REQUIRE(sdp_put_str(&test
, "Hello\0World", 11));
783 ATF_REQUIRE(sdp_put_str(&test
, "Hello World!", -1));
784 ATF_REQUIRE(sdp_put_str(&test
, "Hello\0World", -1));
785 test
.end
= test
.next
;
788 const uint8_t expect
[] = {
789 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
791 0x25, 0x0b, 0x48, 0x65, // str8 "Hello\0World"
792 0x6c, 0x6c, 0x6f, 0x00,
793 0x57, 0x6f, 0x72, 0x6c,
795 0x25, 0x0c, 0x48, 0x65, // str8 "Hello World!"
796 0x6c, 0x6c, 0x6f, 0x20,
797 0x57, 0x6f, 0x72, 0x6c,
799 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
803 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
804 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
807 ATF_TC(check_sdp_put_url
);
809 ATF_TC_HEAD(check_sdp_put_url
, tc
)
812 atf_tc_set_md_var(tc
, "descr", "Test sdp_put_url results");
815 ATF_TC_BODY(check_sdp_put_url
, tc
)
818 sdp_data_t test
= { buf
, buf
+ sizeof(buf
) };
821 * this does not test url16 or url32, but that is
822 * handled by the same code as sdp_put_seq above..
825 ATF_REQUIRE(sdp_put_url(&test
, "http://www.netbsd.org/", 21));
826 ATF_REQUIRE(sdp_put_url(&test
, "http://www.netbsd.org/", -1));
827 test
.end
= test
.next
;
830 const uint8_t expect
[] = {
831 0x45, 0x15, 0x68, 0x74, // url8 "http://www.netbsd.org"
832 0x74, 0x70, 0x3a, 0x2f,
833 0x2f, 0x77, 0x77, 0x77,
834 0x2e, 0x6e, 0x65, 0x74,
835 0x62, 0x73, 0x64, 0x2e,
837 0x45, 0x16, 0x68, 0x74, // url8 "http://www.netbsd.org/"
838 0x74, 0x70, 0x3a, 0x2f,
839 0x2f, 0x77, 0x77, 0x77,
840 0x2e, 0x6e, 0x65, 0x74,
841 0x62, 0x73, 0x64, 0x2e,
842 0x6f, 0x72, 0x67, 0x2f,
845 ATF_REQUIRE_EQ(test
.end
- test
.next
, sizeof(expect
));
846 ATF_CHECK(memcmp(expect
, test
.next
, sizeof(expect
)) == 0);
852 ATF_TP_ADD_TC(tp
, check_sdp_put_data
);
853 ATF_TP_ADD_TC(tp
, check_sdp_put_attr
);
854 ATF_TP_ADD_TC(tp
, check_sdp_put_uuid
);
855 ATF_TP_ADD_TC(tp
, check_sdp_put_uuid16
);
856 ATF_TP_ADD_TC(tp
, check_sdp_put_uuid32
);
857 ATF_TP_ADD_TC(tp
, check_sdp_put_uuid128
);
858 ATF_TP_ADD_TC(tp
, check_sdp_put_bool
);
859 ATF_TP_ADD_TC(tp
, check_sdp_put_uint
);
860 ATF_TP_ADD_TC(tp
, check_sdp_put_uint8
);
861 ATF_TP_ADD_TC(tp
, check_sdp_put_uint16
);
862 ATF_TP_ADD_TC(tp
, check_sdp_put_uint32
);
863 ATF_TP_ADD_TC(tp
, check_sdp_put_uint64
);
864 ATF_TP_ADD_TC(tp
, check_sdp_put_int
);
865 ATF_TP_ADD_TC(tp
, check_sdp_put_int8
);
866 ATF_TP_ADD_TC(tp
, check_sdp_put_int16
);
867 ATF_TP_ADD_TC(tp
, check_sdp_put_int32
);
868 ATF_TP_ADD_TC(tp
, check_sdp_put_int64
);
869 ATF_TP_ADD_TC(tp
, check_sdp_put_seq
);
870 ATF_TP_ADD_TC(tp
, check_sdp_put_alt
);
871 ATF_TP_ADD_TC(tp
, check_sdp_put_str
);
872 ATF_TP_ADD_TC(tp
, check_sdp_put_url
);
874 return atf_no_error();