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