Commit | Line | Data |
---|---|---|
eb5e0673 RK |
1 | /* |
2 | * This file is part of DisOrder. | |
3 | * Copyright (C) 2008 Richard Kettlewell | |
4 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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 | |
18 | * USA | |
19 | */ | |
20 | #include "test.h" | |
21 | #include "eventdist.h" | |
22 | ||
23 | static int wibbles, wobbles, wobble2s; | |
24 | ||
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"); | |
29 | ++wibbles; | |
30 | } | |
31 | ||
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"); | |
36 | ++wobbles; | |
37 | } | |
38 | ||
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"); | |
43 | ++wobble2s; | |
44 | } | |
45 | ||
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); | |
50 | ++tests; | |
51 | ||
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); | |
59 | ||
60 | event_raise("wobble", (void *)"wobble_eventdata"); | |
61 | check_integer(wibbles, 1); | |
62 | check_integer(wobbles, 1); | |
63 | check_integer(wobble2s, 1); | |
64 | ||
65 | event_raise("wobble", (void *)"wobble_eventdata"); | |
66 | check_integer(wibbles, 1); | |
67 | check_integer(wobbles, 2); | |
68 | check_integer(wobble2s, 2); | |
69 | ||
70 | event_cancel(wobble_handle); | |
71 | ||
72 | event_raise("wibble", (void *)"wibble_eventdata"); | |
73 | check_integer(wibbles, 2); | |
74 | check_integer(wobbles, 2); | |
75 | check_integer(wobble2s, 2); | |
76 | ||
77 | event_raise("wobble", (void *)"wobble_eventdata"); | |
78 | check_integer(wibbles, 2); | |
79 | check_integer(wobbles, 2); | |
80 | check_integer(wobble2s, 3); | |
81 | } | |
82 | ||
83 | TEST(eventdist); | |
84 | ||
85 | /* | |
86 | Local Variables: | |
87 | c-basic-offset:2 | |
88 | comment-column:40 | |
89 | fill-column:79 | |
90 | indent-tabs-mode:nil | |
91 | End: | |
92 | */ |