[mutter] tests/wayland: Move test client helper into a utils file
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] tests/wayland: Move test client helper into a utils file
- Date: Wed, 9 Feb 2022 10:03:48 +0000 (UTC)
commit b522e3cecdad737394a7554a7da9dc098eaf9d48
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Thu Jan 27 11:51:26 2022 +0100
tests/wayland: Move test client helper into a utils file
This will make it easier to run Wayland test cases from other test
executables.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2262>
src/tests/meson.build | 2 +
src/tests/meta-wayland-test-utils.c | 115 ++++++++++++++++++++++++++++++
src/tests/meta-wayland-test-utils.h | 27 +++++++
src/tests/wayland-unit-tests.c | 138 +++++++-----------------------------
4 files changed, 170 insertions(+), 112 deletions(-)
---
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 5fdc844b5c..67a4bd5ad0 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -287,6 +287,8 @@ if have_native_tests
sources: [
'meta-wayland-test-driver.c',
'meta-wayland-test-driver.h',
+ 'meta-wayland-test-utils.c',
+ 'meta-wayland-test-utils.h',
'wayland-unit-tests.c',
test_driver_server_header,
test_driver_protocol_code,
diff --git a/src/tests/meta-wayland-test-utils.c b/src/tests/meta-wayland-test-utils.c
new file mode 100644
index 0000000000..7bf4a5803f
--- /dev/null
+++ b/src/tests/meta-wayland-test-utils.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2021-2022 Red Hat, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "tests/meta-wayland-test-utils.h"
+
+#include <gio/gio.h>
+
+#include "wayland/meta-wayland.h"
+
+struct _MetaWaylandTestClient
+{
+ GSubprocess *subprocess;
+ char *path;
+ GMainLoop *main_loop;
+};
+
+static char *
+get_test_client_path (const char *test_client_name)
+{
+ return g_test_build_filename (G_TEST_BUILT,
+ "src",
+ "tests",
+ "wayland-test-clients",
+ test_client_name,
+ NULL);
+}
+
+MetaWaylandTestClient *
+meta_wayland_test_client_new (const char *test_client_name)
+{
+ MetaWaylandCompositor *compositor;
+ const char *wayland_display_name;
+ g_autofree char *test_client_path = NULL;
+ g_autoptr (GSubprocessLauncher) launcher = NULL;
+ GSubprocess *subprocess;
+ GError *error = NULL;
+ MetaWaylandTestClient *wayland_test_client;
+
+ compositor = meta_wayland_compositor_get_default ();
+ wayland_display_name = meta_wayland_get_wayland_display_name (compositor);
+ test_client_path = get_test_client_path (test_client_name);
+
+ launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
+ g_subprocess_launcher_setenv (launcher,
+ "WAYLAND_DISPLAY", wayland_display_name,
+ TRUE);
+
+ subprocess = g_subprocess_launcher_spawn (launcher,
+ &error,
+ test_client_path,
+ NULL);
+ if (!subprocess)
+ {
+ g_error ("Failed to launch Wayland test client '%s': %s",
+ test_client_path, error->message);
+ }
+
+ wayland_test_client = g_new0 (MetaWaylandTestClient, 1);
+ wayland_test_client->subprocess = subprocess;
+ wayland_test_client->path = g_strdup (test_client_name);
+ wayland_test_client->main_loop = g_main_loop_new (NULL, FALSE);
+
+ return wayland_test_client;
+}
+
+static void
+wayland_test_client_finished (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ MetaWaylandTestClient *wayland_test_client = user_data;
+ GError *error = NULL;
+
+ if (!g_subprocess_wait_finish (wayland_test_client->subprocess,
+ res,
+ &error))
+ {
+ g_error ("Failed to wait for Wayland test client '%s': %s",
+ wayland_test_client->path, error->message);
+ }
+
+ g_main_loop_quit (wayland_test_client->main_loop);
+}
+
+void
+meta_wayland_test_client_finish (MetaWaylandTestClient *wayland_test_client)
+{
+ g_subprocess_wait_async (wayland_test_client->subprocess, NULL,
+ wayland_test_client_finished, wayland_test_client);
+
+ g_main_loop_run (wayland_test_client->main_loop);
+
+ g_assert_true (g_subprocess_get_successful (wayland_test_client->subprocess));
+
+ g_main_loop_unref (wayland_test_client->main_loop);
+ g_free (wayland_test_client->path);
+ g_object_unref (wayland_test_client->subprocess);
+ g_free (wayland_test_client);
+}
diff --git a/src/tests/meta-wayland-test-utils.h b/src/tests/meta-wayland-test-utils.h
new file mode 100644
index 0000000000..af1fb09a71
--- /dev/null
+++ b/src/tests/meta-wayland-test-utils.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2021-2022 Red Hat, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef META_WAYLAND_TEST_UTILS_H
+#define META_WAYLAND_TEST_UTILS_H
+
+typedef struct _MetaWaylandTestClient MetaWaylandTestClient;
+
+MetaWaylandTestClient * meta_wayland_test_client_new (const char *test_client_name);
+
+void meta_wayland_test_client_finish (MetaWaylandTestClient *wayland_test_client);
+
+#endif /* META_WAYLAND_TEST_UTILS_H */
diff --git a/src/tests/wayland-unit-tests.c b/src/tests/wayland-unit-tests.c
index 1202d2fcf0..f7e201e04e 100644
--- a/src/tests/wayland-unit-tests.c
+++ b/src/tests/wayland-unit-tests.c
@@ -25,105 +25,14 @@
#include "core/window-private.h"
#include "meta-test/meta-context-test.h"
#include "tests/meta-wayland-test-driver.h"
-#include "wayland/meta-wayland.h"
+#include "tests/meta-wayland-test-utils.h"
#include "wayland/meta-wayland-surface.h"
-typedef struct _WaylandTestClient
-{
- GSubprocess *subprocess;
- char *path;
- GMainLoop *main_loop;
-} WaylandTestClient;
-
static MetaContext *test_context;
static MetaWaylandTestDriver *test_driver;
static MetaVirtualMonitor *virtual_monitor;
static ClutterVirtualInputDevice *virtual_pointer;
-static char *
-get_test_client_path (const char *test_client_name)
-{
- return g_test_build_filename (G_TEST_BUILT,
- "src",
- "tests",
- "wayland-test-clients",
- test_client_name,
- NULL);
-}
-
-static WaylandTestClient *
-wayland_test_client_new (const char *test_client_name)
-{
- MetaWaylandCompositor *compositor;
- const char *wayland_display_name;
- g_autofree char *test_client_path = NULL;
- g_autoptr (GSubprocessLauncher) launcher = NULL;
- GSubprocess *subprocess;
- GError *error = NULL;
- WaylandTestClient *wayland_test_client;
-
- compositor = meta_wayland_compositor_get_default ();
- wayland_display_name = meta_wayland_get_wayland_display_name (compositor);
- test_client_path = get_test_client_path (test_client_name);
-
- launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
- g_subprocess_launcher_setenv (launcher,
- "WAYLAND_DISPLAY", wayland_display_name,
- TRUE);
-
- subprocess = g_subprocess_launcher_spawn (launcher,
- &error,
- test_client_path,
- NULL);
- if (!subprocess)
- {
- g_error ("Failed to launch Wayland test client '%s': %s",
- test_client_path, error->message);
- }
-
- wayland_test_client = g_new0 (WaylandTestClient, 1);
- wayland_test_client->subprocess = subprocess;
- wayland_test_client->path = g_strdup (test_client_name);
- wayland_test_client->main_loop = g_main_loop_new (NULL, FALSE);
-
- return wayland_test_client;
-}
-
-static void
-wayland_test_client_finished (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- WaylandTestClient *wayland_test_client = user_data;
- GError *error = NULL;
-
- if (!g_subprocess_wait_finish (wayland_test_client->subprocess,
- res,
- &error))
- {
- g_error ("Failed to wait for Wayland test client '%s': %s",
- wayland_test_client->path, error->message);
- }
-
- g_main_loop_quit (wayland_test_client->main_loop);
-}
-
-static void
-wayland_test_client_finish (WaylandTestClient *wayland_test_client)
-{
- g_subprocess_wait_async (wayland_test_client->subprocess, NULL,
- wayland_test_client_finished, wayland_test_client);
-
- g_main_loop_run (wayland_test_client->main_loop);
-
- g_assert_true (g_subprocess_get_successful (wayland_test_client->subprocess));
-
- g_main_loop_unref (wayland_test_client->main_loop);
- g_free (wayland_test_client->path);
- g_object_unref (wayland_test_client->subprocess);
- g_free (wayland_test_client);
-}
-
static MetaWindow *
find_client_window (const char *title)
{
@@ -146,44 +55,48 @@ find_client_window (const char *title)
static void
subsurface_remap_toplevel (void)
{
- WaylandTestClient *wayland_test_client;
+ MetaWaylandTestClient *wayland_test_client;
- wayland_test_client = wayland_test_client_new ("subsurface-remap-toplevel");
- wayland_test_client_finish (wayland_test_client);
+ wayland_test_client =
+ meta_wayland_test_client_new ("subsurface-remap-toplevel");
+ meta_wayland_test_client_finish (wayland_test_client);
}
static void
subsurface_reparenting (void)
{
- WaylandTestClient *wayland_test_client;
+ MetaWaylandTestClient *wayland_test_client;
- wayland_test_client = wayland_test_client_new ("subsurface-reparenting");
- wayland_test_client_finish (wayland_test_client);
+ wayland_test_client =
+ meta_wayland_test_client_new ("subsurface-reparenting");
+ meta_wayland_test_client_finish (wayland_test_client);
}
static void
subsurface_invalid_subsurfaces (void)
{
- WaylandTestClient *wayland_test_client;
+ MetaWaylandTestClient *wayland_test_client;
- wayland_test_client = wayland_test_client_new ("invalid-subsurfaces");
+ wayland_test_client =
+ meta_wayland_test_client_new ("invalid-subsurfaces");
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"WL: error in client communication*");
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"WL: error in client communication*");
- wayland_test_client_finish (wayland_test_client);
+ meta_wayland_test_client_finish (wayland_test_client);
g_test_assert_expected_messages ();
}
static void
subsurface_invalid_xdg_shell_actions (void)
{
- WaylandTestClient *wayland_test_client;
+ MetaWaylandTestClient *wayland_test_client;
- wayland_test_client = wayland_test_client_new ("invalid-xdg-shell-actions");
+ wayland_test_client =
+ meta_wayland_test_client_new ("invalid-xdg-shell-actions");
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"Invalid geometry * set on xdg_surface*");
- wayland_test_client_finish (wayland_test_client);
+ meta_wayland_test_client_finish (wayland_test_client);
g_test_assert_expected_messages ();
}
@@ -341,7 +254,7 @@ subsurface_parent_unmapped (void)
{
MetaBackend *backend = meta_context_get_backend (test_context);
MetaDisplay *display = meta_context_get_display (test_context);
- WaylandTestClient *wayland_test_client;
+ MetaWaylandTestClient *wayland_test_client;
ClutterSeat *seat;
gulong window_added_id;
gulong sync_point_id;
@@ -350,7 +263,8 @@ subsurface_parent_unmapped (void)
virtual_pointer = clutter_seat_create_virtual_device (seat,
CLUTTER_POINTER_DEVICE);
- wayland_test_client = wayland_test_client_new ("subsurface-parent-unmapped");
+ wayland_test_client =
+ meta_wayland_test_client_new ("subsurface-parent-unmapped");
window_added_id =
g_signal_connect (display->stack, "window-added",
@@ -361,7 +275,7 @@ subsurface_parent_unmapped (void)
G_CALLBACK (on_unmap_sync_point),
NULL);
- wayland_test_client_finish (wayland_test_client);
+ meta_wayland_test_client_finish (wayland_test_client);
g_clear_object (&virtual_pointer);
g_signal_handler_disconnect (test_driver, sync_point_id);
@@ -378,7 +292,7 @@ typedef enum _ApplyLimitState
typedef struct _ApplyLimitData
{
GMainLoop *loop;
- WaylandTestClient *wayland_test_client;
+ MetaWaylandTestClient *wayland_test_client;
ApplyLimitState state;
} ApplyLimitData;
@@ -427,12 +341,12 @@ toplevel_apply_limits (void)
gulong handler_id;
data.loop = g_main_loop_new (NULL, FALSE);
- data.wayland_test_client = wayland_test_client_new ("xdg-apply-limits");
+ data.wayland_test_client = meta_wayland_test_client_new ("xdg-apply-limits");
handler_id = g_signal_connect (test_driver, "sync-point",
G_CALLBACK (on_sync_point), &data);
g_main_loop_run (data.loop);
g_assert_cmpint (data.state, ==, APPLY_LIMIT_STATE_FINISH);
- wayland_test_client_finish (data.wayland_test_client);
+ meta_wayland_test_client_finish (data.wayland_test_client);
g_test_assert_expected_messages ();
g_signal_handler_disconnect (test_driver, handler_id);
}
@@ -443,8 +357,8 @@ toplevel_activation (void)
ApplyLimitData data = {};
data.loop = g_main_loop_new (NULL, FALSE);
- data.wayland_test_client = wayland_test_client_new ("xdg-activation");
- wayland_test_client_finish (data.wayland_test_client);
+ data.wayland_test_client = meta_wayland_test_client_new ("xdg-activation");
+ meta_wayland_test_client_finish (data.wayland_test_client);
g_test_assert_expected_messages ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]