xref: /freebsd/contrib/netbsd-tests/lib/libbluetooth/t_sdp_data.c (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*	$NetBSD: t_sdp_data.c,v 1.2 2011/04/07 08:29:50 plunky Exp $	*/
2 
3 /*-
4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Iain Hibbert.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
18  *
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.
30  */
31 
32 #include <atf-c.h>
33 
34 #include <sdp.h>
35 
36 ATF_TC(check_sdp_data_type);
37 
38 ATF_TC_HEAD(check_sdp_data_type, tc)
39 {
40 
41 	atf_tc_set_md_var(tc, "descr", "Test sdp_data_type results");
42 }
43 
44 ATF_TC_BODY(check_sdp_data_type, tc)
45 {
46 	uint8_t data[] = {
47 		0x00,			// nil
48 		0x08, 0x00,		// uint8	0x00
49 	};
50 	sdp_data_t test = { data, data + sizeof(data) };
51 	sdp_data_t value;
52 
53 	ATF_REQUIRE(sdp_get_data(&test, &value));
54 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL);
55 
56 	ATF_REQUIRE(sdp_get_data(&test, &value));
57 	ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT8);
58 
59 	ATF_CHECK_EQ(test.next, test.end);
60 }
61 
62 ATF_TC(check_sdp_data_size);
63 
64 ATF_TC_HEAD(check_sdp_data_size, tc)
65 {
66 
67 	atf_tc_set_md_var(tc, "descr", "Test sdp_data_size results");
68 }
69 
70 ATF_TC_BODY(check_sdp_data_size, tc)
71 {
72 	uint8_t data[] = {
73 		0x00,			// nil
74 		0x08, 0x00,		// uint8
75 		0x11, 0x00, 0x00,	// int16
76 		0x1a, 0x00, 0x00, 0x00,	// uuid32
77 		0x00,
78 		0x28, 0x00,		// bool
79 		0x25, 0x00,		// str8(0)
80 		0x25, 0x02, 0x00, 0x00,	// str8(2)
81 		0x36, 0x00, 0x00,	// seq16(0)
82 		0x3e, 0x00, 0x05, 0x00,	// alt16(5)
83 		0x00, 0x00, 0x00, 0x00,
84 		0x37, 0x00, 0x00, 0x00,	// seq32(0)
85 		0x00,
86 		0x47, 0x00, 0x00, 0x00,	// url32(7)
87 		0x07, 0x00, 0x00, 0x00,
88 		0x00, 0x00, 0x00, 0x00,
89 	};
90 	sdp_data_t test = { data, data + sizeof(data) };
91 	sdp_data_t value;
92 
93 	ATF_REQUIRE(sdp_get_data(&test, &value));
94 	ATF_CHECK_EQ(sdp_data_size(&value), 1);
95 
96 	ATF_REQUIRE(sdp_get_data(&test, &value));
97 	ATF_CHECK_EQ(sdp_data_size(&value), 2);
98 
99 	ATF_REQUIRE(sdp_get_data(&test, &value));
100 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
101 
102 	ATF_REQUIRE(sdp_get_data(&test, &value));
103 	ATF_CHECK_EQ(sdp_data_size(&value), 5);
104 
105 	ATF_REQUIRE(sdp_get_data(&test, &value));
106 	ATF_CHECK_EQ(sdp_data_size(&value), 2);
107 
108 	ATF_REQUIRE(sdp_get_data(&test, &value));
109 	ATF_CHECK_EQ(sdp_data_size(&value), 2);
110 
111 	ATF_REQUIRE(sdp_get_data(&test, &value));
112 	ATF_CHECK_EQ(sdp_data_size(&value), 4);
113 
114 	ATF_REQUIRE(sdp_get_data(&test, &value));
115 	ATF_CHECK_EQ(sdp_data_size(&value), 3);
116 
117 	ATF_REQUIRE(sdp_get_data(&test, &value));
118 	ATF_CHECK_EQ(sdp_data_size(&value), 8);
119 
120 	ATF_REQUIRE(sdp_get_data(&test, &value));
121 	ATF_CHECK_EQ(sdp_data_size(&value), 5);
122 
123 	ATF_REQUIRE(sdp_get_data(&test, &value));
124 	ATF_CHECK_EQ(sdp_data_size(&value), 12);
125 
126 	ATF_CHECK_EQ(test.next, test.end);
127 }
128 
129 ATF_TP_ADD_TCS(tp)
130 {
131 
132 	ATF_TP_ADD_TC(tp, check_sdp_data_type);
133 	ATF_TP_ADD_TC(tp, check_sdp_data_size);
134 
135 	return atf_no_error();
136 }
137