tests/wayland: Replace wl_display_dispatch() with helper

In most cases, we just want to fail the test if dispatching fails, so
add a helper that does that.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3475>
This commit is contained in:
Jonas Ådahl 2024-03-25 13:17:46 +01:00 committed by Marge Bot
parent 4d8f6af487
commit 69c7ca02f4
18 changed files with 30 additions and 84 deletions

View File

@ -140,10 +140,7 @@ wait_for_configure (WaylandDisplay *display)
{ {
waiting_for_configure = TRUE; waiting_for_configure = TRUE;
while (waiting_for_configure || window_width == 0) while (waiting_for_configure || window_width == 0)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
exit (EXIT_FAILURE);
}
} }
int int

View File

@ -242,10 +242,7 @@ main (int argc,
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
g_list_free_full (active_buffers, (GDestroyNotify) g_object_unref); g_list_free_full (active_buffers, (GDestroyNotify) g_object_unref);

View File

@ -177,10 +177,7 @@ main (int argc,
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
wl_display_roundtrip (display->display); wl_display_roundtrip (display->display);

View File

@ -97,10 +97,7 @@ main (int argc,
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
wl_display_roundtrip (display->display); wl_display_roundtrip (display->display);

View File

@ -279,10 +279,7 @@ main (int argc,
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -88,10 +88,7 @@ main (int argc,
wl_surface_commit (surface->wl_surface); wl_surface_commit (surface->wl_surface);
while (last_sync_event != 1) while (last_sync_event != 1)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
g_object_unref (surface); g_object_unref (surface);
g_object_unref (display); g_object_unref (display);

View File

@ -89,10 +89,7 @@ wait_for_configure (WaylandDisplay *display)
{ {
waiting_for_configure = TRUE; waiting_for_configure = TRUE;
while (waiting_for_configure || window_width == 0) while (waiting_for_configure || window_width == 0)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
exit (EXIT_FAILURE);
}
} }
static void static void
@ -111,10 +108,7 @@ static void
wait_for_buffer_released (WaylandDisplay *display) wait_for_buffer_released (WaylandDisplay *display)
{ {
while (buffer) while (buffer)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
g_error ("%s: Failed to dispatch Wayland display", __func__);
}
} }
int int

View File

@ -114,10 +114,7 @@ wait_for_configure (WaylandDisplay *display)
{ {
waiting_for_configure = TRUE; waiting_for_configure = TRUE;
while (waiting_for_configure || window_width == 0) while (waiting_for_configure || window_width == 0)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
exit (EXIT_FAILURE);
}
} }
int int

View File

@ -337,10 +337,7 @@ main (int argc,
wl_subsurface_set_desync (subsurface); wl_subsurface_set_desync (subsurface);
while (TRUE) while (TRUE)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -209,10 +209,7 @@ main (int argc,
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -204,10 +204,7 @@ main (int argc,
state = STATE_WAIT_FOR_CONFIGURE_1; state = STATE_WAIT_FOR_CONFIGURE_1;
while (TRUE) while (TRUE)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -426,6 +426,13 @@ wayland_display_new (WaylandDisplayCapabilities capabilities)
wl_display_connect (NULL)); wl_display_connect (NULL));
} }
void
wayland_display_dispatch (WaylandDisplay *display)
{
if (wl_display_dispatch (display->display) == -1)
g_error ("wl_display_dispatch failed");
}
static void static void
wayland_display_finalize (GObject *object) wayland_display_finalize (GObject *object)
{ {
@ -632,10 +639,7 @@ wait_for_effects_completed (WaylandDisplay *display,
NULL); NULL);
while (effects_complete_callback) while (effects_complete_callback)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
g_error ("%s: Failed to dispatch Wayland display", __func__);
}
} }
static void static void
@ -688,10 +692,7 @@ wait_for_view_verified (WaylandDisplay *display,
&view_verification_listener, NULL); &view_verification_listener, NULL);
while (view_verification_callback) while (view_verification_callback)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
g_error ("%s: Failed to dispatch Wayland display", __func__);
}
} }
static void static void
@ -711,10 +712,7 @@ wait_for_sync_event (WaylandDisplay *display,
handler_id = g_signal_connect (display, "sync-event", G_CALLBACK (on_sync_event), NULL); handler_id = g_signal_connect (display, "sync-event", G_CALLBACK (on_sync_event), NULL);
while (expected_serial + 1 > display->sync_event_serial_next) while (expected_serial + 1 > display->sync_event_serial_next)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
g_error ("%s: Failed to dispatch Wayland display", __func__);
}
g_signal_handler_disconnect (display, handler_id); g_signal_handler_disconnect (display, handler_id);
} }

View File

@ -95,6 +95,8 @@ WaylandDisplay * wayland_display_new (WaylandDisplayCapabilities capabilities);
WaylandDisplay * wayland_display_new_full (WaylandDisplayCapabilities capabilities, WaylandDisplay * wayland_display_new_full (WaylandDisplayCapabilities capabilities,
struct wl_display *wayland_display); struct wl_display *wayland_display);
void wayland_display_dispatch (WaylandDisplay *display);
WaylandSurface * wayland_surface_new (WaylandDisplay *display, WaylandSurface * wayland_surface_new (WaylandDisplay *display,
const char *title, const char *title,
int default_width, int default_width,

View File

@ -178,10 +178,7 @@ test_startup_notifications (void)
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return;
}
wl_display_roundtrip (display->display); wl_display_roundtrip (display->display);

View File

@ -221,10 +221,7 @@ main (int argc,
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -171,10 +171,7 @@ main (int argc,
zxdg_exported_v2_add_listener (exported3, &exported_v2_listener, &handle3); zxdg_exported_v2_add_listener (exported3, &exported_v2_listener, &handle3);
while (!handle1 && !handle3) while (!handle1 && !handle3)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
zxdg_importer_v2_import_toplevel (importer_v2, "don't crash on bogus handle"); zxdg_importer_v2_import_toplevel (importer_v2, "don't crash on bogus handle");
zxdg_importer_v1_import (importer_v1, "don't crash on bogus handle"); zxdg_importer_v1_import (importer_v1, "don't crash on bogus handle");
@ -216,10 +213,7 @@ main (int argc,
zxdg_exported_v2_destroy (exported3); zxdg_exported_v2_destroy (exported3);
while (!imported1_destroyed || !imported3_destroyed) while (!imported1_destroyed || !imported3_destroyed)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -177,10 +177,7 @@ main (int argc,
running = TRUE; running = TRUE;
while (running) while (running)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -183,10 +183,7 @@ wait_for_configure (WaylandDisplay *display)
{ {
waiting_for_configure = TRUE; waiting_for_configure = TRUE;
while (waiting_for_configure) while (waiting_for_configure)
{ wayland_display_dispatch (display);
if (wl_display_dispatch (display->display) == -1)
exit (EXIT_FAILURE);
}
} }
int int