t_sdp_data.c revision 1.2 1 1.2 plunky /* $NetBSD: t_sdp_data.c,v 1.2 2011/04/07 08:29:50 plunky Exp $ */
2 1.1 plunky
3 1.1 plunky /*-
4 1.1 plunky * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 plunky * All rights reserved.
6 1.1 plunky *
7 1.1 plunky * This code is derived from software contributed to The NetBSD Foundation
8 1.1 plunky * by Iain Hibbert.
9 1.1 plunky *
10 1.1 plunky * Redistribution and use in source and binary forms, with or without
11 1.1 plunky * modification, are permitted provided that the following conditions
12 1.1 plunky * are met:
13 1.1 plunky * 1. Redistributions of source code must retain the above copyright
14 1.1 plunky * notice, this list of conditions and the following disclaimer.
15 1.1 plunky * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 plunky * notice, this list of conditions and the following disclaimer in the
17 1.1 plunky * documentation and/or other materials provided with the distribution.
18 1.1 plunky *
19 1.1 plunky * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 plunky * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 plunky * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 plunky * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 plunky * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 plunky * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 plunky * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 plunky * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 plunky * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 plunky * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 plunky * POSSIBILITY OF SUCH DAMAGE.
30 1.1 plunky */
31 1.1 plunky
32 1.1 plunky #include <atf-c.h>
33 1.1 plunky
34 1.1 plunky #include <sdp.h>
35 1.1 plunky
36 1.1 plunky ATF_TC(check_sdp_data_type);
37 1.1 plunky
38 1.1 plunky ATF_TC_HEAD(check_sdp_data_type, tc)
39 1.1 plunky {
40 1.2 plunky
41 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_data_type results");
42 1.1 plunky }
43 1.2 plunky
44 1.1 plunky ATF_TC_BODY(check_sdp_data_type, tc)
45 1.1 plunky {
46 1.1 plunky uint8_t data[] = {
47 1.1 plunky 0x00, // nil
48 1.1 plunky 0x08, 0x00, // uint8 0x00
49 1.1 plunky };
50 1.1 plunky sdp_data_t test = { data, data + sizeof(data) };
51 1.1 plunky sdp_data_t value;
52 1.1 plunky
53 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
54 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
55 1.1 plunky
56 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
57 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT8);
58 1.1 plunky
59 1.1 plunky ATF_CHECK_EQ(test.next, test.end);
60 1.1 plunky }
61 1.1 plunky
62 1.1 plunky ATF_TC(check_sdp_data_size);
63 1.1 plunky
64 1.1 plunky ATF_TC_HEAD(check_sdp_data_size, tc)
65 1.1 plunky {
66 1.2 plunky
67 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_data_size results");
68 1.1 plunky }
69 1.2 plunky
70 1.1 plunky ATF_TC_BODY(check_sdp_data_size, tc)
71 1.1 plunky {
72 1.1 plunky uint8_t data[] = {
73 1.1 plunky 0x00, // nil
74 1.1 plunky 0x08, 0x00, // uint8
75 1.1 plunky 0x11, 0x00, 0x00, // int16
76 1.1 plunky 0x1a, 0x00, 0x00, 0x00, // uuid32
77 1.1 plunky 0x00,
78 1.1 plunky 0x28, 0x00, // bool
79 1.1 plunky 0x25, 0x00, // str8(0)
80 1.1 plunky 0x25, 0x02, 0x00, 0x00, // str8(2)
81 1.1 plunky 0x36, 0x00, 0x00, // seq16(0)
82 1.1 plunky 0x3e, 0x00, 0x05, 0x00, // alt16(5)
83 1.1 plunky 0x00, 0x00, 0x00, 0x00,
84 1.1 plunky 0x37, 0x00, 0x00, 0x00, // seq32(0)
85 1.1 plunky 0x00,
86 1.1 plunky 0x47, 0x00, 0x00, 0x00, // url32(7)
87 1.1 plunky 0x07, 0x00, 0x00, 0x00,
88 1.1 plunky 0x00, 0x00, 0x00, 0x00,
89 1.1 plunky };
90 1.1 plunky sdp_data_t test = { data, data + sizeof(data) };
91 1.1 plunky sdp_data_t value;
92 1.1 plunky
93 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
94 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 1);
95 1.1 plunky
96 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
97 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 2);
98 1.1 plunky
99 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
100 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 3);
101 1.1 plunky
102 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
103 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 5);
104 1.1 plunky
105 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
106 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 2);
107 1.1 plunky
108 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
109 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 2);
110 1.1 plunky
111 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
112 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 4);
113 1.1 plunky
114 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
115 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 3);
116 1.1 plunky
117 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
118 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 8);
119 1.1 plunky
120 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
121 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 5);
122 1.1 plunky
123 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value));
124 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 12);
125 1.1 plunky
126 1.1 plunky ATF_CHECK_EQ(test.next, test.end);
127 1.1 plunky }
128 1.1 plunky
129 1.1 plunky ATF_TP_ADD_TCS(tp)
130 1.1 plunky {
131 1.1 plunky
132 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_data_type);
133 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_data_size);
134 1.1 plunky
135 1.1 plunky return atf_no_error();
136 1.1 plunky }
137