2 * This file is part of DisOrder.
3 * Copyright (C) 2008 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "eventdist.h"
21 static int wibbles
, wobbles
, wobble2s
;
23 static 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");
30 static 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");
37 static 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");
44 static 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
);
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);
58 event_raise("wobble", (void *)"wobble_eventdata");
59 check_integer(wibbles
, 1);
60 check_integer(wobbles
, 1);
61 check_integer(wobble2s
, 1);
63 event_raise("wobble", (void *)"wobble_eventdata");
64 check_integer(wibbles
, 1);
65 check_integer(wobbles
, 2);
66 check_integer(wobble2s
, 2);
68 event_cancel(wobble_handle
);
70 event_raise("wibble", (void *)"wibble_eventdata");
71 check_integer(wibbles
, 2);
72 check_integer(wobbles
, 2);
73 check_integer(wobble2s
, 2);
75 event_raise("wobble", (void *)"wobble_eventdata");
76 check_integer(wibbles
, 2);
77 check_integer(wobbles
, 2);
78 check_integer(wobble2s
, 3);
80 event_cancel(wibble_handle
);
81 event_cancel(wobble2_handle
);