[weston,v1,17/17] tests: add interactive tests

Bryce Harrington bryce at osg.samsung.com
Tue Jan 27 12:49:12 PST 2015


On Fri, Dec 05, 2014 at 02:36:50PM +0100, Marek Chalupa wrote:
> These tests are using pointer and keyboard simulated events
> to interact with client.
> 
> Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>

Hi Marek,

This patch series has a number of different improvements for tests, and
looks like a good candidate for 1.7.  It got thorough review and there
were some changes suggested; would you be able to re-post a v2 with
those changes done this week?

Bryce
 
> ---
> Makefile.am              |   7 ++-
>  tests/interactive-test.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 141 insertions(+), 1 deletion(-)
>  create mode 100644 tests/interactive-test.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index 57882cd..f59b52a 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -932,7 +932,8 @@ weston_tests =					\
>  	presentation.weston			\
>  	roles.weston				\
>  	subsurface.weston			\
> -	test-suite-tests.weston
> +	test-suite-tests.weston			\
> +	interactive.weston
>  
>  
>  AM_TESTS_ENVIRONMENT = \
> @@ -1053,6 +1054,10 @@ test_suite_tests_weston_SOURCES = tests/test-suite-test.c
>  test_suite_tests_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS) $(CLIENT_CFLAGS)
>  test_suite_tests_weston_LDADD = libtest-client.la
>  
> +interactive_weston_SOURCES = tests/interactive-test.c
> +interactive_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS) $(CLIENT_CFLAGS)
> +interactive_weston_LDADD = libtest-client.la
> +
>  if ENABLE_EGL
>  weston_tests += buffer-count.weston
>  buffer_count_weston_SOURCES = tests/buffer-count-test.c
> diff --git a/tests/interactive-test.c b/tests/interactive-test.c
> new file mode 100644
> index 0000000..07b3686
> --- /dev/null
> +++ b/tests/interactive-test.c
> @@ -0,0 +1,135 @@
> +/*
> + * Copyright © 2014 Red Hat, Inc.
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and
> + * its documentation for any purpose is hereby granted without fee, provided
> + * that the above copyright notice appear in all copies and that both that
> + * copyright notice and this permission notice appear in supporting
> + * documentation, and that the name of the copyright holders not be used in
> + * advertising or publicity pertaining to distribution of the software
> + * without specific, written prior permission.  The copyright holders make
> + * no representations about the suitability of this software for any
> + * purpose.  It is provided "as is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
> + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
> + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
> + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
> + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
> + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
> + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <unistd.h>
> +#include <time.h>
> +#include <linux/input.h>
> +
> +#include "weston-test-client-helper.h"
> +
> +/* relative position where to grab the client when dragging*/
> +#define GRAB_SHIFT_X 150
> +#define GRAB_SHIFT_Y 45
> +
> +static void
> +drag_and_check(struct client *client, int x, int y)
> +{
> +	wl_test_get_geometry(client->test->wl_test, client->surface->wl_surface);
> +	client_roundtrip(client);
> +
> +	fprintf(stderr, "dragging from %dx%d to %dx%d\n",
> +		client->test->geometry.x, client->test->geometry.y,
> +		x, y);
> +	fflush(stderr);
> +
> +	pointer_simulate_drag(client,
> +			      client->test->geometry.x + GRAB_SHIFT_X,
> +			      client->test->geometry.y + GRAB_SHIFT_Y,
> +			      x + GRAB_SHIFT_X, y + GRAB_SHIFT_Y);
> +	client_roundtrip(client);
> +
> +	wl_test_get_geometry(client->test->wl_test, client->surface->wl_surface);
> +	client_roundtrip(client);
> +
> +	assert(!window_is_maximized(client->toytoolkit->window));
> +	assert(!window_is_fullscreen(client->toytoolkit->window));
> +	assert(client->test->geometry.x == x);
> +	assert(client->test->geometry.y == y);
> +}
> +
> +#define MSEC_TO_USEC(n) ((n) * 1000)
> +
> +TEST(move_client_by_pointer_test)
> +{
> +	int x, y, i;
> +	const int width = 300;
> +	const int height = 300;
> +	struct client *client = toytoolkit_client_create(100, 100, width, height);
> +
> +	srand(time(NULL));
> +
> +	/* random stuff */
> +	for (i = 0; i < 10; ++i) {
> +		x = rand() % (client->output->width - width);
> +		y = rand() % (client->output->height - height);
> +
> +		drag_and_check(client, x, y);
> +		/* sleep a while so that we won't do double click */
> +		usleep(MSEC_TO_USEC(300));
> +	}
> +}
> +
> +TEST(focus_tests_one_client)
> +{
> +	struct client *c1 = toytoolkit_client_create(100, 100, 300, 200);
> +	int dw, dh;
> +
> +	/* if we'll get a motion, then we're out of frame */
> +	c1->input->pointer->x = -1;
> +	c1->input->pointer->y = -1;
> +
> +	/* just for sure ... */
> +	wl_test_get_geometry(c1->test->wl_test, c1->surface->wl_surface);
> +	client_roundtrip(c1);
> +	assert(c1->test->geometry.x == 100);
> +	assert(c1->test->geometry.y == 100);
> +
> +	/* move pointer away from c1 */
> +	pointer_simulate_move(c1, 0, 0, 50, 50);
> +	assert(c1->input->pointer->focus == NULL);
> +	assert(c1->input->keyboard->focus == NULL);
> +
> +	/* move pointer to the c1's top-left corner (to bar) */
> +	pointer_simulate_move(c1, 50, 50,
> +			      100 + GRAB_SHIFT_X, 100 + GRAB_SHIFT_Y);
> +
> +	/* make sure we're in frame */
> +	assert(c1->input->pointer->x == -1);
> +	assert(c1->input->pointer->y == -1);
> +
> +	/* frame is not an input region ... */
> +	assert(c1->input->pointer->focus == NULL);
> +	assert(c1->input->keyboard->focus == NULL);
> +
> +	pointer_click(c1, BTN_LEFT);
> +	client_roundtrip(c1);
> +	assert(c1->input->pointer->focus == NULL);
> +	assert(c1->input->keyboard->focus == c1->surface->wl_surface);
> +
> +	/* move away from window */
> +	pointer_simulate_move(c1, 100, 100, 50, 50);
> +	assert(c1->input->pointer->focus == NULL);
> +	assert(c1->input->keyboard->focus == c1->surface->wl_surface);
> +
> +	/* move to input region */
> +	window_get_decoration_size(c1->toytoolkit->window, &dw, &dh);
> +	pointer_simulate_move(c1, 50, 50, 110 + dw, 110 + dh);
> +	assert(c1->input->pointer->focus == c1->surface->wl_surface);
> +	assert(c1->input->keyboard->focus == c1->surface->wl_surface);
> +	assert(c1->input->pointer->x == dw + 10);
> +	assert(c1->input->pointer->y == dh + 10);
> +
> +	/* move away again */
> +	pointer_simulate_move(c1, 110, 110, 50, 50);
> +	assert(c1->input->keyboard->focus == c1->surface->wl_surface);
> +	assert(c1->input->pointer->focus == NULL);
> +}


More information about the wayland-devel mailing list