diff options
Diffstat (limited to 'auto_tests/file_saving_test.c')
-rw-r--r-- | auto_tests/file_saving_test.c | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c index 0f27f1d6..a5ba7e1f 100644 --- a/auto_tests/file_saving_test.c +++ b/auto_tests/file_saving_test.c | |||
@@ -33,6 +33,8 @@ | |||
33 | 33 | ||
34 | #include "../testing/misc_tools.h" | 34 | #include "../testing/misc_tools.h" |
35 | #include "../toxcore/ccompat.h" | 35 | #include "../toxcore/ccompat.h" |
36 | #include "check_compat.h" | ||
37 | |||
36 | #include "../toxencryptsave/toxencryptsave.h" | 38 | #include "../toxencryptsave/toxencryptsave.h" |
37 | 39 | ||
38 | static const char *pphrase = "bar"; | 40 | static const char *pphrase = "bar"; |
@@ -60,11 +62,9 @@ static void save_data_encrypted(void) | |||
60 | 62 | ||
61 | TOX_ERR_ENCRYPTION eerr; | 63 | TOX_ERR_ENCRYPTION eerr; |
62 | 64 | ||
63 | if (!tox_pass_encrypt(clear, size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)pphrase, strlen(pphrase), cipher, | 65 | ck_assert_msg(tox_pass_encrypt(clear, size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)pphrase, |
64 | &eerr)) { | 66 | strlen(pphrase), cipher, |
65 | fprintf(stderr, "error: could not encrypt, error code %d\n", eerr); | 67 | &eerr), "Could not encrypt, error code %d.", eerr); |
66 | exit(4); | ||
67 | } | ||
68 | 68 | ||
69 | size_t written_value = fwrite(cipher, sizeof(*cipher), size, f); | 69 | size_t written_value = fwrite(cipher, sizeof(*cipher), size, f); |
70 | printf("written written_value = %u of %u\n", (unsigned)written_value, (unsigned)size); | 70 | printf("written written_value = %u of %u\n", (unsigned)written_value, (unsigned)size); |
@@ -79,20 +79,18 @@ static void load_data_decrypted(void) | |||
79 | { | 79 | { |
80 | FILE *f = fopen(savefile, "r"); | 80 | FILE *f = fopen(savefile, "r"); |
81 | fseek(f, 0, SEEK_END); | 81 | fseek(f, 0, SEEK_END); |
82 | long size = ftell(f); | 82 | int64_t size = ftell(f); |
83 | fseek(f, 0, SEEK_SET); | 83 | fseek(f, 0, SEEK_SET); |
84 | 84 | ||
85 | uint8_t *cipher = (uint8_t *)malloc(size); | 85 | uint8_t *cipher = (uint8_t *)malloc(size); |
86 | uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH); | 86 | uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH); |
87 | size_t read_value = fread(cipher, sizeof(*cipher), size, f); | 87 | size_t read_value = fread(cipher, sizeof(*cipher), size, f); |
88 | printf("read read_vavue = %u of %ld\n", (unsigned)read_value, size); | 88 | printf("Read read_vavue = %u of %ld\n", (unsigned)read_value, size); |
89 | 89 | ||
90 | TOX_ERR_DECRYPTION derr; | 90 | TOX_ERR_DECRYPTION derr; |
91 | 91 | ||
92 | if (!tox_pass_decrypt(cipher, size, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr)) { | 92 | ck_assert_msg(tox_pass_decrypt(cipher, size, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr), |
93 | fprintf(stderr, "error: could not decrypt, error code %d\n", derr); | 93 | "Could not decrypt, error code %d.", derr); |
94 | exit(3); | ||
95 | } | ||
96 | 94 | ||
97 | struct Tox_Options *options = tox_options_new(nullptr); | 95 | struct Tox_Options *options = tox_options_new(nullptr); |
98 | 96 | ||
@@ -106,19 +104,14 @@ static void load_data_decrypted(void) | |||
106 | 104 | ||
107 | tox_options_free(options); | 105 | tox_options_free(options); |
108 | 106 | ||
109 | if (t == nullptr) { | 107 | ck_assert_msg(t != nullptr, "tox_new returned the error value %d", err); |
110 | fprintf(stderr, "error: tox_new returned the error value %d\n", err); | ||
111 | return; | ||
112 | } | ||
113 | 108 | ||
114 | uint8_t readname[TOX_MAX_NAME_LENGTH]; | 109 | uint8_t readname[TOX_MAX_NAME_LENGTH]; |
115 | tox_self_get_name(t, readname); | 110 | tox_self_get_name(t, readname); |
116 | readname[tox_self_get_name_size(t)] = '\0'; | 111 | readname[tox_self_get_name_size(t)] = '\0'; |
117 | 112 | ||
118 | if (strcmp((const char *)readname, name)) { | 113 | ck_assert_msg(strcmp((const char *)readname, name) == 0, |
119 | fprintf(stderr, "error: name returned by tox_self_get_name does not match expected result\n"); | 114 | "name returned by tox_self_get_name does not match expected result"); |
120 | exit(2); | ||
121 | } | ||
122 | 115 | ||
123 | free(cipher); | 116 | free(cipher); |
124 | free(clear); | 117 | free(clear); |
@@ -132,11 +125,7 @@ int main(void) | |||
132 | save_data_encrypted(); | 125 | save_data_encrypted(); |
133 | load_data_decrypted(); | 126 | load_data_decrypted(); |
134 | 127 | ||
135 | int ret = remove(savefile); | 128 | ck_assert_msg(remove(savefile) == 0, "Could not remove the savefile."); |
136 | |||
137 | if (ret != 0) { | ||
138 | fprintf(stderr, "error: could not remove savefile\n"); | ||
139 | } | ||
140 | 129 | ||
141 | return 0; | 130 | return 0; |
142 | } | 131 | } |