diff options
author | irungentoo <irungentoo@gmail.com> | 2015-05-22 18:23:56 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-05-22 18:23:56 -0400 |
commit | 8e80ced6cea5c50e628c1931f6b3b764b97efb41 (patch) | |
tree | 43d8aaf1500bee9abdbd11be5175990a98414d3b /auto_tests | |
parent | 2ba076ac5cc6efb5eb41fb4aa6a77a151885f26c (diff) |
Move savedata to options struct.
Add a way to select the type of savedata (normal savedata, load a
secret key, potentially others?) to load.
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/encryptsave_test.c | 20 | ||||
-rw-r--r-- | auto_tests/tox_test.c | 25 | ||||
-rw-r--r-- | auto_tests/toxav_basic_test.c | 6 | ||||
-rw-r--r-- | auto_tests/toxav_many_test.c | 10 |
4 files changed, 38 insertions, 23 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index a239bcee..b0828964 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -55,8 +55,8 @@ END_TEST | |||
55 | 55 | ||
56 | START_TEST(test_save_friend) | 56 | START_TEST(test_save_friend) |
57 | { | 57 | { |
58 | Tox *tox1 = tox_new(0, 0, 0, 0); | 58 | Tox *tox1 = tox_new(0, 0); |
59 | Tox *tox2 = tox_new(0, 0, 0, 0); | 59 | Tox *tox2 = tox_new(0, 0); |
60 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); | 60 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); |
61 | uint32_t to_compare = 974536; | 61 | uint32_t to_compare = 974536; |
62 | tox_callback_friend_request(tox2, accept_friend_request, &to_compare); | 62 | tox_callback_friend_request(tox2, accept_friend_request, &to_compare); |
@@ -75,15 +75,23 @@ START_TEST(test_save_friend) | |||
75 | ck_assert_msg(ret, "failed to encrypted save: %u", error1); | 75 | ck_assert_msg(ret, "failed to encrypted save: %u", error1); |
76 | ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); | 76 | ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); |
77 | 77 | ||
78 | struct Tox_Options options; | ||
79 | tox_options_default(&options); | ||
80 | options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; | ||
81 | options.savedata_data = enc_data; | ||
82 | options.savedata_length = size2; | ||
83 | |||
78 | TOX_ERR_NEW err2; | 84 | TOX_ERR_NEW err2; |
79 | Tox *tox3 = tox_new(0, enc_data, size2, &err2); | 85 | Tox *tox3 = tox_new(&options, &err2); |
80 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, | 86 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, |
81 | TOX_ERR_NEW_LOAD_ENCRYPTED); | 87 | TOX_ERR_NEW_LOAD_ENCRYPTED); |
82 | uint8_t dec_data[size]; | 88 | uint8_t dec_data[size]; |
83 | TOX_ERR_DECRYPTION err3; | 89 | TOX_ERR_DECRYPTION err3; |
84 | ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); | 90 | ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); |
85 | ck_assert_msg(ret, "failed to decrypt save: %u", err3); | 91 | ck_assert_msg(ret, "failed to decrypt save: %u", err3); |
86 | tox3 = tox_new(0, dec_data, size, &err2); | 92 | options.savedata_data = dec_data; |
93 | options.savedata_length = size; | ||
94 | tox3 = tox_new(&options, &err2); | ||
87 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); | 95 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); |
88 | uint8_t address2[TOX_PUBLIC_KEY_SIZE]; | 96 | uint8_t address2[TOX_PUBLIC_KEY_SIZE]; |
89 | ret = tox_friend_get_public_key(tox3, 0, address2, 0); | 97 | ret = tox_friend_get_public_key(tox3, 0, address2, 0); |
@@ -111,7 +119,9 @@ START_TEST(test_save_friend) | |||
111 | 119 | ||
112 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste | 120 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste |
113 | // to remove the manual check now that it's there) | 121 | // to remove the manual check now that it's there) |
114 | Tox *tox4 = tox_new(0, out1, size, &err2); | 122 | options.savedata_data = out1; |
123 | options.savedata_length = size; | ||
124 | Tox *tox4 = tox_new(&options, &err2); | ||
115 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third"); | 125 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third"); |
116 | uint8_t address5[TOX_PUBLIC_KEY_SIZE]; | 126 | uint8_t address5[TOX_PUBLIC_KEY_SIZE]; |
117 | ret = tox_friend_get_public_key(tox4, 0, address5, 0); | 127 | ret = tox_friend_get_public_key(tox4, 0, address5, 0); |
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 40022b0a..22528330 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -286,8 +286,8 @@ void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *use | |||
286 | 286 | ||
287 | START_TEST(test_one) | 287 | START_TEST(test_one) |
288 | { | 288 | { |
289 | Tox *tox1 = tox_new(0, 0, 0, 0); | 289 | Tox *tox1 = tox_new(0, 0); |
290 | Tox *tox2 = tox_new(0, 0, 0, 0); | 290 | Tox *tox2 = tox_new(0, 0); |
291 | 291 | ||
292 | { | 292 | { |
293 | TOX_ERR_GET_PORT error; | 293 | TOX_ERR_GET_PORT error; |
@@ -340,7 +340,12 @@ START_TEST(test_one) | |||
340 | tox_kill(tox2); | 340 | tox_kill(tox2); |
341 | TOX_ERR_NEW err_n; | 341 | TOX_ERR_NEW err_n; |
342 | 342 | ||
343 | tox2 = tox_new(0, data, save_size, &err_n); | 343 | struct Tox_Options options; |
344 | tox_options_default(&options); | ||
345 | options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; | ||
346 | options.savedata_data = data; | ||
347 | options.savedata_length = save_size; | ||
348 | tox2 = tox_new(&options, &err_n); | ||
344 | ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); | 349 | ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); |
345 | 350 | ||
346 | ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); | 351 | ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); |
@@ -361,11 +366,11 @@ START_TEST(test_few_clients) | |||
361 | { | 366 | { |
362 | long long unsigned int con_time, cur_time = time(NULL); | 367 | long long unsigned int con_time, cur_time = time(NULL); |
363 | TOX_ERR_NEW t_n_error; | 368 | TOX_ERR_NEW t_n_error; |
364 | Tox *tox1 = tox_new(0, 0, 0, &t_n_error); | 369 | Tox *tox1 = tox_new(0, &t_n_error); |
365 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); | 370 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); |
366 | Tox *tox2 = tox_new(0, 0, 0, &t_n_error); | 371 | Tox *tox2 = tox_new(0, &t_n_error); |
367 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); | 372 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); |
368 | Tox *tox3 = tox_new(0, 0, 0, &t_n_error); | 373 | Tox *tox3 = tox_new(0, &t_n_error); |
369 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); | 374 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); |
370 | 375 | ||
371 | ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances"); | 376 | ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances"); |
@@ -745,7 +750,7 @@ START_TEST(test_many_clients) | |||
745 | uint32_t to_comp = 974536; | 750 | uint32_t to_comp = 974536; |
746 | 751 | ||
747 | for (i = 0; i < NUM_TOXES; ++i) { | 752 | for (i = 0; i < NUM_TOXES; ++i) { |
748 | toxes[i] = tox_new(0, 0, 0, 0); | 753 | toxes[i] = tox_new(0, 0); |
749 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 754 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
750 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); | 755 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); |
751 | } | 756 | } |
@@ -832,7 +837,7 @@ START_TEST(test_many_clients_tcp) | |||
832 | opts.udp_enabled = 0; | 837 | opts.udp_enabled = 0; |
833 | } | 838 | } |
834 | 839 | ||
835 | toxes[i] = tox_new(&opts, 0, 0, 0); | 840 | toxes[i] = tox_new(&opts, 0); |
836 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 841 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
837 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); | 842 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); |
838 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; | 843 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; |
@@ -926,7 +931,7 @@ START_TEST(test_many_clients_tcp_b) | |||
926 | opts.udp_enabled = 0; | 931 | opts.udp_enabled = 0; |
927 | } | 932 | } |
928 | 933 | ||
929 | toxes[i] = tox_new(&opts, 0, 0, 0); | 934 | toxes[i] = tox_new(&opts, 0); |
930 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 935 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
931 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); | 936 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); |
932 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; | 937 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; |
@@ -1062,7 +1067,7 @@ START_TEST(test_many_group) | |||
1062 | uint32_t to_comp = 234212; | 1067 | uint32_t to_comp = 234212; |
1063 | 1068 | ||
1064 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | 1069 | for (i = 0; i < NUM_GROUP_TOX; ++i) { |
1065 | toxes[i] = tox_new(0, 0, 0, 0); | 1070 | toxes[i] = tox_new(0, 0); |
1066 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 1071 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
1067 | tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); | 1072 | tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); |
1068 | tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); | 1073 | tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); |
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index a43b7c2f..af8d91e9 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -250,9 +250,9 @@ if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) | |||
250 | START_TEST(test_AV_flows) | 250 | START_TEST(test_AV_flows) |
251 | { | 251 | { |
252 | long long unsigned int cur_time = time(NULL); | 252 | long long unsigned int cur_time = time(NULL); |
253 | Tox *bootstrap_node = tox_new(0, 0, 0, 0); | 253 | Tox *bootstrap_node = tox_new(0, 0); |
254 | Tox *Alice = tox_new(0, 0, 0, 0); | 254 | Tox *Alice = tox_new(0, 0); |
255 | Tox *Bob = tox_new(0, 0, 0, 0); | 255 | Tox *Bob = tox_new(0, 0); |
256 | 256 | ||
257 | ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances"); | 257 | ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances"); |
258 | 258 | ||
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 4287118f..6017e526 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -264,12 +264,12 @@ START_TEST(test_AV_three_calls) | |||
264 | // void test_AV_three_calls() | 264 | // void test_AV_three_calls() |
265 | { | 265 | { |
266 | long long unsigned int cur_time = time(NULL); | 266 | long long unsigned int cur_time = time(NULL); |
267 | Tox *bootstrap_node = tox_new(0, 0, 0, 0); | 267 | Tox *bootstrap_node = tox_new(0, 0); |
268 | Tox *caller = tox_new(0, 0, 0, 0); | 268 | Tox *caller = tox_new(0, 0); |
269 | Tox *callees[3] = { | 269 | Tox *callees[3] = { |
270 | tox_new(0, 0, 0, 0), | 270 | tox_new(0, 0), |
271 | tox_new(0, 0, 0, 0), | 271 | tox_new(0, 0), |
272 | tox_new(0, 0, 0, 0), | 272 | tox_new(0, 0), |
273 | }; | 273 | }; |
274 | 274 | ||
275 | 275 | ||