2014-09-11 13:43:32 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "core/window-private.h"
|
2021-05-06 17:37:35 -04:00
|
|
|
#include "meta-test/meta-context-test.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "meta/util.h"
|
|
|
|
#include "meta/window.h"
|
2021-10-29 15:26:51 -04:00
|
|
|
#include "meta/meta-workspace-manager.h"
|
2021-04-20 12:39:53 -04:00
|
|
|
#include "tests/meta-test-utils.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "ui/ui.h"
|
|
|
|
#include "wayland/meta-wayland.h"
|
2017-08-26 12:26:30 -04:00
|
|
|
#include "x11/meta-x11-display-private.h"
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
typedef struct {
|
2021-05-11 03:35:04 -04:00
|
|
|
MetaContext *context;
|
2014-09-11 13:43:32 -04:00
|
|
|
GHashTable *clients;
|
2021-05-06 17:35:44 -04:00
|
|
|
MetaAsyncWaiter *waiter;
|
2014-09-15 14:50:21 -04:00
|
|
|
GString *warning_messages;
|
2014-09-24 15:52:11 -04:00
|
|
|
GMainLoop *loop;
|
2021-05-26 13:31:02 -04:00
|
|
|
gulong x11_display_opened_handler_id;
|
2014-09-11 13:43:32 -04:00
|
|
|
} TestCase;
|
|
|
|
|
|
|
|
static gboolean
|
2017-08-26 12:56:44 -04:00
|
|
|
test_case_alarm_filter (MetaX11Display *x11_display,
|
2014-09-11 13:43:32 -04:00
|
|
|
XSyncAlarmNotifyEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
TestCase *test = data;
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
2021-05-06 17:35:44 -04:00
|
|
|
if (meta_async_waiter_process_x11_event (test->waiter, x11_display, event))
|
2014-09-11 13:43:32 -04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, test->clients);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
2021-05-06 17:34:36 -04:00
|
|
|
{
|
|
|
|
MetaTestClient *client = value;
|
|
|
|
|
|
|
|
if (meta_test_client_process_x11_event (client, x11_display, event))
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-01-21 12:58:28 -05:00
|
|
|
static void
|
|
|
|
on_x11_display_opened (MetaDisplay *display,
|
|
|
|
TestCase *test)
|
|
|
|
{
|
|
|
|
meta_x11_display_set_alarm_filter (display->x11_display,
|
|
|
|
test_case_alarm_filter, test);
|
2022-04-06 04:30:59 -04:00
|
|
|
test->waiter = meta_async_waiter_new (display->x11_display);
|
2021-01-21 12:58:28 -05:00
|
|
|
}
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
static TestCase *
|
2021-05-11 03:35:04 -04:00
|
|
|
test_case_new (MetaContext *context)
|
2014-09-11 13:43:32 -04:00
|
|
|
{
|
|
|
|
TestCase *test = g_new0 (TestCase, 1);
|
2021-05-11 03:35:04 -04:00
|
|
|
MetaDisplay *display = meta_context_get_display (context);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-02-25 10:52:09 -05:00
|
|
|
if (!meta_is_wayland_compositor ())
|
2021-01-21 12:58:28 -05:00
|
|
|
{
|
2021-05-11 03:35:04 -04:00
|
|
|
meta_context_test_wait_for_x11_display (META_CONTEXT_TEST (context));
|
2021-01-21 12:58:28 -05:00
|
|
|
on_x11_display_opened (display, test);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (display->x11_display)
|
|
|
|
on_x11_display_opened (display, test);
|
|
|
|
else
|
2021-05-26 13:31:02 -04:00
|
|
|
test->x11_display_opened_handler_id =
|
|
|
|
g_signal_connect (meta_get_display (), "x11-display-opened",
|
|
|
|
G_CALLBACK (on_x11_display_opened),
|
|
|
|
test);
|
2021-01-21 12:58:28 -05:00
|
|
|
}
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-05-11 03:35:04 -04:00
|
|
|
test->context = context;
|
2014-09-11 13:43:32 -04:00
|
|
|
test->clients = g_hash_table_new (g_str_hash, g_str_equal);
|
2014-09-24 15:52:11 -04:00
|
|
|
test->loop = g_main_loop_new (NULL, FALSE);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
2014-09-24 15:52:11 -04:00
|
|
|
static gboolean
|
2019-06-18 13:33:10 -04:00
|
|
|
test_case_loop_quit (gpointer data)
|
2014-09-24 15:52:11 -04:00
|
|
|
{
|
|
|
|
TestCase *test = data;
|
|
|
|
|
|
|
|
g_main_loop_quit (test->loop);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-21 07:15:48 -04:00
|
|
|
static gboolean
|
|
|
|
test_case_dispatch (TestCase *test,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
/* Wait until we've done any outstanding queued up work.
|
|
|
|
* Though we add this as BEFORE_REDRAW, the iteration that runs the
|
|
|
|
* BEFORE_REDRAW idles will proceed on and do the redraw, so we're
|
|
|
|
* waiting until after *all* frame processing.
|
|
|
|
*/
|
|
|
|
meta_later_add (META_LATER_BEFORE_REDRAW,
|
|
|
|
test_case_loop_quit,
|
|
|
|
test,
|
|
|
|
NULL);
|
|
|
|
g_main_loop_run (test->loop);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
static gboolean
|
|
|
|
test_case_wait (TestCase *test,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
2014-09-24 15:52:11 -04:00
|
|
|
/* First have each client set a XSync counter, and wait until
|
|
|
|
* we receive the resulting event - so we know we've received
|
|
|
|
* everything that the client have sent us.
|
|
|
|
*/
|
2014-09-11 13:43:32 -04:00
|
|
|
g_hash_table_iter_init (&iter, test->clients);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_wait (value, error))
|
2014-09-11 13:43:32 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2019-06-21 07:15:48 -04:00
|
|
|
/* Then wait until we've done any outstanding queued up work. */
|
|
|
|
test_case_dispatch (test, error);
|
2014-09-24 15:52:11 -04:00
|
|
|
|
|
|
|
/* Then set an XSync counter ourselves and and wait until
|
|
|
|
* we receive the resulting event - this makes sure that we've
|
|
|
|
* received back any X events we generated.
|
|
|
|
*/
|
2021-01-21 12:58:28 -05:00
|
|
|
if (test->waiter)
|
2021-05-06 17:35:44 -04:00
|
|
|
meta_async_waiter_set_and_wait (test->waiter);
|
2014-09-11 13:43:32 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-06-18 13:33:10 -04:00
|
|
|
static gboolean
|
|
|
|
test_case_sleep (TestCase *test,
|
|
|
|
guint32 interval,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_timeout_add_full (G_PRIORITY_LOW, interval, test_case_loop_quit, test, NULL);
|
|
|
|
g_main_loop_run (test->loop);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
#define BAD_COMMAND(...) \
|
|
|
|
G_STMT_START { \
|
|
|
|
g_set_error (error, \
|
2021-05-06 17:34:36 -04:00
|
|
|
META_TEST_CLIENT_ERROR, \
|
|
|
|
META_TEST_CLIENT_ERROR_BAD_COMMAND, \
|
2014-09-11 13:43:32 -04:00
|
|
|
__VA_ARGS__); \
|
|
|
|
return FALSE; \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
static MetaTestClient *
|
2014-09-11 13:43:32 -04:00
|
|
|
test_case_lookup_client (TestCase *test,
|
|
|
|
char *client_id,
|
|
|
|
GError **error)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client = g_hash_table_lookup (test->clients, client_id);
|
2014-09-11 13:43:32 -04:00
|
|
|
if (!client)
|
2021-05-06 17:34:36 -04:00
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_BAD_COMMAND,
|
|
|
|
"No such client %s", client_id);
|
|
|
|
}
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2021-05-06 17:34:36 -04:00
|
|
|
test_case_parse_window_id (TestCase *test,
|
|
|
|
const char *client_and_window_id,
|
|
|
|
MetaTestClient **client,
|
|
|
|
const char **window_id,
|
|
|
|
GError **error)
|
2014-09-11 13:43:32 -04:00
|
|
|
{
|
|
|
|
const char *slash = strchr (client_and_window_id, '/');
|
|
|
|
char *tmp;
|
|
|
|
if (slash == NULL)
|
2020-08-26 05:49:50 -04:00
|
|
|
BAD_COMMAND ("client/window ID %s doesn't contain a /", client_and_window_id);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
*window_id = slash + 1;
|
|
|
|
|
|
|
|
tmp = g_strndup (client_and_window_id, slash - client_and_window_id);
|
|
|
|
*client = test_case_lookup_client (test, tmp, error);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
return client != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_case_assert_stacking (TestCase *test,
|
|
|
|
char **expected_windows,
|
|
|
|
int n_expected_windows,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 *windows;
|
2014-09-11 13:43:32 -04:00
|
|
|
int n_windows;
|
|
|
|
GString *stack_string = g_string_new (NULL);
|
|
|
|
GString *expected_string = g_string_new (NULL);
|
|
|
|
int i;
|
|
|
|
|
2017-08-26 13:03:51 -04:00
|
|
|
meta_stack_tracker_get_stack (display->stack_tracker, &windows, &n_windows);
|
2014-09-11 13:43:32 -04:00
|
|
|
for (i = 0; i < n_windows; i++)
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
MetaWindow *window = meta_display_lookup_stack_id (display, windows[i]);
|
2014-09-11 13:43:32 -04:00
|
|
|
if (window != NULL && window->title)
|
|
|
|
{
|
|
|
|
/* See comment in meta_ui_new() about why the dummy window for GTK+ theming
|
|
|
|
* is managed as a MetaWindow.
|
|
|
|
*/
|
2014-09-08 21:20:14 -04:00
|
|
|
if (META_STACK_ID_IS_X11 (windows[i]) &&
|
2017-08-26 15:38:59 -04:00
|
|
|
meta_ui_window_is_dummy (display->x11_display->ui, windows[i]))
|
2014-09-11 13:43:32 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (stack_string->len > 0)
|
|
|
|
g_string_append_c (stack_string, ' ');
|
|
|
|
|
|
|
|
if (g_str_has_prefix (window->title, "test/"))
|
|
|
|
g_string_append (stack_string, window->title + 5);
|
|
|
|
else
|
|
|
|
g_string_append_printf (stack_string, "(%s)", window->title);
|
|
|
|
}
|
2017-08-26 13:03:51 -04:00
|
|
|
else if (windows[i] == display->x11_display->guard_window)
|
2014-09-24 16:07:11 -04:00
|
|
|
{
|
|
|
|
if (stack_string->len > 0)
|
|
|
|
g_string_append_c (stack_string, ' ');
|
|
|
|
|
|
|
|
g_string_append_c (stack_string, '|');
|
|
|
|
}
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_expected_windows; i++)
|
|
|
|
{
|
|
|
|
if (expected_string->len > 0)
|
|
|
|
g_string_append_c (expected_string, ' ');
|
|
|
|
|
|
|
|
g_string_append (expected_string, expected_windows[i]);
|
|
|
|
}
|
|
|
|
|
2014-09-24 16:07:11 -04:00
|
|
|
/* Don't require '| ' as a prefix if there are no hidden windows - we
|
|
|
|
* remove the prefix from the actual string instead of adding it to the
|
|
|
|
* expected string for clarity of the error message
|
|
|
|
*/
|
|
|
|
if (index (expected_string->str, '|') == NULL && stack_string->str[0] == '|')
|
|
|
|
{
|
|
|
|
g_string_erase (stack_string,
|
|
|
|
0, stack_string->str[1] == ' ' ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
if (strcmp (expected_string->str, stack_string->str) != 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
g_set_error (error,
|
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2014-09-11 13:43:32 -04:00
|
|
|
"stacking: expected='%s', actual='%s'",
|
|
|
|
expected_string->str, stack_string->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free (stack_string, TRUE);
|
|
|
|
g_string_free (expected_string, TRUE);
|
|
|
|
|
|
|
|
return *error == NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-13 02:37:14 -05:00
|
|
|
static gboolean
|
|
|
|
test_case_assert_focused (TestCase *test,
|
|
|
|
const char *expected_window,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
|
|
|
|
if (!display->focus_window)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (expected_window, "none") != 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
g_set_error (error,
|
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2018-11-13 02:37:14 -05:00
|
|
|
"focus: expected='%s', actual='none'", expected_window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *focused = display->focus_window->title;
|
|
|
|
|
|
|
|
if (g_str_has_prefix (focused, "test/"))
|
|
|
|
focused += 5;
|
|
|
|
|
|
|
|
if (g_strcmp0 (focused, expected_window) != 0)
|
2021-05-06 17:34:36 -04:00
|
|
|
g_set_error (error,
|
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2018-11-13 02:37:14 -05:00
|
|
|
"focus: expected='%s', actual='%s'",
|
|
|
|
expected_window, focused);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *error == NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:11:09 -04:00
|
|
|
static gboolean
|
|
|
|
test_case_assert_size (TestCase *test,
|
|
|
|
MetaWindow *window,
|
|
|
|
int expected_width,
|
|
|
|
int expected_height,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaRectangle frame_rect;
|
|
|
|
|
|
|
|
meta_window_get_frame_rect (window, &frame_rect);
|
|
|
|
|
|
|
|
if (frame_rect.width != expected_width ||
|
|
|
|
frame_rect.height != expected_height)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
g_set_error (error,
|
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2020-04-02 10:11:09 -04:00
|
|
|
"Expected size %dx%d didn't match actual size %dx%d",
|
|
|
|
expected_width, expected_height,
|
|
|
|
frame_rect.width, frame_rect.height);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
static gboolean
|
|
|
|
test_case_check_xserver_stacking (TestCase *test,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
GString *local_string = g_string_new (NULL);
|
|
|
|
GString *x11_string = g_string_new (NULL);
|
|
|
|
int i;
|
|
|
|
|
2021-01-21 12:58:28 -05:00
|
|
|
if (!display->x11_display)
|
|
|
|
return TRUE;
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 *windows;
|
2014-09-11 13:43:32 -04:00
|
|
|
int n_windows;
|
2017-08-26 13:03:51 -04:00
|
|
|
meta_stack_tracker_get_stack (display->stack_tracker, &windows, &n_windows);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
for (i = 0; i < n_windows; i++)
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
if (META_STACK_ID_IS_X11 (windows[i]))
|
2014-09-11 13:43:32 -04:00
|
|
|
{
|
|
|
|
if (local_string->len > 0)
|
|
|
|
g_string_append_c (local_string, ' ');
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
g_string_append_printf (local_string, "%#lx", (Window)windows[i]);
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Window root;
|
|
|
|
Window parent;
|
|
|
|
Window *children;
|
|
|
|
unsigned int n_children;
|
2017-08-26 12:26:30 -04:00
|
|
|
XQueryTree (display->x11_display->xdisplay,
|
|
|
|
display->x11_display->xroot,
|
2014-09-11 13:43:32 -04:00
|
|
|
&root, &parent, &children, &n_children);
|
|
|
|
|
|
|
|
for (i = 0; i < (int)n_children; i++)
|
|
|
|
{
|
|
|
|
if (x11_string->len > 0)
|
|
|
|
g_string_append_c (x11_string, ' ');
|
|
|
|
|
|
|
|
g_string_append_printf (x11_string, "%#lx", (Window)children[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (x11_string->str, local_string->str) != 0)
|
2021-05-06 17:34:36 -04:00
|
|
|
g_set_error (error,
|
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2014-09-11 13:43:32 -04:00
|
|
|
"xserver stacking: x11='%s', local='%s'",
|
|
|
|
x11_string->str, local_string->str);
|
|
|
|
|
|
|
|
XFree (children);
|
|
|
|
|
|
|
|
g_string_free (local_string, TRUE);
|
|
|
|
g_string_free (x11_string, TRUE);
|
|
|
|
|
|
|
|
return *error == NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:11:09 -04:00
|
|
|
static int
|
|
|
|
maybe_divide (const char *str,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
if (strstr (str, "/") == str)
|
|
|
|
{
|
|
|
|
int divisor;
|
|
|
|
|
|
|
|
str += 1;
|
|
|
|
divisor = atoi (str);
|
|
|
|
|
|
|
|
value /= divisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_window_size (MetaWindow *window,
|
|
|
|
const char *size_str)
|
|
|
|
{
|
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
MetaRectangle logical_monitor_layout;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
logical_monitor = meta_window_calculate_main_logical_monitor (window);
|
|
|
|
g_assert_nonnull (logical_monitor);
|
|
|
|
|
|
|
|
logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
|
|
|
|
|
|
|
|
if (strstr (size_str, "MONITOR_WIDTH") == size_str)
|
|
|
|
{
|
|
|
|
value = logical_monitor_layout.width;
|
|
|
|
size_str += strlen ("MONITOR_WIDTH");
|
|
|
|
value = maybe_divide (size_str, value);
|
|
|
|
}
|
|
|
|
else if (strstr (size_str, "MONITOR_HEIGHT") == size_str)
|
|
|
|
{
|
|
|
|
value = logical_monitor_layout.height;
|
|
|
|
size_str += strlen ("MONITOR_HEIGHT");
|
|
|
|
value = maybe_divide (size_str, value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = atoi (size_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
static gboolean
|
|
|
|
test_case_do (TestCase *test,
|
|
|
|
int argc,
|
|
|
|
char **argv,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
if (strcmp (argv[0], "new_client") == 0)
|
|
|
|
{
|
|
|
|
MetaWindowClientType type;
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
BAD_COMMAND("usage: new_client <client-id> [wayland|x11]");
|
|
|
|
|
|
|
|
if (strcmp (argv[2], "x11") == 0)
|
|
|
|
type = META_WINDOW_CLIENT_TYPE_X11;
|
|
|
|
else if (strcmp (argv[2], "wayland") == 0)
|
|
|
|
type = META_WINDOW_CLIENT_TYPE_WAYLAND;
|
|
|
|
else
|
|
|
|
BAD_COMMAND("usage: new_client <client-id> [wayland|x11]");
|
|
|
|
|
|
|
|
if (g_hash_table_lookup (test->clients, argv[1]))
|
|
|
|
BAD_COMMAND("client %s already exists", argv[1]);
|
|
|
|
|
2021-05-11 03:35:04 -04:00
|
|
|
client = meta_test_client_new (test->context, argv[1], type, error);
|
2014-09-11 13:43:32 -04:00
|
|
|
if (!client)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
g_hash_table_insert (test->clients, meta_test_client_get_id (client), client);
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "quit_client") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
BAD_COMMAND("usage: quit_client <client-id>");
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client = test_case_lookup_client (test, argv[1], error);
|
2014-09-11 13:43:32 -04:00
|
|
|
if (!client)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_quit (client, error))
|
2014-09-11 13:43:32 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
g_hash_table_remove (test->clients, meta_test_client_get_id (client));
|
|
|
|
meta_test_client_destroy (client);
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "create") == 0)
|
|
|
|
{
|
|
|
|
if (!(argc == 2 ||
|
2014-09-15 13:24:05 -04:00
|
|
|
(argc == 3 && strcmp (argv[2], "override") == 0) ||
|
|
|
|
(argc == 3 && strcmp (argv[2], "csd") == 0)))
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id > [override|csd]", argv[0]);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2014-09-11 13:43:32 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error,
|
|
|
|
"create", window_id,
|
|
|
|
argc == 3 ? argv[2] : NULL,
|
|
|
|
NULL))
|
2014-09-11 13:43:32 -04:00
|
|
|
return FALSE;
|
2019-05-17 17:11:04 -04:00
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_wait (client, error))
|
2019-05-17 17:11:04 -04:00
|
|
|
return FALSE;
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
2018-07-13 10:40:31 -04:00
|
|
|
else if (strcmp (argv[0], "set_parent") == 0 ||
|
|
|
|
strcmp (argv[0], "set_parent_exported") == 0)
|
2015-09-24 01:39:58 -04:00
|
|
|
{
|
|
|
|
if (argc != 3)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> <parent-window-id>",
|
|
|
|
argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2015-09-24 01:39:58 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
2018-11-12 21:43:57 -05:00
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error,
|
|
|
|
argv[0], window_id,
|
|
|
|
argv[2],
|
|
|
|
NULL))
|
2018-11-12 21:43:57 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "accept_focus") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 3 ||
|
|
|
|
(g_ascii_strcasecmp (argv[2], "true") != 0 &&
|
|
|
|
g_ascii_strcasecmp (argv[2], "false") != 0))
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
|
|
|
argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2018-11-12 21:43:57 -05:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
2018-11-12 22:04:22 -05:00
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error,
|
|
|
|
argv[0], window_id,
|
|
|
|
argv[2],
|
|
|
|
NULL))
|
2018-11-12 22:04:22 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "can_take_focus") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 3 ||
|
|
|
|
(g_ascii_strcasecmp (argv[2], "true") != 0 &&
|
|
|
|
g_ascii_strcasecmp (argv[2], "false") != 0))
|
2019-07-03 10:47:54 -04:00
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
|
|
|
argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2019-07-03 10:47:54 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error,
|
|
|
|
argv[0], window_id,
|
|
|
|
argv[2],
|
|
|
|
NULL))
|
2019-07-03 10:47:54 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "accept_take_focus") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 3 ||
|
|
|
|
(g_ascii_strcasecmp (argv[2], "true") != 0 &&
|
|
|
|
g_ascii_strcasecmp (argv[2], "false") != 0))
|
2018-11-12 22:04:22 -05:00
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]",
|
|
|
|
argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2018-11-12 22:04:22 -05:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
2015-09-24 01:39:58 -04:00
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error,
|
|
|
|
argv[0], window_id,
|
|
|
|
argv[2],
|
|
|
|
NULL))
|
2015-09-24 01:39:58 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-07-12 04:25:16 -04:00
|
|
|
else if (strcmp (argv[0], "show") == 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaWindow *window;
|
2020-12-16 17:27:19 -05:00
|
|
|
gboolean show_async = FALSE;
|
|
|
|
|
|
|
|
if (argc != 2 && argc != 3)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [async]", argv[0]);
|
|
|
|
|
|
|
|
if (argc == 3 && strcmp (argv[2], "async") == 0)
|
|
|
|
show_async = TRUE;
|
2018-07-12 04:25:16 -04:00
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2018-07-12 04:25:16 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error, argv[0], window_id, NULL))
|
2018-07-12 04:25:16 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2020-06-04 18:03:00 -04:00
|
|
|
if (!test_case_wait (test, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
window = meta_test_client_find_window (client, window_id, error);
|
2018-07-12 04:25:16 -04:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-12-16 17:27:19 -05:00
|
|
|
if (!show_async)
|
2021-05-06 17:34:36 -04:00
|
|
|
meta_test_client_wait_for_window_shown (client, window);
|
2018-07-12 04:25:16 -04:00
|
|
|
}
|
2020-04-01 17:04:59 -04:00
|
|
|
else if (strcmp (argv[0], "resize") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 4)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> width height", argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2020-04-01 17:04:59 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error, argv[0], window_id,
|
|
|
|
argv[2], argv[3], NULL))
|
2020-04-01 17:04:59 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2020-04-02 13:12:39 -04:00
|
|
|
else if (strcmp (argv[0], "move") == 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaWindow *window;
|
|
|
|
|
2020-04-02 13:12:39 -04:00
|
|
|
if (argc != 4)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> x y", argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2020-04-02 13:12:39 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
window = meta_test_client_find_window (client, window_id, error);
|
2020-04-02 13:12:39 -04:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
meta_window_move_frame (window, TRUE, atoi (argv[2]), atoi (argv[3]));
|
|
|
|
}
|
2020-04-02 13:09:14 -04:00
|
|
|
else if (strcmp (argv[0], "tile") == 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaWindow *window;
|
|
|
|
|
2020-04-02 13:09:14 -04:00
|
|
|
if (argc != 3)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> [right|left]", argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2020-04-02 13:09:14 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
window = meta_test_client_find_window (client, window_id, error);
|
2020-04-02 13:09:14 -04:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
MetaTileMode tile_mode;
|
|
|
|
if (strcmp (argv[2], "right") == 0)
|
|
|
|
{
|
|
|
|
tile_mode = META_TILE_RIGHT;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[2], "left") == 0)
|
|
|
|
{
|
|
|
|
tile_mode = META_TILE_LEFT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
2021-05-06 17:34:36 -04:00
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2020-04-02 13:09:14 -04:00
|
|
|
"Invalid tile mode '%s'", argv[2]);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_window_tile (window, tile_mode);
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "untile") == 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaWindow *window;
|
|
|
|
|
2020-04-02 13:09:14 -04:00
|
|
|
if (argc != 2)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2020-04-02 13:09:14 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
window = meta_test_client_find_window (client, window_id, error);
|
2020-04-02 13:09:14 -04:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
meta_window_untile (window);
|
|
|
|
}
|
2018-07-12 04:25:16 -04:00
|
|
|
else if (strcmp (argv[0], "hide") == 0 ||
|
2014-09-11 13:43:32 -04:00
|
|
|
strcmp (argv[0], "activate") == 0 ||
|
|
|
|
strcmp (argv[0], "raise") == 0 ||
|
|
|
|
strcmp (argv[0], "lower") == 0 ||
|
2014-09-24 16:09:20 -04:00
|
|
|
strcmp (argv[0], "minimize") == 0 ||
|
|
|
|
strcmp (argv[0], "unminimize") == 0 ||
|
2020-04-01 09:19:21 -04:00
|
|
|
strcmp (argv[0], "maximize") == 0 ||
|
|
|
|
strcmp (argv[0], "unmaximize") == 0 ||
|
2020-04-02 12:28:24 -04:00
|
|
|
strcmp (argv[0], "fullscreen") == 0 ||
|
|
|
|
strcmp (argv[0], "unfullscreen") == 0 ||
|
2020-12-16 17:27:19 -05:00
|
|
|
strcmp (argv[0], "freeze") == 0 ||
|
|
|
|
strcmp (argv[0], "thaw") == 0 ||
|
2014-09-11 13:43:32 -04:00
|
|
|
strcmp (argv[0], "destroy") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2014-09-11 13:43:32 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error, argv[0], window_id, NULL))
|
2014-09-11 13:43:32 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "local_activate") == 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaWindow *window;
|
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
if (argc != 2)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2014-09-11 13:43:32 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
window = meta_test_client_find_window (client, window_id, error);
|
2014-09-11 13:43:32 -04:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
meta_window_activate (window, 0);
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "wait") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 1)
|
|
|
|
BAD_COMMAND("usage: %s", argv[0]);
|
|
|
|
|
|
|
|
if (!test_case_wait (test, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-04-02 10:14:33 -04:00
|
|
|
else if (strcmp (argv[0], "wait_reconfigure") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 1)
|
|
|
|
BAD_COMMAND("usage: %s", argv[0]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait twice, so that we
|
|
|
|
* 1) First wait for any requests to configure being made
|
|
|
|
* 2) Then wait until the new configuration has been applied
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!test_case_wait (test, error))
|
|
|
|
return FALSE;
|
|
|
|
if (!test_case_dispatch (test, error))
|
|
|
|
return FALSE;
|
|
|
|
if (!test_case_wait (test, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-06-21 07:15:48 -04:00
|
|
|
else if (strcmp (argv[0], "dispatch") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 1)
|
|
|
|
BAD_COMMAND("usage: %s", argv[0]);
|
|
|
|
|
|
|
|
if (!test_case_dispatch (test, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-06-18 13:33:10 -04:00
|
|
|
else if (strcmp (argv[0], "sleep") == 0)
|
|
|
|
{
|
|
|
|
guint64 interval;
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
BAD_COMMAND("usage: %s <milliseconds>", argv[0]);
|
|
|
|
|
|
|
|
if (!g_ascii_string_to_unsigned (argv[1], 10, 0, G_MAXUINT32,
|
|
|
|
&interval, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!test_case_sleep (test, (guint32) interval, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-10-29 15:26:51 -04:00
|
|
|
else if (strcmp (argv[0], "set_strut") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 6)
|
|
|
|
BAD_COMMAND("usage: %s <x> <y> <width> <height> <side>", argv[0]);
|
|
|
|
|
|
|
|
int x = atoi (argv[1]);
|
|
|
|
int y = atoi (argv[2]);
|
|
|
|
int width = atoi (argv[3]);
|
|
|
|
int height = atoi (argv[4]);
|
|
|
|
|
|
|
|
MetaSide side;
|
|
|
|
if (strcmp (argv[5], "left") == 0)
|
|
|
|
side = META_SIDE_LEFT;
|
|
|
|
else if (strcmp (argv[5], "right") == 0)
|
|
|
|
side = META_SIDE_RIGHT;
|
|
|
|
else if (strcmp (argv[5], "top") == 0)
|
|
|
|
side = META_SIDE_TOP;
|
|
|
|
else if (strcmp (argv[5], "bottom") == 0)
|
|
|
|
side = META_SIDE_BOTTOM;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
MetaWorkspaceManager *workspace_manager =
|
|
|
|
meta_display_get_workspace_manager (display);
|
|
|
|
MetaRectangle rect = { x, y, width, height };
|
|
|
|
MetaStrut strut = { rect, side };
|
|
|
|
GSList *struts = g_slist_append (NULL, &strut);
|
|
|
|
GList *workspaces =
|
|
|
|
meta_workspace_manager_get_workspaces (workspace_manager);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = workspaces; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaWorkspace *workspace = l->data;
|
|
|
|
meta_workspace_set_builtin_struts (workspace, struts);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (struts);
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "clear_struts") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 1)
|
|
|
|
BAD_COMMAND("usage: %s", argv[0]);
|
|
|
|
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
MetaWorkspaceManager *workspace_manager =
|
|
|
|
meta_display_get_workspace_manager (display);
|
|
|
|
GList *workspaces =
|
|
|
|
meta_workspace_manager_get_workspaces (workspace_manager);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = workspaces; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaWorkspace *workspace = l->data;
|
|
|
|
meta_workspace_set_builtin_struts (workspace, NULL);
|
|
|
|
}
|
|
|
|
}
|
2014-09-11 13:43:32 -04:00
|
|
|
else if (strcmp (argv[0], "assert_stacking") == 0)
|
|
|
|
{
|
|
|
|
if (!test_case_assert_stacking (test, argv + 1, argc - 1, error))
|
|
|
|
return FALSE;
|
2014-09-24 16:09:20 -04:00
|
|
|
|
2014-09-11 13:43:32 -04:00
|
|
|
if (!test_case_check_xserver_stacking (test, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-13 02:37:14 -05:00
|
|
|
else if (strcmp (argv[0], "assert_focused") == 0)
|
|
|
|
{
|
|
|
|
if (!test_case_assert_focused (test, argv[1], error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-04-02 10:11:09 -04:00
|
|
|
else if (strcmp (argv[0], "assert_size") == 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaWindow *window;
|
|
|
|
|
2020-04-02 10:11:09 -04:00
|
|
|
if (argc != 4)
|
|
|
|
{
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> <width> <height>",
|
|
|
|
argv[0]);
|
|
|
|
}
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2020-04-02 10:11:09 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
window = meta_test_client_find_window (client, window_id, error);
|
2020-04-02 10:11:09 -04:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (meta_window_get_frame (window))
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
2021-05-06 17:34:36 -04:00
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2020-04-02 10:11:09 -04:00
|
|
|
"Can only assert size of CSD window");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = parse_window_size (window, argv[2]);
|
|
|
|
int height = parse_window_size (window, argv[3]);
|
|
|
|
g_autofree char *width_str = g_strdup_printf ("%d", width);
|
|
|
|
g_autofree char *height_str = g_strdup_printf ("%d", height);
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (client, error, argv[0],
|
|
|
|
window_id,
|
|
|
|
width_str,
|
|
|
|
height_str,
|
|
|
|
NULL))
|
2020-04-02 10:11:09 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!test_case_assert_size (test, window,
|
|
|
|
width, height,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-04-02 13:12:39 -04:00
|
|
|
else if (strcmp (argv[0], "assert_position") == 0)
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaWindow *window;
|
|
|
|
|
2020-04-02 13:12:39 -04:00
|
|
|
if (argc != 4)
|
|
|
|
{
|
|
|
|
BAD_COMMAND("usage: %s <client-id>/<window-id> <x> <y>",
|
|
|
|
argv[0]);
|
|
|
|
}
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
MetaTestClient *client;
|
2020-04-02 13:12:39 -04:00
|
|
|
const char *window_id;
|
|
|
|
if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-05-06 17:34:36 -04:00
|
|
|
window = meta_test_client_find_window (client, window_id, error);
|
2020-04-02 13:12:39 -04:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
MetaRectangle frame_rect;
|
|
|
|
meta_window_get_frame_rect (window, &frame_rect);
|
|
|
|
int x = atoi (argv[2]);
|
|
|
|
int y = atoi (argv[3]);
|
|
|
|
if (frame_rect.x != x || frame_rect.y != y)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
2021-05-06 17:34:36 -04:00
|
|
|
META_TEST_CLIENT_ERROR,
|
|
|
|
META_TEST_CLIENT_ERROR_ASSERTION_FAILED,
|
2020-04-02 13:12:39 -04:00
|
|
|
"Expected window position (%d, %d) doesn't match (%d, %d)",
|
|
|
|
x, y, frame_rect.x, frame_rect.y);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2021-10-29 15:18:56 -04:00
|
|
|
else if (strcmp (argv[0], "stop_after_next") == 0 ||
|
|
|
|
strcmp (argv[0], "continue") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
BAD_COMMAND("usage: %s <client-id>", argv[0]);
|
|
|
|
|
|
|
|
MetaTestClient *client = test_case_lookup_client (test, argv[1], error);
|
|
|
|
if (!client)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!meta_test_client_do (client, error, argv[0], NULL))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2022-04-05 17:42:55 -04:00
|
|
|
else if (strcmp (argv[0], "clipboard-set") == 0)
|
|
|
|
{
|
|
|
|
if (argc != 4)
|
|
|
|
BAD_COMMAND("usage: %s <client-id> <mimetype> <text>", argv[0]);
|
|
|
|
|
|
|
|
MetaTestClient *client = test_case_lookup_client (test, argv[1], error);
|
|
|
|
if (!client)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!meta_test_client_do (client, error, argv[0], argv[2], argv[3], NULL))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-11 13:43:32 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
BAD_COMMAND("Unknown command %s", argv[0]);
|
|
|
|
}
|
|
|
|
|
2018-07-16 10:40:31 -04:00
|
|
|
return TRUE;
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_case_destroy (TestCase *test,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
/* Failures when cleaning up the test case aren't recoverable, since we'll
|
|
|
|
* pollute the subsequent test cases, so we just return the error, and
|
|
|
|
* skip the rest of the cleanup.
|
|
|
|
*/
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
2021-05-26 13:31:02 -04:00
|
|
|
MetaDisplay *display;
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, test->clients);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
2021-05-06 17:34:36 -04:00
|
|
|
if (!meta_test_client_do (value, error, "destroy_all", NULL))
|
2014-09-11 13:43:32 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!test_case_wait (test, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!test_case_assert_stacking (test, NULL, 0, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, test->clients);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
2021-05-06 17:34:36 -04:00
|
|
|
meta_test_client_destroy (value);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-05-06 17:35:44 -04:00
|
|
|
g_clear_pointer (&test->waiter, meta_async_waiter_destroy);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-05-26 13:31:02 -04:00
|
|
|
display = meta_get_display ();
|
|
|
|
g_clear_signal_handler (&test->x11_display_opened_handler_id, display);
|
|
|
|
if (display->x11_display)
|
|
|
|
meta_x11_display_set_alarm_filter (display->x11_display, NULL, NULL);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
g_hash_table_destroy (test->clients);
|
|
|
|
g_free (test);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
static gboolean
|
2021-05-11 03:35:04 -04:00
|
|
|
run_test (MetaContext *context,
|
|
|
|
const char *filename,
|
|
|
|
int index)
|
2014-09-11 13:43:32 -04:00
|
|
|
{
|
2021-05-11 03:35:04 -04:00
|
|
|
TestCase *test = test_case_new (context);
|
2014-09-11 13:43:32 -04:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
GFile *file = g_file_new_for_path (filename);
|
|
|
|
|
|
|
|
GDataInputStream *in = NULL;
|
|
|
|
|
|
|
|
GFileInputStream *in_raw = g_file_read (file, NULL, &error);
|
|
|
|
g_object_unref (file);
|
|
|
|
if (in_raw == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
in = g_data_input_stream_new (G_INPUT_STREAM (in_raw));
|
|
|
|
g_object_unref (in_raw);
|
|
|
|
|
|
|
|
int line_no = 0;
|
|
|
|
while (error == NULL)
|
|
|
|
{
|
|
|
|
char *line = g_data_input_stream_read_line_utf8 (in, NULL, NULL, &error);
|
|
|
|
if (line == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
line_no++;
|
|
|
|
|
|
|
|
int argc;
|
|
|
|
char **argv = NULL;
|
|
|
|
if (!g_shell_parse_argv (line, &argc, &argv, &error))
|
|
|
|
{
|
|
|
|
if (g_error_matches (error, G_SHELL_ERROR, G_SHELL_ERROR_EMPTY_STRING))
|
|
|
|
{
|
|
|
|
g_clear_error (&error);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_case_do (test, argc, argv, &error);
|
|
|
|
|
|
|
|
next:
|
|
|
|
if (error)
|
|
|
|
g_prefix_error (&error, "%d: ", line_no);
|
|
|
|
|
|
|
|
g_free (line);
|
|
|
|
g_strfreev (argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
if (!g_input_stream_close (G_INPUT_STREAM (in), NULL, &tmp_error))
|
|
|
|
{
|
|
|
|
if (error != NULL)
|
|
|
|
g_clear_error (&tmp_error);
|
|
|
|
else
|
|
|
|
g_propagate_error (&error, tmp_error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (in != NULL)
|
|
|
|
g_object_unref (in);
|
|
|
|
|
|
|
|
GError *cleanup_error = NULL;
|
|
|
|
test_case_destroy (test, &cleanup_error);
|
|
|
|
|
|
|
|
const char *testspos = strstr (filename, "tests/");
|
|
|
|
char *pretty_name;
|
|
|
|
if (testspos)
|
|
|
|
pretty_name = g_strdup (testspos + strlen("tests/"));
|
|
|
|
else
|
|
|
|
pretty_name = g_strdup (filename);
|
|
|
|
|
|
|
|
if (error || cleanup_error)
|
|
|
|
{
|
|
|
|
g_print ("not ok %d %s\n", index, pretty_name);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
g_print (" %s\n", error->message);
|
|
|
|
|
|
|
|
if (cleanup_error)
|
|
|
|
{
|
|
|
|
g_print (" Fatal Error During Cleanup\n");
|
|
|
|
g_print (" %s\n", cleanup_error->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_print ("ok %d %s\n", index, pretty_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (pretty_name);
|
|
|
|
|
|
|
|
gboolean success = error == NULL;
|
|
|
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
g_clear_error (&cleanup_error);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:53:18 -05:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-09-11 13:43:32 -04:00
|
|
|
int n_tests;
|
|
|
|
char **tests;
|
|
|
|
} RunTestsInfo;
|
|
|
|
|
2021-03-02 12:58:17 -05:00
|
|
|
static int
|
|
|
|
run_tests (MetaContext *context,
|
|
|
|
RunTestsInfo *info)
|
2014-09-11 13:43:32 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
g_print ("1..%d\n", info->n_tests);
|
|
|
|
|
|
|
|
for (i = 0; i < info->n_tests; i++)
|
2021-03-02 10:53:18 -05:00
|
|
|
{
|
2021-05-11 03:35:04 -04:00
|
|
|
if (!run_test (context, info->tests[i], i + 1))
|
2021-03-02 10:53:18 -05:00
|
|
|
success = FALSE;
|
|
|
|
}
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-03-02 12:58:17 -05:00
|
|
|
return success ? 0 : 1;
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_metatests_in_directory (GFile *directory,
|
|
|
|
GPtrArray *results,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileEnumerator *enumerator = g_file_enumerate_children (directory,
|
|
|
|
"standard::name,standard::type",
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, error);
|
|
|
|
if (!enumerator)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*error == NULL)
|
|
|
|
{
|
|
|
|
GFileInfo *info = g_file_enumerator_next_file (enumerator, NULL, error);
|
|
|
|
if (info == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
GFile *child = g_file_enumerator_get_child (enumerator, info);
|
|
|
|
switch (g_file_info_get_file_type (info))
|
|
|
|
{
|
|
|
|
case G_FILE_TYPE_REGULAR:
|
|
|
|
{
|
|
|
|
const char *name = g_file_info_get_name (info);
|
|
|
|
if (g_str_has_suffix (name, ".metatest"))
|
|
|
|
g_ptr_array_add (results, g_file_get_path (child));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case G_FILE_TYPE_DIRECTORY:
|
|
|
|
find_metatests_in_directory (child, results, error);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (child);
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
if (!g_file_enumerator_close (enumerator, NULL, &tmp_error))
|
|
|
|
{
|
|
|
|
if (*error != NULL)
|
|
|
|
g_clear_error (&tmp_error);
|
|
|
|
else
|
|
|
|
g_propagate_error (error, tmp_error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (enumerator);
|
|
|
|
return *error == NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean all_tests = FALSE;
|
|
|
|
|
|
|
|
const GOptionEntry options[] = {
|
|
|
|
{
|
|
|
|
"all", 0, 0, G_OPTION_ARG_NONE,
|
|
|
|
&all_tests,
|
|
|
|
"Run all installed tests",
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2021-03-02 12:58:17 -05:00
|
|
|
g_autoptr (MetaContext) context = NULL;
|
|
|
|
GPtrArray *tests;
|
|
|
|
RunTestsInfo info;
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-03-03 04:42:26 -05:00
|
|
|
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
|
|
|
|
META_CONTEXT_TEST_FLAG_TEST_CLIENT);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-03-02 12:58:17 -05:00
|
|
|
meta_context_add_option_entries (context, options, NULL);
|
2017-06-26 04:31:48 -04:00
|
|
|
|
2021-03-02 12:58:17 -05:00
|
|
|
g_assert (meta_context_configure (context, &argc, &argv, NULL));
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-03-02 12:58:17 -05:00
|
|
|
tests = g_ptr_array_new ();
|
2014-09-11 13:43:32 -04:00
|
|
|
if (all_tests)
|
|
|
|
{
|
|
|
|
GFile *test_dir = g_file_new_for_path (MUTTER_PKGDATADIR "/tests");
|
2021-03-02 12:58:17 -05:00
|
|
|
g_autoptr (GError) error = NULL;
|
2014-09-11 13:43:32 -04:00
|
|
|
|
|
|
|
if (!find_metatests_in_directory (test_dir, tests, &error))
|
|
|
|
{
|
|
|
|
g_printerr ("Error enumerating tests: %s\n", error->message);
|
2021-03-02 12:58:17 -05:00
|
|
|
return EXIT_FAILURE;
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *curdir = g_get_current_dir ();
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (g_path_is_absolute (argv[i]))
|
|
|
|
g_ptr_array_add (tests, g_strdup (argv[i]));
|
|
|
|
else
|
|
|
|
g_ptr_array_add (tests, g_build_filename (curdir, argv[i], NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (curdir);
|
|
|
|
}
|
|
|
|
|
2021-03-02 12:58:17 -05:00
|
|
|
info.tests = (char **) tests->pdata;
|
2014-09-11 13:43:32 -04:00
|
|
|
info.n_tests = tests->len;
|
2021-03-02 12:58:17 -05:00
|
|
|
g_signal_connect (context, "run-tests", G_CALLBACK (run_tests), &info);
|
2014-09-11 13:43:32 -04:00
|
|
|
|
2021-05-17 06:12:49 -04:00
|
|
|
return meta_context_test_run_tests (META_CONTEXT_TEST (context),
|
|
|
|
META_TEST_RUN_FLAG_NONE);
|
2014-09-11 13:43:32 -04:00
|
|
|
}
|