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
25
#include "wayland-server.h"
26
#include "test-runner.h"
29
signal_notify(struct wl_listener *listener, void *data)
31
/* only increase counter*/
37
struct wl_signal signal;
39
wl_signal_init(&signal);
41
/* Test if listeners' list is initialized */
42
assert(&signal.listener_list == signal.listener_list.next
43
&& "Maybe wl_signal implementation changed?");
44
assert(signal.listener_list.next == signal.listener_list.prev
45
&& "Maybe wl_signal implementation changed?");
50
struct wl_signal signal;
52
/* we just need different values of notify */
53
struct wl_listener l1 = {.notify = (wl_notify_func_t) 0x1};
54
struct wl_listener l2 = {.notify = (wl_notify_func_t) 0x2};
55
struct wl_listener l3 = {.notify = (wl_notify_func_t) 0x3};
56
/* one real, why not */
57
struct wl_listener l4 = {.notify = signal_notify};
59
wl_signal_init(&signal);
61
wl_signal_add(&signal, &l1);
62
wl_signal_add(&signal, &l2);
63
wl_signal_add(&signal, &l3);
64
wl_signal_add(&signal, &l4);
66
assert(wl_signal_get(&signal, signal_notify) == &l4);
67
assert(wl_signal_get(&signal, (wl_notify_func_t) 0x3) == &l3);
68
assert(wl_signal_get(&signal, (wl_notify_func_t) 0x2) == &l2);
69
assert(wl_signal_get(&signal, (wl_notify_func_t) 0x1) == &l1);
71
/* get should not be destructive */
72
assert(wl_signal_get(&signal, signal_notify) == &l4);
73
assert(wl_signal_get(&signal, (wl_notify_func_t) 0x3) == &l3);
74
assert(wl_signal_get(&signal, (wl_notify_func_t) 0x2) == &l2);
75
assert(wl_signal_get(&signal, (wl_notify_func_t) 0x1) == &l1);
78
TEST(signal_emit_to_one_listener)
83
struct wl_signal signal;
84
struct wl_listener l1 = {.notify = signal_notify};
86
wl_signal_init(&signal);
87
wl_signal_add(&signal, &l1);
89
for (counter = 0; counter < 100; counter++)
90
wl_signal_emit(&signal, &count);
92
assert(counter == count);
95
TEST(signal_emit_to_more_listeners)
100
struct wl_signal signal;
101
struct wl_listener l1 = {.notify = signal_notify};
102
struct wl_listener l2 = {.notify = signal_notify};
103
struct wl_listener l3 = {.notify = signal_notify};
105
wl_signal_init(&signal);
106
wl_signal_add(&signal, &l1);
107
wl_signal_add(&signal, &l2);
108
wl_signal_add(&signal, &l3);
110
for (counter = 0; counter < 100; counter++)
111
wl_signal_emit(&signal, &count);
113
assert(3 * counter == count);