]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test/bus: Factor out common setup/teardown code
authorSimon McVittie <smcv@collabora.com>
Fri, 15 Jul 2022 14:27:24 +0000 (15:27 +0100)
committerSimon McVittie <smcv@collabora.com>
Mon, 18 Jul 2022 11:15:54 +0000 (11:15 +0000)
Signed-off-by: Simon McVittie <smcv@collabora.com>
test/CMakeLists.txt
test/Makefile.am
test/bus/common.c [new file with mode: 0644]
test/bus/common.h [new file with mode: 0644]
test/bus/dispatch-sha1.c
test/bus/dispatch.c
test/bus/main.c
test/meson.build

index 864d078bef00bec543b0c91591b6e07ab91a30a5..c08ad95ba9d4b4d9269b9bcd1641d98ba3b40f21 100644 (file)
@@ -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})
 
index 1ee9dd215d1b0d4187f160baafef1287f2156985..18798278aa76bcde176705579da11166777752f4 100644 (file)
@@ -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 (file)
index 0000000..9657385
--- /dev/null
@@ -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 (file)
index 0000000..0f3c87d
--- /dev/null
@@ -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
index a32508bc010488fbe077f6e71d6ad58d128c0101..dc2dcb5dc236a9e7e65ac153e33731fed86626be 100644 (file)
  */
 
 #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);
 }
index ad6718fee11418b5f2b5dbc78d0f8f7e63755678..bd86419fa0eb2cc55949723811868da1d79a37c7 100644 (file)
  */
 
 #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);
 }
index 445e926938d2f7592525fb4ca155af16c576d17d..16c0ac2079015d1a59c76d841a41cef8ccbec642 100644 (file)
  */
 
 #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);
 }
index e310e9db802bb22e7967112daa8784253d61bfbb..28e4f0bb0de83e76f492fbc357486fa064f24fe9 100644 (file)
@@ -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'],