1 1.2 plunky /* $NetBSD: t_sdp_get.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 <limits.h> 35 1.1 plunky #include <sdp.h> 36 1.1 plunky #include <string.h> 37 1.1 plunky 38 1.1 plunky ATF_TC(check_sdp_get_data); 39 1.1 plunky 40 1.1 plunky ATF_TC_HEAD(check_sdp_get_data, tc) 41 1.1 plunky { 42 1.2 plunky 43 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_data results"); 44 1.1 plunky } 45 1.2 plunky 46 1.1 plunky ATF_TC_BODY(check_sdp_get_data, tc) 47 1.1 plunky { 48 1.1 plunky uint8_t data[] = { 49 1.1 plunky 0x09, 0x00, 0x00, // uint16 0x0000 50 1.1 plunky 0x35, 0x05, // seq8(5) 51 1.1 plunky 0x19, 0x00, 0x00, // uuid16 0x0000 52 1.1 plunky 0x08, 0x00, // uint8 0x00 53 1.1 plunky 0x36, 0x00, 0x01, // seq16(1) 54 1.1 plunky 0x19, // uint16 /* invalid */ 55 1.1 plunky 0x25, 0x04, 0x54, 0x45, // str8(4) "TEST" 56 1.1 plunky 0x53, 0x54, 57 1.1 plunky }; 58 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 59 1.1 plunky sdp_data_t value, seq; 60 1.1 plunky 61 1.1 plunky /* 62 1.1 plunky * sdp_get_data constructs a new sdp_data_t containing 63 1.1 plunky * the next data element, advancing test if successful 64 1.1 plunky */ 65 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value)); 66 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT16); 67 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 3); 68 1.1 plunky 69 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value)); 70 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8); 71 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 7); 72 1.1 plunky 73 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value)); 74 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ16); 75 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 4); 76 1.1 plunky ATF_REQUIRE_EQ(sdp_get_seq(&value, &seq), true); 77 1.1 plunky ATF_REQUIRE_EQ(sdp_get_data(&seq, &value), false); /* invalid */ 78 1.1 plunky 79 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value)); 80 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_STR8); 81 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 6); 82 1.1 plunky 83 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 84 1.1 plunky } 85 1.1 plunky 86 1.1 plunky ATF_TC(check_sdp_get_attr); 87 1.1 plunky 88 1.1 plunky ATF_TC_HEAD(check_sdp_get_attr, tc) 89 1.1 plunky { 90 1.2 plunky 91 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_attr results"); 92 1.1 plunky } 93 1.2 plunky 94 1.1 plunky ATF_TC_BODY(check_sdp_get_attr, tc) 95 1.1 plunky { 96 1.1 plunky uint8_t data[] = { 97 1.1 plunky 0x09, 0x00, 0x00, // uint16 0x0000 98 1.1 plunky 0x35, 0x05, // seq8(5) 99 1.1 plunky 0x19, 0x00, 0x00, // uuid16 0x0000 100 1.1 plunky 0x08, 0x00, // uint8 0x00 101 1.1 plunky 0x08, 0x00, // uint8 0x00 102 1.1 plunky 0x09, 0x00, 0x01, // uint16 0x0001 103 1.1 plunky 0x19, 0x12, 0x34, // uuid16 0x1234 104 1.1 plunky }; 105 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 106 1.1 plunky sdp_data_t value; 107 1.1 plunky uint16_t attr; 108 1.1 plunky 109 1.1 plunky /* 110 1.1 plunky * sdp_get_attr expects a UINT16 followed by any data item 111 1.1 plunky * and advances test if successful 112 1.1 plunky */ 113 1.1 plunky ATF_REQUIRE(sdp_get_attr(&test, &attr, &value)); 114 1.1 plunky ATF_CHECK_EQ(attr, 0x0000); 115 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_SEQ8); 116 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 7); 117 1.1 plunky 118 1.1 plunky ATF_REQUIRE_EQ(sdp_get_attr(&test, &attr, &value), false); 119 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value)); 120 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UINT8); 121 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 2); 122 1.1 plunky 123 1.1 plunky ATF_REQUIRE(sdp_get_attr(&test, &attr, &value)); 124 1.1 plunky ATF_CHECK_EQ(attr, 0x0001); 125 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_UUID16); 126 1.1 plunky ATF_CHECK_EQ(sdp_data_size(&value), 3); 127 1.1 plunky 128 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 129 1.1 plunky } 130 1.1 plunky 131 1.1 plunky ATF_TC(check_sdp_get_uuid); 132 1.1 plunky 133 1.1 plunky ATF_TC_HEAD(check_sdp_get_uuid, tc) 134 1.1 plunky { 135 1.2 plunky 136 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_uuid results"); 137 1.1 plunky } 138 1.2 plunky 139 1.1 plunky ATF_TC_BODY(check_sdp_get_uuid, tc) 140 1.1 plunky { 141 1.1 plunky uint8_t data[] = { 142 1.1 plunky 0x19, 0x12, 0x34, // uuid16 0x1234 143 1.1 plunky 0x1a, 0x11, 0x22, 0x33, // uuid32 0x11223344 144 1.1 plunky 0x44, 145 1.1 plunky 0x00, // nil 146 1.1 plunky 0x1c, // uuid128 0x00112233-4444--5555-6666-778899aabbcc 147 1.1 plunky 0x00, 0x11, 0x22, 0x33, 148 1.1 plunky 0x44, 0x44, 0x55, 0x55, 149 1.1 plunky 0x66, 0x66, 0x77, 0x88, 150 1.1 plunky 0x99, 0xaa, 0xbb, 0xcc, 151 1.1 plunky }; 152 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 153 1.1 plunky uuid_t u16 = { 154 1.1 plunky 0x00001234, 155 1.1 plunky 0x0000, 156 1.1 plunky 0x1000, 157 1.1 plunky 0x80, 158 1.1 plunky 0x00, 159 1.1 plunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb } 160 1.1 plunky }; 161 1.1 plunky uuid_t u32 = { 162 1.1 plunky 0x11223344, 163 1.1 plunky 0x0000, 164 1.1 plunky 0x1000, 165 1.1 plunky 0x80, 166 1.1 plunky 0x00, 167 1.1 plunky { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb } 168 1.1 plunky }; 169 1.1 plunky uuid_t u128 = { 170 1.1 plunky 0x00112233, 171 1.1 plunky 0x4444, 172 1.1 plunky 0x5555, 173 1.1 plunky 0x66, 174 1.1 plunky 0x66, 175 1.1 plunky { 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc } 176 1.1 plunky }; 177 1.1 plunky sdp_data_t nil; 178 1.1 plunky uuid_t value; 179 1.1 plunky 180 1.1 plunky /* 181 1.1 plunky * sdp_get_uuid expects any UUID type returns the full uuid 182 1.1 plunky * advancing test if successful 183 1.1 plunky */ 184 1.1 plunky ATF_REQUIRE(sdp_get_uuid(&test, &value)); 185 1.1 plunky ATF_CHECK(uuid_equal(&value, &u16, NULL)); 186 1.1 plunky 187 1.1 plunky ATF_REQUIRE(sdp_get_uuid(&test, &value)); 188 1.1 plunky ATF_CHECK(uuid_equal(&value, &u32, NULL)); 189 1.1 plunky 190 1.1 plunky ATF_REQUIRE_EQ(sdp_get_uuid(&test, &value), false); /* not uuid */ 191 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 192 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL); 193 1.1 plunky 194 1.1 plunky ATF_REQUIRE(sdp_get_uuid(&test, &value)); 195 1.1 plunky ATF_CHECK(uuid_equal(&value, &u128, NULL)); 196 1.1 plunky 197 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 198 1.1 plunky } 199 1.1 plunky 200 1.1 plunky ATF_TC(check_sdp_get_bool); 201 1.1 plunky 202 1.1 plunky ATF_TC_HEAD(check_sdp_get_bool, tc) 203 1.1 plunky { 204 1.2 plunky 205 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_bool results"); 206 1.1 plunky } 207 1.2 plunky 208 1.1 plunky ATF_TC_BODY(check_sdp_get_bool, tc) 209 1.1 plunky { 210 1.1 plunky uint8_t data[] = { 211 1.1 plunky 0x28, 0x00, // bool false 212 1.1 plunky 0x00, // nil 213 1.1 plunky 0x28, 0x01, // bool true 214 1.1 plunky }; 215 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 216 1.1 plunky sdp_data_t nil; 217 1.1 plunky bool value; 218 1.1 plunky 219 1.1 plunky /* 220 1.1 plunky * sdp_get_bool expects a BOOL type 221 1.1 plunky * advancing test if successful 222 1.1 plunky */ 223 1.1 plunky ATF_REQUIRE(sdp_get_bool(&test, &value)); 224 1.1 plunky ATF_CHECK_EQ(value, false); 225 1.1 plunky 226 1.1 plunky ATF_REQUIRE_EQ(sdp_get_bool(&test, &value), false); /* not bool */ 227 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 228 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL); 229 1.1 plunky 230 1.1 plunky ATF_REQUIRE(sdp_get_bool(&test, &value)); 231 1.1 plunky ATF_CHECK_EQ(value, true); 232 1.1 plunky 233 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 234 1.1 plunky } 235 1.1 plunky 236 1.1 plunky ATF_TC(check_sdp_get_uint); 237 1.1 plunky 238 1.1 plunky ATF_TC_HEAD(check_sdp_get_uint, tc) 239 1.1 plunky { 240 1.2 plunky 241 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_uint results"); 242 1.1 plunky } 243 1.2 plunky 244 1.1 plunky ATF_TC_BODY(check_sdp_get_uint, tc) 245 1.1 plunky { 246 1.1 plunky uint8_t data[] = { 247 1.1 plunky 0x08, 0x00, // uint8 0x00 248 1.1 plunky 0x08, 0xff, // uint8 0xff 249 1.1 plunky 0x09, 0x01, 0x02, // uint16 0x0102 250 1.1 plunky 0x09, 0xff, 0xff, // uint16 0xffff 251 1.1 plunky 0x00, // nil 252 1.1 plunky 0x0a, 0x01, 0x02, 0x03, // uint32 0x01020304 253 1.1 plunky 0x04, 254 1.1 plunky 0x0a, 0xff, 0xff, 0xff, // uint32 0xffffffff 255 1.1 plunky 0xff, 256 1.1 plunky 0x0b, 0x01, 0x02, 0x03, // uint64 0x0102030405060708 257 1.1 plunky 0x04, 0x05, 0x06, 0x07, 258 1.1 plunky 0x08, 259 1.1 plunky 0x0b, 0xff, 0xff, 0xff, // uint64 0xffffffffffffffff 260 1.1 plunky 0xff, 0xff, 0xff, 0xff, 261 1.1 plunky 0xff, 262 1.1 plunky 0x0c, 0x00, 0x00, 0x00, // uint128 0x00000000000000000000000000000000 263 1.1 plunky 0x00, 0x00, 0x00, 0x00, 264 1.1 plunky 0x00, 0x00, 0x00, 0x00, 265 1.1 plunky 0x00, 0x00, 0x00, 0x00, 266 1.1 plunky 0x00, 267 1.1 plunky 0x0c, 0x00, 0x00, 0x00, // uint128 0x00000000000000010000000000000000 268 1.1 plunky 0x00, 0x00, 0x00, 0x00, 269 1.1 plunky 0x01, 0x00, 0x00, 0x00, 270 1.1 plunky 0x00, 0x00, 0x00, 0x00, 271 1.1 plunky 0x00, 272 1.1 plunky 0x0c, 0x00, 0x00, 0x00, // uint128 0x0000000000000000ffffffffffffffff 273 1.1 plunky 0x00, 0x00, 0x00, 0x00, 274 1.1 plunky 0x00, 0xff, 0xff, 0xff, 275 1.1 plunky 0xff, 0xff, 0xff, 0xff, 276 1.1 plunky 0xff, 277 1.1 plunky }; 278 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 279 1.1 plunky sdp_data_t nil; 280 1.1 plunky uintmax_t value; 281 1.1 plunky 282 1.1 plunky /* 283 1.1 plunky * sdp_get_uint expects any UINT type, advancing test if successful 284 1.1 plunky */ 285 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 286 1.1 plunky ATF_CHECK_EQ(value, 0x00); 287 1.1 plunky 288 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 289 1.1 plunky ATF_CHECK_EQ(value, UINT8_MAX); 290 1.1 plunky 291 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 292 1.1 plunky ATF_CHECK_EQ(value, 0x0102); 293 1.1 plunky 294 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 295 1.1 plunky ATF_CHECK_EQ(value, UINT16_MAX); 296 1.1 plunky 297 1.1 plunky ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false); /* not uint */ 298 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 299 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL); 300 1.1 plunky 301 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 302 1.1 plunky ATF_CHECK_EQ(value, 0x01020304); 303 1.1 plunky 304 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 305 1.1 plunky ATF_CHECK_EQ(value, UINT32_MAX); 306 1.1 plunky 307 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 308 1.1 plunky ATF_CHECK_EQ(value, 0x0102030405060708); 309 1.1 plunky 310 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 311 1.1 plunky ATF_CHECK_EQ(value, UINT64_MAX); 312 1.1 plunky 313 1.1 plunky /* 314 1.1 plunky * expected failure is that we cannot decode UINT128 values larger than UINT64 315 1.1 plunky */ 316 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 317 1.1 plunky ATF_CHECK_EQ(value, 0x00000000000000000000000000000000); 318 1.1 plunky 319 1.1 plunky ATF_REQUIRE_EQ(sdp_get_uint(&test, &value), false); /* overflow */ 320 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 321 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_UINT128); 322 1.1 plunky 323 1.1 plunky ATF_REQUIRE(sdp_get_uint(&test, &value)); 324 1.1 plunky ATF_CHECK_EQ(value, UINT64_MAX); 325 1.1 plunky 326 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 327 1.1 plunky } 328 1.1 plunky 329 1.1 plunky ATF_TC(check_sdp_get_int); 330 1.1 plunky 331 1.1 plunky ATF_TC_HEAD(check_sdp_get_int, tc) 332 1.1 plunky { 333 1.2 plunky 334 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_int results"); 335 1.1 plunky } 336 1.2 plunky 337 1.1 plunky ATF_TC_BODY(check_sdp_get_int, tc) 338 1.1 plunky { 339 1.1 plunky uint8_t data[] = { 340 1.1 plunky 0x10, 0x00, // int8 0x00 341 1.1 plunky 0x10, 0x7f, // int8 0x7f 342 1.1 plunky 0x10, 0x80, // int8 0x80 343 1.1 plunky 0x11, 0x01, 0x02, // int16 0x0102 344 1.1 plunky 0x11, 0x7f, 0xff, // int16 0x7fff 345 1.1 plunky 0x11, 0x80, 0x00, // int16 0x8000 346 1.1 plunky 0x00, // nil 347 1.1 plunky 0x12, 0x01, 0x02, 0x03, // int32 0x01020304 348 1.1 plunky 0x04, 349 1.1 plunky 0x12, 0x7f, 0xff, 0xff, // int32 0x7fffffff 350 1.1 plunky 0xff, 351 1.1 plunky 0x12, 0x80, 0x00, 0x00, // int32 0x80000000 352 1.1 plunky 0x00, 353 1.1 plunky 0x13, 0x01, 0x02, 0x03, // int64 0x0102030405060708 354 1.1 plunky 0x04, 0x05, 0x06, 0x07, 355 1.1 plunky 0x08, 356 1.1 plunky 0x13, 0x7f, 0xff, 0xff, // int64 0x7fffffffffffffff 357 1.1 plunky 0xff, 0xff, 0xff, 0xff, 358 1.1 plunky 0xff, 359 1.1 plunky 0x13, 0x80, 0x00, 0x00, // int64 0x8000000000000000 360 1.1 plunky 0x00, 0x00, 0x00, 0x00, 361 1.1 plunky 0x00, 362 1.1 plunky 0x14, 0x00, 0x00, 0x00, // int128 0x00000000000000000000000000000000 363 1.1 plunky 0x00, 0x00, 0x00, 0x00, 364 1.1 plunky 0x00, 0x00, 0x00, 0x00, 365 1.1 plunky 0x00, 0x00, 0x00, 0x00, 366 1.1 plunky 0x00, 367 1.1 plunky 0x14, 0x00, 0x00, 0x00, // int128 0x00000000000000007fffffffffffffff 368 1.1 plunky 0x00, 0x00, 0x00, 0x00, // (INT64_MAX) 369 1.1 plunky 0x00, 0x7f, 0xff, 0xff, 370 1.1 plunky 0xff, 0xff, 0xff, 0xff, 371 1.1 plunky 0xff, 372 1.1 plunky 0x14, 0x00, 0x00, 0x00, // int128 0x00000000000000008000000000000000 373 1.1 plunky 0x00, 0x00, 0x00, 0x00, // (INT64_MAX + 1) 374 1.1 plunky 0x00, 0x80, 0x00, 0x00, 375 1.1 plunky 0x00, 0x00, 0x00, 0x00, 376 1.1 plunky 0x00, 377 1.1 plunky 0x14, 0xff, 0xff, 0xff, // int128 0xffffffffffffffff8000000000000000 378 1.1 plunky 0xff, 0xff, 0xff, 0xff, // (INT64_MIN) 379 1.1 plunky 0xff, 0x80, 0x00, 0x00, 380 1.1 plunky 0x00, 0x00, 0x00, 0x00, 381 1.1 plunky 0x00, 382 1.1 plunky 0x14, 0xff, 0xff, 0xff, // int128 0xffffffffffffffff7fffffffffffffff 383 1.1 plunky 0xff, 0xff, 0xff, 0xff, // (INT64_MIN - 1) 384 1.1 plunky 0xff, 0x7f, 0xff, 0xff, 385 1.1 plunky 0xff, 0xff, 0xff, 0xff, 386 1.1 plunky 0xff, 387 1.1 plunky }; 388 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 389 1.1 plunky sdp_data_t nil; 390 1.1 plunky intmax_t value; 391 1.1 plunky 392 1.1 plunky /* 393 1.1 plunky * sdp_get_int expects any INT type, advancing test if successful 394 1.1 plunky */ 395 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 396 1.1 plunky ATF_CHECK_EQ(value, 0); 397 1.1 plunky 398 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 399 1.1 plunky ATF_CHECK_EQ(value, INT8_MAX); 400 1.1 plunky 401 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 402 1.1 plunky ATF_CHECK_EQ(value, INT8_MIN); 403 1.1 plunky 404 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 405 1.1 plunky ATF_CHECK_EQ(value, 0x0102); 406 1.1 plunky 407 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 408 1.1 plunky ATF_CHECK_EQ(value, INT16_MAX); 409 1.1 plunky 410 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 411 1.1 plunky ATF_CHECK_EQ(value, INT16_MIN); 412 1.1 plunky 413 1.1 plunky ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false); /* not int */ 414 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 415 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL); 416 1.1 plunky 417 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 418 1.1 plunky ATF_CHECK_EQ(value, 0x01020304); 419 1.1 plunky 420 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 421 1.1 plunky ATF_CHECK_EQ(value, INT32_MAX); 422 1.1 plunky 423 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 424 1.1 plunky ATF_CHECK_EQ(value, INT32_MIN); 425 1.1 plunky 426 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 427 1.1 plunky ATF_CHECK_EQ(value, 0x0102030405060708); 428 1.1 plunky 429 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 430 1.1 plunky ATF_CHECK_EQ(value, INT64_MAX); 431 1.1 plunky 432 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 433 1.1 plunky ATF_CHECK_EQ(value, INT64_MIN); 434 1.1 plunky 435 1.1 plunky /* 436 1.1 plunky * expected failure is that we cannot decode INT128 values larger than INT64 437 1.1 plunky */ 438 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 439 1.1 plunky ATF_CHECK_EQ(value, 0); 440 1.1 plunky 441 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 442 1.1 plunky ATF_CHECK_EQ(value, INT64_MAX); 443 1.1 plunky 444 1.1 plunky ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false); /* overflow */ 445 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 446 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128); 447 1.1 plunky 448 1.1 plunky ATF_REQUIRE(sdp_get_int(&test, &value)); 449 1.1 plunky ATF_CHECK_EQ(value, INT64_MIN); 450 1.1 plunky 451 1.1 plunky ATF_REQUIRE_EQ(sdp_get_int(&test, &value), false); /* underflow */ 452 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 453 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_INT128); 454 1.1 plunky 455 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 456 1.1 plunky } 457 1.1 plunky 458 1.1 plunky ATF_TC(check_sdp_get_seq); 459 1.1 plunky 460 1.1 plunky ATF_TC_HEAD(check_sdp_get_seq, tc) 461 1.1 plunky { 462 1.2 plunky 463 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_seq results"); 464 1.1 plunky } 465 1.2 plunky 466 1.1 plunky ATF_TC_BODY(check_sdp_get_seq, tc) 467 1.1 plunky { 468 1.1 plunky uint8_t data[] = { 469 1.1 plunky 0x35, 0x00, // seq8(0) 470 1.1 plunky 0x00, // nil 471 1.1 plunky 0x36, 0x00, 0x00, // seq16(0) 472 1.1 plunky 0x37, 0x00, 0x00, 0x00, // seq32(0) 473 1.1 plunky 0x00, 474 1.1 plunky }; 475 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 476 1.1 plunky sdp_data_t value; 477 1.1 plunky 478 1.1 plunky /* 479 1.1 plunky * sdp_get_seq expects a SEQ type 480 1.1 plunky * advancing test if successful 481 1.1 plunky */ 482 1.1 plunky ATF_REQUIRE(sdp_get_seq(&test, &value)); 483 1.1 plunky ATF_CHECK_EQ(value.next, value.end); 484 1.1 plunky 485 1.1 plunky ATF_REQUIRE_EQ(sdp_get_seq(&test, &value), false); /* not seq */ 486 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value)); /* (skip) */ 487 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL); 488 1.1 plunky 489 1.1 plunky ATF_REQUIRE(sdp_get_seq(&test, &value)); 490 1.1 plunky ATF_CHECK_EQ(value.next, value.end); 491 1.1 plunky 492 1.1 plunky ATF_REQUIRE(sdp_get_seq(&test, &value)); 493 1.1 plunky ATF_CHECK_EQ(value.next, value.end); 494 1.1 plunky 495 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 496 1.1 plunky } 497 1.1 plunky 498 1.1 plunky ATF_TC(check_sdp_get_alt); 499 1.1 plunky 500 1.1 plunky ATF_TC_HEAD(check_sdp_get_alt, tc) 501 1.1 plunky { 502 1.2 plunky 503 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_alt results"); 504 1.1 plunky } 505 1.2 plunky 506 1.1 plunky ATF_TC_BODY(check_sdp_get_alt, tc) 507 1.1 plunky { 508 1.1 plunky uint8_t data[] = { 509 1.1 plunky 0x3d, 0x00, // alt8(0) 510 1.1 plunky 0x00, // nil 511 1.1 plunky 0x3e, 0x00, 0x00, // alt16(0) 512 1.1 plunky 0x3f, 0x00, 0x00, 0x00, // alt32(0) 513 1.1 plunky 0x00, 514 1.1 plunky }; 515 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 516 1.1 plunky sdp_data_t value; 517 1.1 plunky 518 1.1 plunky /* 519 1.1 plunky * sdp_get_alt expects a ALT type 520 1.1 plunky * advancing test if successful 521 1.1 plunky */ 522 1.1 plunky ATF_REQUIRE(sdp_get_alt(&test, &value)); 523 1.1 plunky ATF_CHECK_EQ(value.next, value.end); 524 1.1 plunky 525 1.1 plunky ATF_REQUIRE_EQ(sdp_get_alt(&test, &value), false); /* not alt */ 526 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &value)); /* (skip) */ 527 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&value), SDP_DATA_NIL); 528 1.1 plunky 529 1.1 plunky ATF_REQUIRE(sdp_get_alt(&test, &value)); 530 1.1 plunky ATF_CHECK_EQ(value.next, value.end); 531 1.1 plunky 532 1.1 plunky ATF_REQUIRE(sdp_get_alt(&test, &value)); 533 1.1 plunky ATF_CHECK_EQ(value.next, value.end); 534 1.1 plunky 535 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 536 1.1 plunky } 537 1.1 plunky 538 1.1 plunky ATF_TC(check_sdp_get_str); 539 1.1 plunky 540 1.1 plunky ATF_TC_HEAD(check_sdp_get_str, tc) 541 1.1 plunky { 542 1.2 plunky 543 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_str results"); 544 1.1 plunky } 545 1.2 plunky 546 1.1 plunky ATF_TC_BODY(check_sdp_get_str, tc) 547 1.1 plunky { 548 1.1 plunky uint8_t data[] = { 549 1.1 plunky 0x25, 0x04, 0x53, 0x54, // str8(4) "STR8" 550 1.1 plunky 0x52, 0x38, 551 1.1 plunky 0x00, // nil 552 1.1 plunky 0x26, 0x00, 0x05, 0x53, // str16(5) "STR16" 553 1.1 plunky 0x54, 0x52, 0x31, 0x36, 554 1.1 plunky 0x27, 0x00, 0x00, 0x00, // str32(5) "STR32" 555 1.1 plunky 0x05, 0x53, 0x54, 0x52, 556 1.1 plunky 0x33, 0x32, 557 1.1 plunky }; 558 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 559 1.1 plunky sdp_data_t nil; 560 1.1 plunky char *str; 561 1.1 plunky size_t len; 562 1.1 plunky 563 1.1 plunky /* 564 1.1 plunky * sdp_get_str expects a STR type 565 1.1 plunky * advancing test if successful 566 1.1 plunky */ 567 1.1 plunky ATF_REQUIRE(sdp_get_str(&test, &str, &len)); 568 1.1 plunky ATF_CHECK(len == 4 && strncmp(str, "STR8", 4) == 0); 569 1.1 plunky 570 1.1 plunky ATF_REQUIRE_EQ(sdp_get_str(&test, &str, &len), false); /* not str */ 571 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 572 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL); 573 1.1 plunky 574 1.1 plunky ATF_REQUIRE(sdp_get_str(&test, &str, &len)); 575 1.1 plunky ATF_CHECK(len == 5 && strncmp(str, "STR16", 5) == 0); 576 1.1 plunky 577 1.1 plunky ATF_REQUIRE(sdp_get_str(&test, &str, &len)); 578 1.1 plunky ATF_CHECK(len == 5 && strncmp(str, "STR32", 5) == 0); 579 1.1 plunky 580 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 581 1.1 plunky } 582 1.1 plunky 583 1.1 plunky ATF_TC(check_sdp_get_url); 584 1.1 plunky 585 1.1 plunky ATF_TC_HEAD(check_sdp_get_url, tc) 586 1.1 plunky { 587 1.2 plunky 588 1.1 plunky atf_tc_set_md_var(tc, "descr", "Test sdp_get_url results"); 589 1.1 plunky } 590 1.2 plunky 591 1.1 plunky ATF_TC_BODY(check_sdp_get_url, tc) 592 1.1 plunky { 593 1.1 plunky uint8_t data[] = { 594 1.1 plunky 0x45, 0x04, 0x55, 0x52, // url8(4) "URL8" 595 1.1 plunky 0x4c, 0x38, 596 1.1 plunky 0x00, // nil 597 1.1 plunky 0x46, 0x00, 0x05, 0x55, // url16(5) "URL16" 598 1.1 plunky 0x52, 0x4c, 0x31, 0x36, 599 1.1 plunky 0x47, 0x00, 0x00, 0x00, // url32(5) "URL32" 600 1.1 plunky 0x05, 0x55, 0x52, 0x4c, 601 1.1 plunky 0x33, 0x32, 602 1.1 plunky }; 603 1.1 plunky sdp_data_t test = { data, data + sizeof(data) }; 604 1.1 plunky sdp_data_t nil; 605 1.1 plunky char *url; 606 1.1 plunky size_t len; 607 1.1 plunky 608 1.1 plunky /* 609 1.1 plunky * sdp_get_url expects a URL type 610 1.1 plunky * advancing test if successful 611 1.1 plunky */ 612 1.1 plunky ATF_REQUIRE(sdp_get_url(&test, &url, &len)); 613 1.1 plunky ATF_CHECK(len == 4 && strncmp(url, "URL8", 4) == 0); 614 1.1 plunky 615 1.1 plunky ATF_REQUIRE_EQ(sdp_get_url(&test, &url, &len), false); /* not url */ 616 1.1 plunky ATF_REQUIRE(sdp_get_data(&test, &nil)); /* (skip) */ 617 1.1 plunky ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL); 618 1.1 plunky 619 1.1 plunky ATF_REQUIRE(sdp_get_url(&test, &url, &len)); 620 1.1 plunky ATF_CHECK(len == 5 && strncmp(url, "URL16", 5) == 0); 621 1.1 plunky 622 1.1 plunky ATF_REQUIRE(sdp_get_url(&test, &url, &len)); 623 1.1 plunky ATF_CHECK(len == 5 && strncmp(url, "URL32", 5) == 0); 624 1.1 plunky 625 1.1 plunky ATF_CHECK_EQ(test.next, test.end); 626 1.1 plunky } 627 1.1 plunky 628 1.1 plunky ATF_TP_ADD_TCS(tp) 629 1.1 plunky { 630 1.1 plunky 631 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_data); 632 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_attr); 633 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_uuid); 634 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_bool); 635 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_uint); 636 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_int); 637 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_seq); 638 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_alt); 639 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_str); 640 1.1 plunky ATF_TP_ADD_TC(tp, check_sdp_get_url); 641 1.1 plunky 642 1.1 plunky return atf_no_error(); 643 1.1 plunky } 644