~ubuntu-branches/ubuntu/trusty/wayland/trusty

« back to all changes in this revision

Viewing changes to tests/signal-test.c

  • Committer: Package Import Robot
  • Author(s): Hector Oron, Timo Aaltonen, Hector Oron
  • Date: 2013-10-11 11:23:38 UTC
  • mfrom: (1.1.15) (0.4.2 sid)
  • Revision ID: package-import@ubuntu.com-20131011112338-2jg0z6ncpm9qnots
Tags: 1.3.0-1
[ Timo Aaltonen ]
* control: Bump the libwayland0 C/R to (<< 1.1.0) so that it covers
  the ubuntu version too, and add it to -cursor.

[ Hector Oron ]
* New upstream stable release (1.3.0).
* Add myself to Uploaders.
* Switch to Debian source format 3.0 quilt.
* d/libwayland-dev.install:
  - install wayland documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 Marek Chalupa
 
3
 *
 
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.
 
13
 *
 
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
 
20
 * OF THIS SOFTWARE.
 
21
 */
 
22
 
 
23
#include <assert.h>
 
24
 
 
25
#include "wayland-server.h"
 
26
#include "test-runner.h"
 
27
 
 
28
static void
 
29
signal_notify(struct wl_listener *listener, void *data)
 
30
{
 
31
        /* only increase counter*/
 
32
        ++(*((int *) data));
 
33
}
 
34
 
 
35
TEST(signal_init)
 
36
{
 
37
        struct wl_signal signal;
 
38
 
 
39
        wl_signal_init(&signal);
 
40
 
 
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?");
 
46
}
 
47
 
 
48
TEST(signal_add_get)
 
49
{
 
50
        struct wl_signal signal;
 
51
 
 
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};
 
58
 
 
59
        wl_signal_init(&signal);
 
60
 
 
61
        wl_signal_add(&signal, &l1);
 
62
        wl_signal_add(&signal, &l2);
 
63
        wl_signal_add(&signal, &l3);
 
64
        wl_signal_add(&signal, &l4);
 
65
 
 
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);
 
70
 
 
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);
 
76
}
 
77
 
 
78
TEST(signal_emit_to_one_listener)
 
79
{
 
80
        int count = 0;
 
81
        int counter;
 
82
 
 
83
        struct wl_signal signal;
 
84
        struct wl_listener l1 = {.notify = signal_notify};
 
85
 
 
86
        wl_signal_init(&signal);
 
87
        wl_signal_add(&signal, &l1);
 
88
 
 
89
        for (counter = 0; counter < 100; counter++)
 
90
                wl_signal_emit(&signal, &count);
 
91
 
 
92
        assert(counter == count);
 
93
}
 
94
 
 
95
TEST(signal_emit_to_more_listeners)
 
96
{
 
97
        int count = 0;
 
98
        int counter;
 
99
 
 
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};
 
104
 
 
105
        wl_signal_init(&signal);
 
106
        wl_signal_add(&signal, &l1);
 
107
        wl_signal_add(&signal, &l2);
 
108
        wl_signal_add(&signal, &l3);
 
109
 
 
110
        for (counter = 0; counter < 100; counter++)
 
111
                wl_signal_emit(&signal, &count);
 
112
 
 
113
        assert(3 * counter == count);
 
114
}