summaryrefslogtreecommitdiff
path: root/testing/timer_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/timer_test.c')
-rw-r--r--testing/timer_test.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/testing/timer_test.c b/testing/timer_test.c
new file mode 100644
index 00000000..63083940
--- /dev/null
+++ b/testing/timer_test.c
@@ -0,0 +1,66 @@
1#include "../core/timer.h"
2#include <stdio.h>
3
4#ifdef WINDOWS
5#include <windows.h>
6#else
7#include <unistd.h>
8#endif
9
10void mssleep(int ms)
11{
12#ifdef WINDOWS
13 Sleep(ms);
14#else
15 usleep(ms * 1000);
16#endif
17}
18
19int callback(timer* t, void* arg){
20 printf("%s\n", (char*)arg);
21 return 1;
22}
23
24int repeating(timer* t, void *arg) {
25 printf("%s\n", (char*)arg);
26 timer_start(t, 3);
27 return 0;
28}
29
30extern void timer_debug_print();
31
32int main(int argc, char** argv)
33{
34 timer_init();
35 timer_debug_print();
36
37 timer* t = new_timer();
38 timer_setup(t, &callback, "Long setup method, 4 seconds");
39 timer_start(t, 4);
40 timer_debug_print();
41
42 timer_single(&repeating, (void*)"This repeats every 3 seconds", 3);
43 timer_debug_print();
44
45 timer_single(&callback, "Short method, 4 seconds", 4);
46 timer_debug_print();
47
48 timer_single(&callback, "1 second", 1);
49 timer_debug_print();
50
51 timer_single(&callback, "15 seconds", 15);
52 timer_debug_print();
53
54 timer_single(&callback, "10 seconds", 10);
55 timer_debug_print();
56
57 timer_us(&callback, "100000us", 100000);
58 timer_us(&callback, "13s", 13 * US_PER_SECOND);
59
60 while (true) {
61 timer_poll();
62 mssleep(10);
63 }
64
65 return 0;
66}