summaryrefslogtreecommitdiff
path: root/auto_tests/file_transfer_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-08-25 12:16:54 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-08-25 15:25:33 +0000
commit94b06818fbd7a93387ff4c155b6eff711651aea9 (patch)
tree63365adeb88705c5c2f0cdb4d2afd00a4bd8b43c /auto_tests/file_transfer_test.c
parent0935aab92760a7c9c547faa86c29dcd0d1e03f24 (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/file_transfer_test.c')
-rw-r--r--auto_tests/file_transfer_test.c20
1 files changed, 10 insertions, 10 deletions
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,