2
* Copyright © 2013 Marek Chalupa
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
* documentation for any purpose is hereby granted without fee, provided that
6
* the above copyright notice appear in all copies and that both that copyright
7
* notice and this permission notice appear in supporting documentation, and
8
* that the name of the copyright holders not be used in advertising or
9
* publicity pertaining to distribution of the software without specific,
10
* written prior permission. The copyright holders make no representations
11
* about the suitability of this software for any purpose. It is provided "as
12
* is" without express or implied warranty.
14
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24
#include <sys/socket.h>
27
#include "wayland-server.h"
28
#include "test-runner.h"
30
TEST(create_resource_tst)
32
struct wl_display *display;
33
struct wl_client *client;
34
struct wl_resource *res;
39
assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
40
display = wl_display_create();
42
client = wl_client_create(display, s[0]);
45
res = wl_resource_create(client, &wl_display_interface, 4, 0);
49
assert(wl_resource_get_version(res) == 4);
51
assert(client == wl_resource_get_client(res));
52
id = wl_resource_get_id(res);
53
assert(wl_client_get_object(client, id) == res);
55
link = wl_resource_get_link(res);
57
assert(wl_resource_from_link(link) == res);
59
wl_resource_set_user_data(res, (void *) 0xbee);
60
assert(wl_resource_get_user_data(res) == (void *) 0xbee);
62
wl_resource_destroy(res);
63
wl_client_destroy(client);
64
wl_display_destroy(display);
69
res_destroy_func(struct wl_resource *res)
73
_Bool *destr = wl_resource_get_user_data(res);
77
static _Bool notify_called = 0;
79
destroy_notify(struct wl_listener *l, void *data)
87
struct wl_display *display;
88
struct wl_client *client;
89
struct wl_resource *res;
95
struct wl_listener destroy_listener = {
96
.notify = &destroy_notify
99
assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
100
display = wl_display_create();
102
client = wl_client_create(display, s[0]);
105
res = wl_resource_create(client, &wl_display_interface, 4, 0);
107
wl_resource_set_implementation(res, NULL, &destroyed, res_destroy_func);
108
wl_resource_add_destroy_listener(res, &destroy_listener);
110
/* without implementation this should be ignored .. */
111
wl_resource_post_event(res, 0);
113
id = wl_resource_get_id(res);
114
link = wl_resource_get_link(res);
117
wl_resource_destroy(res);
119
assert(notify_called); /* check if signal was emitted */
120
assert(wl_client_get_object(client, id) == NULL);
122
res = wl_resource_create(client, &wl_display_interface, 2, 0);
126
wl_resource_set_destructor(res, res_destroy_func);
127
wl_resource_set_user_data(res, &destroyed);
128
wl_resource_add_destroy_listener(res, &destroy_listener);
129
/* client should destroy the resource upon its destruction */
130
wl_client_destroy(client);
132
assert(notify_called);
134
wl_display_destroy(display);
138
TEST(create_resource_with_same_id)
140
struct wl_display *display;
141
struct wl_client *client;
142
struct wl_resource *res, *res2;
146
assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
147
display = wl_display_create();
149
client = wl_client_create(display, s[0]);
152
res = wl_resource_create(client, &wl_display_interface, 2, 0);
154
id = wl_resource_get_id(res);
155
assert(wl_client_get_object(client, id) == res);
157
/* this one should replace the old one */
158
res2 = wl_resource_create(client, &wl_display_interface, 1, id);
159
assert(wl_client_get_object(client, id) == res2);
161
wl_resource_destroy(res2);
162
wl_resource_destroy(res);
164
wl_client_destroy(client);
165
wl_display_destroy(display);