[glib: 5/7] gdbus, tests, win32: test session dbus autolaunch
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 5/7] gdbus, tests, win32: test session dbus autolaunch
- Date: Fri, 15 Mar 2019 10:21:45 +0000 (UTC)
commit b245344cec18447a777f996559e6426436b93c34
Author: Vasily Galkin <galkin-vv ya ru>
Date: Tue Jan 29 23:10:57 2019 +0300
gdbus, tests, win32: test session dbus autolaunch
The test performs implicit autolaunching of a bus
and checks if it is connectible.
In build the test is moved from "only non-windows with have_dbus_daemon"
to "anywhere".
This is intentional: actually it doesn't execute any external
binaries on unix (so doesn't require dbus_daemon)
and now has win32 implementation.
The test has some problems that are not problems of test itself,
but are reasoned by current win32 implementation:
- since the implementation uses global win32 kernel objects
with fixed names not depending on g_get_user_runtime_dir or other context
if preexisting bus running by some other libgio-using application
the test would silently pass.
- since the implementation uses problematic time-based synchronization,
that has a race condition between opening and reading mmaped address,
the test may randomly fail (I'd not seen this in practice).
- since the implementation autolaunched process works for 3 seconds
after last client disconnects, the executed subprocess runs for 3 seconds
after test exit, maybe locking the libgio-2.0-0.dll file for that time.
gio/tests/gdbus-address-get-session.c | 56 ++++++++++++++++++++++++++++++++---
gio/tests/meson.build | 2 +-
2 files changed, 53 insertions(+), 5 deletions(-)
---
diff --git a/gio/tests/gdbus-address-get-session.c b/gio/tests/gdbus-address-get-session.c
index 531ce7a85..72de2c79f 100644
--- a/gio/tests/gdbus-address-get-session.c
+++ b/gio/tests/gdbus-address-get-session.c
@@ -18,9 +18,12 @@
#include <glib.h>
-#ifndef G_OS_UNIX
-#error This is a Unix-specific test
-#endif
+/* This test does NOT depend on any dbus binaries preinstalled on test host.
+ * On Unix it uses mock environment (test_xdg_runtime)
+ * or mock dbus-launch binary (test_x11_autolaunch).
+ * On Windows it relies on the fact that libgio provides
+ * internal session dbus-server on win32.
+ */
#include <errno.h>
@@ -43,6 +46,8 @@ print_address (void)
g_free (addr);
}
+#ifdef G_OS_UNIX
+
static GSocket *mock_bus = NULL;
static gchar *mock_bus_path = NULL;
/* this is deliberately something that needs escaping */
@@ -166,14 +171,57 @@ test_xdg_runtime (void)
g_test_trap_assert_passed ();
}
+#endif
+
+#ifdef G_OS_WIN32
+static void
+check_and_cleanup_autolaunched_win32_bus (void)
+{
+ /* win32 autostarted bus runs infinitely if no client ever connected.
+ * However it exits in several seconds if the last client disconnects.
+ * _This_ test only checks successful launching and connectivity,
+ * and don't bother on bus termination behavior (being it a bug or not).
+ * So connect+disconnect here is not only connectivity test,
+ * but also the workaround the bus process infinite run.
+ */
+ GError *err = NULL;
+ GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &err);
+ g_assert_no_error (err);
+ g_object_unref (bus);
+}
+
+static void
+test_win32_autolaunch (void)
+{
+ if (g_test_subprocess ())
+ {
+ print_address ();
+
+ check_and_cleanup_autolaunched_win32_bus ();
+ return;
+ }
+
+ g_test_trap_subprocess (NULL, 0, 0);
+ /* stderr is not checked: coverage prints warnings there */
+ g_test_trap_assert_stdout ("nonce-tcp:host=localhost,port=*,noncefile=*\\gdbus-nonce-file-*\n");
+ g_test_trap_assert_passed ();
+}
+#endif
+
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
+#ifdef G_OS_UNIX
g_test_add_func ("/gdbus/x11-autolaunch", test_x11_autolaunch);
g_test_add_func ("/gdbus/xdg-runtime", test_xdg_runtime);
+#endif
+
+#ifdef G_OS_WIN32
+ g_test_add_func ("/gdbus/win32-autolaunch", test_win32_autolaunch);
+#endif
- return g_test_run();
+ return g_test_run ();
}
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index 31ed7d167..172c52503 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -78,6 +78,7 @@ gio_tests = {
'tls-certificate' : {'extra_sources' : ['gtesttlsbackend.c']},
'tls-interaction' : {'extra_sources' : ['gtesttlsbackend.c']},
'tls-database' : {'extra_sources' : ['gtesttlsbackend.c']},
+ 'gdbus-address-get-session' : {},
}
test_extra_programs = {
@@ -283,7 +284,6 @@ if host_machine.system() != 'windows'
'-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36'],
},
'gapplication' : {'extra_sources' : extra_sources},
- 'gdbus-address-get-session' : {},
}
if not glib_have_cocoa
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]