mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 01:20:42 -05:00
tests: Move 'wait-for-X11-display' helper to MetaContextTest
Gets rid of a un-prefixed helper function relying on a global singleton. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
parent
e8742be568
commit
724a7eee74
@ -22,6 +22,7 @@
|
|||||||
#define META_CONTEXT_PRIVATE_H
|
#define META_CONTEXT_PRIVATE_H
|
||||||
|
|
||||||
#include "core/meta-private-enums.h"
|
#include "core/meta-private-enums.h"
|
||||||
|
#include "core/util-private.h"
|
||||||
#include "meta/meta-backend.h"
|
#include "meta/meta-backend.h"
|
||||||
#include "meta/meta-context.h"
|
#include "meta/meta-context.h"
|
||||||
#include "wayland/meta-wayland-types.h"
|
#include "wayland/meta-wayland-types.h"
|
||||||
@ -54,6 +55,7 @@ const char * meta_context_get_name (MetaContext *context);
|
|||||||
|
|
||||||
const char * meta_context_get_gnome_wm_keybindings (MetaContext *context);
|
const char * meta_context_get_gnome_wm_keybindings (MetaContext *context);
|
||||||
|
|
||||||
|
META_EXPORT_TEST
|
||||||
MetaWaylandCompositor * meta_context_get_wayland_compositor (MetaContext *context);
|
MetaWaylandCompositor * meta_context_get_wayland_compositor (MetaContext *context);
|
||||||
|
|
||||||
MetaX11DisplayPolicy meta_context_get_x11_display_policy (MetaContext *context);
|
MetaX11DisplayPolicy meta_context_get_x11_display_policy (MetaContext *context);
|
||||||
|
@ -256,6 +256,17 @@ meta_context_test_run_tests (MetaContextTest *context_test)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
meta_context_test_wait_for_x11_display (MetaContextTest *context_test)
|
||||||
|
{
|
||||||
|
MetaDisplay *display = meta_context_get_display (META_CONTEXT (context_test));
|
||||||
|
|
||||||
|
while (!meta_display_get_x11_display (display))
|
||||||
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
|
g_assert_nonnull (meta_display_get_x11_display (display));
|
||||||
|
}
|
||||||
|
|
||||||
MetaContext *
|
MetaContext *
|
||||||
meta_create_test_context (MetaContextTestType type,
|
meta_create_test_context (MetaContextTestType type,
|
||||||
MetaContextTestFlag flags)
|
MetaContextTestFlag flags)
|
||||||
|
@ -49,4 +49,7 @@ MetaContext * meta_create_test_context (MetaContextTestType type,
|
|||||||
|
|
||||||
int meta_context_test_run_tests (MetaContextTest *context_test);
|
int meta_context_test_run_tests (MetaContextTest *context_test);
|
||||||
|
|
||||||
|
META_EXPORT
|
||||||
|
void meta_context_test_wait_for_x11_display (MetaContextTest *context_test);
|
||||||
|
|
||||||
#endif /* META_CONTEXT_TEST_H */
|
#endif /* META_CONTEXT_TEST_H */
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "core/display-private.h"
|
#include "core/display-private.h"
|
||||||
#include "core/window-private.h"
|
#include "core/window-private.h"
|
||||||
|
#include "tests/meta-context-test.h"
|
||||||
#include "wayland/meta-wayland.h"
|
#include "wayland/meta-wayland.h"
|
||||||
#include "wayland/meta-xwayland.h"
|
#include "wayland/meta-xwayland.h"
|
||||||
#include "x11/meta-x11-display-private.h"
|
#include "x11/meta-x11-display-private.h"
|
||||||
@ -437,7 +438,8 @@ spawn_xwayland (gpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MetaTestClient *
|
MetaTestClient *
|
||||||
meta_test_client_new (const char *id,
|
meta_test_client_new (MetaContext *context,
|
||||||
|
const char *id,
|
||||||
MetaWindowClientType type,
|
MetaWindowClientType type,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
@ -452,7 +454,7 @@ meta_test_client_new (const char *id,
|
|||||||
G_SUBPROCESS_FLAGS_STDOUT_PIPE));
|
G_SUBPROCESS_FLAGS_STDOUT_PIPE));
|
||||||
|
|
||||||
g_assert (meta_is_wayland_compositor ());
|
g_assert (meta_is_wayland_compositor ());
|
||||||
compositor = meta_wayland_compositor_get_default ();
|
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);
|
||||||
x11_display_name = meta_wayland_get_public_xwayland_display_name (compositor);
|
x11_display_name = meta_wayland_get_public_xwayland_display_name (compositor);
|
||||||
|
|
||||||
@ -498,7 +500,7 @@ meta_test_client_new (const char *id,
|
|||||||
thread = g_thread_new ("Mutter Spawn Xwayland Thread",
|
thread = g_thread_new ("Mutter Spawn Xwayland Thread",
|
||||||
spawn_xwayland,
|
spawn_xwayland,
|
||||||
NULL);
|
NULL);
|
||||||
test_wait_for_x11_display ();
|
meta_context_test_wait_for_x11_display (META_CONTEXT_TEST (context));
|
||||||
g_thread_join (thread);
|
g_thread_join (thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,17 +565,3 @@ meta_test_get_plugin_name (void)
|
|||||||
else
|
else
|
||||||
return "libdefault";
|
return "libdefault";
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
test_wait_for_x11_display (void)
|
|
||||||
{
|
|
||||||
MetaDisplay *display;
|
|
||||||
|
|
||||||
display = meta_get_display ();
|
|
||||||
g_assert_nonnull (display);
|
|
||||||
|
|
||||||
while (!display->x11_display)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
g_assert_nonnull (display->x11_display);
|
|
||||||
}
|
|
||||||
|
@ -73,7 +73,8 @@ void meta_test_client_wait_for_window_shown (MetaTestClient *client,
|
|||||||
gboolean meta_test_client_quit (MetaTestClient *client,
|
gboolean meta_test_client_quit (MetaTestClient *client,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
MetaTestClient * meta_test_client_new (const char *id,
|
MetaTestClient * meta_test_client_new (MetaContext *context,
|
||||||
|
const char *id,
|
||||||
MetaWindowClientType type,
|
MetaWindowClientType type,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
@ -81,8 +82,6 @@ void meta_test_client_destroy (MetaTestClient *client);
|
|||||||
|
|
||||||
const char * meta_test_get_plugin_name (void);
|
const char * meta_test_get_plugin_name (void);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "tests/meta-monitor-manager-test.h"
|
#include "tests/meta-monitor-manager-test.h"
|
||||||
#include "tests/monitor-test-utils.h"
|
#include "tests/monitor-test-utils.h"
|
||||||
#include "tests/meta-test-utils.h"
|
#include "tests/meta-test-utils.h"
|
||||||
|
#include "tests/unit-tests.h"
|
||||||
#include "x11/meta-x11-display-private.h"
|
#include "x11/meta-x11-display-private.h"
|
||||||
|
|
||||||
static MonitorTestCase initial_test_case = {
|
static MonitorTestCase initial_test_case = {
|
||||||
@ -175,17 +176,19 @@ monitor_tests_alarm_filter (MetaX11Display *x11_display,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
create_monitor_test_clients (void)
|
create_monitor_test_clients (MetaContext *context)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
wayland_monitor_test_client = meta_test_client_new (WAYLAND_TEST_CLIENT_NAME,
|
wayland_monitor_test_client = meta_test_client_new (context,
|
||||||
|
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 = meta_test_client_new (X11_TEST_CLIENT_NAME,
|
x11_monitor_test_client = meta_test_client_new (context,
|
||||||
|
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)
|
||||||
@ -5482,7 +5485,8 @@ dispatch (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static MetaTestClient *
|
static MetaTestClient *
|
||||||
create_test_window (const char *window_name)
|
create_test_window (MetaContext *context,
|
||||||
|
const char *window_name)
|
||||||
{
|
{
|
||||||
MetaTestClient *test_client;
|
MetaTestClient *test_client;
|
||||||
static int client_count = 0;
|
static int client_count = 0;
|
||||||
@ -5490,7 +5494,8 @@ create_test_window (const char *window_name)
|
|||||||
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 = meta_test_client_new (client_name, META_WINDOW_CLIENT_TYPE_WAYLAND,
|
test_client = meta_test_client_new (context,
|
||||||
|
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);
|
||||||
@ -5506,6 +5511,7 @@ create_test_window (const char *window_name)
|
|||||||
static void
|
static void
|
||||||
meta_test_monitor_wm_tiling (void)
|
meta_test_monitor_wm_tiling (void)
|
||||||
{
|
{
|
||||||
|
MetaContext *context = test_context;
|
||||||
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;
|
||||||
@ -5523,7 +5529,7 @@ meta_test_monitor_wm_tiling (void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const char *test_window_name= "window1";
|
const char *test_window_name= "window1";
|
||||||
test_client = create_test_window (test_window_name);
|
test_client = create_test_window (context, test_window_name);
|
||||||
|
|
||||||
if (!meta_test_client_do (test_client, &error,
|
if (!meta_test_client_do (test_client, &error,
|
||||||
"show", test_window_name,
|
"show", test_window_name,
|
||||||
@ -5850,9 +5856,9 @@ init_monitor_tests (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pre_run_monitor_tests (void)
|
pre_run_monitor_tests (MetaContext *context)
|
||||||
{
|
{
|
||||||
create_monitor_test_clients ();
|
create_monitor_test_clients (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -27,7 +27,7 @@ typedef struct _MonitorTestCase MonitorTestCase;
|
|||||||
|
|
||||||
void init_monitor_tests (void);
|
void init_monitor_tests (void);
|
||||||
|
|
||||||
void pre_run_monitor_tests (void);
|
void pre_run_monitor_tests (MetaContext *context);
|
||||||
|
|
||||||
void finish_monitor_tests (void);
|
void finish_monitor_tests (void);
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "x11/meta-x11-display-private.h"
|
#include "x11/meta-x11-display-private.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
MetaContext *context;
|
||||||
GHashTable *clients;
|
GHashTable *clients;
|
||||||
MetaAsyncWaiter *waiter;
|
MetaAsyncWaiter *waiter;
|
||||||
GString *warning_messages;
|
GString *warning_messages;
|
||||||
@ -75,14 +76,14 @@ on_x11_display_opened (MetaDisplay *display,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static TestCase *
|
static TestCase *
|
||||||
test_case_new (void)
|
test_case_new (MetaContext *context)
|
||||||
{
|
{
|
||||||
TestCase *test = g_new0 (TestCase, 1);
|
TestCase *test = g_new0 (TestCase, 1);
|
||||||
MetaDisplay *display = meta_get_display ();
|
MetaDisplay *display = meta_context_get_display (context);
|
||||||
|
|
||||||
if (!meta_is_wayland_compositor ())
|
if (!meta_is_wayland_compositor ())
|
||||||
{
|
{
|
||||||
test_wait_for_x11_display ();
|
meta_context_test_wait_for_x11_display (META_CONTEXT_TEST (context));
|
||||||
on_x11_display_opened (display, test);
|
on_x11_display_opened (display, test);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -96,6 +97,7 @@ test_case_new (void)
|
|||||||
test);
|
test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test->context = context;
|
||||||
test->clients = g_hash_table_new (g_str_hash, g_str_equal);
|
test->clients = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
test->loop = g_main_loop_new (NULL, FALSE);
|
test->loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
@ -485,7 +487,7 @@ 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 = meta_test_client_new (argv[1], type, error);
|
client = meta_test_client_new (test->context, argv[1], type, error);
|
||||||
if (!client)
|
if (!client)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -953,10 +955,11 @@ test_case_destroy (TestCase *test,
|
|||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
run_test (const char *filename,
|
run_test (MetaContext *context,
|
||||||
|
const char *filename,
|
||||||
int index)
|
int index)
|
||||||
{
|
{
|
||||||
TestCase *test = test_case_new ();
|
TestCase *test = test_case_new (context);
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
GFile *file = g_file_new_for_path (filename);
|
GFile *file = g_file_new_for_path (filename);
|
||||||
@ -1074,7 +1077,7 @@ run_tests (MetaContext *context,
|
|||||||
|
|
||||||
for (i = 0; i < info->n_tests; i++)
|
for (i = 0; i < info->n_tests; i++)
|
||||||
{
|
{
|
||||||
if (!run_test (info->tests[i], i + 1))
|
if (!run_test (context, info->tests[i], i + 1))
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "tests/unit-tests.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -35,6 +37,8 @@
|
|||||||
#include "tests/monitor-transform-tests.h"
|
#include "tests/monitor-transform-tests.h"
|
||||||
#include "tests/wayland-unit-tests.h"
|
#include "tests/wayland-unit-tests.h"
|
||||||
|
|
||||||
|
MetaContext *test_context;
|
||||||
|
|
||||||
typedef struct _MetaTestLaterOrderCallbackData
|
typedef struct _MetaTestLaterOrderCallbackData
|
||||||
{
|
{
|
||||||
GMainLoop *loop; /* Loop to terminate when done. */
|
GMainLoop *loop; /* Loop to terminate when done. */
|
||||||
@ -239,6 +243,8 @@ main (int argc, char *argv[])
|
|||||||
META_CONTEXT_TEST_FLAG_TEST_CLIENT);
|
META_CONTEXT_TEST_FLAG_TEST_CLIENT);
|
||||||
g_assert (meta_context_configure (context, &argc, &argv, NULL));
|
g_assert (meta_context_configure (context, &argc, &argv, NULL));
|
||||||
|
|
||||||
|
test_context = context;
|
||||||
|
|
||||||
init_tests ();
|
init_tests ();
|
||||||
|
|
||||||
g_signal_connect (context, "before-tests",
|
g_signal_connect (context, "before-tests",
|
||||||
|
25
src/tests/unit-tests.h
Normal file
25
src/tests/unit-tests.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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 UNIT_TESTS_H
|
||||||
|
#define UNIT_TESTS_H
|
||||||
|
|
||||||
|
#include "meta/meta-context.h"
|
||||||
|
|
||||||
|
extern MetaContext *test_context;
|
||||||
|
|
||||||
|
#endif /* UNIT_TESTS_H */
|
Loading…
Reference in New Issue
Block a user