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 <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Alexandros Frantzis 2017-12-13 13:27:55 +02:00 committed by Pekka Paalanen
parent 10d708d268
commit 2180858592
7 changed files with 53 additions and 16 deletions

View File

@ -40,10 +40,16 @@
<arg name="y" type="int"/>
</request>
<request name="move_pointer">
<arg name="tv_sec_hi" type="uint"/>
<arg name="tv_sec_lo" type="uint"/>
<arg name="tv_nsec" type="uint"/>
<arg name="x" type="int"/>
<arg name="y" type="int"/>
</request>
<request name="send_button">
<arg name="tv_sec_hi" type="uint"/>
<arg name="tv_sec_lo" type="uint"/>
<arg name="tv_nsec" type="uint"/>
<arg name="button" type="int"/>
<arg name="state" type="uint"/>
</request>

View File

@ -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);

View File

@ -28,8 +28,36 @@
#include <linux/input.h>
#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));
}

View File

@ -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;

View File

@ -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);

View File

@ -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 {

View File

@ -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);
}