mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 17:40:40 -05:00
tests/wayland-unit-tests: Order unit test categories alphabetically
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3394>
This commit is contained in:
parent
c0952f02e7
commit
3897bf68f7
@ -77,6 +77,202 @@ buffer_single_pixel_buffer (void)
|
||||
meta_wayland_test_client_finish (wayland_test_client);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_true (gpointer user_data)
|
||||
{
|
||||
gboolean *done = user_data;
|
||||
|
||||
*done = TRUE;
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
idle_inhibit_instant_destroy (void)
|
||||
{
|
||||
MetaWaylandTestClient *wayland_test_client;
|
||||
gboolean done;
|
||||
|
||||
wayland_test_client =
|
||||
meta_wayland_test_client_new (test_context, "idle-inhibit");
|
||||
meta_wayland_test_client_finish (wayland_test_client);
|
||||
|
||||
done = FALSE;
|
||||
g_timeout_add_seconds (1, set_true, &done);
|
||||
while (!done)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
}
|
||||
|
||||
static MetaWaylandAccess
|
||||
dummy_global_filter (const struct wl_client *client,
|
||||
const struct wl_global *global,
|
||||
gpointer user_data)
|
||||
{
|
||||
MetaWaylandClient *allowed_client = META_WAYLAND_CLIENT (user_data);
|
||||
|
||||
if (g_object_get_data (G_OBJECT (allowed_client),
|
||||
"test-client-destroyed"))
|
||||
return META_WAYLAND_ACCESS_DENIED;
|
||||
else if (meta_wayland_client_matches (allowed_client, client))
|
||||
return META_WAYLAND_ACCESS_ALLOWED;
|
||||
else
|
||||
return META_WAYLAND_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
static void
|
||||
dummy_bind (struct wl_client *client,
|
||||
void *data,
|
||||
uint32_t version,
|
||||
uint32_t id)
|
||||
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
handle_registry_global (void *user_data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t id,
|
||||
const char *interface,
|
||||
uint32_t version)
|
||||
{
|
||||
gboolean *global_seen = user_data;
|
||||
|
||||
if (strcmp (interface, dummy_interface.name) == 0)
|
||||
*global_seen = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_registry_global_remove (void *user_data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t name)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
handle_registry_global,
|
||||
handle_registry_global_remove
|
||||
};
|
||||
|
||||
static gpointer
|
||||
test_client_thread_func (gpointer user_data)
|
||||
{
|
||||
int fd = GPOINTER_TO_INT (user_data);
|
||||
struct wl_display *wl_display;
|
||||
struct wl_registry *wl_registry;
|
||||
gboolean global_seen = FALSE;
|
||||
|
||||
wl_display = wl_display_connect_to_fd (fd);
|
||||
g_assert_nonnull (wl_display);
|
||||
|
||||
wl_registry = wl_display_get_registry (wl_display);
|
||||
wl_registry_add_listener (wl_registry, ®istry_listener, &global_seen);
|
||||
wl_display_roundtrip (wl_display);
|
||||
wl_registry_destroy (wl_registry);
|
||||
|
||||
wl_display_disconnect (wl_display);
|
||||
|
||||
return GINT_TO_POINTER (global_seen);
|
||||
}
|
||||
|
||||
static void
|
||||
on_client_destroyed (MetaWaylandClient *client,
|
||||
gboolean *client_destroyed)
|
||||
{
|
||||
*client_destroyed = TRUE;
|
||||
g_object_set_data (G_OBJECT (client), "test-client-destroyed",
|
||||
GINT_TO_POINTER (TRUE));
|
||||
}
|
||||
|
||||
static void
|
||||
registry_filter (void)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaWaylandCompositor *wayland_compositor =
|
||||
meta_context_get_wayland_compositor (test_context);
|
||||
MetaWaylandFilterManager *filter_manager =
|
||||
meta_wayland_compositor_get_filter_manager (wayland_compositor);
|
||||
struct wl_display *wayland_display =
|
||||
meta_wayland_compositor_get_wayland_display (wayland_compositor);
|
||||
struct wl_global *dummy_global;
|
||||
int fd;
|
||||
g_autoptr (MetaWaylandClient) client1 = NULL;
|
||||
g_autoptr (MetaWaylandClient) client2 = NULL;
|
||||
g_autoptr (MetaWaylandClient) client3 = NULL;
|
||||
GThread *thread1;
|
||||
GThread *thread2;
|
||||
GThread *thread3;
|
||||
gboolean client1_destroyed = FALSE;
|
||||
gboolean client2_destroyed = FALSE;
|
||||
gboolean client3_destroyed = FALSE;
|
||||
gboolean client1_saw_global;
|
||||
gboolean client2_saw_global;
|
||||
gboolean client3_saw_global;
|
||||
|
||||
client1 = meta_wayland_client_new_indirect (test_context, &error);
|
||||
g_assert_nonnull (client1);
|
||||
g_assert_null (error);
|
||||
client2 = meta_wayland_client_new_indirect (test_context, &error);
|
||||
g_assert_nonnull (client2);
|
||||
g_assert_null (error);
|
||||
client3 = meta_wayland_client_new_indirect (test_context, &error);
|
||||
g_assert_nonnull (client3);
|
||||
g_assert_null (error);
|
||||
|
||||
g_signal_connect (client1, "client-destroyed",
|
||||
G_CALLBACK (on_client_destroyed), &client1_destroyed);
|
||||
g_signal_connect (client2, "client-destroyed",
|
||||
G_CALLBACK (on_client_destroyed), &client2_destroyed);
|
||||
g_signal_connect (client3, "client-destroyed",
|
||||
G_CALLBACK (on_client_destroyed), &client3_destroyed);
|
||||
|
||||
dummy_global = wl_global_create (wayland_display,
|
||||
&dummy_interface,
|
||||
1, NULL, dummy_bind);
|
||||
meta_wayland_filter_manager_add_global (filter_manager,
|
||||
dummy_global,
|
||||
dummy_global_filter,
|
||||
client1);
|
||||
|
||||
fd = meta_wayland_client_setup_fd (client1, &error);
|
||||
g_assert_cmpint (fd, >=, 0);
|
||||
g_assert_null (error);
|
||||
thread1 = g_thread_new ("test client thread 1",
|
||||
test_client_thread_func,
|
||||
GINT_TO_POINTER (fd));
|
||||
|
||||
fd = meta_wayland_client_setup_fd (client2, &error);
|
||||
g_assert_cmpint (fd, >=, 0);
|
||||
g_assert_null (error);
|
||||
thread2 = g_thread_new ("test client thread 2",
|
||||
test_client_thread_func,
|
||||
GINT_TO_POINTER (fd));
|
||||
|
||||
while (!client1_destroyed || !client2_destroyed)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
||||
client1_saw_global = GPOINTER_TO_INT (g_thread_join (thread1));
|
||||
client2_saw_global = GPOINTER_TO_INT (g_thread_join (thread2));
|
||||
|
||||
g_assert_true (client1_saw_global);
|
||||
g_assert_false (client2_saw_global);
|
||||
|
||||
meta_wayland_filter_manager_remove_global (filter_manager, dummy_global);
|
||||
wl_global_destroy (dummy_global);
|
||||
|
||||
fd = meta_wayland_client_setup_fd (client3, &error);
|
||||
g_assert_cmpint (fd, >=, 0);
|
||||
g_assert_null (error);
|
||||
thread3 = g_thread_new ("test client thread 3",
|
||||
test_client_thread_func,
|
||||
GINT_TO_POINTER (fd));
|
||||
while (!client3_destroyed)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
||||
client3_saw_global = GPOINTER_TO_INT (g_thread_join (thread3));
|
||||
g_assert_false (client3_saw_global);
|
||||
}
|
||||
|
||||
static void
|
||||
subsurface_corner_cases (void)
|
||||
{
|
||||
@ -634,202 +830,6 @@ xdg_foreign_set_parent_of (void)
|
||||
meta_wayland_test_client_finish (wayland_test_client);
|
||||
}
|
||||
|
||||
static MetaWaylandAccess
|
||||
dummy_global_filter (const struct wl_client *client,
|
||||
const struct wl_global *global,
|
||||
gpointer user_data)
|
||||
{
|
||||
MetaWaylandClient *allowed_client = META_WAYLAND_CLIENT (user_data);
|
||||
|
||||
if (g_object_get_data (G_OBJECT (allowed_client),
|
||||
"test-client-destroyed"))
|
||||
return META_WAYLAND_ACCESS_DENIED;
|
||||
else if (meta_wayland_client_matches (allowed_client, client))
|
||||
return META_WAYLAND_ACCESS_ALLOWED;
|
||||
else
|
||||
return META_WAYLAND_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
static void
|
||||
dummy_bind (struct wl_client *client,
|
||||
void *data,
|
||||
uint32_t version,
|
||||
uint32_t id)
|
||||
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
handle_registry_global (void *user_data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t id,
|
||||
const char *interface,
|
||||
uint32_t version)
|
||||
{
|
||||
gboolean *global_seen = user_data;
|
||||
|
||||
if (strcmp (interface, dummy_interface.name) == 0)
|
||||
*global_seen = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_registry_global_remove (void *user_data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t name)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
handle_registry_global,
|
||||
handle_registry_global_remove
|
||||
};
|
||||
|
||||
static gpointer
|
||||
test_client_thread_func (gpointer user_data)
|
||||
{
|
||||
int fd = GPOINTER_TO_INT (user_data);
|
||||
struct wl_display *wl_display;
|
||||
struct wl_registry *wl_registry;
|
||||
gboolean global_seen = FALSE;
|
||||
|
||||
wl_display = wl_display_connect_to_fd (fd);
|
||||
g_assert_nonnull (wl_display);
|
||||
|
||||
wl_registry = wl_display_get_registry (wl_display);
|
||||
wl_registry_add_listener (wl_registry, ®istry_listener, &global_seen);
|
||||
wl_display_roundtrip (wl_display);
|
||||
wl_registry_destroy (wl_registry);
|
||||
|
||||
wl_display_disconnect (wl_display);
|
||||
|
||||
return GINT_TO_POINTER (global_seen);
|
||||
}
|
||||
|
||||
static void
|
||||
on_client_destroyed (MetaWaylandClient *client,
|
||||
gboolean *client_destroyed)
|
||||
{
|
||||
*client_destroyed = TRUE;
|
||||
g_object_set_data (G_OBJECT (client), "test-client-destroyed",
|
||||
GINT_TO_POINTER (TRUE));
|
||||
}
|
||||
|
||||
static void
|
||||
registry_filter (void)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaWaylandCompositor *wayland_compositor =
|
||||
meta_context_get_wayland_compositor (test_context);
|
||||
MetaWaylandFilterManager *filter_manager =
|
||||
meta_wayland_compositor_get_filter_manager (wayland_compositor);
|
||||
struct wl_display *wayland_display =
|
||||
meta_wayland_compositor_get_wayland_display (wayland_compositor);
|
||||
struct wl_global *dummy_global;
|
||||
int fd;
|
||||
g_autoptr (MetaWaylandClient) client1 = NULL;
|
||||
g_autoptr (MetaWaylandClient) client2 = NULL;
|
||||
g_autoptr (MetaWaylandClient) client3 = NULL;
|
||||
GThread *thread1;
|
||||
GThread *thread2;
|
||||
GThread *thread3;
|
||||
gboolean client1_destroyed = FALSE;
|
||||
gboolean client2_destroyed = FALSE;
|
||||
gboolean client3_destroyed = FALSE;
|
||||
gboolean client1_saw_global;
|
||||
gboolean client2_saw_global;
|
||||
gboolean client3_saw_global;
|
||||
|
||||
client1 = meta_wayland_client_new_indirect (test_context, &error);
|
||||
g_assert_nonnull (client1);
|
||||
g_assert_null (error);
|
||||
client2 = meta_wayland_client_new_indirect (test_context, &error);
|
||||
g_assert_nonnull (client2);
|
||||
g_assert_null (error);
|
||||
client3 = meta_wayland_client_new_indirect (test_context, &error);
|
||||
g_assert_nonnull (client3);
|
||||
g_assert_null (error);
|
||||
|
||||
g_signal_connect (client1, "client-destroyed",
|
||||
G_CALLBACK (on_client_destroyed), &client1_destroyed);
|
||||
g_signal_connect (client2, "client-destroyed",
|
||||
G_CALLBACK (on_client_destroyed), &client2_destroyed);
|
||||
g_signal_connect (client3, "client-destroyed",
|
||||
G_CALLBACK (on_client_destroyed), &client3_destroyed);
|
||||
|
||||
dummy_global = wl_global_create (wayland_display,
|
||||
&dummy_interface,
|
||||
1, NULL, dummy_bind);
|
||||
meta_wayland_filter_manager_add_global (filter_manager,
|
||||
dummy_global,
|
||||
dummy_global_filter,
|
||||
client1);
|
||||
|
||||
fd = meta_wayland_client_setup_fd (client1, &error);
|
||||
g_assert_cmpint (fd, >=, 0);
|
||||
g_assert_null (error);
|
||||
thread1 = g_thread_new ("test client thread 1",
|
||||
test_client_thread_func,
|
||||
GINT_TO_POINTER (fd));
|
||||
|
||||
fd = meta_wayland_client_setup_fd (client2, &error);
|
||||
g_assert_cmpint (fd, >=, 0);
|
||||
g_assert_null (error);
|
||||
thread2 = g_thread_new ("test client thread 2",
|
||||
test_client_thread_func,
|
||||
GINT_TO_POINTER (fd));
|
||||
|
||||
while (!client1_destroyed || !client2_destroyed)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
||||
client1_saw_global = GPOINTER_TO_INT (g_thread_join (thread1));
|
||||
client2_saw_global = GPOINTER_TO_INT (g_thread_join (thread2));
|
||||
|
||||
g_assert_true (client1_saw_global);
|
||||
g_assert_false (client2_saw_global);
|
||||
|
||||
meta_wayland_filter_manager_remove_global (filter_manager, dummy_global);
|
||||
wl_global_destroy (dummy_global);
|
||||
|
||||
fd = meta_wayland_client_setup_fd (client3, &error);
|
||||
g_assert_cmpint (fd, >=, 0);
|
||||
g_assert_null (error);
|
||||
thread3 = g_thread_new ("test client thread 3",
|
||||
test_client_thread_func,
|
||||
GINT_TO_POINTER (fd));
|
||||
while (!client3_destroyed)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
|
||||
client3_saw_global = GPOINTER_TO_INT (g_thread_join (thread3));
|
||||
g_assert_false (client3_saw_global);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_true (gpointer user_data)
|
||||
{
|
||||
gboolean *done = user_data;
|
||||
|
||||
*done = TRUE;
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
idle_inhibit_instant_destroy (void)
|
||||
{
|
||||
MetaWaylandTestClient *wayland_test_client;
|
||||
gboolean done;
|
||||
|
||||
wayland_test_client =
|
||||
meta_wayland_test_client_new (test_context, "idle-inhibit");
|
||||
meta_wayland_test_client_finish (wayland_test_client);
|
||||
|
||||
done = FALSE;
|
||||
g_timeout_add_seconds (1, set_true, &done);
|
||||
while (!done)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
on_before_tests (void)
|
||||
{
|
||||
@ -855,6 +855,10 @@ init_tests (void)
|
||||
buffer_transform);
|
||||
g_test_add_func ("/wayland/buffer/single-pixel-buffer",
|
||||
buffer_single_pixel_buffer);
|
||||
g_test_add_func ("/wayland/idle-inhibit/instant-destroy",
|
||||
idle_inhibit_instant_destroy);
|
||||
g_test_add_func ("/wayland/registry/filter",
|
||||
registry_filter);
|
||||
g_test_add_func ("/wayland/subsurface/remap-toplevel",
|
||||
subsurface_remap_toplevel);
|
||||
g_test_add_func ("/wayland/subsurface/reparent",
|
||||
@ -877,10 +881,6 @@ init_tests (void)
|
||||
toplevel_bounds_monitors);
|
||||
g_test_add_func ("/wayland/xdg-foreign/set-parent-of",
|
||||
xdg_foreign_set_parent_of);
|
||||
g_test_add_func ("/wayland/registry/filter",
|
||||
registry_filter);
|
||||
g_test_add_func ("/wayland/idle-inhibit/instant-destroy",
|
||||
idle_inhibit_instant_destroy);
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user