tests/utils: Prefix TestClient with Meta

Soon we'll expose it via a libmutter-test library.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-05-06 23:34:36 +02:00
parent f74d311d61
commit 4a6e22311a
4 changed files with 249 additions and 206 deletions

View File

@ -31,7 +31,8 @@
#include "wayland/meta-xwayland.h" #include "wayland/meta-xwayland.h"
#include "x11/meta-x11-display-private.h" #include "x11/meta-x11-display-private.h"
struct _TestClient { struct _MetaTestClient
{
char *id; char *id;
MetaWindowClientType type; MetaWindowClientType type;
GSubprocess *subprocess; GSubprocess *subprocess;
@ -55,7 +56,7 @@ struct _AsyncWaiter {
int counter_wait_value; int counter_wait_value;
}; };
G_DEFINE_QUARK (test-runner-error-quark, test_runner_error) G_DEFINE_QUARK (meta-test-client-error-quark, meta_test_client_error)
static char *test_client_path; static char *test_client_path;
@ -205,7 +206,7 @@ async_waiter_alarm_filter (MetaX11Display *x11_display,
} }
char * char *
test_client_get_id (TestClient *client) meta_test_client_get_id (MetaTestClient *client)
{ {
return client->id; return client->id;
} }
@ -213,9 +214,9 @@ test_client_get_id (TestClient *client)
static void static void
test_client_line_read (GObject *source, test_client_line_read (GObject *source,
GAsyncResult *result, GAsyncResult *result,
gpointer data) gpointer user_data)
{ {
TestClient *client = data; MetaTestClient *client = user_data;
client->line = g_data_input_stream_read_line_finish_utf8 (client->out, client->line = g_data_input_stream_read_line_finish_utf8 (client->out,
result, result,
@ -225,9 +226,9 @@ test_client_line_read (GObject *source,
} }
gboolean gboolean
test_client_do (TestClient *client, meta_test_client_do (MetaTestClient *client,
GError **error, GError **error,
...) ...)
{ {
GString *command = g_string_new (NULL); GString *command = g_string_new (NULL);
char *line = NULL; char *line = NULL;
@ -274,14 +275,20 @@ test_client_do (TestClient *client,
if (!line) if (!line)
{ {
if (*error == NULL) if (*error == NULL)
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_RUNTIME_ERROR, {
"test client exited"); g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_RUNTIME_ERROR,
"test client exited");
}
goto out; goto out;
} }
if (strcmp (line, "OK") != 0) if (strcmp (line, "OK") != 0)
{ {
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_RUNTIME_ERROR, g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_RUNTIME_ERROR,
"%s", line); "%s", line);
goto out; goto out;
} }
@ -294,12 +301,12 @@ test_client_do (TestClient *client,
} }
gboolean gboolean
test_client_wait (TestClient *client, meta_test_client_wait (MetaTestClient *client,
GError **error) GError **error)
{ {
if (client->type == META_WINDOW_CLIENT_TYPE_WAYLAND) if (client->type == META_WINDOW_CLIENT_TYPE_WAYLAND)
{ {
return test_client_do (client, error, "sync", NULL); return meta_test_client_do (client, error, "sync", NULL);
} }
else else
{ {
@ -308,9 +315,9 @@ test_client_wait (TestClient *client,
char *wait_value_str = g_strdup_printf ("%d", wait_value); char *wait_value_str = g_strdup_printf ("%d", wait_value);
gboolean success; gboolean success;
success = test_client_do (client, error, success = meta_test_client_do (client, error,
"set_counter", counter_str, wait_value_str, "set_counter", counter_str, wait_value_str,
NULL); NULL);
g_free (counter_str); g_free (counter_str);
g_free (wait_value_str); g_free (wait_value_str);
if (!success) if (!success)
@ -322,9 +329,9 @@ test_client_wait (TestClient *client,
} }
MetaWindow * MetaWindow *
test_client_find_window (TestClient *client, meta_test_client_find_window (MetaTestClient *client,
const char *window_id, const char *window_id,
GError **error) GError **error)
{ {
MetaDisplay *display = meta_get_display (); MetaDisplay *display = meta_get_display ();
GSList *windows; GSList *windows;
@ -354,8 +361,12 @@ test_client_find_window (TestClient *client,
g_free (expected_title); g_free (expected_title);
if (result == NULL) if (result == NULL)
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_RUNTIME_ERROR, {
"window %s/%s isn't known to Mutter", client->id, window_id); g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_RUNTIME_ERROR,
"window %s/%s isn't known to Mutter", client->id, window_id);
}
return result; return result;
} }
@ -394,8 +405,8 @@ wait_for_showing_before_redraw (gpointer user_data)
} }
void void
test_client_wait_for_window_shown (TestClient *client, meta_test_client_wait_for_window_shown (MetaTestClient *client,
MetaWindow *window) MetaWindow *window)
{ {
WaitForShownData data = { WaitForShownData data = {
.loop = g_main_loop_new (NULL, FALSE), .loop = g_main_loop_new (NULL, FALSE),
@ -411,12 +422,10 @@ test_client_wait_for_window_shown (TestClient *client,
} }
gboolean gboolean
test_client_alarm_filter (MetaX11Display *x11_display, meta_test_client_process_x11_event (MetaTestClient *client,
XSyncAlarmNotifyEvent *event, MetaX11Display *x11_display,
gpointer data) XSyncAlarmNotifyEvent *event)
{ {
TestClient *client = data;
if (client->waiter) if (client->waiter)
return async_waiter_alarm_filter (x11_display, event, client->waiter); return async_waiter_alarm_filter (x11_display, event, client->waiter);
else else
@ -435,12 +444,12 @@ spawn_xwayland (gpointer user_data)
return NULL; return NULL;
} }
TestClient * MetaTestClient *
test_client_new (const char *id, meta_test_client_new (const char *id,
MetaWindowClientType type, MetaWindowClientType type,
GError **error) GError **error)
{ {
TestClient *client; MetaTestClient *client;
GSubprocessLauncher *launcher; GSubprocessLauncher *launcher;
GSubprocess *subprocess; GSubprocess *subprocess;
MetaWaylandCompositor *compositor; MetaWaylandCompositor *compositor;
@ -475,7 +484,7 @@ test_client_new (const char *id,
if (!subprocess) if (!subprocess)
return NULL; return NULL;
client = g_new0 (TestClient, 1); client = g_new0 (MetaTestClient, 1);
client->type = type; client->type = type;
client->id = g_strdup (id); client->id = g_strdup (id);
client->cancellable = g_cancellable_new (); client->cancellable = g_cancellable_new ();
@ -508,20 +517,20 @@ test_client_new (const char *id,
} }
gboolean gboolean
test_client_quit (TestClient *client, meta_test_client_quit (MetaTestClient *client,
GError **error) GError **error)
{ {
if (!test_client_do (client, error, "destroy_all", NULL)) if (!meta_test_client_do (client, error, "destroy_all", NULL))
return FALSE; return FALSE;
if (!test_client_wait (client, error)) if (!meta_test_client_wait (client, error))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
void void
test_client_destroy (TestClient *client) meta_test_client_destroy (MetaTestClient *client)
{ {
GError *error = NULL; GError *error = NULL;

View File

@ -26,19 +26,19 @@
#include "meta/window.h" #include "meta/window.h"
#define TEST_RUNNER_ERROR test_runner_error_quark () #define META_TEST_CLIENT_ERROR meta_test_client_error_quark ()
typedef enum typedef enum _MetaClientError
{ {
TEST_RUNNER_ERROR_BAD_COMMAND, META_TEST_CLIENT_ERROR_BAD_COMMAND,
TEST_RUNNER_ERROR_RUNTIME_ERROR, META_TEST_CLIENT_ERROR_RUNTIME_ERROR,
TEST_RUNNER_ERROR_ASSERTION_FAILED META_TEST_CLIENT_ERROR_ASSERTION_FAILED
} TestRunnerError; } MetaClientError;
GQuark test_runner_error_quark (void); GQuark meta_test_client_error_quark (void);
typedef struct _AsyncWaiter AsyncWaiter; typedef struct _AsyncWaiter AsyncWaiter;
typedef struct _TestClient TestClient; typedef struct _MetaTestClient MetaTestClient;
void test_init (int *argc, void test_init (int *argc,
char ***argv); char ***argv);
@ -53,34 +53,34 @@ AsyncWaiter * async_waiter_new (void);
void async_waiter_destroy (AsyncWaiter *waiter); void async_waiter_destroy (AsyncWaiter *waiter);
char * test_client_get_id (TestClient *client); char * meta_test_client_get_id (MetaTestClient *client);
gboolean test_client_alarm_filter (MetaX11Display *x11_display, gboolean meta_test_client_process_x11_event (MetaTestClient *client,
XSyncAlarmNotifyEvent *event, MetaX11Display *x11_display,
gpointer data); XSyncAlarmNotifyEvent *event);
gboolean test_client_wait (TestClient *client, gboolean meta_test_client_wait (MetaTestClient *client,
GError **error); GError **error);
gboolean test_client_do (TestClient *client, gboolean meta_test_client_do (MetaTestClient *client,
GError **error, GError **error,
...) G_GNUC_NULL_TERMINATED; ...) G_GNUC_NULL_TERMINATED;
MetaWindow * test_client_find_window (TestClient *client, MetaWindow * meta_test_client_find_window (MetaTestClient *client,
const char *window_id, const char *window_id,
GError **error); GError **error);
void test_client_wait_for_window_shown (TestClient *client, void meta_test_client_wait_for_window_shown (MetaTestClient *client,
MetaWindow *window); MetaWindow *window);
gboolean test_client_quit (TestClient *client, gboolean meta_test_client_quit (MetaTestClient *client,
GError **error); GError **error);
TestClient * test_client_new (const char *id, MetaTestClient * meta_test_client_new (const char *id,
MetaWindowClientType type, MetaWindowClientType type,
GError **error); GError **error);
void test_client_destroy (TestClient *client); void meta_test_client_destroy (MetaTestClient *client);
const char * test_get_plugin_name (void); const char * test_get_plugin_name (void);
@ -89,4 +89,4 @@ void test_wait_for_x11_display (void);
void meta_ensure_test_client_path (int argc, void meta_ensure_test_client_path (int argc,
char **argv); char **argv);
#endif /* META_TEST_UTILS_H */ #endif /* TEST_UTILS_H */

View File

@ -157,8 +157,8 @@ static MonitorTestCase initial_test_case = {
} }
}; };
static TestClient *wayland_monitor_test_client = NULL; static MetaTestClient *wayland_monitor_test_client = NULL;
static TestClient *x11_monitor_test_client = NULL; static MetaTestClient *x11_monitor_test_client = NULL;
#define WAYLAND_TEST_CLIENT_NAME "wayland_monitor_test_client" #define WAYLAND_TEST_CLIENT_NAME "wayland_monitor_test_client"
#define WAYLAND_TEST_CLIENT_WINDOW "window1" #define WAYLAND_TEST_CLIENT_WINDOW "window1"
@ -170,7 +170,8 @@ monitor_tests_alarm_filter (MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event, XSyncAlarmNotifyEvent *event,
gpointer data) gpointer data)
{ {
return test_client_alarm_filter (x11_display, event, x11_monitor_test_client); return meta_test_client_process_x11_event (x11_monitor_test_client,
x11_display, event);
} }
static void static void
@ -178,51 +179,51 @@ create_monitor_test_clients (void)
{ {
GError *error = NULL; GError *error = NULL;
wayland_monitor_test_client = test_client_new (WAYLAND_TEST_CLIENT_NAME, wayland_monitor_test_client = meta_test_client_new (WAYLAND_TEST_CLIENT_NAME,
META_WINDOW_CLIENT_TYPE_WAYLAND, META_WINDOW_CLIENT_TYPE_WAYLAND,
&error); &error);
if (!wayland_monitor_test_client) if (!wayland_monitor_test_client)
g_error ("Failed to launch Wayland test client: %s", error->message); g_error ("Failed to launch Wayland test client: %s", error->message);
x11_monitor_test_client = test_client_new (X11_TEST_CLIENT_NAME, x11_monitor_test_client = meta_test_client_new (X11_TEST_CLIENT_NAME,
META_WINDOW_CLIENT_TYPE_X11, META_WINDOW_CLIENT_TYPE_X11,
&error); &error);
if (!x11_monitor_test_client) if (!x11_monitor_test_client)
g_error ("Failed to launch X11 test client: %s", error->message); g_error ("Failed to launch X11 test client: %s", error->message);
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display, meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
monitor_tests_alarm_filter, NULL); monitor_tests_alarm_filter, NULL);
if (!test_client_do (wayland_monitor_test_client, &error, if (!meta_test_client_do (wayland_monitor_test_client, &error,
"create", WAYLAND_TEST_CLIENT_WINDOW, "create", WAYLAND_TEST_CLIENT_WINDOW,
NULL)) NULL))
g_error ("Failed to create Wayland window: %s", error->message); g_error ("Failed to create Wayland window: %s", error->message);
if (!test_client_do (x11_monitor_test_client, &error, if (!meta_test_client_do (x11_monitor_test_client, &error,
"create", X11_TEST_CLIENT_WINDOW, "create", X11_TEST_CLIENT_WINDOW,
NULL)) NULL))
g_error ("Failed to create X11 window: %s", error->message); g_error ("Failed to create X11 window: %s", error->message);
if (!test_client_do (wayland_monitor_test_client, &error, if (!meta_test_client_do (wayland_monitor_test_client, &error,
"show", WAYLAND_TEST_CLIENT_WINDOW, "show", WAYLAND_TEST_CLIENT_WINDOW,
NULL)) NULL))
g_error ("Failed to show the window: %s", error->message); g_error ("Failed to show the window: %s", error->message);
if (!test_client_do (x11_monitor_test_client, &error, if (!meta_test_client_do (x11_monitor_test_client, &error,
"show", X11_TEST_CLIENT_WINDOW, "show", X11_TEST_CLIENT_WINDOW,
NULL)) NULL))
g_error ("Failed to show the window: %s", error->message); g_error ("Failed to show the window: %s", error->message);
} }
static void static void
check_test_client_state (TestClient *test_client) check_test_client_state (MetaTestClient *test_client)
{ {
GError *error = NULL; GError *error = NULL;
if (!test_client_wait (test_client, &error)) if (!meta_test_client_wait (test_client, &error))
{ {
g_error ("Failed to sync test client '%s': %s", g_error ("Failed to sync test client '%s': %s",
test_client_get_id (test_client), error->message); meta_test_client_get_id (test_client), error->message);
} }
} }
@ -238,14 +239,14 @@ destroy_monitor_test_clients (void)
{ {
GError *error = NULL; GError *error = NULL;
if (!test_client_quit (wayland_monitor_test_client, &error)) if (!meta_test_client_quit (wayland_monitor_test_client, &error))
g_error ("Failed to quit Wayland test client: %s", error->message); g_error ("Failed to quit Wayland test client: %s", error->message);
if (!test_client_quit (x11_monitor_test_client, &error)) if (!meta_test_client_quit (x11_monitor_test_client, &error))
g_error ("Failed to quit X11 test client: %s", error->message); g_error ("Failed to quit X11 test client: %s", error->message);
test_client_destroy (wayland_monitor_test_client); meta_test_client_destroy (wayland_monitor_test_client);
test_client_destroy (x11_monitor_test_client); meta_test_client_destroy (x11_monitor_test_client);
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display, meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
NULL, NULL); NULL, NULL);
@ -2260,16 +2261,16 @@ meta_test_monitor_no_outputs (void)
check_monitor_configuration (&test_case.expect); check_monitor_configuration (&test_case.expect);
check_monitor_test_clients_state (); check_monitor_test_clients_state ();
if (!test_client_do (x11_monitor_test_client, &error, if (!meta_test_client_do (x11_monitor_test_client, &error,
"resize", X11_TEST_CLIENT_WINDOW, "resize", X11_TEST_CLIENT_WINDOW,
"123", "210", "123", "210",
NULL)) NULL))
g_error ("Failed to resize X11 window: %s", error->message); g_error ("Failed to resize X11 window: %s", error->message);
if (!test_client_do (wayland_monitor_test_client, &error, if (!meta_test_client_do (wayland_monitor_test_client, &error,
"resize", WAYLAND_TEST_CLIENT_WINDOW, "resize", WAYLAND_TEST_CLIENT_WINDOW,
"123", "210", "123", "210",
NULL)) NULL))
g_error ("Failed to resize Wayland window: %s", error->message); g_error ("Failed to resize Wayland window: %s", error->message);
check_monitor_test_clients_state (); check_monitor_test_clients_state ();
@ -5480,23 +5481,23 @@ dispatch (void)
g_main_loop_run (loop); g_main_loop_run (loop);
} }
static TestClient * static MetaTestClient *
create_test_window (const char *window_name) create_test_window (const char *window_name)
{ {
TestClient *test_client; MetaTestClient *test_client;
static int client_count = 0; static int client_count = 0;
g_autofree char *client_name = NULL; g_autofree char *client_name = NULL;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
client_name = g_strdup_printf ("test_client_%d", client_count++); client_name = g_strdup_printf ("test_client_%d", client_count++);
test_client = test_client_new (client_name, META_WINDOW_CLIENT_TYPE_WAYLAND, test_client = meta_test_client_new (client_name, META_WINDOW_CLIENT_TYPE_WAYLAND,
&error); &error);
if (!test_client) if (!test_client)
g_error ("Failed to launch test client: %s", error->message); g_error ("Failed to launch test client: %s", error->message);
if (!test_client_do (test_client, &error, if (!meta_test_client_do (test_client, &error,
"create", window_name, "create", window_name,
NULL)) NULL))
g_error ("Failed to create window: %s", error->message); g_error ("Failed to create window: %s", error->message);
return test_client; return test_client;
@ -5508,6 +5509,7 @@ meta_test_monitor_wm_tiling (void)
MonitorTestCase test_case = initial_test_case; MonitorTestCase test_case = initial_test_case;
MetaMonitorTestSetup *test_setup; MetaMonitorTestSetup *test_setup;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
MetaTestClient *test_client;
test_setup = create_monitor_test_setup (&test_case.setup, test_setup = create_monitor_test_setup (&test_case.setup,
MONITOR_TEST_FLAG_NO_STORED); MONITOR_TEST_FLAG_NO_STORED);
@ -5521,20 +5523,20 @@ meta_test_monitor_wm_tiling (void)
*/ */
const char *test_window_name= "window1"; const char *test_window_name= "window1";
TestClient *test_client = create_test_window (test_window_name); test_client = create_test_window (test_window_name);
if (!test_client_do (test_client, &error, if (!meta_test_client_do (test_client, &error,
"show", test_window_name, "show", test_window_name,
NULL)) NULL))
g_error ("Failed to show the window: %s", error->message); g_error ("Failed to show the window: %s", error->message);
MetaWindow *test_window = MetaWindow *test_window =
test_client_find_window (test_client, meta_test_client_find_window (test_client,
test_window_name, test_window_name,
&error); &error);
if (!test_window) if (!test_window)
g_error ("Failed to find the window: %s", error->message); g_error ("Failed to find the window: %s", error->message);
test_client_wait_for_window_shown (test_client, test_window); meta_test_client_wait_for_window_shown (test_client, test_window);
meta_window_tile (test_window, META_TILE_MAXIMIZED); meta_window_tile (test_window, META_TILE_MAXIMIZED);
meta_window_move_to_monitor (test_window, 1); meta_window_move_to_monitor (test_window, 1);
@ -5574,7 +5576,7 @@ meta_test_monitor_wm_tiling (void)
meta_window_tile (test_window, META_TILE_MAXIMIZED); meta_window_tile (test_window, META_TILE_MAXIMIZED);
test_client_destroy (test_client); meta_test_client_destroy (test_client);
} }
static void static void

View File

@ -55,8 +55,12 @@ test_case_alarm_filter (MetaX11Display *x11_display,
g_hash_table_iter_init (&iter, test->clients); g_hash_table_iter_init (&iter, test->clients);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
if (test_client_alarm_filter (x11_display, event, value)) {
return TRUE; MetaTestClient *client = value;
if (meta_test_client_process_x11_event (client, x11_display, event))
return TRUE;
}
return FALSE; return FALSE;
} }
@ -139,7 +143,7 @@ test_case_wait (TestCase *test,
*/ */
g_hash_table_iter_init (&iter, test->clients); g_hash_table_iter_init (&iter, test->clients);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
if (!test_client_wait (value, error)) if (!meta_test_client_wait (value, error))
return FALSE; return FALSE;
/* Then wait until we've done any outstanding queued up work. */ /* Then wait until we've done any outstanding queued up work. */
@ -168,30 +172,35 @@ test_case_sleep (TestCase *test,
#define BAD_COMMAND(...) \ #define BAD_COMMAND(...) \
G_STMT_START { \ G_STMT_START { \
g_set_error (error, \ g_set_error (error, \
TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_BAD_COMMAND, \ META_TEST_CLIENT_ERROR, \
META_TEST_CLIENT_ERROR_BAD_COMMAND, \
__VA_ARGS__); \ __VA_ARGS__); \
return FALSE; \ return FALSE; \
} G_STMT_END } G_STMT_END
static TestClient * static MetaTestClient *
test_case_lookup_client (TestCase *test, test_case_lookup_client (TestCase *test,
char *client_id, char *client_id,
GError **error) GError **error)
{ {
TestClient *client = g_hash_table_lookup (test->clients, client_id); MetaTestClient *client = g_hash_table_lookup (test->clients, client_id);
if (!client) if (!client)
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_BAD_COMMAND, {
"No such client %s", client_id); g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_BAD_COMMAND,
"No such client %s", client_id);
}
return client; return client;
} }
static gboolean static gboolean
test_case_parse_window_id (TestCase *test, test_case_parse_window_id (TestCase *test,
const char *client_and_window_id, const char *client_and_window_id,
TestClient **client, MetaTestClient **client,
const char **window_id, const char **window_id,
GError **error) GError **error)
{ {
const char *slash = strchr (client_and_window_id, '/'); const char *slash = strchr (client_and_window_id, '/');
char *tmp; char *tmp;
@ -270,7 +279,9 @@ test_case_assert_stacking (TestCase *test,
if (strcmp (expected_string->str, stack_string->str) != 0) if (strcmp (expected_string->str, stack_string->str) != 0)
{ {
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED, g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"stacking: expected='%s', actual='%s'", "stacking: expected='%s', actual='%s'",
expected_string->str, stack_string->str); expected_string->str, stack_string->str);
} }
@ -292,7 +303,9 @@ test_case_assert_focused (TestCase *test,
{ {
if (g_strcmp0 (expected_window, "none") != 0) if (g_strcmp0 (expected_window, "none") != 0)
{ {
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED, g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"focus: expected='%s', actual='none'", expected_window); "focus: expected='%s', actual='none'", expected_window);
} }
} }
@ -304,7 +317,9 @@ test_case_assert_focused (TestCase *test,
focused += 5; focused += 5;
if (g_strcmp0 (focused, expected_window) != 0) if (g_strcmp0 (focused, expected_window) != 0)
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED, g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"focus: expected='%s', actual='%s'", "focus: expected='%s', actual='%s'",
expected_window, focused); expected_window, focused);
} }
@ -326,7 +341,9 @@ test_case_assert_size (TestCase *test,
if (frame_rect.width != expected_width || if (frame_rect.width != expected_width ||
frame_rect.height != expected_height) frame_rect.height != expected_height)
{ {
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED, g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"Expected size %dx%d didn't match actual size %dx%d", "Expected size %dx%d didn't match actual size %dx%d",
expected_width, expected_height, expected_width, expected_height,
frame_rect.width, frame_rect.height); frame_rect.width, frame_rect.height);
@ -380,7 +397,9 @@ test_case_check_xserver_stacking (TestCase *test,
} }
if (strcmp (x11_string->str, local_string->str) != 0) if (strcmp (x11_string->str, local_string->str) != 0)
g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED, g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"xserver stacking: x11='%s', local='%s'", "xserver stacking: x11='%s', local='%s'",
x11_string->str, local_string->str); x11_string->str, local_string->str);
@ -451,7 +470,7 @@ test_case_do (TestCase *test,
if (strcmp (argv[0], "new_client") == 0) if (strcmp (argv[0], "new_client") == 0)
{ {
MetaWindowClientType type; MetaWindowClientType type;
TestClient *client; MetaTestClient *client;
if (argc != 3) if (argc != 3)
BAD_COMMAND("usage: new_client <client-id> [wayland|x11]"); BAD_COMMAND("usage: new_client <client-id> [wayland|x11]");
@ -466,26 +485,26 @@ test_case_do (TestCase *test,
if (g_hash_table_lookup (test->clients, argv[1])) if (g_hash_table_lookup (test->clients, argv[1]))
BAD_COMMAND("client %s already exists", argv[1]); BAD_COMMAND("client %s already exists", argv[1]);
client = test_client_new (argv[1], type, error); client = meta_test_client_new (argv[1], type, error);
if (!client) if (!client)
return FALSE; return FALSE;
g_hash_table_insert (test->clients, test_client_get_id (client), client); g_hash_table_insert (test->clients, meta_test_client_get_id (client), client);
} }
else if (strcmp (argv[0], "quit_client") == 0) else if (strcmp (argv[0], "quit_client") == 0)
{ {
if (argc != 2) if (argc != 2)
BAD_COMMAND("usage: quit_client <client-id>"); BAD_COMMAND("usage: quit_client <client-id>");
TestClient *client = test_case_lookup_client (test, argv[1], error); MetaTestClient *client = test_case_lookup_client (test, argv[1], error);
if (!client) if (!client)
return FALSE; return FALSE;
if (!test_client_quit (client, error)) if (!meta_test_client_quit (client, error))
return FALSE; return FALSE;
g_hash_table_remove (test->clients, test_client_get_id (client)); g_hash_table_remove (test->clients, meta_test_client_get_id (client));
test_client_destroy (client); meta_test_client_destroy (client);
} }
else if (strcmp (argv[0], "create") == 0) else if (strcmp (argv[0], "create") == 0)
{ {
@ -494,18 +513,18 @@ test_case_do (TestCase *test,
(argc == 3 && strcmp (argv[2], "csd") == 0))) (argc == 3 && strcmp (argv[2], "csd") == 0)))
BAD_COMMAND("usage: %s <client-id>/<window-id > [override|csd]", argv[0]); BAD_COMMAND("usage: %s <client-id>/<window-id > [override|csd]", argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, if (!meta_test_client_do (client, error,
"create", window_id, "create", window_id,
argc == 3 ? argv[2] : NULL, argc == 3 ? argv[2] : NULL,
NULL)) NULL))
return FALSE; return FALSE;
if (!test_client_wait (client, error)) if (!meta_test_client_wait (client, error))
return FALSE; return FALSE;
} }
else if (strcmp (argv[0], "set_parent") == 0 || else if (strcmp (argv[0], "set_parent") == 0 ||
@ -515,15 +534,15 @@ test_case_do (TestCase *test,
BAD_COMMAND("usage: %s <client-id>/<window-id> <parent-window-id>", BAD_COMMAND("usage: %s <client-id>/<window-id> <parent-window-id>",
argv[0]); argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, if (!meta_test_client_do (client, error,
argv[0], window_id, argv[0], window_id,
argv[2], argv[2],
NULL)) NULL))
return FALSE; return FALSE;
} }
else if (strcmp (argv[0], "accept_focus") == 0) else if (strcmp (argv[0], "accept_focus") == 0)
@ -534,15 +553,15 @@ test_case_do (TestCase *test,
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]", BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
argv[0]); argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, if (!meta_test_client_do (client, error,
argv[0], window_id, argv[0], window_id,
argv[2], argv[2],
NULL)) NULL))
return FALSE; return FALSE;
} }
else if (strcmp (argv[0], "can_take_focus") == 0) else if (strcmp (argv[0], "can_take_focus") == 0)
@ -553,15 +572,15 @@ test_case_do (TestCase *test,
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]", BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
argv[0]); argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, if (!meta_test_client_do (client, error,
argv[0], window_id, argv[0], window_id,
argv[2], argv[2],
NULL)) NULL))
return FALSE; return FALSE;
} }
else if (strcmp (argv[0], "accept_take_focus") == 0) else if (strcmp (argv[0], "accept_take_focus") == 0)
@ -572,19 +591,20 @@ test_case_do (TestCase *test,
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]", BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
argv[0]); argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, if (!meta_test_client_do (client, error,
argv[0], window_id, argv[0], window_id,
argv[2], argv[2],
NULL)) NULL))
return FALSE; return FALSE;
} }
else if (strcmp (argv[0], "show") == 0) else if (strcmp (argv[0], "show") == 0)
{ {
MetaWindow *window;
gboolean show_async = FALSE; gboolean show_async = FALSE;
if (argc != 2 && argc != 3) if (argc != 2 && argc != 3)
@ -593,49 +613,51 @@ test_case_do (TestCase *test,
if (argc == 3 && strcmp (argv[2], "async") == 0) if (argc == 3 && strcmp (argv[2], "async") == 0)
show_async = TRUE; show_async = TRUE;
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, argv[0], window_id, NULL)) if (!meta_test_client_do (client, error, argv[0], window_id, NULL))
return FALSE; return FALSE;
if (!test_case_wait (test, error)) if (!test_case_wait (test, error))
return FALSE; return FALSE;
MetaWindow *window = test_client_find_window (client, window_id, error); window = meta_test_client_find_window (client, window_id, error);
if (!window) if (!window)
return FALSE; return FALSE;
if (!show_async) if (!show_async)
test_client_wait_for_window_shown (client, window); meta_test_client_wait_for_window_shown (client, window);
} }
else if (strcmp (argv[0], "resize") == 0) else if (strcmp (argv[0], "resize") == 0)
{ {
if (argc != 4) if (argc != 4)
BAD_COMMAND("usage: %s <client-id>/<window-id> width height", argv[0]); BAD_COMMAND("usage: %s <client-id>/<window-id> width height", argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, argv[0], window_id, if (!meta_test_client_do (client, error, argv[0], window_id,
argv[2], argv[3], NULL)) argv[2], argv[3], NULL))
return FALSE; return FALSE;
} }
else if (strcmp (argv[0], "move") == 0) else if (strcmp (argv[0], "move") == 0)
{ {
MetaWindow *window;
if (argc != 4) if (argc != 4)
BAD_COMMAND("usage: %s <client-id>/<window-id> x y", argv[0]); BAD_COMMAND("usage: %s <client-id>/<window-id> x y", argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
MetaWindow *window = test_client_find_window (client, window_id, error); window = meta_test_client_find_window (client, window_id, error);
if (!window) if (!window)
return FALSE; return FALSE;
@ -643,15 +665,17 @@ test_case_do (TestCase *test,
} }
else if (strcmp (argv[0], "tile") == 0) else if (strcmp (argv[0], "tile") == 0)
{ {
MetaWindow *window;
if (argc != 3) if (argc != 3)
BAD_COMMAND("usage: %s <client-id>/<window-id> [right|left]", argv[0]); BAD_COMMAND("usage: %s <client-id>/<window-id> [right|left]", argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
MetaWindow *window = test_client_find_window (client, window_id, error); window = meta_test_client_find_window (client, window_id, error);
if (!window) if (!window)
return FALSE; return FALSE;
@ -667,8 +691,8 @@ test_case_do (TestCase *test,
else else
{ {
g_set_error (error, g_set_error (error,
TEST_RUNNER_ERROR, META_TEST_CLIENT_ERROR,
TEST_RUNNER_ERROR_ASSERTION_FAILED, META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"Invalid tile mode '%s'", argv[2]); "Invalid tile mode '%s'", argv[2]);
return FALSE; return FALSE;
} }
@ -677,15 +701,17 @@ test_case_do (TestCase *test,
} }
else if (strcmp (argv[0], "untile") == 0) else if (strcmp (argv[0], "untile") == 0)
{ {
MetaWindow *window;
if (argc != 2) if (argc != 2)
BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]); BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
MetaWindow *window = test_client_find_window (client, window_id, error); window = meta_test_client_find_window (client, window_id, error);
if (!window) if (!window)
return FALSE; return FALSE;
@ -708,25 +734,27 @@ test_case_do (TestCase *test,
if (argc != 2) if (argc != 2)
BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]); BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
if (!test_client_do (client, error, argv[0], window_id, NULL)) if (!meta_test_client_do (client, error, argv[0], window_id, NULL))
return FALSE; return FALSE;
} }
else if (strcmp (argv[0], "local_activate") == 0) else if (strcmp (argv[0], "local_activate") == 0)
{ {
MetaWindow *window;
if (argc != 2) if (argc != 2)
BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]); BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]);
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
MetaWindow *window = test_client_find_window (client, window_id, error); window = meta_test_client_find_window (client, window_id, error);
if (!window) if (!window)
return FALSE; return FALSE;
@ -795,26 +823,28 @@ test_case_do (TestCase *test,
} }
else if (strcmp (argv[0], "assert_size") == 0) else if (strcmp (argv[0], "assert_size") == 0)
{ {
MetaWindow *window;
if (argc != 4) if (argc != 4)
{ {
BAD_COMMAND("usage: %s <client-id>/<window-id> <width> <height>", BAD_COMMAND("usage: %s <client-id>/<window-id> <width> <height>",
argv[0]); argv[0]);
} }
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
MetaWindow *window = test_client_find_window (client, window_id, error); window = meta_test_client_find_window (client, window_id, error);
if (!window) if (!window)
return FALSE; return FALSE;
if (meta_window_get_frame (window)) if (meta_window_get_frame (window))
{ {
g_set_error (error, g_set_error (error,
TEST_RUNNER_ERROR, META_TEST_CLIENT_ERROR,
TEST_RUNNER_ERROR_ASSERTION_FAILED, META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"Can only assert size of CSD window"); "Can only assert size of CSD window");
return FALSE; return FALSE;
} }
@ -824,11 +854,11 @@ test_case_do (TestCase *test,
g_autofree char *width_str = g_strdup_printf ("%d", width); g_autofree char *width_str = g_strdup_printf ("%d", width);
g_autofree char *height_str = g_strdup_printf ("%d", height); g_autofree char *height_str = g_strdup_printf ("%d", height);
if (!test_client_do (client, error, argv[0], if (!meta_test_client_do (client, error, argv[0],
window_id, window_id,
width_str, width_str,
height_str, height_str,
NULL)) NULL))
return FALSE; return FALSE;
if (!test_case_assert_size (test, window, if (!test_case_assert_size (test, window,
@ -838,18 +868,20 @@ test_case_do (TestCase *test,
} }
else if (strcmp (argv[0], "assert_position") == 0) else if (strcmp (argv[0], "assert_position") == 0)
{ {
MetaWindow *window;
if (argc != 4) if (argc != 4)
{ {
BAD_COMMAND("usage: %s <client-id>/<window-id> <x> <y>", BAD_COMMAND("usage: %s <client-id>/<window-id> <x> <y>",
argv[0]); argv[0]);
} }
TestClient *client; MetaTestClient *client;
const char *window_id; const char *window_id;
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
return FALSE; return FALSE;
MetaWindow *window = test_client_find_window (client, window_id, error); window = meta_test_client_find_window (client, window_id, error);
if (!window) if (!window)
return FALSE; return FALSE;
@ -860,8 +892,8 @@ test_case_do (TestCase *test,
if (frame_rect.x != x || frame_rect.y != y) if (frame_rect.x != x || frame_rect.y != y)
{ {
g_set_error (error, g_set_error (error,
TEST_RUNNER_ERROR, META_TEST_CLIENT_ERROR,
TEST_RUNNER_ERROR_ASSERTION_FAILED, META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
"Expected window position (%d, %d) doesn't match (%d, %d)", "Expected window position (%d, %d) doesn't match (%d, %d)",
x, y, frame_rect.x, frame_rect.y); x, y, frame_rect.x, frame_rect.y);
return FALSE; return FALSE;
@ -890,7 +922,7 @@ test_case_destroy (TestCase *test,
g_hash_table_iter_init (&iter, test->clients); g_hash_table_iter_init (&iter, test->clients);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
{ {
if (!test_client_do (value, error, "destroy_all", NULL)) if (!meta_test_client_do (value, error, "destroy_all", NULL))
return FALSE; return FALSE;
} }
@ -903,7 +935,7 @@ test_case_destroy (TestCase *test,
g_hash_table_iter_init (&iter, test->clients); g_hash_table_iter_init (&iter, test->clients);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
test_client_destroy (value); meta_test_client_destroy (value);
g_clear_pointer (&test->waiter, async_waiter_destroy); g_clear_pointer (&test->waiter, async_waiter_destroy);