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 | |
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')
-rw-r--r-- | auto_tests/conference_test.c | 40 | ||||
-rw-r--r-- | auto_tests/conference_two_test.c | 6 | ||||
-rw-r--r-- | auto_tests/crypto_test.c | 30 | ||||
-rw-r--r-- | auto_tests/dht_test.c | 53 |
4 files changed, 64 insertions, 65 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) |
diff --git a/auto_tests/conference_two_test.c b/auto_tests/conference_two_test.c index c3036165..8d834dc4 100644 --- a/auto_tests/conference_two_test.c +++ b/auto_tests/conference_two_test.c | |||
@@ -14,15 +14,15 @@ | |||
14 | int main(void) | 14 | int main(void) |
15 | { | 15 | { |
16 | // Create toxes. | 16 | // Create toxes. |
17 | uint32_t id = 1; | 17 | uint8_t id = 1; |
18 | Tox *tox1 = tox_new_log(nullptr, nullptr, &id); | 18 | Tox *tox1 = tox_new_log(nullptr, nullptr, &id); |
19 | 19 | ||
20 | // Create two conferences and then exit. | 20 | // Create two conferences and then exit. |
21 | TOX_ERR_CONFERENCE_NEW err; | 21 | TOX_ERR_CONFERENCE_NEW err; |
22 | tox_conference_new(tox1, &err); | 22 | tox_conference_new(tox1, &err); |
23 | ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 1: %d", err); | 23 | ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "Failed to create conference 1: %d.", err); |
24 | tox_conference_new(tox1, &err); | 24 | tox_conference_new(tox1, &err); |
25 | ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 2: %d", err); | 25 | ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "Failed to create conference 2: %d.", err); |
26 | 26 | ||
27 | tox_kill(tox1); | 27 | tox_kill(tox1); |
28 | 28 | ||
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index 23c45dd0..c87ffa54 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c | |||
@@ -92,7 +92,7 @@ START_TEST(test_known) | |||
92 | { | 92 | { |
93 | unsigned char c[147]; | 93 | unsigned char c[147]; |
94 | unsigned char m[131]; | 94 | unsigned char m[131]; |
95 | int clen, mlen; | 95 | uint16_t clen, mlen; |
96 | 96 | ||
97 | ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(unsigned char), | 97 | ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(unsigned char), |
98 | "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); | 98 | "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); |
@@ -116,7 +116,7 @@ START_TEST(test_fast_known) | |||
116 | unsigned char k[CRYPTO_SHARED_KEY_SIZE]; | 116 | unsigned char k[CRYPTO_SHARED_KEY_SIZE]; |
117 | unsigned char c[147]; | 117 | unsigned char c[147]; |
118 | unsigned char m[131]; | 118 | unsigned char m[131]; |
119 | int clen, mlen; | 119 | uint16_t clen, mlen; |
120 | 120 | ||
121 | encrypt_precompute(bobpk, alicesk, k); | 121 | encrypt_precompute(bobpk, alicesk, k); |
122 | 122 | ||
@@ -158,11 +158,11 @@ START_TEST(test_endtoend) | |||
158 | unsigned char m3[sizeof(m)]; | 158 | unsigned char m3[sizeof(m)]; |
159 | unsigned char m4[sizeof(m)]; | 159 | unsigned char m4[sizeof(m)]; |
160 | 160 | ||
161 | int mlen; | 161 | uint16_t mlen; |
162 | int c1len, c2len, c3len, c4len; | 162 | uint16_t c1len, c2len, c3len, c4len; |
163 | int m1len, m2len, m3len, m4len; | 163 | uint16_t m1len, m2len, m3len, m4len; |
164 | 164 | ||
165 | int testno; | 165 | uint8_t testno; |
166 | 166 | ||
167 | // Test 100 random messages and keypairs | 167 | // Test 100 random messages and keypairs |
168 | for (testno = 0; testno < 100; testno++) { | 168 | for (testno = 0; testno < 100; testno++) { |
@@ -188,7 +188,7 @@ START_TEST(test_endtoend) | |||
188 | c4len = encrypt_data_symmetric(k2, n, m, mlen, c4); | 188 | c4len = encrypt_data_symmetric(k2, n, m, mlen, c4); |
189 | 189 | ||
190 | ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ"); | 190 | ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ"); |
191 | ck_assert_msg(c1len == mlen + (int)CRYPTO_MAC_SIZE, "wrong cyphertext length"); | 191 | ck_assert_msg(c1len == mlen + (uint16_t)CRYPTO_MAC_SIZE, "wrong cyphertext length"); |
192 | ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0 | 192 | ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0 |
193 | && memcmp(c1, c4, c1len) == 0, "crypertexts differ"); | 193 | && memcmp(c1, c4, c1len) == 0, "crypertexts differ"); |
194 | 194 | ||
@@ -220,8 +220,8 @@ START_TEST(test_large_data) | |||
220 | unsigned char m2[MAX_CRYPTO_PACKET_SIZE]; | 220 | unsigned char m2[MAX_CRYPTO_PACKET_SIZE]; |
221 | unsigned char c2[sizeof(m2) + CRYPTO_MAC_SIZE]; | 221 | unsigned char c2[sizeof(m2) + CRYPTO_MAC_SIZE]; |
222 | 222 | ||
223 | int c1len, c2len; | 223 | uint16_t c1len, c2len; |
224 | int m1plen; | 224 | uint16_t m1plen; |
225 | 225 | ||
226 | //Generate random messages | 226 | //Generate random messages |
227 | rand_bytes(m1, sizeof(m1)); | 227 | rand_bytes(m1, sizeof(m1)); |
@@ -254,8 +254,8 @@ START_TEST(test_large_data_symmetric) | |||
254 | unsigned char c1[sizeof(m1) + CRYPTO_MAC_SIZE]; | 254 | unsigned char c1[sizeof(m1) + CRYPTO_MAC_SIZE]; |
255 | unsigned char m1prime[sizeof(m1)]; | 255 | unsigned char m1prime[sizeof(m1)]; |
256 | 256 | ||
257 | int c1len; | 257 | uint16_t c1len; |
258 | int m1plen; | 258 | uint16_t m1plen; |
259 | 259 | ||
260 | //Generate random messages | 260 | //Generate random messages |
261 | rand_bytes(m1, sizeof(m1)); | 261 | rand_bytes(m1, sizeof(m1)); |
@@ -282,9 +282,7 @@ static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) | |||
282 | num2 = num + num1; | 282 | num2 = num + num1; |
283 | 283 | ||
284 | if (num2 < num1) { | 284 | if (num2 < num1) { |
285 | uint32_t i; | 285 | for (uint16_t i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) { |
286 | |||
287 | for (i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) { | ||
288 | ++nonce[i - 1]; | 286 | ++nonce[i - 1]; |
289 | 287 | ||
290 | if (nonce[i - 1] != 0) { | 288 | if (nonce[i - 1] != 0) { |
@@ -299,7 +297,7 @@ static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) | |||
299 | 297 | ||
300 | START_TEST(test_increment_nonce) | 298 | START_TEST(test_increment_nonce) |
301 | { | 299 | { |
302 | long long unsigned int i; | 300 | uint32_t i; |
303 | 301 | ||
304 | uint8_t n[CRYPTO_NONCE_SIZE]; | 302 | uint8_t n[CRYPTO_NONCE_SIZE]; |
305 | 303 | ||
@@ -362,7 +360,7 @@ int main(void) | |||
362 | 360 | ||
363 | Suite *crypto = crypto_suite(); | 361 | Suite *crypto = crypto_suite(); |
364 | SRunner *test_runner = srunner_create(crypto); | 362 | SRunner *test_runner = srunner_create(crypto); |
365 | int number_failed = 0; | 363 | uint8_t number_failed = 0; |
366 | 364 | ||
367 | srunner_run_all(test_runner, CK_NORMAL); | 365 | srunner_run_all(test_runner, CK_NORMAL); |
368 | number_failed = srunner_ntests_failed(test_runner); | 366 | number_failed = srunner_ntests_failed(test_runner); |
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index a63a55b0..dec803e5 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c | |||
@@ -94,9 +94,9 @@ static uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uin | |||
94 | 94 | ||
95 | static int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key) | 95 | static int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key) |
96 | { | 96 | { |
97 | int i; | 97 | uint32_t i; |
98 | 98 | ||
99 | for (i = 0; i < (int)length; ++i) { | 99 | for (i = 0; i < (uint32_t)length; ++i) { |
100 | if (id_equal(public_key, list[i].public_key)) { | 100 | if (id_equal(public_key, list[i].public_key)) { |
101 | return i; | 101 | return i; |
102 | } | 102 | } |
@@ -110,7 +110,7 @@ static void test_addto_lists_update(DHT *dht, | |||
110 | uint32_t length, | 110 | uint32_t length, |
111 | IP_Port *ip_port) | 111 | IP_Port *ip_port) |
112 | { | 112 | { |
113 | int used, test, test1, test2, found; | 113 | uint32_t used, test, test1, test2, found; |
114 | IP_Port test_ipp; | 114 | IP_Port test_ipp; |
115 | uint8_t test_id[CRYPTO_PUBLIC_KEY_SIZE]; | 115 | uint8_t test_id[CRYPTO_PUBLIC_KEY_SIZE]; |
116 | uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0; | 116 | uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0; |
@@ -229,7 +229,7 @@ static void test_addto_lists_possible_bad(DHT *dht, | |||
229 | const uint8_t *comp_client_id) | 229 | const uint8_t *comp_client_id) |
230 | { | 230 | { |
231 | // check "possibly bad" clients replacement | 231 | // check "possibly bad" clients replacement |
232 | int used, test1, test2, test3; | 232 | uint32_t used, test1, test2, test3; |
233 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], | 233 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], |
234 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; | 234 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; |
235 | uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0; | 235 | uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0; |
@@ -263,9 +263,9 @@ static void test_addto_lists_possible_bad(DHT *dht, | |||
263 | 263 | ||
264 | ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Client id is not in the list"); | 264 | ck_assert_msg(client_in_list(list, length, public_key) >= 0, "Client id is not in the list"); |
265 | 265 | ||
266 | int inlist_id1 = client_in_list(list, length, test_id1) >= 0; | 266 | bool inlist_id1 = client_in_list(list, length, test_id1) >= 0; |
267 | int inlist_id2 = client_in_list(list, length, test_id2) >= 0; | 267 | bool inlist_id2 = client_in_list(list, length, test_id2) >= 0; |
268 | int inlist_id3 = client_in_list(list, length, test_id3) >= 0; | 268 | bool inlist_id3 = client_in_list(list, length, test_id3) >= 0; |
269 | 269 | ||
270 | ck_assert_msg(inlist_id1 + inlist_id2 + inlist_id3 == 2, "Wrong client removed"); | 270 | ck_assert_msg(inlist_id1 + inlist_id2 + inlist_id3 == 2, "Wrong client removed"); |
271 | 271 | ||
@@ -337,7 +337,7 @@ static void test_addto_lists(IP ip) | |||
337 | ip_port.ip = ip; | 337 | ip_port.ip = ip; |
338 | ip_port.port = TOX_PORT_DEFAULT; | 338 | ip_port.port = TOX_PORT_DEFAULT; |
339 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 339 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
340 | int i, used; | 340 | uint16_t i, used; |
341 | 341 | ||
342 | // check lists filling | 342 | // check lists filling |
343 | for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { | 343 | for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { |
@@ -426,11 +426,11 @@ static void print_pk(uint8_t *public_key) | |||
426 | } | 426 | } |
427 | 427 | ||
428 | static void test_add_to_list(uint8_t cmp_list[][CRYPTO_PUBLIC_KEY_SIZE + 1], | 428 | static void test_add_to_list(uint8_t cmp_list[][CRYPTO_PUBLIC_KEY_SIZE + 1], |
429 | unsigned int length, const uint8_t *pk, | 429 | uint16_t length, const uint8_t *pk, |
430 | const uint8_t *cmp_pk) | 430 | const uint8_t *cmp_pk) |
431 | { | 431 | { |
432 | uint8_t p_b[CRYPTO_PUBLIC_KEY_SIZE]; | 432 | uint8_t p_b[CRYPTO_PUBLIC_KEY_SIZE]; |
433 | unsigned int i; | 433 | uint16_t i; |
434 | 434 | ||
435 | for (i = 0; i < length; ++i) { | 435 | for (i = 0; i < length; ++i) { |
436 | if (!cmp_list[i][CRYPTO_PUBLIC_KEY_SIZE]) { | 436 | if (!cmp_list[i][CRYPTO_PUBLIC_KEY_SIZE]) { |
@@ -465,7 +465,7 @@ static void test_list_main(void) | |||
465 | uint8_t cmp_list1[NUM_DHT][MAX_FRIEND_CLIENTS][CRYPTO_PUBLIC_KEY_SIZE + 1]; | 465 | uint8_t cmp_list1[NUM_DHT][MAX_FRIEND_CLIENTS][CRYPTO_PUBLIC_KEY_SIZE + 1]; |
466 | memset(cmp_list1, 0, sizeof(cmp_list1)); | 466 | memset(cmp_list1, 0, sizeof(cmp_list1)); |
467 | 467 | ||
468 | unsigned int i, j, k, l; | 468 | uint16_t i, j, k, l; |
469 | 469 | ||
470 | for (i = 0; i < NUM_DHT; ++i) { | 470 | for (i = 0; i < NUM_DHT; ++i) { |
471 | IP ip; | 471 | IP ip; |
@@ -481,14 +481,14 @@ static void test_list_main(void) | |||
481 | "Bound to wrong port: %d", net_port(dhts[i]->net)); | 481 | "Bound to wrong port: %d", net_port(dhts[i]->net)); |
482 | } | 482 | } |
483 | 483 | ||
484 | for (j = 0; j < NUM_DHT; ++j) { | 484 | for (i = 0; i < NUM_DHT; ++i) { |
485 | for (i = 1; i < NUM_DHT; ++i) { | 485 | for (j = 1; j < NUM_DHT; ++j) { |
486 | test_add_to_list(cmp_list1[j], MAX_FRIEND_CLIENTS, dhts[(i + j) % NUM_DHT]->self_public_key, dhts[j]->self_public_key); | 486 | test_add_to_list(cmp_list1[i], MAX_FRIEND_CLIENTS, dhts[(i + j) % NUM_DHT]->self_public_key, dhts[i]->self_public_key); |
487 | } | 487 | } |
488 | } | 488 | } |
489 | 489 | ||
490 | for (j = 0; j < NUM_DHT; ++j) { | 490 | for (i = 0; i < NUM_DHT; ++i) { |
491 | for (i = 0; i < NUM_DHT; ++i) { | 491 | for (j = 0; j < NUM_DHT; ++j) { |
492 | if (i == j) { | 492 | if (i == j) { |
493 | continue; | 493 | continue; |
494 | } | 494 | } |
@@ -498,7 +498,7 @@ static void test_list_main(void) | |||
498 | ip_port.ip.ip.v4.uint32 = random_u32(); | 498 | ip_port.ip.ip.v4.uint32 = random_u32(); |
499 | ip_port.port = random_u32() % (UINT16_MAX - 1); | 499 | ip_port.port = random_u32() % (UINT16_MAX - 1); |
500 | ++ip_port.port; | 500 | ++ip_port.port; |
501 | addto_lists(dhts[j], ip_port, dhts[i]->self_public_key); | 501 | addto_lists(dhts[i], ip_port, dhts[j]->self_public_key); |
502 | } | 502 | } |
503 | } | 503 | } |
504 | 504 | ||
@@ -512,7 +512,7 @@ static void test_list_main(void) | |||
512 | } | 512 | } |
513 | 513 | ||
514 | #endif | 514 | #endif |
515 | unsigned int m_count = 0; | 515 | uint16_t m_count = 0; |
516 | 516 | ||
517 | for (l = 0; l < NUM_DHT; ++l) { | 517 | for (l = 0; l < NUM_DHT; ++l) { |
518 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { | 518 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { |
@@ -521,7 +521,7 @@ static void test_list_main(void) | |||
521 | continue; | 521 | continue; |
522 | } | 522 | } |
523 | 523 | ||
524 | unsigned int count = 0; | 524 | uint16_t count = 0; |
525 | 525 | ||
526 | for (k = 0; k < LCLIENT_LIST; ++k) { | 526 | for (k = 0; k < LCLIENT_LIST; ++k) { |
527 | if (memcmp(dhts[l]->self_public_key, dhts[(l + j) % NUM_DHT]->close_clientlist[k].public_key, | 527 | if (memcmp(dhts[l]->self_public_key, dhts[(l + j) % NUM_DHT]->close_clientlist[k].public_key, |
@@ -550,7 +550,7 @@ static void test_list_main(void) | |||
550 | ck_assert_msg(count == 1, "Nodes in search don't know ip of friend. %u %u %u", i, j, count); | 550 | ck_assert_msg(count == 1, "Nodes in search don't know ip of friend. %u %u %u", i, j, count); |
551 | 551 | ||
552 | Node_format ln[MAX_SENT_NODES]; | 552 | Node_format ln[MAX_SENT_NODES]; |
553 | int n = get_close_nodes(dhts[(l + j) % NUM_DHT], dhts[l]->self_public_key, ln, net_family_unspec, 1, 0); | 553 | uint16_t n = get_close_nodes(dhts[(l + j) % NUM_DHT], dhts[l]->self_public_key, ln, net_family_unspec, 1, 0); |
554 | ck_assert_msg(n == MAX_SENT_NODES, "bad num close %u | %u %u", n, i, j); | 554 | ck_assert_msg(n == MAX_SENT_NODES, "bad num close %u | %u %u", n, i, j); |
555 | 555 | ||
556 | count = 0; | 556 | count = 0; |
@@ -589,7 +589,7 @@ static void test_list_main(void) | |||
589 | 589 | ||
590 | START_TEST(test_list) | 590 | START_TEST(test_list) |
591 | { | 591 | { |
592 | unsigned int i; | 592 | uint8_t i; |
593 | 593 | ||
594 | for (i = 0; i < 10; ++i) { | 594 | for (i = 0; i < 10; ++i) { |
595 | test_list_main(); | 595 | test_list_main(); |
@@ -610,7 +610,7 @@ START_TEST(test_DHT_test) | |||
610 | Logger *logs[NUM_DHT]; | 610 | Logger *logs[NUM_DHT]; |
611 | uint32_t index[NUM_DHT]; | 611 | uint32_t index[NUM_DHT]; |
612 | 612 | ||
613 | unsigned int i, j; | 613 | uint32_t i, j; |
614 | 614 | ||
615 | for (i = 0; i < NUM_DHT; ++i) { | 615 | for (i = 0; i < NUM_DHT; ++i) { |
616 | IP ip; | 616 | IP ip; |
@@ -631,6 +631,7 @@ START_TEST(test_DHT_test) | |||
631 | } pairs[NUM_DHT_FRIENDS]; | 631 | } pairs[NUM_DHT_FRIENDS]; |
632 | 632 | ||
633 | for (i = 0; i < NUM_DHT_FRIENDS; ++i) { | 633 | for (i = 0; i < NUM_DHT_FRIENDS; ++i) { |
634 | //TODO: Hugbubby say goto bad >:( | ||
634 | loop_top: | 635 | loop_top: |
635 | pairs[i].tox1 = random_u32() % NUM_DHT; | 636 | pairs[i].tox1 = random_u32() % NUM_DHT; |
636 | pairs[i].tox2 = (pairs[i].tox1 + (random_u32() % (NUM_DHT - 1)) + 1) % NUM_DHT; | 637 | pairs[i].tox2 = (pairs[i].tox1 + (random_u32() % (NUM_DHT - 1)) + 1) % NUM_DHT; |
@@ -694,7 +695,7 @@ START_TEST(test_dht_create_packet) | |||
694 | uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]; | 695 | uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]; |
695 | new_symmetric_key(key); | 696 | new_symmetric_key(key); |
696 | 697 | ||
697 | int length = dht_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt); | 698 | uint16_t length = dht_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt); |
698 | 699 | ||
699 | ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet."); | 700 | ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet."); |
700 | ck_assert_msg(memcmp(pkt + 1, key, CRYPTO_SYMMETRIC_KEY_SIZE) == 0, "Malformed packet."); | 701 | ck_assert_msg(memcmp(pkt + 1, key, CRYPTO_SYMMETRIC_KEY_SIZE) == 0, "Malformed packet."); |
@@ -709,14 +710,14 @@ END_TEST | |||
709 | 710 | ||
710 | static void dht_pack_unpack(const Node_format *nodes, size_t size, uint8_t *data, size_t length) | 711 | static void dht_pack_unpack(const Node_format *nodes, size_t size, uint8_t *data, size_t length) |
711 | { | 712 | { |
712 | int packed_size = pack_nodes(data, length, nodes, size); | 713 | uint16_t packed_size = pack_nodes(data, length, nodes, size); |
713 | ck_assert_msg(packed_size != -1, "Wrong pack_nodes result"); | 714 | ck_assert_msg(packed_size != -1, "Wrong pack_nodes result"); |
714 | 715 | ||
715 | uint16_t processed = 0; | 716 | uint16_t processed = 0; |
716 | VLA(Node_format, nodes_unpacked, size); | 717 | VLA(Node_format, nodes_unpacked, size); |
717 | const uint8_t tcp_enabled = 1; | 718 | const uint8_t tcp_enabled = 1; |
718 | 719 | ||
719 | int unpacked_count = unpack_nodes(nodes_unpacked, size, &processed, data, length, tcp_enabled); | 720 | uint16_t unpacked_count = unpack_nodes(nodes_unpacked, size, &processed, data, length, tcp_enabled); |
720 | ck_assert_msg(unpacked_count == size, "Wrong unpack_nodes result"); | 721 | ck_assert_msg(unpacked_count == size, "Wrong unpack_nodes result"); |
721 | ck_assert_msg(processed == packed_size, "unpack_nodes did not process all data"); | 722 | ck_assert_msg(processed == packed_size, "unpack_nodes did not process all data"); |
722 | 723 | ||
@@ -822,7 +823,7 @@ int main(void) | |||
822 | Suite *dht = dht_suite(); | 823 | Suite *dht = dht_suite(); |
823 | SRunner *test_runner = srunner_create(dht); | 824 | SRunner *test_runner = srunner_create(dht); |
824 | 825 | ||
825 | int number_failed = 0; | 826 | uint8_t number_failed = 0; |
826 | //srunner_set_fork_status(test_runner, CK_NOFORK); | 827 | //srunner_set_fork_status(test_runner, CK_NOFORK); |
827 | srunner_run_all(test_runner, CK_NORMAL); | 828 | srunner_run_all(test_runner, CK_NORMAL); |
828 | number_failed = srunner_ntests_failed(test_runner); | 829 | number_failed = srunner_ntests_failed(test_runner); |