Message ID | 1417786610-2440-17-git-send-email-mchqwerty@gmail.com |
---|---|
State | Changes Requested |
Headers | show |
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 *
On 05/12/14 07:36 AM, Marek Chalupa wrote: > 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@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) Not sure I like the #define here... but that's just me
On Fri, 5 Dec 2014 14:36:49 +0100 Marek Chalupa <mchqwerty@gmail.com> wrote: > 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@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> > +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)); nanosleep, please. :-) Thanks, pq
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@gmail.com> --- tests/weston-test-client-helper.c | 57 +++++++++++++++++++++++++++++++++++++++ tests/weston-test-client-helper.h | 9 +++++++ 2 files changed, 66 insertions(+)