1*831ec44fSplunky /* $NetBSD: t_sdp_put.c,v 1.3 2011/04/16 07:32:27 plunky Exp $ */
238293af7Splunky
338293af7Splunky /*-
438293af7Splunky * Copyright (c) 2011 The NetBSD Foundation, Inc.
538293af7Splunky * All rights reserved.
638293af7Splunky *
738293af7Splunky * This code is derived from software contributed to The NetBSD Foundation
838293af7Splunky * by Iain Hibbert.
938293af7Splunky *
1038293af7Splunky * Redistribution and use in source and binary forms, with or without
1138293af7Splunky * modification, are permitted provided that the following conditions
1238293af7Splunky * are met:
1338293af7Splunky * 1. Redistributions of source code must retain the above copyright
1438293af7Splunky * notice, this list of conditions and the following disclaimer.
1538293af7Splunky * 2. Redistributions in binary form must reproduce the above copyright
1638293af7Splunky * notice, this list of conditions and the following disclaimer in the
1738293af7Splunky * documentation and/or other materials provided with the distribution.
1838293af7Splunky *
1938293af7Splunky * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2038293af7Splunky * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2138293af7Splunky * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2238293af7Splunky * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2338293af7Splunky * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2438293af7Splunky * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2538293af7Splunky * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2638293af7Splunky * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2738293af7Splunky * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2838293af7Splunky * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2938293af7Splunky * POSSIBILITY OF SUCH DAMAGE.
3038293af7Splunky */
3138293af7Splunky
3238293af7Splunky #include <atf-c.h>
3338293af7Splunky
3438293af7Splunky #include <limits.h>
3538293af7Splunky #include <sdp.h>
3638293af7Splunky #include <string.h>
3738293af7Splunky
3838293af7Splunky ATF_TC(check_sdp_put_data);
3938293af7Splunky
ATF_TC_HEAD(check_sdp_put_data,tc)4038293af7Splunky ATF_TC_HEAD(check_sdp_put_data, tc)
4138293af7Splunky {
4238293af7Splunky
4338293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_data results");
4438293af7Splunky }
4538293af7Splunky
ATF_TC_BODY(check_sdp_put_data,tc)4638293af7Splunky ATF_TC_BODY(check_sdp_put_data, tc)
4738293af7Splunky {
4838293af7Splunky uint8_t buf[256];
4938293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
5038293af7Splunky uint8_t data[] = {
5138293af7Splunky 0x35, 0x05, // seq8(5)
5238293af7Splunky 0x08, 0x00, // uint8 0x00
5338293af7Splunky 0x09, 0x12, 0x34, // uint16 0x1234
5438293af7Splunky };
5538293af7Splunky sdp_data_t value = { data, data + sizeof(data) };
5638293af7Splunky
5738293af7Splunky ATF_REQUIRE(sdp_put_data(&test, &value));
5838293af7Splunky test.end = test.next;
5938293af7Splunky test.next = buf;
6038293af7Splunky
6138293af7Splunky const uint8_t expect[] = {
6238293af7Splunky 0x35, 0x05, // seq8(5)
6338293af7Splunky 0x08, 0x00, // uint8 0x00
6438293af7Splunky 0x09, 0x12, 0x34, // uint16 0x1234
6538293af7Splunky };
6638293af7Splunky
6738293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
6838293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
6938293af7Splunky }
7038293af7Splunky
7138293af7Splunky ATF_TC(check_sdp_put_attr);
7238293af7Splunky
ATF_TC_HEAD(check_sdp_put_attr,tc)7338293af7Splunky ATF_TC_HEAD(check_sdp_put_attr, tc)
7438293af7Splunky {
7538293af7Splunky
7638293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_attr results");
7738293af7Splunky }
7838293af7Splunky
ATF_TC_BODY(check_sdp_put_attr,tc)7938293af7Splunky ATF_TC_BODY(check_sdp_put_attr, tc)
8038293af7Splunky {
8138293af7Splunky uint8_t buf[256];
8238293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
8338293af7Splunky uint8_t data[] = {
84*831ec44fSplunky 0x00, // nil
8538293af7Splunky 0x19, 0x33, 0x44, // uuid16 0x3344
8638293af7Splunky };
8738293af7Splunky sdp_data_t value = { data, data + sizeof(data) };
8838293af7Splunky
89*831ec44fSplunky ATF_REQUIRE_EQ(sdp_put_attr(&test, 0xabcd, &value), false);
90*831ec44fSplunky value.next += 1; // skip "nil"
9138293af7Splunky ATF_REQUIRE(sdp_put_attr(&test, 0x1337, &value));
9238293af7Splunky test.end = test.next;
9338293af7Splunky test.next = buf;
9438293af7Splunky
9538293af7Splunky const uint8_t expect[] = {
9638293af7Splunky 0x09, 0x13, 0x37, // uint16 0x1337
9738293af7Splunky 0x19, 0x33, 0x44, // uuid16 0x3344
9838293af7Splunky };
9938293af7Splunky
10038293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
10138293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
10238293af7Splunky }
10338293af7Splunky
10438293af7Splunky ATF_TC(check_sdp_put_uuid);
10538293af7Splunky
ATF_TC_HEAD(check_sdp_put_uuid,tc)10638293af7Splunky ATF_TC_HEAD(check_sdp_put_uuid, tc)
10738293af7Splunky {
10838293af7Splunky
10938293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid results");
11038293af7Splunky }
11138293af7Splunky
ATF_TC_BODY(check_sdp_put_uuid,tc)11238293af7Splunky ATF_TC_BODY(check_sdp_put_uuid, tc)
11338293af7Splunky {
11438293af7Splunky uint8_t buf[256];
11538293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
11638293af7Splunky const uuid_t u16 = {
11738293af7Splunky 0x00001234,
11838293af7Splunky 0x0000,
11938293af7Splunky 0x1000,
12038293af7Splunky 0x80,
12138293af7Splunky 0x00,
12238293af7Splunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
12338293af7Splunky };
12438293af7Splunky const uuid_t u32 = {
12538293af7Splunky 0x12345678,
12638293af7Splunky 0x0000,
12738293af7Splunky 0x1000,
12838293af7Splunky 0x80,
12938293af7Splunky 0x00,
13038293af7Splunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
13138293af7Splunky };
13238293af7Splunky const uuid_t u128 = {
13338293af7Splunky 0x00112233,
13438293af7Splunky 0x4444,
13538293af7Splunky 0x5555,
13638293af7Splunky 0x66,
13738293af7Splunky 0x77,
13838293af7Splunky { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }
13938293af7Splunky };
14038293af7Splunky
14138293af7Splunky ATF_REQUIRE(sdp_put_uuid(&test, &u16));
14238293af7Splunky ATF_REQUIRE(sdp_put_uuid(&test, &u32));
14338293af7Splunky ATF_REQUIRE(sdp_put_uuid(&test, &u128));
14438293af7Splunky test.end = test.next;
14538293af7Splunky test.next = buf;
14638293af7Splunky
14738293af7Splunky const uint8_t expect[] = {
14838293af7Splunky 0x19, 0x12, 0x34, // uuid16 0x1234
14938293af7Splunky 0x1a, 0x12, 0x34, 0x56, // uuid32 0x12345678
15038293af7Splunky 0x78,
15138293af7Splunky 0x1c, 0x00, 0x11, 0x22, // uuid128 00112233-4444-5555-6677-8899aabbccdd
15238293af7Splunky 0x33, 0x44, 0x44, 0x55,
15338293af7Splunky 0x55, 0x66, 0x77, 0x88,
15438293af7Splunky 0x99, 0xaa, 0xbb, 0xcc,
15538293af7Splunky 0xdd,
15638293af7Splunky };
15738293af7Splunky
15838293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
15938293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
16038293af7Splunky }
16138293af7Splunky
16238293af7Splunky ATF_TC(check_sdp_put_uuid16);
16338293af7Splunky
ATF_TC_HEAD(check_sdp_put_uuid16,tc)16438293af7Splunky ATF_TC_HEAD(check_sdp_put_uuid16, tc)
16538293af7Splunky {
16638293af7Splunky
16738293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid16 results");
16838293af7Splunky }
16938293af7Splunky
ATF_TC_BODY(check_sdp_put_uuid16,tc)17038293af7Splunky ATF_TC_BODY(check_sdp_put_uuid16, tc)
17138293af7Splunky {
17238293af7Splunky uint8_t buf[256];
17338293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
17438293af7Splunky
17538293af7Splunky ATF_REQUIRE(sdp_put_uuid16(&test, 0x4567));
17638293af7Splunky test.end = test.next;
17738293af7Splunky test.next = buf;
17838293af7Splunky
17938293af7Splunky const uint8_t expect[] = {
18038293af7Splunky 0x19, 0x45, 0x67, // uuid16 0x4567
18138293af7Splunky };
18238293af7Splunky
18338293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
18438293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
18538293af7Splunky }
18638293af7Splunky
18738293af7Splunky ATF_TC(check_sdp_put_uuid32);
18838293af7Splunky
ATF_TC_HEAD(check_sdp_put_uuid32,tc)18938293af7Splunky ATF_TC_HEAD(check_sdp_put_uuid32, tc)
19038293af7Splunky {
19138293af7Splunky
19238293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid32 results");
19338293af7Splunky }
19438293af7Splunky
ATF_TC_BODY(check_sdp_put_uuid32,tc)19538293af7Splunky ATF_TC_BODY(check_sdp_put_uuid32, tc)
19638293af7Splunky {
19738293af7Splunky uint8_t buf[256];
19838293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
19938293af7Splunky
20038293af7Splunky ATF_REQUIRE(sdp_put_uuid32(&test, 0xabcdef00));
20138293af7Splunky test.end = test.next;
20238293af7Splunky test.next = buf;
20338293af7Splunky
20438293af7Splunky const uint8_t expect[] = {
20538293af7Splunky 0x1a, 0xab, 0xcd, 0xef, // uuid32 0xabcdef00
20638293af7Splunky 0x00,
20738293af7Splunky };
20838293af7Splunky
20938293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
21038293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
21138293af7Splunky }
21238293af7Splunky
21338293af7Splunky ATF_TC(check_sdp_put_uuid128);
21438293af7Splunky
ATF_TC_HEAD(check_sdp_put_uuid128,tc)21538293af7Splunky ATF_TC_HEAD(check_sdp_put_uuid128, tc)
21638293af7Splunky {
21738293af7Splunky
21838293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uuid128 results");
21938293af7Splunky }
22038293af7Splunky
ATF_TC_BODY(check_sdp_put_uuid128,tc)22138293af7Splunky ATF_TC_BODY(check_sdp_put_uuid128, tc)
22238293af7Splunky {
22338293af7Splunky uint8_t buf[256];
22438293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
22538293af7Splunky uuid_t value = {
22638293af7Splunky 0x00000100,
22738293af7Splunky 0x0000,
22838293af7Splunky 0x1000,
22938293af7Splunky 0x80,
23038293af7Splunky 0x00,
23138293af7Splunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }
23238293af7Splunky };
23338293af7Splunky
23438293af7Splunky ATF_REQUIRE(sdp_put_uuid128(&test, &value));
23538293af7Splunky test.end = test.next;
23638293af7Splunky test.next = buf;
23738293af7Splunky
23838293af7Splunky const uint8_t expect[] = {
23938293af7Splunky 0x1c, 0x00, 0x00, 0x01, // uuid128 0000100-0000-1000-8000-00805f9b34fb
24038293af7Splunky 0x00, 0x00, 0x00, 0x10, // (L2CAP protocol)
24138293af7Splunky 0x00, 0x80, 0x00, 0x00,
24238293af7Splunky 0x80, 0x5f, 0x9b, 0x34,
24338293af7Splunky 0xfb,
24438293af7Splunky };
24538293af7Splunky
24638293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
24738293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
24838293af7Splunky }
24938293af7Splunky
25038293af7Splunky ATF_TC(check_sdp_put_bool);
25138293af7Splunky
ATF_TC_HEAD(check_sdp_put_bool,tc)25238293af7Splunky ATF_TC_HEAD(check_sdp_put_bool, tc)
25338293af7Splunky {
25438293af7Splunky
25538293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_bool results");
25638293af7Splunky }
25738293af7Splunky
ATF_TC_BODY(check_sdp_put_bool,tc)25838293af7Splunky ATF_TC_BODY(check_sdp_put_bool, tc)
25938293af7Splunky {
26038293af7Splunky uint8_t buf[256];
26138293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
26238293af7Splunky
26338293af7Splunky ATF_REQUIRE(sdp_put_bool(&test, true));
26438293af7Splunky ATF_REQUIRE(sdp_put_bool(&test, false));
26538293af7Splunky test.end = test.next;
26638293af7Splunky test.next = buf;
26738293af7Splunky
26838293af7Splunky const uint8_t expect[] = {
26938293af7Splunky 0x28, 0x01, // bool true
27038293af7Splunky 0x28, 0x00, // bool false
27138293af7Splunky };
27238293af7Splunky
27338293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
27438293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
27538293af7Splunky }
27638293af7Splunky
27738293af7Splunky ATF_TC(check_sdp_put_uint);
27838293af7Splunky
ATF_TC_HEAD(check_sdp_put_uint,tc)27938293af7Splunky ATF_TC_HEAD(check_sdp_put_uint, tc)
28038293af7Splunky {
28138293af7Splunky
28238293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint results");
28338293af7Splunky }
28438293af7Splunky
ATF_TC_BODY(check_sdp_put_uint,tc)28538293af7Splunky ATF_TC_BODY(check_sdp_put_uint, tc)
28638293af7Splunky {
28738293af7Splunky uint8_t buf[256];
28838293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
28938293af7Splunky
29038293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)0));
29138293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT8_MAX));
29238293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT8_MAX + 1));
29338293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT16_MAX));
29438293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT16_MAX + 1));
29538293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT32_MAX));
29638293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT32_MAX + 1));
29738293af7Splunky ATF_REQUIRE(sdp_put_uint(&test, (uintmax_t)UINT64_MAX));
29838293af7Splunky test.end = test.next;
29938293af7Splunky test.next = buf;
30038293af7Splunky
30138293af7Splunky const uint8_t expect[] = {
30238293af7Splunky 0x08, 0x00, // uint8 0x00
30338293af7Splunky 0x08, 0xff, // uint8 0xff
30438293af7Splunky 0x09, 0x01, 0x00, // uint16 0x0100
30538293af7Splunky 0x09, 0xff, 0xff, // uint16 0xffff
30638293af7Splunky 0x0a, 0x00, 0x01, 0x00, // uint32 0x00010000
30738293af7Splunky 0x00,
30838293af7Splunky 0x0a, 0xff, 0xff, 0xff, // uint32 0xffffffff
30938293af7Splunky 0xff,
31038293af7Splunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x0000000100000000
31138293af7Splunky 0x01, 0x00, 0x00, 0x00,
31238293af7Splunky 0x00,
31338293af7Splunky 0x0b, 0xff, 0xff, 0xff, // uint64 0xffffffffffffffff
31438293af7Splunky 0xff, 0xff, 0xff, 0xff,
31538293af7Splunky 0xff,
31638293af7Splunky };
31738293af7Splunky
31838293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
31938293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
32038293af7Splunky }
32138293af7Splunky
32238293af7Splunky ATF_TC(check_sdp_put_uint8);
32338293af7Splunky
ATF_TC_HEAD(check_sdp_put_uint8,tc)32438293af7Splunky ATF_TC_HEAD(check_sdp_put_uint8, tc)
32538293af7Splunky {
32638293af7Splunky
32738293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint8 results");
32838293af7Splunky }
32938293af7Splunky
ATF_TC_BODY(check_sdp_put_uint8,tc)33038293af7Splunky ATF_TC_BODY(check_sdp_put_uint8, tc)
33138293af7Splunky {
33238293af7Splunky uint8_t buf[256];
33338293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
33438293af7Splunky
33538293af7Splunky ATF_REQUIRE(sdp_put_uint8(&test, (uint8_t)0));
33638293af7Splunky ATF_REQUIRE(sdp_put_uint8(&test, (uint8_t)UINT8_MAX));
33738293af7Splunky test.end = test.next;
33838293af7Splunky test.next = buf;
33938293af7Splunky
34038293af7Splunky const uint8_t expect[] = {
34138293af7Splunky 0x08, 0x00, // uint8 0x00
34238293af7Splunky 0x08, 0xff, // uint8 0xff
34338293af7Splunky };
34438293af7Splunky
34538293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
34638293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
34738293af7Splunky }
34838293af7Splunky
34938293af7Splunky ATF_TC(check_sdp_put_uint16);
35038293af7Splunky
ATF_TC_HEAD(check_sdp_put_uint16,tc)35138293af7Splunky ATF_TC_HEAD(check_sdp_put_uint16, tc)
35238293af7Splunky {
35338293af7Splunky
35438293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint16 results");
35538293af7Splunky }
35638293af7Splunky
ATF_TC_BODY(check_sdp_put_uint16,tc)35738293af7Splunky ATF_TC_BODY(check_sdp_put_uint16, tc)
35838293af7Splunky {
35938293af7Splunky uint8_t buf[256];
36038293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
36138293af7Splunky
36238293af7Splunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)0));
36338293af7Splunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)UINT8_MAX));
36438293af7Splunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)UINT16_MAX));
36538293af7Splunky ATF_REQUIRE(sdp_put_uint16(&test, (uint16_t)0xabcd));
36638293af7Splunky test.end = test.next;
36738293af7Splunky test.next = buf;
36838293af7Splunky
36938293af7Splunky const uint8_t expect[] = {
37038293af7Splunky 0x09, 0x00, 0x00, // uint16 0x0000
37138293af7Splunky 0x09, 0x00, 0xff, // uint16 0x00ff
37238293af7Splunky 0x09, 0xff, 0xff, // uint16 0xffff
37338293af7Splunky 0x09, 0xab, 0xcd, // uint16 0xabcd
37438293af7Splunky };
37538293af7Splunky
37638293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
37738293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
37838293af7Splunky }
37938293af7Splunky
38038293af7Splunky ATF_TC(check_sdp_put_uint32);
38138293af7Splunky
ATF_TC_HEAD(check_sdp_put_uint32,tc)38238293af7Splunky ATF_TC_HEAD(check_sdp_put_uint32, tc)
38338293af7Splunky {
38438293af7Splunky
38538293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint32 results");
38638293af7Splunky }
38738293af7Splunky
ATF_TC_BODY(check_sdp_put_uint32,tc)38838293af7Splunky ATF_TC_BODY(check_sdp_put_uint32, tc)
38938293af7Splunky {
39038293af7Splunky uint8_t buf[256];
39138293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
39238293af7Splunky
39338293af7Splunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)0));
39438293af7Splunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT8_MAX));
39538293af7Splunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT16_MAX));
39638293af7Splunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)UINT32_MAX));
39738293af7Splunky ATF_REQUIRE(sdp_put_uint32(&test, (uint32_t)0xdeadbeef));
39838293af7Splunky test.end = test.next;
39938293af7Splunky test.next = buf;
40038293af7Splunky
40138293af7Splunky const uint8_t expect[] = {
40238293af7Splunky 0x0a, 0x00, 0x00, 0x00, // uint32 0x00000000
40338293af7Splunky 0x00,
40438293af7Splunky 0x0a, 0x00, 0x00, 0x00, // uint32 0x000000ff
40538293af7Splunky 0xff,
40638293af7Splunky 0x0a, 0x00, 0x00, 0xff, // uint32 0x0000ffff
40738293af7Splunky 0xff,
40838293af7Splunky 0x0a, 0xff, 0xff, 0xff, // uint32 0xffffffff
40938293af7Splunky 0xff,
41038293af7Splunky 0x0a, 0xde, 0xad, 0xbe, // uint32 0xdeadbeef
41138293af7Splunky 0xef,
41238293af7Splunky };
41338293af7Splunky
41438293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
41538293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
41638293af7Splunky }
41738293af7Splunky
41838293af7Splunky ATF_TC(check_sdp_put_uint64);
41938293af7Splunky
ATF_TC_HEAD(check_sdp_put_uint64,tc)42038293af7Splunky ATF_TC_HEAD(check_sdp_put_uint64, tc)
42138293af7Splunky {
42238293af7Splunky
42338293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_uint64 results");
42438293af7Splunky }
42538293af7Splunky
ATF_TC_BODY(check_sdp_put_uint64,tc)42638293af7Splunky ATF_TC_BODY(check_sdp_put_uint64, tc)
42738293af7Splunky {
42838293af7Splunky uint8_t buf[256];
42938293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
43038293af7Splunky
43138293af7Splunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)0));
43238293af7Splunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT8_MAX));
43338293af7Splunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT16_MAX));
43438293af7Splunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT32_MAX));
43538293af7Splunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)UINT64_MAX));
43638293af7Splunky ATF_REQUIRE(sdp_put_uint64(&test, (uint64_t)0xc0ffeecafec0ffee));
43738293af7Splunky test.end = test.next;
43838293af7Splunky test.next = buf;
43938293af7Splunky
44038293af7Splunky const uint8_t expect[] = {
44138293af7Splunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x0000000000000000
44238293af7Splunky 0x00, 0x00, 0x00, 0x00,
44338293af7Splunky 0x00,
44438293af7Splunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x00000000000000ff
44538293af7Splunky 0x00, 0x00, 0x00, 0x00,
44638293af7Splunky 0xff,
44738293af7Splunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x000000000000ffff
44838293af7Splunky 0x00, 0x00, 0x00, 0xff,
44938293af7Splunky 0xff,
45038293af7Splunky 0x0b, 0x00, 0x00, 0x00, // uint64 0x00000000ffffffff
45138293af7Splunky 0x00, 0xff, 0xff, 0xff,
45238293af7Splunky 0xff,
45338293af7Splunky 0x0b, 0xff, 0xff, 0xff, // uint64 0xffffffffffffffff
45438293af7Splunky 0xff, 0xff, 0xff, 0xff,
45538293af7Splunky 0xff,
45638293af7Splunky 0x0b, 0xc0, 0xff, 0xee, // uint64 0xc0ffeecafec0ffee
45738293af7Splunky 0xca, 0xfe, 0xc0, 0xff,
45838293af7Splunky 0xee,
45938293af7Splunky };
46038293af7Splunky
46138293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
46238293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
46338293af7Splunky }
46438293af7Splunky
46538293af7Splunky ATF_TC(check_sdp_put_int);
46638293af7Splunky
ATF_TC_HEAD(check_sdp_put_int,tc)46738293af7Splunky ATF_TC_HEAD(check_sdp_put_int, tc)
46838293af7Splunky {
46938293af7Splunky
47038293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int results");
47138293af7Splunky }
47238293af7Splunky
ATF_TC_BODY(check_sdp_put_int,tc)47338293af7Splunky ATF_TC_BODY(check_sdp_put_int, tc)
47438293af7Splunky {
47538293af7Splunky uint8_t buf[256];
47638293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
47738293af7Splunky
47838293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)0));
47938293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MIN));
48038293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MAX));
48138293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MIN - 1));
48238293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT8_MAX + 1));
48338293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MIN));
48438293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MAX));
48538293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MIN - 1));
48638293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT16_MAX + 1));
48738293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MIN));
48838293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MAX));
48938293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MIN - 1));
49038293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT32_MAX + 1));
49138293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT64_MIN));
49238293af7Splunky ATF_REQUIRE(sdp_put_int(&test, (intmax_t)INT64_MAX));
49338293af7Splunky test.end = test.next;
49438293af7Splunky test.next = buf;
49538293af7Splunky
49638293af7Splunky const uint8_t expect[] = {
49738293af7Splunky 0x10, 0x00, // int8 0
49838293af7Splunky 0x10, 0x80, // int8 -128
49938293af7Splunky 0x10, 0x7f, // int8 127
50038293af7Splunky 0x11, 0xff, 0x7f, // int16 -129
50138293af7Splunky 0x11, 0x00, 0x80, // int16 128
50238293af7Splunky 0x11, 0x80, 0x00, // int16 -32768
50338293af7Splunky 0x11, 0x7f, 0xff, // int16 32767
50438293af7Splunky 0x12, 0xff, 0xff, 0x7f, // int32 -32769
50538293af7Splunky 0xff,
50638293af7Splunky 0x12, 0x00, 0x00, 0x80, // int32 32768
50738293af7Splunky 0x00,
50838293af7Splunky 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
50938293af7Splunky 0x00,
51038293af7Splunky 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
51138293af7Splunky 0xff,
51238293af7Splunky 0x13, 0xff, 0xff, 0xff, // int64 -2147483649
51338293af7Splunky 0xff, 0x7f, 0xff, 0xff,
51438293af7Splunky 0xff,
51538293af7Splunky 0x13, 0x00, 0x00, 0x00, // int64 2147483648
51638293af7Splunky 0x00, 0x80, 0x00, 0x00,
51738293af7Splunky 0x00,
51838293af7Splunky 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
51938293af7Splunky 0x00, 0x00, 0x00, 0x00,
52038293af7Splunky 0x00,
52138293af7Splunky 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
52238293af7Splunky 0xff, 0xff, 0xff, 0xff,
52338293af7Splunky 0xff,
52438293af7Splunky };
52538293af7Splunky
52638293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
52738293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
52838293af7Splunky }
52938293af7Splunky
53038293af7Splunky ATF_TC(check_sdp_put_int8);
53138293af7Splunky
ATF_TC_HEAD(check_sdp_put_int8,tc)53238293af7Splunky ATF_TC_HEAD(check_sdp_put_int8, tc)
53338293af7Splunky {
53438293af7Splunky
53538293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int8 results");
53638293af7Splunky }
53738293af7Splunky
ATF_TC_BODY(check_sdp_put_int8,tc)53838293af7Splunky ATF_TC_BODY(check_sdp_put_int8, tc)
53938293af7Splunky {
54038293af7Splunky uint8_t buf[256];
54138293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
54238293af7Splunky
54338293af7Splunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)0));
54438293af7Splunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MIN));
54538293af7Splunky ATF_REQUIRE(sdp_put_int8(&test, (int8_t)INT8_MAX));
54638293af7Splunky test.end = test.next;
54738293af7Splunky test.next = buf;
54838293af7Splunky
54938293af7Splunky const uint8_t expect[] = {
55038293af7Splunky 0x10, 0x00, // int8 0
55138293af7Splunky 0x10, 0x80, // int8 -128
55238293af7Splunky 0x10, 0x7f, // int8 127
55338293af7Splunky };
55438293af7Splunky
55538293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
55638293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
55738293af7Splunky }
55838293af7Splunky
55938293af7Splunky ATF_TC(check_sdp_put_int16);
56038293af7Splunky
ATF_TC_HEAD(check_sdp_put_int16,tc)56138293af7Splunky ATF_TC_HEAD(check_sdp_put_int16, tc)
56238293af7Splunky {
56338293af7Splunky
56438293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int16 results");
56538293af7Splunky }
56638293af7Splunky
ATF_TC_BODY(check_sdp_put_int16,tc)56738293af7Splunky ATF_TC_BODY(check_sdp_put_int16, tc)
56838293af7Splunky {
56938293af7Splunky uint8_t buf[256];
57038293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
57138293af7Splunky
57238293af7Splunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)0));
57338293af7Splunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MIN));
57438293af7Splunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT8_MAX));
57538293af7Splunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MIN));
57638293af7Splunky ATF_REQUIRE(sdp_put_int16(&test, (int16_t)INT16_MAX));
57738293af7Splunky test.end = test.next;
57838293af7Splunky test.next = buf;
57938293af7Splunky
58038293af7Splunky const uint8_t expect[] = {
58138293af7Splunky 0x11, 0x00, 0x00, // int16 0
58238293af7Splunky 0x11, 0xff, 0x80, // int16 -128
58338293af7Splunky 0x11, 0x00, 0x7f, // int16 127
58438293af7Splunky 0x11, 0x80, 0x00, // int16 -32768
58538293af7Splunky 0x11, 0x7f, 0xff, // int16 32767
58638293af7Splunky };
58738293af7Splunky
58838293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
58938293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
59038293af7Splunky }
59138293af7Splunky
59238293af7Splunky ATF_TC(check_sdp_put_int32);
59338293af7Splunky
ATF_TC_HEAD(check_sdp_put_int32,tc)59438293af7Splunky ATF_TC_HEAD(check_sdp_put_int32, tc)
59538293af7Splunky {
59638293af7Splunky
59738293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int32 results");
59838293af7Splunky }
59938293af7Splunky
ATF_TC_BODY(check_sdp_put_int32,tc)60038293af7Splunky ATF_TC_BODY(check_sdp_put_int32, tc)
60138293af7Splunky {
60238293af7Splunky uint8_t buf[256];
60338293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
60438293af7Splunky
60538293af7Splunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)0));
60638293af7Splunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MIN));
60738293af7Splunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT8_MAX));
60838293af7Splunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MIN));
60938293af7Splunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT16_MAX));
61038293af7Splunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MIN));
61138293af7Splunky ATF_REQUIRE(sdp_put_int32(&test, (int32_t)INT32_MAX));
61238293af7Splunky test.end = test.next;
61338293af7Splunky test.next = buf;
61438293af7Splunky
61538293af7Splunky const uint8_t expect[] = {
61638293af7Splunky 0x12, 0x00, 0x00, 0x00, // int32 0
61738293af7Splunky 0x00,
61838293af7Splunky 0x12, 0xff, 0xff, 0xff, // int32 -128
61938293af7Splunky 0x80,
62038293af7Splunky 0x12, 0x00, 0x00, 0x00, // int32 127
62138293af7Splunky 0x7f,
62238293af7Splunky 0x12, 0xff, 0xff, 0x80, // int32 -32768
62338293af7Splunky 0x00,
62438293af7Splunky 0x12, 0x00, 0x00, 0x7f, // int32 32767
62538293af7Splunky 0xff,
62638293af7Splunky 0x12, 0x80, 0x00, 0x00, // int32 -2147483648
62738293af7Splunky 0x00,
62838293af7Splunky 0x12, 0x7f, 0xff, 0xff, // int32 2147483647
62938293af7Splunky 0xff,
63038293af7Splunky };
63138293af7Splunky
63238293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
63338293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
63438293af7Splunky }
63538293af7Splunky
63638293af7Splunky ATF_TC(check_sdp_put_int64);
63738293af7Splunky
ATF_TC_HEAD(check_sdp_put_int64,tc)63838293af7Splunky ATF_TC_HEAD(check_sdp_put_int64, tc)
63938293af7Splunky {
64038293af7Splunky
64138293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_int64 results");
64238293af7Splunky }
64338293af7Splunky
ATF_TC_BODY(check_sdp_put_int64,tc)64438293af7Splunky ATF_TC_BODY(check_sdp_put_int64, tc)
64538293af7Splunky {
64638293af7Splunky uint8_t buf[256];
64738293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
64838293af7Splunky
64938293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)0));
65038293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MIN));
65138293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT8_MAX));
65238293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MIN));
65338293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT16_MAX));
65438293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MIN));
65538293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT32_MAX));
65638293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MIN));
65738293af7Splunky ATF_REQUIRE(sdp_put_int64(&test, (int64_t)INT64_MAX));
65838293af7Splunky test.end = test.next;
65938293af7Splunky test.next = buf;
66038293af7Splunky
66138293af7Splunky const uint8_t expect[] = {
66238293af7Splunky 0x13, 0x00, 0x00, 0x00, // int64 0
66338293af7Splunky 0x00, 0x00, 0x00, 0x00,
66438293af7Splunky 0x00,
66538293af7Splunky 0x13, 0xff, 0xff, 0xff, // int64 -128
66638293af7Splunky 0xff, 0xff, 0xff, 0xff,
66738293af7Splunky 0x80,
66838293af7Splunky 0x13, 0x00, 0x00, 0x00, // int64 127
66938293af7Splunky 0x00, 0x00, 0x00, 0x00,
67038293af7Splunky 0x7f,
67138293af7Splunky 0x13, 0xff, 0xff, 0xff, // int64 -32768
67238293af7Splunky 0xff, 0xff, 0xff, 0x80,
67338293af7Splunky 0x00,
67438293af7Splunky 0x13, 0x00, 0x00, 0x00, // int64 32767
67538293af7Splunky 0x00, 0x00, 0x00, 0x7f,
67638293af7Splunky 0xff,
67738293af7Splunky 0x13, 0xff, 0xff, 0xff, // int64 -2147483648
67838293af7Splunky 0xff, 0x80, 0x00, 0x00,
67938293af7Splunky 0x00,
68038293af7Splunky 0x13, 0x00, 0x00, 0x00, // int64 2147483647
68138293af7Splunky 0x00, 0x7f, 0xff, 0xff,
68238293af7Splunky 0xff,
68338293af7Splunky 0x13, 0x80, 0x00, 0x00, // int64 -9223372036854775808
68438293af7Splunky 0x00, 0x00, 0x00, 0x00,
68538293af7Splunky 0x00,
68638293af7Splunky 0x13, 0x7f, 0xff, 0xff, // int64 9223372036854775807
68738293af7Splunky 0xff, 0xff, 0xff, 0xff,
68838293af7Splunky 0xff,
68938293af7Splunky };
69038293af7Splunky
69138293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
69238293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
69338293af7Splunky }
69438293af7Splunky
69538293af7Splunky ATF_TC(check_sdp_put_seq);
69638293af7Splunky
ATF_TC_HEAD(check_sdp_put_seq,tc)69738293af7Splunky ATF_TC_HEAD(check_sdp_put_seq, tc)
69838293af7Splunky {
69938293af7Splunky
70038293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_seq results");
70138293af7Splunky }
70238293af7Splunky
ATF_TC_BODY(check_sdp_put_seq,tc)70338293af7Splunky ATF_TC_BODY(check_sdp_put_seq, tc)
70438293af7Splunky {
70538293af7Splunky uint8_t buf[512];
70638293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
70738293af7Splunky
70838293af7Splunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)0));
70938293af7Splunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX));
71038293af7Splunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)UINT8_MAX + 1));
71138293af7Splunky ATF_REQUIRE(sdp_put_seq(&test, (ssize_t)-1));
71238293af7Splunky ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)UINT16_MAX), false); /* no room */
71338293af7Splunky ATF_CHECK_EQ(sdp_put_seq(&test, (ssize_t)SSIZE_MAX), false); /* no room */
71438293af7Splunky test.end = test.next;
71538293af7Splunky test.next = buf;
71638293af7Splunky
71738293af7Splunky /* (not a valid element list) */
71838293af7Splunky const uint8_t expect[] = {
71938293af7Splunky 0x35, 0x00, // seq8(0)
72038293af7Splunky 0x35, 0xff, // seq8(255)
72138293af7Splunky 0x36, 0x01, 0x00, // seq16(256)
72238293af7Splunky 0x36, 0x01, 0xf6, // seq16(502) <- sizeof(buf) - 7 - 3
72338293af7Splunky };
72438293af7Splunky
72538293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
72638293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
72738293af7Splunky }
72838293af7Splunky
72938293af7Splunky ATF_TC(check_sdp_put_alt);
73038293af7Splunky
ATF_TC_HEAD(check_sdp_put_alt,tc)73138293af7Splunky ATF_TC_HEAD(check_sdp_put_alt, tc)
73238293af7Splunky {
73338293af7Splunky
73438293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_alt results");
73538293af7Splunky }
73638293af7Splunky
ATF_TC_BODY(check_sdp_put_alt,tc)73738293af7Splunky ATF_TC_BODY(check_sdp_put_alt, tc)
73838293af7Splunky {
73938293af7Splunky uint8_t buf[512];
74038293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
74138293af7Splunky
74238293af7Splunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)0));
74338293af7Splunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX));
74438293af7Splunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)UINT8_MAX + 1));
74538293af7Splunky ATF_REQUIRE(sdp_put_alt(&test, (ssize_t)-1));
74638293af7Splunky ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)UINT16_MAX), false); /* no room */
74738293af7Splunky ATF_CHECK_EQ(sdp_put_alt(&test, (ssize_t)SSIZE_MAX), false); /* no room */
74838293af7Splunky test.end = test.next;
74938293af7Splunky test.next = buf;
75038293af7Splunky
75138293af7Splunky /* (not a valid element list) */
75238293af7Splunky const uint8_t expect[] = {
75338293af7Splunky 0x3d, 0x00, // alt8(0)
75438293af7Splunky 0x3d, 0xff, // alt8(255)
75538293af7Splunky 0x3e, 0x01, 0x00, // alt16(256)
75638293af7Splunky 0x3e, 0x01, 0xf6, // alt16(502) <- sizeof(buf) - 7 - 3
75738293af7Splunky };
75838293af7Splunky
75938293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
76038293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
76138293af7Splunky }
76238293af7Splunky
76338293af7Splunky ATF_TC(check_sdp_put_str);
76438293af7Splunky
ATF_TC_HEAD(check_sdp_put_str,tc)76538293af7Splunky ATF_TC_HEAD(check_sdp_put_str, tc)
76638293af7Splunky {
76738293af7Splunky
76838293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_str results");
76938293af7Splunky }
77038293af7Splunky
ATF_TC_BODY(check_sdp_put_str,tc)77138293af7Splunky ATF_TC_BODY(check_sdp_put_str, tc)
77238293af7Splunky {
77338293af7Splunky uint8_t buf[512];
77438293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
77538293af7Splunky
77638293af7Splunky /*
77738293af7Splunky * this does not test str16 or str32, but that is
77838293af7Splunky * handled by the same code as sdp_put_seq above..
77938293af7Splunky */
78038293af7Splunky
78138293af7Splunky ATF_REQUIRE(sdp_put_str(&test, "Hello World!", 5));
78238293af7Splunky ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", 11));
78338293af7Splunky ATF_REQUIRE(sdp_put_str(&test, "Hello World!", -1));
78438293af7Splunky ATF_REQUIRE(sdp_put_str(&test, "Hello\0World", -1));
78538293af7Splunky test.end = test.next;
78638293af7Splunky test.next = buf;
78738293af7Splunky
78838293af7Splunky const uint8_t expect[] = {
78938293af7Splunky 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
79038293af7Splunky 0x6c, 0x6c, 0x6f,
79138293af7Splunky 0x25, 0x0b, 0x48, 0x65, // str8 "Hello\0World"
79238293af7Splunky 0x6c, 0x6c, 0x6f, 0x00,
79338293af7Splunky 0x57, 0x6f, 0x72, 0x6c,
79438293af7Splunky 0x64,
79538293af7Splunky 0x25, 0x0c, 0x48, 0x65, // str8 "Hello World!"
79638293af7Splunky 0x6c, 0x6c, 0x6f, 0x20,
79738293af7Splunky 0x57, 0x6f, 0x72, 0x6c,
79838293af7Splunky 0x64, 0x21,
79938293af7Splunky 0x25, 0x05, 0x48, 0x65, // str8 "Hello"
80038293af7Splunky 0x6c, 0x6c, 0x6f,
80138293af7Splunky };
80238293af7Splunky
80338293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
80438293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
80538293af7Splunky }
80638293af7Splunky
80738293af7Splunky ATF_TC(check_sdp_put_url);
80838293af7Splunky
ATF_TC_HEAD(check_sdp_put_url,tc)80938293af7Splunky ATF_TC_HEAD(check_sdp_put_url, tc)
81038293af7Splunky {
81138293af7Splunky
81238293af7Splunky atf_tc_set_md_var(tc, "descr", "Test sdp_put_url results");
81338293af7Splunky }
81438293af7Splunky
ATF_TC_BODY(check_sdp_put_url,tc)81538293af7Splunky ATF_TC_BODY(check_sdp_put_url, tc)
81638293af7Splunky {
81738293af7Splunky uint8_t buf[512];
81838293af7Splunky sdp_data_t test = { buf, buf + sizeof(buf) };
81938293af7Splunky
82038293af7Splunky /*
82138293af7Splunky * this does not test url16 or url32, but that is
82238293af7Splunky * handled by the same code as sdp_put_seq above..
82338293af7Splunky */
82438293af7Splunky
82538293af7Splunky ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", 21));
82638293af7Splunky ATF_REQUIRE(sdp_put_url(&test, "http://www.netbsd.org/", -1));
82738293af7Splunky test.end = test.next;
82838293af7Splunky test.next = buf;
82938293af7Splunky
83038293af7Splunky const uint8_t expect[] = {
83138293af7Splunky 0x45, 0x15, 0x68, 0x74, // url8 "http://www.netbsd.org"
83238293af7Splunky 0x74, 0x70, 0x3a, 0x2f,
83338293af7Splunky 0x2f, 0x77, 0x77, 0x77,
83438293af7Splunky 0x2e, 0x6e, 0x65, 0x74,
83538293af7Splunky 0x62, 0x73, 0x64, 0x2e,
83638293af7Splunky 0x6f, 0x72, 0x67,
83738293af7Splunky 0x45, 0x16, 0x68, 0x74, // url8 "http://www.netbsd.org/"
83838293af7Splunky 0x74, 0x70, 0x3a, 0x2f,
83938293af7Splunky 0x2f, 0x77, 0x77, 0x77,
84038293af7Splunky 0x2e, 0x6e, 0x65, 0x74,
84138293af7Splunky 0x62, 0x73, 0x64, 0x2e,
84238293af7Splunky 0x6f, 0x72, 0x67, 0x2f,
84338293af7Splunky };
84438293af7Splunky
84538293af7Splunky ATF_REQUIRE_EQ(test.end - test.next, sizeof(expect));
84638293af7Splunky ATF_CHECK(memcmp(expect, test.next, sizeof(expect)) == 0);
84738293af7Splunky }
84838293af7Splunky
ATF_TP_ADD_TCS(tp)84938293af7Splunky ATF_TP_ADD_TCS(tp)
85038293af7Splunky {
85138293af7Splunky
85238293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_data);
85338293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_attr);
85438293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid);
85538293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid16);
85638293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid32);
85738293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uuid128);
85838293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_bool);
85938293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uint);
86038293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uint8);
86138293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uint16);
86238293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uint32);
86338293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_uint64);
86438293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_int);
86538293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_int8);
86638293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_int16);
86738293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_int32);
86838293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_int64);
86938293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_seq);
87038293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_alt);
87138293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_str);
87238293af7Splunky ATF_TP_ADD_TC(tp, check_sdp_put_url);
87338293af7Splunky
87438293af7Splunky return atf_no_error();
87538293af7Splunky }
876