summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>2017-12-13 13:27:58 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2017-12-18 11:46:28 +0200
commitc20b580b5288d6ee6aa6bed4de165e2c191d3a28 (patch)
treeb4dc95c9e3868d61b9f1e52bd065c88c47ae54a7
parentdae224c6dc8054d1cf3ce4596588f922ff029fd2 (diff)
tests: Add test for touch event timestamps
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>
-rw-r--r--Makefile.am7
-rw-r--r--protocol/weston-test.xml9
-rw-r--r--tests/touch-test.c71
-rw-r--r--tests/weston-test-client-helper.c13
-rw-r--r--tests/weston-test-client-helper.h3
-rw-r--r--tests/weston-test.c16
6 files changed, 114 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index f67e693d..883249c0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index 4c258f4b..fa3d15e1 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -89,6 +89,15 @@
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
index 00000000..9635257f
--- /dev/null
+++ b/tests/touch-test.c
@@ -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));
+}
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 695f6912..c5a00320 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -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);
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index 214f6959..86ecb640 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -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 {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 7dd7a1cf..14030f4c 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -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