tests/wayland-test-utils: Add helper to start a client with args

Add a helper function similar to meta_wayland_test_client_new() that
allows to pass command line arguments to the test clients.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4031>
This commit is contained in:
José Expósito 2024-09-08 16:17:16 +02:00 committed by Marge Bot
parent bc8a376b81
commit b4aba293b0
2 changed files with 33 additions and 7 deletions

View File

@ -62,8 +62,9 @@ wayland_test_client_finished (GObject *source_object,
} }
MetaWaylandTestClient * MetaWaylandTestClient *
meta_wayland_test_client_new (MetaContext *context, meta_wayland_test_client_new_with_args (MetaContext *context,
const char *test_client_name) const char *test_client_name,
...)
{ {
MetaWaylandCompositor *compositor; MetaWaylandCompositor *compositor;
const char *wayland_display_name; const char *wayland_display_name;
@ -72,6 +73,9 @@ meta_wayland_test_client_new (MetaContext *context,
GSubprocess *subprocess; GSubprocess *subprocess;
GError *error = NULL; GError *error = NULL;
MetaWaylandTestClient *wayland_test_client; MetaWaylandTestClient *wayland_test_client;
g_autoptr (GPtrArray) args = NULL;
const gchar *arg;
va_list ap;
compositor = meta_context_get_wayland_compositor (context); compositor = meta_context_get_wayland_compositor (context);
wayland_display_name = meta_wayland_get_wayland_display_name (compositor); wayland_display_name = meta_wayland_get_wayland_display_name (compositor);
@ -85,10 +89,19 @@ meta_wayland_test_client_new (MetaContext *context,
"G_MESSAGES_DEBUG", "all", "G_MESSAGES_DEBUG", "all",
TRUE); TRUE);
subprocess = g_subprocess_launcher_spawn (launcher, va_start (ap, test_client_name);
&error, args = g_ptr_array_new ();
test_client_path, g_ptr_array_add (args, (char *) test_client_path);
NULL);
while ((arg = va_arg (ap, const gchar *)))
g_ptr_array_add (args, (gchar *) arg);
g_ptr_array_add (args, NULL);
va_end (ap);
subprocess = g_subprocess_launcher_spawnv (launcher,
(const gchar * const *) args->pdata,
&error);
if (!subprocess) if (!subprocess)
{ {
g_error ("Failed to launch Wayland test client '%s': %s", g_error ("Failed to launch Wayland test client '%s': %s",
@ -106,6 +119,15 @@ meta_wayland_test_client_new (MetaContext *context,
return wayland_test_client; return wayland_test_client;
} }
MetaWaylandTestClient *
meta_wayland_test_client_new (MetaContext *context,
const char *test_client_name)
{
return meta_wayland_test_client_new_with_args (context,
test_client_name,
NULL);
}
static void static void
wayland_test_client_destroy (MetaWaylandTestClient *wayland_test_client) wayland_test_client_destroy (MetaWaylandTestClient *wayland_test_client)
{ {

View File

@ -24,6 +24,10 @@ typedef struct _MetaWaylandTestClient MetaWaylandTestClient;
MetaWaylandTestClient * meta_wayland_test_client_new (MetaContext *context, MetaWaylandTestClient * meta_wayland_test_client_new (MetaContext *context,
const char *test_client_name); const char *test_client_name);
MetaWaylandTestClient * meta_wayland_test_client_new_with_args (MetaContext *context,
const char *test_client_name,
...) G_GNUC_NULL_TERMINATED;
void meta_wayland_test_client_finish (MetaWaylandTestClient *wayland_test_client); void meta_wayland_test_client_finish (MetaWaylandTestClient *wayland_test_client);
MetaWindow * meta_find_client_window (MetaContext *context, MetaWindow * meta_find_client_window (MetaContext *context,