From 2180858592bdfa67ed75fb91cde1c18ee17270a2 Mon Sep 17 00:00:00 2001 From: Alexandros Frantzis Date: Wed, 13 Dec 2017 13:27:55 +0200 Subject: [PATCH] tests: Add checks for pointer motion and button event timestamps Enhance the existing pointer motion and button event tests to additionally verify the event timestamps. This requires updating the weston-test protocol to support passing motion and button event timestamps. Signed-off-by: Alexandros Frantzis Reviewed-by: Pekka Paalanen --- protocol/weston-test.xml | 6 ++++++ tests/internal-screenshot-test.c | 2 +- tests/pointer-test.c | 45 ++++++++++++++++++++++++++++++--------- tests/subsurface-shot-test.c | 2 +- tests/weston-test-client-helper.c | 6 ++++-- tests/weston-test-client-helper.h | 2 ++ tests/weston-test.c | 6 ++++-- 7 files changed, 53 insertions(+), 16 deletions(-) diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml index 74a1521..ae3349e 100644 --- a/protocol/weston-test.xml +++ b/protocol/weston-test.xml @@ -40,10 +40,16 @@ + + + + + + diff --git a/tests/internal-screenshot-test.c b/tests/internal-screenshot-test.c index 3bf9b31..2a7424b 100644 --- a/tests/internal-screenshot-test.c +++ b/tests/internal-screenshot-test.c @@ -97,7 +97,7 @@ TEST(internal_screenshot) */ /* Move the pointer away from the screenshot area. */ - weston_test_move_pointer(client->test->weston_test, 0, 0); + weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 0, 0); buf = create_shm_buffer_a8r8g8b8(client, 100, 100); draw_stuff(buf->image); diff --git a/tests/pointer-test.c b/tests/pointer-test.c index e0e700e..61bf83b 100644 --- a/tests/pointer-test.c +++ b/tests/pointer-test.c @@ -28,8 +28,36 @@ #include +#include "shared/timespec-util.h" #include "weston-test-client-helper.h" +static const struct timespec t0 = { .tv_sec = 0, .tv_nsec = 100000000 }; +static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 1000001 }; +static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 2000001 }; + +static void +send_motion(struct client *client, const struct timespec *time, int x, int y) +{ + uint32_t tv_sec_hi, tv_sec_lo, tv_nsec; + + timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec); + weston_test_move_pointer(client->test->weston_test, tv_sec_hi, tv_sec_lo, + tv_nsec, x, y); + client_roundtrip(client); +} + +static void +send_button(struct client *client, const struct timespec *time, + uint32_t button, uint32_t state) +{ + 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_button(client->test->weston_test, tv_sec_hi, tv_sec_lo, + tv_nsec, button, state); + client_roundtrip(client); +} + static void check_pointer(struct client *client, int x, int y) { @@ -64,8 +92,7 @@ check_pointer(struct client *client, int x, int y) static void check_pointer_move(struct client *client, int x, int y) { - weston_test_move_pointer(client->test->weston_test, x, y); - client_roundtrip(client); + send_motion(client, &t0, x, y); check_pointer(client, x, y); } @@ -303,10 +330,10 @@ TEST(pointer_motion_events) 100, 100); struct pointer *pointer = client->input->pointer; - weston_test_move_pointer(client->test->weston_test, 150, 150); - client_roundtrip(client); + send_motion(client, &t1, 150, 150); assert(pointer->x == 50); assert(pointer->y == 50); + assert(pointer->motion_time_msec == timespec_to_msec(&t1)); } TEST(pointer_button_events) @@ -318,15 +345,13 @@ TEST(pointer_button_events) assert(pointer->button == 0); assert(pointer->state == 0); - weston_test_send_button(client->test->weston_test, BTN_LEFT, - WL_POINTER_BUTTON_STATE_PRESSED); - client_roundtrip(client); + send_button(client, &t1, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); assert(pointer->button == BTN_LEFT); assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED); + assert(pointer->button_time_msec == timespec_to_msec(&t1)); - weston_test_send_button(client->test->weston_test, BTN_LEFT, - WL_POINTER_BUTTON_STATE_RELEASED); - client_roundtrip(client); + send_button(client, &t2, BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED); assert(pointer->button == BTN_LEFT); assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED); + assert(pointer->button_time_msec == timespec_to_msec(&t2)); } diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c index 10415ec..e8bab67 100644 --- a/tests/subsurface-shot-test.c +++ b/tests/subsurface-shot-test.c @@ -200,7 +200,7 @@ TEST(subsurface_z_order) subco = get_subcompositor(client); /* move the pointer clearly away from our screenshooting area */ - weston_test_move_pointer(client->test->weston_test, 2, 30); + weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30); /* make the parent surface red */ surf[0] = client->surface->wl_surface; diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index ee50845..203cd44 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -148,12 +148,13 @@ pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, - uint32_t time, wl_fixed_t x, wl_fixed_t y) + uint32_t time_msec, wl_fixed_t x, wl_fixed_t y) { struct pointer *pointer = data; pointer->x = wl_fixed_to_int(x); pointer->y = wl_fixed_to_int(y); + pointer->motion_time_msec = time_msec; fprintf(stderr, "test-client: got pointer motion %d %d\n", pointer->x, pointer->y); @@ -161,13 +162,14 @@ pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, - uint32_t serial, uint32_t time, uint32_t button, + uint32_t serial, uint32_t time_msec, uint32_t button, uint32_t state) { struct pointer *pointer = data; pointer->button = button; pointer->state = state; + pointer->button_time_msec = time_msec; fprintf(stderr, "test-client: got pointer button %u %u\n", button, state); diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index 880f47a..6f5f9c4 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -90,6 +90,8 @@ struct pointer { int y; uint32_t button; uint32_t state; + uint32_t motion_time_msec; + uint32_t button_time_msec; }; struct keyboard { diff --git a/tests/weston-test.c b/tests/weston-test.c index 6e7beeb..1799de9 100644 --- a/tests/weston-test.c +++ b/tests/weston-test.c @@ -146,6 +146,7 @@ move_surface(struct wl_client *client, struct wl_resource *resource, static void move_pointer(struct wl_client *client, struct wl_resource *resource, + uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, int32_t x, int32_t y) { struct weston_test *test = wl_resource_get_user_data(resource); @@ -160,7 +161,7 @@ move_pointer(struct wl_client *client, struct wl_resource *resource, .dy = wl_fixed_to_double(wl_fixed_from_int(y) - pointer->y), }; - timespec_from_msec(&time, 100); + timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); notify_motion(seat, &time, &event); @@ -169,6 +170,7 @@ move_pointer(struct wl_client *client, struct wl_resource *resource, static void send_button(struct wl_client *client, struct wl_resource *resource, + uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, int32_t button, uint32_t state) { struct timespec time; @@ -176,7 +178,7 @@ send_button(struct wl_client *client, struct wl_resource *resource, struct weston_test *test = wl_resource_get_user_data(resource); struct weston_seat *seat = get_seat(test); - timespec_from_msec(&time, 100); + timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); notify_button(seat, &time, button, state); } -- 2.7.4