Skip to content

Commit f276b39

Browse files
committed
test: Add some more asserts for I/O and alloc to succeed.
Silences some warnings from static analysis.
1 parent edb4dfc commit f276b39

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

auto_tests/file_saving_test.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
#include <stdlib.h>
1414
#include <string.h>
1515

16-
#include "../testing/misc_tools.h"
17-
#include "../toxcore/ccompat.h"
1816
#include "auto_test_support.h"
1917
#include "check_compat.h"
2018

19+
#include "../toxcore/ccompat.h"
20+
#include "../toxcore/tox.h"
2121
#include "../toxencryptsave/toxencryptsave.h"
2222

2323
static const char *pphrase = "bar";
@@ -27,21 +27,26 @@ static const char *savefile = "./save";
2727
static void save_data_encrypted(void)
2828
{
2929
struct Tox_Options *options = tox_options_new(nullptr);
30+
ck_assert(options != nullptr);
3031
Tox *t = tox_new_log(options, nullptr, nullptr);
32+
ck_assert(t != nullptr);
3133
tox_options_free(options);
3234

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

3537
FILE *f = fopen(savefile, "wb");
38+
ck_assert(f != nullptr);
3639

3740
size_t size = tox_get_savedata_size(t);
3841
uint8_t *clear = (uint8_t *)malloc(size);
42+
ck_assert(clear != nullptr);
3943

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

4347
size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
4448
uint8_t *cipher = (uint8_t *)malloc(size);
49+
ck_assert(cipher != nullptr);
4550

4651
Tox_Err_Encryption eerr;
4752

@@ -78,7 +83,7 @@ static void load_data_decrypted(void)
7883
Tox_Err_Decryption derr;
7984

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

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

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

94100
tox_options_free(options);
95101

96-
ck_assert_msg(t != nullptr, "tox_new returned the error value %d", err);
97-
98102
uint8_t *readname = (uint8_t *)malloc(tox_self_get_name_size(t));
99103
ck_assert(readname != nullptr);
100104
tox_self_get_name(t, readname);

0 commit comments

Comments
 (0)