From 029077107eb09895f973184b1075fdf4c46d9041 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 18 Oct 2011 14:33:32 +0300 Subject: [PATCH] Add basic unit tests framework for EIR parsing --- Makefile.am | 12 ++++++++++ unit/test-eir.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 unit/test-eir.c diff --git a/Makefile.am b/Makefile.am index 06332de86..138ab322f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -443,6 +443,18 @@ if MCAP INCLUDES += -I$(builddir)/health endif +unit_objects = + +unit_tests = unit/test-eir + +noinst_PROGRAMS += $(unit_tests) + +unit_test_eir_SOURCES = unit/test-eir.c src/eir.c src/glib-helper.c +unit_test_eir_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@ +unit_objects += $(unit_test_eir_OBJECTS) + +TESTS = $(unit_tests) + pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = bluez.pc diff --git a/unit/test-eir.c b/unit/test-eir.c new file mode 100644 index 000000000..5ea5d756f --- /dev/null +++ b/unit/test-eir.c @@ -0,0 +1,62 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2011 Intel Corporation + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +#include +#include +#include + +#include "eir.h" + +static void test_basic(void) +{ + struct eir_data data; + unsigned char buf[HCI_MAX_EIR_LENGTH]; + int err; + + memset(buf, 0, sizeof(buf)); + memset(&data, 0, sizeof(data)); + + err = eir_parse(&data, buf); + g_assert(err == 0); + g_assert(data.services == NULL); + g_assert(data.name == NULL); + + eir_data_free(&data); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/eir/test_basic", test_basic); + + return g_test_run(); +} -- 2.47.3