diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/CMakeLists.txt | 1 | ||||
-rw-r--r-- | testing/cmake/timer_test.cmake | 9 | ||||
-rw-r--r-- | testing/timer_test.c | 66 |
3 files changed, 76 insertions, 0 deletions
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 7322509a..65ba35c0 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt | |||
@@ -9,6 +9,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake) | |||
9 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake) | 9 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake) |
10 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake) | 10 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake) |
11 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake) | 11 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake) |
12 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/timer_test.cmake) | ||
12 | 13 | ||
13 | if(WIN32) | 14 | if(WIN32) |
14 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) | 15 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) |
diff --git a/testing/cmake/timer_test.cmake b/testing/cmake/timer_test.cmake new file mode 100644 index 00000000..a5f8c5ec --- /dev/null +++ b/testing/cmake/timer_test.cmake | |||
@@ -0,0 +1,9 @@ | |||
1 | cmake_minimum_required(VERSION 2.6.0) | ||
2 | project(timer_test C) | ||
3 | |||
4 | set(exe_name timer_test) | ||
5 | |||
6 | add_executable(${exe_name} | ||
7 | timer_test.c) | ||
8 | |||
9 | linkCoreLibraries(${exe_name}) | ||
diff --git a/testing/timer_test.c b/testing/timer_test.c new file mode 100644 index 00000000..50c4cda7 --- /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 | |||
10 | void mssleep(int ms) | ||
11 | { | ||
12 | #ifdef WINDOWS | ||
13 | Sleep(ms); | ||
14 | #else | ||
15 | usleep(ms * 1000); | ||
16 | #endif | ||
17 | } | ||
18 | |||
19 | int callback(timer* t, void* arg){ | ||
20 | printf("%s\n", (char*)arg); | ||
21 | return 1; | ||
22 | } | ||
23 | |||
24 | int repeating(timer* t, void *arg) { | ||
25 | printf("%s\n", (char*)arg); | ||
26 | timer_start(t, 3); | ||
27 | return 0; | ||
28 | } | ||
29 | |||
30 | extern void timer_debug_print(); | ||
31 | |||
32 | int main(int argc, char** argv) | ||
33 | { | ||
34 | timer_init(); | ||
35 | timer_debug_print(); | ||
36 | |||
37 | timer* t = timer_new(); | ||
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 | } | ||