summaryrefslogtreecommitdiff
path: root/auto_tests/encryptsave_test.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-05-22 18:23:56 -0400
committerirungentoo <irungentoo@gmail.com>2015-05-22 18:23:56 -0400
commit8e80ced6cea5c50e628c1931f6b3b764b97efb41 (patch)
tree43d8aaf1500bee9abdbd11be5175990a98414d3b /auto_tests/encryptsave_test.c
parent2ba076ac5cc6efb5eb41fb4aa6a77a151885f26c (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/encryptsave_test.c')
-rw-r--r--auto_tests/encryptsave_test.c20
1 files changed, 15 insertions, 5 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
56START_TEST(test_save_friend) 56START_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);