From 9d387f43726c170f12420158edb6fb0e3fdca0fb Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 24 Oct 2011 23:37:34 +0200 Subject: [PATCH] Convert unit tests from GLib to GNU Check --- Makefile.am | 3 ++- configure.ac | 2 ++ unit/test-eir.c | 41 ++++++++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index 138ab322f..283af4de1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -450,7 +450,8 @@ 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_test_eir_CFLAGS = @GLIB_CFLAGS@ @CHECK_CFLAGS@ +unit_test_eir_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@ @CHECK_LIBS@ unit_objects += $(unit_test_eir_OBJECTS) TESTS = $(unit_tests) diff --git a/configure.ac b/configure.ac index 50ca5dce9..50ab5433a 100644 --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,8 @@ AC_PROG_YACC AM_PROG_LEX AM_PROG_MKDIR_P +AM_PATH_CHECK + m4_define([_LT_AC_TAGCONFIG], []) m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])]) diff --git a/unit/test-eir.c b/unit/test-eir.c index f25b58edd..cefcacd13 100644 --- a/unit/test-eir.c +++ b/unit/test-eir.c @@ -25,6 +25,8 @@ #include #endif +#include + #include #include @@ -35,7 +37,7 @@ #include "eir.h" -static void test_basic(void) +START_TEST(test_basic) { struct eir_data data; unsigned char buf[HCI_MAX_EIR_LENGTH]; @@ -45,18 +47,43 @@ static void test_basic(void) memset(&data, 0, sizeof(data)); err = eir_parse(&data, buf, HCI_MAX_EIR_LENGTH); - g_assert(err == 0); - g_assert(data.services == NULL); - g_assert(data.name == NULL); + ck_assert(err == 0); + ck_assert(data.services == NULL); + ck_assert(data.name == NULL); eir_data_free(&data); } +END_TEST + +static void add_test(Suite *s, const char *name, TFun func) +{ + TCase *t; + + t = tcase_create(name); + tcase_add_test(t, func); + suite_add_tcase(s, t); +} int main(int argc, char *argv[]) { - g_test_init(&argc, &argv, NULL); + int fails; + SRunner *sr; + Suite *s; + + s = suite_create("EIR"); + + add_test(s, "basic", test_basic); + + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + + fails = srunner_ntests_failed(sr); + + srunner_free(sr); - g_test_add_func("/eir/test_basic", test_basic); + if (fails > 0) + return -1; - return g_test_run(); + return 0; } -- 2.47.3