From 58e89b3a5deee361fe9a5c9eb2fd645fa3320724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 16 Nov 2022 20:16:46 +0100 Subject: [PATCH] tests/clutter: Use the headless backend One test depends on a pointer event having been emitted so that the stage has a focused pointer; make sure that has happened. Part-of: --- src/tests/clutter-test-utils.c | 32 +++++++++++++++++--- src/tests/clutter/conform/actor-event-hold.c | 11 ++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/tests/clutter-test-utils.c b/src/tests/clutter-test-utils.c index de4b94e23..1fe32c4ab 100644 --- a/src/tests/clutter-test-utils.c +++ b/src/tests/clutter-test-utils.c @@ -4,11 +4,14 @@ #include #include +#include "backends/meta-monitor-manager-private.h" +#include "backends/meta-virtual-monitor.h" #include "compositor/meta-plugin-manager.h" #include "core/meta-context-private.h" -typedef struct { - gpointer dummy_field; +typedef struct +{ + MetaContext *context; } ClutterTestEnvironment; static ClutterTestEnvironment *test_environ = NULL; @@ -46,12 +49,13 @@ clutter_test_init (int *argc, { MetaContext *context; - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, + context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS, META_CONTEXT_TEST_FLAG_NO_X11); g_assert (meta_context_configure (context, argc, argv, NULL)); g_assert (meta_context_setup (context, NULL)); test_environ = g_new0 (ClutterTestEnvironment, 1); + test_environ->context = context; g_assert (meta_context_start (context, NULL)); @@ -251,12 +255,30 @@ clutter_test_add_data_full (const char *test_path, int clutter_test_run (void) { + MetaBackend *backend = meta_context_get_backend (test_environ->context); + MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); + MetaVirtualMonitor *virtual_monitor; + g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL; + g_autoptr (GError) error = NULL; int res; - g_assert (test_environ != NULL); - + monitor_info = meta_virtual_monitor_info_new (1024, 768, 60.0, + "MetaTestVendor", + "ClutterTestMonitor", + "0x123"); + 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); + res = g_test_run (); + g_object_unref (virtual_monitor); + + g_clear_object (&test_environ->context); g_free (test_environ); return res; diff --git a/src/tests/clutter/conform/actor-event-hold.c b/src/tests/clutter/conform/actor-event-hold.c index aa3b1be7b..834395c97 100644 --- a/src/tests/clutter/conform/actor-event-hold.c +++ b/src/tests/clutter/conform/actor-event-hold.c @@ -66,6 +66,8 @@ actor_event_hold (void) ClutterActor *stage; ClutterBackend *backend; ClutterSeat *seat; + g_autoptr (ClutterVirtualInputDevice) virtual_pointer = NULL; + int64_t now_us; ClutterInputDevice *device; ClutterEvent *event; ClutterEvent *captured_event; @@ -81,8 +83,15 @@ actor_event_hold (void) /* Get the input device*/ backend = clutter_get_default_backend (); seat = clutter_backend_get_default_seat (backend); - device = clutter_seat_get_pointer (seat); + virtual_pointer = + clutter_seat_create_virtual_device (seat, CLUTTER_POINTER_DEVICE); + now_us = g_get_monotonic_time (); + clutter_virtual_input_device_notify_absolute_motion (virtual_pointer, + now_us, + 1.0, 1.0); + + device = clutter_seat_get_pointer (seat); while (clutter_stage_get_device_actor (CLUTTER_STAGE (stage), device, NULL) == NULL) g_main_context_iteration (NULL, FALSE);