test: ensure we only get frame events after device events

Because we're doing this per dispatch call (rather than a device state)
we need to ensure that the various tests gobble up all pending frame
events - the assert_no_events helpers do this.

If we only check for specific events, a frame event may still be pending
from one interaction. This causing the assertion to fail on the
subsequent dispatch call.
This commit is contained in:
Peter Hutterer 2022-04-29 09:15:40 +10:00
parent a4dde7c35f
commit 425c7804d4
2 changed files with 56 additions and 2 deletions

View file

@ -654,6 +654,7 @@ _peck_dispatch_eis(struct peck *peck, int lineno)
{
struct eis *eis = peck->eis;
bool had_event = false;
bool need_frame = false;
log_debug(peck, "EIS Dispatch, line %d\n", lineno);
peck_indent(peck);
@ -686,6 +687,9 @@ _peck_dispatch_eis(struct peck *peck, int lineno)
process_event = tristate_no;
break;
case EIS_EVENT_FRAME:
/* Ensure we only expect frames when we expect them */
munit_assert_true(need_frame);
need_frame = false;
if (flag_is_set(peck->eis_behavior, PECK_EIS_BEHAVIOR_HANDLE_FRAME))
process_event = tristate_yes;
break;
@ -697,7 +701,20 @@ _peck_dispatch_eis(struct peck *peck, int lineno)
if (flag_is_set(peck->eis_behavior, PECK_EIS_BEHAVIOR_HANDLE_STOP_EMULATING))
process_event = tristate_yes;
break;
default:
case EIS_EVENT_CLIENT_PROPERTY:
break;
case EIS_EVENT_POINTER_MOTION:
case EIS_EVENT_POINTER_MOTION_ABSOLUTE:
case EIS_EVENT_POINTER_BUTTON:
case EIS_EVENT_POINTER_SCROLL:
case EIS_EVENT_POINTER_SCROLL_STOP:
case EIS_EVENT_POINTER_SCROLL_CANCEL:
case EIS_EVENT_POINTER_SCROLL_DISCRETE:
case EIS_EVENT_KEYBOARD_KEY:
case EIS_EVENT_TOUCH_DOWN:
case EIS_EVENT_TOUCH_UP:
case EIS_EVENT_TOUCH_MOTION:
need_frame = true;
break;
}
@ -769,6 +786,7 @@ _peck_dispatch_ei(struct peck *peck, int lineno)
{
struct ei *ei = peck->ei;
bool had_event = false;
bool need_frame = false;
log_debug(peck, "ei dispatch, line %d\n", lineno);
peck_indent(peck);
@ -787,15 +805,21 @@ _peck_dispatch_ei(struct peck *peck, int lineno)
PECK_EI_BEHAVIOR_AUTOCONNECT))
process_event = tristate_yes;
break;
case EI_EVENT_DISCONNECT:
break;
case EI_EVENT_SEAT_ADDED:
if (peck->ei_seat == NULL &&
flag_is_set(peck->ei_behavior,
PECK_EI_BEHAVIOR_AUTOSEAT))
process_event = tristate_yes;
break;
case EI_EVENT_SEAT_REMOVED:
break;
case EI_EVENT_DEVICE_ADDED:
process_event = peck_check_ei_added(peck, e);
break;
case EI_EVENT_DEVICE_REMOVED:
break;
case EI_EVENT_DEVICE_RESUMED:
if (flag_is_set(peck->ei_behavior, PECK_EI_BEHAVIOR_HANDLE_RESUMED))
process_event = tristate_yes;
@ -805,10 +829,31 @@ _peck_dispatch_ei(struct peck *peck, int lineno)
process_event = tristate_yes;
break;
case EI_EVENT_FRAME:
/* Ensure we only expect frames when we expect them */
munit_assert_true(need_frame);
need_frame = false;
if (flag_is_set(peck->ei_behavior, PECK_EI_BEHAVIOR_HANDLE_FRAME))
process_event = tristate_yes;
break;
default:
case EI_EVENT_DEVICE_START_EMULATING:
case EI_EVENT_DEVICE_STOP_EMULATING:
break;
case EI_EVENT_PROPERTY:
break;
case EI_EVENT_POINTER_MOTION:
case EI_EVENT_POINTER_MOTION_ABSOLUTE:
case EI_EVENT_POINTER_BUTTON:
case EI_EVENT_POINTER_SCROLL:
case EI_EVENT_POINTER_SCROLL_STOP:
case EI_EVENT_POINTER_SCROLL_CANCEL:
case EI_EVENT_POINTER_SCROLL_DISCRETE:
case EI_EVENT_KEYBOARD_KEY:
case EI_EVENT_KEYBOARD_MODIFIERS:
case EI_EVENT_TOUCH_DOWN:
case EI_EVENT_TOUCH_UP:
case EI_EVENT_TOUCH_MOTION:
need_frame = true;
break;
}

