diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-25 22:50:26 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-25 23:25:15 +0000 |
commit | 80f8458146061e5fe6edd97e06e039f1ad2cf3a9 (patch) | |
tree | 89502730a4d9f26c15946ce08820bc0abe4f4653 /auto_tests/save_compatibility_test.c | |
parent | 17e8195a8f988a45b2822522bc7b967b3ebc3ca6 (diff) |
Run save_compatibility_test in the autotools build.
Diffstat (limited to 'auto_tests/save_compatibility_test.c')
-rw-r--r-- | auto_tests/save_compatibility_test.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/auto_tests/save_compatibility_test.c b/auto_tests/save_compatibility_test.c index 30e87ef8..216b368c 100644 --- a/auto_tests/save_compatibility_test.c +++ b/auto_tests/save_compatibility_test.c | |||
@@ -1,9 +1,11 @@ | |||
1 | //Tests to make sure new save code is compatible with old save files | 1 | // Tests to make sure new save code is compatible with old save files |
2 | 2 | ||
3 | #include "../testing/misc_tools.h" | 3 | #include "../testing/misc_tools.h" |
4 | #include "../toxcore/tox.h" | 4 | #include "../toxcore/tox.h" |
5 | #include "check_compat.h" | 5 | #include "check_compat.h" |
6 | 6 | ||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
7 | #include <string.h> | 9 | #include <string.h> |
8 | 10 | ||
9 | #define LOADED_SAVE_FILE "../auto_tests/data/save.tox" | 11 | #define LOADED_SAVE_FILE "../auto_tests/data/save.tox" |
@@ -67,12 +69,12 @@ static uint8_t *read_save(const char *save_path, size_t *length) | |||
67 | 69 | ||
68 | static void test_save_compatibility(const char *save_path) | 70 | static void test_save_compatibility(const char *save_path) |
69 | { | 71 | { |
70 | struct Tox_Options options = { 0 }; | 72 | struct Tox_Options options = {0}; |
71 | tox_options_default(&options); | 73 | tox_options_default(&options); |
72 | 74 | ||
73 | size_t size = 0; | 75 | size_t size = 0; |
74 | uint8_t *save_data = read_save(save_path, &size); | 76 | uint8_t *save_data = read_save(save_path, &size); |
75 | ck_assert_msg(save_data != nullptr, "Error while reading save file."); | 77 | ck_assert_msg(save_data != nullptr, "error while reading save file '%s'", save_path); |
76 | 78 | ||
77 | options.savedata_data = save_data; | 79 | options.savedata_data = save_data; |
78 | options.savedata_length = size; | 80 | options.savedata_length = size; |
@@ -109,14 +111,14 @@ static void test_save_compatibility(const char *save_path) | |||
109 | "number of friends do not match, expected %d got %zu", EXPECTED_NUM_FRIENDS, num_friends); | 111 | "number of friends do not match, expected %d got %zu", EXPECTED_NUM_FRIENDS, num_friends); |
110 | 112 | ||
111 | const uint32_t nospam = tox_self_get_nospam(tox); | 113 | const uint32_t nospam = tox_self_get_nospam(tox); |
112 | char nospam_str[(TOX_NOSPAM_SIZE * 2) + 1]; | 114 | char nospam_str[TOX_NOSPAM_SIZE * 2 + 1]; |
113 | const size_t length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam); | 115 | const size_t length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam); |
114 | nospam_str[length] = '\0'; | 116 | nospam_str[length] = '\0'; |
115 | ck_assert_msg(strcmp(nospam_str, EXPECTED_NOSPAM) == 0, | 117 | ck_assert_msg(strcmp(nospam_str, EXPECTED_NOSPAM) == 0, |
116 | "nospam does not match, expected %s got %s", EXPECTED_NOSPAM, nospam_str); | 118 | "nospam does not match, expected %s got %s", EXPECTED_NOSPAM, nospam_str); |
117 | 119 | ||
118 | uint8_t tox_id[TOX_ADDRESS_SIZE]; | 120 | uint8_t tox_id[TOX_ADDRESS_SIZE]; |
119 | char tox_id_str[TOX_ADDRESS_SIZE * 2]; | 121 | char tox_id_str[TOX_ADDRESS_SIZE * 2 + 1] = {0}; |
120 | tox_self_get_address(tox, tox_id); | 122 | tox_self_get_address(tox, tox_id); |
121 | to_hex(tox_id_str, tox_id, TOX_ADDRESS_SIZE); | 123 | to_hex(tox_id_str, tox_id, TOX_ADDRESS_SIZE); |
122 | ck_assert_msg(strncmp(tox_id_str, EXPECTED_TOX_ID, TOX_ADDRESS_SIZE * 2) == 0, | 124 | ck_assert_msg(strncmp(tox_id_str, EXPECTED_TOX_ID, TOX_ADDRESS_SIZE * 2) == 0, |
@@ -127,12 +129,16 @@ static void test_save_compatibility(const char *save_path) | |||
127 | 129 | ||
128 | int main(int argc, char *argv[]) | 130 | int main(int argc, char *argv[]) |
129 | { | 131 | { |
130 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
131 | |||
132 | char base_path[4096]; | 132 | char base_path[4096]; |
133 | 133 | ||
134 | if (argc <= 1) { | 134 | if (argc <= 1) { |
135 | strcpy(base_path, "."); | 135 | const char *srcdir = getenv("srcdir"); |
136 | |||
137 | if (srcdir == nullptr) { | ||
138 | srcdir = "."; | ||
139 | } | ||
140 | |||
141 | strcpy(base_path, srcdir); | ||
136 | } else { | 142 | } else { |
137 | strcpy(base_path, argv[1]); | 143 | strcpy(base_path, argv[1]); |
138 | base_path[strrchr(base_path, '/') - base_path] = 0; | 144 | base_path[strrchr(base_path, '/') - base_path] = 0; |