tests: Add helper for creating virtual test monitors

This uses virtual monitors in the headless backend, in contrast to the
ones used by the monitor configuration tests which use the nseted
backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2262>
This commit is contained in:
Jonas Ådahl 2022-01-28 00:12:59 +01:00 committed by Marge Bot
parent b7f23c1baf
commit 195766cb69
3 changed files with 40 additions and 15 deletions

View File

@ -26,6 +26,7 @@
#include <X11/Xlib-xcb.h>
#include "backends/meta-monitor-config-store.h"
#include "backends/meta-virtual-monitor.h"
#include "core/display-private.h"
#include "core/window-private.h"
#include "meta-test/meta-context-test.h"
@ -645,3 +646,32 @@ meta_wait_for_paint (MetaContext *context)
g_main_context_iteration (NULL, TRUE);
g_signal_handler_disconnect (stage, handler_id);
}
MetaVirtualMonitor *
meta_create_test_monitor (MetaContext *context,
int width,
int height,
float refresh_rate)
{
MetaBackend *backend = meta_context_get_backend (context);
MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend);
g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL;
g_autoptr (GError) error = NULL;
static int serial_count = 0x10000;
g_autofree char *serial = NULL;
MetaVirtualMonitor *virtual_monitor;
serial = g_strdup_printf ("0x%x", serial_count++);
monitor_info = meta_virtual_monitor_info_new (width, height, refresh_rate,
"MetaTestVendor",
"MetaVirtualMonitor",
serial);
virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager,
monitor_info,
&error);
if (!virtual_monitor)
g_error ("Failed to create virtual monitor: %s", error->message);
meta_monitor_manager_reload (monitor_manager);
return virtual_monitor;
}

View File

@ -121,4 +121,10 @@ void meta_set_custom_monitor_config (MetaBackend *backend,
META_EXPORT
void meta_wait_for_paint (MetaContext *context);
META_EXPORT
MetaVirtualMonitor * meta_create_test_monitor (MetaContext *context,
int width,
int height,
float refresh_rate);
#endif /* TEST_UTILS_H */

View File

@ -24,6 +24,7 @@
#include "core/display-private.h"
#include "core/window-private.h"
#include "meta-test/meta-context-test.h"
#include "tests/meta-test-utils.h"
#include "tests/meta-wayland-test-driver.h"
#include "tests/meta-wayland-test-utils.h"
#include "wayland/meta-wayland-surface.h"
@ -365,30 +366,18 @@ toplevel_activation (void)
static void
on_before_tests (void)
{
MetaBackend *backend = meta_context_get_backend (test_context);
MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend);
MetaWaylandCompositor *compositor =
meta_context_get_wayland_compositor (test_context);
g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL;
g_autoptr (GError) error = NULL;
test_driver = meta_wayland_test_driver_new (compositor);
monitor_info = meta_virtual_monitor_info_new (400, 400, 60.0,
"MetaTestVendor",
"MetaVirtualMonitor",
"0x1234");
virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager,
monitor_info,
&error);
if (!virtual_monitor)
g_error ("Failed to create virtual monitor: %s", error->message);
meta_monitor_manager_reload (monitor_manager);
virtual_monitor = meta_create_test_monitor (test_context,
400, 400, 60.0);
}
static void
on_after_tests (void)
{
g_clear_object (&test_driver);
g_clear_object (&virtual_monitor);
}