summaryrefslogtreecommitdiff
path: root/auto_tests/set_status_message_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/set_status_message_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/set_status_message_test.c')
-rw-r--r--auto_tests/set_status_message_test.c16
1 files changed, 8 insertions, 8 deletions
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");