summaryrefslogtreecommitdiff
path: root/auto_tests/typing_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/typing_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/typing_test.c')
-rw-r--r--auto_tests/typing_test.c20
1 files changed, 10 insertions, 10 deletions
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");