tests: Ensure resource vs. client destroy handler order
Make sure that the client destroy handler runs strictly before the resource destroy handler, which runs strictly before the client late-destroy handler. Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
parent
51d788de5b
commit
86d73b2da2
|
@ -43,6 +43,8 @@ struct client_destroy_listener {
|
||||||
bool done;
|
bool done;
|
||||||
struct wl_listener late_listener;
|
struct wl_listener late_listener;
|
||||||
bool late_done;
|
bool late_done;
|
||||||
|
struct wl_listener resource_listener;
|
||||||
|
bool resource_done;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -51,8 +53,20 @@ client_destroy_notify(struct wl_listener *l, void *data)
|
||||||
struct client_destroy_listener *listener =
|
struct client_destroy_listener *listener =
|
||||||
wl_container_of(l, listener, listener);
|
wl_container_of(l, listener, listener);
|
||||||
|
|
||||||
assert(!listener->late_done);
|
|
||||||
listener->done = true;
|
listener->done = true;
|
||||||
|
assert(!listener->resource_done);
|
||||||
|
assert(!listener->late_done);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
client_resource_destroy_notify(struct wl_listener *l, void *data)
|
||||||
|
{
|
||||||
|
struct client_destroy_listener *listener =
|
||||||
|
wl_container_of(l, listener, resource_listener);
|
||||||
|
|
||||||
|
assert(listener->done);
|
||||||
|
listener->resource_done = true;
|
||||||
|
assert(!listener->late_done);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -62,6 +76,7 @@ client_late_destroy_notify(struct wl_listener *l, void *data)
|
||||||
wl_container_of(l, listener, late_listener);
|
wl_container_of(l, listener, late_listener);
|
||||||
|
|
||||||
assert(listener->done);
|
assert(listener->done);
|
||||||
|
assert(listener->resource_done);
|
||||||
listener->late_done = true;
|
listener->late_done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +84,7 @@ TEST(client_destroy_listener)
|
||||||
{
|
{
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
struct wl_client *client;
|
struct wl_client *client;
|
||||||
|
struct wl_resource *resource;
|
||||||
struct client_destroy_listener a, b;
|
struct client_destroy_listener a, b;
|
||||||
int s[2];
|
int s[2];
|
||||||
|
|
||||||
|
@ -78,33 +94,47 @@ TEST(client_destroy_listener)
|
||||||
client = wl_client_create(display, s[0]);
|
client = wl_client_create(display, s[0]);
|
||||||
assert(client);
|
assert(client);
|
||||||
|
|
||||||
|
resource = wl_resource_create(client, &wl_callback_interface, 1, 0);
|
||||||
|
assert(resource);
|
||||||
|
|
||||||
a.listener.notify = client_destroy_notify;
|
a.listener.notify = client_destroy_notify;
|
||||||
a.done = false;
|
a.done = false;
|
||||||
|
a.resource_listener.notify = client_resource_destroy_notify;
|
||||||
|
a.resource_done = false;
|
||||||
a.late_listener.notify = client_late_destroy_notify;
|
a.late_listener.notify = client_late_destroy_notify;
|
||||||
a.late_done = false;
|
a.late_done = false;
|
||||||
wl_client_add_destroy_listener(client, &a.listener);
|
wl_client_add_destroy_listener(client, &a.listener);
|
||||||
|
wl_resource_add_destroy_listener(resource, &a.resource_listener);
|
||||||
wl_client_add_destroy_late_listener(client, &a.late_listener);
|
wl_client_add_destroy_late_listener(client, &a.late_listener);
|
||||||
|
|
||||||
assert(wl_client_get_destroy_listener(client, client_destroy_notify) ==
|
assert(wl_client_get_destroy_listener(client, client_destroy_notify) ==
|
||||||
&a.listener);
|
&a.listener);
|
||||||
|
assert(wl_resource_get_destroy_listener(resource, client_resource_destroy_notify) ==
|
||||||
|
&a.resource_listener);
|
||||||
assert(wl_client_get_destroy_late_listener(client, client_late_destroy_notify) ==
|
assert(wl_client_get_destroy_late_listener(client, client_late_destroy_notify) ==
|
||||||
&a.late_listener);
|
&a.late_listener);
|
||||||
|
|
||||||
b.listener.notify = client_destroy_notify;
|
b.listener.notify = client_destroy_notify;
|
||||||
b.done = false;
|
b.done = false;
|
||||||
|
b.resource_listener.notify = client_resource_destroy_notify;
|
||||||
|
b.resource_done = false;
|
||||||
b.late_listener.notify = client_late_destroy_notify;
|
b.late_listener.notify = client_late_destroy_notify;
|
||||||
b.late_done = false;
|
b.late_done = false;
|
||||||
wl_client_add_destroy_listener(client, &b.listener);
|
wl_client_add_destroy_listener(client, &b.listener);
|
||||||
|
wl_resource_add_destroy_listener(resource, &b.resource_listener);
|
||||||
wl_client_add_destroy_late_listener(client, &b.late_listener);
|
wl_client_add_destroy_late_listener(client, &b.late_listener);
|
||||||
|
|
||||||
wl_list_remove(&a.listener.link);
|
wl_list_remove(&a.listener.link);
|
||||||
|
wl_list_remove(&a.resource_listener.link);
|
||||||
wl_list_remove(&a.late_listener.link);
|
wl_list_remove(&a.late_listener.link);
|
||||||
|
|
||||||
wl_client_destroy(client);
|
wl_client_destroy(client);
|
||||||
|
|
||||||
assert(!a.done);
|
assert(!a.done);
|
||||||
|
assert(!a.resource_done);
|
||||||
assert(!a.late_done);
|
assert(!a.late_done);
|
||||||
assert(b.done);
|
assert(b.done);
|
||||||
|
assert(b.resource_done);
|
||||||
assert(b.late_done);
|
assert(b.late_done);
|
||||||
|
|
||||||
close(s[0]);
|
close(s[0]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user