]> 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, 28 Oct 2024 13:48:32 +0000 (13:48 +0000)
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 11e6c92e9521ef55ceb0b421c5d077d5793c71d5)

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

index e27e3285c48aa55508d5836c2484a78a0457fcd3..abf31b55ba1b839daa78e33f6d814d07f1a29920 100644 (file)
@@ -145,15 +145,15 @@ if(DBUS_ENABLE_EMBEDDED_TESTS)
     add_test_executable(test-misc-internals "${SOURCES}" dbus-testutils)
     set_target_properties(test-misc-internals PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
 
-    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 878016e6fc5136f1aebaa4d9b5022c8a731eef81..23a6ca13ad3fab75aef6747411e2db3aecebc0d2 100644 (file)
@@ -207,19 +207,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);
 }