2 * Copyright © 2012 Jonas Ådahl
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
26 #include <sys/types.h>
30 #include "wayland-client.h"
31 #include "wayland-server.h"
32 #include "test-runner.h"
34 #define SOCKET_NAME "wayland-queue-test"
36 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
38 #define client_assert(expr) \
41 fprintf(stderr, "%s:%d: " \
42 "Assertion `%s' failed.\n", \
43 __FILE__, __LINE__, #expr); \
49 struct wl_display *display;
50 int child_exit_status;
54 sigchld_handler(int signal_number, void *data)
56 struct display *display = data;
59 waitpid(-1, &status, 0);
60 display->child_exit_status = WEXITSTATUS(status);
62 wl_display_terminate(display->display);
68 registry_handle_global(void *data, struct wl_registry *registry,
69 uint32_t id, const char *interface, uint32_t version)
73 client_assert(*pcounter == 1);
74 wl_registry_destroy(registry);
77 static const struct wl_registry_listener registry_listener = {
78 registry_handle_global,
83 client_alarm_handler(int sig)
89 client_continue_handler(int sig)
96 struct wl_display *display;
97 struct wl_registry *registry;
100 signal(SIGALRM, client_alarm_handler);
101 signal(SIGCONT, client_continue_handler);
105 display = wl_display_connect(SOCKET_NAME);
106 client_assert(display);
108 registry = wl_display_get_registry(display);
109 wl_registry_add_listener(registry, ®istry_listener, &counter);
110 wl_display_roundtrip(display);
112 client_assert(counter == 1);
114 wl_display_disconnect(display);
120 dummy_bind(struct wl_client *client,
121 void *data, uint32_t version, uint32_t id)
125 TEST(queue_destroy_proxy)
127 struct display display;
128 struct wl_event_loop *loop;
129 struct wl_event_source *signal_source;
130 const struct wl_interface *dummy_interfaces[] = {
132 &wl_pointer_interface,
133 &wl_keyboard_interface,
134 &wl_surface_interface
144 } else if (pid == 0) {
148 display.child_exit_status = EXIT_FAILURE;
149 display.display = wl_display_create();
150 assert(display.display);
152 for (i = 0; i < ARRAY_LENGTH(dummy_interfaces); i++)
153 wl_display_add_global(display.display, dummy_interfaces[i],
156 ret = wl_display_add_socket(display.display, SOCKET_NAME);
159 loop = wl_display_get_event_loop(display.display);
160 signal_source = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
164 wl_display_run(display.display);
166 wl_event_source_remove(signal_source);
167 wl_display_destroy(display.display);
169 assert(display.child_exit_status == EXIT_SUCCESS);