Home | History | Annotate | Line # | Download | only in libbluetooth
t_sdp_match.c revision 1.2
      1  1.2  plunky /*	$NetBSD: t_sdp_match.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_match_uuid16);
     37  1.1  plunky 
     38  1.1  plunky ATF_TC_HEAD(check_sdp_match_uuid16, tc)
     39  1.1  plunky {
     40  1.2  plunky 
     41  1.1  plunky 	atf_tc_set_md_var(tc, "descr", "Test sdp_match_uuid16 results");
     42  1.1  plunky }
     43  1.2  plunky 
     44  1.1  plunky ATF_TC_BODY(check_sdp_match_uuid16, tc)
     45  1.1  plunky {
     46  1.1  plunky 	uint8_t data[] = {
     47  1.1  plunky 		0x19, 0x11, 0x11,	// uuid16	0x1111
     48  1.1  plunky 		0x00,			// nil
     49  1.1  plunky 		0x19, 0x12, 0x34,	// uuid16	0x1234
     50  1.1  plunky 		0x1a, 0x00, 0x00, 0x34,	// uuid32	0x00003456
     51  1.1  plunky 		0x56,
     52  1.1  plunky 		0x1c, 0x00, 0x00, 0x43,	// uuid128	00004321-0000-1000-8000-00805f9b34fb
     53  1.1  plunky 		0x21, 0x00, 0x00, 0x10,
     54  1.1  plunky 		0x00, 0x80, 0x00, 0x00,
     55  1.1  plunky 		0x80, 0x5f, 0x9b, 0x34,
     56  1.1  plunky 		0xfb,
     57  1.1  plunky 	};
     58  1.1  plunky 	sdp_data_t test = { data, data + sizeof(data) };
     59  1.1  plunky 	sdp_data_t nil;
     60  1.1  plunky 
     61  1.1  plunky 	/*
     62  1.1  plunky 	 * sdp_match_uuid16 advances if the UUID matches the 16-bit short alias given
     63  1.1  plunky 	 */
     64  1.1  plunky 
     65  1.1  plunky 	ATF_REQUIRE_EQ(sdp_match_uuid16(&test, 0x1100), false);	/* mismatch */
     66  1.1  plunky 	ATF_REQUIRE(sdp_match_uuid16(&test, 0x1111));
     67  1.1  plunky 
     68  1.1  plunky 	ATF_REQUIRE_EQ(sdp_match_uuid16(&test, 0x1234), false);	/* not uuid */
     69  1.1  plunky 	ATF_REQUIRE(sdp_get_data(&test, &nil));			/* (skip) */
     70  1.1  plunky 	ATF_CHECK_EQ(sdp_data_type(&nil), SDP_DATA_NIL);
     71  1.1  plunky 	ATF_REQUIRE(sdp_match_uuid16(&test, 0x1234));
     72  1.1  plunky 
     73  1.1  plunky 	ATF_REQUIRE(sdp_match_uuid16(&test, 0x3456));
     74  1.1  plunky 
     75  1.1  plunky 	ATF_REQUIRE_EQ(sdp_match_uuid16(&test, 0x1234), false);	/* mismatch */
     76  1.1  plunky 	ATF_REQUIRE(sdp_match_uuid16(&test, 0x4321));
     77  1.1  plunky 
     78  1.1  plunky 	ATF_CHECK_EQ(test.next, test.end);
     79  1.1  plunky }
     80  1.1  plunky 
     81  1.1  plunky ATF_TP_ADD_TCS(tp)
     82  1.1  plunky {
     83  1.1  plunky 
     84  1.1  plunky 	ATF_TP_ADD_TC(tp, check_sdp_match_uuid16);
     85  1.1  plunky 
     86  1.1  plunky 	return atf_no_error();
     87  1.1  plunky }
     88