diff options
-rw-r--r-- | auto_tests/friends_test.c | 26 | ||||
-rw-r--r-- | testing/CMakeLists.txt | 1 | ||||
-rw-r--r-- | testing/Messenger_test.c | 3 | ||||
-rw-r--r-- | testing/cmake/timer_test.cmake | 9 | ||||
-rw-r--r-- | testing/timer_test.c | 68 |
5 files changed, 16 insertions, 91 deletions
diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c index dd2db3e3..b6223489 100644 --- a/auto_tests/friends_test.c +++ b/auto_tests/friends_test.c | |||
@@ -44,6 +44,8 @@ | |||
44 | #define c_sleep(x) usleep(1000*x) | 44 | #define c_sleep(x) usleep(1000*x) |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #define PORT 33445 | ||
48 | |||
47 | static Messenger *m; | 49 | static Messenger *m; |
48 | 50 | ||
49 | uint8_t *parent_id = NULL; | 51 | uint8_t *parent_id = NULL; |
@@ -52,13 +54,13 @@ uint8_t *child_id = NULL; | |||
52 | pid_t child_pid = 0; | 54 | pid_t child_pid = 0; |
53 | int request_flags = 0; | 55 | int request_flags = 0; |
54 | 56 | ||
55 | void do_tox(void) | 57 | void do_tox(DHT *dht) |
56 | { | 58 | { |
57 | static int dht_on = 0; | 59 | static int dht_on = 0; |
58 | 60 | ||
59 | if (!dht_on && DHT_isconnected()) { | 61 | if (!dht_on && DHT_isconnected(dht)) { |
60 | dht_on = 1; | 62 | dht_on = 1; |
61 | } else if (dht_on && !DHT_isconnected()) { | 63 | } else if (dht_on && !DHT_isconnected(dht)) { |
62 | dht_on = 0; | 64 | dht_on = 0; |
63 | } | 65 | } |
64 | 66 | ||
@@ -77,7 +79,7 @@ void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length | |||
77 | request_flags |= FIRST_FLAG; | 79 | request_flags |= FIRST_FLAG; |
78 | } | 80 | } |
79 | 81 | ||
80 | int parent_friend_request(void) | 82 | int parent_friend_request(DHT *dht) |
81 | { | 83 | { |
82 | char *message = "Watson, come here, I need you."; | 84 | char *message = "Watson, come here, I need you."; |
83 | int len = strlen(message); | 85 | int len = strlen(message); |
@@ -90,7 +92,7 @@ int parent_friend_request(void) | |||
90 | 92 | ||
91 | /* wait on the status change */ | 93 | /* wait on the status change */ |
92 | for (i = 0; i < WAIT_COUNT; i++) { | 94 | for (i = 0; i < WAIT_COUNT; i++) { |
93 | do_tox(); | 95 | do_tox(dht); |
94 | 96 | ||
95 | if (request_flags & FIRST_FLAG) | 97 | if (request_flags & FIRST_FLAG) |
96 | break; | 98 | break; |
@@ -123,7 +125,7 @@ void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint1 | |||
123 | request_flags |= SECOND_FLAG; | 125 | request_flags |= SECOND_FLAG; |
124 | } | 126 | } |
125 | 127 | ||
126 | int parent_wait_for_message(void) | 128 | int parent_wait_for_message(DHT *dht) |
127 | { | 129 | { |
128 | int i = 0; | 130 | int i = 0; |
129 | 131 | ||
@@ -131,7 +133,7 @@ int parent_wait_for_message(void) | |||
131 | fflush(stdout); | 133 | fflush(stdout); |
132 | 134 | ||
133 | for (i = 0; i < WAIT_COUNT; i++) { | 135 | for (i = 0; i < WAIT_COUNT; i++) { |
134 | do_tox(); | 136 | do_tox(dht); |
135 | 137 | ||
136 | if (request_flags & SECOND_FLAG) | 138 | if (request_flags & SECOND_FLAG) |
137 | break; | 139 | break; |
@@ -185,16 +187,16 @@ int main(int argc, char *argv[]) | |||
185 | 187 | ||
186 | /* wait on the friend request */ | 188 | /* wait on the friend request */ |
187 | while (!(request_flags & FIRST_FLAG)) | 189 | while (!(request_flags & FIRST_FLAG)) |
188 | do_tox(); | 190 | do_tox(m->dht); |
189 | 191 | ||
190 | /* wait for the status change */ | 192 | /* wait for the status change */ |
191 | while (!(request_flags & SECOND_FLAG)) | 193 | while (!(request_flags & SECOND_FLAG)) |
192 | do_tox(); | 194 | do_tox(m->dht); |
193 | 195 | ||
194 | for (i = 0; i < 6; i++) { | 196 | for (i = 0; i < 6; i++) { |
195 | /* send the message six times, just to be sure */ | 197 | /* send the message six times, just to be sure */ |
196 | m_sendmessage(m, 0, (uint8_t *)message, strlen(message)); | 198 | m_sendmessage(m, 0, (uint8_t *)message, strlen(message)); |
197 | do_tox(); | 199 | do_tox(m->dht); |
198 | } | 200 | } |
199 | 201 | ||
200 | cleanupMessenger(m); | 202 | cleanupMessenger(m); |
@@ -220,10 +222,10 @@ int main(int argc, char *argv[]) | |||
220 | 222 | ||
221 | Messenger_save(m, parent_id); | 223 | Messenger_save(m, parent_id); |
222 | 224 | ||
223 | if (parent_friend_request() == -1) | 225 | if (parent_friend_request(m->dht) == -1) |
224 | return -1; | 226 | return -1; |
225 | 227 | ||
226 | if (parent_wait_for_message() == -1) | 228 | if (parent_wait_for_message(m->dht) == -1) |
227 | return -1; | 229 | return -1; |
228 | 230 | ||
229 | wait(NULL); | 231 | wait(NULL); |
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 9e07135c..e3cdc838 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt | |||
@@ -9,7 +9,6 @@ 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) | ||
13 | 12 | ||
14 | if(WIN32) | 13 | if(WIN32) |
15 | # include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) | 14 | # include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake) |
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index f8685b39..c76584d7 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <unistd.h> | 48 | #include <unistd.h> |
49 | #include <arpa/inet.h> | 49 | #include <arpa/inet.h> |
50 | #define c_sleep(x) usleep(1000*x) | 50 | #define c_sleep(x) usleep(1000*x) |
51 | #define PORT 33445 | ||
51 | 52 | ||
52 | #endif | 53 | #endif |
53 | 54 | ||
@@ -106,7 +107,7 @@ int main(int argc, char *argv[]) | |||
106 | IP_Port bootstrap_ip_port; | 107 | IP_Port bootstrap_ip_port; |
107 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 108 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
108 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); | 109 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); |
109 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 110 | DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3])); |
110 | } else { | 111 | } else { |
111 | FILE *file = fopen(argv[1], "rb"); | 112 | FILE *file = fopen(argv[1], "rb"); |
112 | 113 | ||
diff --git a/testing/cmake/timer_test.cmake b/testing/cmake/timer_test.cmake deleted file mode 100644 index a5f8c5ec..00000000 --- a/testing/cmake/timer_test.cmake +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
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 deleted file mode 100644 index f47d4878..00000000 --- a/testing/timer_test.c +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
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 | { | ||
21 | printf("%s\n", (char *)arg); | ||
22 | return 1; | ||
23 | } | ||
24 | |||
25 | int repeating(timer *t, void *arg) | ||
26 | { | ||
27 | printf("%s\n", (char *)arg); | ||
28 | timer_start(t, 3); | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | extern void timer_debug_print(); | ||
33 | |||
34 | int main(int argc, char **argv) | ||
35 | { | ||
36 | timer_init(); | ||
37 | timer_debug_print(); | ||
38 | |||
39 | timer *t = new_timer(); | ||
40 | timer_setup(t, &callback, "Long setup method, 4 seconds"); | ||
41 | timer_start(t, 4); | ||
42 | timer_debug_print(); | ||
43 | |||
44 | timer_single(&repeating, (void *)"This repeats every 3 seconds", 3); | ||
45 | timer_debug_print(); | ||
46 | |||
47 | timer_single(&callback, "Short method, 4 seconds", 4); | ||
48 | timer_debug_print(); | ||
49 | |||
50 | timer_single(&callback, "1 second", 1); | ||
51 | timer_debug_print(); | ||
52 | |||
53 | timer_single(&callback, "15 seconds", 15); | ||
54 | timer_debug_print(); | ||
55 | |||
56 | timer_single(&callback, "10 seconds", 10); | ||
57 | timer_debug_print(); | ||
58 | |||
59 | timer_us(&callback, "100000us", 100000); | ||
60 | timer_us(&callback, "13s", 13 * US_PER_SECOND); | ||
61 | |||
62 | while (true) { | ||
63 | timer_poll(); | ||
64 | mssleep(10); | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||