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 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 #include "eventdist.h"
23 static int wibbles
, wobbles
, wobble2s
;
25 static void on_wibble(const char *event
, void *eventdata
, void *callbackdata
) {
26 check_string(event
, "wibble");
27 check_string(eventdata
, "wibble_eventdata");
28 check_string(callbackdata
, "wibble_data");
32 static void on_wobble(const char *event
, void *eventdata
, void *callbackdata
) {
33 check_string(event
, "wobble");
34 check_string(eventdata
, "wobble_eventdata");
35 check_string(callbackdata
, "wobble_data");
39 static void on_wobble2(const char *event
, void *eventdata
, void *callbackdata
) {
40 check_string(event
, "wobble");
41 check_string(eventdata
, "wobble_eventdata");
42 check_string(callbackdata
, "wobble2_data");
46 static void test_eventdist(void) {
47 event_handle wibble_handle
, wobble_handle
, wobble2_handle
;
48 /* Raising unregistered events should be safe */
49 event_raise("wibble", NULL
);
52 wibble_handle
= event_register("wibble", on_wibble
, (void *)"wibble_data");
53 wobble_handle
= event_register("wobble", on_wobble
, (void *)"wobble_data");
54 wobble2_handle
= event_register("wobble", on_wobble2
, (void *)"wobble2_data");
55 event_raise("wibble", (void *) "wibble_eventdata");
56 check_integer(wibbles
, 1);
57 check_integer(wobbles
, 0);
58 check_integer(wobble2s
, 0);
60 event_raise("wobble", (void *)"wobble_eventdata");
61 check_integer(wibbles
, 1);
62 check_integer(wobbles
, 1);
63 check_integer(wobble2s
, 1);
65 event_raise("wobble", (void *)"wobble_eventdata");
66 check_integer(wibbles
, 1);
67 check_integer(wobbles
, 2);
68 check_integer(wobble2s
, 2);
70 event_cancel(wobble_handle
);
72 event_raise("wibble", (void *)"wibble_eventdata");
73 check_integer(wibbles
, 2);
74 check_integer(wobbles
, 2);
75 check_integer(wobble2s
, 2);
77 event_raise("wobble", (void *)"wobble_eventdata");
78 check_integer(wibbles
, 2);
79 check_integer(wobbles
, 2);
80 check_integer(wobble2s
, 3);