2012-04-13 21:53:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
*
|
2015-06-10 17:57:59 +08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2012-04-13 21:53:15 +08:00
|
|
|
*
|
2015-06-10 17:57:59 +08:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2012-04-13 21:53:15 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2012-10-21 22:04:17 +08:00
|
|
|
#include "wayland-private.h"
|
2013-06-28 09:09:18 +08:00
|
|
|
#include "wayland-server.h"
|
2012-04-13 21:53:15 +08:00
|
|
|
#include "test-runner.h"
|
|
|
|
|
|
|
|
struct client_destroy_listener {
|
|
|
|
struct wl_listener listener;
|
2022-07-21 17:50:30 +08:00
|
|
|
bool done;
|
2022-07-21 18:07:04 +08:00
|
|
|
struct wl_listener late_listener;
|
|
|
|
bool late_done;
|
2022-07-21 18:18:48 +08:00
|
|
|
struct wl_listener resource_listener;
|
|
|
|
bool resource_done;
|
2012-04-13 21:53:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_destroy_notify(struct wl_listener *l, void *data)
|
|
|
|
{
|
|
|
|
struct client_destroy_listener *listener =
|
2019-06-02 06:11:48 +08:00
|
|
|
wl_container_of(l, listener, listener);
|
2012-04-13 21:53:15 +08:00
|
|
|
|
2022-07-21 17:50:30 +08:00
|
|
|
listener->done = true;
|
2022-07-21 18:18:48 +08:00
|
|
|
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);
|
2012-04-13 21:53:15 +08:00
|
|
|
}
|
|
|
|
|
2022-07-21 18:07:04 +08:00
|
|
|
static void
|
|
|
|
client_late_destroy_notify(struct wl_listener *l, void *data)
|
|
|
|
{
|
|
|
|
struct client_destroy_listener *listener =
|
|
|
|
wl_container_of(l, listener, late_listener);
|
|
|
|
|
|
|
|
assert(listener->done);
|
2022-07-21 18:18:48 +08:00
|
|
|
assert(listener->resource_done);
|
2022-07-21 18:07:04 +08:00
|
|
|
listener->late_done = true;
|
|
|
|
}
|
|
|
|
|
2012-04-13 21:53:15 +08:00
|
|
|
TEST(client_destroy_listener)
|
|
|
|
{
|
|
|
|
struct wl_display *display;
|
|
|
|
struct wl_client *client;
|
2022-07-21 18:18:48 +08:00
|
|
|
struct wl_resource *resource;
|
2012-04-13 21:53:15 +08:00
|
|
|
struct client_destroy_listener a, b;
|
|
|
|
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);
|
|
|
|
|
2022-07-21 18:18:48 +08:00
|
|
|
resource = wl_resource_create(client, &wl_callback_interface, 1, 0);
|
|
|
|
assert(resource);
|
|
|
|
|
2012-04-13 21:53:15 +08:00
|
|
|
a.listener.notify = client_destroy_notify;
|
2022-07-21 17:50:30 +08:00
|
|
|
a.done = false;
|
2022-07-21 18:18:48 +08:00
|
|
|
a.resource_listener.notify = client_resource_destroy_notify;
|
|
|
|
a.resource_done = false;
|
2022-07-21 18:07:04 +08:00
|
|
|
a.late_listener.notify = client_late_destroy_notify;
|
|
|
|
a.late_done = false;
|
2012-04-13 21:53:15 +08:00
|
|
|
wl_client_add_destroy_listener(client, &a.listener);
|
2022-07-21 18:18:48 +08:00
|
|
|
wl_resource_add_destroy_listener(resource, &a.resource_listener);
|
2022-07-21 18:07:04 +08:00
|
|
|
wl_client_add_destroy_late_listener(client, &a.late_listener);
|
2012-04-13 21:53:15 +08:00
|
|
|
|
|
|
|
assert(wl_client_get_destroy_listener(client, client_destroy_notify) ==
|
|
|
|
&a.listener);
|
2022-07-21 18:18:48 +08:00
|
|
|
assert(wl_resource_get_destroy_listener(resource, client_resource_destroy_notify) ==
|
|
|
|
&a.resource_listener);
|
2022-07-21 18:07:04 +08:00
|
|
|
assert(wl_client_get_destroy_late_listener(client, client_late_destroy_notify) ==
|
|
|
|
&a.late_listener);
|
2012-04-13 21:53:15 +08:00
|
|
|
|
|
|
|
b.listener.notify = client_destroy_notify;
|
2022-07-21 17:50:30 +08:00
|
|
|
b.done = false;
|
2022-07-21 18:18:48 +08:00
|
|
|
b.resource_listener.notify = client_resource_destroy_notify;
|
|
|
|
b.resource_done = false;
|
2022-07-21 18:07:04 +08:00
|
|
|
b.late_listener.notify = client_late_destroy_notify;
|
|
|
|
b.late_done = false;
|
2012-04-13 21:53:15 +08:00
|
|
|
wl_client_add_destroy_listener(client, &b.listener);
|
2022-07-21 18:18:48 +08:00
|
|
|
wl_resource_add_destroy_listener(resource, &b.resource_listener);
|
2022-07-21 18:07:04 +08:00
|
|
|
wl_client_add_destroy_late_listener(client, &b.late_listener);
|
2012-04-13 21:53:15 +08:00
|
|
|
|
|
|
|
wl_list_remove(&a.listener.link);
|
2022-07-21 18:18:48 +08:00
|
|
|
wl_list_remove(&a.resource_listener.link);
|
2022-07-21 18:07:04 +08:00
|
|
|
wl_list_remove(&a.late_listener.link);
|
2012-04-13 21:53:15 +08:00
|
|
|
|
|
|
|
wl_client_destroy(client);
|
|
|
|
|
|
|
|
assert(!a.done);
|
2022-07-21 18:18:48 +08:00
|
|
|
assert(!a.resource_done);
|
2022-07-21 18:07:04 +08:00
|
|
|
assert(!a.late_done);
|
2012-04-13 21:53:15 +08:00
|
|
|
assert(b.done);
|
2022-07-21 18:18:48 +08:00
|
|
|
assert(b.resource_done);
|
2022-07-21 18:07:04 +08:00
|
|
|
assert(b.late_done);
|
2012-04-13 21:53:15 +08:00
|
|
|
|
|
|
|
close(s[0]);
|
|
|
|
close(s[1]);
|
|
|
|
|
|
|
|
wl_display_destroy(display);
|
|
|
|
}
|
|
|
|
|