diff options
author | hugbubby <hugbubby@protonmail.com> | 2018-07-15 17:09:13 -0700 |
---|---|---|
committer | hugbubby <hugbubby@protonmail.com> | 2018-07-18 13:55:30 -0700 |
commit | 864d1c15e4a3b8df236af320312e8115c6bcd791 (patch) | |
tree | 945467578a0f7ee140f7d1641e3f4042e63b5bc8 /auto_tests/conference_test.c | |
parent | 392eef7900fdedda28f9c3aff5b0434f963a7f86 (diff) |
Using stdint instead of int/long
Did my best to surmise the size requirements of
these integers, will do the rest of the tests soon. Also added a todo
and made an obsessive change to a for loop.
Diffstat (limited to 'auto_tests/conference_test.c')
-rw-r--r-- | auto_tests/conference_test.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index caa00356..374274b8 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c | |||
@@ -27,7 +27,7 @@ | |||
27 | static void handle_self_connection_status( | 27 | static void handle_self_connection_status( |
28 | Tox *tox, TOX_CONNECTION connection_status, void *user_data) | 28 | Tox *tox, TOX_CONNECTION connection_status, void *user_data) |
29 | { | 29 | { |
30 | const int id = *(int *)user_data; | 30 | const uint16_t id = *(uint16_t *)user_data; |
31 | 31 | ||
32 | if (connection_status != TOX_CONNECTION_NONE) { | 32 | if (connection_status != TOX_CONNECTION_NONE) { |
33 | printf("tox #%d: is now connected\n", id); | 33 | printf("tox #%d: is now connected\n", id); |
@@ -39,7 +39,7 @@ static void handle_self_connection_status( | |||
39 | static void handle_friend_connection_status( | 39 | static void handle_friend_connection_status( |
40 | Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, void *user_data) | 40 | Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, void *user_data) |
41 | { | 41 | { |
42 | const int id = *(int *)user_data; | 42 | const uint16_t id = *(uint16_t *)user_data; |
43 | 43 | ||
44 | if (connection_status != TOX_CONNECTION_NONE) { | 44 | if (connection_status != TOX_CONNECTION_NONE) { |
45 | printf("tox #%d: is now connected to friend %d\n", id, friendnumber); | 45 | printf("tox #%d: is now connected to friend %d\n", id, friendnumber); |
@@ -52,7 +52,7 @@ static void handle_conference_invite( | |||
52 | Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, | 52 | Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, |
53 | const uint8_t *data, size_t length, void *user_data) | 53 | const uint8_t *data, size_t length, void *user_data) |
54 | { | 54 | { |
55 | const int id = *(int *)user_data; | 55 | const uint16_t id = *(uint16_t *)user_data; |
56 | ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type); | 56 | ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type); |
57 | 57 | ||
58 | TOX_ERR_CONFERENCE_JOIN err; | 58 | TOX_ERR_CONFERENCE_JOIN err; |
@@ -74,7 +74,7 @@ static void handle_conference_invite( | |||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | static unsigned int num_recv; | 77 | static uint16_t num_recv; |
78 | 78 | ||
79 | static void handle_conference_message( | 79 | static void handle_conference_message( |
80 | Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, | 80 | Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, |
@@ -87,7 +87,7 @@ static void handle_conference_message( | |||
87 | 87 | ||
88 | static void run_conference_tests(Tox **toxes, uint32_t *tox_index) | 88 | static void run_conference_tests(Tox **toxes, uint32_t *tox_index) |
89 | { | 89 | { |
90 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 90 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
91 | tox_callback_conference_message(toxes[i], &handle_conference_message); | 91 | tox_callback_conference_message(toxes[i], &handle_conference_message); |
92 | } | 92 | } |
93 | 93 | ||
@@ -100,8 +100,8 @@ static void run_conference_tests(Tox **toxes, uint32_t *tox_index) | |||
100 | err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message."); | 100 | err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message."); |
101 | num_recv = 0; | 101 | num_recv = 0; |
102 | 102 | ||
103 | for (unsigned j = 0; j < 20; ++j) { | 103 | for (uint8_t j = 0; j < 20; ++j) { |
104 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 104 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
105 | tox_iterate(toxes[i], &tox_index[i]); | 105 | tox_iterate(toxes[i], &tox_index[i]); |
106 | } | 106 | } |
107 | 107 | ||
@@ -111,18 +111,18 @@ static void run_conference_tests(Tox **toxes, uint32_t *tox_index) | |||
111 | c_sleep(25); | 111 | c_sleep(25); |
112 | ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages."); | 112 | ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages."); |
113 | 113 | ||
114 | for (unsigned k = NUM_GROUP_TOX; k != 0 ; --k) { | 114 | for (uint16_t k = NUM_GROUP_TOX; k != 0 ; --k) { |
115 | tox_conference_delete(toxes[k - 1], 0, nullptr); | 115 | tox_conference_delete(toxes[k - 1], 0, nullptr); |
116 | 116 | ||
117 | for (unsigned j = 0; j < 10; ++j) { | 117 | for (uint8_t j = 0; j < 10; ++j) { |
118 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 118 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
119 | tox_iterate(toxes[i], &tox_index[i]); | 119 | tox_iterate(toxes[i], &tox_index[i]); |
120 | } | 120 | } |
121 | 121 | ||
122 | c_sleep(50); | 122 | c_sleep(50); |
123 | } | 123 | } |
124 | 124 | ||
125 | for (unsigned i = 0; i < k - 1; ++i) { | 125 | for (uint16_t i = 0; i < k - 1; ++i) { |
126 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); | 126 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); |
127 | ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)." | 127 | ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)." |
128 | "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n", | 128 | "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n", |
@@ -144,7 +144,7 @@ static void test_many_group(void) | |||
144 | 144 | ||
145 | printf("creating %d toxes\n", NUM_GROUP_TOX); | 145 | printf("creating %d toxes\n", NUM_GROUP_TOX); |
146 | 146 | ||
147 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 147 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
148 | TOX_ERR_NEW err; | 148 | TOX_ERR_NEW err; |
149 | tox_index[i] = i + 1; | 149 | tox_index[i] = i + 1; |
150 | toxes[i] = tox_new_log(opts, &err, &tox_index[i]); | 150 | toxes[i] = tox_new_log(opts, &err, &tox_index[i]); |
@@ -186,7 +186,7 @@ static void test_many_group(void) | |||
186 | while (online_count != NUM_GROUP_TOX) { | 186 | while (online_count != NUM_GROUP_TOX) { |
187 | online_count = 0; | 187 | online_count = 0; |
188 | 188 | ||
189 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 189 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
190 | tox_iterate(toxes[i], &tox_index[i]); | 190 | tox_iterate(toxes[i], &tox_index[i]); |
191 | online_count += tox_friend_get_connection_status(toxes[i], 0, nullptr) != TOX_CONNECTION_NONE; | 191 | online_count += tox_friend_get_connection_status(toxes[i], 0, nullptr) != TOX_CONNECTION_NONE; |
192 | } | 192 | } |
@@ -197,7 +197,7 @@ static void test_many_group(void) | |||
197 | c_sleep(1000); | 197 | c_sleep(1000); |
198 | } | 198 | } |
199 | 199 | ||
200 | printf("friends connected, took %d seconds\n", (int)(time(nullptr) - cur_time)); | 200 | printf("friends connected, took %d seconds\n", (uint16_t)(time(nullptr) - cur_time)); |
201 | 201 | ||
202 | ck_assert_msg(tox_conference_new(toxes[0], nullptr) != UINT32_MAX, "Failed to create group"); | 202 | ck_assert_msg(tox_conference_new(toxes[0], nullptr) != UINT32_MAX, "Failed to create group"); |
203 | printf("tox #%d: inviting its first friend\n", tox_index[0]); | 203 | printf("tox #%d: inviting its first friend\n", tox_index[0]); |
@@ -206,7 +206,7 @@ static void test_many_group(void) | |||
206 | "Failed to set group title"); | 206 | "Failed to set group title"); |
207 | 207 | ||
208 | // One iteration for all the invitations to happen. | 208 | // One iteration for all the invitations to happen. |
209 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 209 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
210 | tox_iterate(toxes[i], &tox_index[i]); | 210 | tox_iterate(toxes[i], &tox_index[i]); |
211 | } | 211 | } |
212 | 212 | ||
@@ -218,7 +218,7 @@ static void test_many_group(void) | |||
218 | invited_count = 0; | 218 | invited_count = 0; |
219 | printf("current peer counts: ["); | 219 | printf("current peer counts: ["); |
220 | 220 | ||
221 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 221 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
222 | tox_iterate(toxes[i], &tox_index[i]); | 222 | tox_iterate(toxes[i], &tox_index[i]); |
223 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); | 223 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); |
224 | invited_count += peer_count == NUM_GROUP_TOX; | 224 | invited_count += peer_count == NUM_GROUP_TOX; |
@@ -236,7 +236,7 @@ static void test_many_group(void) | |||
236 | c_sleep(1000); | 236 | c_sleep(1000); |
237 | } | 237 | } |
238 | 238 | ||
239 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 239 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
240 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); | 240 | uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); |
241 | 241 | ||
242 | ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." | 242 | ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." |
@@ -250,17 +250,17 @@ static void test_many_group(void) | |||
250 | ck_assert_msg(memcmp("Gentoo", title, ret) == 0, "Wrong title"); | 250 | ck_assert_msg(memcmp("Gentoo", title, ret) == 0, "Wrong title"); |
251 | } | 251 | } |
252 | 252 | ||
253 | printf("group connected, took %d seconds\n", (int)(time(nullptr) - cur_time)); | 253 | printf("group connected, took %d seconds\n", (uint16_t)(time(nullptr) - cur_time)); |
254 | 254 | ||
255 | run_conference_tests(toxes, tox_index); | 255 | run_conference_tests(toxes, tox_index); |
256 | 256 | ||
257 | printf("tearing down toxes\n"); | 257 | printf("tearing down toxes\n"); |
258 | 258 | ||
259 | for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { | 259 | for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { |
260 | tox_kill(toxes[i]); | 260 | tox_kill(toxes[i]); |
261 | } | 261 | } |
262 | 262 | ||
263 | printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time)); | 263 | printf("test_many_group succeeded, took %d seconds\n", (uint16_t)(time(nullptr) - test_start_time)); |
264 | } | 264 | } |
265 | 265 | ||
266 | int main(void) | 266 | int main(void) |