Commit | Line | Data |
---|---|---|
3af7813d 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 |
3af7813d | 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 |
3af7813d | 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 | * | |
3af7813d | 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/>. |
3af7813d RK |
17 | */ |
18 | #include "test.h" | |
19 | #include "event.h" | |
20 | ||
21 | #include <time.h> | |
22 | ||
3af7813d RK |
23 | static int run1, run2, run3; |
24 | static ev_timeout_handle t1, t2, t3; | |
25 | ||
0ddbd899 | 26 | static int callback1(ev_source *ev, |
3af7813d RK |
27 | const struct timeval attribute((unused)) *now, |
28 | void attribute((unused)) *u) { | |
29 | run1 = 1; | |
30 | ev_timeout_cancel(ev, t2); | |
31 | return 0; | |
32 | } | |
33 | ||
34 | static int callback2(ev_source attribute((unused)) *ev, | |
35 | const struct timeval attribute((unused)) *now, | |
36 | void attribute((unused)) *u) { | |
37 | run2 = 1; | |
38 | return 0; | |
39 | } | |
40 | ||
41 | static int callback3(ev_source attribute((unused)) *ev, | |
42 | const struct timeval attribute((unused)) *now, | |
43 | void attribute((unused)) *u) { | |
44 | run3 = 1; | |
45 | return 1; | |
46 | } | |
47 | ||
48 | static void test_event(void) { | |
49 | struct timeval w; | |
0ddbd899 | 50 | ev_source *ev; |
3af7813d RK |
51 | |
52 | ev = ev_new(); | |
53 | w.tv_sec = time(0) + 2; | |
54 | w.tv_usec = 0; | |
55 | ev_timeout(ev, &t1, &w, callback1, 0); | |
56 | w.tv_sec = time(0) + 3; | |
57 | w.tv_usec = 0; | |
58 | ev_timeout(ev, &t2, &w, callback2, 0); | |
59 | w.tv_sec = time(0) + 4; | |
60 | w.tv_usec = 0; | |
61 | ev_timeout(ev, &t3, &w, callback3, 0); | |
62 | check_integer(ev_run(ev), 1); | |
63 | check_integer(run1, 1); | |
64 | check_integer(run2, 0); | |
65 | check_integer(run3, 1); | |
66 | } | |
67 | ||
68 | TEST(event); | |
69 | ||
70 | /* | |
71 | Local Variables: | |
72 | c-basic-offset:2 | |
73 | comment-column:40 | |
74 | fill-column:79 | |
75 | indent-tabs-mode:nil | |
76 | End: | |
77 | */ |