summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2017-01-20 21:16:55 +0000
committeriphydf <iphydf@users.noreply.github.com>2017-01-28 20:49:12 +0000
commit6ae33c16cf9e37fda85d70c78b3c2779eb8ca21a (patch)
tree99c3a8c26e02039b515bb6f57d2797d1cdf77c1d /auto_tests
parent895de7ef26e7617769f2271345e414545c2581f8 (diff)
Add VLA compatibility macro for C89-ish compilers.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/TCP_test.c6
-rw-r--r--auto_tests/encryptsave_test.c14
-rw-r--r--auto_tests/messenger_test.c10
-rw-r--r--auto_tests/save_friend_test.c7
-rw-r--r--auto_tests/tox_one_test.c3
-rw-r--r--auto_tests/tox_test.c9
6 files changed, 27 insertions, 22 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index a1de4874..a5a70c4b 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -188,19 +188,19 @@ static void kill_TCP_con(struct sec_TCP_con *con)
188 188
189static int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length) 189static int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length)
190{ 190{
191 uint8_t packet[sizeof(uint16_t) + length + CRYPTO_MAC_SIZE]; 191 VLA(uint8_t, packet, sizeof(uint16_t) + length + CRYPTO_MAC_SIZE);
192 192
193 uint16_t c_length = htons(length + CRYPTO_MAC_SIZE); 193 uint16_t c_length = htons(length + CRYPTO_MAC_SIZE);
194 memcpy(packet, &c_length, sizeof(uint16_t)); 194 memcpy(packet, &c_length, sizeof(uint16_t));
195 int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t)); 195 int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t));
196 196
197 if ((unsigned int)len != (sizeof(packet) - sizeof(uint16_t))) { 197 if ((unsigned int)len != (SIZEOF_VLA(packet) - sizeof(uint16_t))) {
198 return -1; 198 return -1;
199 } 199 }
200 200
201 increment_nonce(con->sent_nonce); 201 increment_nonce(con->sent_nonce);
202 202
203 ck_assert_msg(send(con->sock, (const char *)packet, sizeof(packet), 0) == sizeof(packet), "send failed"); 203 ck_assert_msg(send(con->sock, (const char *)packet, SIZEOF_VLA(packet), 0) == SIZEOF_VLA(packet), "send failed");
204 return 0; 204 return 0;
205} 205}
206 206
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c
index 22c585ed..749767a0 100644
--- a/auto_tests/encryptsave_test.c
+++ b/auto_tests/encryptsave_test.c
@@ -13,6 +13,7 @@
13 13
14#include "../toxcore/tox.h" 14#include "../toxcore/tox.h"
15 15
16#include "../toxcore/ccompat.h"
16#include "../toxcore/crypto_core.h" 17#include "../toxcore/crypto_core.h"
17#include "../toxencryptsave/toxencryptsave.h" 18#include "../toxencryptsave/toxencryptsave.h"
18#ifdef VANILLA_NACL 19#ifdef VANILLA_NACL
@@ -68,10 +69,10 @@ START_TEST(test_save_friend)
68 ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); 69 ck_assert_msg(test != UINT32_MAX, "Failed to add friend");
69 70
70 size_t size = tox_get_savedata_size(tox1); 71 size_t size = tox_get_savedata_size(tox1);
71 uint8_t data[size]; 72 VLA(uint8_t, data, size);
72 tox_get_savedata(tox1, data); 73 tox_get_savedata(tox1, data);
73 size_t size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 74 size_t size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
74 uint8_t enc_data[size2]; 75 VLA(uint8_t, enc_data, size2);
75 TOX_ERR_ENCRYPTION error1; 76 TOX_ERR_ENCRYPTION error1;
76 bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1); 77 bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1);
77 ck_assert_msg(ret, "failed to encrypted save: %u", error1); 78 ck_assert_msg(ret, "failed to encrypted save: %u", error1);
@@ -86,7 +87,7 @@ START_TEST(test_save_friend)
86 ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, 87 ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2,
87 TOX_ERR_NEW_LOAD_ENCRYPTED); 88 TOX_ERR_NEW_LOAD_ENCRYPTED);
88 ck_assert_msg(tox3 == NULL, "tox_new with error should return NULL"); 89 ck_assert_msg(tox3 == NULL, "tox_new with error should return NULL");
89 uint8_t dec_data[size]; 90 VLA(uint8_t, dec_data, size);
90 TOX_ERR_DECRYPTION err3; 91 TOX_ERR_DECRYPTION err3;
91 ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3); 92 ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3);
92 ck_assert_msg(ret, "failed to decrypt save: %u", err3); 93 ck_assert_msg(ret, "failed to decrypt save: %u", err3);
@@ -99,19 +100,20 @@ START_TEST(test_save_friend)
99 ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match!"); 100 ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match!");
100 101
101 size = tox_get_savedata_size(tox3); 102 size = tox_get_savedata_size(tox3);
102 uint8_t data2[size]; 103 VLA(uint8_t, data2, size);
103 tox_get_savedata(tox3, data2); 104 tox_get_savedata(tox3, data2);
104 Tox_Pass_Key *key = tox_pass_key_new(); 105 Tox_Pass_Key *key = tox_pass_key_new();
105 ck_assert_msg(key != NULL, "pass key allocation failure"); 106 ck_assert_msg(key != NULL, "pass key allocation failure");
106 memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH); 107 memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH);
107 memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key2, TOX_PASS_KEY_LENGTH); 108 memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key2, TOX_PASS_KEY_LENGTH);
108 size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; 109 size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
109 uint8_t encdata2[size2]; 110 VLA(uint8_t, encdata2, size2);
110 ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1); 111 ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1);
111 ck_assert_msg(ret, "failed to key encrypt %u", error1); 112 ck_assert_msg(ret, "failed to key encrypt %u", error1);
112 ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing"); 113 ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing");
113 114
114 uint8_t out1[size], out2[size]; 115 VLA(uint8_t, out1, size);
116 VLA(uint8_t, out2, size);
115 ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3); 117 ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3);
116 ck_assert_msg(ret, "failed to pw decrypt %u", err3); 118 ck_assert_msg(ret, "failed to pw decrypt %u", err3);
117 ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3); 119 ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3);
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index efe2963a..bd524014 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -184,7 +184,7 @@ START_TEST(test_getself_name)
184{ 184{
185 const char *nickname = "testGallop"; 185 const char *nickname = "testGallop";
186 int len = strlen(nickname); 186 int len = strlen(nickname);
187 char nick_check[len]; 187 VLA(char, nick_check, len);
188 188
189 setname(m, (const uint8_t *)nickname, len); 189 setname(m, (const uint8_t *)nickname, len);
190 getself_name(m, (uint8_t *)nick_check); 190 getself_name(m, (uint8_t *)nick_check);
@@ -237,7 +237,7 @@ START_TEST(test_dht_state_saveloadsave)
237 * d) the second save() is of equal content */ 237 * d) the second save() is of equal content */
238 size_t i, extra = 64; 238 size_t i, extra = 64;
239 size_t size = DHT_size(m->dht); 239 size_t size = DHT_size(m->dht);
240 uint8_t buffer[size + 2 * extra]; 240 VLA(uint8_t, buffer, size + 2 * extra);
241 memset(buffer, 0xCD, extra); 241 memset(buffer, 0xCD, extra);
242 memset(buffer + extra + size, 0xCD, extra); 242 memset(buffer + extra + size, 0xCD, extra);
243 DHT_save(m->dht, buffer + extra); 243 DHT_save(m->dht, buffer + extra);
@@ -263,7 +263,7 @@ START_TEST(test_dht_state_saveloadsave)
263 size_t size2 = DHT_size(m->dht); 263 size_t size2 = DHT_size(m->dht);
264 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2); 264 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
265 265
266 uint8_t buffer2[size2]; 266 VLA(uint8_t, buffer2, size2);
267 DHT_save(m->dht, buffer2); 267 DHT_save(m->dht, buffer2);
268 268
269 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "DHT state changed by store/load/store cycle"); 269 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "DHT state changed by store/load/store cycle");
@@ -279,7 +279,7 @@ START_TEST(test_messenger_state_saveloadsave)
279 * d) the second save() is of equal content */ 279 * d) the second save() is of equal content */
280 size_t i, extra = 64; 280 size_t i, extra = 64;
281 size_t size = messenger_size(m); 281 size_t size = messenger_size(m);
282 uint8_t buffer[size + 2 * extra]; 282 VLA(uint8_t, buffer, size + 2 * extra);
283 memset(buffer, 0xCD, extra); 283 memset(buffer, 0xCD, extra);
284 memset(buffer + extra + size, 0xCD, extra); 284 memset(buffer + extra + size, 0xCD, extra);
285 messenger_save(m, buffer + extra); 285 messenger_save(m, buffer + extra);
@@ -305,7 +305,7 @@ START_TEST(test_messenger_state_saveloadsave)
305 size_t size2 = messenger_size(m); 305 size_t size2 = messenger_size(m);
306 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2); 306 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
307 307
308 uint8_t buffer2[size2]; 308 VLA(uint8_t, buffer2, size2);
309 messenger_save(m, buffer2); 309 messenger_save(m, buffer2);
310 310
311 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "Messenger state changed by store/load/store cycle"); 311 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "Messenger state changed by store/load/store cycle");
diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c
index 448160c0..6d0640c3 100644
--- a/auto_tests/save_friend_test.c
+++ b/auto_tests/save_friend_test.c
@@ -4,6 +4,7 @@
4#define _XOPEN_SOURCE 600 4#define _XOPEN_SOURCE 600
5 5
6#include "helpers.h" 6#include "helpers.h"
7#include "../toxcore/ccompat.h"
7#include "../toxcore/tox.h" 8#include "../toxcore/tox.h"
8 9
9#include <assert.h> 10#include <assert.h>
@@ -28,14 +29,14 @@ struct test_data {
28 29
29static void set_random(Tox *m, bool (*setter)(Tox *, const uint8_t *, size_t, TOX_ERR_SET_INFO *), size_t length) 30static void set_random(Tox *m, bool (*setter)(Tox *, const uint8_t *, size_t, TOX_ERR_SET_INFO *), size_t length)
30{ 31{
31 uint8_t text[length]; 32 VLA(uint8_t, text, length);
32 uint32_t i; 33 uint32_t i;
33 34
34 for (i = 0; i < length; ++i) { 35 for (i = 0; i < length; ++i) {
35 text[i] = rand(); 36 text[i] = rand();
36 } 37 }
37 38
38 setter(m, text, sizeof(text), 0); 39 setter(m, text, SIZEOF_VLA(text), 0);
39} 40}
40 41
41void namechange_callback(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, void *user_data) 42void namechange_callback(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, void *user_data)
@@ -106,7 +107,7 @@ int main(int argc, char *argv[])
106 } 107 }
107 108
108 size_t save_size = tox_get_savedata_size(tox1); 109 size_t save_size = tox_get_savedata_size(tox1);
109 uint8_t savedata[save_size]; 110 VLA(uint8_t, savedata, save_size);
110 tox_get_savedata(tox1, savedata); 111 tox_get_savedata(tox1, savedata);
111 112
112 struct Tox_Options *options = tox_options_new(NULL); 113 struct Tox_Options *options = tox_options_new(NULL);
diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c
index 8726d5c5..ce698486 100644
--- a/auto_tests/tox_one_test.c
+++ b/auto_tests/tox_one_test.c
@@ -9,6 +9,7 @@
9#include <stdlib.h> 9#include <stdlib.h>
10#include <time.h> 10#include <time.h>
11 11
12#include "../toxcore/ccompat.h"
12#include "../toxcore/tox.h" 13#include "../toxcore/tox.h"
13#include "../toxcore/util.h" 14#include "../toxcore/util.h"
14 15
@@ -77,7 +78,7 @@ START_TEST(test_one)
77 78
78 tox_self_get_address(tox1, address); 79 tox_self_get_address(tox1, address);
79 size_t save_size = tox_get_savedata_size(tox1); 80 size_t save_size = tox_get_savedata_size(tox1);
80 uint8_t data[save_size]; 81 VLA(uint8_t, data, save_size);
81 tox_get_savedata(tox1, data); 82 tox_get_savedata(tox1, data);
82 83
83 tox_kill(tox2); 84 tox_kill(tox2);
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index ab2202d1..d9074ac0 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -21,6 +21,7 @@
21#include <stdlib.h> 21#include <stdlib.h>
22#include <time.h> 22#include <time.h>
23 23
24#include "../toxcore/ccompat.h"
24#include "../toxcore/tox.h" 25#include "../toxcore/tox.h"
25#include "../toxcore/util.h" 26#include "../toxcore/util.h"
26 27
@@ -125,7 +126,7 @@ static void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *dat
125 return; 126 return;
126 } 127 }
127 128
128 uint8_t f_data[len]; 129 VLA(uint8_t, f_data, len);
129 memset(f_data, number, len); 130 memset(f_data, number, len);
130 131
131 if (memcmp(f_data, data, len) == 0) { 132 if (memcmp(f_data, data, len) == 0) {
@@ -260,7 +261,7 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
260 } 261 }
261 262
262 TOX_ERR_FILE_SEND_CHUNK error; 263 TOX_ERR_FILE_SEND_CHUNK error;
263 uint8_t f_data[length]; 264 VLA(uint8_t, f_data, length);
264 memset(f_data, sending_num, length); 265 memset(f_data, sending_num, length);
265 266
266 if (tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error)) { 267 if (tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error)) {
@@ -294,7 +295,7 @@ static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uin
294 return; 295 return;
295 } 296 }
296 297
297 uint8_t f_data[length]; 298 VLA(uint8_t, f_data, length);
298 memset(f_data, num, length); 299 memset(f_data, num, length);
299 ++num; 300 ++num;
300 301
@@ -416,7 +417,7 @@ START_TEST(test_few_clients)
416 unsigned int save_size1 = tox_get_savedata_size(tox2); 417 unsigned int save_size1 = tox_get_savedata_size(tox2);
417 ck_assert_msg(save_size1 != 0 && save_size1 < 4096, "save is invalid size %u", save_size1); 418 ck_assert_msg(save_size1 != 0 && save_size1 < 4096, "save is invalid size %u", save_size1);
418 printf("%u\n", save_size1); 419 printf("%u\n", save_size1);
419 uint8_t save1[save_size1]; 420 VLA(uint8_t, save1, save_size1);
420 tox_get_savedata(tox2, save1); 421 tox_get_savedata(tox2, save1);
421 tox_kill(tox2); 422 tox_kill(tox2);
422 423