when the client is being destroyed, we can use wl_client_get_object()
to get an object. Test whether it returns NULL when the object
has been destroyed

Signed-off-by: Marek Chalupa <mchqwe...@gmail.com>
---
 tests/client-test.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/tests/client-test.c b/tests/client-test.c
index cb08e39..f171f19 100644
--- a/tests/client-test.c
+++ b/tests/client-test.c
@@ -126,3 +126,66 @@ TEST(client_post_nomem_on_destruction)
        wl_display_destroy(display);
 }
 
+static void
+seat_destroy_get_object(struct wl_listener *l, void *data)
+{
+       struct wl_resource *resource = data;
+       struct wl_client *client = wl_resource_get_client(resource);
+       /* This seat was created last,
+        * therefore the seat's id is the upper bound for all ids */
+       uint32_t max_id = wl_resource_get_id(resource);
+       uint32_t i;
+
+       for (i = WL_SERVER_ID_START; i < max_id; ++i) {
+               /* all these objects are destroyed now, since
+                * we destroy the objects in id order */
+               assert(wl_client_get_object(client, i) == NULL);
+       }
+
+       /* only our object is not still destroyed */
+       assert(wl_client_get_object(client, max_id) != NULL);
+       assert(wl_client_get_object(client, max_id + 1) == NULL);
+}
+
+TEST(client_get_object_on_destruction)
+{
+       struct wl_display *display;
+       struct wl_client *client;
+       struct wl_resource *resource;
+       int s[2];
+
+       assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
+       display = wl_display_create();
+       assert(display);
+       client = wl_client_create(display, s[0]);
+       assert(client);
+
+       /* create few other objects
+        * -- it doesn't matter what is the interface */
+       resource = wl_resource_create(client, &wl_seat_interface,
+                                     wl_seat_interface.version, 0);
+       assert(resource);
+       resource = wl_resource_create(client, &wl_seat_interface,
+                                     wl_seat_interface.version, 0);
+       assert(resource);
+       resource = wl_resource_create(client, &wl_seat_interface,
+                                     wl_seat_interface.version, 0);
+       assert(resource);
+
+
+       /* for the last one we set destroy listener */
+       resource = wl_resource_create(client, &wl_seat_interface,
+                                     wl_seat_interface.version, 0);
+       assert(resource);
+
+       seat_destroy_listener.notify = seat_destroy_get_object;
+       wl_resource_add_destroy_listener(resource, &seat_destroy_listener);
+
+       wl_client_destroy(client);
+
+       close(s[0]);
+       close(s[1]);
+
+       wl_display_destroy(display);
+}
+
-- 
2.5.5

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to