diff options
author | Simon McVittie <smcv@collabora.com> | 2022-07-15 15:27:24 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2022-07-18 11:15:54 +0000 |
commit | 11e6c92e9521ef55ceb0b421c5d077d5793c71d5 (patch) | |
tree | 737f48038518e68f79e16a93deac93ada11d0832 | |
parent | 2cdd0d0f30e61298f2ae93157baa9ad987788184 (diff) | |
download | dbus-11e6c92e9521ef55ceb0b421c5d077d5793c71d5.tar.gz |
test/bus: Factor out common setup/teardown code
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | test/CMakeLists.txt | 6 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/bus/common.c | 61 | ||||
-rw-r--r-- | test/bus/common.h | 21 | ||||
-rw-r--r-- | test/bus/dispatch-sha1.c | 33 | ||||
-rw-r--r-- | test/bus/dispatch.c | 33 | ||||
-rw-r--r-- | test/bus/main.c | 33 | ||||
-rw-r--r-- | test/meson.build | 6 |
8 files changed, 97 insertions, 102 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 864d078b..c08ad95b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -146,15 +146,15 @@ if(DBUS_ENABLE_EMBEDDED_TESTS) add_test_executable(test-platform-mutex test-platform-mutex.c ${DBUS_INTERNAL_LIBRARIES} dbus-testutils) - set(SOURCES bus/main.c) + set(SOURCES bus/main.c bus/common.c bus/common.h) add_test_executable(test-bus "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) - set(SOURCES bus/dispatch.c) + set(SOURCES bus/dispatch.c bus/common.c bus/common.h) add_test_executable(test-bus-dispatch "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) set_target_properties(test-bus-dispatch PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) - set(SOURCES bus/dispatch-sha1.c) + set(SOURCES bus/dispatch-sha1.c bus/common.c bus/common.h) add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) set_target_properties(test-bus-dispatch-sha1 PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) diff --git a/test/Makefile.am b/test/Makefile.am index 1ee9dd21..18798278 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -199,19 +199,19 @@ test_bus_system_LDADD = \ libdbus-testutils.la \ $(NULL) -test_bus_SOURCES = bus/main.c +test_bus_SOURCES = bus/main.c bus/common.c bus/common.h test_bus_LDADD = \ $(top_builddir)/bus/libdbus-daemon-internal.la \ libdbus-testutils.la \ $(NULL) -test_bus_dispatch_SOURCES = bus/dispatch.c +test_bus_dispatch_SOURCES = bus/dispatch.c bus/common.c bus/common.h test_bus_dispatch_LDADD = \ $(top_builddir)/bus/libdbus-daemon-internal.la \ libdbus-testutils.la \ $(NULL) -test_bus_dispatch_sha1_SOURCES = bus/dispatch-sha1.c +test_bus_dispatch_sha1_SOURCES = bus/dispatch-sha1.c bus/common.c bus/common.h test_bus_dispatch_sha1_LDADD = \ $(top_builddir)/bus/libdbus-daemon-internal.la \ libdbus-testutils.la \ diff --git a/test/bus/common.c b/test/bus/common.c new file mode 100644 index 00000000..96573858 --- /dev/null +++ b/test/bus/common.c @@ -0,0 +1,61 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright 2003-2009 Red Hat, Inc. + * Copyright 2011-2022 Collabora Ltd. + * SPDX-License-Identifier: AFL-2.1 or GPL-2-or-later + * + * Licensed under the Academic Free License version 2.1 + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <config.h> + +#include "bus/audit.h" +#include "bus/selinux.h" + +#include "test/bus/common.h" +#include "test/test-utils.h" + +#ifndef DBUS_ENABLE_EMBEDDED_TESTS +#error This file is only relevant for the embedded tests +#endif + +static void +test_pre_hook (void) +{ +} + +static void +test_post_hook (void) +{ + if (_dbus_getenv ("DBUS_TEST_SELINUX")) + bus_selinux_shutdown (); + + bus_audit_shutdown (); +} + +int +bus_test_main (int argc, + char **argv, + size_t n_tests, + const DBusTestCase *tests) +{ + return _dbus_test_main (argc, argv, n_tests, tests, + (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | + DBUS_TEST_FLAGS_CHECK_FD_LEAKS | + DBUS_TEST_FLAGS_REQUIRE_DATA), + test_pre_hook, test_post_hook); +} diff --git a/test/bus/common.h b/test/bus/common.h new file mode 100644 index 00000000..0f3c87d0 --- /dev/null +++ b/test/bus/common.h @@ -0,0 +1,21 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: MIT + */ + +#ifndef TEST_BUS_COMMON_H +#define TEST_BUS_COMMON_H + +#ifndef DBUS_ENABLE_EMBEDDED_TESTS +#error This file is only relevant for the embedded tests +#endif + +#include "bus/test.h" +#include "test/test-utils.h" + +int bus_test_main (int argc, + char **argv, + size_t n_tests, + const DBusTestCase *tests); + +#endif diff --git a/test/bus/dispatch-sha1.c b/test/bus/dispatch-sha1.c index a32508bc..dc2dcb5d 100644 --- a/test/bus/dispatch-sha1.c +++ b/test/bus/dispatch-sha1.c @@ -22,41 +22,12 @@ */ #include <config.h> - -#include "bus/test.h" - -#include <dbus/dbus-test-tap.h> - -#include "bus/audit.h" -#include "bus/selinux.h" -#include "test/test-utils.h" - -#ifndef DBUS_ENABLE_EMBEDDED_TESTS -#error This file is only relevant for the embedded tests -#endif - -static void -test_pre_hook (void) -{ -} - -static void -test_post_hook (void) -{ - if (_dbus_getenv ("DBUS_TEST_SELINUX")) - bus_selinux_shutdown (); - - bus_audit_shutdown (); -} +#include "test/bus/common.h" static DBusTestCase test = { "dispatch-sha1", bus_dispatch_sha1_test }; int main (int argc, char **argv) { - return _dbus_test_main (argc, argv, 1, &test, - (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | - DBUS_TEST_FLAGS_CHECK_FD_LEAKS | - DBUS_TEST_FLAGS_REQUIRE_DATA), - test_pre_hook, test_post_hook); + return bus_test_main (argc, argv, 1, &test); } diff --git a/test/bus/dispatch.c b/test/bus/dispatch.c index ad6718fe..bd86419f 100644 --- a/test/bus/dispatch.c +++ b/test/bus/dispatch.c @@ -22,41 +22,12 @@ */ #include <config.h> - -#include "bus/test.h" - -#include <dbus/dbus-test-tap.h> - -#include "bus/audit.h" -#include "bus/selinux.h" -#include "test/test-utils.h" - -#ifndef DBUS_ENABLE_EMBEDDED_TESTS -#error This file is only relevant for the embedded tests -#endif - -static void -test_pre_hook (void) -{ -} - -static void -test_post_hook (void) -{ - if (_dbus_getenv ("DBUS_TEST_SELINUX")) - bus_selinux_shutdown (); - - bus_audit_shutdown (); -} +#include "test/bus/common.h" static DBusTestCase test = { "dispatch", bus_dispatch_test }; int main (int argc, char **argv) { - return _dbus_test_main (argc, argv, 1, &test, - (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | - DBUS_TEST_FLAGS_CHECK_FD_LEAKS | - DBUS_TEST_FLAGS_REQUIRE_DATA), - test_pre_hook, test_post_hook); + return bus_test_main (argc, argv, 1, &test); } diff --git a/test/bus/main.c b/test/bus/main.c index 445e9269..16c0ac20 100644 --- a/test/bus/main.c +++ b/test/bus/main.c @@ -23,32 +23,7 @@ */ #include <config.h> - -#include "bus/test.h" - -#include <dbus/dbus-test-tap.h> - -#include "bus/audit.h" -#include "bus/selinux.h" -#include "test/test-utils.h" - -#ifndef DBUS_ENABLE_EMBEDDED_TESTS -#error This file is only relevant for the embedded tests -#endif - -static void -test_pre_hook (void) -{ -} - -static void -test_post_hook (void) -{ - if (_dbus_getenv ("DBUS_TEST_SELINUX")) - bus_selinux_shutdown (); - - bus_audit_shutdown (); -} +#include "test/bus/common.h" static DBusTestCase tests[] = { @@ -63,9 +38,5 @@ static DBusTestCase tests[] = int main (int argc, char **argv) { - return _dbus_test_main (argc, argv, _DBUS_N_ELEMENTS (tests), tests, - (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | - DBUS_TEST_FLAGS_CHECK_FD_LEAKS | - DBUS_TEST_FLAGS_REQUIRE_DATA), - test_pre_hook, test_post_hook); + return bus_test_main (argc, argv, _DBUS_N_ELEMENTS (tests), tests); } diff --git a/test/meson.build b/test/meson.build index e310e9db..28e4f0bb 100644 --- a/test/meson.build +++ b/test/meson.build @@ -230,20 +230,20 @@ if embedded_tests tests += [ { 'name': 'bus', - 'srcs': [ 'bus/main.c' ], + 'srcs': [ 'bus/main.c', 'bus/common.c' ], 'link': [ libdbus_testutils, libdbus_daemon_internal, ], 'install': false, }, { 'name': 'bus-dispatch-sha1', - 'srcs': [ 'bus/dispatch-sha1.c' ], + 'srcs': [ 'bus/dispatch-sha1.c', 'bus/common.c' ], 'link': [ libdbus_testutils, libdbus_daemon_internal, ], 'install': false, 'suite': ['slow'], }, { 'name': 'bus-dispatch', - 'srcs': [ 'bus/dispatch.c' ], + 'srcs': [ 'bus/dispatch.c', 'bus/common.c' ], 'link': [ libdbus_testutils, libdbus_daemon_internal, ], 'install': false, 'suite': ['slow'], |