[glib: 8/11] gio/tests: add gdbus-peer test to win32
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 8/11] gio/tests: add gdbus-peer test to win32
- Date: Wed, 18 May 2022 14:01:44 +0000 (UTC)
commit 984103b0e74ef10797834b9a8b2bb367270fc0d0
Author: Marc-André Lureau <marcandre lureau redhat com>
Date: Thu Apr 7 20:03:51 2022 +0400
gio/tests: add gdbus-peer test to win32
Because we can :)
Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>
gio/tests/gdbus-peer.c | 63 ++++++++++++++++++++++++++++++++++++++++++--------
gio/tests/meson.build | 12 +++++-----
2 files changed, 60 insertions(+), 15 deletions(-)
---
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index 8df78af1dc..a2df028e12 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -21,7 +21,6 @@
#include "config.h"
#include <gio/gio.h>
-#include <unistd.h>
#include <string.h>
/* for open(2) */
@@ -43,6 +42,10 @@
#include <errno.h>
#endif
+#ifdef G_OS_WIN32
+#include <gio/giowin32-afunix.h>
+#endif
+
#include "gdbus-tests.h"
#include "gdbus-object-manager-example/objectmanager-gen.h"
@@ -296,10 +299,27 @@ on_proxy_signal_received_with_name_set (GDBusProxy *proxy,
/* ---------------------------------------------------------------------------------------------------- */
+static gboolean
+af_unix_works (void)
+{
+ int fd;
+
+ g_networking_init ();
+ fd = socket (AF_UNIX, SOCK_STREAM, 0);
+
+#ifdef G_OS_WIN32
+ closesocket (fd);
+ return fd != (int) INVALID_SOCKET;
+#else
+ g_close (fd, NULL);
+ return fd >= 0;
+#endif
+}
+
static void
setup_test_address (void)
{
- if (is_unix)
+ if (is_unix || af_unix_works ())
{
g_test_message ("Testing with unix:dir address");
tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
@@ -388,6 +408,13 @@ on_new_connection (GDBusServer *server,
credentials = g_dbus_connection_get_peer_credentials (connection);
g_assert (credentials != NULL);
+#ifdef G_OS_WIN32
+ {
+ DWORD *pid;
+ pid = g_credentials_get_native (credentials, G_CREDENTIALS_TYPE_WIN32_PID);
+ g_assert_cmpuint (*pid, ==, GetCurrentProcessId ());
+ }
+#else
g_assert_cmpuint (g_credentials_get_unix_user (credentials, NULL), ==,
getuid ());
#if G_CREDENTIALS_HAS_PID
@@ -398,9 +425,10 @@ on_new_connection (GDBusServer *server,
g_assert_cmpint (g_credentials_get_unix_pid (credentials, &error), ==, -1);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
g_clear_error (&error);
-#endif
+#endif /* G_CREDENTIALS_HAS_PID */
+#endif /* G_OS_WIN32 */
}
-#endif
+#endif /* G_CREDENTIALS_SUPPORTED */
/* export object on the newly established connection */
reg_id = g_dbus_connection_register_object (connection,
@@ -998,6 +1026,13 @@ do_test_peer (void)
g_assert_no_error (error);
g_assert (G_IS_CREDENTIALS (credentials));
+#ifdef G_OS_WIN32
+ {
+ DWORD *pid;
+ pid = g_credentials_get_native (credentials, G_CREDENTIALS_TYPE_WIN32_PID);
+ g_assert_cmpuint (*pid, ==, GetCurrentProcessId ());
+ }
+#else
g_assert_cmpuint (g_credentials_get_unix_user (credentials, NULL), ==,
getuid ());
#if G_CREDENTIALS_HAS_PID
@@ -1008,12 +1043,13 @@ do_test_peer (void)
g_assert_cmpint (g_credentials_get_unix_pid (credentials, &error), ==, -1);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
g_clear_error (&error);
-#endif
+#endif /* G_CREDENTIALS_HAS_PID */
g_object_unref (credentials);
+#endif /* G_OS_WIN32 */
#else
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
g_assert (credentials == NULL);
-#endif
+#endif /* G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED */
}
@@ -1472,7 +1508,7 @@ dmp_on_new_connection (GDBusServer *server,
* G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING really works
* (GDBusServer uses this feature).
*/
- usleep (100 * 1000);
+ g_usleep (100 * 1000);
/* export an object */
error = NULL;
@@ -1807,17 +1843,26 @@ test_credentials (void)
GCredentials *c1, *c2;
GError *error;
gchar *desc;
+ gboolean same;
c1 = g_credentials_new ();
c2 = g_credentials_new ();
error = NULL;
+#ifdef G_OS_UNIX
if (g_credentials_set_unix_user (c2, getuid (), &error))
g_assert_no_error (error);
+#endif
- g_clear_error (&error);
- g_assert (g_credentials_is_same_user (c1, c2, &error));
+ same = g_credentials_is_same_user (c1, c2, &error);
+#ifdef G_OS_UNIX
+ g_assert (same);
g_assert_no_error (error);
+#else
+ g_assert (!same);
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
+ g_clear_error (&error);
+#endif
desc = g_credentials_to_string (c1);
g_assert (desc != NULL);
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index 7867918f5d..b90c3e5c60 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -81,6 +81,12 @@ gio_tests = {
'g-icon' : {},
'gdbus-addresses' : {},
'gdbus-message' : {},
+ 'gdbus-peer' : {
+ 'dependencies' : [libgdbus_example_objectmanager_dep],
+ 'install_rpath' : installed_tests_execdir,
+ # FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
+ 'should_fail' : host_system == 'darwin',
+ },
'inet-address' : {},
'io-stream' : {},
'memory-input-stream' : {},
@@ -184,12 +190,6 @@ endif
if host_machine.system() != 'windows'
gio_tests += {
'file' : {},
- 'gdbus-peer' : {
- 'dependencies' : [libgdbus_example_objectmanager_dep],
- 'install_rpath' : installed_tests_execdir,
- # FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
- 'should_fail' : host_system == 'darwin',
- },
'gdbus-peer-object-manager' : {},
'live-g-file' : {},
'resolver-parsing' : {'dependencies' : [network_libs]},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]