1 | /* |
2 | * Copyright © 2012 Intel Corporation |
3 | * |
4 | * Permission is hereby granted, free of charge, to any person obtaining |
5 | * a copy of this software and associated documentation files (the |
6 | * "Software"), to deal in the Software without restriction, including |
7 | * without limitation the rights to use, copy, modify, merge, publish, |
8 | * distribute, sublicense, and/or sell copies of the Software, and to |
9 | * permit persons to whom the Software is furnished to do so, subject to |
10 | * the following conditions: |
11 | * |
12 | * The above copyright notice and this permission notice (including the |
13 | * next paragraph) shall be included in all copies or substantial |
14 | * portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23 | * SOFTWARE. |
24 | */ |
25 | |
26 | #include <stdio.h> |
27 | #include <stdlib.h> |
28 | #include <stdarg.h> |
29 | #include <string.h> |
30 | #include <assert.h> |
31 | #include <sys/socket.h> |
32 | #include <unistd.h> |
33 | #include <errno.h> |
34 | #include <sys/types.h> |
35 | #include <sys/stat.h> |
36 | |
37 | #include "wayland-private.h" |
38 | #include "wayland-server.h" |
39 | #include "test-runner.h" |
40 | |
41 | struct client_destroy_listener { |
42 | struct wl_listener listener; |
43 | int done; |
44 | }; |
45 | |
46 | static void |
47 | client_destroy_notify(struct wl_listener *l, void *data) |
48 | { |
49 | struct client_destroy_listener *listener = |
50 | wl_container_of(l, listener, listener); |
51 | |
52 | listener->done = 1; |
53 | } |
54 | |
55 | TEST(client_destroy_listener) |
56 | { |
57 | struct wl_display *display; |
58 | struct wl_client *client; |
59 | struct client_destroy_listener a, b; |
60 | int s[2]; |
61 | |
62 | assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0); |
63 | display = wl_display_create(); |
64 | assert(display); |
65 | client = wl_client_create(display, fd: s[0]); |
66 | assert(client); |
67 | |
68 | a.listener.notify = client_destroy_notify; |
69 | a.done = 0; |
70 | wl_client_add_destroy_listener(client, listener: &a.listener); |
71 | |
72 | assert(wl_client_get_destroy_listener(client, client_destroy_notify) == |
73 | &a.listener); |
74 | |
75 | b.listener.notify = client_destroy_notify; |
76 | b.done = 0; |
77 | wl_client_add_destroy_listener(client, listener: &b.listener); |
78 | |
79 | wl_list_remove(elm: &a.listener.link); |
80 | |
81 | wl_client_destroy(client); |
82 | |
83 | assert(!a.done); |
84 | assert(b.done); |
85 | |
86 | close(fd: s[0]); |
87 | close(fd: s[1]); |
88 | |
89 | wl_display_destroy(display); |
90 | } |
91 | |
92 | |