Add basic unit tests framework for EIR parsing

This commit is contained in:
Johan Hedberg 2011-10-18 14:33:32 +03:00
parent 4a4b56556f
commit 029077107e
2 changed files with 74 additions and 0 deletions

View File

@ -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

62
unit/test-eir.c Normal file
View File

@ -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 <config.h>
#endif
#include <stdint.h>
#include <glib.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/sdp.h>
#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();
}