xref: /netbsd-src/tests/lib/libbluetooth/t_bluetooth.c (revision 5a4807fa7d17d0c1280be680686b5965edb14b8f)
1*5a4807faSplunky /*	$NetBSD: t_bluetooth.c,v 1.2 2011/04/07 08:29:50 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 <bluetooth.h>
3538293af7Splunky #include <string.h>
3638293af7Splunky 
3738293af7Splunky ATF_TC(check_bt_aton);
3838293af7Splunky 
ATF_TC_HEAD(check_bt_aton,tc)3938293af7Splunky ATF_TC_HEAD(check_bt_aton, tc)
4038293af7Splunky {
4138293af7Splunky 
4238293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test bt_aton results");
4338293af7Splunky }
4438293af7Splunky 
ATF_TC_BODY(check_bt_aton,tc)4538293af7Splunky ATF_TC_BODY(check_bt_aton, tc)
4638293af7Splunky {
4738293af7Splunky 	bdaddr_t bdaddr;
4838293af7Splunky 
4938293af7Splunky 	ATF_CHECK_EQ(bt_aton("0a:0b:0c:0d:0e", &bdaddr), 0);
5038293af7Splunky 	ATF_CHECK_EQ(bt_aton("0a:0b:0c:0d0:0e:0f", &bdaddr), 0);
5138293af7Splunky 	ATF_CHECK_EQ(bt_aton("0a:0b:0c:0d:0e:0f:00", &bdaddr), 0);
5238293af7Splunky 	ATF_CHECK_EQ(bt_aton("0a:0b:0c:0d:0e:0f\n", &bdaddr), 0);
5338293af7Splunky 	ATF_CHECK_EQ(bt_aton(" 0a:0b:0c:0d:0e:0f", &bdaddr), 0);
5438293af7Splunky 	ATF_CHECK_EQ(bt_aton("0a:0b:0x:0d:0e:0f", &bdaddr), 0);
5538293af7Splunky 
5638293af7Splunky 	ATF_REQUIRE(bt_aton("0a:0b:0c:0d:0e:0f", &bdaddr));
5738293af7Splunky 	ATF_CHECK_EQ(bdaddr.b[0], 0x0f);
5838293af7Splunky 	ATF_CHECK_EQ(bdaddr.b[1], 0x0e);
5938293af7Splunky 	ATF_CHECK_EQ(bdaddr.b[2], 0x0d);
6038293af7Splunky 	ATF_CHECK_EQ(bdaddr.b[3], 0x0c);
6138293af7Splunky 	ATF_CHECK_EQ(bdaddr.b[4], 0x0b);
6238293af7Splunky 	ATF_CHECK_EQ(bdaddr.b[5], 0x0a);
6338293af7Splunky }
6438293af7Splunky 
6538293af7Splunky ATF_TC(check_bt_ntoa);
6638293af7Splunky 
ATF_TC_HEAD(check_bt_ntoa,tc)6738293af7Splunky ATF_TC_HEAD(check_bt_ntoa, tc)
6838293af7Splunky {
6938293af7Splunky 
7038293af7Splunky 	atf_tc_set_md_var(tc, "descr", "Test bt_ntoa results");
7138293af7Splunky }
7238293af7Splunky 
ATF_TC_BODY(check_bt_ntoa,tc)7338293af7Splunky ATF_TC_BODY(check_bt_ntoa, tc)
7438293af7Splunky {
7538293af7Splunky 	bdaddr_t bdaddr = { { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } };
7638293af7Splunky 
7738293af7Splunky 	ATF_CHECK_STREQ(bt_ntoa(&bdaddr, NULL), "55:44:33:22:11:00");
7838293af7Splunky }
7938293af7Splunky 
ATF_TP_ADD_TCS(tp)8038293af7Splunky ATF_TP_ADD_TCS(tp)
8138293af7Splunky {
8238293af7Splunky 
8338293af7Splunky 	ATF_TP_ADD_TC(tp, check_bt_aton);
8438293af7Splunky 	ATF_TP_ADD_TC(tp, check_bt_ntoa);
8538293af7Splunky 
8638293af7Splunky 	return atf_no_error();
8738293af7Splunky }
88