Skip to content

Commit

Permalink
test: Add some more asserts for I/O and alloc to succeed.
Browse files Browse the repository at this point in the history
Silences some warnings from static analysis.
  • Loading branch information
iphydf committed Jan 19, 2025
1 parent edb4dfc commit f276b39
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions auto_tests/file_saving_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include <stdlib.h>
#include <string.h>

#include "../testing/misc_tools.h"
#include "../toxcore/ccompat.h"
#include "auto_test_support.h"
#include "check_compat.h"

#include "../toxcore/ccompat.h"
#include "../toxcore/tox.h"
#include "../toxencryptsave/toxencryptsave.h"

static const char *pphrase = "bar";
Expand All @@ -27,21 +27,26 @@ static const char *savefile = "./save";
static void save_data_encrypted(void)
{
struct Tox_Options *options = tox_options_new(nullptr);
ck_assert(options != nullptr);
Tox *t = tox_new_log(options, nullptr, nullptr);
ck_assert(t != nullptr);
tox_options_free(options);

tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr);

FILE *f = fopen(savefile, "wb");
ck_assert(f != nullptr);

size_t size = tox_get_savedata_size(t);
uint8_t *clear = (uint8_t *)malloc(size);
ck_assert(clear != nullptr);

/*this function does not write any data at all*/
tox_get_savedata(t, clear);

size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
uint8_t *cipher = (uint8_t *)malloc(size);
ck_assert(cipher != nullptr);

Tox_Err_Encryption eerr;

Expand Down Expand Up @@ -78,7 +83,7 @@ static void load_data_decrypted(void)
Tox_Err_Decryption derr;

ck_assert_msg(tox_pass_decrypt(cipher, size, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr),
"Could not decrypt, error code %d.", derr);
"Could not decrypt, error code %s.", tox_err_decryption_to_string(derr));

struct Tox_Options *options = tox_options_new(nullptr);
ck_assert(options != nullptr);
Expand All @@ -90,11 +95,10 @@ static void load_data_decrypted(void)
Tox_Err_New err;

Tox *t = tox_new_log(options, &err, nullptr);
ck_assert_msg(t != nullptr, "tox_new returned the error value %s", tox_err_new_to_string(err));

tox_options_free(options);

ck_assert_msg(t != nullptr, "tox_new returned the error value %d", err);

uint8_t *readname = (uint8_t *)malloc(tox_self_get_name_size(t));
ck_assert(readname != nullptr);
tox_self_get_name(t, readname);
Expand Down

0 comments on commit f276b39

Please sign in to comment.