From 8e80ced6cea5c50e628c1931f6b3b764b97efb41 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 22 May 2015 18:23:56 -0400 Subject: Move savedata to options struct. Add a way to select the type of savedata (normal savedata, load a secret key, potentially others?) to load. --- auto_tests/encryptsave_test.c | 20 +++++++++++++++----- auto_tests/tox_test.c | 25 +++++++++++++++---------- auto_tests/toxav_basic_test.c | 6 +++--- auto_tests/toxav_many_test.c | 10 +++++----- 4 files changed, 38 insertions(+), 23 deletions(-) (limited to 'auto_tests') 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 START_TEST(test_save_friend) { - Tox *tox1 = tox_new(0, 0, 0, 0); - Tox *tox2 = tox_new(0, 0, 0, 0); + Tox *tox1 = tox_new(0, 0); + Tox *tox2 = tox_new(0, 0); ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); uint32_t to_compare = 974536; tox_callback_friend_request(tox2, accept_friend_request, &to_compare); @@ -75,15 +75,23 @@ START_TEST(test_save_friend) ck_assert_msg(ret, "failed to encrypted save: %u", error1); ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); + struct Tox_Options options; + tox_options_default(&options); + options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; + options.savedata_data = enc_data; + options.savedata_length = size2; + TOX_ERR_NEW err2; - Tox *tox3 = tox_new(0, enc_data, size2, &err2); + Tox *tox3 = tox_new(&options, &err2); ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, TOX_ERR_NEW_LOAD_ENCRYPTED); uint8_t dec_data[size]; TOX_ERR_DECRYPTION err3; ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); ck_assert_msg(ret, "failed to decrypt save: %u", err3); - tox3 = tox_new(0, dec_data, size, &err2); + options.savedata_data = dec_data; + options.savedata_length = size; + tox3 = tox_new(&options, &err2); ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); uint8_t address2[TOX_PUBLIC_KEY_SIZE]; ret = tox_friend_get_public_key(tox3, 0, address2, 0); @@ -111,7 +119,9 @@ START_TEST(test_save_friend) // and now with the code in use (I only bothered with manually to debug this, and it seems a waste // to remove the manual check now that it's there) - Tox *tox4 = tox_new(0, out1, size, &err2); + options.savedata_data = out1; + options.savedata_length = size; + Tox *tox4 = tox_new(&options, &err2); ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third"); uint8_t address5[TOX_PUBLIC_KEY_SIZE]; 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 START_TEST(test_one) { - Tox *tox1 = tox_new(0, 0, 0, 0); - Tox *tox2 = tox_new(0, 0, 0, 0); + Tox *tox1 = tox_new(0, 0); + Tox *tox2 = tox_new(0, 0); { TOX_ERR_GET_PORT error; @@ -340,7 +340,12 @@ START_TEST(test_one) tox_kill(tox2); TOX_ERR_NEW err_n; - tox2 = tox_new(0, data, save_size, &err_n); + struct Tox_Options options; + tox_options_default(&options); + options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; + options.savedata_data = data; + options.savedata_length = save_size; + tox2 = tox_new(&options, &err_n); ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); @@ -361,11 +366,11 @@ START_TEST(test_few_clients) { long long unsigned int con_time, cur_time = time(NULL); TOX_ERR_NEW t_n_error; - Tox *tox1 = tox_new(0, 0, 0, &t_n_error); + Tox *tox1 = tox_new(0, &t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); - Tox *tox2 = tox_new(0, 0, 0, &t_n_error); + Tox *tox2 = tox_new(0, &t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); - Tox *tox3 = tox_new(0, 0, 0, &t_n_error); + Tox *tox3 = tox_new(0, &t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances"); @@ -745,7 +750,7 @@ START_TEST(test_many_clients) uint32_t to_comp = 974536; for (i = 0; i < NUM_TOXES; ++i) { - toxes[i] = tox_new(0, 0, 0, 0); + toxes[i] = tox_new(0, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); } @@ -832,7 +837,7 @@ START_TEST(test_many_clients_tcp) opts.udp_enabled = 0; } - toxes[i] = tox_new(&opts, 0, 0, 0); + toxes[i] = tox_new(&opts, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; @@ -926,7 +931,7 @@ START_TEST(test_many_clients_tcp_b) opts.udp_enabled = 0; } - toxes[i] = tox_new(&opts, 0, 0, 0); + toxes[i] = tox_new(&opts, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; @@ -1062,7 +1067,7 @@ START_TEST(test_many_group) uint32_t to_comp = 234212; for (i = 0; i < NUM_GROUP_TOX; ++i) { - toxes[i] = tox_new(0, 0, 0, 0); + toxes[i] = tox_new(0, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); 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) START_TEST(test_AV_flows) { long long unsigned int cur_time = time(NULL); - Tox *bootstrap_node = tox_new(0, 0, 0, 0); - Tox *Alice = tox_new(0, 0, 0, 0); - Tox *Bob = tox_new(0, 0, 0, 0); + Tox *bootstrap_node = tox_new(0, 0); + Tox *Alice = tox_new(0, 0); + Tox *Bob = tox_new(0, 0); ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances"); 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) // void test_AV_three_calls() { long long unsigned int cur_time = time(NULL); - Tox *bootstrap_node = tox_new(0, 0, 0, 0); - Tox *caller = tox_new(0, 0, 0, 0); + Tox *bootstrap_node = tox_new(0, 0); + Tox *caller = tox_new(0, 0); Tox *callees[3] = { - tox_new(0, 0, 0, 0), - tox_new(0, 0, 0, 0), - tox_new(0, 0, 0, 0), + tox_new(0, 0), + tox_new(0, 0), + tox_new(0, 0), }; -- cgit v1.2.3