From 3ef8bb9935b84bcf7d8f81aac6d0559122cecc9a Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Tue, 7 Feb 2023 07:13:48 -0600 Subject: [PATCH] tests: Don't send real coordinates with WL_TOUCH_UP events Wayland protocol can't do this, but the way our test protocol handles touch through a single event can - ensure that we don't by accident. This will matter more shortly when we add assert()s to prevent having coordinates with WL_TOUCH_UP events internally later. Signed-off-by: Derek Foreman --- protocol/weston-test.xml | 6 ++++++ tests/touch-test.c | 39 ++++++++++++++++++++++++++++++++++++--- tests/weston-test.c | 14 ++++++++++++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml index f880414d..845b1d41 100644 --- a/protocol/weston-test.xml +++ b/protocol/weston-test.xml @@ -34,6 +34,12 @@ These requests may allow clients to do very bad things. + + + + + diff --git a/tests/touch-test.c b/tests/touch-test.c index 080e7e73..d6a4ac40 100644 --- a/tests/touch-test.c +++ b/tests/touch-test.c @@ -59,17 +59,50 @@ create_touch_test_client(void) } static void -send_touch(struct client *client, const struct timespec *time, - uint32_t touch_type) +send_broken_touch(struct client *client, const struct timespec *time) { uint32_t tv_sec_hi, tv_sec_lo, tv_nsec; timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec); + weston_test_send_touch(client->test->weston_test, tv_sec_hi, tv_sec_lo, - tv_nsec, 1, 1, 1, touch_type); + tv_nsec, 1, 1, 1, WL_TOUCH_UP); + + expect_protocol_error(client, &weston_test_interface, + WESTON_TEST_ERROR_TOUCH_UP_WITH_COORDINATE); +} + +static void +send_touch(struct client *client, const struct timespec *time, + uint32_t touch_type) +{ + uint32_t tv_sec_hi, tv_sec_lo, tv_nsec; + wl_fixed_t x = 0, y = 0; + + timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec); + if (touch_type != WL_TOUCH_UP) { + x = 1; + y = 1; + } + + weston_test_send_touch(client->test->weston_test, tv_sec_hi, tv_sec_lo, + tv_nsec, 1, x, y, touch_type); client_roundtrip(client); } +TEST(broken_touch_event) +{ + struct client *client = create_touch_test_client(); + struct input_timestamps *input_ts = + input_timestamps_create_for_touch(client); + + send_broken_touch(client, &t1); + + input_timestamps_destroy(input_ts); + + client_destroy(client); +} + TEST(touch_events) { struct client *client = create_touch_test_client(); diff --git a/tests/weston-test.c b/tests/weston-test.c index 58f27a04..c15dbfee 100644 --- a/tests/weston-test.c +++ b/tests/weston-test.c @@ -426,8 +426,18 @@ send_touch(struct wl_client *client, struct wl_resource *resource, timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); - notify_touch(device, &time, touch_id, wl_fixed_to_double(x), - wl_fixed_to_double(y), touch_type); + if (touch_type == WL_TOUCH_UP) { + if (x != 0 || y != 0) { + wl_resource_post_error(resource, + WESTON_TEST_ERROR_TOUCH_UP_WITH_COORDINATE, + "Test protocol sent valid " + "coordinates with WL_TOUCH_UP"); + + return; + } + } + + notify_touch(device, &time, touch_id, x, y, touch_type); } static const struct weston_test_interface test_implementation = {