From 260ea3731218ec30eb7cc74be282b995b9d569bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Wed, 16 Nov 2022 14:17:57 +0100 Subject: [PATCH] tests/clutter/conform: Add a test for event delivery Add a test for everything related to event delivery. The first test we add here is making sure we don't regress on the bug fixed with commit edc226a04d75d23189232ed69d73b6a20c69da58. Part-of: --- src/tests/clutter/conform/event-delivery.c | 69 ++++++++++++++++++++++ src/tests/clutter/conform/meson.build | 1 + 2 files changed, 70 insertions(+) create mode 100644 src/tests/clutter/conform/event-delivery.c diff --git a/src/tests/clutter/conform/event-delivery.c b/src/tests/clutter/conform/event-delivery.c new file mode 100644 index 000000000..e1dba7e0d --- /dev/null +++ b/src/tests/clutter/conform/event-delivery.c @@ -0,0 +1,69 @@ +#include + +#include "tests/clutter-test-utils.h" + +static void +on_after_update (ClutterStage *stage, + ClutterStageView *view, + gboolean *was_updated) +{ + *was_updated = TRUE; +} + +static gboolean +on_event_return_stop (ClutterActor *actor, + ClutterEvent *event, + unsigned int *n_events) +{ + (*n_events)++; + + return CLUTTER_EVENT_STOP; +} + +static void +wait_stage_updated (gboolean *was_updated) +{ + *was_updated = FALSE; + while (!*was_updated) + g_main_context_iteration (NULL, TRUE); +} + +static void +event_delivery_consecutive_touch_begin_end (void) +{ + ClutterActor *stage = clutter_test_get_stage (); + ClutterSeat *seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + g_autoptr (ClutterVirtualInputDevice) virtual_pointer = NULL; + int64_t now_us; + gboolean was_updated; + unsigned int n_captured_touch_events = 0; + + virtual_pointer = clutter_seat_create_virtual_device (seat, CLUTTER_POINTER_DEVICE); + now_us = g_get_monotonic_time (); + + g_signal_connect (stage, "after-update", G_CALLBACK (on_after_update), + &was_updated); + g_signal_connect (stage, "captured-event::touch", G_CALLBACK (on_event_return_stop), + &n_captured_touch_events); + + clutter_actor_show (stage); + + was_updated = FALSE; + clutter_virtual_input_device_notify_touch_down (virtual_pointer, now_us, 0, 5, 5); + clutter_virtual_input_device_notify_touch_up (virtual_pointer, now_us, 0); + clutter_virtual_input_device_notify_touch_down (virtual_pointer, now_us, 0, 5, 5); + g_assert_true (!was_updated); + wait_stage_updated (&was_updated); + g_assert_cmpint (n_captured_touch_events, ==, 3); + + clutter_virtual_input_device_notify_touch_up (virtual_pointer, now_us, 0); + wait_stage_updated (&was_updated); + g_assert_cmpint (n_captured_touch_events, ==, 4); + + g_signal_handlers_disconnect_by_func (stage, on_event_return_stop, &n_captured_touch_events); + g_signal_handlers_disconnect_by_func (stage, on_after_update, &was_updated); +} + +CLUTTER_TEST_SUITE ( + CLUTTER_TEST_UNIT ("/event/delivery/consecutive-touch-begin-end", event_delivery_consecutive_touch_begin_end); +) diff --git a/src/tests/clutter/conform/meson.build b/src/tests/clutter/conform/meson.build index 093686329..b10299e7a 100644 --- a/src/tests/clutter/conform/meson.build +++ b/src/tests/clutter/conform/meson.build @@ -34,6 +34,7 @@ clutter_conform_tests_classes_tests = [ clutter_conform_tests_general_tests = [ 'binding-pool', 'color', + 'event-delivery', 'frame-clock', 'frame-clock-timeline', 'grab',