View file

@ -511,6 +511,7 @@ MUNIT_TEST(test_ei_device_pointer_abs)
munit_assert_double_equal(eis_event_pointer_get_absolute_x(e), 1.0 * i, 2 /* precision */);
munit_assert_double_equal(eis_event_pointer_get_absolute_y(e), 2.0 + i, 2 /* precision */);
}
peck_assert_no_eis_events(eis);
}
with_client(peck) {
@ -819,6 +820,8 @@ MUNIT_TEST(test_ei_device_touch)
_unref_(eis_event) *up = peck_eis_touch_up(eis);
munit_assert_uint32(eis_event_touch_get_id(up), ==, tid);
peck_assert_no_eis_events(eis);
}
with_client(peck) {
@ -862,6 +865,7 @@ MUNIT_TEST(test_ei_device_touch)
with_server(peck) {
_unref_(eis_event) *down = peck_eis_touch_down(eis, 100, 200);
_unref_(eis_event) *up = peck_eis_touch_up(eis);
peck_assert_no_eis_events(eis);
}
with_client(peck) {
@ -876,6 +880,7 @@ MUNIT_TEST(test_ei_device_touch)
with_server(peck) {
_unref_(eis_event) *down = peck_eis_touch_down(eis, 100, 100);
_unref_(eis_event) *up = peck_eis_touch_up(eis);
peck_assert_no_eis_events(eis);
}
with_client(peck) {
@ -1396,6 +1401,7 @@ MUNIT_TEST(test_passive_ei_device_pointer_abs)
munit_assert_double_equal(ei_event_pointer_get_absolute_x(e), 1.0 * i, 2 /* precision */);
munit_assert_double_equal(ei_event_pointer_get_absolute_y(e), 2.0 + i, 2 /* precision */);
}
peck_assert_no_ei_events(ei);
}
with_server(peck) {
@ -1772,6 +1778,7 @@ MUNIT_TEST(test_passive_ei_device_touch)
_unref_(ei_event) *up = peck_ei_touch_up(ei);
munit_assert_uint32(ei_event_touch_get_id(up), ==, tid);
peck_assert_no_ei_events(ei);
}
with_server(peck) {
@ -1815,6 +1822,7 @@ MUNIT_TEST(test_passive_ei_device_touch)
with_client(peck) {
_unref_(ei_event) *down = peck_ei_touch_down(ei, 100, 200);
_unref_(ei_event) *up = peck_ei_touch_up(ei);
peck_assert_no_ei_events(ei);
}
with_server(peck) {
@ -1829,6 +1837,7 @@ MUNIT_TEST(test_passive_ei_device_touch)
with_client(peck) {
_unref_(ei_event) *down = peck_ei_touch_down(ei, 100, 100);
_unref_(ei_event) *up = peck_ei_touch_up(ei);
peck_assert_no_ei_events(ei);
}
with_server(peck) {