chiark / gitweb /
Leave a bit of headroom above test port number, since we go at least
[disorder] / libtests / t-eventdist.c
CommitLineData
eb5e0673
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2008 Richard Kettlewell
4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
eb5e0673 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
eb5e0673 8 * (at your option) any later version.
e7eb3a27
RK
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
eb5e0673 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
eb5e0673
RK
17 */
18#include "test.h"
19#include "eventdist.h"
20
21static int wibbles, wobbles, wobble2s;
22
23static void on_wibble(const char *event, void *eventdata, void *callbackdata) {
24 check_string(event, "wibble");
25 check_string(eventdata, "wibble_eventdata");
26 check_string(callbackdata, "wibble_data");
27 ++wibbles;
28}
29
30static void on_wobble(const char *event, void *eventdata, void *callbackdata) {
31 check_string(event, "wobble");
32 check_string(eventdata, "wobble_eventdata");
33 check_string(callbackdata, "wobble_data");
34 ++wobbles;
35}
36
37static void on_wobble2(const char *event, void *eventdata, void *callbackdata) {
38 check_string(event, "wobble");
39 check_string(eventdata, "wobble_eventdata");
40 check_string(callbackdata, "wobble2_data");
41 ++wobble2s;
42}
43
44static void test_eventdist(void) {
45 event_handle wibble_handle, wobble_handle, wobble2_handle;
46 /* Raising unregistered events should be safe */
47 event_raise("wibble", NULL);
48 ++tests;
49
50 wibble_handle = event_register("wibble", on_wibble, (void *)"wibble_data");
51 wobble_handle = event_register("wobble", on_wobble, (void *)"wobble_data");
52 wobble2_handle = event_register("wobble", on_wobble2, (void *)"wobble2_data");
53 event_raise("wibble", (void *) "wibble_eventdata");
54 check_integer(wibbles, 1);
55 check_integer(wobbles, 0);
56 check_integer(wobble2s, 0);
57
58 event_raise("wobble", (void *)"wobble_eventdata");
59 check_integer(wibbles, 1);
60 check_integer(wobbles, 1);
61 check_integer(wobble2s, 1);
62
63 event_raise("wobble", (void *)"wobble_eventdata");
64 check_integer(wibbles, 1);
65 check_integer(wobbles, 2);
66 check_integer(wobble2s, 2);
67
68 event_cancel(wobble_handle);
69
70 event_raise("wibble", (void *)"wibble_eventdata");
71 check_integer(wibbles, 2);
72 check_integer(wobbles, 2);
73 check_integer(wobble2s, 2);
74
75 event_raise("wobble", (void *)"wobble_eventdata");
76 check_integer(wibbles, 2);
77 check_integer(wobbles, 2);
78 check_integer(wobble2s, 3);
79}
80
81TEST(eventdist);
82
83/*
84Local Variables:
85c-basic-offset:2
86comment-column:40
87fill-column:79
88indent-tabs-mode:nil
89End:
90*/