diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-25 12:16:54 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-25 15:25:33 +0000 |
commit | 94b06818fbd7a93387ff4c155b6eff711651aea9 (patch) | |
tree | 63365adeb88705c5c2f0cdb4d2afd00a4bd8b43c /auto_tests | |
parent | 0935aab92760a7c9c547faa86c29dcd0d1e03f24 (diff) |
Use do-while instead of while in tests.
This forces all the loop bodies to be executed at least once, which is
harmless since it just means one more tox event loop iteration. This
reduces the jitter we see in coverage measurements, which is partially
caused by loops sometimes being entered and sometimes not (because their
condition happens to randomly already be true).
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/bootstrap_test.c | 4 | ||||
-rw-r--r-- | auto_tests/conference_double_invite_test.c | 4 | ||||
-rw-r--r-- | auto_tests/conference_peer_nick_test.c | 9 | ||||
-rw-r--r-- | auto_tests/conference_simple_test.c | 20 | ||||
-rw-r--r-- | auto_tests/conference_test.c | 12 | ||||
-rw-r--r-- | auto_tests/dht_test.c | 2 | ||||
-rw-r--r-- | auto_tests/file_transfer_test.c | 20 | ||||
-rw-r--r-- | auto_tests/friend_request_test.c | 12 | ||||
-rw-r--r-- | auto_tests/lan_discovery_test.c | 6 | ||||
-rw-r--r-- | auto_tests/lossless_packet_test.c | 4 | ||||
-rw-r--r-- | auto_tests/lossy_packet_test.c | 4 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 36 | ||||
-rw-r--r-- | auto_tests/run_auto_test.h | 8 | ||||
-rw-r--r-- | auto_tests/save_load_test.c | 4 | ||||
-rw-r--r-- | auto_tests/send_message_test.c | 4 | ||||
-rw-r--r-- | auto_tests/set_name_test.c | 16 | ||||
-rw-r--r-- | auto_tests/set_status_message_test.c | 16 | ||||
-rw-r--r-- | auto_tests/tcp_relay_test.c | 4 | ||||
-rw-r--r-- | auto_tests/tox_many_tcp_test.c | 4 | ||||
-rw-r--r-- | auto_tests/tox_many_test.c | 2 | ||||
-rw-r--r-- | auto_tests/toxav_basic_test.c | 36 | ||||
-rw-r--r-- | auto_tests/toxav_many_test.c | 14 | ||||
-rw-r--r-- | auto_tests/typing_test.c | 20 |
23 files changed, 130 insertions, 131 deletions
diff --git a/auto_tests/bootstrap_test.c b/auto_tests/bootstrap_test.c index cbe81ebc..7d1a2f06 100644 --- a/auto_tests/bootstrap_test.c +++ b/auto_tests/bootstrap_test.c | |||
@@ -24,13 +24,13 @@ int main(void) | |||
24 | 24 | ||
25 | printf("Waiting for connection"); | 25 | printf("Waiting for connection"); |
26 | 26 | ||
27 | while (tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_NONE) { | 27 | do { |
28 | printf("."); | 28 | printf("."); |
29 | fflush(stdout); | 29 | fflush(stdout); |
30 | 30 | ||
31 | tox_iterate(tox_udp, nullptr); | 31 | tox_iterate(tox_udp, nullptr); |
32 | c_sleep(ITERATION_INTERVAL); | 32 | c_sleep(ITERATION_INTERVAL); |
33 | } | 33 | } while (tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_NONE); |
34 | 34 | ||
35 | const TOX_CONNECTION status = tox_self_get_connection_status(tox_udp); | 35 | const TOX_CONNECTION status = tox_self_get_connection_status(tox_udp); |
36 | ck_assert_msg(status == TOX_CONNECTION_UDP, | 36 | ck_assert_msg(status == TOX_CONNECTION_UDP, |
diff --git a/auto_tests/conference_double_invite_test.c b/auto_tests/conference_double_invite_test.c index 026c2fcb..33026986 100644 --- a/auto_tests/conference_double_invite_test.c +++ b/auto_tests/conference_double_invite_test.c | |||
@@ -63,12 +63,12 @@ static void conference_double_invite_test(Tox **toxes, State *state) | |||
63 | 63 | ||
64 | fprintf(stderr, "Waiting for invitation to arrive\n"); | 64 | fprintf(stderr, "Waiting for invitation to arrive\n"); |
65 | 65 | ||
66 | while (!state[0].joined || !state[1].joined) { | 66 | do { |
67 | tox_iterate(toxes[0], &state[0]); | 67 | tox_iterate(toxes[0], &state[0]); |
68 | tox_iterate(toxes[1], &state[1]); | 68 | tox_iterate(toxes[1], &state[1]); |
69 | 69 | ||
70 | c_sleep(ITERATION_INTERVAL); | 70 | c_sleep(ITERATION_INTERVAL); |
71 | } | 71 | } while (!state[0].joined || !state[1].joined); |
72 | 72 | ||
73 | fprintf(stderr, "Invitations accepted\n"); | 73 | fprintf(stderr, "Invitations accepted\n"); |
74 | 74 | ||
diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c index e99d3b79..14676b76 100644 --- a/auto_tests/conference_peer_nick_test.c +++ b/auto_tests/conference_peer_nick_test.c | |||
@@ -107,26 +107,25 @@ static void conference_peer_nick_test(Tox **toxes, State *state) | |||
107 | 107 | ||
108 | fprintf(stderr, "Waiting for invitation to arrive and peers to be in the group\n"); | 108 | fprintf(stderr, "Waiting for invitation to arrive and peers to be in the group\n"); |
109 | 109 | ||
110 | while (!state[0].joined || !state[1].joined || !state[0].friend_in_group || !state[1].friend_in_group) { | 110 | do { |
111 | tox_iterate(toxes[0], &state[0]); | 111 | tox_iterate(toxes[0], &state[0]); |
112 | tox_iterate(toxes[1], &state[1]); | 112 | tox_iterate(toxes[1], &state[1]); |
113 | 113 | ||
114 | c_sleep(ITERATION_INTERVAL); | 114 | c_sleep(ITERATION_INTERVAL); |
115 | } | 115 | } while (!state[0].joined || !state[1].joined || !state[0].friend_in_group || !state[1].friend_in_group); |
116 | 116 | ||
117 | fprintf(stderr, "Running tox0, but not tox1, waiting for tox1 to drop out\n"); | 117 | fprintf(stderr, "Running tox0, but not tox1, waiting for tox1 to drop out\n"); |
118 | 118 | ||
119 | while (state[0].friend_in_group) { | 119 | do { |
120 | tox_iterate(toxes[0], &state[0]); | 120 | tox_iterate(toxes[0], &state[0]); |
121 | 121 | ||
122 | // Rebuild peer list after every iteration. | 122 | // Rebuild peer list after every iteration. |
123 | rebuild_peer_list(toxes[0]); | 123 | rebuild_peer_list(toxes[0]); |
124 | 124 | ||
125 | c_sleep(ITERATION_INTERVAL); | 125 | c_sleep(ITERATION_INTERVAL); |
126 | } | 126 | } while (state[0].friend_in_group); |
127 | 127 | ||
128 | fprintf(stderr, "Invitations accepted\n"); | 128 | fprintf(stderr, "Invitations accepted\n"); |
129 | |||
130 | } | 129 | } |
131 | 130 | ||
132 | int main(void) | 131 | int main(void) |
diff --git a/auto_tests/conference_simple_test.c b/auto_tests/conference_simple_test.c index 20e4ec8b..c9d24dad 100644 --- a/auto_tests/conference_simple_test.c +++ b/auto_tests/conference_simple_test.c | |||
@@ -165,26 +165,26 @@ int main(void) | |||
165 | // Wait for self connection. | 165 | // Wait for self connection. |
166 | fprintf(stderr, "Waiting for toxes to come online\n"); | 166 | fprintf(stderr, "Waiting for toxes to come online\n"); |
167 | 167 | ||
168 | while (!state1.self_online || !state2.self_online || !state3.self_online) { | 168 | do { |
169 | tox_iterate(tox1, &state1); | 169 | tox_iterate(tox1, &state1); |
170 | tox_iterate(tox2, &state2); | 170 | tox_iterate(tox2, &state2); |
171 | tox_iterate(tox3, &state3); | 171 | tox_iterate(tox3, &state3); |
172 | 172 | ||
173 | c_sleep(100); | 173 | c_sleep(100); |
174 | } | 174 | } while (!state1.self_online || !state2.self_online || !state3.self_online); |
175 | 175 | ||
176 | fprintf(stderr, "Toxes are online\n"); | 176 | fprintf(stderr, "Toxes are online\n"); |
177 | 177 | ||
178 | // Wait for friend connection. | 178 | // Wait for friend connection. |
179 | fprintf(stderr, "Waiting for friends to connect\n"); | 179 | fprintf(stderr, "Waiting for friends to connect\n"); |
180 | 180 | ||
181 | while (!state1.friend_online || !state2.friend_online || !state3.friend_online) { | 181 | do { |
182 | tox_iterate(tox1, &state1); | 182 | tox_iterate(tox1, &state1); |
183 | tox_iterate(tox2, &state2); | 183 | tox_iterate(tox2, &state2); |
184 | tox_iterate(tox3, &state3); | 184 | tox_iterate(tox3, &state3); |
185 | 185 | ||
186 | c_sleep(100); | 186 | c_sleep(100); |
187 | } | 187 | } while (!state1.friend_online || !state2.friend_online || !state3.friend_online); |
188 | 188 | ||
189 | fprintf(stderr, "Friends are connected\n"); | 189 | fprintf(stderr, "Friends are connected\n"); |
190 | 190 | ||
@@ -208,25 +208,25 @@ int main(void) | |||
208 | 208 | ||
209 | fprintf(stderr, "Waiting for invitation to arrive\n"); | 209 | fprintf(stderr, "Waiting for invitation to arrive\n"); |
210 | 210 | ||
211 | while (!state1.joined || !state2.joined || !state3.joined) { | 211 | do { |
212 | tox_iterate(tox1, &state1); | 212 | tox_iterate(tox1, &state1); |
213 | tox_iterate(tox2, &state2); | 213 | tox_iterate(tox2, &state2); |
214 | tox_iterate(tox3, &state3); | 214 | tox_iterate(tox3, &state3); |
215 | 215 | ||
216 | c_sleep(100); | 216 | c_sleep(100); |
217 | } | 217 | } while (!state1.joined || !state2.joined || !state3.joined); |
218 | 218 | ||
219 | fprintf(stderr, "Invitations accepted\n"); | 219 | fprintf(stderr, "Invitations accepted\n"); |
220 | 220 | ||
221 | fprintf(stderr, "Waiting for peers to come online\n"); | 221 | fprintf(stderr, "Waiting for peers to come online\n"); |
222 | 222 | ||
223 | while (state1.peers == 0 || state2.peers == 0 || state3.peers == 0) { | 223 | do { |
224 | tox_iterate(tox1, &state1); | 224 | tox_iterate(tox1, &state1); |
225 | tox_iterate(tox2, &state2); | 225 | tox_iterate(tox2, &state2); |
226 | tox_iterate(tox3, &state3); | 226 | tox_iterate(tox3, &state3); |
227 | 227 | ||
228 | c_sleep(100); | 228 | c_sleep(100); |
229 | } | 229 | } while (state1.peers == 0 || state2.peers == 0 || state3.peers == 0); |
230 | 230 | ||
231 | fprintf(stderr, "All peers are online\n"); | 231 | fprintf(stderr, "All peers are online\n"); |
232 | 232 | ||
@@ -244,13 +244,13 @@ int main(void) | |||
244 | 244 | ||
245 | fprintf(stderr, "Waiting for messages to arrive\n"); | 245 | fprintf(stderr, "Waiting for messages to arrive\n"); |
246 | 246 | ||
247 | while (!state2.received || !state3.received) { | 247 | do { |
248 | tox_iterate(tox1, &state1); | 248 | tox_iterate(tox1, &state1); |
249 | tox_iterate(tox2, &state2); | 249 | tox_iterate(tox2, &state2); |
250 | tox_iterate(tox3, &state3); | 250 | tox_iterate(tox3, &state3); |
251 | 251 | ||
252 | c_sleep(100); | 252 | c_sleep(100); |
253 | } | 253 | } while (!state2.received || !state3.received); |
254 | 254 | ||
255 | fprintf(stderr, "Messages received. Test complete.\n"); | 255 | fprintf(stderr, "Messages received. Test complete.\n"); |
256 | 256 | ||
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index 8f8f9357..235200cd 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c | |||
@@ -216,7 +216,7 @@ static void test_many_group(void) | |||
216 | printf("waiting for everyone to come online\n"); | 216 | printf("waiting for everyone to come online\n"); |
217 | unsigned online_count = 0; | 217 | unsigned online_count = 0; |
218 | 218 | ||
219 | while (online_count != NUM_GROUP_TOX) { | 219 | do { |
220 | online_count = 0; | 220 | online_count = 0; |
221 | 221 | ||
222 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { | 222 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
@@ -228,7 +228,7 @@ static void test_many_group(void) | |||
228 | fflush(stdout); | 228 | fflush(stdout); |
229 | 229 | ||
230 | c_sleep(1000); | 230 | c_sleep(1000); |
231 | } | 231 | } while (online_count != NUM_GROUP_TOX); |
232 | 232 | ||
233 | printf("friends connected, took %d seconds\n", (int)(time(nullptr) - cur_time)); | 233 | printf("friends connected, took %d seconds\n", (int)(time(nullptr) - cur_time)); |
234 | 234 | ||
@@ -243,7 +243,7 @@ static void test_many_group(void) | |||
243 | printf("waiting for invitations to be made\n"); | 243 | printf("waiting for invitations to be made\n"); |
244 | uint16_t invited_count = 0; | 244 | uint16_t invited_count = 0; |
245 | 245 | ||
246 | while (invited_count != NUM_GROUP_TOX - 1) { | 246 | do { |
247 | invited_count = 0; | 247 | invited_count = 0; |
248 | 248 | ||
249 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { | 249 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
@@ -252,13 +252,13 @@ static void test_many_group(void) | |||
252 | } | 252 | } |
253 | 253 | ||
254 | c_sleep(50); | 254 | c_sleep(50); |
255 | } | 255 | } while (invited_count != NUM_GROUP_TOX - 1); |
256 | 256 | ||
257 | cur_time = time(nullptr); | 257 | cur_time = time(nullptr); |
258 | printf("waiting for all toxes to be in the group\n"); | 258 | printf("waiting for all toxes to be in the group\n"); |
259 | uint16_t fully_connected_count = 0; | 259 | uint16_t fully_connected_count = 0; |
260 | 260 | ||
261 | while (fully_connected_count != NUM_GROUP_TOX) { | 261 | do { |
262 | fully_connected_count = 0; | 262 | fully_connected_count = 0; |
263 | printf("current peer counts: ["); | 263 | printf("current peer counts: ["); |
264 | 264 | ||
@@ -284,7 +284,7 @@ static void test_many_group(void) | |||
284 | fflush(stdout); | 284 | fflush(stdout); |
285 | 285 | ||
286 | c_sleep(200); | 286 | c_sleep(200); |
287 | } | 287 | } while (fully_connected_count != NUM_GROUP_TOX); |
288 | 288 | ||
289 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { | 289 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
290 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); | 290 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); |
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 009c0bbd..25316496 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c | |||
@@ -655,7 +655,7 @@ loop_top: | |||
655 | dht_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key); | 655 | dht_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key); |
656 | } | 656 | } |
657 | 657 | ||
658 | while (1) { | 658 | while (true) { |
659 | uint16_t counter = 0; | 659 | uint16_t counter = 0; |
660 | 660 | ||
661 | for (i = 0; i < NUM_DHT_FRIENDS; ++i) { | 661 | for (i = 0; i < NUM_DHT_FRIENDS; ++i) { |
diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c index 63dc3fed..2e791662 100644 --- a/auto_tests/file_transfer_test.c +++ b/auto_tests/file_transfer_test.c | |||
@@ -184,11 +184,7 @@ static void file_transfer_test(void) | |||
184 | 184 | ||
185 | printf("Waiting for toxes to come online\n"); | 185 | printf("Waiting for toxes to come online\n"); |
186 | 186 | ||
187 | while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | 187 | do { |
188 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE || | ||
189 | tox_self_get_connection_status(tox3) == TOX_CONNECTION_NONE || | ||
190 | tox_friend_get_connection_status(tox2, 0, nullptr) == TOX_CONNECTION_NONE || | ||
191 | tox_friend_get_connection_status(tox3, 0, nullptr) == TOX_CONNECTION_NONE) { | ||
192 | tox_iterate(tox1, nullptr); | 188 | tox_iterate(tox1, nullptr); |
193 | tox_iterate(tox2, nullptr); | 189 | tox_iterate(tox2, nullptr); |
194 | tox_iterate(tox3, nullptr); | 190 | tox_iterate(tox3, nullptr); |
@@ -200,7 +196,11 @@ static void file_transfer_test(void) | |||
200 | tox_friend_get_connection_status(tox2, 0, nullptr), | 196 | tox_friend_get_connection_status(tox2, 0, nullptr), |
201 | tox_friend_get_connection_status(tox3, 0, nullptr)); | 197 | tox_friend_get_connection_status(tox3, 0, nullptr)); |
202 | c_sleep(ITERATION_INTERVAL); | 198 | c_sleep(ITERATION_INTERVAL); |
203 | } | 199 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
200 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE || | ||
201 | tox_self_get_connection_status(tox3) == TOX_CONNECTION_NONE || | ||
202 | tox_friend_get_connection_status(tox2, 0, nullptr) == TOX_CONNECTION_NONE || | ||
203 | tox_friend_get_connection_status(tox3, 0, nullptr) == TOX_CONNECTION_NONE); | ||
204 | 204 | ||
205 | printf("Starting file transfer test: 100MiB file.\n"); | 205 | printf("Starting file transfer test: 100MiB file.\n"); |
206 | 206 | ||
@@ -292,7 +292,7 @@ static void file_transfer_test(void) | |||
292 | max_sending = 100 * 1024; | 292 | max_sending = 100 * 1024; |
293 | m_send_reached = 0; | 293 | m_send_reached = 0; |
294 | 294 | ||
295 | while (!file_sending_done) { | 295 | do { |
296 | tox_iterate(tox1, nullptr); | 296 | tox_iterate(tox1, nullptr); |
297 | tox_iterate(tox2, nullptr); | 297 | tox_iterate(tox2, nullptr); |
298 | tox_iterate(tox3, nullptr); | 298 | tox_iterate(tox3, nullptr); |
@@ -302,7 +302,7 @@ static void file_transfer_test(void) | |||
302 | uint32_t tox3_interval = tox_iteration_interval(tox3); | 302 | uint32_t tox3_interval = tox_iteration_interval(tox3); |
303 | 303 | ||
304 | c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval))); | 304 | c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval))); |
305 | } | 305 | } while (!file_sending_done); |
306 | 306 | ||
307 | ck_assert_msg(sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending | 307 | ck_assert_msg(sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending |
308 | && sending_pos == size_recv && file_accepted == 1, | 308 | && sending_pos == size_recv && file_accepted == 1, |
@@ -336,7 +336,7 @@ static void file_transfer_test(void) | |||
336 | ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed"); | 336 | ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed"); |
337 | ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error"); | 337 | ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error"); |
338 | 338 | ||
339 | while (!file_sending_done) { | 339 | do { |
340 | uint32_t tox1_interval = tox_iteration_interval(tox1); | 340 | uint32_t tox1_interval = tox_iteration_interval(tox1); |
341 | uint32_t tox2_interval = tox_iteration_interval(tox2); | 341 | uint32_t tox2_interval = tox_iteration_interval(tox2); |
342 | uint32_t tox3_interval = tox_iteration_interval(tox3); | 342 | uint32_t tox3_interval = tox_iteration_interval(tox3); |
@@ -346,7 +346,7 @@ static void file_transfer_test(void) | |||
346 | tox_iterate(tox1, nullptr); | 346 | tox_iterate(tox1, nullptr); |
347 | tox_iterate(tox2, nullptr); | 347 | tox_iterate(tox2, nullptr); |
348 | tox_iterate(tox3, nullptr); | 348 | tox_iterate(tox3, nullptr); |
349 | } | 349 | } while (!file_sending_done); |
350 | 350 | ||
351 | ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size | 351 | ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size |
352 | && sending_pos == size_recv && file_accepted == 1, | 352 | && sending_pos == size_recv && file_accepted == 1, |
diff --git a/auto_tests/friend_request_test.c b/auto_tests/friend_request_test.c index 528a3b4f..b13c6a64 100644 --- a/auto_tests/friend_request_test.c +++ b/auto_tests/friend_request_test.c | |||
@@ -43,13 +43,13 @@ static void test_friend_request(void) | |||
43 | 43 | ||
44 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); | 44 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); |
45 | 45 | ||
46 | while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | 46 | do { |
47 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { | ||
48 | tox_iterate(tox1, nullptr); | 47 | tox_iterate(tox1, nullptr); |
49 | tox_iterate(tox2, nullptr); | 48 | tox_iterate(tox2, nullptr); |
50 | 49 | ||
51 | c_sleep(ITERATION_INTERVAL); | 50 | c_sleep(ITERATION_INTERVAL); |
52 | } | 51 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
52 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); | ||
53 | 53 | ||
54 | printf("Toxes are online, took %lu seconds.\n", (unsigned long)(time(nullptr) - cur_time)); | 54 | printf("Toxes are online, took %lu seconds.\n", (unsigned long)(time(nullptr) - cur_time)); |
55 | const time_t con_time = time(nullptr); | 55 | const time_t con_time = time(nullptr); |
@@ -63,13 +63,13 @@ static void test_friend_request(void) | |||
63 | const uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)FR_MESSAGE, sizeof(FR_MESSAGE), nullptr); | 63 | const uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)FR_MESSAGE, sizeof(FR_MESSAGE), nullptr); |
64 | ck_assert_msg(test == 0, "failed to add friend error code: %u", test); | 64 | ck_assert_msg(test == 0, "failed to add friend error code: %u", test); |
65 | 65 | ||
66 | while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || | 66 | do { |
67 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP) { | ||
68 | tox_iterate(tox1, nullptr); | 67 | tox_iterate(tox1, nullptr); |
69 | tox_iterate(tox2, nullptr); | 68 | tox_iterate(tox2, nullptr); |
70 | 69 | ||
71 | c_sleep(ITERATION_INTERVAL); | 70 | c_sleep(ITERATION_INTERVAL); |
72 | } | 71 | } while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || |
72 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP); | ||
73 | 73 | ||
74 | printf("Tox clients connected took %lu seconds.\n", (unsigned long)(time(nullptr) - con_time)); | 74 | printf("Tox clients connected took %lu seconds.\n", (unsigned long)(time(nullptr) - con_time)); |
75 | printf("friend_request_test succeeded, took %lu seconds.\n", (unsigned long)(time(nullptr) - cur_time)); | 75 | printf("friend_request_test succeeded, took %lu seconds.\n", (unsigned long)(time(nullptr) - cur_time)); |
diff --git a/auto_tests/lan_discovery_test.c b/auto_tests/lan_discovery_test.c index 28a5ddf0..69bf8e31 100644 --- a/auto_tests/lan_discovery_test.c +++ b/auto_tests/lan_discovery_test.c | |||
@@ -16,15 +16,15 @@ int main(void) | |||
16 | 16 | ||
17 | printf("Waiting for LAN discovery. This loop will attempt to run until successful."); | 17 | printf("Waiting for LAN discovery. This loop will attempt to run until successful."); |
18 | 18 | ||
19 | while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | 19 | do { |
20 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { | ||
21 | printf("."); | 20 | printf("."); |
22 | fflush(stdout); | 21 | fflush(stdout); |
23 | 22 | ||
24 | tox_iterate(tox1, nullptr); | 23 | tox_iterate(tox1, nullptr); |
25 | tox_iterate(tox2, nullptr); | 24 | tox_iterate(tox2, nullptr); |
26 | c_sleep(1000); | 25 | c_sleep(1000); |
27 | } | 26 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
27 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); | ||
28 | 28 | ||
29 | printf(" %d <-> %d\n", | 29 | printf(" %d <-> %d\n", |
30 | tox_self_get_connection_status(tox1), | 30 | tox_self_get_connection_status(tox1), |
diff --git a/auto_tests/lossless_packet_test.c b/auto_tests/lossless_packet_test.c index dc4dc0b5..9d9fe71b 100644 --- a/auto_tests/lossless_packet_test.c +++ b/auto_tests/lossless_packet_test.c | |||
@@ -50,12 +50,12 @@ static void test_lossless_packet(Tox **toxes, State *state) | |||
50 | ret = tox_friend_send_lossless_packet(toxes[0], 0, packet, TOX_MAX_CUSTOM_PACKET_SIZE, nullptr); | 50 | ret = tox_friend_send_lossless_packet(toxes[0], 0, packet, TOX_MAX_CUSTOM_PACKET_SIZE, nullptr); |
51 | ck_assert_msg(ret == true, "tox_friend_send_lossless_packet fail %i", ret); | 51 | ck_assert_msg(ret == true, "tox_friend_send_lossless_packet fail %i", ret); |
52 | 52 | ||
53 | while (!state[1].custom_packet_received) { | 53 | do { |
54 | tox_iterate(toxes[0], nullptr); | 54 | tox_iterate(toxes[0], nullptr); |
55 | tox_iterate(toxes[1], &state[1]); | 55 | tox_iterate(toxes[1], &state[1]); |
56 | 56 | ||
57 | c_sleep(ITERATION_INTERVAL); | 57 | c_sleep(ITERATION_INTERVAL); |
58 | } | 58 | } while (!state[1].custom_packet_received); |
59 | } | 59 | } |
60 | 60 | ||
61 | int main(void) | 61 | int main(void) |
diff --git a/auto_tests/lossy_packet_test.c b/auto_tests/lossy_packet_test.c index ef4ff7bf..51081a39 100644 --- a/auto_tests/lossy_packet_test.c +++ b/auto_tests/lossy_packet_test.c | |||
@@ -46,11 +46,11 @@ static void test_lossy_packet(Tox **toxes, State *state) | |||
46 | ret = tox_friend_send_lossy_packet(toxes[0], 0, packet, TOX_MAX_CUSTOM_PACKET_SIZE, nullptr); | 46 | ret = tox_friend_send_lossy_packet(toxes[0], 0, packet, TOX_MAX_CUSTOM_PACKET_SIZE, nullptr); |
47 | ck_assert_msg(ret == true, "tox_friend_send_lossy_packet fail %i", ret); | 47 | ck_assert_msg(ret == true, "tox_friend_send_lossy_packet fail %i", ret); |
48 | 48 | ||
49 | while (!state[1].custom_packet_received) { | 49 | do { |
50 | tox_iterate(toxes[0], nullptr); | 50 | tox_iterate(toxes[0], nullptr); |
51 | tox_iterate(toxes[1], &state[1]); | 51 | tox_iterate(toxes[1], &state[1]); |
52 | c_sleep(ITERATION_INTERVAL); | 52 | c_sleep(ITERATION_INTERVAL); |
53 | } | 53 | } while (!state[1].custom_packet_received); |
54 | } | 54 | } |
55 | 55 | ||
56 | int main(void) | 56 | int main(void) |
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index a11fb807..6cd06494 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -192,18 +192,18 @@ static void test_basic(void) | |||
192 | 192 | ||
193 | handled_test_1 = 0; | 193 | handled_test_1 = 0; |
194 | 194 | ||
195 | while (handled_test_1 == 0) { | 195 | do { |
196 | do_onion(onion1); | 196 | do_onion(onion1); |
197 | do_onion(onion2); | 197 | do_onion(onion2); |
198 | } | 198 | } while (handled_test_1 == 0); |
199 | 199 | ||
200 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_2, onion1); | 200 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_2, onion1); |
201 | handled_test_2 = 0; | 201 | handled_test_2 = 0; |
202 | 202 | ||
203 | while (handled_test_2 == 0) { | 203 | do { |
204 | do_onion(onion1); | 204 | do_onion(onion1); |
205 | do_onion(onion2); | 205 | do_onion(onion2); |
206 | } | 206 | } while (handled_test_2 == 0); |
207 | 207 | ||
208 | Onion_Announce *onion1_a = new_onion_announce(mono_time1, onion1->dht); | 208 | Onion_Announce *onion1_a = new_onion_announce(mono_time1, onion1->dht); |
209 | Onion_Announce *onion2_a = new_onion_announce(mono_time2, onion2->dht); | 209 | Onion_Announce *onion2_a = new_onion_announce(mono_time2, onion2->dht); |
@@ -223,11 +223,11 @@ static void test_basic(void) | |||
223 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); | 223 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); |
224 | handled_test_3 = 0; | 224 | handled_test_3 = 0; |
225 | 225 | ||
226 | while (handled_test_3 == 0) { | 226 | do { |
227 | do_onion(onion1); | 227 | do_onion(onion1); |
228 | do_onion(onion2); | 228 | do_onion(onion2); |
229 | c_sleep(50); | 229 | c_sleep(50); |
230 | } | 230 | } while (handled_test_3 == 0); |
231 | 231 | ||
232 | random_bytes(sb_data, sizeof(sb_data)); | 232 | random_bytes(sb_data, sizeof(sb_data)); |
233 | memcpy(&s, sb_data, sizeof(uint64_t)); | 233 | memcpy(&s, sb_data, sizeof(uint64_t)); |
@@ -241,13 +241,13 @@ static void test_basic(void) | |||
241 | dht_get_self_public_key(onion1->dht), | 241 | dht_get_self_public_key(onion1->dht), |
242 | dht_get_self_public_key(onion1->dht), s); | 242 | dht_get_self_public_key(onion1->dht), s); |
243 | 243 | ||
244 | while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2), | 244 | do { |
245 | dht_get_self_public_key(onion1->dht), | ||
246 | CRYPTO_PUBLIC_KEY_SIZE) != 0) { | ||
247 | do_onion(onion1); | 245 | do_onion(onion1); |
248 | do_onion(onion2); | 246 | do_onion(onion2); |
249 | c_sleep(50); | 247 | c_sleep(50); |
250 | } | 248 | } while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2), |
249 | dht_get_self_public_key(onion1->dht), | ||
250 | CRYPTO_PUBLIC_KEY_SIZE) != 0); | ||
251 | 251 | ||
252 | c_sleep(1000); | 252 | c_sleep(1000); |
253 | Logger *log3 = logger_new(); | 253 | Logger *log3 = logger_new(); |
@@ -266,11 +266,11 @@ static void test_basic(void) | |||
266 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); | 266 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); |
267 | handled_test_4 = 0; | 267 | handled_test_4 = 0; |
268 | 268 | ||
269 | while (handled_test_4 == 0) { | 269 | do { |
270 | do_onion(onion1); | 270 | do_onion(onion1); |
271 | do_onion(onion2); | 271 | do_onion(onion2); |
272 | c_sleep(50); | 272 | c_sleep(50); |
273 | } | 273 | } while (handled_test_4 == 0); |
274 | 274 | ||
275 | kill_onion_announce(onion2_a); | 275 | kill_onion_announce(onion2_a); |
276 | kill_onion_announce(onion1_a); | 276 | kill_onion_announce(onion1_a); |
@@ -513,7 +513,7 @@ static void test_announce(void) | |||
513 | 513 | ||
514 | uint32_t connected = 0; | 514 | uint32_t connected = 0; |
515 | 515 | ||
516 | while (connected != NUM_ONIONS) { | 516 | do { |
517 | connected = 0; | 517 | connected = 0; |
518 | 518 | ||
519 | for (i = 0; i < NUM_ONIONS; ++i) { | 519 | for (i = 0; i < NUM_ONIONS; ++i) { |
@@ -522,7 +522,7 @@ static void test_announce(void) | |||
522 | } | 522 | } |
523 | 523 | ||
524 | c_sleep(50); | 524 | c_sleep(50); |
525 | } | 525 | } while (connected != NUM_ONIONS); |
526 | 526 | ||
527 | printf("connected\n"); | 527 | printf("connected\n"); |
528 | 528 | ||
@@ -548,23 +548,23 @@ static void test_announce(void) | |||
548 | 548 | ||
549 | IP_Port ip_port; | 549 | IP_Port ip_port; |
550 | 550 | ||
551 | while (!first || !last) { | 551 | do { |
552 | for (i = 0; i < NUM_ONIONS; ++i) { | 552 | for (i = 0; i < NUM_ONIONS; ++i) { |
553 | do_onions(onions[i]); | 553 | do_onions(onions[i]); |
554 | } | 554 | } |
555 | 555 | ||
556 | c_sleep(50); | 556 | c_sleep(50); |
557 | } | 557 | } while (!first || !last); |
558 | 558 | ||
559 | printf("Waiting for ips\n"); | 559 | printf("Waiting for ips\n"); |
560 | 560 | ||
561 | while (!first_ip || !last_ip) { | 561 | do { |
562 | for (i = 0; i < NUM_ONIONS; ++i) { | 562 | for (i = 0; i < NUM_ONIONS; ++i) { |
563 | do_onions(onions[i]); | 563 | do_onions(onions[i]); |
564 | } | 564 | } |
565 | 565 | ||
566 | c_sleep(50); | 566 | c_sleep(50); |
567 | } | 567 | } while (!first_ip || !last_ip); |
568 | 568 | ||
569 | onion_getfriendip(onions[NUM_LAST]->onion_c, frnum, &ip_port); | 569 | onion_getfriendip(onions[NUM_LAST]->onion_c, frnum, &ip_port); |
570 | ck_assert_msg(ip_port.port == net_port(onions[NUM_FIRST]->onion->net), "Port in returned ip not correct."); | 570 | ck_assert_msg(ip_port.port == net_port(onions[NUM_FIRST]->onion->net), "Port in returned ip not correct."); |
diff --git a/auto_tests/run_auto_test.h b/auto_tests/run_auto_test.h index 04d24791..ad89992a 100644 --- a/auto_tests/run_auto_test.h +++ b/auto_tests/run_auto_test.h | |||
@@ -72,19 +72,19 @@ static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *stat | |||
72 | tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, nullptr); | 72 | tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, nullptr); |
73 | } | 73 | } |
74 | 74 | ||
75 | while (!all_connected(tox_count, toxes)) { | 75 | do { |
76 | iterate_all(tox_count, toxes, state); | 76 | iterate_all(tox_count, toxes, state); |
77 | 77 | ||
78 | c_sleep(ITERATION_INTERVAL); | 78 | c_sleep(ITERATION_INTERVAL); |
79 | } | 79 | } while (!all_connected(tox_count, toxes)); |
80 | 80 | ||
81 | printf("toxes are online\n"); | 81 | printf("toxes are online\n"); |
82 | 82 | ||
83 | while (!all_friends_connected(tox_count, toxes)) { | 83 | do { |
84 | iterate_all(tox_count, toxes, state); | 84 | iterate_all(tox_count, toxes, state); |
85 | 85 | ||
86 | c_sleep(ITERATION_INTERVAL); | 86 | c_sleep(ITERATION_INTERVAL); |
87 | } | 87 | } while (!all_friends_connected(tox_count, toxes)); |
88 | 88 | ||
89 | printf("tox clients connected\n"); | 89 | printf("tox clients connected\n"); |
90 | 90 | ||
diff --git a/auto_tests/save_load_test.c b/auto_tests/save_load_test.c index 57b2bda5..9c171602 100644 --- a/auto_tests/save_load_test.c +++ b/auto_tests/save_load_test.c | |||
@@ -63,7 +63,7 @@ static void test_few_clients(void) | |||
63 | 63 | ||
64 | uint8_t off = 1; | 64 | uint8_t off = 1; |
65 | 65 | ||
66 | while (1) { | 66 | while (true) { |
67 | tox_iterate(tox1, nullptr); | 67 | tox_iterate(tox1, nullptr); |
68 | tox_iterate(tox2, nullptr); | 68 | tox_iterate(tox2, nullptr); |
69 | tox_iterate(tox3, nullptr); | 69 | tox_iterate(tox3, nullptr); |
@@ -103,7 +103,7 @@ static void test_few_clients(void) | |||
103 | cur_time = time(nullptr); | 103 | cur_time = time(nullptr); |
104 | off = 1; | 104 | off = 1; |
105 | 105 | ||
106 | while (1) { | 106 | while (true) { |
107 | tox_iterate(tox1, nullptr); | 107 | tox_iterate(tox1, nullptr); |
108 | tox_iterate(tox2, nullptr); | 108 | tox_iterate(tox2, nullptr); |
109 | tox_iterate(tox3, nullptr); | 109 | tox_iterate(tox3, nullptr); |
diff --git a/auto_tests/send_message_test.c b/auto_tests/send_message_test.c index d7747ebe..8857d232 100644 --- a/auto_tests/send_message_test.c +++ b/auto_tests/send_message_test.c | |||
@@ -50,12 +50,12 @@ static void send_message_test(Tox **toxes, State *state) | |||
50 | tox_friend_send_message(toxes[0], 0, TOX_MESSAGE_TYPE_NORMAL, msgs, TOX_MAX_MESSAGE_LENGTH, &errm); | 50 | tox_friend_send_message(toxes[0], 0, TOX_MESSAGE_TYPE_NORMAL, msgs, TOX_MAX_MESSAGE_LENGTH, &errm); |
51 | ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_OK, "TOX_MAX_MESSAGE_LENGTH is too big? error=%d", errm); | 51 | ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_OK, "TOX_MAX_MESSAGE_LENGTH is too big? error=%d", errm); |
52 | 52 | ||
53 | while (!state[1].message_received) { | 53 | do { |
54 | tox_iterate(toxes[0], &state[0]); | 54 | tox_iterate(toxes[0], &state[0]); |
55 | tox_iterate(toxes[1], &state[1]); | 55 | tox_iterate(toxes[1], &state[1]); |
56 | 56 | ||
57 | c_sleep(ITERATION_INTERVAL); | 57 | c_sleep(ITERATION_INTERVAL); |
58 | } | 58 | } while (!state[1].message_received); |
59 | } | 59 | } |
60 | 60 | ||
61 | int main(void) | 61 | int main(void) |
diff --git a/auto_tests/set_name_test.c b/auto_tests/set_name_test.c index f8f94047..1e35aa30 100644 --- a/auto_tests/set_name_test.c +++ b/auto_tests/set_name_test.c | |||
@@ -49,22 +49,22 @@ static void test_set_name(void) | |||
49 | 49 | ||
50 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); | 50 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); |
51 | 51 | ||
52 | while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | 52 | do { |
53 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { | ||
54 | tox_iterate(tox1, nullptr); | 53 | tox_iterate(tox1, nullptr); |
55 | tox_iterate(tox2, nullptr); | 54 | tox_iterate(tox2, nullptr); |
56 | c_sleep(ITERATION_INTERVAL); | 55 | c_sleep(ITERATION_INTERVAL); |
57 | } | 56 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
57 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); | ||
58 | 58 | ||
59 | printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); | 59 | printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); |
60 | const time_t con_time = time(nullptr); | 60 | const time_t con_time = time(nullptr); |
61 | 61 | ||
62 | while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || | 62 | do { |
63 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP) { | ||
64 | tox_iterate(tox1, nullptr); | 63 | tox_iterate(tox1, nullptr); |
65 | tox_iterate(tox2, nullptr); | 64 | tox_iterate(tox2, nullptr); |
66 | c_sleep(ITERATION_INTERVAL); | 65 | c_sleep(ITERATION_INTERVAL); |
67 | } | 66 | } while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || |
67 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP); | ||
68 | 68 | ||
69 | printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); | 69 | printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); |
70 | 70 | ||
@@ -75,11 +75,11 @@ static void test_set_name(void) | |||
75 | 75 | ||
76 | bool nickname_updated = false; | 76 | bool nickname_updated = false; |
77 | 77 | ||
78 | while (!nickname_updated) { | 78 | do { |
79 | tox_iterate(tox1, nullptr); | 79 | tox_iterate(tox1, nullptr); |
80 | tox_iterate(tox2, &nickname_updated); | 80 | tox_iterate(tox2, &nickname_updated); |
81 | c_sleep(ITERATION_INTERVAL); | 81 | c_sleep(ITERATION_INTERVAL); |
82 | } | 82 | } while (!nickname_updated); |
83 | 83 | ||
84 | ck_assert_msg(tox_friend_get_name_size(tox2, 0, nullptr) == sizeof(NICKNAME), "Name length not correct"); | 84 | ck_assert_msg(tox_friend_get_name_size(tox2, 0, nullptr) == sizeof(NICKNAME), "Name length not correct"); |
85 | uint8_t temp_name[sizeof(NICKNAME)]; | 85 | uint8_t temp_name[sizeof(NICKNAME)]; |
diff --git a/auto_tests/set_status_message_test.c b/auto_tests/set_status_message_test.c index b6f01c09..1ef8ae56 100644 --- a/auto_tests/set_status_message_test.c +++ b/auto_tests/set_status_message_test.c | |||
@@ -51,24 +51,24 @@ static void test_set_status_message(void) | |||
51 | 51 | ||
52 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); | 52 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); |
53 | 53 | ||
54 | while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | 54 | do { |
55 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { | ||
56 | tox_iterate(tox1, nullptr); | 55 | tox_iterate(tox1, nullptr); |
57 | tox_iterate(tox2, nullptr); | 56 | tox_iterate(tox2, nullptr); |
58 | 57 | ||
59 | c_sleep(ITERATION_INTERVAL); | 58 | c_sleep(ITERATION_INTERVAL); |
60 | } | 59 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
60 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); | ||
61 | 61 | ||
62 | printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); | 62 | printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); |
63 | const time_t con_time = time(nullptr); | 63 | const time_t con_time = time(nullptr); |
64 | 64 | ||
65 | while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || | 65 | do { |
66 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP) { | ||
67 | tox_iterate(tox1, nullptr); | 66 | tox_iterate(tox1, nullptr); |
68 | tox_iterate(tox2, nullptr); | 67 | tox_iterate(tox2, nullptr); |
69 | 68 | ||
70 | c_sleep(ITERATION_INTERVAL); | 69 | c_sleep(ITERATION_INTERVAL); |
71 | } | 70 | } while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || |
71 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP); | ||
72 | 72 | ||
73 | printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); | 73 | printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); |
74 | 74 | ||
@@ -80,11 +80,11 @@ static void test_set_status_message(void) | |||
80 | 80 | ||
81 | bool status_updated = false; | 81 | bool status_updated = false; |
82 | 82 | ||
83 | while (!status_updated) { | 83 | do { |
84 | tox_iterate(tox1, nullptr); | 84 | tox_iterate(tox1, nullptr); |
85 | tox_iterate(tox2, &status_updated); | 85 | tox_iterate(tox2, &status_updated); |
86 | c_sleep(ITERATION_INTERVAL); | 86 | c_sleep(ITERATION_INTERVAL); |
87 | } | 87 | } while (!status_updated); |
88 | 88 | ||
89 | ck_assert_msg(tox_friend_get_status_message_size(tox2, 0, nullptr) == sizeof(STATUS_MESSAGE), | 89 | ck_assert_msg(tox_friend_get_status_message_size(tox2, 0, nullptr) == sizeof(STATUS_MESSAGE), |
90 | "status message length not correct"); | 90 | "status message length not correct"); |
diff --git a/auto_tests/tcp_relay_test.c b/auto_tests/tcp_relay_test.c index 54a28e4a..4020b064 100644 --- a/auto_tests/tcp_relay_test.c +++ b/auto_tests/tcp_relay_test.c | |||
@@ -28,13 +28,13 @@ int main(void) | |||
28 | 28 | ||
29 | printf("Waiting for connection"); | 29 | printf("Waiting for connection"); |
30 | 30 | ||
31 | while (tox_self_get_connection_status(tox_tcp) == TOX_CONNECTION_NONE) { | 31 | do { |
32 | printf("."); | 32 | printf("."); |
33 | fflush(stdout); | 33 | fflush(stdout); |
34 | 34 | ||
35 | tox_iterate(tox_tcp, nullptr); | 35 | tox_iterate(tox_tcp, nullptr); |
36 | c_sleep(ITERATION_INTERVAL); | 36 | c_sleep(ITERATION_INTERVAL); |
37 | } | 37 | } while (tox_self_get_connection_status(tox_tcp) == TOX_CONNECTION_NONE); |
38 | 38 | ||
39 | const TOX_CONNECTION status = tox_self_get_connection_status(tox_tcp); | 39 | const TOX_CONNECTION status = tox_self_get_connection_status(tox_tcp); |
40 | ck_assert_msg(status == TOX_CONNECTION_TCP, | 40 | ck_assert_msg(status == TOX_CONNECTION_TCP, |
diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index b8343f74..e09ed8fb 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c | |||
@@ -101,7 +101,7 @@ loop_top: | |||
101 | ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test); | 101 | ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test); |
102 | } | 102 | } |
103 | 103 | ||
104 | while (1) { | 104 | while (true) { |
105 | uint16_t counter = 0; | 105 | uint16_t counter = 0; |
106 | 106 | ||
107 | for (i = 0; i < NUM_TOXES_TCP; ++i) { | 107 | for (i = 0; i < NUM_TOXES_TCP; ++i) { |
@@ -197,7 +197,7 @@ loop_top: | |||
197 | 197 | ||
198 | uint16_t last_count = 0; | 198 | uint16_t last_count = 0; |
199 | 199 | ||
200 | while (1) { | 200 | while (true) { |
201 | uint16_t counter = 0; | 201 | uint16_t counter = 0; |
202 | 202 | ||
203 | for (i = 0; i < NUM_TOXES_TCP; ++i) { | 203 | for (i = 0; i < NUM_TOXES_TCP; ++i) { |
diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index 62c7c621..6a2f5485 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c | |||
@@ -92,7 +92,7 @@ loop_top: | |||
92 | 92 | ||
93 | uint16_t last_count = 0; | 93 | uint16_t last_count = 0; |
94 | 94 | ||
95 | while (1) { | 95 | while (true) { |
96 | uint16_t counter = 0; | 96 | uint16_t counter = 0; |
97 | 97 | ||
98 | for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) { | 98 | for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) { |
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 4289df53..048b54a5 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -121,9 +121,9 @@ static void regular_call_flow( | |||
121 | ck_assert(0); | 121 | ck_assert(0); |
122 | } | 122 | } |
123 | 123 | ||
124 | time_t start_time = time(nullptr); | 124 | const time_t start_time = time(nullptr); |
125 | 125 | ||
126 | while (BobCC->state != TOXAV_FRIEND_CALL_STATE_FINISHED) { | 126 | do { |
127 | if (BobCC->incoming) { | 127 | if (BobCC->incoming) { |
128 | TOXAV_ERR_ANSWER answer_err; | 128 | TOXAV_ERR_ANSWER answer_err; |
129 | toxav_answer(BobAV, 0, a_br, v_br, &answer_err); | 129 | toxav_answer(BobAV, 0, a_br, v_br, &answer_err); |
@@ -148,7 +148,7 @@ static void regular_call_flow( | |||
148 | } | 148 | } |
149 | 149 | ||
150 | iterate_tox(bootstrap, Alice, Bob); | 150 | iterate_tox(bootstrap, Alice, Bob); |
151 | } | 151 | } while (BobCC->state != TOXAV_FRIEND_CALL_STATE_FINISHED); |
152 | 152 | ||
153 | printf("Success!\n"); | 153 | printf("Success!\n"); |
154 | } | 154 | } |
@@ -195,7 +195,7 @@ static void test_av_flows(void) | |||
195 | 195 | ||
196 | uint8_t off = 1; | 196 | uint8_t off = 1; |
197 | 197 | ||
198 | while (1) { | 198 | while (true) { |
199 | iterate_tox(bootstrap, Alice, Bob); | 199 | iterate_tox(bootstrap, Alice, Bob); |
200 | 200 | ||
201 | if (tox_self_get_connection_status(bootstrap) && | 201 | if (tox_self_get_connection_status(bootstrap) && |
@@ -270,9 +270,9 @@ static void test_av_flows(void) | |||
270 | } | 270 | } |
271 | } | 271 | } |
272 | 272 | ||
273 | while (!BobCC.incoming) { | 273 | do { |
274 | iterate_tox(bootstrap, Alice, Bob); | 274 | iterate_tox(bootstrap, Alice, Bob); |
275 | } | 275 | } while (!BobCC.incoming); |
276 | 276 | ||
277 | /* Reject */ | 277 | /* Reject */ |
278 | { | 278 | { |
@@ -285,9 +285,9 @@ static void test_av_flows(void) | |||
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | while (AliceCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED) { | 288 | do { |
289 | iterate_tox(bootstrap, Alice, Bob); | 289 | iterate_tox(bootstrap, Alice, Bob); |
290 | } | 290 | } while (AliceCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED); |
291 | 291 | ||
292 | printf("Success!\n"); | 292 | printf("Success!\n"); |
293 | } | 293 | } |
@@ -308,9 +308,9 @@ static void test_av_flows(void) | |||
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | while (!BobCC.incoming) { | 311 | do { |
312 | iterate_tox(bootstrap, Alice, Bob); | 312 | iterate_tox(bootstrap, Alice, Bob); |
313 | } | 313 | } while (!BobCC.incoming); |
314 | 314 | ||
315 | /* Cancel */ | 315 | /* Cancel */ |
316 | { | 316 | { |
@@ -324,9 +324,9 @@ static void test_av_flows(void) | |||
324 | } | 324 | } |
325 | 325 | ||
326 | /* Alice will not receive end state */ | 326 | /* Alice will not receive end state */ |
327 | while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED) { | 327 | do { |
328 | iterate_tox(bootstrap, Alice, Bob); | 328 | iterate_tox(bootstrap, Alice, Bob); |
329 | } | 329 | } while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED); |
330 | 330 | ||
331 | printf("Success!\n"); | 331 | printf("Success!\n"); |
332 | } | 332 | } |
@@ -348,9 +348,9 @@ static void test_av_flows(void) | |||
348 | } | 348 | } |
349 | } | 349 | } |
350 | 350 | ||
351 | while (!BobCC.incoming) { | 351 | do { |
352 | iterate_tox(bootstrap, Alice, Bob); | 352 | iterate_tox(bootstrap, Alice, Bob); |
353 | } | 353 | } while (!BobCC.incoming); |
354 | 354 | ||
355 | /* At first try all stuff while in invalid state */ | 355 | /* At first try all stuff while in invalid state */ |
356 | ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, nullptr)); | 356 | ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, nullptr)); |
@@ -438,9 +438,9 @@ static void test_av_flows(void) | |||
438 | } | 438 | } |
439 | } | 439 | } |
440 | 440 | ||
441 | while (!BobCC.incoming) { | 441 | do { |
442 | iterate_tox(bootstrap, Alice, Bob); | 442 | iterate_tox(bootstrap, Alice, Bob); |
443 | } | 443 | } while (!BobCC.incoming); |
444 | 444 | ||
445 | { | 445 | { |
446 | TOXAV_ERR_ANSWER rc; | 446 | TOXAV_ERR_ANSWER rc; |
@@ -506,9 +506,9 @@ static void test_av_flows(void) | |||
506 | } | 506 | } |
507 | } | 507 | } |
508 | 508 | ||
509 | while (!BobCC.incoming) { | 509 | do { |
510 | iterate_tox(bootstrap, Alice, Bob); | 510 | iterate_tox(bootstrap, Alice, Bob); |
511 | } | 511 | } while (!BobCC.incoming); |
512 | 512 | ||
513 | { | 513 | { |
514 | TOXAV_ERR_ANSWER rc; | 514 | TOXAV_ERR_ANSWER rc; |
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index a8ed1c80..1cdc0733 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -116,9 +116,9 @@ static void *call_thread(void *pd) | |||
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | while (!BobCC->incoming) { | 119 | do { |
120 | c_sleep(10); | 120 | c_sleep(10); |
121 | } | 121 | } while (!BobCC->incoming); |
122 | 122 | ||
123 | { /* Answer */ | 123 | { /* Answer */ |
124 | TOXAV_ERR_ANSWER rc; | 124 | TOXAV_ERR_ANSWER rc; |
@@ -139,7 +139,7 @@ static void *call_thread(void *pd) | |||
139 | 139 | ||
140 | time_t start_time = time(nullptr); | 140 | time_t start_time = time(nullptr); |
141 | 141 | ||
142 | while (time(nullptr) - start_time < 4) { | 142 | do { |
143 | toxav_iterate(AliceAV); | 143 | toxav_iterate(AliceAV); |
144 | toxav_iterate(BobAV); | 144 | toxav_iterate(BobAV); |
145 | 145 | ||
@@ -150,7 +150,7 @@ static void *call_thread(void *pd) | |||
150 | toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, nullptr); | 150 | toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, nullptr); |
151 | 151 | ||
152 | c_sleep(10); | 152 | c_sleep(10); |
153 | } | 153 | } while (time(nullptr) - start_time < 4); |
154 | 154 | ||
155 | { /* Hangup */ | 155 | { /* Hangup */ |
156 | TOXAV_ERR_CALL_CONTROL rc; | 156 | TOXAV_ERR_CALL_CONTROL rc; |
@@ -228,7 +228,7 @@ static void test_av_three_calls(void) | |||
228 | 228 | ||
229 | uint8_t off = 1; | 229 | uint8_t off = 1; |
230 | 230 | ||
231 | while (1) { | 231 | while (true) { |
232 | tox_iterate(bootstrap, nullptr); | 232 | tox_iterate(bootstrap, nullptr); |
233 | tox_iterate(Alice, nullptr); | 233 | tox_iterate(Alice, nullptr); |
234 | tox_iterate(Bobs[0], nullptr); | 234 | tox_iterate(Bobs[0], nullptr); |
@@ -290,14 +290,14 @@ static void test_av_three_calls(void) | |||
290 | 290 | ||
291 | time_t start_time = time(nullptr); | 291 | time_t start_time = time(nullptr); |
292 | 292 | ||
293 | while (time(nullptr) - start_time < 5) { | 293 | do { |
294 | tox_iterate(bootstrap, nullptr); | 294 | tox_iterate(bootstrap, nullptr); |
295 | tox_iterate(Alice, nullptr); | 295 | tox_iterate(Alice, nullptr); |
296 | tox_iterate(Bobs[0], nullptr); | 296 | tox_iterate(Bobs[0], nullptr); |
297 | tox_iterate(Bobs[1], nullptr); | 297 | tox_iterate(Bobs[1], nullptr); |
298 | tox_iterate(Bobs[2], nullptr); | 298 | tox_iterate(Bobs[2], nullptr); |
299 | c_sleep(20); | 299 | c_sleep(20); |
300 | } | 300 | } while (time(nullptr) - start_time < 5); |
301 | 301 | ||
302 | ck_assert(pthread_join(tids[0], &retval) == 0); | 302 | ck_assert(pthread_join(tids[0], &retval) == 0); |
303 | ck_assert(retval == nullptr); | 303 | ck_assert(retval == nullptr); |
diff --git a/auto_tests/typing_test.c b/auto_tests/typing_test.c index 3b41dd40..71131d13 100644 --- a/auto_tests/typing_test.c +++ b/auto_tests/typing_test.c | |||
@@ -45,24 +45,24 @@ static void test_typing(void) | |||
45 | 45 | ||
46 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); | 46 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); |
47 | 47 | ||
48 | while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | 48 | do { |
49 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { | ||
50 | tox_iterate(tox1, nullptr); | 49 | tox_iterate(tox1, nullptr); |
51 | tox_iterate(tox2, nullptr); | 50 | tox_iterate(tox2, nullptr); |
52 | 51 | ||
53 | c_sleep(200); | 52 | c_sleep(200); |
54 | } | 53 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
54 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); | ||
55 | 55 | ||
56 | printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); | 56 | printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); |
57 | const time_t con_time = time(nullptr); | 57 | const time_t con_time = time(nullptr); |
58 | 58 | ||
59 | while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || | 59 | do { |
60 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP) { | ||
61 | tox_iterate(tox1, nullptr); | 60 | tox_iterate(tox1, nullptr); |
62 | tox_iterate(tox2, nullptr); | 61 | tox_iterate(tox2, nullptr); |
63 | 62 | ||
64 | c_sleep(200); | 63 | c_sleep(200); |
65 | } | 64 | } while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || |
65 | tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP); | ||
66 | 66 | ||
67 | printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); | 67 | printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); |
68 | 68 | ||
@@ -71,20 +71,20 @@ static void test_typing(void) | |||
71 | 71 | ||
72 | bool is_typing = false; | 72 | bool is_typing = false; |
73 | 73 | ||
74 | while (!is_typing) { | 74 | do { |
75 | tox_iterate(tox1, nullptr); | 75 | tox_iterate(tox1, nullptr); |
76 | tox_iterate(tox2, &is_typing); | 76 | tox_iterate(tox2, &is_typing); |
77 | c_sleep(200); | 77 | c_sleep(200); |
78 | } | 78 | } while (!is_typing); |
79 | 79 | ||
80 | ck_assert_msg(tox_friend_get_typing(tox2, 0, nullptr) == 1, "Typing failure"); | 80 | ck_assert_msg(tox_friend_get_typing(tox2, 0, nullptr) == 1, "Typing failure"); |
81 | tox_self_set_typing(tox1, 0, false, nullptr); | 81 | tox_self_set_typing(tox1, 0, false, nullptr); |
82 | 82 | ||
83 | while (is_typing) { | 83 | do { |
84 | tox_iterate(tox1, nullptr); | 84 | tox_iterate(tox1, nullptr); |
85 | tox_iterate(tox2, &is_typing); | 85 | tox_iterate(tox2, &is_typing); |
86 | c_sleep(200); | 86 | c_sleep(200); |
87 | } | 87 | } while (is_typing); |
88 | 88 | ||
89 | TOX_ERR_FRIEND_QUERY err_t; | 89 | TOX_ERR_FRIEND_QUERY err_t; |
90 | ck_assert_msg(tox_friend_get_typing(tox2, 0, &err_t) == 0, "Typing failure"); | 90 | ck_assert_msg(tox_friend_get_typing(tox2, 0, &err_t) == 0, "Typing failure"); |