tests: Add test for touch event timestamps
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>
Wed, 13 Dec 2017 11:27:58 +0000 (13:27 +0200)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Mon, 18 Dec 2017 09:46:28 +0000 (11:46 +0200)
Add test to verify that the server correctly sets the timestamps of
touch events. This requires updating the weston-test protocol with a new
request for touch events.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Makefile.am
protocol/weston-test.xml
tests/touch-test.c [new file with mode: 0644]
tests/weston-test-client-helper.c
tests/weston-test-client-helper.h
tests/weston-test.c

index f67e693..883249c 100644 (file)
@@ -1233,7 +1233,8 @@ weston_tests =                                    \
        roles.weston                            \
        subsurface.weston                       \
        subsurface-shot.weston                  \
-       devices.weston
+       devices.weston                          \
+       touch.weston
 
 ivi_tests =
 
@@ -1428,6 +1429,10 @@ nodist_viewporter_weston_SOURCES =               \
 viewporter_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
 viewporter_weston_LDADD = libtest-client.la
 
+touch_weston_SOURCES = tests/touch-test.c
+touch_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
+touch_weston_LDADD = libtest-client.la
+
 if ENABLE_XWAYLAND_TEST
 weston_tests +=        xwayland-test.weston
 xwayland_test_weston_SOURCES = tests/xwayland-test.c
index 4c258f4..fa3d15e 100644 (file)
                provided buffer.
          </description>
     </event>
+    <request name="send_touch">
+      <arg name="tv_sec_hi" type="uint"/>
+      <arg name="tv_sec_lo" type="uint"/>
+      <arg name="tv_nsec" type="uint"/>
+      <arg name="touch_id" type="int"/>
+      <arg name="x" type="fixed"/>
+      <arg name="y" type="fixed"/>
+      <arg name="touch_type" type="uint"/>
+    </request>
   </interface>
 
   <interface name="weston_test_runner" version="1">
diff --git a/tests/touch-test.c b/tests/touch-test.c
new file mode 100644 (file)
index 0000000..9635257
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2017 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <time.h>
+
+#include "shared/timespec-util.h"
+#include "weston-test-client-helper.h"
+#include "wayland-server-protocol.h"
+
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 1000001 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 2000001 };
+static const struct timespec t3 = { .tv_sec = 3, .tv_nsec = 3000001 };
+
+static struct client *
+create_touch_test_client(void)
+{
+       struct client *cl = create_client_and_test_surface(0, 0, 100, 100);
+       assert(cl);
+       return cl;
+}
+
+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;
+
+       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);
+       client_roundtrip(client);
+}
+
+TEST(touch_events)
+{
+       struct client *client = create_touch_test_client();
+       struct touch *touch = client->input->touch;
+
+       send_touch(client, &t1, WL_TOUCH_DOWN);
+       assert(touch->down_time_msec == timespec_to_msec(&t1));
+
+       send_touch(client, &t2, WL_TOUCH_MOTION);
+       assert(touch->motion_time_msec == timespec_to_msec(&t2));
+
+       send_touch(client, &t3, WL_TOUCH_UP);
+       assert(touch->up_time_msec == timespec_to_msec(&t3));
+}
index 695f691..c5a0032 100644 (file)
@@ -315,14 +315,16 @@ static const struct wl_keyboard_listener keyboard_listener = {
 
 static void
 touch_handle_down(void *data, struct wl_touch *wl_touch,
-                 uint32_t serial, uint32_t time, struct wl_surface *surface,
-                 int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+                 uint32_t serial, uint32_t time_msec,
+                 struct wl_surface *surface, int32_t id,
+                 wl_fixed_t x_w, wl_fixed_t y_w)
 {
        struct touch *touch = data;
 
        touch->down_x = wl_fixed_to_int(x_w);
        touch->down_y = wl_fixed_to_int(y_w);
        touch->id = id;
+       touch->down_time_msec = time_msec;
 
        fprintf(stderr, "test-client: got touch down %d %d, surf: %p, id: %d\n",
                touch->down_x, touch->down_y, surface, id);
@@ -330,21 +332,24 @@ touch_handle_down(void *data, struct wl_touch *wl_touch,
 
 static void
 touch_handle_up(void *data, struct wl_touch *wl_touch,
-               uint32_t serial, uint32_t time, int32_t id)
+               uint32_t serial, uint32_t time_msec, int32_t id)
 {
        struct touch *touch = data;
        touch->up_id = id;
+       touch->up_time_msec = time_msec;
 
        fprintf(stderr, "test-client: got touch up, id: %d\n", id);
 }
 
 static void
 touch_handle_motion(void *data, struct wl_touch *wl_touch,
-                   uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+                   uint32_t time_msec, int32_t id,
+                   wl_fixed_t x_w, wl_fixed_t y_w)
 {
        struct touch *touch = data;
        touch->x = wl_fixed_to_int(x_w);
        touch->y = wl_fixed_to_int(y_w);
+       touch->motion_time_msec = time_msec;
 
        fprintf(stderr, "test-client: got touch motion, %d %d, id: %d\n",
                touch->x, touch->y, id);
index 214f695..86ecb64 100644 (file)
@@ -120,6 +120,9 @@ struct touch {
        int up_id; /* id of last wl_touch.up event */
        int frame_no;
        int cancel_no;
+       uint32_t down_time_msec;
+       uint32_t up_time_msec;
+       uint32_t motion_time_msec;
 };
 
 struct output {
index 7dd7a1c..14030f4 100644 (file)
@@ -500,6 +500,21 @@ capture_screenshot(struct wl_client *client,
                                     capture_screenshot_done, resource);
 }
 
+static void
+send_touch(struct wl_client *client, struct wl_resource *resource,
+          uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
+          int32_t touch_id, wl_fixed_t x, wl_fixed_t y, uint32_t touch_type)
+{
+       struct weston_test *test = wl_resource_get_user_data(resource);
+       struct weston_seat *seat = get_seat(test);
+       struct timespec time;
+
+       timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
+
+       notify_touch(seat, &time, touch_id, wl_fixed_to_double(x),
+                    wl_fixed_to_double(y), touch_type);
+}
+
 static const struct weston_test_interface test_implementation = {
        move_surface,
        move_pointer,
@@ -509,6 +524,7 @@ static const struct weston_test_interface test_implementation = {
        device_release,
        device_add,
        capture_screenshot,
+       send_touch,
 };
 
 static void