Commit 20ca9380 authored by Simon Ser's avatar Simon Ser

tests: add a test for wl_global_remove

This test makes sure that after wl_global_remove:

* The global_remove event is sent to existing clients
* Binding to the removed global still works
* A new client will not see the removed global advertised
Signed-off-by: Simon Ser's avatarSimon Ser <contact@emersion.fr>
parent 733af776
Pipeline #62520 passed with stage
in 1 minute and 48 seconds
...@@ -1487,3 +1487,154 @@ TEST(send_overflow_disconnection) ...@@ -1487,3 +1487,154 @@ TEST(send_overflow_disconnection)
display_destroy(d); display_destroy(d);
} }
static void
registry_global_remove_before_handle_global(void *data,
struct wl_registry *registry,
uint32_t id, const char *intf,
uint32_t ver)
{
uint32_t *id_ptr = data;
if (strcmp(intf, wl_seat_interface.name) == 0) {
assert(*id_ptr == 0);
*id_ptr = id;
}
}
static void
registry_global_remove_before_handle_global_remove(void *data,
struct wl_registry *registry,
uint32_t id)
{
uint32_t *id_ptr = data;
if (*id_ptr == id) {
*id_ptr = 0;
}
}
/* This listener expects a uint32_t user data pointer, sets it to the wl_seat
* global ID when receiving a "global" event, and sets it to zero when receiving
* a "global_remove" event. */
static const struct wl_registry_listener global_remove_before_registry_listener = {
registry_global_remove_before_handle_global,
registry_global_remove_before_handle_global_remove,
};
static void
global_remove_before_client(void *data)
{
struct client *c = client_connect();
struct wl_registry *registry;
uint32_t global_id = 0;
struct wl_seat *seat;
int ret;
char tmp = '\0';
int *fds = data;
registry = wl_display_get_registry(c->wl_display);
wl_registry_add_listener(registry,
&global_remove_before_registry_listener,
&global_id);
ret = wl_display_roundtrip(c->wl_display);
assert(ret >= 0);
assert(global_id != 0);
/* Wait for the compositor to remove the global */
assert(write(fds[1], &tmp, sizeof(tmp)) == sizeof(tmp));
(void)read(fds[1], &tmp, sizeof(tmp));
/* Check binding still works after the global has been removed. Also
* check we get the global_remove event. */
seat = wl_registry_bind(registry, global_id, &wl_seat_interface, 1);
ret = wl_display_roundtrip(c->wl_display);
assert(ret >= 0);
assert(global_id == 0);
wl_seat_destroy(seat);
wl_registry_destroy(registry);
client_disconnect_nocheck(c);
}
static void
registry_global_remove_after_handle_global(void *data,
struct wl_registry *registry,
uint32_t id, const char *intf,
uint32_t ver)
{
/* Make sure the global isn't advertised anymore after being removed */
assert(strcmp(intf, wl_seat_interface.name) != 0);
}
static const struct wl_registry_listener global_remove_after_registry_listener = {
registry_global_remove_after_handle_global,
NULL,
};
static void
global_remove_after_client(void *data)
{
struct client *c = client_connect();
struct wl_registry *registry;
uint32_t global_id = 0;
struct wl_seat *seat;
int ret;
registry = wl_display_get_registry(c->wl_display);
wl_registry_add_listener(registry,
&global_remove_after_registry_listener,
&global_id);
ret = wl_display_roundtrip(c->wl_display);
assert(ret >= 0);
wl_registry_destroy(registry);
client_disconnect_nocheck(c);
}
TEST(global_remove)
{
struct display *d;
struct wl_global *global;
int fds[2];
char tmp = '\0';
int i;
assert(socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) != -1);
d = display_create();
global = wl_global_create(d->wl_display, &wl_seat_interface,
1, d, bind_seat);
/* Create a client before removing the global */
client_create(d, global_remove_before_client, fds);
close(fds[1]);
for (i = 0; i < 2; i++) {
wl_event_loop_dispatch(wl_display_get_event_loop(d->wl_display), -1);
wl_display_flush_clients(d->wl_display);
}
/* Wait for the first client to receive the list of globals */
(void)read(fds[0], &tmp, sizeof(tmp));
wl_global_remove(global);
assert(write(fds[0], &tmp, sizeof(tmp)) == sizeof(tmp));
close(fds[0]);
/* Create another client after removing the global */
client_create_noarg(d, global_remove_after_client);
display_run(d);
wl_global_destroy(global);
display_destroy(d);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment