tests: Add test for pointer axis events

Add test to verify the server correctly emits pointer axis events.  This
requires updating the weston-test protocol with a new request for
pointer axis events.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Alexandros Frantzis 7 years ago committed by Pekka Paalanen
parent c20b580b52
commit b0341ae972
  1. 7
      protocol/weston-test.xml
  2. 28
      tests/pointer-test.c
  3. 17
      tests/weston-test-client-helper.c
  4. 4
      tests/weston-test-client-helper.h
  5. 20
      tests/weston-test.c

@ -53,6 +53,13 @@
<arg name="button" type="int"/> <arg name="button" type="int"/>
<arg name="state" type="uint"/> <arg name="state" type="uint"/>
</request> </request>
<request name="send_axis">
<arg name="tv_sec_hi" type="uint"/>
<arg name="tv_sec_lo" type="uint"/>
<arg name="tv_nsec" type="uint"/>
<arg name="axis" type="uint"/>
<arg name="value" type="fixed"/>
</request>
<request name="activate_surface"> <request name="activate_surface">
<arg name="surface" type="object" interface="wl_surface" allow-null="true"/> <arg name="surface" type="object" interface="wl_surface" allow-null="true"/>
</request> </request>

@ -58,6 +58,18 @@ send_button(struct client *client, const struct timespec *time,
client_roundtrip(client); client_roundtrip(client);
} }
static void
send_axis(struct client *client, const struct timespec *time, uint32_t axis,
double value)
{
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_axis(client->test->weston_test, tv_sec_hi, tv_sec_lo,
tv_nsec, axis, wl_fixed_from_double(value));
client_roundtrip(client);
}
static void static void
check_pointer(struct client *client, int x, int y) check_pointer(struct client *client, int x, int y)
{ {
@ -355,3 +367,19 @@ TEST(pointer_button_events)
assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED); assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
assert(pointer->button_time_msec == timespec_to_msec(&t2)); assert(pointer->button_time_msec == timespec_to_msec(&t2));
} }
TEST(pointer_axis_events)
{
struct client *client = create_client_with_pointer_focus(100, 100,
100, 100);
struct pointer *pointer = client->input->pointer;
send_axis(client, &t1, 1, 1.0);
assert(pointer->axis == 1);
assert(pointer->axis_value == 1.0);
assert(pointer->axis_time_msec == timespec_to_msec(&t1));
send_axis(client, &t2, 2, 0.0);
assert(pointer->axis == 2);
assert(pointer->axis_stop_time_msec == timespec_to_msec(&t2));
}

@ -177,8 +177,14 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
static void static void
pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value) uint32_t time_msec, uint32_t axis, wl_fixed_t value)
{ {
struct pointer *pointer = data;
pointer->axis = axis;
pointer->axis_value = wl_fixed_to_double(value);
pointer->axis_time_msec = time_msec;
fprintf(stderr, "test-client: got pointer axis %u %f\n", fprintf(stderr, "test-client: got pointer axis %u %f\n",
axis, wl_fixed_to_double(value)); axis, wl_fixed_to_double(value));
} }
@ -198,9 +204,14 @@ pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer,
static void static void
pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer, pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis) uint32_t time_msec, uint32_t axis)
{ {
fprintf(stderr, "test-client: got pointer axis stop\n"); struct pointer *pointer = data;
pointer->axis = axis;
pointer->axis_stop_time_msec = time_msec;
fprintf(stderr, "test-client: got pointer axis stop %u\n", axis);
} }
static void static void

@ -90,8 +90,12 @@ struct pointer {
int y; int y;
uint32_t button; uint32_t button;
uint32_t state; uint32_t state;
uint32_t axis;
double axis_value;
uint32_t motion_time_msec; uint32_t motion_time_msec;
uint32_t button_time_msec; uint32_t button_time_msec;
uint32_t axis_time_msec;
uint32_t axis_stop_time_msec;
}; };
struct keyboard { struct keyboard {

@ -183,6 +183,25 @@ send_button(struct wl_client *client, struct wl_resource *resource,
notify_button(seat, &time, button, state); notify_button(seat, &time, button, state);
} }
static void
send_axis(struct wl_client *client, struct wl_resource *resource,
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
uint32_t axis, wl_fixed_t value)
{
struct weston_test *test = wl_resource_get_user_data(resource);
struct weston_seat *seat = get_seat(test);
struct timespec time;
struct weston_pointer_axis_event axis_event;
timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
axis_event.axis = axis;
axis_event.value = wl_fixed_to_double(value);
axis_event.has_discrete = false;
axis_event.discrete = 0;
notify_axis(seat, &time, &axis_event);
}
static void static void
activate_surface(struct wl_client *client, struct wl_resource *resource, activate_surface(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *surface_resource) struct wl_resource *surface_resource)
@ -519,6 +538,7 @@ static const struct weston_test_interface test_implementation = {
move_surface, move_surface,
move_pointer, move_pointer,
send_button, send_button,
send_axis,
activate_surface, activate_surface,
send_key, send_key,
device_release, device_release,

Loading…
Cancel
Save