diff options
author | hugbubby <hugbubby@protonmail.com> | 2018-09-13 09:49:10 -0500 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-09-14 13:51:41 +0000 |
commit | 0688877fba0e224ecd33e521c58475b150575235 (patch) | |
tree | f923e938ecb49404c35bd7f69526eff67af6e195 /auto_tests | |
parent | 9f1757e3a50c17fcd00ab3778846ef520aa99b74 (diff) |
Use run_auto_test fixture in typing_test.c
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/typing_test.c | 91 |
1 files changed, 25 insertions, 66 deletions
diff --git a/auto_tests/typing_test.c b/auto_tests/typing_test.c index 71131d13..60968876 100644 --- a/auto_tests/typing_test.c +++ b/auto_tests/typing_test.c | |||
@@ -15,91 +15,50 @@ | |||
15 | #include "../toxcore/util.h" | 15 | #include "../toxcore/util.h" |
16 | #include "check_compat.h" | 16 | #include "check_compat.h" |
17 | 17 | ||
18 | typedef struct State { | ||
19 | uint32_t index; | ||
20 | uint64_t clock; | ||
21 | bool friend_is_typing; | ||
22 | } State; | ||
23 | |||
24 | #include "run_auto_test.h" | ||
25 | |||
18 | static void typing_callback(Tox *m, uint32_t friendnumber, bool typing, void *userdata) | 26 | static void typing_callback(Tox *m, uint32_t friendnumber, bool typing, void *userdata) |
19 | { | 27 | { |
20 | bool *is_typing = (bool *)userdata; | 28 | State *state = (State *)userdata; |
21 | *is_typing = typing; | 29 | state->friend_is_typing = typing; |
22 | } | 30 | } |
23 | 31 | ||
24 | static void test_typing(void) | 32 | static void test_typing(Tox **toxes, State *state) |
25 | { | 33 | { |
26 | printf("initialising 2 toxes\n"); | 34 | time_t cur_time = time(nullptr); |
27 | uint32_t index[] = { 1, 2 }; | ||
28 | const time_t cur_time = time(nullptr); | ||
29 | Tox *const tox1 = tox_new_log(nullptr, nullptr, &index[0]); | ||
30 | Tox *const tox2 = tox_new_log(nullptr, nullptr, &index[1]); | ||
31 | |||
32 | ck_assert_msg(tox1 && tox2, "failed to create 2 tox instances"); | ||
33 | |||
34 | printf("tox1 adds tox2 as friend, tox2 adds tox1\n"); | ||
35 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; | ||
36 | tox_self_get_public_key(tox2, public_key); | ||
37 | tox_friend_add_norequest(tox1, public_key, nullptr); | ||
38 | tox_self_get_public_key(tox1, public_key); | ||
39 | tox_friend_add_norequest(tox2, public_key, nullptr); | ||
40 | |||
41 | printf("bootstrapping tox2 off tox1\n"); | ||
42 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | ||
43 | tox_self_get_dht_id(tox1, dht_key); | ||
44 | const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr); | ||
45 | 35 | ||
46 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); | 36 | tox_callback_friend_typing(toxes[1], &typing_callback); |
37 | tox_self_set_typing(toxes[0], 0, true, nullptr); | ||
47 | 38 | ||
48 | do { | 39 | do { |
49 | tox_iterate(tox1, nullptr); | 40 | iterate_all_wait(2, toxes, state, 200); |
50 | tox_iterate(tox2, nullptr); | 41 | } while (!state[1].friend_is_typing); |
51 | 42 | ||
52 | c_sleep(200); | 43 | ck_assert_msg(tox_friend_get_typing(toxes[1], 0, nullptr) == 1, |
53 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | 44 | "tox_friend_get_typing should have returned true, but it didn't"); |
54 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); | 45 | tox_self_set_typing(toxes[0], 0, false, nullptr); |
55 | |||
56 | printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); | ||
57 | const time_t con_time = time(nullptr); | ||
58 | 46 | ||
59 | do { | 47 | do { |
60 | tox_iterate(tox1, nullptr); | 48 | iterate_all_wait(2, toxes, state, 200); |
61 | tox_iterate(tox2, nullptr); | 49 | } while (state[1].friend_is_typing); |
62 | |||
63 | c_sleep(200); | ||
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 | |||
67 | printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); | ||
68 | |||
69 | tox_callback_friend_typing(tox2, &typing_callback); | ||
70 | tox_self_set_typing(tox1, 0, true, nullptr); | ||
71 | |||
72 | bool is_typing = false; | ||
73 | |||
74 | do { | ||
75 | tox_iterate(tox1, nullptr); | ||
76 | tox_iterate(tox2, &is_typing); | ||
77 | c_sleep(200); | ||
78 | } while (!is_typing); | ||
79 | |||
80 | ck_assert_msg(tox_friend_get_typing(tox2, 0, nullptr) == 1, "Typing failure"); | ||
81 | tox_self_set_typing(tox1, 0, false, nullptr); | ||
82 | |||
83 | do { | ||
84 | tox_iterate(tox1, nullptr); | ||
85 | tox_iterate(tox2, &is_typing); | ||
86 | c_sleep(200); | ||
87 | } while (is_typing); | ||
88 | 50 | ||
89 | TOX_ERR_FRIEND_QUERY err_t; | 51 | TOX_ERR_FRIEND_QUERY err_t; |
90 | ck_assert_msg(tox_friend_get_typing(tox2, 0, &err_t) == 0, "Typing failure"); | 52 | ck_assert_msg(tox_friend_get_typing(toxes[1], 0, &err_t) == 0, |
91 | ck_assert_msg(err_t == TOX_ERR_FRIEND_QUERY_OK, "Typing failure"); | 53 | "tox_friend_get_typing should have returned false, but it didn't"); |
54 | ck_assert_msg(err_t == TOX_ERR_FRIEND_QUERY_OK, "tox_friend_get_typing call did not return correct error"); | ||
92 | 55 | ||
93 | printf("test_typing succeeded, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); | 56 | printf("test_typing succeeded, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time)); |
94 | |||
95 | tox_kill(tox1); | ||
96 | tox_kill(tox2); | ||
97 | } | 57 | } |
98 | 58 | ||
99 | int main(void) | 59 | int main(void) |
100 | { | 60 | { |
101 | setvbuf(stdout, nullptr, _IONBF, 0); | 61 | setvbuf(stdout, nullptr, _IONBF, 0); |
102 | 62 | run_auto_test(2, test_typing, false); | |
103 | test_typing(); | ||
104 | return 0; | 63 | return 0; |
105 | } | 64 | } |