tests: Add test for pointer axis events
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>
Mon, 18 Dec 2017 10:16:55 +0000 (12:16 +0200)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Mon, 18 Dec 2017 11:18:00 +0000 (13:18 +0200)
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>
protocol/weston-test.xml
tests/pointer-test.c
tests/weston-test-client-helper.c
tests/weston-test-client-helper.h
tests/weston-test.c

index fa3d15e..00b7185 100644 (file)
       <arg name="button" type="int"/>
       <arg name="state" type="uint"/>
     </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">
       <arg name="surface" type="object" interface="wl_surface" allow-null="true"/>
     </request>
index 61bf83b..4c438a2 100644 (file)
@@ -59,6 +59,18 @@ send_button(struct client *client, const struct timespec *time,
 }
 
 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
 check_pointer(struct client *client, int x, int y)
 {
        int sx, sy;
@@ -355,3 +367,19 @@ TEST(pointer_button_events)
        assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
        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));
+}
index c5a0032..6e0a524 100644 (file)
@@ -177,8 +177,14 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
 
 static void
 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",
                axis, wl_fixed_to_double(value));
 }
@@ -198,9 +204,14 @@ pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer,
 
 static void
 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
index 86ecb64..09a5df4 100644 (file)
@@ -90,8 +90,12 @@ struct pointer {
        int y;
        uint32_t button;
        uint32_t state;
+       uint32_t axis;
+       double axis_value;
        uint32_t motion_time_msec;
        uint32_t button_time_msec;
+       uint32_t axis_time_msec;
+       uint32_t axis_stop_time_msec;
 };
 
 struct keyboard {
index 14030f4..80b3d65 100644 (file)
@@ -184,6 +184,25 @@ send_button(struct wl_client *client, struct wl_resource *resource,
 }
 
 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
 activate_surface(struct wl_client *client, struct wl_resource *resource,
                 struct wl_resource *surface_resource)
 {
@@ -519,6 +538,7 @@ static const struct weston_test_interface test_implementation = {
        move_surface,
        move_pointer,
        send_button,
+       send_axis,
        activate_surface,
        send_key,
        device_release,