tests: Support weston_test request for adding a test seat

Support adding a test seat using the weston_test.device_add request.
This will be used in tests in upcoming commits where we will need to
re-add the seat after having it removed.

We only support one test seat at the moment, so this commit also
introduces checks to ensure the client doesn't try to create multiple
test seats or try to remove an already removed test seat.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Alexandros Frantzis 7 years ago committed by Pekka Paalanen
parent b0b598c73c
commit 85f8432911
  1. 32
      tests/weston-test.c

@ -50,6 +50,7 @@ struct weston_test {
struct weston_layer layer; struct weston_layer layer;
struct weston_process process; struct weston_process process;
struct weston_seat seat; struct weston_seat seat;
bool is_seat_initialized;
}; };
struct weston_test_surface { struct weston_test_surface {
@ -76,6 +77,22 @@ test_client_sigchld(struct weston_process *process, int status)
wl_display_terminate(test->compositor->wl_display); wl_display_terminate(test->compositor->wl_display);
} }
static int
test_seat_init(struct weston_test *test)
{
/* create our own seat */
weston_seat_init(&test->seat, test->compositor, "test-seat");
test->is_seat_initialized = true;
/* add devices */
weston_seat_init_pointer(&test->seat);
if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
return -1;
weston_seat_init_touch(&test->seat);
return 0;
}
static struct weston_seat * static struct weston_seat *
get_seat(struct weston_test *test) get_seat(struct weston_test *test)
{ {
@ -253,7 +270,10 @@ device_release(struct wl_client *client,
} else if (strcmp(device, "touch") == 0) { } else if (strcmp(device, "touch") == 0) {
weston_seat_release_touch(seat); weston_seat_release_touch(seat);
} else if (strcmp(device, "seat") == 0) { } else if (strcmp(device, "seat") == 0) {
assert(test->is_seat_initialized &&
"Trying to release already released test seat");
weston_seat_release(seat); weston_seat_release(seat);
test->is_seat_initialized = false;
} else { } else {
assert(0 && "Unsupported device"); assert(0 && "Unsupported device");
} }
@ -272,6 +292,10 @@ device_add(struct wl_client *client,
weston_seat_init_keyboard(seat, NULL); weston_seat_init_keyboard(seat, NULL);
} else if (strcmp(device, "touch") == 0) { } else if (strcmp(device, "touch") == 0) {
weston_seat_init_touch(seat); weston_seat_init_touch(seat);
} else if (strcmp(device, "seat") == 0) {
assert(!test->is_seat_initialized &&
"Trying to add already added test seat");
test_seat_init(test);
} else { } else {
assert(0 && "Unsupported device"); assert(0 && "Unsupported device");
} }
@ -611,14 +635,8 @@ wet_module_init(struct weston_compositor *ec,
test, bind_test) == NULL) test, bind_test) == NULL)
return -1; return -1;
/* create our own seat */ if (test_seat_init(test) == -1)
weston_seat_init(&test->seat, ec, "test-seat");
/* add devices */
weston_seat_init_pointer(&test->seat);
if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
return -1; return -1;
weston_seat_init_touch(&test->seat);
loop = wl_display_get_event_loop(ec->wl_display); loop = wl_display_get_event_loop(ec->wl_display);
wl_event_loop_add_idle(loop, idle_launch_client, test); wl_event_loop_add_idle(loop, idle_launch_client, test);

Loading…
Cancel
Save