[PATCH weston v1 16/17] test-helpers: add functions that simulate pointer actions
Marek Chalupa
mchqwerty at gmail.com
Fri Dec 5 05:36:49 PST 2014
Add functions that simulate pointer movement, draging and clicking.
These functions will be handy in more tests, so add them to helpers.
Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
tests/weston-test-client-helper.c | 57 +++++++++++++++++++++++++++++++++++++++
tests/weston-test-client-helper.h | 9 +++++++
2 files changed, 66 insertions(+)
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index dc34fc4..7f7f4f5 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
+#include <linux/input.h>
#include "../shared/os-compatibility.h"
#include "../clients/window.h"
@@ -130,6 +131,62 @@ move_client(struct client *client, int x, int y)
}
}
+void
+pointer_simulate_move(struct client *client, int x1, int y1, int x2, int y2)
+{
+ struct wl_test *wl_test = client->test->wl_test;
+
+ wl_test_move_pointer(wl_test, x1, y1);
+ client_roundtrip(client);
+
+ while (x1 != x2 || y1 != y2) {
+ if (x2 < x1)
+ --x1;
+ else if (x2 > x1)
+ ++x1;
+
+ if (y2 < y1)
+ --y1;
+ else if (y2 > y1)
+ ++y1;
+
+ wl_test_move_pointer(wl_test, x1, y1);
+ client_roundtrip(client);
+ }
+}
+
+void
+pointer_simulate_drag(struct client *client, int x1, int y1, int x2, int y2)
+{
+ struct wl_test *wl_test = client->test->wl_test;
+
+ pointer_simulate_move(client, x1 - 50, y1 - 50, x1, y1);
+
+ wl_test_send_button(wl_test, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
+ client_roundtrip(client);
+
+ pointer_simulate_move(client, x1, y1, x2, y2);
+
+ wl_test_send_button(wl_test, BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED);
+ client_roundtrip(client);
+}
+
+#define MSEC_TO_USEC(n) ((n) * 1000)
+
+void
+pointer_click(struct client *client, uint32_t button)
+{
+ struct wl_test *wl_test = client->test->wl_test;
+
+ wl_test_send_button(wl_test, button, WL_POINTER_BUTTON_STATE_PRESSED);
+ wl_display_flush(client->wl_display);
+
+ usleep(MSEC_TO_USEC(30));
+
+ wl_test_send_button(wl_test, button, WL_POINTER_BUTTON_STATE_RELEASED);
+ client_roundtrip(client);
+}
+
int
get_n_egl_buffers(struct client *client)
{
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index bdd8cd9..a5a12ae 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -133,6 +133,15 @@ void
move_client(struct client *client, int x, int y);
void
+pointer_simulate_move(struct client *client, int x1, int y1, int x2, int y2);
+
+void
+pointer_simulate_drag(struct client *client, int x1, int y1, int x2, int y2);
+
+void
+pointer_click(struct client *client, uint32_t button);
+
+void
client_roundtrip(struct client *client);
struct wl_callback *
--
2.1.0
More information about the wayland-devel
mailing list